SDESGETAPPTWRAP ;ALB/RRM - RPC WRAPPER FOR VIEWING AN APPOINTMENT ;APR 12, 2022@13:47
;;5.3;Scheduling;**814**;Aug 13, 1993;Build 11
;;Per VHA Directive 6402, this routine should not be modified
;
;
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.
;
;This is the entry point to retrieve appointments from (not in particular order):
; - HOSPITAL LOCATION File #44
; - PATIENT File #2, and
; - SDEC APPOINTMENT File #409.84
;
; Called from the following RPC:
; - SDES GET APPTS BY CLINIC #44
; - SDES GET APPTS BY DFN #2
GETAPPTS(RETURNJSON,SDPOINTERIEN,SDBEGDATE,SDENDDATE) ;
;
; Input:
; SDPOINTERIEN [Required] = This can be a patient's DFN from PATIENT File #2 or the Internal Entry Number (IEN) from HOSPITAL LOCATION FILE #44.
; SDBEGDATE [Required] = The beginning date/time in ISO8601 Time Format for the search.
; SDENDDATE [Required] = The ending date/time in ISO8601 Time Format for the search.
;
; Output:
; RETURNJSON = Returns fields from the (not in particular order) HOSPITAL LOCATION File #44, PATIENT File #2, and SDEC APPOINTMENT File #409.84
; in JSON format. JSON Errors will be returned for any invalid/missing parameters.
;
N ERRORS,RETURNERROR ;temp data storage for input validation error
N SDAPPT40984 ;temp data storage for File #409.84
N SDAPPT44 ;temp data storage for File #44
N SDAPPTMULT2 ;temp data storage for Appointment Multiple File #2
N SDALLAPPTARY ;temp data storage for all records found in the HOSPITAL LOCATION File #44, PATIENT File #2, and SDEC APPOINTMENT File #409.84
N SDDFN,SDCLINICIEN,HASDFNERRORS,HASCLINIENERRORS,HASBEGDATEERRORS,HASENDDATEERRORS
;
;NOTE: Ensure that before calling this routine the SDVIEWAPPTBY variable is set to either 0 OR 1
; 0 - View Appointment using DFN
; 1 - View Appointment using CLINIC IEN
;
S ERRORFLAG=0
;Input parameters validation begins here
I $G(SDVIEWAPPTBY)=0 D ;DFN input parameter validation
. S SDDFN=SDPOINTERIEN
. S HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,SDDFN)
. I HASDFNERRORS M RETURNERROR=ERRORS
;
I $G(SDVIEWAPPTBY)=1 D ;CLINIC IEN input parameter validation
. S SDCLINICIEN=SDPOINTERIEN
. S HASCLINIENERRORS=$$VALIDATECLINIC(.ERRORS,SDCLINICIEN)
. I HASCLINIENERRORS M RETURNERROR=ERRORS
;
;convert beginning and ending date time to Fileman Format
S:$G(SDBEGDATE)'="" SDBEGDATE=$$ISOTFM^SDAMUTDT(SDBEGDATE)
S:$G(SDENDDATE)'="" SDENDDATE=$$ISOTFM^SDAMUTDT(SDENDDATE)
;
S HASBEGDATEERRORS=$$VALIDATEBEGDATE(.ERRORS,SDBEGDATE) ;SDBEGDATE input parameter validation
I HASBEGDATEERRORS M RETURNERROR=ERRORS
;
S HASENDDATEERRORS=$$VALIDATEENDDATE(.ERRORS,SDENDDATE) ;SDENDDATE input parameter validation
I HASENDDATEERRORS M RETURNERROR=ERRORS
;Input parameters validation ends here
;
I $O(RETURNERROR("Error",""))'="" D BUILDJSON(.RETURNERROR,.RETURNJSON) Q ;do not continue processing if errors are detected
;
K RETURNJSON,SDAPPT40984,SDAPPT44,SDAPPTMULT2 ;always clear returned data to ensure a new array of data are returned
;
I $G(SDVIEWAPPTBY)=0 D GETAPPTBYDFN(SDDFN,SDBEGDATE,SDENDDATE) ;view appointment using DFN of the patient
I $G(SDVIEWAPPTBY)=1 D GETAPPTBYCLIN(SDCLINICIEN,SDBEGDATE,SDENDDATE) ;view appointment using Clinic IEN
;
;Merge the three retrieved appointments into one big array
D MERGEALLAPPT(.SDALLAPPTARY,.SDAPPT40984,.SDAPPT44,.SDAPPTMULT2)
;
D BUILDJSON(.SDALLAPPTARY,.RETURNJSON)
D CLEANUP
Q
;
VALIDATEPTDFN(ERRORS,SDDFN) ;Validate patient DFN
N ERRORFLAG
S ERRORFLAG=$$VALIDATEPTDFN^SDESGETPATAPPT(.ERRORS,SDDFN)
Q ERRORFLAG
;
VALIDATECLINIC(ERRORS,SDCLINICIEN) ;Validate Clinic
N ERRORFLAG
S ERRORFLAG=$$VALIDATECLINIC^SDESGETPATAPPT(.ERRORS,SDCLINICIEN)
Q ERRORFLAG
;
VALIDATEBEGDATE(ERRORS,SDBEGDATE) ;Validate Beginning Date
N ERRORFLAG
I $G(SDBEGDATE)="" D ERRLOG^SDESJSON(.ERRORS,25) S ERRORFLAG=1 Q ERRORFLAG
S ERRORFLAG=$$VALIDATEBEGDT^SDESPRINTPATAPPT(.ERRORS,SDBEGDATE)
Q ERRORFLAG
;
VALIDATEENDDATE(ERRORS,SDENDDATE) ;Validate ENding Date
N ERRORFLAG
I SDENDDATE="" D ERRLOG^SDESJSON(.ERRORS,26) S ERRORFLAG=1 Q ERRORFLAG
S ERRORFLAG=$$VALIDATEENDDT^SDESPRINTPATAPPT(.ERRORS,SDENDDATE)
Q ERRORFLAG
;
GETAPPTBYDFN(DFN,SDBEG,SDEND) ;View Appointment using DFN of the patient
N SDCLINICARY
D GETAPPT40984(DFN,SDBEG,SDEND) ;retrieves appointment from File #409.84
;SDCLINICARY is set while retrieving the appointments from File #409.84 in GETAPPT40984 line tag
D LOOPCLINICARY(.SDCLINICARY,SDBEG,SDEND) ;retrieves appointment from File #44
D GETAPPT2(DFN,SDBEG,SDEND) ;retrieves appointment from Appointment Multiple Patient File #2
Q
;
GETAPPTBYCLIN(SDCLINICIEN,SDBEGDATE,SDENDDATE) ;View Appointment using Clinic IEN
N PATDFNARY
D GETAPPT44(SDCLINICIEN,SDBEGDATE,SDENDDATE) ;Retrieves appointments in File #44
;PATDFNARY array is created while retrieving appointments from File #44 in GETAPPT44 line tag
;PATDFNARY will be use to retrieve appointments from Appointment Multiple PATIENT File #2 and File #409.84
I $D(PATDFNARY) D
. S DFN="" F S DFN=$O(PATDFNARY(DFN)) Q:DFN="" D
. . D GETAPPT40984(DFN,SDBEGDATE,SDENDDATE) ;retrieves appointment from File #409.84
. . D GETAPPT2(DFN,SDBEGDATE,SDENDDATE) ;retrieve appointments from Appointment Multiple PATIENT File #2
Q
;
GETAPPT40984(DFN,BDATE,EDATE) ;Traverse the "CPAT" cross reference in File #409.84 to retrieve appointments for a given datetime range
N APPTIEN,APPTDATA,RECNUM,CLINICIEN
S RECNUM=0
S APPTIEN=0 F S APPTIEN=$O(^SDEC(409.84,"CPAT",DFN,APPTIEN)) Q:'APPTIEN D
. K SDMSG
. I '$$APPTINDTRANGE^SDESAPPT(APPTIEN,BDATE,EDATE) Q
. D SUMMARY^SDESAPPTDATA(.APPTDATA,APPTIEN)
. I $G(SDVIEWAPPTBY)=1,$G(APPTDATA("Resource","ClinicIEN"))'=SDCLINICIEN Q ;if view appointment by Clinic IEN, we are only interested of those Clinic IEN passed in
. S RECNUM=RECNUM+1
. S APPTDATA("AppointmentType")=$$GET1^DIQ(409.84,APPTIEN_",",.06)
. I $D(APPTDATA) D
. . M SDAPPT40984("PatientAppt","File#409.84",RECNUM)=APPTDATA
. . I $G(SDVIEWAPPTBY)=0 D
. . . S CLINICIEN=$G(APPTDATA("Resource","ClinicIEN"))
. . . I $G(CLINICIEN)'="" S SDCLINICARY(CLINICIEN)="" ;this will use later when retrieving the appointments in File #44
I $O(SDAPPT40984("PatientAppt","File#409.84",""))="" S SDAPPT40984("PatientAppt","File#409.84")="" ;if no record found, set the array into a null value
Q
;
LOOPCLINICARY(SDCLINICARY,SDBEG,SDEND) ;Retrieve appointments from File #44
N CLINICIEN
S CLINICIEN="" F S CLINICIEN=$O(SDCLINICARY(CLINICIEN)) Q:CLINICIEN="" D GETAPPT44(CLINICIEN,SDBEG,SDEND)
Q
;
GETAPPT44(SDCLINICIEN,BDATE,EDATE) ;Traverse the "S" node in HOSPITAL LOCATION File #44 to retrieve appointments for a given datetime range
N APPDATETIME,APPTREC,SDAPPTNO,SDIEN,SDAPPT,SDMSG,SDSTDT,SDCLIN,FOUND,NUM,SDCLINDFN
S NUM=0
S APPDATETIME=$$FMADD^XLFDT(BDATE,-1) ;always start the previous date in order to get the needed date range
F S APPDATETIME=$O(^SC(SDCLINICIEN,"S",APPDATETIME)) Q:(APPDATETIME="")!(APPDATETIME>EDATE) D
. Q:APPDATETIME<BDATE
. S SDAPPTNO=0 F S SDAPPTNO=$O(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTNO)) Q:SDAPPTNO="" D
. . I '$D(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTNO,0)) Q
. . S SDIEN=SDAPPTNO_","_APPDATETIME_","_SDCLINICIEN_","
. . S SDCLINDFN=$$GET1^DIQ(44.003,SDIEN,.01,"I")
. . Q:'$D(^DPT(SDCLINDFN,"S",APPDATETIME,0))
. . K SDMSG,SDAPPT D GETS^DIQ(44.003,SDIEN,"**","IE","SDAPPT","SDMSG")
. . Q:$D(SDMSG)
. . I $G(SDVIEWAPPTBY)=0,$G(SDAPPT(44.003,SDIEN,.01,"I"))'=DFN Q ;if view appointment by DFN, we are only interested of those DFN's passed in
. . S SDSTDT=APPDATETIME
. . S SDCLIN=SDCLINICIEN
. . S NUM=NUM+1
. . D BLDREC^SDESGETCLINAPPT
. . I $D(APPTREC) M SDAPPT44("PatientAppt","File#44",NUM)=APPTREC("ClinicApptDate",SDSTDT)
. . I $G(SDVIEWAPPTBY)=1 S PATDFNARY(SDAPPT(44.003,SDIEN,.01,"I"))="" ;will be used later to retrieve appointments from the appointment multiple in File #2
I $O(SDAPPT44("PatientAppt","File#44",""))="" S SDAPPT44("PatientAppt","File#44")="" ;if no record found, set the array into a null value
Q
;
GETAPPT2(DFN,BDATE,EDATE) ;Traverse the "S" node in Appointment Multiple Patient File #2 to retrieve appointments for a given datetime range
N APPT,APPDATETIME,SDPATAPPT,SDMSG,ERR,NUM
S NUM=0
S APPDATETIME=$$FMADD^XLFDT(BDATE,-1) ;always start the previous date in order to get the needed date range
F S APPDATETIME=$O(^DPT(DFN,"S",APPDATETIME)) Q:(APPDATETIME="")!(APPDATETIME>EDATE) D
. Q:APPDATETIME<BDATE
. I $G(SDVIEWAPPTBY)=1,$$GET1^DIQ(2.98,APPDATETIME_","_DFN_",",.01,"I")'=SDCLINICIEN Q ;if view appointment by Clinic IEN, we are only interested of those Clinic IEN passed in
. K SDMSG,ERR
. S NUM=NUM+1
. S APPT=$$GETAPPT^SDESGETPATAPPT(.SDPATAPPT,$G(DFN),APPDATETIME)
. Q:$D(ERR)
. I $G(APPT) M SDAPPTMULT2("PatientAppt","File#2.98",NUM)=SDPATAPPT("PatientAppt",NUM)
I $O(SDAPPTMULT2("PatientAppt","File#2.98",""))="" S SDAPPTMULT2("PatientAppt","File#2.98")="" ;if no record found, set the array into a null value
Q
;
MERGEALLAPPT(SDALLAPPTARY,SDAPPT40984,SDAPPT44,SDAPPTMULT2) ;Merge all appointments(409.84, 44, and 2.98) altogther into one big array
M SDALLAPPTARY=SDAPPT40984
M SDALLAPPTARY=SDAPPT44
M SDALLAPPTARY=SDAPPTMULT2
Q
;
BUILDJSON(RETURNJSON,INPUT) ; Build JSON format
N JSONERROR
S JSONERROR=""
D ENCODE^XLFJSON("RETURNJSON","INPUT","JSONERROR")
Q
;
CLEANUP ;
K RETURNERROR,SDALLAPPTARY,SDBEG,SDEND,ERRORFLAG,HASDFNERRORS,HASCLINIENERRORS,ERRORS
K SDMSG,FOUND,ERR,SDCLINICIEN,SDDFN,SDVIEWAPPTBY,HASBEGDATEERRORS,HASENDDATEERRORS
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESGETAPPTWRAP 9936 printed Dec 13, 2024@02:56:41 Page 2
SDESGETAPPTWRAP ;ALB/RRM - RPC WRAPPER FOR VIEWING AN APPOINTMENT ;APR 12, 2022@13:47
+1 ;;5.3;Scheduling;**814**;Aug 13, 1993;Build 11
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ;
+5 ;No Direct Call
QUIT
+6 ;
+7 ; The parameter list for this RPC must be kept in sync.
+8 ; If you need to add or remove a parameter, ensure that the Remote Procedure File #8994 definition is also updated.
+9 ;
+10 ;This is the entry point to retrieve appointments from (not in particular order):
+11 ; - HOSPITAL LOCATION File #44
+12 ; - PATIENT File #2, and
+13 ; - SDEC APPOINTMENT File #409.84
+14 ;
+15 ; Called from the following RPC:
+16 ; - SDES GET APPTS BY CLINIC #44
+17 ; - SDES GET APPTS BY DFN #2
GETAPPTS(RETURNJSON,SDPOINTERIEN,SDBEGDATE,SDENDDATE) ;
+1 ;
+2 ; Input:
+3 ; SDPOINTERIEN [Required] = This can be a patient's DFN from PATIENT File #2 or the Internal Entry Number (IEN) from HOSPITAL LOCATION FILE #44.
+4 ; SDBEGDATE [Required] = The beginning date/time in ISO8601 Time Format for the search.
+5 ; SDENDDATE [Required] = The ending date/time in ISO8601 Time Format for the search.
+6 ;
+7 ; Output:
+8 ; RETURNJSON = Returns fields from the (not in particular order) HOSPITAL LOCATION File #44, PATIENT File #2, and SDEC APPOINTMENT File #409.84
+9 ; in JSON format. JSON Errors will be returned for any invalid/missing parameters.
+10 ;
+11 ;temp data storage for input validation error
NEW ERRORS,RETURNERROR
+12 ;temp data storage for File #409.84
NEW SDAPPT40984
+13 ;temp data storage for File #44
NEW SDAPPT44
+14 ;temp data storage for Appointment Multiple File #2
NEW SDAPPTMULT2
+15 ;temp data storage for all records found in the HOSPITAL LOCATION File #44, PATIENT File #2, and SDEC APPOINTMENT File #409.84
NEW SDALLAPPTARY
+16 NEW SDDFN,SDCLINICIEN,HASDFNERRORS,HASCLINIENERRORS,HASBEGDATEERRORS,HASENDDATEERRORS
+17 ;
+18 ;NOTE: Ensure that before calling this routine the SDVIEWAPPTBY variable is set to either 0 OR 1
+19 ; 0 - View Appointment using DFN
+20 ; 1 - View Appointment using CLINIC IEN
+21 ;
+22 SET ERRORFLAG=0
+23 ;Input parameters validation begins here
+24 ;DFN input parameter validation
IF $GET(SDVIEWAPPTBY)=0
Begin DoDot:1
+25 SET SDDFN=SDPOINTERIEN
+26 SET HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,SDDFN)
+27 IF HASDFNERRORS
MERGE RETURNERROR=ERRORS
End DoDot:1
+28 ;
+29 ;CLINIC IEN input parameter validation
IF $GET(SDVIEWAPPTBY)=1
Begin DoDot:1
+30 SET SDCLINICIEN=SDPOINTERIEN
+31 SET HASCLINIENERRORS=$$VALIDATECLINIC(.ERRORS,SDCLINICIEN)
+32 IF HASCLINIENERRORS
MERGE RETURNERROR=ERRORS
End DoDot:1
+33 ;
+34 ;convert beginning and ending date time to Fileman Format
+35 if $GET(SDBEGDATE)'=""
SET SDBEGDATE=$$ISOTFM^SDAMUTDT(SDBEGDATE)
+36 if $GET(SDENDDATE)'=""
SET SDENDDATE=$$ISOTFM^SDAMUTDT(SDENDDATE)
+37 ;
+38 ;SDBEGDATE input parameter validation
SET HASBEGDATEERRORS=$$VALIDATEBEGDATE(.ERRORS,SDBEGDATE)
+39 IF HASBEGDATEERRORS
MERGE RETURNERROR=ERRORS
+40 ;
+41 ;SDENDDATE input parameter validation
SET HASENDDATEERRORS=$$VALIDATEENDDATE(.ERRORS,SDENDDATE)
+42 IF HASENDDATEERRORS
MERGE RETURNERROR=ERRORS
+43 ;Input parameters validation ends here
+44 ;
+45 ;do not continue processing if errors are detected
IF $ORDER(RETURNERROR("Error",""))'=""
DO BUILDJSON(.RETURNERROR,.RETURNJSON)
QUIT
+46 ;
+47 ;always clear returned data to ensure a new array of data are returned
KILL RETURNJSON,SDAPPT40984,SDAPPT44,SDAPPTMULT2
+48 ;
+49 ;view appointment using DFN of the patient
IF $GET(SDVIEWAPPTBY)=0
DO GETAPPTBYDFN(SDDFN,SDBEGDATE,SDENDDATE)
+50 ;view appointment using Clinic IEN
IF $GET(SDVIEWAPPTBY)=1
DO GETAPPTBYCLIN(SDCLINICIEN,SDBEGDATE,SDENDDATE)
+51 ;
+52 ;Merge the three retrieved appointments into one big array
+53 DO MERGEALLAPPT(.SDALLAPPTARY,.SDAPPT40984,.SDAPPT44,.SDAPPTMULT2)
+54 ;
+55 DO BUILDJSON(.SDALLAPPTARY,.RETURNJSON)
+56 DO CLEANUP
+57 QUIT
+58 ;
VALIDATEPTDFN(ERRORS,SDDFN) ;Validate patient DFN
+1 NEW ERRORFLAG
+2 SET ERRORFLAG=$$VALIDATEPTDFN^SDESGETPATAPPT(.ERRORS,SDDFN)
+3 QUIT ERRORFLAG
+4 ;
VALIDATECLINIC(ERRORS,SDCLINICIEN) ;Validate Clinic
+1 NEW ERRORFLAG
+2 SET ERRORFLAG=$$VALIDATECLINIC^SDESGETPATAPPT(.ERRORS,SDCLINICIEN)
+3 QUIT ERRORFLAG
+4 ;
VALIDATEBEGDATE(ERRORS,SDBEGDATE) ;Validate Beginning Date
+1 NEW ERRORFLAG
+2 IF $GET(SDBEGDATE)=""
DO ERRLOG^SDESJSON(.ERRORS,25)
SET ERRORFLAG=1
QUIT ERRORFLAG
+3 SET ERRORFLAG=$$VALIDATEBEGDT^SDESPRINTPATAPPT(.ERRORS,SDBEGDATE)
+4 QUIT ERRORFLAG
+5 ;
VALIDATEENDDATE(ERRORS,SDENDDATE) ;Validate ENding Date
+1 NEW ERRORFLAG
+2 IF SDENDDATE=""
DO ERRLOG^SDESJSON(.ERRORS,26)
SET ERRORFLAG=1
QUIT ERRORFLAG
+3 SET ERRORFLAG=$$VALIDATEENDDT^SDESPRINTPATAPPT(.ERRORS,SDENDDATE)
+4 QUIT ERRORFLAG
+5 ;
GETAPPTBYDFN(DFN,SDBEG,SDEND) ;View Appointment using DFN of the patient
+1 NEW SDCLINICARY
+2 ;retrieves appointment from File #409.84
DO GETAPPT40984(DFN,SDBEG,SDEND)
+3 ;SDCLINICARY is set while retrieving the appointments from File #409.84 in GETAPPT40984 line tag
+4 ;retrieves appointment from File #44
DO LOOPCLINICARY(.SDCLINICARY,SDBEG,SDEND)
+5 ;retrieves appointment from Appointment Multiple Patient File #2
DO GETAPPT2(DFN,SDBEG,SDEND)
+6 QUIT
+7 ;
GETAPPTBYCLIN(SDCLINICIEN,SDBEGDATE,SDENDDATE) ;View Appointment using Clinic IEN
+1 NEW PATDFNARY
+2 ;Retrieves appointments in File #44
DO GETAPPT44(SDCLINICIEN,SDBEGDATE,SDENDDATE)
+3 ;PATDFNARY array is created while retrieving appointments from File #44 in GETAPPT44 line tag
+4 ;PATDFNARY will be use to retrieve appointments from Appointment Multiple PATIENT File #2 and File #409.84
+5 IF $DATA(PATDFNARY)
Begin DoDot:1
+6 SET DFN=""
FOR
SET DFN=$ORDER(PATDFNARY(DFN))
if DFN=""
QUIT
Begin DoDot:2
+7 ;retrieves appointment from File #409.84
DO GETAPPT40984(DFN,SDBEGDATE,SDENDDATE)
+8 ;retrieve appointments from Appointment Multiple PATIENT File #2
DO GETAPPT2(DFN,SDBEGDATE,SDENDDATE)
End DoDot:2
End DoDot:1
+9 QUIT
+10 ;
GETAPPT40984(DFN,BDATE,EDATE) ;Traverse the "CPAT" cross reference in File #409.84 to retrieve appointments for a given datetime range
+1 NEW APPTIEN,APPTDATA,RECNUM,CLINICIEN
+2 SET RECNUM=0
+3 SET APPTIEN=0
FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"CPAT",DFN,APPTIEN))
if 'APPTIEN
QUIT
Begin DoDot:1
+4 KILL SDMSG
+5 IF '$$APPTINDTRANGE^SDESAPPT(APPTIEN,BDATE,EDATE)
QUIT
+6 DO SUMMARY^SDESAPPTDATA(.APPTDATA,APPTIEN)
+7 ;if view appointment by Clinic IEN, we are only interested of those Clinic IEN passed in
IF $GET(SDVIEWAPPTBY)=1
IF $GET(APPTDATA("Resource","ClinicIEN"))'=SDCLINICIEN
QUIT
+8 SET RECNUM=RECNUM+1
+9 SET APPTDATA("AppointmentType")=$$GET1^DIQ(409.84,APPTIEN_",",.06)
+10 IF $DATA(APPTDATA)
Begin DoDot:2
+11 MERGE SDAPPT40984("PatientAppt","File#409.84",RECNUM)=APPTDATA
+12 IF $GET(SDVIEWAPPTBY)=0
Begin DoDot:3
+13 SET CLINICIEN=$GET(APPTDATA("Resource","ClinicIEN"))
+14 ;this will use later when retrieving the appointments in File #44
IF $GET(CLINICIEN)'=""
SET SDCLINICARY(CLINICIEN)=""
End DoDot:3
End DoDot:2
End DoDot:1
+15 ;if no record found, set the array into a null value
IF $ORDER(SDAPPT40984("PatientAppt","File#409.84",""))=""
SET SDAPPT40984("PatientAppt","File#409.84")=""
+16 QUIT
+17 ;
LOOPCLINICARY(SDCLINICARY,SDBEG,SDEND) ;Retrieve appointments from File #44
+1 NEW CLINICIEN
+2 SET CLINICIEN=""
FOR
SET CLINICIEN=$ORDER(SDCLINICARY(CLINICIEN))
if CLINICIEN=""
QUIT
DO GETAPPT44(CLINICIEN,SDBEG,SDEND)
+3 QUIT
+4 ;
GETAPPT44(SDCLINICIEN,BDATE,EDATE) ;Traverse the "S" node in HOSPITAL LOCATION File #44 to retrieve appointments for a given datetime range
+1 NEW APPDATETIME,APPTREC,SDAPPTNO,SDIEN,SDAPPT,SDMSG,SDSTDT,SDCLIN,FOUND,NUM,SDCLINDFN
+2 SET NUM=0
+3 ;always start the previous date in order to get the needed date range
SET APPDATETIME=$$FMADD^XLFDT(BDATE,-1)
+4 FOR
SET APPDATETIME=$ORDER(^SC(SDCLINICIEN,"S",APPDATETIME))
if (APPDATETIME="")!(APPDATETIME>EDATE)
QUIT
Begin DoDot:1
+5 if APPDATETIME<BDATE
QUIT
+6 SET SDAPPTNO=0
FOR
SET SDAPPTNO=$ORDER(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTNO))
if SDAPPTNO=""
QUIT
Begin DoDot:2
+7 IF '$DATA(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTNO,0))
QUIT
+8 SET SDIEN=SDAPPTNO_","_APPDATETIME_","_SDCLINICIEN_","
+9 SET SDCLINDFN=$$GET1^DIQ(44.003,SDIEN,.01,"I")
+10 if '$DATA(^DPT(SDCLINDFN,"S",APPDATETIME,0))
QUIT
+11 KILL SDMSG,SDAPPT
DO GETS^DIQ(44.003,SDIEN,"**","IE","SDAPPT","SDMSG")
+12 if $DATA(SDMSG)
QUIT
+13 ;if view appointment by DFN, we are only interested of those DFN's passed in
IF $GET(SDVIEWAPPTBY)=0
IF $GET(SDAPPT(44.003,SDIEN,.01,"I"))'=DFN
QUIT
+14 SET SDSTDT=APPDATETIME
+15 SET SDCLIN=SDCLINICIEN
+16 SET NUM=NUM+1
+17 DO BLDREC^SDESGETCLINAPPT
+18 IF $DATA(APPTREC)
MERGE SDAPPT44("PatientAppt","File#44",NUM)=APPTREC("ClinicApptDate",SDSTDT)
+19 ;will be used later to retrieve appointments from the appointment multiple in File #2
IF $GET(SDVIEWAPPTBY)=1
SET PATDFNARY(SDAPPT(44.003,SDIEN,.01,"I"))=""
End DoDot:2
End DoDot:1
+20 ;if no record found, set the array into a null value
IF $ORDER(SDAPPT44("PatientAppt","File#44",""))=""
SET SDAPPT44("PatientAppt","File#44")=""
+21 QUIT
+22 ;
GETAPPT2(DFN,BDATE,EDATE) ;Traverse the "S" node in Appointment Multiple Patient File #2 to retrieve appointments for a given datetime range
+1 NEW APPT,APPDATETIME,SDPATAPPT,SDMSG,ERR,NUM
+2 SET NUM=0
+3 ;always start the previous date in order to get the needed date range
SET APPDATETIME=$$FMADD^XLFDT(BDATE,-1)
+4 FOR
SET APPDATETIME=$ORDER(^DPT(DFN,"S",APPDATETIME))
if (APPDATETIME="")!(APPDATETIME>EDATE)
QUIT
Begin DoDot:1
+5 if APPDATETIME<BDATE
QUIT
+6 ;if view appointment by Clinic IEN, we are only interested of those Clinic IEN passed in
IF $GET(SDVIEWAPPTBY)=1
IF $$GET1^DIQ(2.98,APPDATETIME_","_DFN_",",.01,"I")'=SDCLINICIEN
QUIT
+7 KILL SDMSG,ERR
+8 SET NUM=NUM+1
+9 SET APPT=$$GETAPPT^SDESGETPATAPPT(.SDPATAPPT,$GET(DFN),APPDATETIME)
+10 if $DATA(ERR)
QUIT
+11 IF $GET(APPT)
MERGE SDAPPTMULT2("PatientAppt","File#2.98",NUM)=SDPATAPPT("PatientAppt",NUM)
End DoDot:1
+12 ;if no record found, set the array into a null value
IF $ORDER(SDAPPTMULT2("PatientAppt","File#2.98",""))=""
SET SDAPPTMULT2("PatientAppt","File#2.98")=""
+13 QUIT
+14 ;
MERGEALLAPPT(SDALLAPPTARY,SDAPPT40984,SDAPPT44,SDAPPTMULT2) ;Merge all appointments(409.84, 44, and 2.98) altogther into one big array
+1 MERGE SDALLAPPTARY=SDAPPT40984
+2 MERGE SDALLAPPTARY=SDAPPT44
+3 MERGE SDALLAPPTARY=SDAPPTMULT2
+4 QUIT
+5 ;
BUILDJSON(RETURNJSON,INPUT) ; Build JSON format
+1 NEW JSONERROR
+2 SET JSONERROR=""
+3 DO ENCODE^XLFJSON("RETURNJSON","INPUT","JSONERROR")
+4 QUIT
+5 ;
CLEANUP ;
+1 KILL RETURNERROR,SDALLAPPTARY,SDBEG,SDEND,ERRORFLAG,HASDFNERRORS,HASCLINIENERRORS,ERRORS
+2 KILL SDMSG,FOUND,ERR,SDCLINICIEN,SDDFN,SDVIEWAPPTBY,HASBEGDATEERRORS,HASENDDATEERRORS
+3 QUIT
+4 ;