SDES2GETAPPTRPCS ;ALB/LAB,JAS,LAB - VISTA SCHEDULING RPCS TO GET APPOINTMENTS ;MAY 15,2024
;;5.3;Scheduling;**871,873,875,877,880**;Aug 13, 1993;Build 5
;;Per VHA Directive 6402, this routine should not be modified
;
Q
;
BYAPPTIEN(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPT BY APPT IEN
N ERRORS,APPTOBJ,SDDUZ
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
D VALIDATEBYIEN(.ERRORS,.APPTPARAMS)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
D BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTPARAMS("APPOINTMENT IEN"),1,.ERRORS,SDDUZ)
I $D(ERRORS) M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
APPTSBYIENLIST(RESULT,SDCONTEXT,SDPARAM) ;SDES2 GET APPTS BY APPT IENS
N APPTIEN,APPTOBJ,ERRORS,RECCNT,SDDUZ,VALFLAG
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
S RECCNT=0
S APPTIEN=""
F S APPTIEN=$O(SDPARAM("APPOINTMENT IEN",APPTIEN)) Q:(APPTIEN="")!(RECCNT>50) D
. S RECCNT=RECCNT+1
. I RECCNT>50 D
. . D ERRLOG^SDESJSON(.ERRORS,429)
. Q:RECCNT>50
. S VALFLAG=1
. D VALIDATEBYIENS(.ERRORS,APPTIEN,.VALFLAG)
. D:VALFLAG BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
I $D(ERRORS) M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
BYCLINICLIST(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY CLINIC LIST
N ERRORS,CLINICCNT,CLINICIEN,RESOURCEIEN,SDBEGDATE,SDENDDATE,SDDUZ,RECCNT,APPTOBJ,VALFLAG,APPTDATE,APPTIEN
N TODAY,CLINTODAY
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S TODAY=$$FMTISO^SDAMUTDT($$NOW^XLFDT)
S CLINICCNT=0
S CLINICIEN=""
S RECCNT=0
F S CLINICIEN=$O(APPTPARAMS("ClinicIEN",CLINICIEN)) Q:(CLINICIEN="")!(CLINICCNT>50) D
. S CLINICCNT=CLINICCNT+1
. I CLINICCNT>50 D
. . D ERRLOG^SDESJSON(.ERRORS,429)
. Q:CLINICCNT>50
. S VALFLAG=1
. D VALFILEIEN^SDES2VALUTIL(.VALFLAG,.ERRORS,44,$G(CLINICIEN),1,0,18,19)
. Q:'VALFLAG
. ; The date conversions need to be done on a per clinic basis because of timezones
. S CLINTODAY=$P($$ISOTFM^SDAMUTDT(TODAY,CLINICIEN),".",1)
. S SDBEGDATE=$$FMADD^XLFDT(CLINTODAY,"","","",-1)
. S SDENDDATE=$$FMADD^XLFDT(CLINTODAY,"",23,59,59) ;end of today
. S RESOURCEIEN=$$GETRES^SDES2UTIL1(CLINICIEN,1)
. I RESOURCEIEN="" S VALFLAG=0 D ERRLOG^SDES2JSON(.ERRORS,52,"Clinic is missing a resourceIEN")
. Q:'VALFLAG
. S APPTDATE=SDBEGDATE-.0001
. F S APPTDATE=$O(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE)) Q:(APPTDATE>SDENDDATE)!(APPTDATE="") D
. . S APPTIEN=""
. . F S APPTIEN=$O(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE,APPTIEN)) Q:APPTIEN="" D
. . . S RECCNT=RECCNT+1
. . . D BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
I $D(ERRORS) M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S:'$D(APPTOBJ) APPTOBJ("Appointment",1)=""
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
BYCLINIEN(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY CLINIC IEN
N ERRORS,SDBEGDATE,SDENDDATE,RESOURCEIEN,APPTIEN,APPTOBJ,RECCNT,APPTDATE,SDDUZ
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
D VALIDATEBYCLIN(.ERRORS,.APPTPARAMS,.SDBEGDATE,.SDENDDATE)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S RESOURCEIEN=$$GETRES^SDES2UTIL1(APPTPARAMS("ClinicIEN"),1)
I RESOURCEIEN="" D ERRLOG^SDES2JSON(.ERRORS,52,"Clinic is missing a resourceIEN")
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
;add error if resource not found]
S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
S APPTDATE=SDBEGDATE-.0001
S RECCNT=0
F S APPTDATE=$O(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE)) Q:(APPTDATE>SDENDDATE)!(APPTDATE="") D
. S APPTIEN=""
. F S APPTIEN=$O(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE,APPTIEN)) Q:APPTIEN="" D
. . S RECCNT=RECCNT+1
. . D BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
I $D(ERRORS) M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S:'$D(APPTOBJ) APPTOBJ("Appointment",1)=""
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
BYPATDFN(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY PATIENT DFN
N ERRORS,SDBEGDATE,SDENDDATE,APPTOBJ,APPTIEN,APPTDATE,RECCNT,SDDUZ
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
D VALIDATEBYDFN(.ERRORS,.APPTPARAMS,.SDBEGDATE,.SDENDDATE)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
S APPTDATE=SDBEGDATE-.0001
S RECCNT=0
F S APPTDATE=$O(^SDEC(409.84,"APTDT",APPTPARAMS("DFN"),APPTDATE)) Q:(APPTDATE>SDENDDATE)!(APPTDATE="") D
. S APPTIEN=""
. F S APPTIEN=$O(^SDEC(409.84,"APTDT",APPTPARAMS("DFN"),APPTDATE,APPTIEN)) Q:APPTIEN="" D
. . S RECCNT=RECCNT+1
. . D BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
I $D(ERRORS) M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S:'$D(APPTOBJ) APPTOBJ("Appointment",1)=""
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
BYCLINRESOURCE(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY CLN RES IEN
N ERRORS,SDBEGDATE,SDENDDATE,APPTIEN,APPTOBJ,RECCNT,APPTDATE,SDDUZ
D VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
D VALIDATEBYRES(.ERRORS,.APPTPARAMS,.SDBEGDATE,.SDENDDATE)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
;add error if resource not found]
S SDDUZ=$S($G(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
S APPTDATE=SDBEGDATE-.0001
S RECCNT=0
F S APPTDATE=$O(^SDEC(409.84,"ARSRC",APPTPARAMS("ResourceIEN"),APPTDATE)) Q:(APPTDATE>SDENDDATE)!(APPTDATE="") D
. S APPTIEN=""
. F S APPTIEN=$O(^SDEC(409.84,"ARSRC",APPTPARAMS("ResourceIEN"),APPTDATE,APPTIEN)) Q:APPTIEN="" D
. . S RECCNT=RECCNT+1
. . D BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
I $D(ERRORS) S:'$D(APPTOBJ) ERRORS("Appointment",1)="" M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S:'$D(APPTOBJ) APPTOBJ("Appointment",1)=""
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
VALIDATEBYIEN(ERRORS,APPTPARAMS) ;
; Validate APPT IEN
D VALFILEIEN^SDES2VALUTIL(,.ERRORS,409.84,$G(APPTPARAMS("APPOINTMENT IEN")),1,0,14,15) Q
Q
;
VALIDATEBYIENS(ERRORS,APPTIEN,VALFLAG) ;
;Validate APPT IEN
D VALFILEIEN^SDES2VALUTIL(.VALFLAG,.ERRORS,409.84,$G(APPTIEN),1,0,14,15,,," "_APPTIEN) Q
Q
;
VALIDATEBYCLIN(ERRORS,APPTPARAMS,SDBEGDATE,SDENDDATE) ;
; Validate Clinic IEN
D VALFILEIEN^SDES2VALUTIL(,.ERRORS,44,$G(APPTPARAMS("ClinicIEN")),1,0,18,19)
S SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("BeginDateTime")),$G(APPTPARAMS("ClinicIEN")),1,9,11)
S SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("EndDateTime")),$G(APPTPARAMS("ClinicIEN")),1,10,12)
Q:(SDBEGDATE="")!(SDENDDATE="")
I SDBEGDATE>SDENDDATE D ERRLOG^SDESJSON(.ERRORS,13)
Q
;
VALIDATEDATES(ERRORS,CLINICIEN,APPTPARAMS,SDBEGDATE,SDENDDATE,VALFLAG) ;
S SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("BeginDateTime")),CLINICIEN,1,9,11)
S SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("EndDateTime")),CLINICIEN,1,10,12)
S:(SDBEGDATE="")!(SDENDDATE="") VALFLAG=0
Q:'VALFLAG
I SDBEGDATE>SDENDDATE D ERRLOG^SDESJSON(.ERRORS,13) S VALFLAG=0
Q
;
VALIDATEBYRES(ERRORS,APPTPARAMS,SDBEGDATE,SDENDDATE) ;
; Validate Clinic IEN
D VALFILEIEN^SDES2VALUTIL(,.ERRORS,409.831,$G(APPTPARAMS("ResourceIEN")),1,0,69,70)
S SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("BeginDateTime")),$G(APPTPARAMS("ClinicIEN")),1,9,11)
S SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("EndDateTime")),$G(APPTPARAMS("ClinicIEN")),1,10,12)
I SDBEGDATE>SDENDDATE D ERRLOG^SDESJSON(.ERRORS,13)
Q
;
VALIDATEBYDFN(ERRORS,APPTPARAMS,SDBEGDATE,SDENDDATE) ;
D VALFILEIEN^SDES2VALUTIL(,.ERRORS,2,$G(APPTPARAMS("DFN")),1,,1,2)
S SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("BeginDateTime")),,1,9,11)
S SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(APPTPARAMS("EndDateTime")),,1,10,12)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDES2GETAPPTRPCS 8952 printed Sep 15, 2024@22:17:48 Page 2
SDES2GETAPPTRPCS ;ALB/LAB,JAS,LAB - VISTA SCHEDULING RPCS TO GET APPOINTMENTS ;MAY 15,2024
+1 ;;5.3;Scheduling;**871,873,875,877,880**;Aug 13, 1993;Build 5
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
BYAPPTIEN(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPT BY APPT IEN
+1 NEW ERRORS,APPTOBJ,SDDUZ
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+4 DO VALIDATEBYIEN(.ERRORS,.APPTPARAMS)
+5 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+6 SET SDDUZ=$SELECT($GET(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
+7 DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTPARAMS("APPOINTMENT IEN"),1,.ERRORS,SDDUZ)
+8 IF $DATA(ERRORS)
MERGE ERRORS=APPTOBJ
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+9 DO BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
+10 QUIT
+11 ;
APPTSBYIENLIST(RESULT,SDCONTEXT,SDPARAM) ;SDES2 GET APPTS BY APPT IENS
+1 NEW APPTIEN,APPTOBJ,ERRORS,RECCNT,SDDUZ,VALFLAG
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+4 SET SDDUZ=$SELECT($GET(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
+5 SET RECCNT=0
+6 SET APPTIEN=""
+7 FOR
SET APPTIEN=$ORDER(SDPARAM("APPOINTMENT IEN",APPTIEN))
if (APPTIEN="")!(RECCNT>50)
QUIT
Begin DoDot:1
+8 SET RECCNT=RECCNT+1
+9 IF RECCNT>50
Begin DoDot:2
+10 DO ERRLOG^SDESJSON(.ERRORS,429)
End DoDot:2
+11 if RECCNT>50
QUIT
+12 SET VALFLAG=1
+13 DO VALIDATEBYIENS(.ERRORS,APPTIEN,.VALFLAG)
+14 if VALFLAG
DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
End DoDot:1
+15 IF $DATA(ERRORS)
MERGE ERRORS=APPTOBJ
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+16 DO BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
+17 QUIT
+18 ;
BYCLINICLIST(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY CLINIC LIST
+1 NEW ERRORS,CLINICCNT,CLINICIEN,RESOURCEIEN,SDBEGDATE,SDENDDATE,SDDUZ,RECCNT,APPTOBJ,VALFLAG,APPTDATE,APPTIEN
+2 NEW TODAY,CLINTODAY
+3 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+4 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+5 SET SDDUZ=$SELECT($GET(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
+6 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+7 SET TODAY=$$FMTISO^SDAMUTDT($$NOW^XLFDT)
+8 SET CLINICCNT=0
+9 SET CLINICIEN=""
+10 SET RECCNT=0
+11 FOR
SET CLINICIEN=$ORDER(APPTPARAMS("ClinicIEN",CLINICIEN))
if (CLINICIEN="")!(CLINICCNT>50)
QUIT
Begin DoDot:1
+12 SET CLINICCNT=CLINICCNT+1
+13 IF CLINICCNT>50
Begin DoDot:2
+14 DO ERRLOG^SDESJSON(.ERRORS,429)
End DoDot:2
+15 if CLINICCNT>50
QUIT
+16 SET VALFLAG=1
+17 DO VALFILEIEN^SDES2VALUTIL(.VALFLAG,.ERRORS,44,$GET(CLINICIEN),1,0,18,19)
+18 if 'VALFLAG
QUIT
+19 ; The date conversions need to be done on a per clinic basis because of timezones
+20 SET CLINTODAY=$PIECE($$ISOTFM^SDAMUTDT(TODAY,CLINICIEN),".",1)
+21 SET SDBEGDATE=$$FMADD^XLFDT(CLINTODAY,"","","",-1)
+22 ;end of today
SET SDENDDATE=$$FMADD^XLFDT(CLINTODAY,"",23,59,59)
+23 SET RESOURCEIEN=$$GETRES^SDES2UTIL1(CLINICIEN,1)
+24 IF RESOURCEIEN=""
SET VALFLAG=0
DO ERRLOG^SDES2JSON(.ERRORS,52,"Clinic is missing a resourceIEN")
+25 if 'VALFLAG
QUIT
+26 SET APPTDATE=SDBEGDATE-.0001
+27 FOR
SET APPTDATE=$ORDER(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE))
if (APPTDATE>SDENDDATE)!(APPTDATE="")
QUIT
Begin DoDot:2
+28 SET APPTIEN=""
+29 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:3
+30 SET RECCNT=RECCNT+1
+31 DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
End DoDot:3
End DoDot:2
End DoDot:1
+32 IF $DATA(ERRORS)
MERGE ERRORS=APPTOBJ
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+33 if '$DATA(APPTOBJ)
SET APPTOBJ("Appointment",1)=""
+34 DO BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
+35 QUIT
+36 ;
BYCLINIEN(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY CLINIC IEN
+1 NEW ERRORS,SDBEGDATE,SDENDDATE,RESOURCEIEN,APPTIEN,APPTOBJ,RECCNT,APPTDATE,SDDUZ
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+4 DO VALIDATEBYCLIN(.ERRORS,.APPTPARAMS,.SDBEGDATE,.SDENDDATE)
+5 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+6 SET RESOURCEIEN=$$GETRES^SDES2UTIL1(APPTPARAMS("ClinicIEN"),1)
+7 IF RESOURCEIEN=""
DO ERRLOG^SDES2JSON(.ERRORS,52,"Clinic is missing a resourceIEN")
+8 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+9 ;add error if resource not found]
+10 SET SDDUZ=$SELECT($GET(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
+11 SET APPTDATE=SDBEGDATE-.0001
+12 SET RECCNT=0
+13 FOR
SET APPTDATE=$ORDER(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE))
if (APPTDATE>SDENDDATE)!(APPTDATE="")
QUIT
Begin DoDot:1
+14 SET APPTIEN=""
+15 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:2
+16 SET RECCNT=RECCNT+1
+17 DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
End DoDot:2
End DoDot:1
+18 IF $DATA(ERRORS)
MERGE ERRORS=APPTOBJ
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+19 if '$DATA(APPTOBJ)
SET APPTOBJ("Appointment",1)=""
+20 DO BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
+21 QUIT
+22 ;
BYPATDFN(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY PATIENT DFN
+1 NEW ERRORS,SDBEGDATE,SDENDDATE,APPTOBJ,APPTIEN,APPTDATE,RECCNT,SDDUZ
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+4 DO VALIDATEBYDFN(.ERRORS,.APPTPARAMS,.SDBEGDATE,.SDENDDATE)
+5 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+6 SET SDDUZ=$SELECT($GET(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
+7 SET APPTDATE=SDBEGDATE-.0001
+8 SET RECCNT=0
+9 FOR
SET APPTDATE=$ORDER(^SDEC(409.84,"APTDT",APPTPARAMS("DFN"),APPTDATE))
if (APPTDATE>SDENDDATE)!(APPTDATE="")
QUIT
Begin DoDot:1
+10 SET APPTIEN=""
+11 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"APTDT",APPTPARAMS("DFN"),APPTDATE,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:2
+12 SET RECCNT=RECCNT+1
+13 DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
End DoDot:2
End DoDot:1
+14 IF $DATA(ERRORS)
MERGE ERRORS=APPTOBJ
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+15 if '$DATA(APPTOBJ)
SET APPTOBJ("Appointment",1)=""
+16 DO BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
+17 QUIT
+18 ;
BYCLINRESOURCE(RESULT,SDCONTEXT,APPTPARAMS) ;SDES2 GET APPTS BY CLN RES IEN
+1 NEW ERRORS,SDBEGDATE,SDENDDATE,APPTIEN,APPTOBJ,RECCNT,APPTDATE,SDDUZ
+2 DO VALCONTEXT^SDES2VALCONTEXT(.ERRORS,.SDCONTEXT)
+3 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+4 DO VALIDATEBYRES(.ERRORS,.APPTPARAMS,.SDBEGDATE,.SDENDDATE)
+5 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+6 ;add error if resource not found]
+7 SET SDDUZ=$SELECT($GET(SDCONTEXT("USER DUZ"))'="":SDCONTEXT("USER DUZ"),1:DUZ)
+8 SET APPTDATE=SDBEGDATE-.0001
+9 SET RECCNT=0
+10 FOR
SET APPTDATE=$ORDER(^SDEC(409.84,"ARSRC",APPTPARAMS("ResourceIEN"),APPTDATE))
if (APPTDATE>SDENDDATE)!(APPTDATE="")
QUIT
Begin DoDot:1
+11 SET APPTIEN=""
+12 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"ARSRC",APPTPARAMS("ResourceIEN"),APPTDATE,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:2
+13 SET RECCNT=RECCNT+1
+14 DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,SDDUZ)
End DoDot:2
End DoDot:1
+15 IF $DATA(ERRORS)
if '$DATA(APPTOBJ)
SET ERRORS("Appointment",1)=""
MERGE ERRORS=APPTOBJ
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+16 if '$DATA(APPTOBJ)
SET APPTOBJ("Appointment",1)=""
+17 DO BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
+18 QUIT
+19 ;
VALIDATEBYIEN(ERRORS,APPTPARAMS) ;
+1 ; Validate APPT IEN
+2 DO VALFILEIEN^SDES2VALUTIL(,.ERRORS,409.84,$GET(APPTPARAMS("APPOINTMENT IEN")),1,0,14,15)
QUIT
+3 QUIT
+4 ;
VALIDATEBYIENS(ERRORS,APPTIEN,VALFLAG) ;
+1 ;Validate APPT IEN
+2 DO VALFILEIEN^SDES2VALUTIL(.VALFLAG,.ERRORS,409.84,$GET(APPTIEN),1,0,14,15,,," "_APPTIEN)
QUIT
+3 QUIT
+4 ;
VALIDATEBYCLIN(ERRORS,APPTPARAMS,SDBEGDATE,SDENDDATE) ;
+1 ; Validate Clinic IEN
+2 DO VALFILEIEN^SDES2VALUTIL(,.ERRORS,44,$GET(APPTPARAMS("ClinicIEN")),1,0,18,19)
+3 SET SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("BeginDateTime")),$GET(APPTPARAMS("ClinicIEN")),1,9,11)
+4 SET SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("EndDateTime")),$GET(APPTPARAMS("ClinicIEN")),1,10,12)
+5 if (SDBEGDATE="")!(SDENDDATE="")
QUIT
+6 IF SDBEGDATE>SDENDDATE
DO ERRLOG^SDESJSON(.ERRORS,13)
+7 QUIT
+8 ;
VALIDATEDATES(ERRORS,CLINICIEN,APPTPARAMS,SDBEGDATE,SDENDDATE,VALFLAG) ;
+1 SET SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("BeginDateTime")),CLINICIEN,1,9,11)
+2 SET SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("EndDateTime")),CLINICIEN,1,10,12)
+3 if (SDBEGDATE="")!(SDENDDATE="")
SET VALFLAG=0
+4 if 'VALFLAG
QUIT
+5 IF SDBEGDATE>SDENDDATE
DO ERRLOG^SDESJSON(.ERRORS,13)
SET VALFLAG=0
+6 QUIT
+7 ;
VALIDATEBYRES(ERRORS,APPTPARAMS,SDBEGDATE,SDENDDATE) ;
+1 ; Validate Clinic IEN
+2 DO VALFILEIEN^SDES2VALUTIL(,.ERRORS,409.831,$GET(APPTPARAMS("ResourceIEN")),1,0,69,70)
+3 SET SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("BeginDateTime")),$GET(APPTPARAMS("ClinicIEN")),1,9,11)
+4 SET SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("EndDateTime")),$GET(APPTPARAMS("ClinicIEN")),1,10,12)
+5 IF SDBEGDATE>SDENDDATE
DO ERRLOG^SDESJSON(.ERRORS,13)
+6 QUIT
+7 ;
VALIDATEBYDFN(ERRORS,APPTPARAMS,SDBEGDATE,SDENDDATE) ;
+1 DO VALFILEIEN^SDES2VALUTIL(,.ERRORS,2,$GET(APPTPARAMS("DFN")),1,,1,2)
+2 SET SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("BeginDateTime")),,1,9,11)
+3 SET SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(APPTPARAMS("EndDateTime")),,1,10,12)
+4 QUIT
+5 ;