SDESGETPATAPPT ;ALB/BLB,ANU - VISTA SCHEDULING RPCS ;JUNE 27, 2023@14:48
;;5.3;Scheduling;**809,847**;Aug 13, 1993;Build 4
;;Per VHA Directive 6402, this routine should not be modified
;
Q
;
GETSINGLEAPPT(SDECY,DFN,DATETIME,CLINIC) ; get single appt from patient 2 multiple based on dfn and date/time
N DFNERRORS,HASDFNERRORS,RETURN,HASDTTMERRORS,DTTMERRORS,SINGLEAPPT,APPT,SDPATAPPT,NUM,ERRORS,HASCLINICERRORS
;;
S HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,$G(DFN))
I HASDFNERRORS M RETURN=ERRORS
;;
S HASDTTMERRORS=$$VALIDATEDTTM(.ERRORS,$G(DATETIME))
I HASDTTMERRORS M RETURN=ERRORS
;;
S HASCLINICERRORS=$$VALIDATECLINIC(.ERRORS,$G(CLINIC))
I HASCLINICERRORS M RETURN=ERRORS
;
I '$D(ERRORS) D
.S NUM=1
.S SINGLEAPPT=$$GETAPPT(.SDPATAPPT,$G(DFN),$$ISOTFM^SDAMUTDT(DATETIME,CLINIC))
.I SINGLEAPPT M RETURN=SDPATAPPT
;;
D BUILDJSON(.SDECY,.RETURN) ;
D CLEANUP
Q
;
GETALLAPPTS(SDECY,DFN) ;
N HASDFNERRORS,RETURN,APPT,NUM,ERRORS,SUBIEN,SDPATAPPT
;
S HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,$G(DFN))
I HASDFNERRORS M RETURN=ERRORS
;
I '$D(ERRORS) D
.S SUBIEN=0,NUM=0
.F S SUBIEN=$O(^DPT(DFN,"S",SUBIEN)) Q:'SUBIEN D
..S NUM=NUM+1
..S APPT=$$GETAPPT(.SDPATAPPT,$G(DFN),SUBIEN)
..I $G(APPT) M RETURN=SDPATAPPT
D BUILDJSON(.SDECY,.RETURN)
D CLEANUP
Q
VALIDATECLINIC(ERRORS,CLINIC) ;
N ERRORFLAG
I CLINIC="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,18)
I CLINIC'="",'$D(^SC(CLINIC,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,19)
Q $D(ERRORFLAG)
;
VALIDATEPTDFN(ERRORS,DFN) ; VALIDATE PATIENT DFN
N ERRORFLAG
I DFN="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,1)
I DFN'="",'$D(^DPT(DFN,0)) S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,2)
Q $D(ERRORFLAG)
;
VALIDATEDTTM(ERRORS,DATETIME) ;
N ERRORFLAG,VALIDATED
I DATETIME="" S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,25)
I DATETIME'="" D
.S VALIDATED=$$ISOTFM^SDAMUTDT(DATETIME,CLINIC)
.I VALIDATED=-1!(VALIDATED="") S ERRORFLAG=1 D ERRLOG^SDESJSON(.ERRORS,27)
Q $D(ERRORFLAG)
;
GETAPPT(SDPATAPPT,DFN,DATETIME) ; get patient appointment from file
N IENS,F,APPTARY,FMDATE,CLINICIEN,OUTPDATE
S F=2.98
S IENS=DATETIME_","_DFN_"," ;
D GETS^DIQ(F,IENS,"**","IE","APPTARY","ERR")
S CLINICIEN=$G(APPTARY(F,IENS,.01,"I"))
S SDPATAPPT("PatientAppt",NUM,"AppointmentDateTime")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,.001,"I")),CLINICIEN)
S SDPATAPPT("PatientAppt",NUM,"Clinic")=$G(APPTARY(F,IENS,.01,"E"))
S SDPATAPPT("PatientAppt",NUM,"TelephoneOfClinic")=$G(APPTARY(F,IENS,.02,"E"))
S SDPATAPPT("PatientAppt",NUM,"Status")=$G(APPTARY(F,IENS,3,"E"))
S SDPATAPPT("PatientAppt",NUM,"RealAppointment")=$G(APPTARY(F,IENS,4,"E"))
S SDPATAPPT("PatientAppt",NUM,"LabDateTime")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,5,"I")),CLINICIEN)
S SDPATAPPT("PatientAppt",NUM,"XrayDateTime")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,6,"I")),CLINICIEN)
S SDPATAPPT("PatientAppt",NUM,"EkgDateTime")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,7,"I")),CLINICIEN)
S SDPATAPPT("PatientAppt",NUM,"RoutingSlipPrinted")=$G(APPTARY(F,IENS,8,"E"))
S SDPATAPPT("PatientAppt",NUM,"RoutingSlipPrintDate")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,8.5,"I")))
S SDPATAPPT("PatientAppt",NUM,"PurposeOfVisit")=$G(APPTARY(F,IENS,9,"E"))
S SDPATAPPT("PatientAppt",NUM,"AppointmentType")=$G(APPTARY(F,IENS,9.5,"E"))
S SDPATAPPT("PatientAppt",NUM,"SpecialSurveyDisposition")=$G(APPTARY(F,IENS,10,"E"))
S SDPATAPPT("PatientAppt",NUM,"NumberOfCollateralSeen")=$G(APPTARY(F,IENS,11,"E"))
S SDPATAPPT("PatientAppt",NUM,"AutoRebookedApptDateTime")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,12,"I")))
S SDPATAPPT("PatientAppt",NUM,"CollateralVisit")=$G(APPTARY(F,IENS,13,"E"))
S SDPATAPPT("PatientAppt",NUM,"NoShowCancelledBy")=$G(APPTARY(F,IENS,14,"E"))
S SDPATAPPT("PatientAppt",NUM,"NoShowCancelDateTime")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,15,"I")))
S SDPATAPPT("PatientAppt",NUM,"CancellationReason")=$G(APPTARY(F,IENS,16,"E"))
S SDPATAPPT("PatientAppt",NUM,"CancellationRemarks")=$G(APPTARY(F,IENS,17,"E"))
S SDPATAPPT("PatientAppt",NUM,"ApptCancelled")=$G(APPTARY(F,IENS,18,"E"))
S SDPATAPPT("PatientAppt",NUM,"DataEntryClerk")=$G(APPTARY(F,IENS,19,"E"))
S SDPATAPPT("PatientAppt",NUM,"DateApptMade")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,20,"I")))
S OUTPDATE=$$GET1^DIQ(409.68,$G(APPTARY(F,IENS,21,"I")),.01,"I")
S SDPATAPPT("PatientAppt",NUM,"OutpatientEncounter")=$$FMTISO^SDAMUTDT($G(OUTPDATE))
S SDPATAPPT("PatientAppt",NUM,"EncounterFormsPrinted")=$G(APPTARY(F,IENS,22,"E"))
S SDPATAPPT("PatientAppt",NUM,"EncounterFormsAsAddOns")=$G(APPTARY(F,IENS,23,"E"))
S SDPATAPPT("PatientAppt",NUM,"EncounterConversionStatus")=$G(APPTARY(F,IENS,23.1,"E"))
S SDPATAPPT("PatientAppt",NUM,"AppointmentTypeSubCategory")=$G(APPTARY(F,IENS,24,"E"))
S SDPATAPPT("PatientAppt",NUM,"SchedulingRequestType")=$G(APPTARY(F,IENS,25,"E"))
S SDPATAPPT("PatientAppt",NUM,"NextAvaApptIndicator")=$G(APPTARY(F,IENS,26,"E"))
S SDPATAPPT("PatientAppt",NUM,"DesiredDateOfAppointment")=$$FMTISO^SDAMUTDT($G(APPTARY(F,IENS,27,"I")))
S SDPATAPPT("PatientAppt",NUM,"FollowUpVisit")=$G(APPTARY(F,IENS,28,"E"))
S SDPATAPPT("PatientAppt",NUM,"SchedulingApplication")=$G(APPTARY(F,IENS,29,"I"))
S SDPATAPPT("PatientAppt",NUM,"SchedulerName")=$G(APPTARY(F,IENS,30,"E"))
;S SDPATAPPT("PatientAppt",NUM,"CurrentStatus")=$G(APPTARY(F,IENS,100,"E"))
I $D(SDPATAPPT) Q 1
Q 0
;
BUILDJSON(SDECY,RETURN) ; build json
N ERR
S ERR=""
D ENCODE^XLFJSON("RETURN","SDECY","ERR")
Q
;
CLEANUP ; kill vars
K RETURN,ERRORS,DTTMERRORS,APPTARY,SDPATAPPT,APPTARY
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESGETPATAPPT 5580 printed Dec 13, 2024@02:56:59 Page 2
SDESGETPATAPPT ;ALB/BLB,ANU - VISTA SCHEDULING RPCS ;JUNE 27, 2023@14:48
+1 ;;5.3;Scheduling;**809,847**;Aug 13, 1993;Build 4
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
GETSINGLEAPPT(SDECY,DFN,DATETIME,CLINIC) ; get single appt from patient 2 multiple based on dfn and date/time
+1 NEW DFNERRORS,HASDFNERRORS,RETURN,HASDTTMERRORS,DTTMERRORS,SINGLEAPPT,APPT,SDPATAPPT,NUM,ERRORS,HASCLINICERRORS
+2 ;;
+3 SET HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,$GET(DFN))
+4 IF HASDFNERRORS
MERGE RETURN=ERRORS
+5 ;;
+6 SET HASDTTMERRORS=$$VALIDATEDTTM(.ERRORS,$GET(DATETIME))
+7 IF HASDTTMERRORS
MERGE RETURN=ERRORS
+8 ;;
+9 SET HASCLINICERRORS=$$VALIDATECLINIC(.ERRORS,$GET(CLINIC))
+10 IF HASCLINICERRORS
MERGE RETURN=ERRORS
+11 ;
+12 IF '$DATA(ERRORS)
Begin DoDot:1
+13 SET NUM=1
+14 SET SINGLEAPPT=$$GETAPPT(.SDPATAPPT,$GET(DFN),$$ISOTFM^SDAMUTDT(DATETIME,CLINIC))
+15 IF SINGLEAPPT
MERGE RETURN=SDPATAPPT
End DoDot:1
+16 ;;
+17 ;
DO BUILDJSON(.SDECY,.RETURN)
+18 DO CLEANUP
+19 QUIT
+20 ;
GETALLAPPTS(SDECY,DFN) ;
+1 NEW HASDFNERRORS,RETURN,APPT,NUM,ERRORS,SUBIEN,SDPATAPPT
+2 ;
+3 SET HASDFNERRORS=$$VALIDATEPTDFN(.ERRORS,$GET(DFN))
+4 IF HASDFNERRORS
MERGE RETURN=ERRORS
+5 ;
+6 IF '$DATA(ERRORS)
Begin DoDot:1
+7 SET SUBIEN=0
SET NUM=0
+8 FOR
SET SUBIEN=$ORDER(^DPT(DFN,"S",SUBIEN))
if 'SUBIEN
QUIT
Begin DoDot:2
+9 SET NUM=NUM+1
+10 SET APPT=$$GETAPPT(.SDPATAPPT,$GET(DFN),SUBIEN)
+11 IF $GET(APPT)
MERGE RETURN=SDPATAPPT
End DoDot:2
End DoDot:1
+12 DO BUILDJSON(.SDECY,.RETURN)
+13 DO CLEANUP
+14 QUIT
VALIDATECLINIC(ERRORS,CLINIC) ;
+1 NEW ERRORFLAG
+2 IF CLINIC=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,18)
+3 IF CLINIC'=""
IF '$DATA(^SC(CLINIC,0))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,19)
+4 QUIT $DATA(ERRORFLAG)
+5 ;
VALIDATEPTDFN(ERRORS,DFN) ; VALIDATE PATIENT DFN
+1 NEW ERRORFLAG
+2 IF DFN=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,1)
+3 IF DFN'=""
IF '$DATA(^DPT(DFN,0))
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,2)
+4 QUIT $DATA(ERRORFLAG)
+5 ;
VALIDATEDTTM(ERRORS,DATETIME) ;
+1 NEW ERRORFLAG,VALIDATED
+2 IF DATETIME=""
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,25)
+3 IF DATETIME'=""
Begin DoDot:1
+4 SET VALIDATED=$$ISOTFM^SDAMUTDT(DATETIME,CLINIC)
+5 IF VALIDATED=-1!(VALIDATED="")
SET ERRORFLAG=1
DO ERRLOG^SDESJSON(.ERRORS,27)
End DoDot:1
+6 QUIT $DATA(ERRORFLAG)
+7 ;
GETAPPT(SDPATAPPT,DFN,DATETIME) ; get patient appointment from file
+1 NEW IENS,F,APPTARY,FMDATE,CLINICIEN,OUTPDATE
+2 SET F=2.98
+3 ;
SET IENS=DATETIME_","_DFN_","
+4 DO GETS^DIQ(F,IENS,"**","IE","APPTARY","ERR")
+5 SET CLINICIEN=$GET(APPTARY(F,IENS,.01,"I"))
+6 SET SDPATAPPT("PatientAppt",NUM,"AppointmentDateTime")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,.001,"I")),CLINICIEN)
+7 SET SDPATAPPT("PatientAppt",NUM,"Clinic")=$GET(APPTARY(F,IENS,.01,"E"))
+8 SET SDPATAPPT("PatientAppt",NUM,"TelephoneOfClinic")=$GET(APPTARY(F,IENS,.02,"E"))
+9 SET SDPATAPPT("PatientAppt",NUM,"Status")=$GET(APPTARY(F,IENS,3,"E"))
+10 SET SDPATAPPT("PatientAppt",NUM,"RealAppointment")=$GET(APPTARY(F,IENS,4,"E"))
+11 SET SDPATAPPT("PatientAppt",NUM,"LabDateTime")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,5,"I")),CLINICIEN)
+12 SET SDPATAPPT("PatientAppt",NUM,"XrayDateTime")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,6,"I")),CLINICIEN)
+13 SET SDPATAPPT("PatientAppt",NUM,"EkgDateTime")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,7,"I")),CLINICIEN)
+14 SET SDPATAPPT("PatientAppt",NUM,"RoutingSlipPrinted")=$GET(APPTARY(F,IENS,8,"E"))
+15 SET SDPATAPPT("PatientAppt",NUM,"RoutingSlipPrintDate")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,8.5,"I")))
+16 SET SDPATAPPT("PatientAppt",NUM,"PurposeOfVisit")=$GET(APPTARY(F,IENS,9,"E"))
+17 SET SDPATAPPT("PatientAppt",NUM,"AppointmentType")=$GET(APPTARY(F,IENS,9.5,"E"))
+18 SET SDPATAPPT("PatientAppt",NUM,"SpecialSurveyDisposition")=$GET(APPTARY(F,IENS,10,"E"))
+19 SET SDPATAPPT("PatientAppt",NUM,"NumberOfCollateralSeen")=$GET(APPTARY(F,IENS,11,"E"))
+20 SET SDPATAPPT("PatientAppt",NUM,"AutoRebookedApptDateTime")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,12,"I")))
+21 SET SDPATAPPT("PatientAppt",NUM,"CollateralVisit")=$GET(APPTARY(F,IENS,13,"E"))
+22 SET SDPATAPPT("PatientAppt",NUM,"NoShowCancelledBy")=$GET(APPTARY(F,IENS,14,"E"))
+23 SET SDPATAPPT("PatientAppt",NUM,"NoShowCancelDateTime")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,15,"I")))
+24 SET SDPATAPPT("PatientAppt",NUM,"CancellationReason")=$GET(APPTARY(F,IENS,16,"E"))
+25 SET SDPATAPPT("PatientAppt",NUM,"CancellationRemarks")=$GET(APPTARY(F,IENS,17,"E"))
+26 SET SDPATAPPT("PatientAppt",NUM,"ApptCancelled")=$GET(APPTARY(F,IENS,18,"E"))
+27 SET SDPATAPPT("PatientAppt",NUM,"DataEntryClerk")=$GET(APPTARY(F,IENS,19,"E"))
+28 SET SDPATAPPT("PatientAppt",NUM,"DateApptMade")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,20,"I")))
+29 SET OUTPDATE=$$GET1^DIQ(409.68,$GET(APPTARY(F,IENS,21,"I")),.01,"I")
+30 SET SDPATAPPT("PatientAppt",NUM,"OutpatientEncounter")=$$FMTISO^SDAMUTDT($GET(OUTPDATE))
+31 SET SDPATAPPT("PatientAppt",NUM,"EncounterFormsPrinted")=$GET(APPTARY(F,IENS,22,"E"))
+32 SET SDPATAPPT("PatientAppt",NUM,"EncounterFormsAsAddOns")=$GET(APPTARY(F,IENS,23,"E"))
+33 SET SDPATAPPT("PatientAppt",NUM,"EncounterConversionStatus")=$GET(APPTARY(F,IENS,23.1,"E"))
+34 SET SDPATAPPT("PatientAppt",NUM,"AppointmentTypeSubCategory")=$GET(APPTARY(F,IENS,24,"E"))
+35 SET SDPATAPPT("PatientAppt",NUM,"SchedulingRequestType")=$GET(APPTARY(F,IENS,25,"E"))
+36 SET SDPATAPPT("PatientAppt",NUM,"NextAvaApptIndicator")=$GET(APPTARY(F,IENS,26,"E"))
+37 SET SDPATAPPT("PatientAppt",NUM,"DesiredDateOfAppointment")=$$FMTISO^SDAMUTDT($GET(APPTARY(F,IENS,27,"I")))
+38 SET SDPATAPPT("PatientAppt",NUM,"FollowUpVisit")=$GET(APPTARY(F,IENS,28,"E"))
+39 SET SDPATAPPT("PatientAppt",NUM,"SchedulingApplication")=$GET(APPTARY(F,IENS,29,"I"))
+40 SET SDPATAPPT("PatientAppt",NUM,"SchedulerName")=$GET(APPTARY(F,IENS,30,"E"))
+41 ;S SDPATAPPT("PatientAppt",NUM,"CurrentStatus")=$G(APPTARY(F,IENS,100,"E"))
+42 IF $DATA(SDPATAPPT)
QUIT 1
+43 QUIT 0
+44 ;
BUILDJSON(SDECY,RETURN) ; build json
+1 NEW ERR
+2 SET ERR=""
+3 DO ENCODE^XLFJSON("RETURN","SDECY","ERR")
+4 QUIT
+5 ;
CLEANUP ; kill vars
+1 KILL RETURN,ERRORS,DTTMERRORS,APPTARY,SDPATAPPT,APPTARY
+2 QUIT