SDESPRINTPATAPPT ;ALB/LAB,MGD - SDES Print basic appointments ;July 5, 2022
;;5.3;Scheduling;**813,820**;Aug 13, 1993;Build 10
;;Per VHA Directive 6402, this routine should not be modified
;
; SDDFN (REQUIRED) = DFN OF THE PATIENT
Q
;
PRINTPATAPPTS(SDPATIENTAPPTS,SDDFN,SDBEG,SDEND,EAS) ; PRINT PATIENT APPOINTMENTS
N HASDFNERRORS,HASBEGDTERRORS,HASENDDTERRORS,HASERRORS,HASEASERRORS,ERRORS,SDAPPOINTARRAY,PRINTFIELDS,RETURN
S (RETURN,HASERRORS,PRINTFIELDS)=""
;
S HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,SDDFN)
I HASDFNERRORS M RETURN=ERRORS
;
S HASBEGDTERRORS=$$VALIDATEBEGDT(.ERRORS,SDBEG)
I HASBEGDTERRORS M RETURN=ERRORS
;
S HASENDDTERRORS=$$VALIDATEENDDT(.ERRORS,SDEND)
I HASENDDTERRORS M RETURN=ERRORS
;
S HASEASERRORS=$$VALIDATEEAS(.ERRORS,EAS)
I HASEASERRORS M RETURN=ERRORS
;
I '$D(ERRORS) D
. S PRINTFIELDS=$$GETAPPOINTMENTS(.SDAPPOINTARRAY,SDDFN,SDBEG,SDEND)
. I PRINTFIELDS M RETURN=SDAPPOINTARRAY
;
D BUILDJSON(.SDPATIENTAPPTS,.RETURN)
Q
;
VALIDATEPTDFN(ERRORS,SDDFN) ;Validate Patient DFN
N ERRORFLAG
I SDDFN="" D
.S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,1)
.S RETURN("PatientAppointments",1)=""
I SDDFN'="",('$D(^DPT(SDDFN,0))) D
.S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,2)
.S RETURN("PatientAppointments",1)=""
Q $D(ERRORFLAG)
;
VALIDATEBEGDT(ERRORS,SDBEG) ;Validate Begin date - converted in SDES so -1 if invalid
N ERRORFLAG
I SDBEG=-1 D
.S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,11)
.S RETURN("PatientAppointments",1)=""
Q $D(ERRORFLAG)
;
VALIDATEENDDT(ERRORS,SDEND) ;validate End date - converted in SDES so -1 if invalid
N ERRORFLAG
I SDEND=-1 D
.S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,12)
.S RETURN("PatientAppointments",1)=""
Q $D(ERRORFLAG)
;
VALIDATEEAS(ERRORS,EAS) ;Validate EAS Tracking number
N ERRORFLAG
S EAS=$G(EAS,"")
I $L(EAS) S EAS=$$EASVALIDATE^SDESUTIL(EAS)
I EAS=-1 D
.S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,142)
.S RETURN("PatientAppointments",1)=""
Q $D(ERRORFLAG)
;
GETAPPOINTMENTS(SDPATIENTAPPTS,SDDFN,SDBEGIN,SDEND) ;select appointments
N SDAPPTIEN,DISPLAY,SDCANCELDT,COUNT,SDRESOURCE,SDAPPTDTTIM,SDAPPTDTTIME,SDTIMEZONE,SDCLINIC,SDRESOURCENAME
N SDNOSHOWDT
S SDAPPTIEN=0,DISPLAY=1,SDCANCELDT="",COUNT=0
F S SDAPPTIEN=$O(^SDEC(409.84,"CPAT",SDDFN,SDAPPTIEN)) Q:SDAPPTIEN="" D
. S SDAPPTDTTIM=$$GET1^DIQ(409.84,SDAPPTIEN,.01,"I")
. Q:(SDBEGIN>SDAPPTDTTIM)!(SDAPPTDTTIM>SDEND)
. ;
. S SDCANCELDT=$$GET1^DIQ(409.84,SDAPPTIEN,.12,"I")
. S SDNOSHOWDT=$$GET1^DIQ(409.84,SDAPPTIEN,.101,"I")
. Q:(+SDCANCELDT)!(+SDNOSHOWDT)
. ;
. S SDRESOURCE=$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I")
. S SDCLINIC=$$GET1^DIQ(409.831,SDRESOURCE,.04,"I")
. S DISPLAY=$$GET1^DIQ(44,SDCLINIC,62,"I")
. Q:(DISPLAY'="Y")
. ;
. S SDTIMEZONE=$$TIMEZONEDATA^SDESUTIL($G(SDCLINIC)),SDTIMEZONE=$P($G(SDTIMEZONE),U)
. S SDRESOURCENAME=$$GET1^DIQ(409.84,SDAPPTIEN,.07,"E")
. S SDAPPTDTTIME=$$FMTISO^SDAMUTDT(SDAPPTDTTIM,SDCLINIC)
. ;
. S COUNT=COUNT+1
. S SDPATIENTAPPTS("PatientAppointments",COUNT,"AppointDateTime")=SDAPPTDTTIME
. S SDPATIENTAPPTS("PatientAppointments",COUNT,"TimeZone")=SDTIMEZONE
. S SDPATIENTAPPTS("PatientAppointments",COUNT,"Clinic")=SDRESOURCENAME
I COUNT=0 D
. S SDPATIENTAPPTS("PatientAppointments",1)=""
. S COUNT=1
Q COUNT
;
BUILDJSON(JSONRETURN,INPUT) ;
N JSONERROR
S JSONERROR=""
D ENCODE^XLFJSON("INPUT","JSONRETURN","JSONERROR")
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESPRINTPATAPPT 3457 printed Oct 16, 2024@18:57:57 Page 2
SDESPRINTPATAPPT ;ALB/LAB,MGD - SDES Print basic appointments ;July 5, 2022
+1 ;;5.3;Scheduling;**813,820**;Aug 13, 1993;Build 10
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; SDDFN (REQUIRED) = DFN OF THE PATIENT
+5 QUIT
+6 ;
PRINTPATAPPTS(SDPATIENTAPPTS,SDDFN,SDBEG,SDEND,EAS) ; PRINT PATIENT APPOINTMENTS
+1 NEW HASDFNERRORS,HASBEGDTERRORS,HASENDDTERRORS,HASERRORS,HASEASERRORS,ERRORS,SDAPPOINTARRAY,PRINTFIELDS,RETURN
+2 SET (RETURN,HASERRORS,PRINTFIELDS)=""
+3 ;
+4 SET HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,SDDFN)
+5 IF HASDFNERRORS
MERGE RETURN=ERRORS
+6 ;
+7 SET HASBEGDTERRORS=$$VALIDATEBEGDT(.ERRORS,SDBEG)
+8 IF HASBEGDTERRORS
MERGE RETURN=ERRORS
+9 ;
+10 SET HASENDDTERRORS=$$VALIDATEENDDT(.ERRORS,SDEND)
+11 IF HASENDDTERRORS
MERGE RETURN=ERRORS
+12 ;
+13 SET HASEASERRORS=$$VALIDATEEAS(.ERRORS,EAS)
+14 IF HASEASERRORS
MERGE RETURN=ERRORS
+15 ;
+16 IF '$DATA(ERRORS)
Begin DoDot:1
+17 SET PRINTFIELDS=$$GETAPPOINTMENTS(.SDAPPOINTARRAY,SDDFN,SDBEG,SDEND)
+18 IF PRINTFIELDS
MERGE RETURN=SDAPPOINTARRAY
End DoDot:1
+19 ;
+20 DO BUILDJSON(.SDPATIENTAPPTS,.RETURN)
+21 QUIT
+22 ;
VALIDATEPTDFN(ERRORS,SDDFN) ;Validate Patient DFN
+1 NEW ERRORFLAG
+2 IF SDDFN=""
Begin DoDot:1
+3 SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,1)
+4 SET RETURN("PatientAppointments",1)=""
End DoDot:1
+5 IF SDDFN'=""
IF ('$DATA(^DPT(SDDFN,0)))
Begin DoDot:1
+6 SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,2)
+7 SET RETURN("PatientAppointments",1)=""
End DoDot:1
+8 QUIT $DATA(ERRORFLAG)
+9 ;
VALIDATEBEGDT(ERRORS,SDBEG) ;Validate Begin date - converted in SDES so -1 if invalid
+1 NEW ERRORFLAG
+2 IF SDBEG=-1
Begin DoDot:1
+3 SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,11)
+4 SET RETURN("PatientAppointments",1)=""
End DoDot:1
+5 QUIT $DATA(ERRORFLAG)
+6 ;
VALIDATEENDDT(ERRORS,SDEND) ;validate End date - converted in SDES so -1 if invalid
+1 NEW ERRORFLAG
+2 IF SDEND=-1
Begin DoDot:1
+3 SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,12)
+4 SET RETURN("PatientAppointments",1)=""
End DoDot:1
+5 QUIT $DATA(ERRORFLAG)
+6 ;
VALIDATEEAS(ERRORS,EAS) ;Validate EAS Tracking number
+1 NEW ERRORFLAG
+2 SET EAS=$GET(EAS,"")
+3 IF $LENGTH(EAS)
SET EAS=$$EASVALIDATE^SDESUTIL(EAS)
+4 IF EAS=-1
Begin DoDot:1
+5 SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,142)
+6 SET RETURN("PatientAppointments",1)=""
End DoDot:1
+7 QUIT $DATA(ERRORFLAG)
+8 ;
GETAPPOINTMENTS(SDPATIENTAPPTS,SDDFN,SDBEGIN,SDEND) ;select appointments
+1 NEW SDAPPTIEN,DISPLAY,SDCANCELDT,COUNT,SDRESOURCE,SDAPPTDTTIM,SDAPPTDTTIME,SDTIMEZONE,SDCLINIC,SDRESOURCENAME
+2 NEW SDNOSHOWDT
+3 SET SDAPPTIEN=0
SET DISPLAY=1
SET SDCANCELDT=""
SET COUNT=0
+4 FOR
SET SDAPPTIEN=$ORDER(^SDEC(409.84,"CPAT",SDDFN,SDAPPTIEN))
if SDAPPTIEN=""
QUIT
Begin DoDot:1
+5 SET SDAPPTDTTIM=$$GET1^DIQ(409.84,SDAPPTIEN,.01,"I")
+6 if (SDBEGIN>SDAPPTDTTIM)!(SDAPPTDTTIM>SDEND)
QUIT
+7 ;
+8 SET SDCANCELDT=$$GET1^DIQ(409.84,SDAPPTIEN,.12,"I")
+9 SET SDNOSHOWDT=$$GET1^DIQ(409.84,SDAPPTIEN,.101,"I")
+10 if (+SDCANCELDT)!(+SDNOSHOWDT)
QUIT
+11 ;
+12 SET SDRESOURCE=$$GET1^DIQ(409.84,SDAPPTIEN,.07,"I")
+13 SET SDCLINIC=$$GET1^DIQ(409.831,SDRESOURCE,.04,"I")
+14 SET DISPLAY=$$GET1^DIQ(44,SDCLINIC,62,"I")
+15 if (DISPLAY'="Y")
QUIT
+16 ;
+17 SET SDTIMEZONE=$$TIMEZONEDATA^SDESUTIL($GET(SDCLINIC))
SET SDTIMEZONE=$PIECE($GET(SDTIMEZONE),U)
+18 SET SDRESOURCENAME=$$GET1^DIQ(409.84,SDAPPTIEN,.07,"E")
+19 SET SDAPPTDTTIME=$$FMTISO^SDAMUTDT(SDAPPTDTTIM,SDCLINIC)
+20 ;
+21 SET COUNT=COUNT+1
+22 SET SDPATIENTAPPTS("PatientAppointments",COUNT,"AppointDateTime")=SDAPPTDTTIME
+23 SET SDPATIENTAPPTS("PatientAppointments",COUNT,"TimeZone")=SDTIMEZONE
+24 SET SDPATIENTAPPTS("PatientAppointments",COUNT,"Clinic")=SDRESOURCENAME
End DoDot:1
+25 IF COUNT=0
Begin DoDot:1
+26 SET SDPATIENTAPPTS("PatientAppointments",1)=""
+27 SET COUNT=1
End DoDot:1
+28 QUIT COUNT
+29 ;
BUILDJSON(JSONRETURN,INPUT) ;
+1 NEW JSONERROR
+2 SET JSONERROR=""
+3 DO ENCODE^XLFJSON("INPUT","JSONRETURN","JSONERROR")
+4 QUIT
+5 ;