SDES2UNDOCHKOUT ;ALB/ANU/TJB - VISTA SCHEDULING RPCS - SDES2 UNDO CHECKOUT ;APR 08, 2024
;;5.3;Scheduling;**877**;Aug 13, 1993;Build 14
;;Per VHA Directive 6402, this routine should not be modified;
;
; Reference to MAS PARAMETERS in ICR #483
; Reference to WARD LOCATION in ICR #1377
; Reference to MAS PARAMETERS in ICR #2296
; Reference to VISIT in ICR #2028
;
Q
; INPUT
;
; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
; 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.
; 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.
; SDINPUT("APPOINTMENT IEN") = (Required) Appointment IEN
;
UNDOCHECKOUT(JSONRETURN,SDCONTEXT,SDINPUT) ;
N ERRORS,SDRETURN,PARAMETERS,SDDUZ
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("UndoCheckOut",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
S PARAMETERS=$$VALPARAMS(.SDINPUT,.ERRORS)
I $D(ERRORS) S ERRORS("UndoCheckOut",1)="" D BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS) Q
;
S SDDUZ=$S(+$G(SDCONTEXT("USER DUZ")):+SDCONTEXT("USER DUZ"),1:$G(DUZ))
D UNDOCKOUT(.SDRETURN,PARAMETERS,SDDUZ)
I '$D(SDRETURN) S SDRETURN("UndoCheckOut",1)=""
D BUILDJSON^SDES2JSON(.JSONRETURN,.SDRETURN)
Q
;
VALPARAMS(PARAMS,SDERRORS) ; Validate
N SDIEN,SDCHECKDT
;
; Validate Appointment IEN
S SDIEN=$G(PARAMS("APPOINTMENT IEN"))
I '$G(SDIEN) D ERRLOG^SDES2JSON(.SDERRORS,14) Q 0
I '$D(^SDEC(409.84,SDIEN,0)) D ERRLOG^SDES2JSON(.SDERRORS,15) Q 0 ;invalid appt IEN
S SDCHECKDT=$$GET1^DIQ(409.84,SDIEN,.14,"I")
I 'SDCHECKDT D ERRLOG^SDES2JSON(.SDERRORS,377) Q 0
I $$FMDIFF^XLFDT(DT,SDCHECKDT,1)'=0 D ERRLOG^SDES2JSON(.SDERRORS,47,"Undo Checkout must be performed same calendar day as checkout") Q 0
;
Q:$D(SDERRORS) 0
Q SDIEN
;
UNDOCKOUT(SDRETURN,APPTIEN,SDDUZ) ;
N ERRORS,APPTSUBIEN44,APPTSTARTTIME,DFN,CLINICIEN,RESOURCEIEN,SDATA,SDCIHDL
;
S APPTSTARTTIME=$$GET1^DIQ(409.84,APPTIEN,.01,"I")
S DFN=$$GET1^DIQ(409.84,APPTIEN,.05,"I")
S RESOURCEIEN=$$GET1^DIQ(409.84,APPTIEN,.07,"I")
S CLINICIEN=$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I")
S APPTSUBIEN44=$$FIND^SDESCHECKOUT(DFN,APPTSTARTTIME,CLINICIEN)
S SDATA=APPTSUBIEN44_U_DFN_U_APPTSTARTTIME_U_CLINICIEN
S SDCIHDL=$$HANDLE^SDAMEVT(1)
;
D BEFOREEVENT($G(APPTSTARTTIME),$G(DFN),$G(CLINICIEN),$G(APPTSUBIEN44),SDCIHDL,.SDATA)
D UNDO($G(APPTIEN),$G(CLINICIEN),$G(APPTSTARTTIME),$G(DFN),SDDUZ)
D AFTEREVENT($G(APPTSTARTTIME),$G(DFN),$G(CLINICIEN),$G(APPTSUBIEN44),SDCIHDL,.SDATA)
;
S SDRETURN("UndoCheckOut","UndoCheckOutCompleted")=1
Q
;
UNDO(APPTIEN,CLINICIEN,APPTSTARTTIME,DFN,SDDUZ) ;
N FDA84,ERR84,FDA44,ERR44,IENS44,ENCOUNTERIEN,VISITFILEIEN,FDA9000010,ERR9000010,FDA40968,ERR40968
;
S FDA84(409.84,APPTIEN_",",.14)="@"
S FDA84(409.84,APPTIEN_",",.08)=$G(SDDUZ)
D FILE^DIE(,"FDA84","ERR84") K FDA84
;
S IENS44=$$GET44RECORDIENS^SDESCANCELAPPTS(CLINICIEN,APPTSTARTTIME,DFN)
I $G(IENS44) D
.S FDA44(44.003,IENS44,303)="@"
.S FDA44(44.003,IENS44,304)="@"
.S FDA44(44.003,IENS44,306)="@"
.D FILE^DIE(,"FDA44","ERR44") K FDA44
;
S ENCOUNTERIEN=$$GETAPT^SDVSIT2(DFN,APPTSTARTTIME,CLINICIEN)
S VISITFILEIEN=$$GET1^DIQ(409.68,ENCOUNTERIEN,.05,"I")
I $D(^AUPNVSIT($G(VISITFILEIEN),0)) D
.S FDA9000010(9000010,VISITFILEIEN_",",.18)="@"
.D FILE^DIE(,"FDA9000010","ERR9000010") K FDA9000010
;
I $D(^SCE($G(ENCOUNTERIEN),0)),$$GET1^DIQ(409.84,APPTIEN,.19,"I") D
.S FDA40968(409.68,ENCOUNTERIEN_",",.07)="@"
.S FDA40968(409.68,ENCOUNTERIEN_",",.12)=$$GET1^DIQ(409.84,APPTIEN,.19,"I")
.S FDA40968(409.68,ENCOUNTERIEN_",",101)=$G(SDDUZ)
.S FDA40968(409.68,ENCOUNTERIEN_",",102)=$$NOW^XLFDT
.D FILE^DIE(,"FDA40968","ERR40968") K FDA40968
;
Q
;
BEFOREEVENT(APPTSTARTTIME,DFN,CLINICIEN,APPTSUBIEN44,SDCIHDL,SDATA) ;
D BEFORE^SDAMEVT(.SDATA,DFN,APPTSTARTTIME,CLINICIEN,APPTSUBIEN44,SDCIHDL)
Q
;
AFTEREVENT(APPTSTARTTIME,DFN,CLINICIEN,APPTSUBIEN44,SDCIHDL,SDATA) ;
D AFTER^SDAMEVT(.SDATA,DFN,APPTSTARTTIME,CLINICIEN,APPTSUBIEN44,SDCIHDL)
D EVT^SDAMEVT(.SDATA,5,2,SDCIHDL) ;
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2UNDOCHKOUT 4365 printed Dec 13, 2024@02:54:45 Page 2
SDES2UNDOCHKOUT ;ALB/ANU/TJB - VISTA SCHEDULING RPCS - SDES2 UNDO CHECKOUT ;APR 08, 2024
+1 ;;5.3;Scheduling;**877**;Aug 13, 1993;Build 14
+2 ;;Per VHA Directive 6402, this routine should not be modified;
+3 ;
+4 ; Reference to MAS PARAMETERS in ICR #483
+5 ; Reference to WARD LOCATION in ICR #1377
+6 ; Reference to MAS PARAMETERS in ICR #2296
+7 ; Reference to VISIT in ICR #2028
+8 ;
+9 QUIT
+10 ; INPUT
+11 ;
+12 ; SDCONTEXT("ACHERON AUDIT ID") = Up to 40 Character unique ID number. Ex: 11d9dcc6-c6a2-4785-8031-8261576fca37
+13 ; SDCONTEXT("USER DUZ") = The DUZ of the user taking action in the calling application.
+14 ; SDCONTEXT("USER SECID") = The SECID of the user taking action in the calling application.
+15 ; SDCONTEXT("PATIENT DFN") = The DFN/IEN of the target patient from the calling application.
+16 ; SDCONTEXT("PATIENT ICN") = The ICN of the target patient from the calling application.
+17 ; SDINPUT("APPOINTMENT IEN") = (Required) Appointment IEN
+18 ;
UNDOCHECKOUT(JSONRETURN,SDCONTEXT,SDINPUT) ;
+1 NEW ERRORS,SDRETURN,PARAMETERS,SDDUZ
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 IF $DATA(ERRORS)
SET ERRORS("UndoCheckOut",1)=""
DO BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS)
QUIT
+4 SET PARAMETERS=$$VALPARAMS(.SDINPUT,.ERRORS)
+5 IF $DATA(ERRORS)
SET ERRORS("UndoCheckOut",1)=""
DO BUILDJSON^SDES2JSON(.JSONRETURN,.ERRORS)
QUIT
+6 ;
+7 SET SDDUZ=$SELECT(+$GET(SDCONTEXT("USER DUZ")):+SDCONTEXT("USER DUZ"),1:$GET(DUZ))
+8 DO UNDOCKOUT(.SDRETURN,PARAMETERS,SDDUZ)
+9 IF '$DATA(SDRETURN)
SET SDRETURN("UndoCheckOut",1)=""
+10 DO BUILDJSON^SDES2JSON(.JSONRETURN,.SDRETURN)
+11 QUIT
+12 ;
VALPARAMS(PARAMS,SDERRORS) ; Validate
+1 NEW SDIEN,SDCHECKDT
+2 ;
+3 ; Validate Appointment IEN
+4 SET SDIEN=$GET(PARAMS("APPOINTMENT IEN"))
+5 IF '$GET(SDIEN)
DO ERRLOG^SDES2JSON(.SDERRORS,14)
QUIT 0
+6 ;invalid appt IEN
IF '$DATA(^SDEC(409.84,SDIEN,0))
DO ERRLOG^SDES2JSON(.SDERRORS,15)
QUIT 0
+7 SET SDCHECKDT=$$GET1^DIQ(409.84,SDIEN,.14,"I")
+8 IF 'SDCHECKDT
DO ERRLOG^SDES2JSON(.SDERRORS,377)
QUIT 0
+9 IF $$FMDIFF^XLFDT(DT,SDCHECKDT,1)'=0
DO ERRLOG^SDES2JSON(.SDERRORS,47,"Undo Checkout must be performed same calendar day as checkout")
QUIT 0
+10 ;
+11 if $DATA(SDERRORS)
QUIT 0
+12 QUIT SDIEN
+13 ;
UNDOCKOUT(SDRETURN,APPTIEN,SDDUZ) ;
+1 NEW ERRORS,APPTSUBIEN44,APPTSTARTTIME,DFN,CLINICIEN,RESOURCEIEN,SDATA,SDCIHDL
+2 ;
+3 SET APPTSTARTTIME=$$GET1^DIQ(409.84,APPTIEN,.01,"I")
+4 SET DFN=$$GET1^DIQ(409.84,APPTIEN,.05,"I")
+5 SET RESOURCEIEN=$$GET1^DIQ(409.84,APPTIEN,.07,"I")
+6 SET CLINICIEN=$$GET1^DIQ(409.831,RESOURCEIEN,.04,"I")
+7 SET APPTSUBIEN44=$$FIND^SDESCHECKOUT(DFN,APPTSTARTTIME,CLINICIEN)
+8 SET SDATA=APPTSUBIEN44_U_DFN_U_APPTSTARTTIME_U_CLINICIEN
+9 SET SDCIHDL=$$HANDLE^SDAMEVT(1)
+10 ;
+11 DO BEFOREEVENT($GET(APPTSTARTTIME),$GET(DFN),$GET(CLINICIEN),$GET(APPTSUBIEN44),SDCIHDL,.SDATA)
+12 DO UNDO($GET(APPTIEN),$GET(CLINICIEN),$GET(APPTSTARTTIME),$GET(DFN),SDDUZ)
+13 DO AFTEREVENT($GET(APPTSTARTTIME),$GET(DFN),$GET(CLINICIEN),$GET(APPTSUBIEN44),SDCIHDL,.SDATA)
+14 ;
+15 SET SDRETURN("UndoCheckOut","UndoCheckOutCompleted")=1
+16 QUIT
+17 ;
UNDO(APPTIEN,CLINICIEN,APPTSTARTTIME,DFN,SDDUZ) ;
+1 NEW FDA84,ERR84,FDA44,ERR44,IENS44,ENCOUNTERIEN,VISITFILEIEN,FDA9000010,ERR9000010,FDA40968,ERR40968
+2 ;
+3 SET FDA84(409.84,APPTIEN_",",.14)="@"
+4 SET FDA84(409.84,APPTIEN_",",.08)=$GET(SDDUZ)
+5 DO FILE^DIE(,"FDA84","ERR84")
KILL FDA84
+6 ;
+7 SET IENS44=$$GET44RECORDIENS^SDESCANCELAPPTS(CLINICIEN,APPTSTARTTIME,DFN)
+8 IF $GET(IENS44)
Begin DoDot:1
+9 SET FDA44(44.003,IENS44,303)="@"
+10 SET FDA44(44.003,IENS44,304)="@"
+11 SET FDA44(44.003,IENS44,306)="@"
+12 DO FILE^DIE(,"FDA44","ERR44")
KILL FDA44
End DoDot:1
+13 ;
+14 SET ENCOUNTERIEN=$$GETAPT^SDVSIT2(DFN,APPTSTARTTIME,CLINICIEN)
+15 SET VISITFILEIEN=$$GET1^DIQ(409.68,ENCOUNTERIEN,.05,"I")
+16 IF $DATA(^AUPNVSIT($GET(VISITFILEIEN),0))
Begin DoDot:1
+17 SET FDA9000010(9000010,VISITFILEIEN_",",.18)="@"
+18 DO FILE^DIE(,"FDA9000010","ERR9000010")
KILL FDA9000010
End DoDot:1
+19 ;
+20 IF $DATA(^SCE($GET(ENCOUNTERIEN),0))
IF $$GET1^DIQ(409.84,APPTIEN,.19,"I")
Begin DoDot:1
+21 SET FDA40968(409.68,ENCOUNTERIEN_",",.07)="@"
+22 SET FDA40968(409.68,ENCOUNTERIEN_",",.12)=$$GET1^DIQ(409.84,APPTIEN,.19,"I")
+23 SET FDA40968(409.68,ENCOUNTERIEN_",",101)=$GET(SDDUZ)
+24 SET FDA40968(409.68,ENCOUNTERIEN_",",102)=$$NOW^XLFDT
+25 DO FILE^DIE(,"FDA40968","ERR40968")
KILL FDA40968
End DoDot:1
+26 ;
+27 QUIT
+28 ;
BEFOREEVENT(APPTSTARTTIME,DFN,CLINICIEN,APPTSUBIEN44,SDCIHDL,SDATA) ;
+1 DO BEFORE^SDAMEVT(.SDATA,DFN,APPTSTARTTIME,CLINICIEN,APPTSUBIEN44,SDCIHDL)
+2 QUIT
+3 ;
AFTEREVENT(APPTSTARTTIME,DFN,CLINICIEN,APPTSUBIEN44,SDCIHDL,SDATA) ;
+1 DO AFTER^SDAMEVT(.SDATA,DFN,APPTSTARTTIME,CLINICIEN,APPTSUBIEN44,SDCIHDL)
+2 ;
DO EVT^SDAMEVT(.SDATA,5,2,SDCIHDL)
+3 QUIT
+4 ;