SDES2CHECKIN ;ALB/LAB,TJB,JAS - SDES VISTA SCHEDULING SDES2 CHECKIN ;May 1,2024@10:00
;;5.3;Scheduling;**866,878**;Aug 13, 1993;Build 11
;;Per VHA Directive 6402, this routine should not be modified
Q
; Copied from SDESCHECKIN to be in SDES2 namespace
; CHECKIN(SDRETURN,SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER) ;Check in appointment
CHECKIN(SDRETURN,SDCONTEXT,SDPARAM) ;Check in appointment
;INPUT -
; 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("APPOINTMENT IEN")=IEN The appointment IEN from the SDES APPOINTMENT (#409.84) file. (required)
; SDPARAM("CHECKIN DATE TIME")=DATE ISO DATE and TIME to check-in the patient (required)
; SDPARAM("PROVIDER")=IEN IEN of the PROVIDER in file NEW PERSON (#200)
;
;RETURN PARMETER:
; {
; "Checkin":[
; "Checked In."
; ]
; }
;
N BSDVSTN,EMSG,ERRORS,RETURN
N SDECNOD,DFN,SDECSTART,DIK,DA,SDECID,SDECI,SDECIENS,SDECVEN,SDCLINICIEN
N SDECNOEV,SDECCAN,SDRESOURCE,%DT,X,Y
S SDECNOEV=1 ;Don't execute protocol
;
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Checkin",1)="" D BUILDJSON^SDES2JSON(.SDRETURN,.ERRORS) Q
D VALIDATEAPPT(.ERRORS,$G(SDPARAM("APPOINTMENT IEN")))
D:'$D(ERRORS) ASSIGNCLININFO($G(SDPARAM("APPOINTMENT IEN")),.SDCLINICIEN,.SDCLINSTOP) ;need clinic ien for checkin time conversion
S SDPARAM("CHECKIN DATE TIME")=$G(SDPARAM("CHECKIN DATE TIME"))
I '$D(ERRORS) S SDPARAM("CHECKIN DATE TIME")=$$VALIDATECHKINDT(.ERRORS,SDPARAM("CHECKIN DATE TIME"),SDCLINICIEN)
D VALPROVIDER^SDES2VAL200(.ERRORS,$G(SDPARAM("PROVIDER")))
I $D(ERRORS) S ERRORS("Checkin",1)="" M RETURN=ERRORS
I '$D(ERRORS) D
. D PROCESSCHECKIN(SDPARAM("APPOINTMENT IEN"),$G(SDPARAM("PROVIDER")),SDCLINICIEN,$G(SDCONTEXT("USER DUZ")),SDCLINSTOP,SDPARAM("CHECKIN DATE TIME"),$G(SDCONTEXT("ACHERON AUDIT ID")),.ERRORS)
I '$D(ERRORS) D
. S RETURN("Checkin")="Checked in"
D BUILDJSON^SDES2JSON(.SDRETURN,.RETURN)
Q
;
VALIDATEAPPT(ERRORS,SDAPPTIEN) ;validate SDEC appointment ID
;invalid appointment ID is error 15
N RET
D VALFILEIEN^SDES2VALUTIL(.RET,.ERRORS,"409.84",SDAPPTIEN,1,,14,15)
Q
;
VALIDATECHKINDT(ERRORS,SDCHECKINDTTIM,SDCLINICIEN) ;validate checkin date/time (required)
; need to change to accept ISO 8601 date/time
S SDCHECKINDTTIM=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(SDCHECKINDTTIM),SDCLINICIEN,1,21,22)
Q SDCHECKINDTTIM
;
ASSIGNCLININFO(SDAPPTIEN,CLINICIEN,CLINICSTOP) ;
S CLINICIEN=$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I"),.04,"I")
S CLINICSTOP=$$GET1^DIQ(44,CLINICIEN,8,"I")
Q
;
PROCESSCHECKIN(SDAPPTIEN,SDPROVIDER,SDCLINICIEN,SDDUZ,SDCLINICSTOP,SDCHECKINDTTIM,SDACHAUDIT,ERRORS) ;
N DFN,SDECSTART,SDRESOURCE
S DFN=$$GET1^DIQ(409.84,SDAPPTIEN,.05,"I") ; must use variable name DFN as it is needed to be defined for event logic.
S SDECSTART=$$GET1^DIQ(409.84,SDAPPTIEN,.01,"I")
S SDRESOURCE=$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I")
; Hospital Location is required for CHECKIN
I 'SDCLINICIEN]"",'$D(^SC(+SDCLINICIEN,0)) D ERRLOG^SDES2JSON(.ERRORS,342) Q
I SDRESOURCE]"",$D(^SDEC(409.831,SDRESOURCE,0)) D
. ;
. ; Event driver "BEFORE" actions
. N SDATA,SDDA,SDCIHDL ;
. S SDDA=$$FIND(DFN,SDECSTART,SDCLINICIEN)
. S SDATA=SDDA_U_DFN_U_SDECSTART_U_SDCLINICIEN,SDCIHDL=$$HANDLE^SDAMEVT(1) ;
. D BEFORE^SDAMEVT(.SDATA,DFN,SDECSTART,SDCLINICIEN,SDDA,SDCIHDL) ;
. ;
. ; Checkin SDEC APPOINTMENT entry
. D SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER,$G(SDACHAUDIT)) ; sets field .03 (Checkin), in file 409.84
. D APCHK(SDCLINICIEN,DFN,SDCHECKINDTTIM,SDECSTART,SDDUZ,SDCLINICSTOP,SDPROVIDER)
. ;
. ; Event driver "AFTER" actions
. D AFTER^SDAMEVT(.SDATA,DFN,SDECSTART,SDCLINICIEN,SDDA,SDCIHDL) ;
. ;
. ; Execute event driver. 4=check in (see #409.66), 2=non-interactive
. ;
. D EVT^SDAMEVT(.SDATA,4,2,SDCIHDL)
. Q
;
Q
;
SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER,SDACHAUDIT) ;
N SDECFDA,SDECMSG
S SDECIENS=SDAPPTIEN_","
S SDECFDA(409.84,SDECIENS,.03)=SDCHECKINDTTIM
S SDECFDA(409.84,SDECIENS,.04)=$S(SDCHECKINDTTIM'="":$$NOW^XLFDT,1:"")
S:$G(SDPROVIDER) SDECFDA(409.84,SDECIENS,.16)=SDPROVIDER
S:$G(SDACHAUDIT)'="" SDECFDA(409.84,SDECIENS,100)=SDACHAUDIT
D FILE^DIE("","SDECFDA","SDECMSG")
Q
;
FIND(DFN,APPTDTTM,CLINICIEN) ; -- return appt ifn for pat
; input: DFN := ifn of pat.
; APPTDTTM := appt d/t
; SDCL := ifn of clinic
; output: [returned] := ifn if pat has appt on date/time
;
N CLNAPPTIEN,FND,APPTIEN
S CLNAPPTIEN=99999
S APPTIEN=0
S FND=0
F S CLNAPPTIEN=$O(^SC(CLINICIEN,"S",APPTDTTM,1,CLNAPPTIEN),-1) Q:('CLNAPPTIEN)!(FND) D
. I $D(^SC(CLINICIEN,"S",APPTDTTM,1,CLNAPPTIEN,0)) D
. . I DFN=+^SC(CLINICIEN,"S",APPTDTTM,1,CLNAPPTIEN,0) D
. . . I $D(^DPT(+DFN,"S",APPTDTTM,0)) D
. . . . I $$VALID(DFN,CLINICIEN,APPTDTTM,CLNAPPTIEN) D
. . . . . S FND=1
. . . . . S APPTIEN=CLNAPPTIEN
Q APPTIEN
;
APCHK(SDRESCLIN,DFN,SDCHECKINDTTIM,SDECSTART,SDDUZ,SDCLINSTOP,SDPROVIDER) ;
;Checkin appointment for patient DFN in clinic SDRESCLIN
;at time SDECSD
N BSDMSG,SDECC
S SDECC("PAT")=DFN
S SDECC("HOS LOC")=SDRESCLIN
S SDECC("CLINIC CODE")=SDCLINSTOP
S SDECC("PROVIDER")=SDPROVIDER
S SDECC("APPT DATE")=SDECSTART
S SDECC("CDT")=SDCHECKINDTTIM
S SDECC("USR")=$S(SDDUZ'="":SDDUZ,1:DUZ) ; DUZ
;Required by NEW API:
S SDECC("SRV CAT")="A"
S SDECC("TIME RANGE")=-1
S SDECC("VISIT DATE")=SDCHECKINDTTIM
S SDECC("SITE")=$$GETSITECODE(SDRESCLIN)
S SDECC("VISIT TYPE")="V"
S SDECC("CLN")=SDECC("HOS LOC")
S SDECC("ADT")=SDECC("APPT DATE")
;
N SDECOUT
D GETVISIT^SDES2GETVISIT(.SDECOUT,.SDECC)
Q
;
VALID(DFN,CLINICIEN,APPTDTTM,SDDA) ; -- return valid appt. 1 for valid appt., 0 for not valid
Q:($$GET1^DIQ(44.003,SDDA_","_APPTDTTM_","_CLINICIEN_",",310,"I")'="C") 1
Q:($$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",3,"I")["C") 1
Q 0
;
GETSITECODE(CLINICIEN) ; Get the SITE/INSTITUTION from the CLINIC IEN otherwise use DUZ(2)
N SDDIV,CLINICSITECODE
S SDDIV=$$GET1^DIQ(44,CLINICIEN_",",3.5,"I")
S CLINICSITECODE=$$GET1^DIQ(40.8,SDDIV_",",.07,"I")
Q $S(+CLINICSITECODE:CLINICSITECODE,1:DUZ(2))
;
BUILDERROR(RESULT,JSONRETURN) ;
N RETURNERROR
M RETURNERROR=RESULT
D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURNERROR)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2CHECKIN 6776 printed Dec 13, 2024@02:53:27 Page 2
SDES2CHECKIN ;ALB/LAB,TJB,JAS - SDES VISTA SCHEDULING SDES2 CHECKIN ;May 1,2024@10:00
+1 ;;5.3;Scheduling;**866,878**;Aug 13, 1993;Build 11
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 QUIT
+4 ; Copied from SDESCHECKIN to be in SDES2 namespace
+5 ; CHECKIN(SDRETURN,SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER) ;Check in appointment
CHECKIN(SDRETURN,SDCONTEXT,SDPARAM) ;Check in appointment
+1 ;INPUT -
+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("APPOINTMENT IEN")=IEN The appointment IEN from the SDES APPOINTMENT (#409.84) file. (required)
+9 ; SDPARAM("CHECKIN DATE TIME")=DATE ISO DATE and TIME to check-in the patient (required)
+10 ; SDPARAM("PROVIDER")=IEN IEN of the PROVIDER in file NEW PERSON (#200)
+11 ;
+12 ;RETURN PARMETER:
+13 ; {
+14 ; "Checkin":[
+15 ; "Checked In."
+16 ; ]
+17 ; }
+18 ;
+19 NEW BSDVSTN,EMSG,ERRORS,RETURN
+20 NEW SDECNOD,DFN,SDECSTART,DIK,DA,SDECID,SDECI,SDECIENS,SDECVEN,SDCLINICIEN
+21 NEW SDECNOEV,SDECCAN,SDRESOURCE,%DT,X,Y
+22 ;Don't execute protocol
SET SDECNOEV=1
+23 ;
+24 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+25 IF $DATA(ERRORS)
SET ERRORS("Checkin",1)=""
DO BUILDJSON^SDES2JSON(.SDRETURN,.ERRORS)
QUIT
+26 DO VALIDATEAPPT(.ERRORS,$GET(SDPARAM("APPOINTMENT IEN")))
+27 ;need clinic ien for checkin time conversion
if '$DATA(ERRORS)
DO ASSIGNCLININFO($GET(SDPARAM("APPOINTMENT IEN")),.SDCLINICIEN,.SDCLINSTOP)
+28 SET SDPARAM("CHECKIN DATE TIME")=$GET(SDPARAM("CHECKIN DATE TIME"))
+29 IF '$DATA(ERRORS)
SET SDPARAM("CHECKIN DATE TIME")=$$VALIDATECHKINDT(.ERRORS,SDPARAM("CHECKIN DATE TIME"),SDCLINICIEN)
+30 DO VALPROVIDER^SDES2VAL200(.ERRORS,$GET(SDPARAM("PROVIDER")))
+31 IF $DATA(ERRORS)
SET ERRORS("Checkin",1)=""
MERGE RETURN=ERRORS
+32 IF '$DATA(ERRORS)
Begin DoDot:1
+33 DO PROCESSCHECKIN(SDPARAM("APPOINTMENT IEN"),$GET(SDPARAM("PROVIDER")),SDCLINICIEN,$GET(SDCONTEXT("USER DUZ")),SDCLINSTOP,SDPARAM("CHECKIN DATE TIME"),$GET(SDCONTEXT("ACHERON AUDIT ID")),.ERRORS)
End DoDot:1
+34 IF '$DATA(ERRORS)
Begin DoDot:1
+35 SET RETURN("Checkin")="Checked in"
End DoDot:1
+36 DO BUILDJSON^SDES2JSON(.SDRETURN,.RETURN)
+37 QUIT
+38 ;
VALIDATEAPPT(ERRORS,SDAPPTIEN) ;validate SDEC appointment ID
+1 ;invalid appointment ID is error 15
+2 NEW RET
+3 DO VALFILEIEN^SDES2VALUTIL(.RET,.ERRORS,"409.84",SDAPPTIEN,1,,14,15)
+4 QUIT
+5 ;
VALIDATECHKINDT(ERRORS,SDCHECKINDTTIM,SDCLINICIEN) ;validate checkin date/time (required)
+1 ; need to change to accept ISO 8601 date/time
+2 SET SDCHECKINDTTIM=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(SDCHECKINDTTIM),SDCLINICIEN,1,21,22)
+3 QUIT SDCHECKINDTTIM
+4 ;
ASSIGNCLININFO(SDAPPTIEN,CLINICIEN,CLINICSTOP) ;
+1 SET CLINICIEN=$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I"),.04,"I")
+2 SET CLINICSTOP=$$GET1^DIQ(44,CLINICIEN,8,"I")
+3 QUIT
+4 ;
PROCESSCHECKIN(SDAPPTIEN,SDPROVIDER,SDCLINICIEN,SDDUZ,SDCLINICSTOP,SDCHECKINDTTIM,SDACHAUDIT,ERRORS) ;
+1 NEW DFN,SDECSTART,SDRESOURCE
+2 ; must use variable name DFN as it is needed to be defined for event logic.
SET DFN=$$GET1^DIQ(409.84,SDAPPTIEN,.05,"I")
+3 SET SDECSTART=$$GET1^DIQ(409.84,SDAPPTIEN,.01,"I")
+4 SET SDRESOURCE=$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I")
+5 ; Hospital Location is required for CHECKIN
+6 IF 'SDCLINICIEN]""
IF '$DATA(^SC(+SDCLINICIEN,0))
DO ERRLOG^SDES2JSON(.ERRORS,342)
QUIT
+7 IF SDRESOURCE]""
IF $DATA(^SDEC(409.831,SDRESOURCE,0))
Begin DoDot:1
+8 ;
+9 ; Event driver "BEFORE" actions
+10 ;
NEW SDATA,SDDA,SDCIHDL
+11 SET SDDA=$$FIND(DFN,SDECSTART,SDCLINICIEN)
+12 ;
SET SDATA=SDDA_U_DFN_U_SDECSTART_U_SDCLINICIEN
SET SDCIHDL=$$HANDLE^SDAMEVT(1)
+13 ;
DO BEFORE^SDAMEVT(.SDATA,DFN,SDECSTART,SDCLINICIEN,SDDA,SDCIHDL)
+14 ;
+15 ; Checkin SDEC APPOINTMENT entry
+16 ; sets field .03 (Checkin), in file 409.84
DO SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER,$GET(SDACHAUDIT))
+17 DO APCHK(SDCLINICIEN,DFN,SDCHECKINDTTIM,SDECSTART,SDDUZ,SDCLINICSTOP,SDPROVIDER)
+18 ;
+19 ; Event driver "AFTER" actions
+20 ;
DO AFTER^SDAMEVT(.SDATA,DFN,SDECSTART,SDCLINICIEN,SDDA,SDCIHDL)
+21 ;
+22 ; Execute event driver. 4=check in (see #409.66), 2=non-interactive
+23 ;
+24 DO EVT^SDAMEVT(.SDATA,4,2,SDCIHDL)
+25 QUIT
End DoDot:1
+26 ;
+27 QUIT
+28 ;
SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER,SDACHAUDIT) ;
+1 NEW SDECFDA,SDECMSG
+2 SET SDECIENS=SDAPPTIEN_","
+3 SET SDECFDA(409.84,SDECIENS,.03)=SDCHECKINDTTIM
+4 SET SDECFDA(409.84,SDECIENS,.04)=$SELECT(SDCHECKINDTTIM'="":$$NOW^XLFDT,1:"")
+5 if $GET(SDPROVIDER)
SET SDECFDA(409.84,SDECIENS,.16)=SDPROVIDER
+6 if $GET(SDACHAUDIT)'=""
SET SDECFDA(409.84,SDECIENS,100)=SDACHAUDIT
+7 DO FILE^DIE("","SDECFDA","SDECMSG")
+8 QUIT
+9 ;
FIND(DFN,APPTDTTM,CLINICIEN) ; -- return appt ifn for pat
+1 ; input: DFN := ifn of pat.
+2 ; APPTDTTM := appt d/t
+3 ; SDCL := ifn of clinic
+4 ; output: [returned] := ifn if pat has appt on date/time
+5 ;
+6 NEW CLNAPPTIEN,FND,APPTIEN
+7 SET CLNAPPTIEN=99999
+8 SET APPTIEN=0
+9 SET FND=0
+10 FOR
SET CLNAPPTIEN=$ORDER(^SC(CLINICIEN,"S",APPTDTTM,1,CLNAPPTIEN),-1)
if ('CLNAPPTIEN)!(FND)
QUIT
Begin DoDot:1
+11 IF $DATA(^SC(CLINICIEN,"S",APPTDTTM,1,CLNAPPTIEN,0))
Begin DoDot:2
+12 IF DFN=+^SC(CLINICIEN,"S",APPTDTTM,1,CLNAPPTIEN,0)
Begin DoDot:3
+13 IF $DATA(^DPT(+DFN,"S",APPTDTTM,0))
Begin DoDot:4
+14 IF $$VALID(DFN,CLINICIEN,APPTDTTM,CLNAPPTIEN)
Begin DoDot:5
+15 SET FND=1
+16 SET APPTIEN=CLNAPPTIEN
End DoDot:5
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+17 QUIT APPTIEN
+18 ;
APCHK(SDRESCLIN,DFN,SDCHECKINDTTIM,SDECSTART,SDDUZ,SDCLINSTOP,SDPROVIDER) ;
+1 ;Checkin appointment for patient DFN in clinic SDRESCLIN
+2 ;at time SDECSD
+3 NEW BSDMSG,SDECC
+4 SET SDECC("PAT")=DFN
+5 SET SDECC("HOS LOC")=SDRESCLIN
+6 SET SDECC("CLINIC CODE")=SDCLINSTOP
+7 SET SDECC("PROVIDER")=SDPROVIDER
+8 SET SDECC("APPT DATE")=SDECSTART
+9 SET SDECC("CDT")=SDCHECKINDTTIM
+10 ; DUZ
SET SDECC("USR")=$SELECT(SDDUZ'="":SDDUZ,1:DUZ)
+11 ;Required by NEW API:
+12 SET SDECC("SRV CAT")="A"
+13 SET SDECC("TIME RANGE")=-1
+14 SET SDECC("VISIT DATE")=SDCHECKINDTTIM
+15 SET SDECC("SITE")=$$GETSITECODE(SDRESCLIN)
+16 SET SDECC("VISIT TYPE")="V"
+17 SET SDECC("CLN")=SDECC("HOS LOC")
+18 SET SDECC("ADT")=SDECC("APPT DATE")
+19 ;
+20 NEW SDECOUT
+21 DO GETVISIT^SDES2GETVISIT(.SDECOUT,.SDECC)
+22 QUIT
+23 ;
VALID(DFN,CLINICIEN,APPTDTTM,SDDA) ; -- return valid appt. 1 for valid appt., 0 for not valid
+1 if ($$GET1^DIQ(44.003,SDDA_","_APPTDTTM_","_CLINICIEN_",",310,"I")'="C")
QUIT 1
+2 if ($$GET1^DIQ(2.98,APPTDTTM_","_DFN_",",3,"I")["C")
QUIT 1
+3 QUIT 0
+4 ;
GETSITECODE(CLINICIEN) ; Get the SITE/INSTITUTION from the CLINIC IEN otherwise use DUZ(2)
+1 NEW SDDIV,CLINICSITECODE
+2 SET SDDIV=$$GET1^DIQ(44,CLINICIEN_",",3.5,"I")
+3 SET CLINICSITECODE=$$GET1^DIQ(40.8,SDDIV_",",.07,"I")
+4 QUIT $SELECT(+CLINICSITECODE:CLINICSITECODE,1:DUZ(2))
+5 ;
BUILDERROR(RESULT,JSONRETURN) ;
+1 NEW RETURNERROR
+2 MERGE RETURNERROR=RESULT
+3 DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURNERROR)
+4 QUIT
+5 ;