Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: SDES2GETAPPTRPCS

SDES2GETAPPTRPCS.m

Go to the documentation of this file.
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
 ;