SDES2REACTTCLIN ;ALB/TJB,MGD - VISTA SCHEDULING REACTIVATE CLINIC RPC in HOSPITAL LOCATION FILE 44 ;Mar 18, 2024
;;5.3;Scheduling;**861,864,877**;Aug 13, 1993;Build 14
;;Per VHA Directive 6402, this routine should not be modified
;
; Documented API's and Integration Agreements
; -------------------------------------------
; Reference to $$GET1^DIQ is supported by IA #2056
; Reference to TURNON^DIAUTL is supported by IA #4397
;
Q ;No Direct Call
;
; The parameter list for this RPC must be kept in sync.
; If you need to add or remove a parameter, ensure that the Remote Procedure File #8994 definition is also updated.
;
REACTIVATECLIN(RETURNJSON,SDCONTEXT,SDPARAM) ;Entry point for SDES2 REACTIVATE CLINIC RPC
;
; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
; SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
; SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
; SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
; SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
;
; SDPARAM("CLINIC IEN")=CLINIC IEN IEN of the clinic in file 44 - Hospital location (required)
; SDPARAM("REACTIVATION DATE")=DATE ISO DATE to reactivate the clinic (required)
;
;RETURN PARMETER:
;
; Output:
; Successful Return:
; RETURNJSON = Returns the reactivated clinic IEN along with the successful message in JSON formatted string.
; Otherwise, JSON Errors will be returned for any invalid/missing parameters.
;
N ERRORS,RETURNERROR,RETURN ;temp data storage for input validation error
N ISREACTIVATED
;
K RETURNJSON ;always kill the return json array
;
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("ReactivateClinic",1)="" D BUILDJSON^SDES2JSON(.RETURNJSON,.ERRORS) Q
D INITVAR
D VALCLNIENREACTDT(.ERRORS,SDCLINICIEN,REACTIVATIONDATE)
I $O(ERRORS("Error",""))'="" D SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON) Q
D TURNON^DIAUTL(44,2506,"y") ;turn on auditing for REACTIVATE DATE field in the HOSPITAL LOCATION (#44) file
S REACTIVATIONDATE=$$ISOTFM^SDAMUTDT(REACTIVATIONDATE,SDCLINICIEN)
S ISREACTIVATED=$$REACTIVATE(.RETURN,SDCLINICIEN,REACTIVATIONDATE)
I $O(ERRORS("Error",""))'="" D SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON) Q ;error occured during filing
I ISREACTIVATED D UPDATECLNRES(SDCLINICIEN,REACTIVATIONDATE,$G(SDCONTEXT("USER DUZ")))
D BUILDJSON^SDES2JSON(.RETURNJSON,.RETURN)
Q
;
INITVAR ;Initialize input parameter
S SDCLINICIEN=$G(SDPARAM("CLINIC IEN"))
S REACTIVATIONDATE=$G(SDPARAM("REACTIVATION DATE"))
Q
;
REACTIVATE(RETURN,SDCLINICIEN,REACTIVATIONDATE) ;Reactivate Clinic
N SDERR,SDFDA,SDCLNNAME,ISFILED
S ISFILED=0
;Only update the Reactivate Date field if the reacivation passed in is different
I $$GET1^DIQ(44,SDCLINICIEN,2506)'=$P(REACTIVATIONDATE,".") D
. S SDCLNNAME=$$GET1^DIQ(44,SDCLINICIEN,.01)
. I $E(SDCLNNAME,1,2)="ZZ" S SDFDA(44,SDCLINICIEN_",",.01)=$$TRIM^XLFSTR($E($$GET1^DIQ(44,SDCLINICIEN,.01),3,32),"L")
. S SDFDA(44,SDCLINICIEN_",",2506)=$P(REACTIVATIONDATE,".")
. D FILE^DIE("","SDFDA","SDERR")
. I $G(SDERR) S ISFILED=0 D ERRLOG^SDES2JSON(.ERRORS,239) Q
. S RETURN("ReactivateClinic","IEN")=SDCLINICIEN
. S RETURN("ReactivateClinic","SuccessMessage")="Clinic is successfully reactivated effective "_$TR($$FMTE^XLFDT(REACTIVATIONDATE,"5DF")," ","0")
. S ISFILED=1
Q ISFILED
;
UPDATECLNRES(SDCLINICIEN,REACTIVATIONDATE,SDDUZ) ;Update REACTIVATED DATE/TIME and REACTIVATED BY USER in SDEC RESOURCE File #409.831
N SDRESFDA,SDCLINRES
S SDCLINRES=$$GETRES^SDES2UTIL1(SDCLINICIEN,1)
Q:SDCLINRES=""
S SDRESFDA(409.831,SDCLINRES_",",.025)=$P(REACTIVATIONDATE,".")
S SDRESFDA(409.831,SDCLINRES_",",.026)=$S(SDDUZ'="":SDDUZ,1:DUZ)
D FILE^DIE("","SDRESFDA")
Q
;
VALCLNIENREACTDT(ERRORS,CLINICIEN,REACTIVATIONDATE) ;validate Clinic IEN and Reactivation Date (they need to go hand in hand together)
N INACTDT,REACTDT,SDCLINNAME
I CLINICIEN="" D ERRLOG^SDES2JSON(.ERRORS,18)
I CLINICIEN'="" D
. I '$D(^SC(CLINICIEN,0)) D ERRLOG^SDES2JSON(.ERRORS,19) Q
. I $$GET1^DIQ(44,CLINICIEN,2,"I")'="C" D ERRLOG^SDES2JSON(.ERRORS,236) Q
;
S SDCLNNAME=$$GET1^DIQ(44,CLINICIEN,.01)
; Check to see if there is a Clinic with the same name without the "ZZ"
I $E(SDCLNNAME,1,2)="ZZ" D
. N SDNEWNAME,TEMPIEN S TEMPIEN=""
. S SDNEWNAME=$$TRIM^XLFSTR($E(SDCLNNAME,3,32),"L") ; Take care of ZZ{space}NAME
. S TEMPIEN=$O(^SC("B",SDNEWNAME,TEMPIEN))
. I TEMPIEN'="" D ERRLOG^SDES2JSON(.ERRORS,51,"Clinic Name without leading ZZ is the same as active Clinic")
;
S REACTIVATIONDATE=$$ISOTFM^SDAMUTDT(REACTIVATIONDATE,CLINICIEN)
I REACTIVATIONDATE="" D ERRLOG^SDES2JSON(.ERRORS,240) Q
I REACTIVATIONDATE'="",REACTIVATIONDATE<1 D ERRLOG^SDES2JSON(.ERRORS,238) Q
S INACTDT=$$GET1^DIQ(44,CLINICIEN,2505,"I")
S REACTDT=$$GET1^DIQ(44,CLINICIEN,2506,"I")
I INACTDT="" D ERRLOG^SDES2JSON(.ERRORS,52,"Clinic is not inactive") Q
I REACTIVATIONDATE<=INACTDT D ERRLOG^SDES2JSON(.ERRORS,237,"Inactivation date "_$TR($$FMTE^XLFDT(INACTDT,"5DF")," ","0")) Q
I REACTIVATIONDATE<=DT D ERRLOG^SDES2JSON(.ERRORS,52,"Reactivation date must be greater than "_$TR($$FMTE^XLFDT(DT,"5DF")," ","0")) Q
I REACTDT'="",REACTDT>INACTDT,REACTDT=REACTIVATIONDATE D Q
. D ERRLOG^SDES2JSON(.ERRORS,52,"Clinic already reactivated effective "_$TR($$FMTE^XLFDT(REACTDT,"5DF")," ","0"))
Q
;
SETERRORRETURN(ERRORS,RETURNERROR,RETURNJSON) ;
M RETURNERROR=ERRORS
D SETEMPTYOBJECT(.RETURNERROR) ;set the return object into null if an error occur
D BUILDJSON^SDES2JSON(.RETURNJSON,.RETURNERROR)
Q
;
SETEMPTYOBJECT(RETURNERROR) ;set the return object into null if an error occur
S RETURNERROR("ReactivateClinic","IEN")=""
S RETURNERROR("ReactivateClinic","SuccessMessage")=""
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2REACTTCLIN 6023 printed Sep 15, 2024@22:18:24 Page 2
SDES2REACTTCLIN ;ALB/TJB,MGD - VISTA SCHEDULING REACTIVATE CLINIC RPC in HOSPITAL LOCATION FILE 44 ;Mar 18, 2024
+1 ;;5.3;Scheduling;**861,864,877**;Aug 13, 1993;Build 14
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; Documented API's and Integration Agreements
+5 ; -------------------------------------------
+6 ; Reference to $$GET1^DIQ is supported by IA #2056
+7 ; Reference to TURNON^DIAUTL is supported by IA #4397
+8 ;
+9 ;No Direct Call
QUIT
+10 ;
+11 ; The parameter list for this RPC must be kept in sync.
+12 ; If you need to add or remove a parameter, ensure that the Remote Procedure File #8994 definition is also updated.
+13 ;
REACTIVATECLIN(RETURNJSON,SDCONTEXT,SDPARAM) ;Entry point for SDES2 REACTIVATE CLINIC RPC
+1 ;
+2 ; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
+3 ; SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
+4 ; SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
+5 ; SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
+6 ; SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
+7 ;
+8 ; SDPARAM("CLINIC IEN")=CLINIC IEN IEN of the clinic in file 44 - Hospital location (required)
+9 ; SDPARAM("REACTIVATION DATE")=DATE ISO DATE to reactivate the clinic (required)
+10 ;
+11 ;RETURN PARMETER:
+12 ;
+13 ; Output:
+14 ; Successful Return:
+15 ; RETURNJSON = Returns the reactivated clinic IEN along with the successful message in JSON formatted string.
+16 ; Otherwise, JSON Errors will be returned for any invalid/missing parameters.
+17 ;
+18 ;temp data storage for input validation error
NEW ERRORS,RETURNERROR,RETURN
+19 NEW ISREACTIVATED
+20 ;
+21 ;always kill the return json array
KILL RETURNJSON
+22 ;
+23 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+24 IF $DATA(ERRORS)
SET ERRORS("ReactivateClinic",1)=""
DO BUILDJSON^SDES2JSON(.RETURNJSON,.ERRORS)
QUIT
+25 DO INITVAR
+26 DO VALCLNIENREACTDT(.ERRORS,SDCLINICIEN,REACTIVATIONDATE)
+27 IF $ORDER(ERRORS("Error",""))'=""
DO SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON)
QUIT
+28 ;turn on auditing for REACTIVATE DATE field in the HOSPITAL LOCATION (#44) file
DO TURNON^DIAUTL(44,2506,"y")
+29 SET REACTIVATIONDATE=$$ISOTFM^SDAMUTDT(REACTIVATIONDATE,SDCLINICIEN)
+30 SET ISREACTIVATED=$$REACTIVATE(.RETURN,SDCLINICIEN,REACTIVATIONDATE)
+31 ;error occured during filing
IF $ORDER(ERRORS("Error",""))'=""
DO SETERRORRETURN(.ERRORS,.RETURNERROR,.RETURNJSON)
QUIT
+32 IF ISREACTIVATED
DO UPDATECLNRES(SDCLINICIEN,REACTIVATIONDATE,$GET(SDCONTEXT("USER DUZ")))
+33 DO BUILDJSON^SDES2JSON(.RETURNJSON,.RETURN)
+34 QUIT
+35 ;
INITVAR ;Initialize input parameter
+1 SET SDCLINICIEN=$GET(SDPARAM("CLINIC IEN"))
+2 SET REACTIVATIONDATE=$GET(SDPARAM("REACTIVATION DATE"))
+3 QUIT
+4 ;
REACTIVATE(RETURN,SDCLINICIEN,REACTIVATIONDATE) ;Reactivate Clinic
+1 NEW SDERR,SDFDA,SDCLNNAME,ISFILED
+2 SET ISFILED=0
+3 ;Only update the Reactivate Date field if the reacivation passed in is different
+4 IF $$GET1^DIQ(44,SDCLINICIEN,2506)'=$PIECE(REACTIVATIONDATE,".")
Begin DoDot:1
+5 SET SDCLNNAME=$$GET1^DIQ(44,SDCLINICIEN,.01)
+6 IF $EXTRACT(SDCLNNAME,1,2)="ZZ"
SET SDFDA(44,SDCLINICIEN_",",.01)=$$TRIM^XLFSTR($EXTRACT($$GET1^DIQ(44,SDCLINICIEN,.01),3,32),"L")
+7 SET SDFDA(44,SDCLINICIEN_",",2506)=$PIECE(REACTIVATIONDATE,".")
+8 DO FILE^DIE("","SDFDA","SDERR")
+9 IF $GET(SDERR)
SET ISFILED=0
DO ERRLOG^SDES2JSON(.ERRORS,239)
QUIT
+10 SET RETURN("ReactivateClinic","IEN")=SDCLINICIEN
+11 SET RETURN("ReactivateClinic","SuccessMessage")="Clinic is successfully reactivated effective "_$TRANSLATE($$FMTE^XLFDT(REACTIVATIONDATE,"5DF")," ","0")
+12 SET ISFILED=1
End DoDot:1
+13 QUIT ISFILED
+14 ;
UPDATECLNRES(SDCLINICIEN,REACTIVATIONDATE,SDDUZ) ;Update REACTIVATED DATE/TIME and REACTIVATED BY USER in SDEC RESOURCE File #409.831
+1 NEW SDRESFDA,SDCLINRES
+2 SET SDCLINRES=$$GETRES^SDES2UTIL1(SDCLINICIEN,1)
+3 if SDCLINRES=""
QUIT
+4 SET SDRESFDA(409.831,SDCLINRES_",",.025)=$PIECE(REACTIVATIONDATE,".")
+5 SET SDRESFDA(409.831,SDCLINRES_",",.026)=$SELECT(SDDUZ'="":SDDUZ,1:DUZ)
+6 DO FILE^DIE("","SDRESFDA")
+7 QUIT
+8 ;
VALCLNIENREACTDT(ERRORS,CLINICIEN,REACTIVATIONDATE) ;validate Clinic IEN and Reactivation Date (they need to go hand in hand together)
+1 NEW INACTDT,REACTDT,SDCLINNAME
+2 IF CLINICIEN=""
DO ERRLOG^SDES2JSON(.ERRORS,18)
+3 IF CLINICIEN'=""
Begin DoDot:1
+4 IF '$DATA(^SC(CLINICIEN,0))
DO ERRLOG^SDES2JSON(.ERRORS,19)
QUIT
+5 IF $$GET1^DIQ(44,CLINICIEN,2,"I")'="C"
DO ERRLOG^SDES2JSON(.ERRORS,236)
QUIT
End DoDot:1
+6 ;
+7 SET SDCLNNAME=$$GET1^DIQ(44,CLINICIEN,.01)
+8 ; Check to see if there is a Clinic with the same name without the "ZZ"
+9 IF $EXTRACT(SDCLNNAME,1,2)="ZZ"
Begin DoDot:1
+10 NEW SDNEWNAME,TEMPIEN
SET TEMPIEN=""
+11 ; Take care of ZZ{space}NAME
SET SDNEWNAME=$$TRIM^XLFSTR($EXTRACT(SDCLNNAME,3,32),"L")
+12 SET TEMPIEN=$ORDER(^SC("B",SDNEWNAME,TEMPIEN))
+13 IF TEMPIEN'=""
DO ERRLOG^SDES2JSON(.ERRORS,51,"Clinic Name without leading ZZ is the same as active Clinic")
End DoDot:1
+14 ;
+15 SET REACTIVATIONDATE=$$ISOTFM^SDAMUTDT(REACTIVATIONDATE,CLINICIEN)
+16 IF REACTIVATIONDATE=""
DO ERRLOG^SDES2JSON(.ERRORS,240)
QUIT
+17 IF REACTIVATIONDATE'=""
IF REACTIVATIONDATE<1
DO ERRLOG^SDES2JSON(.ERRORS,238)
QUIT
+18 SET INACTDT=$$GET1^DIQ(44,CLINICIEN,2505,"I")
+19 SET REACTDT=$$GET1^DIQ(44,CLINICIEN,2506,"I")
+20 IF INACTDT=""
DO ERRLOG^SDES2JSON(.ERRORS,52,"Clinic is not inactive")
QUIT
+21 IF REACTIVATIONDATE<=INACTDT
DO ERRLOG^SDES2JSON(.ERRORS,237,"Inactivation date "_$TRANSLATE($$FMTE^XLFDT(INACTDT,"5DF")," ","0"))
QUIT
+22 IF REACTIVATIONDATE<=DT
DO ERRLOG^SDES2JSON(.ERRORS,52,"Reactivation date must be greater than "_$TRANSLATE($$FMTE^XLFDT(DT,"5DF")," ","0"))
QUIT
+23 IF REACTDT'=""
IF REACTDT>INACTDT
IF REACTDT=REACTIVATIONDATE
Begin DoDot:1
+24 DO ERRLOG^SDES2JSON(.ERRORS,52,"Clinic already reactivated effective "_$TRANSLATE($$FMTE^XLFDT(REACTDT,"5DF")," ","0"))
End DoDot:1
QUIT
+25 QUIT
+26 ;
SETERRORRETURN(ERRORS,RETURNERROR,RETURNJSON) ;
+1 MERGE RETURNERROR=ERRORS
+2 ;set the return object into null if an error occur
DO SETEMPTYOBJECT(.RETURNERROR)
+3 DO BUILDJSON^SDES2JSON(.RETURNJSON,.RETURNERROR)
+4 QUIT
+5 ;
SETEMPTYOBJECT(RETURNERROR) ;set the return object into null if an error occur
+1 SET RETURNERROR("ReactivateClinic","IEN")=""
+2 SET RETURNERROR("ReactivateClinic","SuccessMessage")=""
+3 QUIT
+4 ;