SDESCHECKIN ;ALB/LAB - SDES VISTA SCHEDULING RPCS CHECK IN APPOINTMENT ;Sep 14,2022@16:15
;;5.3;Scheduling;**827**;Aug 13, 1993;Build 10
;
Q
;
CHECKIN(SDRETURN,SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER) ;Check in appointment
;
N BSDVSTN,EMSG,ERRORS,RETURN
N SDECNOD,DFN,SDECSTART,DIK,DA,SDECID,SDECI,SDECIENS,SDECVEN
N SDECNOEV,SDECCAN,SDRESOURCE,%DT,X,Y
S SDECNOEV=1 ;Don't execute protocol
;
D VALIDATEAPPT(.ERRORS,.SDAPPTIEN)
D:'$D(ERRORS) ASSIGNCLININFO(SDAPPTIEN,.SDCLINICIEN,.SDCLINSTOP) ;need clinic ien for checkin time conversion
D:'$D(ERRORS) VALIDATECHKINDT(.ERRORS,.SDCHECKINDTTIM,SDAPPTIEN,SDCLINICIEN)
D VALIDATEPROV(.ERRORS,.SDPROVIDER)
I $D(ERRORS) M RETURN=ERRORS
I '$D(ERRORS) D
. D PROCESSCHECKIN(SDAPPTIEN,SDPROVIDER,.ERRORS)
I '$D(ERRORS) D
. S RETURN("Checkin")="Checked in"
D BUILDJSON^SDESBUILDJSON(.SDRETURN,.RETURN)
Q
;
VALIDATEAPPT(ERRORS,SDAPPTIEN) ;validate SDEC appointment ID
;invalid appointment ID is error 15
I '$G(SDAPPTIEN) D ERRLOG^SDESJSON(.ERRORS,14) Q
I '$D(^SDEC(409.84,SDAPPTIEN,0)) D ERRLOG^SDESJSON(.ERRORS,15)
Q
;
VALIDATECHKINDT(ERRORS,SDCHECKINDTTIM,SDAPPTIEN,SDCLINICIEN) ;validate checkin date/time (required)
; need to change to accept ISO 8601 date/time
S SDCHECKINDTTIM=$G(SDCHECKINDTTIM)
I SDCHECKINDTTIM="" D ERRLOG^SDESJSON(.ERRORS,21) Q
S SDCHECKINDTTIM=$$ISOTFM^SDAMUTDT(SDCHECKINDTTIM,SDCLINICIEN)
I SDCHECKINDTTIM=-1 D ERRLOG^SDESJSON(.ERRORS,22)
Q
;
ASSIGNCLININFO(SDAPPTIEN,SDCLINICIEN,SDCLINSTOP) ;
S SDCLINICIEN=$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I"),.04,"I")
S SDCLINSTOP=$$GET1^DIQ(44,SDCLINICIEN,8,"I")
Q
;
VALIDATEPROV(ERRORS,SDPROVIDER) ;validate provider (optional)
S SDPROVIDER=$G(SDPROVIDER)
I SDPROVIDER'="" I '$D(^VA(200,+SDPROVIDER,0)) D ERRLOG^SDESJSON(.ERRORS,54)
Q
;
PROCESSCHECKIN(SDAPPTIEN,SDPROVIDER,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")
I SDRESOURCE]"",$D(^SDEC(409.831,SDRESOURCE,0)) D
. S SDRESCLIN=$$GET1^DIQ(409.831,SDRESOURCE,.04,"I")
. ;Hospital Location is required for CHECKIN
. I 'SDRESCLIN]"",'$D(^SC(+SDRESCLIN,0)) D ERRLOG^SDESJSON(.ERRORS,342) Q
. ;
. ; Event driver "BEFORE" actions
. ;
. N SDATA,SDDA,SDCIHDL ;
. S SDDA=$$FIND(DFN,SDECSTART,SDRESCLIN)
. S SDATA=SDDA_U_DFN_U_SDECSTART_U_SDRESCLIN,SDCIHDL=$$HANDLE^SDAMEVT(1) ;
. D BEFORE^SDAMEVT(.SDATA,DFN,SDECSTART,SDRESCLIN,SDDA,SDCIHDL) ;
. ;
. ; Checkin SDEC APPOINTMENT entry
. ;
. D SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER) ; sets field .03 (Checkin), in file 409.84
. D APCHK(SDRESCLIN,DFN,SDCHECKINDTTIM,SDECSTART)
. ;
. ; Event driver "AFTER" actions
. ;
. D AFTER^SDAMEVT(.SDATA,DFN,SDECSTART,SDRESCLIN,SDDA,SDCIHDL) ;
. ;
. ; Execute event driver. 4=check in (see #409.66), 2=non-interactive
. ;
. D EVT^SDAMEVT(.SDATA,4,2,SDCIHDL)
. I $D(ERRORS) M RETURN=ERRORS
;
Q
;
SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER) ;
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
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) ;
;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")=DUZ
;Required by NEW API:
S SDECC("SRV CAT")="A"
S SDECC("TIME RANGE")=-1
S SDECC("VISIT DATE")=SDCHECKINDTTIM
S SDECC("SITE")=$G(DUZ(2))
S SDECC("VISIT TYPE")="V"
S SDECC("CLN")=SDECC("HOS LOC")
S SDECC("ADT")=SDECC("APPT DATE")
;
N SDECOUT
D GETVISIT^SDECAPI4(.SDECC,.SDECOUT)
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
;
BUILDERROR(RESULT,JSONRETURN) ;
NEW RETURNERROR
M RETURNERROR=RESULT
D BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURNERROR)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESCHECKIN 5163 printed Nov 22, 2024@18:05:55 Page 2
SDESCHECKIN ;ALB/LAB - SDES VISTA SCHEDULING RPCS CHECK IN APPOINTMENT ;Sep 14,2022@16:15
+1 ;;5.3;Scheduling;**827**;Aug 13, 1993;Build 10
+2 ;
+3 QUIT
+4 ;
CHECKIN(SDRETURN,SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER) ;Check in appointment
+1 ;
+2 NEW BSDVSTN,EMSG,ERRORS,RETURN
+3 NEW SDECNOD,DFN,SDECSTART,DIK,DA,SDECID,SDECI,SDECIENS,SDECVEN
+4 NEW SDECNOEV,SDECCAN,SDRESOURCE,%DT,X,Y
+5 ;Don't execute protocol
SET SDECNOEV=1
+6 ;
+7 DO VALIDATEAPPT(.ERRORS,.SDAPPTIEN)
+8 ;need clinic ien for checkin time conversion
if '$DATA(ERRORS)
DO ASSIGNCLININFO(SDAPPTIEN,.SDCLINICIEN,.SDCLINSTOP)
+9 if '$DATA(ERRORS)
DO VALIDATECHKINDT(.ERRORS,.SDCHECKINDTTIM,SDAPPTIEN,SDCLINICIEN)
+10 DO VALIDATEPROV(.ERRORS,.SDPROVIDER)
+11 IF $DATA(ERRORS)
MERGE RETURN=ERRORS
+12 IF '$DATA(ERRORS)
Begin DoDot:1
+13 DO PROCESSCHECKIN(SDAPPTIEN,SDPROVIDER,.ERRORS)
End DoDot:1
+14 IF '$DATA(ERRORS)
Begin DoDot:1
+15 SET RETURN("Checkin")="Checked in"
End DoDot:1
+16 DO BUILDJSON^SDESBUILDJSON(.SDRETURN,.RETURN)
+17 QUIT
+18 ;
VALIDATEAPPT(ERRORS,SDAPPTIEN) ;validate SDEC appointment ID
+1 ;invalid appointment ID is error 15
+2 IF '$GET(SDAPPTIEN)
DO ERRLOG^SDESJSON(.ERRORS,14)
QUIT
+3 IF '$DATA(^SDEC(409.84,SDAPPTIEN,0))
DO ERRLOG^SDESJSON(.ERRORS,15)
+4 QUIT
+5 ;
VALIDATECHKINDT(ERRORS,SDCHECKINDTTIM,SDAPPTIEN,SDCLINICIEN) ;validate checkin date/time (required)
+1 ; need to change to accept ISO 8601 date/time
+2 SET SDCHECKINDTTIM=$GET(SDCHECKINDTTIM)
+3 IF SDCHECKINDTTIM=""
DO ERRLOG^SDESJSON(.ERRORS,21)
QUIT
+4 SET SDCHECKINDTTIM=$$ISOTFM^SDAMUTDT(SDCHECKINDTTIM,SDCLINICIEN)
+5 IF SDCHECKINDTTIM=-1
DO ERRLOG^SDESJSON(.ERRORS,22)
+6 QUIT
+7 ;
ASSIGNCLININFO(SDAPPTIEN,SDCLINICIEN,SDCLINSTOP) ;
+1 SET SDCLINICIEN=$$GET1^DIQ(409.831,$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I"),.04,"I")
+2 SET SDCLINSTOP=$$GET1^DIQ(44,SDCLINICIEN,8,"I")
+3 QUIT
+4 ;
VALIDATEPROV(ERRORS,SDPROVIDER) ;validate provider (optional)
+1 SET SDPROVIDER=$GET(SDPROVIDER)
+2 IF SDPROVIDER'=""
IF '$DATA(^VA(200,+SDPROVIDER,0))
DO ERRLOG^SDESJSON(.ERRORS,54)
+3 QUIT
+4 ;
PROCESSCHECKIN(SDAPPTIEN,SDPROVIDER,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 IF SDRESOURCE]""
IF $DATA(^SDEC(409.831,SDRESOURCE,0))
Begin DoDot:1
+6 SET SDRESCLIN=$$GET1^DIQ(409.831,SDRESOURCE,.04,"I")
+7 ;Hospital Location is required for CHECKIN
+8 IF 'SDRESCLIN]""
IF '$DATA(^SC(+SDRESCLIN,0))
DO ERRLOG^SDESJSON(.ERRORS,342)
QUIT
+9 ;
+10 ; Event driver "BEFORE" actions
+11 ;
+12 ;
NEW SDATA,SDDA,SDCIHDL
+13 SET SDDA=$$FIND(DFN,SDECSTART,SDRESCLIN)
+14 ;
SET SDATA=SDDA_U_DFN_U_SDECSTART_U_SDRESCLIN
SET SDCIHDL=$$HANDLE^SDAMEVT(1)
+15 ;
DO BEFORE^SDAMEVT(.SDATA,DFN,SDECSTART,SDRESCLIN,SDDA,SDCIHDL)
+16 ;
+17 ; Checkin SDEC APPOINTMENT entry
+18 ;
+19 ; sets field .03 (Checkin), in file 409.84
DO SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER)
+20 DO APCHK(SDRESCLIN,DFN,SDCHECKINDTTIM,SDECSTART)
+21 ;
+22 ; Event driver "AFTER" actions
+23 ;
+24 ;
DO AFTER^SDAMEVT(.SDATA,DFN,SDECSTART,SDRESCLIN,SDDA,SDCIHDL)
+25 ;
+26 ; Execute event driver. 4=check in (see #409.66), 2=non-interactive
+27 ;
+28 DO EVT^SDAMEVT(.SDATA,4,2,SDCIHDL)
+29 IF $DATA(ERRORS)
MERGE RETURN=ERRORS
End DoDot:1
+30 ;
+31 QUIT
+32 ;
SDECCHK(SDAPPTIEN,SDCHECKINDTTIM,SDPROVIDER) ;
+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 DO FILE^DIE("","SDECFDA","SDECMSG")
+7 QUIT
+8 ;
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) ;
+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 SET SDECC("USR")=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")=$GET(DUZ(2))
+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^SDECAPI4(.SDECC,.SDECOUT)
+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 ;
BUILDERROR(RESULT,JSONRETURN) ;
+1 NEW RETURNERROR
+2 MERGE RETURNERROR=RESULT
+3 DO BUILDJSON^SDESBUILDJSON(.JSONRETURN,.RETURNERROR)
+4 QUIT
+5 ;