SDESGETAPPTRPCS ;ALB/LAB - VISTA SCHEDULING RPCS TO GET APPOINTMENTS ;MAY 10,2024
;;5.3;Scheduling;**880**;Aug 13, 1993;Build 5
;;Per VHA Directive 6402, this routine should not be modified
;
Q
;
BYPATDFN(RESULT,DFN,SDBEGDATE,SDENDDATE,SDEAS) ;RPC: SDES GET APPTS BY PATIENT DFN3
N RECCNT,APPTDATE,APPTIEN,ERRORS,APPTOBJ
D VALIDATEBYDFN(.ERRORS,DFN,.SDBEGDATE,.SDENDDATE,.SDEAS)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S APPTDATE=SDBEGDATE-.0001
S RECCNT=0
F S APPTDATE=$O(^SDEC(409.84,"APTDT",DFN,APPTDATE)) Q:(APPTDATE>SDENDDATE)!(APPTDATE="") D
. S APPTIEN=""
. F S APPTIEN=$O(^SDEC(409.84,"APTDT",DFN,APPTDATE,APPTIEN)) Q:APPTIEN="" D
. . S RECCNT=RECCNT+1
. . D BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,DUZ)
I $D(ERRORS) M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S:'$D(APPTOBJ) APPTOBJ("Appointment",1)=""
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
VALIDATEBYDFN(ERRORS,DFN,SDBEGDATE,SDENDDATE,SDEAS) ;
D VALFILEIEN^SDES2VALUTIL(,.ERRORS,2,$G(DFN),1,,1,2)
S SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,SDBEGDATE,,1,9,11)
S SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,SDENDDATE,,1,10,12)
S SDEAS=$G(SDEAS)
I $L(SDEAS) S SDEAS=$$EASVALIDATE^SDESUTIL($G(SDEAS))
I $P($G(SDEAS),U)=-1 D ERRLOG^SDESJSON(.ERRORS,142)
Q
;
BYCLINIEN(RESULT,CLINICIEN,SDBEGDATE,SDENDDATE,SDEAS) ;Called from the RPC: SDES GET APPTS BY CLIN IEN
N ERRORS,RESOURCEIEN,APPTIEN,APPTOBJ,RECCNT,APPTDATE
D VALIDATEBYCLIN(.ERRORS,.CLINICIEN,.SDBEGDATE,.SDENDDATE)
I $D(ERRORS) S ERRORS("Appointment",1)="" D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S RESOURCEIEN=$$GETRES^SDES2UTIL1(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 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,DUZ)
I $D(ERRORS) M ERRORS=APPTOBJ D BUILDJSON^SDES2JSON(.RESULT,.ERRORS) Q
S:'$D(APPTOBJ) APPTOBJ("Appointment",1)=""
D BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
Q
;
VALIDATEBYCLIN(ERRORS,CLINICIEN,SDBEGDATE,SDENDDATE) ;
; Validate Clinic IEN
D VALFILEIEN^SDES2VALUTIL(,.ERRORS,44,$G(CLINICIEN),1,0,18,19)
S SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(SDBEGDATE),$G(CLINICIEN),1,9,11)
S SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$G(SDENDDATE),$G(CLINICIEN),1,10,12)
Q:$D(ERRORS)
I SDBEGDATE>SDENDDATE D ERRLOG^SDESJSON(.ERRORS,13)
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESGETAPPTRPCS 2842 printed Dec 13, 2024@02:56:37 Page 2
SDESGETAPPTRPCS ;ALB/LAB - VISTA SCHEDULING RPCS TO GET APPOINTMENTS ;MAY 10,2024
+1 ;;5.3;Scheduling;**880**;Aug 13, 1993;Build 5
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
+5 ;
BYPATDFN(RESULT,DFN,SDBEGDATE,SDENDDATE,SDEAS) ;RPC: SDES GET APPTS BY PATIENT DFN3
+1 NEW RECCNT,APPTDATE,APPTIEN,ERRORS,APPTOBJ
+2 DO VALIDATEBYDFN(.ERRORS,DFN,.SDBEGDATE,.SDENDDATE,.SDEAS)
+3 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+4 SET APPTDATE=SDBEGDATE-.0001
+5 SET RECCNT=0
+6 FOR
SET APPTDATE=$ORDER(^SDEC(409.84,"APTDT",DFN,APPTDATE))
if (APPTDATE>SDENDDATE)!(APPTDATE="")
QUIT
Begin DoDot:1
+7 SET APPTIEN=""
+8 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"APTDT",DFN,APPTDATE,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:2
+9 SET RECCNT=RECCNT+1
+10 DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,DUZ)
End DoDot:2
End DoDot:1
+11 IF $DATA(ERRORS)
MERGE ERRORS=APPTOBJ
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+12 if '$DATA(APPTOBJ)
SET APPTOBJ("Appointment",1)=""
+13 DO BUILDJSON^SDES2JSON(.RESULT,.APPTOBJ)
+14 QUIT
+15 ;
VALIDATEBYDFN(ERRORS,DFN,SDBEGDATE,SDENDDATE,SDEAS) ;
+1 DO VALFILEIEN^SDES2VALUTIL(,.ERRORS,2,$GET(DFN),1,,1,2)
+2 SET SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,SDBEGDATE,,1,9,11)
+3 SET SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,SDENDDATE,,1,10,12)
+4 SET SDEAS=$GET(SDEAS)
+5 IF $LENGTH(SDEAS)
SET SDEAS=$$EASVALIDATE^SDESUTIL($GET(SDEAS))
+6 IF $PIECE($GET(SDEAS),U)=-1
DO ERRLOG^SDESJSON(.ERRORS,142)
+7 QUIT
+8 ;
BYCLINIEN(RESULT,CLINICIEN,SDBEGDATE,SDENDDATE,SDEAS) ;Called from the RPC: SDES GET APPTS BY CLIN IEN
+1 NEW ERRORS,RESOURCEIEN,APPTIEN,APPTOBJ,RECCNT,APPTDATE
+2 DO VALIDATEBYCLIN(.ERRORS,.CLINICIEN,.SDBEGDATE,.SDENDDATE)
+3 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+4 SET RESOURCEIEN=$$GETRES^SDES2UTIL1(CLINICIEN,1)
+5 IF RESOURCEIEN=""
DO ERRLOG^SDES2JSON(.ERRORS,52,"Clinic is missing a resourceIEN")
+6 IF $DATA(ERRORS)
SET ERRORS("Appointment",1)=""
DO BUILDJSON^SDES2JSON(.RESULT,.ERRORS)
QUIT
+7 ;add error if resource not found
+8 SET APPTDATE=SDBEGDATE-.0001
+9 SET RECCNT=0
+10 FOR
SET APPTDATE=$ORDER(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE))
if (APPTDATE>SDENDDATE)!(APPTDATE="")
QUIT
Begin DoDot:1
+11 SET APPTIEN=""
+12 FOR
SET APPTIEN=$ORDER(^SDEC(409.84,"ARSRC",RESOURCEIEN,APPTDATE,APPTIEN))
if APPTIEN=""
QUIT
Begin DoDot:2
+13 SET RECCNT=RECCNT+1
+14 DO BUILDAPPTOBJ^SDES2BLDAPPTOBJ(.APPTOBJ,APPTIEN,RECCNT,.ERRORS,DUZ)
End DoDot:2
End DoDot:1
+15 IF $DATA(ERRORS)
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 ;
VALIDATEBYCLIN(ERRORS,CLINICIEN,SDBEGDATE,SDENDDATE) ;
+1 ; Validate Clinic IEN
+2 DO VALFILEIEN^SDES2VALUTIL(,.ERRORS,44,$GET(CLINICIEN),1,0,18,19)
+3 SET SDBEGDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(SDBEGDATE),$GET(CLINICIEN),1,9,11)
+4 SET SDENDDATE=$$VALISODTTM^SDES2VALISODTTM(.ERRORS,$GET(SDENDDATE),$GET(CLINICIEN),1,10,12)
+5 if $DATA(ERRORS)
QUIT
+6 IF SDBEGDATE>SDENDDATE
DO ERRLOG^SDESJSON(.ERRORS,13)
+7 QUIT
+8 ;