SDESGETAPPTWRAP5 ;ALB/RRM,LAB,JAS - RPC WRAPPER FOR VIEWING AN APPOINTMENT CONTINUATION;JUL 17,2023@13:17
;;5.3;Scheduling;**823,824,825,838,851**;Aug 13, 1993;Build 10
;;Per VHA Directive 6402, this routine should not be modified
;
; Copy of SDESGETAPPTWRAP3
;
Q ;No Direct Call
;
GETAPPT40984(SDALLAPPTARY,DFN,BDATE,EDATE,SDAPPTIEN,RECNUM,SDVIEWAPPTBY) ;Traverse the "APTDT" cross reference in File #409.84 to retrieve appointments for a given datetime range
N APPTIEN,APPTDATA,CLINICIEN,EXIST,STARTTIME,APPTSTATUS,ENDTIME,SDAPPTIENARY,SDAPPTNUM
S SDAPPTIEN=$G(SDAPPTIEN)
D BUILDAPPTARY(.SDAPPTIENARY,DFN,BDATE,EDATE,SDAPPTIEN)
S EXIST=0
S APPTIEN="" F S APPTIEN=$O(SDAPPTIENARY(APPTIEN)) Q:APPTIEN=""!(EXIST) D
. S SDAPPTNUM="" F S SDAPPTNUM=$O(SDAPPTIENARY(APPTIEN,SDAPPTNUM)) Q:SDAPPTNUM=""!(EXIST) D
. . K SDMSG,APPTDATA D SUMMARY2^SDESAPPTDATA(.APPTDATA,APPTIEN)
. . I $G(SDVIEWAPPTBY)=1,$G(APPTDATA("Resource","ClinicIEN"))'=$G(SDCLINICIEN) Q ;if view appointment by Clinic IEN, we are only interested of those Clinic IEN passed in
. . I $G(SDVIEWAPPTBY)=0!($G(SDVIEWAPPTBY)=2) S RECNUM=RECNUM+1
. . S APPTSTATUS=SDAPPTIENARY(APPTIEN,SDAPPTNUM)
. . I $D(APPTDATA) D
. . . ;Build the appointment object as we go along
. . . I $G(SDVIEWAPPTBY)=0!($G(SDVIEWAPPTBY)=2) D Q
. . . . ;while we are here, using the CLINICIEN, retrieve the rest of the appointment
. . . . S CLINICIEN=$G(APPTDATA("Resource","ClinicIEN"))
. . . . S STARTTIME=APPTDATA("StartTimeFM")
. . . . S ENDTIME=$$GET1^DIQ(409.84,APPTIEN,.02,"I")
. . . . D SETOVERLAIDAPPT(.SDALLAPPTARY,APPTSTATUS,RECNUM)
. . . . I APPTSTATUS=0 D GETPATAPPT(.SDALLAPPTARY,DFN,STARTTIME,RECNUM) ;retrieve appointments from Appointment Multiple PATIENT File #2
. . . . I CLINICIEN="",$D(SDALLAPPTARY("Appointment",RECNUM,"Clinic")) S CLINICIEN=SDALLAPPTARY("Appointment",RECNUM,"Clinic"),CLINICIEN=$$FIND1^DIC(44,"","MX",CLINICIEN,"","","ERROR")
. . . . I CLINICIEN'="" D GETAPPT44(.SDALLAPPTARY,CLINICIEN,STARTTIME,ENDTIME,RECNUM,SDVIEWAPPTBY) ;retrieves appointments in File #44
. . . . I APPTDATA("Status")="" D SETSTATUS(.APPTDATA,APPTIEN,CLINICIEN)
. . . . K SDALLAPPTARY("Appointment",RECNUM,"Clinic")
. . . . M SDALLAPPTARY("Appointment",RECNUM)=APPTDATA ;merge File #409.84 last to override some of the duplicates File #2 and File #44
. . . . D REMOVEDUPLICATE ;remove duplicates as we go along
. . . I $D(SDAPPTIENARY(APPTIEN,CNTR)) D Q
. . . . Q:APPTSTATUS'=SDCLINSTATUS
. . . . S SDCLINSTATUS=APPTSTATUS
. . . . I APPTDATA("Status")="" D SETSTATUS(.APPTDATA,APPTIEN,SDCLINICIEN)
. . . . M SDALLAPPTARY("Appointment",RECNUM)=APPTDATA
. . . . S EXIST=1
. . . I SDCLINSTATUS=0,APPTSTATUS=0 D
. . . . I APPTDATA("Status")="" D SETSTATUS(.APPTDATA,APPTIEN,SDCLINICIEN)
. . . . M SDALLAPPTARY("Appointment",RECNUM)=APPTDATA ;merge File #409.84 last to override some of the duplicates File #2 and File #44
. . . . S EXIST=1
I $O(SDALLAPPTARY("Appointment",""))="" S SDALLAPPTARY("Appointment",1)="" ;if no record found,set the array into a NULL value.
Q
;
GETPATAPPT(SDALLAPPTARY,DFN,APPDATETIME,RECNUM) ;
N APPT,SDPATAPPT,SDMSG,ERR,NUM
K SDMSG,ERR,SDPATAPPT,APPT,NUM
S NUM=1
S APPT=$$GETAPPT^SDESGETPATAPPT(.SDPATAPPT,$G(DFN),APPDATETIME)
Q:$D(ERR)
K SDPATAPPT("PatientAppt",NUM,"Clinic")
K SDPATAPPT("PatientAppt",NUM,"Status")
I $G(APPT) M SDALLAPPTARY("Appointment",RECNUM)=SDPATAPPT("PatientAppt",NUM)
I $O(SDALLAPPTARY("Appointment",""))="" S SDALLAPPTARY("Appointment",1)="" ;if no record found, set the array into a NULL value
Q
;
GETAPPT2(SDALLAPPTARY,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 datetime 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,SDPATAPPT,APPT
. S NUM=NUM+1
. S APPT=$$GETAPPT^SDESGETPATAPPT(.SDPATAPPT,$G(DFN),APPDATETIME)
. Q:$D(ERR)
. K SDPATAPPT("PatientAppt",NUM,"Clinic")
. K SDPATAPPT("PatientAppt",NUM,"Status")
. I $G(APPT) M SDALLAPPTARY("Appointment",RECNUM)=SDPATAPPT("PatientAppt",NUM)
I $O(SDALLAPPTARY("Appointment",""))="" S SDALLAPPTARY("Appointment",1)="" ;if no record found, set the array into a NULL value
Q
;
GETAPPT44(SDALLAPPTARY,SDCLINICIEN,BDATE,EDATE,RECNUM,SDVIEWAPPTBY) ;Traverse the "S" node in HOSPITAL LOCATION File #44 to retrieve appointments for a given datetime range
N APPTREC,APTDATETIME,CNTR,EXIST,SDIEN,SDAPPT,SDAPPTNO,SDMSG,SDSTDT,SDCLIN,FOUND,SDCLINDFN,SDDFNARY,SDTMPARY,SDCLINSTATUS
S EXIST=0
D BUILDCLINAPPTARY(.SDDFNARY,SDCLINICIEN,BDATE,EDATE,SDVIEWAPPTBY)
S SDCLINDFN="" F S SDCLINDFN=$O(SDDFNARY(SDCLINDFN)) Q:SDCLINDFN=""!(EXIST) D
. S APTDATETIME="" F S APTDATETIME=$O(SDDFNARY(SDCLINDFN,APTDATETIME)) Q:APTDATETIME=""!(EXIST) D
. . S CNTR="" F S CNTR=$O(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR)) Q:CNTR="" D
. . . S SDIEN=$P(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR),"^",2)
. . . S SDAPPTNO=$P(SDIEN,",")
. . . S SDSTDT=$P(SDIEN,",",2)
. . . S SDCLIN=$P(SDIEN,",",3)
. . . I $G(SDVIEWAPPTBY)=0!($G(SDVIEWAPPTBY)=2),$D(SDDFNARY(DFN,APTDATETIME,SDAPPTNUM)) S EXIST=1
. . . I $G(SDVIEWAPPTBY)=1 S RECNUM=RECNUM+1,DFN=SDCLINDFN
. . . Q:'$D(^DPT(SDCLINDFN,"S",SDSTDT,0))
. . . Q:$G(DFN)'=SDCLINDFN
. . . K SDMSG,SDAPPT,APPTREC D GETS^DIQ(44.003,SDIEN,"**","IE","SDAPPT","SDMSG")
. . . Q:$D(SDMSG)
. . . D BLDREC^SDESGETCLINAPPT
. . . I $D(APPTREC) D
. . . . ;Build the appointment object as we go along
. . . . K APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"SSN")
. . . . K APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"Last4")
. . . . S APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"SSN")=$$LAST4SSN^SDESINPUTVALUTL(DFN)
. . . . S APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"ICN")=$$GETPATICN^SDESINPUTVALUTL(DFN)
. . . . M SDTMPARY("Patient")=APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN)
. . . . K APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN)
. . . . M SDALLAPPTARY("Appointment",RECNUM)=APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO)
. . . . M SDALLAPPTARY("Appointment",RECNUM)=SDTMPARY K SDTMPARY
. . . . I $G(SDVIEWAPPTBY)=1 D
. . . . . I $D(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR+1)) S SDCLINSTATUS=-1 ;Current Appt is cancelled and there is another APPT
. . . . . I '$D(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR+1)) S SDCLINSTATUS=0 ;Current Appt is either cancelled/not and no other APPT
. . . . . D GETAPPT40984(.SDALLAPPTARY,SDCLINDFN,SDSTDT,SDSTDT,,RECNUM,$G(SDVIEWAPPTBY)) ;retrieve appointments from Appointment Multiple PATIENT File #2
. . . . . D SETOVERLAIDAPPT(.SDALLAPPTARY,SDCLINSTATUS,RECNUM)
. . . . . I SDCLINSTATUS=0 D GETAPPT2(.SDALLAPPTARY,SDCLINDFN,SDSTDT,SDSTDT) ;retrieve appointments from Appointment Multiple PATIENT File #2
. . . . . D REMOVEDUPLICATE ;remove duplicates as we go along
I $O(SDALLAPPTARY("Appointment",""))="" S SDALLAPPTARY("Appointment",1)="" ;if no record found, set the array into a NULL value
Q
;
BUILDAPPTARY(SDAPPTIENARY,DFN,BDATE,EDATE,SDAPPTIEN) ;Retrieve all appointment IENs for a given DFN within the given date range
N APPTIEN,SDAPPTNO,OLDAPPTIEN,SDBEGINDX
S OLDAPPTIEN=""
S SDBEGINDX=$$FMADD^XLFDT(BDATE,-1) ;Reset BDATE to immediately before actual start time
S SDBEGINDX=0 F S SDBEGINDX=$O(^SDEC(409.84,"APTDT",DFN,SDBEGINDX)) Q:SDBEGINDX=""!(SDBEGINDX>EDATE) D
. Q:SDBEGINDX<BDATE
. S SDAPPTNO=0
. S APPTIEN="" F S APPTIEN=$O(^SDEC(409.84,"APTDT",DFN,SDBEGINDX,APPTIEN)) Q:APPTIEN="" D
. . I OLDAPPTIEN'=APPTIEN D
. . . I $G(SDVIEWAPPTBY)=2,APPTIEN'=SDAPPTIEN Q
. . . S SDAPPTNO=SDAPPTNO+1
. . . S APPTSTATUS=$$SDEXPST(.SDRET,DFN,SDBEGINDX,APPTIEN)
. . . S SDAPPTIENARY(APPTIEN,SDAPPTNO)=APPTSTATUS
. . S OLDAPPTIEN=APPTIEN
Q
;
BUILDCLINAPPTARY(SDDFNARY,SDCLINICIEN,BDATE,EDATE,SDVIEWAPPTBY) ;Retrieve all appointments for a given clinic within the given date range
N APPDATETIME,SDCLINDFN,SDAPPTCLNO,CLINAPPTSTAT,CNTR,OLDDFN
K SDDFNARY
S CNTR=0,OLDDFN=""
S APPDATETIME=$$FMADD^XLFDT(BDATE,-1) ;always start the previous datetime 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 SDAPPTCLNO="" F S SDAPPTCLNO=$O(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTCLNO)) Q:SDAPPTCLNO="" D
. . I '$D(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTCLNO,0)) Q
. . S SDCLINDFN=$$GET1^DIQ(44.003,SDAPPTCLNO_","_APPDATETIME_","_SDCLINICIEN_",",.01,"I")
. . Q:'SDCLINDFN
. . I ($G(SDVIEWAPPTBY)=0!($G(SDVIEWAPPTBY)=2)),SDCLINDFN'=DFN Q ;if view appointment by DFN, we are only interested of those DFN's passed in
. . I $D(SDDFNARY(SDCLINDFN,APPDATETIME)) S CNTR=$O(SDDFNARY(SDCLINDFN,APPDATETIME,""),-1)
. . I '$D(SDDFNARY(SDCLINDFN,APPDATETIME)) S CNTR=0
. . S CLINAPPTSTAT=$$GET1^DIQ(44.003,SDAPPTCLNO_","_APPDATETIME_","_SDCLINICIEN_",",310,"I")
. . S CNTR=CNTR+1
. . S SDDFNARY(SDCLINDFN,APPDATETIME,CNTR)=CLINAPPTSTAT_"^"_SDAPPTCLNO_","_APPDATETIME_","_SDCLINICIEN_","
Q
;
SETOVERLAIDAPPT(SDALLAPPTARY,STATUS,RECNUM) ;set this subscript if the Appointment is cancelled and there is another APPT
;This is due to the record does not exist in the Appointment Multiple File #2.98 anymore
;This is per BJ to add a boolean subscript to identify the data no longer exist
S SDALLAPPTARY("Appointment",RECNUM,"OverLaidAppointmentData")=$S($G(STATUS)=-1:"YES",1:"NO")
I STATUS=-1 D SETAPPTMULT2NULL(.SDALLAPPTARY,RECNUM) ;Set all the fields of Appointment Multiple File #2.98 to NULL
Q
;
SETSTATUS(APPTDATA,APPTIEN,CLINICIEN) ;
N SDAPPTNODE,APPOINTMENTSTAT
S SDAPPTNODE=$G(^SDEC(409.84,APPTIEN,0))
S APPOINTMENTSTAT=$$APPTSTS^SDEC50(APPTIEN,SDAPPTNODE,CLINICIEN)
S APPTDATA("Status")=$P(APPOINTMENTSTAT,"^")
S APPTDATA("StatusCancelDateTime")=$$FMTISO^SDAMUTDT($P(APPOINTMENTSTAT,"^",2),CLINICIEN)
Q
;
SDEXPST(SDRET,DFN,ADT,SDAPPTIEN) ;
N SDAPPT,SDRTN,SDNEXTIEN,SDCAN
S SDRTN="" ; Appt can be expanded
S SDAPPT="",ADT=+ADT
F S SDAPPT=$O(^SDEC(409.84,"APTDT",DFN,ADT,SDAPPT)) Q:'SDAPPT D Q:SDRTN'=""
. Q:SDAPPT'=SDAPPTIEN
. S SDCAN=($$GET1^DIQ(409.84,SDAPPT,.12,"I")'="")
. S SDNEXTIEN=$O(^SDEC(409.84,"APTDT",DFN,ADT,SDAPPT))
. ; Current Appt is cancelled and there is another APPT
. I SDCAN,SDNEXTIEN S SDRTN=-1 Q
. ; Current Appt is cancelled & no other Appt
. I SDCAN,'SDNEXTIEN S SDRTN=0 Q
. ; Current Appt is NOT cancelled so there can't be other Appt for same Date/Time
. I 'SDCAN,'SDNEXTIEN S SDRTN=0 Q
S SDRET=SDRTN
Q SDRET
;
REMOVEDUPLICATE ;
K SDALLAPPTARY("Appointment",RECNUM,"DateApptMade")
K SDALLAPPTARY("Appointment",RECNUM,"EKGTIME")
K SDALLAPPTARY("Appointment",RECNUM,"LABTIME")
K SDALLAPPTARY("Appointment",RECNUM,"AppointmentLength")
K SDALLAPPTARY("Appointment",RECNUM,"ApptCancelled")
K SDALLAPPTARY("Appointment",RECNUM,"CheckedOutDate")
K SDALLAPPTARY("Appointment",RECNUM,"CheckedIn")
K SDALLAPPTARY("Appointment",RECNUM,"TelephoneOfClinic")
K SDALLAPPTARY("Appointment",RECNUM,"XRAYTIME")
K SDALLAPPTARY("Appointment",RECNUM,"Patient","NAME")
K SDALLAPPTARY("Appointment",RECNUM,"DFN")
K SDALLAPPTARY("Appointment",RECNUM,"COLLATERAL")
K SDALLAPPTARY("Appointment",RECNUM,"AppointmentTime")
Q
;
SETAPPTMULT2NULL(SDALLAPPTARY,RECNUM) ;Set all the fields of Appointment Multiple File #2.98 to NULL
;This is per BJ and Lori as of 04/27/2022 to set all fields to NULL if the appointment is an overlaid appointment data
S SDPATAPPT("PatientAppt",RECNUM,"RealAppointment")=""
S SDPATAPPT("PatientAppt",RECNUM,"LabDateTime")=""
S SDPATAPPT("PatientAppt",RECNUM,"XrayDateTime")=""
S SDPATAPPT("PatientAppt",RECNUM,"EkgDateTime")=""
S SDPATAPPT("PatientAppt",RECNUM,"RoutingSlipPrinted")=""
S SDPATAPPT("PatientAppt",RECNUM,"RoutingSlipPrintDate")=""
S SDPATAPPT("PatientAppt",RECNUM,"PurposeOfVisit")=""
S SDPATAPPT("PatientAppt",RECNUM,"AppointmentType")=""
S SDPATAPPT("PatientAppt",RECNUM,"SpecialSurveyDisposition")=""
S SDPATAPPT("PatientAppt",RECNUM,"NumberOfCollateralSeen")=""
S SDPATAPPT("PatientAppt",RECNUM,"AutoRebookedApptDateTime")=""
S SDPATAPPT("PatientAppt",RECNUM,"CollateralVisit")=""
S SDPATAPPT("PatientAppt",RECNUM,"NoShowCancelledBy")=""
S SDPATAPPT("PatientAppt",RECNUM,"NoShowCancelDateTime")=""
S SDPATAPPT("PatientAppt",RECNUM,"CancellationReason")=""
S SDPATAPPT("PatientAppt",RECNUM,"CancellationRemarks")=""
S SDPATAPPT("PatientAppt",RECNUM,"ApptCancelled")=""
S SDPATAPPT("PatientAppt",RECNUM,"DataEntryClerk")=""
S SDPATAPPT("PatientAppt",RECNUM,"DateApptMade")=""
S SDPATAPPT("PatientAppt",RECNUM,"OutpatientEncounter")=""
S SDPATAPPT("PatientAppt",RECNUM,"EncounterFormsPrinted")=""
S SDPATAPPT("PatientAppt",RECNUM,"EncounterFormsAsAddOns")=""
S SDPATAPPT("PatientAppt",RECNUM,"EncounterConversionStatus")=""
S SDPATAPPT("PatientAppt",RECNUM,"AppointmentTypeSubCategory")=""
S SDPATAPPT("PatientAppt",RECNUM,"SchedulingRequestType")=""
S SDPATAPPT("PatientAppt",RECNUM,"NextAvaApptIndicator")=""
S SDPATAPPT("PatientAppt",RECNUM,"DesiredDateOfAppointment")=""
S SDPATAPPT("PatientAppt",RECNUM,"FollowUpVisit")=""
S SDPATAPPT("PatientAppt",RECNUM,"SchedulingApplication")=""
S SDPATAPPT("PatientAppt",RECNUM,"SchedulerName")=""
S SDPATAPPT("PatientAppt",RECNUM,"CurrentStatus")=""
M SDALLAPPTARY("Appointment",RECNUM)=SDPATAPPT("PatientAppt",RECNUM)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESGETAPPTWRAP5 14072 printed Dec 13, 2024@02:56:45 Page 2
SDESGETAPPTWRAP5 ;ALB/RRM,LAB,JAS - RPC WRAPPER FOR VIEWING AN APPOINTMENT CONTINUATION;JUL 17,2023@13:17
+1 ;;5.3;Scheduling;**823,824,825,838,851**;Aug 13, 1993;Build 10
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 ; Copy of SDESGETAPPTWRAP3
+5 ;
+6 ;No Direct Call
QUIT
+7 ;
GETAPPT40984(SDALLAPPTARY,DFN,BDATE,EDATE,SDAPPTIEN,RECNUM,SDVIEWAPPTBY) ;Traverse the "APTDT" cross reference in File #409.84 to retrieve appointments for a given datetime range
+1 NEW APPTIEN,APPTDATA,CLINICIEN,EXIST,STARTTIME,APPTSTATUS,ENDTIME,SDAPPTIENARY,SDAPPTNUM
+2 SET SDAPPTIEN=$GET(SDAPPTIEN)
+3 DO BUILDAPPTARY(.SDAPPTIENARY,DFN,BDATE,EDATE,SDAPPTIEN)
+4 SET EXIST=0
+5 SET APPTIEN=""
FOR
SET APPTIEN=$ORDER(SDAPPTIENARY(APPTIEN))
if APPTIEN=""!(EXIST)
QUIT
Begin DoDot:1
+6 SET SDAPPTNUM=""
FOR
SET SDAPPTNUM=$ORDER(SDAPPTIENARY(APPTIEN,SDAPPTNUM))
if SDAPPTNUM=""!(EXIST)
QUIT
Begin DoDot:2
+7 KILL SDMSG,APPTDATA
DO SUMMARY2^SDESAPPTDATA(.APPTDATA,APPTIEN)
+8 ;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"))'=$GET(SDCLINICIEN)
QUIT
+9 IF $GET(SDVIEWAPPTBY)=0!($GET(SDVIEWAPPTBY)=2)
SET RECNUM=RECNUM+1
+10 SET APPTSTATUS=SDAPPTIENARY(APPTIEN,SDAPPTNUM)
+11 IF $DATA(APPTDATA)
Begin DoDot:3
+12 ;Build the appointment object as we go along
+13 IF $GET(SDVIEWAPPTBY)=0!($GET(SDVIEWAPPTBY)=2)
Begin DoDot:4
+14 ;while we are here, using the CLINICIEN, retrieve the rest of the appointment
+15 SET CLINICIEN=$GET(APPTDATA("Resource","ClinicIEN"))
+16 SET STARTTIME=APPTDATA("StartTimeFM")
+17 SET ENDTIME=$$GET1^DIQ(409.84,APPTIEN,.02,"I")
+18 DO SETOVERLAIDAPPT(.SDALLAPPTARY,APPTSTATUS,RECNUM)
+19 ;retrieve appointments from Appointment Multiple PATIENT File #2
IF APPTSTATUS=0
DO GETPATAPPT(.SDALLAPPTARY,DFN,STARTTIME,RECNUM)
+20 IF CLINICIEN=""
IF $DATA(SDALLAPPTARY("Appointment",RECNUM,"Clinic"))
SET CLINICIEN=SDALLAPPTARY("Appointment",RECNUM,"Clinic")
SET CLINICIEN=$$FIND1^DIC(44,"","MX",CLINICIEN,"","","ERROR")
+21 ;retrieves appointments in File #44
IF CLINICIEN'=""
DO GETAPPT44(.SDALLAPPTARY,CLINICIEN,STARTTIME,ENDTIME,RECNUM,SDVIEWAPPTBY)
+22 IF APPTDATA("Status")=""
DO SETSTATUS(.APPTDATA,APPTIEN,CLINICIEN)
+23 KILL SDALLAPPTARY("Appointment",RECNUM,"Clinic")
+24 ;merge File #409.84 last to override some of the duplicates File #2 and File #44
MERGE SDALLAPPTARY("Appointment",RECNUM)=APPTDATA
+25 ;remove duplicates as we go along
DO REMOVEDUPLICATE
End DoDot:4
QUIT
+26 IF $DATA(SDAPPTIENARY(APPTIEN,CNTR))
Begin DoDot:4
+27 if APPTSTATUS'=SDCLINSTATUS
QUIT
+28 SET SDCLINSTATUS=APPTSTATUS
+29 IF APPTDATA("Status")=""
DO SETSTATUS(.APPTDATA,APPTIEN,SDCLINICIEN)
+30 MERGE SDALLAPPTARY("Appointment",RECNUM)=APPTDATA
+31 SET EXIST=1
End DoDot:4
QUIT
+32 IF SDCLINSTATUS=0
IF APPTSTATUS=0
Begin DoDot:4
+33 IF APPTDATA("Status")=""
DO SETSTATUS(.APPTDATA,APPTIEN,SDCLINICIEN)
+34 ;merge File #409.84 last to override some of the duplicates File #2 and File #44
MERGE SDALLAPPTARY("Appointment",RECNUM)=APPTDATA
+35 SET EXIST=1
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+36 ;if no record found,set the array into a NULL value.
IF $ORDER(SDALLAPPTARY("Appointment",""))=""
SET SDALLAPPTARY("Appointment",1)=""
+37 QUIT
+38 ;
GETPATAPPT(SDALLAPPTARY,DFN,APPDATETIME,RECNUM) ;
+1 NEW APPT,SDPATAPPT,SDMSG,ERR,NUM
+2 KILL SDMSG,ERR,SDPATAPPT,APPT,NUM
+3 SET NUM=1
+4 SET APPT=$$GETAPPT^SDESGETPATAPPT(.SDPATAPPT,$GET(DFN),APPDATETIME)
+5 if $DATA(ERR)
QUIT
+6 KILL SDPATAPPT("PatientAppt",NUM,"Clinic")
+7 KILL SDPATAPPT("PatientAppt",NUM,"Status")
+8 IF $GET(APPT)
MERGE SDALLAPPTARY("Appointment",RECNUM)=SDPATAPPT("PatientAppt",NUM)
+9 ;if no record found, set the array into a NULL value
IF $ORDER(SDALLAPPTARY("Appointment",""))=""
SET SDALLAPPTARY("Appointment",1)=""
+10 QUIT
+11 ;
GETAPPT2(SDALLAPPTARY,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 datetime 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,SDPATAPPT,APPT
+8 SET NUM=NUM+1
+9 SET APPT=$$GETAPPT^SDESGETPATAPPT(.SDPATAPPT,$GET(DFN),APPDATETIME)
+10 if $DATA(ERR)
QUIT
+11 KILL SDPATAPPT("PatientAppt",NUM,"Clinic")
+12 KILL SDPATAPPT("PatientAppt",NUM,"Status")
+13 IF $GET(APPT)
MERGE SDALLAPPTARY("Appointment",RECNUM)=SDPATAPPT("PatientAppt",NUM)
End DoDot:1
+14 ;if no record found, set the array into a NULL value
IF $ORDER(SDALLAPPTARY("Appointment",""))=""
SET SDALLAPPTARY("Appointment",1)=""
+15 QUIT
+16 ;
GETAPPT44(SDALLAPPTARY,SDCLINICIEN,BDATE,EDATE,RECNUM,SDVIEWAPPTBY) ;Traverse the "S" node in HOSPITAL LOCATION File #44 to retrieve appointments for a given datetime range
+1 NEW APPTREC,APTDATETIME,CNTR,EXIST,SDIEN,SDAPPT,SDAPPTNO,SDMSG,SDSTDT,SDCLIN,FOUND,SDCLINDFN,SDDFNARY,SDTMPARY,SDCLINSTATUS
+2 SET EXIST=0
+3 DO BUILDCLINAPPTARY(.SDDFNARY,SDCLINICIEN,BDATE,EDATE,SDVIEWAPPTBY)
+4 SET SDCLINDFN=""
FOR
SET SDCLINDFN=$ORDER(SDDFNARY(SDCLINDFN))
if SDCLINDFN=""!(EXIST)
QUIT
Begin DoDot:1
+5 SET APTDATETIME=""
FOR
SET APTDATETIME=$ORDER(SDDFNARY(SDCLINDFN,APTDATETIME))
if APTDATETIME=""!(EXIST)
QUIT
Begin DoDot:2
+6 SET CNTR=""
FOR
SET CNTR=$ORDER(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR))
if CNTR=""
QUIT
Begin DoDot:3
+7 SET SDIEN=$PIECE(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR),"^",2)
+8 SET SDAPPTNO=$PIECE(SDIEN,",")
+9 SET SDSTDT=$PIECE(SDIEN,",",2)
+10 SET SDCLIN=$PIECE(SDIEN,",",3)
+11 IF $GET(SDVIEWAPPTBY)=0!($GET(SDVIEWAPPTBY)=2)
IF $DATA(SDDFNARY(DFN,APTDATETIME,SDAPPTNUM))
SET EXIST=1
+12 IF $GET(SDVIEWAPPTBY)=1
SET RECNUM=RECNUM+1
SET DFN=SDCLINDFN
+13 if '$DATA(^DPT(SDCLINDFN,"S",SDSTDT,0))
QUIT
+14 if $GET(DFN)'=SDCLINDFN
QUIT
+15 KILL SDMSG,SDAPPT,APPTREC
DO GETS^DIQ(44.003,SDIEN,"**","IE","SDAPPT","SDMSG")
+16 if $DATA(SDMSG)
QUIT
+17 DO BLDREC^SDESGETCLINAPPT
+18 IF $DATA(APPTREC)
Begin DoDot:4
+19 ;Build the appointment object as we go along
+20 KILL APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"SSN")
+21 KILL APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"Last4")
+22 SET APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"SSN")=$$LAST4SSN^SDESINPUTVALUTL(DFN)
+23 SET APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN,"ICN")=$$GETPATICN^SDESINPUTVALUTL(DFN)
+24 MERGE SDTMPARY("Patient")=APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN)
+25 KILL APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO,"Patient",SDCLINDFN)
+26 MERGE SDALLAPPTARY("Appointment",RECNUM)=APPTREC("ClinicApptDate",SDSTDT,"ClinicApptNumber",SDAPPTNO)
+27 MERGE SDALLAPPTARY("Appointment",RECNUM)=SDTMPARY
KILL SDTMPARY
+28 IF $GET(SDVIEWAPPTBY)=1
Begin DoDot:5
+29 ;Current Appt is cancelled and there is another APPT
IF $DATA(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR+1))
SET SDCLINSTATUS=-1
+30 ;Current Appt is either cancelled/not and no other APPT
IF '$DATA(SDDFNARY(SDCLINDFN,APTDATETIME,CNTR+1))
SET SDCLINSTATUS=0
+31 ;retrieve appointments from Appointment Multiple PATIENT File #2
DO GETAPPT40984(.SDALLAPPTARY,SDCLINDFN,SDSTDT,SDSTDT,,RECNUM,$GET(SDVIEWAPPTBY))
+32 DO SETOVERLAIDAPPT(.SDALLAPPTARY,SDCLINSTATUS,RECNUM)
+33 ;retrieve appointments from Appointment Multiple PATIENT File #2
IF SDCLINSTATUS=0
DO GETAPPT2(.SDALLAPPTARY,SDCLINDFN,SDSTDT,SDSTDT)
+34 ;remove duplicates as we go along
DO REMOVEDUPLICATE
End DoDot:5
End DoDot:4
End DoDot:3
End DoDot:2
End DoDot:1
+35 ;if no record found, set the array into a NULL value
IF $ORDER(SDALLAPPTARY("Appointment",""))=""
SET SDALLAPPTARY("Appointment",1)=""
+36 QUIT
+37 ;
BUILDAPPTARY(SDAPPTIENARY,DFN,BDATE,EDATE,SDAPPTIEN) ;Retrieve all appointment IENs for a given DFN within the given date range
+1 NEW APPTIEN,SDAPPTNO,OLDAPPTIEN,SDBEGINDX
+2 SET OLDAPPTIEN=""
+3 ;Reset BDATE to immediately before actual start time
SET SDBEGINDX=$$FMADD^XLFDT(BDATE,-1)
+4 SET SDBEGINDX=0
FOR
SET SDBEGINDX=$ORDER(^SDEC(409.84,"APTDT",DFN,SDBEGINDX))
if SDBEGINDX=""!(SDBEGINDX>EDATE)
QUIT
Begin DoDot:1
+5 if SDBEGINDX<BDATE
QUIT
+6 SET SDAPPTNO=0
+7 SET APPTIEN=""
FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"APTDT",DFN,SDBEGINDX,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:2
+8 IF OLDAPPTIEN'=APPTIEN
Begin DoDot:3
+9 IF $GET(SDVIEWAPPTBY)=2
IF APPTIEN'=SDAPPTIEN
QUIT
+10 SET SDAPPTNO=SDAPPTNO+1
+11 SET APPTSTATUS=$$SDEXPST(.SDRET,DFN,SDBEGINDX,APPTIEN)
+12 SET SDAPPTIENARY(APPTIEN,SDAPPTNO)=APPTSTATUS
End DoDot:3
+13 SET OLDAPPTIEN=APPTIEN
End DoDot:2
End DoDot:1
+14 QUIT
+15 ;
BUILDCLINAPPTARY(SDDFNARY,SDCLINICIEN,BDATE,EDATE,SDVIEWAPPTBY) ;Retrieve all appointments for a given clinic within the given date range
+1 NEW APPDATETIME,SDCLINDFN,SDAPPTCLNO,CLINAPPTSTAT,CNTR,OLDDFN
+2 KILL SDDFNARY
+3 SET CNTR=0
SET OLDDFN=""
+4 ;always start the previous datetime in order to get the needed date range
SET APPDATETIME=$$FMADD^XLFDT(BDATE,-1)
+5 FOR
SET APPDATETIME=$ORDER(^SC(SDCLINICIEN,"S",APPDATETIME))
if APPDATETIME=""!(APPDATETIME>EDATE)
QUIT
Begin DoDot:1
+6 if APPDATETIME<BDATE
QUIT
+7 SET SDAPPTCLNO=""
FOR
SET SDAPPTCLNO=$ORDER(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTCLNO))
if SDAPPTCLNO=""
QUIT
Begin DoDot:2
+8 IF '$DATA(^SC(SDCLINICIEN,"S",APPDATETIME,1,SDAPPTCLNO,0))
QUIT
+9 SET SDCLINDFN=$$GET1^DIQ(44.003,SDAPPTCLNO_","_APPDATETIME_","_SDCLINICIEN_",",.01,"I")
+10 if 'SDCLINDFN
QUIT
+11 ;if view appointment by DFN, we are only interested of those DFN's passed in
IF ($GET(SDVIEWAPPTBY)=0!($GET(SDVIEWAPPTBY)=2))
IF SDCLINDFN'=DFN
QUIT
+12 IF $DATA(SDDFNARY(SDCLINDFN,APPDATETIME))
SET CNTR=$ORDER(SDDFNARY(SDCLINDFN,APPDATETIME,""),-1)
+13 IF '$DATA(SDDFNARY(SDCLINDFN,APPDATETIME))
SET CNTR=0
+14 SET CLINAPPTSTAT=$$GET1^DIQ(44.003,SDAPPTCLNO_","_APPDATETIME_","_SDCLINICIEN_",",310,"I")
+15 SET CNTR=CNTR+1
+16 SET SDDFNARY(SDCLINDFN,APPDATETIME,CNTR)=CLINAPPTSTAT_"^"_SDAPPTCLNO_","_APPDATETIME_","_SDCLINICIEN_","
End DoDot:2
End DoDot:1
+17 QUIT
+18 ;
SETOVERLAIDAPPT(SDALLAPPTARY,STATUS,RECNUM) ;set this subscript if the Appointment is cancelled and there is another APPT
+1 ;This is due to the record does not exist in the Appointment Multiple File #2.98 anymore
+2 ;This is per BJ to add a boolean subscript to identify the data no longer exist
+3 SET SDALLAPPTARY("Appointment",RECNUM,"OverLaidAppointmentData")=$SELECT($GET(STATUS)=-1:"YES",1:"NO")
+4 ;Set all the fields of Appointment Multiple File #2.98 to NULL
IF STATUS=-1
DO SETAPPTMULT2NULL(.SDALLAPPTARY,RECNUM)
+5 QUIT
+6 ;
SETSTATUS(APPTDATA,APPTIEN,CLINICIEN) ;
+1 NEW SDAPPTNODE,APPOINTMENTSTAT
+2 SET SDAPPTNODE=$GET(^SDEC(409.84,APPTIEN,0))
+3 SET APPOINTMENTSTAT=$$APPTSTS^SDEC50(APPTIEN,SDAPPTNODE,CLINICIEN)
+4 SET APPTDATA("Status")=$PIECE(APPOINTMENTSTAT,"^")
+5 SET APPTDATA("StatusCancelDateTime")=$$FMTISO^SDAMUTDT($PIECE(APPOINTMENTSTAT,"^",2),CLINICIEN)
+6 QUIT
+7 ;
SDEXPST(SDRET,DFN,ADT,SDAPPTIEN) ;
+1 NEW SDAPPT,SDRTN,SDNEXTIEN,SDCAN
+2 ; Appt can be expanded
SET SDRTN=""
+3 SET SDAPPT=""
SET ADT=+ADT
+4 FOR
SET SDAPPT=$ORDER(^SDEC(409.84,"APTDT",DFN,ADT,SDAPPT))
if 'SDAPPT
QUIT
Begin DoDot:1
+5 if SDAPPT'=SDAPPTIEN
QUIT
+6 SET SDCAN=($$GET1^DIQ(409.84,SDAPPT,.12,"I")'="")
+7 SET SDNEXTIEN=$ORDER(^SDEC(409.84,"APTDT",DFN,ADT,SDAPPT))
+8 ; Current Appt is cancelled and there is another APPT
+9 IF SDCAN
IF SDNEXTIEN
SET SDRTN=-1
QUIT
+10 ; Current Appt is cancelled & no other Appt
+11 IF SDCAN
IF 'SDNEXTIEN
SET SDRTN=0
QUIT
+12 ; Current Appt is NOT cancelled so there can't be other Appt for same Date/Time
+13 IF 'SDCAN
IF 'SDNEXTIEN
SET SDRTN=0
QUIT
End DoDot:1
if SDRTN'=""
QUIT
+14 SET SDRET=SDRTN
+15 QUIT SDRET
+16 ;
REMOVEDUPLICATE ;
+1 KILL SDALLAPPTARY("Appointment",RECNUM,"DateApptMade")
+2 KILL SDALLAPPTARY("Appointment",RECNUM,"EKGTIME")
+3 KILL SDALLAPPTARY("Appointment",RECNUM,"LABTIME")
+4 KILL SDALLAPPTARY("Appointment",RECNUM,"AppointmentLength")
+5 KILL SDALLAPPTARY("Appointment",RECNUM,"ApptCancelled")
+6 KILL SDALLAPPTARY("Appointment",RECNUM,"CheckedOutDate")
+7 KILL SDALLAPPTARY("Appointment",RECNUM,"CheckedIn")
+8 KILL SDALLAPPTARY("Appointment",RECNUM,"TelephoneOfClinic")
+9 KILL SDALLAPPTARY("Appointment",RECNUM,"XRAYTIME")
+10 KILL SDALLAPPTARY("Appointment",RECNUM,"Patient","NAME")
+11 KILL SDALLAPPTARY("Appointment",RECNUM,"DFN")
+12 KILL SDALLAPPTARY("Appointment",RECNUM,"COLLATERAL")
+13 KILL SDALLAPPTARY("Appointment",RECNUM,"AppointmentTime")
+14 QUIT
+15 ;
SETAPPTMULT2NULL(SDALLAPPTARY,RECNUM) ;Set all the fields of Appointment Multiple File #2.98 to NULL
+1 ;This is per BJ and Lori as of 04/27/2022 to set all fields to NULL if the appointment is an overlaid appointment data
+2 SET SDPATAPPT("PatientAppt",RECNUM,"RealAppointment")=""
+3 SET SDPATAPPT("PatientAppt",RECNUM,"LabDateTime")=""
+4 SET SDPATAPPT("PatientAppt",RECNUM,"XrayDateTime")=""
+5 SET SDPATAPPT("PatientAppt",RECNUM,"EkgDateTime")=""
+6 SET SDPATAPPT("PatientAppt",RECNUM,"RoutingSlipPrinted")=""
+7 SET SDPATAPPT("PatientAppt",RECNUM,"RoutingSlipPrintDate")=""
+8 SET SDPATAPPT("PatientAppt",RECNUM,"PurposeOfVisit")=""
+9 SET SDPATAPPT("PatientAppt",RECNUM,"AppointmentType")=""
+10 SET SDPATAPPT("PatientAppt",RECNUM,"SpecialSurveyDisposition")=""
+11 SET SDPATAPPT("PatientAppt",RECNUM,"NumberOfCollateralSeen")=""
+12 SET SDPATAPPT("PatientAppt",RECNUM,"AutoRebookedApptDateTime")=""
+13 SET SDPATAPPT("PatientAppt",RECNUM,"CollateralVisit")=""
+14 SET SDPATAPPT("PatientAppt",RECNUM,"NoShowCancelledBy")=""
+15 SET SDPATAPPT("PatientAppt",RECNUM,"NoShowCancelDateTime")=""
+16 SET SDPATAPPT("PatientAppt",RECNUM,"CancellationReason")=""
+17 SET SDPATAPPT("PatientAppt",RECNUM,"CancellationRemarks")=""
+18 SET SDPATAPPT("PatientAppt",RECNUM,"ApptCancelled")=""
+19 SET SDPATAPPT("PatientAppt",RECNUM,"DataEntryClerk")=""
+20 SET SDPATAPPT("PatientAppt",RECNUM,"DateApptMade")=""
+21 SET SDPATAPPT("PatientAppt",RECNUM,"OutpatientEncounter")=""
+22 SET SDPATAPPT("PatientAppt",RECNUM,"EncounterFormsPrinted")=""
+23 SET SDPATAPPT("PatientAppt",RECNUM,"EncounterFormsAsAddOns")=""
+24 SET SDPATAPPT("PatientAppt",RECNUM,"EncounterConversionStatus")=""
+25 SET SDPATAPPT("PatientAppt",RECNUM,"AppointmentTypeSubCategory")=""
+26 SET SDPATAPPT("PatientAppt",RECNUM,"SchedulingRequestType")=""
+27 SET SDPATAPPT("PatientAppt",RECNUM,"NextAvaApptIndicator")=""
+28 SET SDPATAPPT("PatientAppt",RECNUM,"DesiredDateOfAppointment")=""
+29 SET SDPATAPPT("PatientAppt",RECNUM,"FollowUpVisit")=""
+30 SET SDPATAPPT("PatientAppt",RECNUM,"SchedulingApplication")=""
+31 SET SDPATAPPT("PatientAppt",RECNUM,"SchedulerName")=""
+32 SET SDPATAPPT("PatientAppt",RECNUM,"CurrentStatus")=""
+33 MERGE SDALLAPPTARY("Appointment",RECNUM)=SDPATAPPT("PatientAppt",RECNUM)
+34 QUIT
+35 ;