SDESGETDIVISION ;ALB/BWF,TJB - SDES GET DIVISION/FACILITY/TIMEZONE ;JUNE 5, 2023
;;5.3;Scheduling;**819,846**;Aug 13, 1993;Build 12
;;Per VHA Directive 6402, this routine should not be modified
;
Q
GETDIVISIONLIST(RESULTS,SEARCHTRM,EAS) ;
N DATA,FACILITYNUM,FACARRY,ERRORS,ERR
S SEARCHTRM=$G(SEARCHTRM)
D VALINPUT(.ERRORS,SEARCHTRM)
D VALIDATEEAS(.ERRORS,$G(EAS))
I $D(ERRORS) D Q
.S ERRORS("Division",1)=""
.D BUILDJSON^SDESBUILDJSON(.RESULTS,.ERRORS) Q
; If INPUT data passed in use FIND to get the list of matching DIVISIONS
I SEARCHTRM'="" D
. K DATA,ERR D FIND^DIC(40.8,,".07I;1","M",SEARCHTRM,,,,,"DATA","ERR")
; Otherwise just list all DIVISION from file 40.8
I SEARCHTRM="" D
. K DATA,ERR D LIST^DIC(40.8,,".07I;1","",,,,,,,"DATA","ERR")
I $D(ERR) D Q
. S ERRORS("Division",1)=""
. S ERRORS("Error",1)="Errors in "_$S(SEARCHTRM'="":"FIND^DIC",1:"LIST^DIC")
. S ERRORS("Error",2)=$G(ERR("DIERR",1,"TEXT",1))
. D BUILDJSON^SDESBUILDJSON(.RESULTS,.ERRORS) Q
; Build the FACARRY to then be returned
D BUILDATA(.DATA,.FACARRY)
D BUILDJSON^SDESBUILDJSON(.RESULTS,.FACARRY)
Q
VALINPUT(ERRORS,INPUT) ;
Q:$G(INPUT)="" ; If INP is empty then just continue
I $L($G(INPUT))<2 D ERRLOG^SDESJSON(.ERRORS,64)
Q
VALIDATEEAS(ERRORS,SDEAS) ;
I $L(SDEAS) S SDEAS=$$EASVALIDATE^SDESUTIL($G(SDEAS))
I $P($G(SDEAS),U)=-1 D ERRLOG^SDESJSON(.ERRORS,142)
Q
BUILDATA(DATA,FACARRY) ; Build out array to be put into JSON format
N DCNT,ITEM,DIVNM,DIVIEN,FACILITYNUM,INST,INSTIMEZONE,FACTYP,PARINST,INSTFAC,J,JJ,TZARRAY,JTZ
S (DCNT,ITEM,J)=0 F S ITEM=$O(DATA("DILIST",1,ITEM)) Q:'ITEM D
. S (DIVNM,DIVIEN,FACILITYNUM,PARINST,FACTYP)=""
. S DCNT=DCNT+1
. S DIVNM=$G(DATA("DILIST",1,ITEM)) ; DIVISION Name
. S DIVIEN=$G(DATA("DILIST",2,ITEM)) ; DIVISION IEN
. S FACILITYNUM=$G(DATA("DILIST","ID",ITEM,1))
. S PARINST=$G(DATA("DILIST","ID",ITEM,.07)) ; Parent Institution IEN
. S FACARRY("Division",DCNT,"Name")=DIVNM
. S FACARRY("Division",DCNT,"ID")=DIVIEN
. S FACARRY("Division",DCNT,"FacilityNumber")=FACILITYNUM
. ; Get data from the instution file
. K INST,ERR D GETS^DIQ(4,PARINST_",","101;.01;99;11;13;800;802","IEP","INST","ERR")
. S INSTIMEZONE=$G(INST(4,PARINST_",",800,"I"))
. ; Get data from world timezone file
. I INSTIMEZONE'="" K TZARRAY,ERR D GETS^DIQ(1.71,INSTIMEZONE_",","1*","IE","TZARRAY","ERR")
. S FACTYP=$G(INST(4,PARINST_",",13,"I"))
. ; Get data from the Facility Type file
. I FACTYP'="" K INSTFAC,ERR D GETS^DIQ(4.1,FACTYP_",",".01;3","IE","INSTFAC","ERR")
. S FACARRY("Division",DCNT,"Institution","Inactive")=$G(INST(4,PARINST_",",101,"I"))
. S FACARRY("Division",DCNT,"Institution","Name")=$G(INST(4,PARINST_",",.01,"I"))
. S FACARRY("Division",DCNT,"Institution","StationNumber")=$G(INST(4,PARINST_",",99,"I"))
. S FACARRY("Division",DCNT,"FacilityType","Name")=$G(INSTFAC(4.1,FACTYP_",",.01,"I"))
. S FACARRY("Division",DCNT,"FacilityType","Status")=$G(INSTFAC(4.1,FACTYP_",",3,"I"))
. S FACARRY("Division",DCNT,"ParentFacility")=PARINST
. S FACARRY("Division",DCNT,"Status")=$G(INST(4,PARINST_",",11,"I"))
. S FACARRY("Division",DCNT,"InactiveFacilityFlag")=$G(INST(4,PARINST_",",101,"I"))
. S FACARRY("Division",DCNT,"TimeZone")=$G(INST(4,PARINST_",",800,"E"))
. I $D(TZARRAY(1.711))>0 S JJ="",J=0 F S JJ=$O(TZARRAY(1.711,JJ)) Q:JJ="" D
. . S J=J+1
. . S FACARRY("Division",DCNT,"TimeZoneDetails",J,"TimeFrame")=$G(TZARRAY(1.711,JJ,.01,"E"))
. . S FACARRY("Division",DCNT,"TimeZoneDetails",J,"Offset")=$G(TZARRAY(1.711,JJ,.02,"E"))
. . S FACARRY("Division",DCNT,"TimeZoneDetails",J,"TimeZoneCode")=$G(TZARRAY(1.711,JJ,.03,"E"))
. S FACARRY("Division",DCNT,"TimeZoneException")=$G(INST(4,PARINST_",",802,"E"))
I '$D(FACARRY) S FACARRY("Division",1)=""
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDESGETDIVISION 3815 printed Nov 22, 2024@18:06:48 Page 2
SDESGETDIVISION ;ALB/BWF,TJB - SDES GET DIVISION/FACILITY/TIMEZONE ;JUNE 5, 2023
+1 ;;5.3;Scheduling;**819,846**;Aug 13, 1993;Build 12
+2 ;;Per VHA Directive 6402, this routine should not be modified
+3 ;
+4 QUIT
GETDIVISIONLIST(RESULTS,SEARCHTRM,EAS) ;
+1 NEW DATA,FACILITYNUM,FACARRY,ERRORS,ERR
+2 SET SEARCHTRM=$GET(SEARCHTRM)
+3 DO VALINPUT(.ERRORS,SEARCHTRM)
+4 DO VALIDATEEAS(.ERRORS,$GET(EAS))
+5 IF $DATA(ERRORS)
Begin DoDot:1
+6 SET ERRORS("Division",1)=""
+7 DO BUILDJSON^SDESBUILDJSON(.RESULTS,.ERRORS)
QUIT
End DoDot:1
QUIT
+8 ; If INPUT data passed in use FIND to get the list of matching DIVISIONS
+9 IF SEARCHTRM'=""
Begin DoDot:1
+10 KILL DATA,ERR
DO FIND^DIC(40.8,,".07I;1","M",SEARCHTRM,,,,,"DATA","ERR")
End DoDot:1
+11 ; Otherwise just list all DIVISION from file 40.8
+12 IF SEARCHTRM=""
Begin DoDot:1
+13 KILL DATA,ERR
DO LIST^DIC(40.8,,".07I;1","",,,,,,,"DATA","ERR")
End DoDot:1
+14 IF $DATA(ERR)
Begin DoDot:1
+15 SET ERRORS("Division",1)=""
+16 SET ERRORS("Error",1)="Errors in "_$SELECT(SEARCHTRM'="":"FIND^DIC",1:"LIST^DIC")
+17 SET ERRORS("Error",2)=$GET(ERR("DIERR",1,"TEXT",1))
+18 DO BUILDJSON^SDESBUILDJSON(.RESULTS,.ERRORS)
QUIT
End DoDot:1
QUIT
+19 ; Build the FACARRY to then be returned
+20 DO BUILDATA(.DATA,.FACARRY)
+21 DO BUILDJSON^SDESBUILDJSON(.RESULTS,.FACARRY)
+22 QUIT
VALINPUT(ERRORS,INPUT) ;
+1 ; If INP is empty then just continue
if $GET(INPUT)=""
QUIT
+2 IF $LENGTH($GET(INPUT))<2
DO ERRLOG^SDESJSON(.ERRORS,64)
+3 QUIT
VALIDATEEAS(ERRORS,SDEAS) ;
+1 IF $LENGTH(SDEAS)
SET SDEAS=$$EASVALIDATE^SDESUTIL($GET(SDEAS))
+2 IF $PIECE($GET(SDEAS),U)=-1
DO ERRLOG^SDESJSON(.ERRORS,142)
+3 QUIT
BUILDATA(DATA,FACARRY) ; Build out array to be put into JSON format
+1 NEW DCNT,ITEM,DIVNM,DIVIEN,FACILITYNUM,INST,INSTIMEZONE,FACTYP,PARINST,INSTFAC,J,JJ,TZARRAY,JTZ
+2 SET (DCNT,ITEM,J)=0
FOR
SET ITEM=$ORDER(DATA("DILIST",1,ITEM))
if 'ITEM
QUIT
Begin DoDot:1
+3 SET (DIVNM,DIVIEN,FACILITYNUM,PARINST,FACTYP)=""
+4 SET DCNT=DCNT+1
+5 ; DIVISION Name
SET DIVNM=$GET(DATA("DILIST",1,ITEM))
+6 ; DIVISION IEN
SET DIVIEN=$GET(DATA("DILIST",2,ITEM))
+7 SET FACILITYNUM=$GET(DATA("DILIST","ID",ITEM,1))
+8 ; Parent Institution IEN
SET PARINST=$GET(DATA("DILIST","ID",ITEM,.07))
+9 SET FACARRY("Division",DCNT,"Name")=DIVNM
+10 SET FACARRY("Division",DCNT,"ID")=DIVIEN
+11 SET FACARRY("Division",DCNT,"FacilityNumber")=FACILITYNUM
+12 ; Get data from the instution file
+13 KILL INST,ERR
DO GETS^DIQ(4,PARINST_",","101;.01;99;11;13;800;802","IEP","INST","ERR")
+14 SET INSTIMEZONE=$GET(INST(4,PARINST_",",800,"I"))
+15 ; Get data from world timezone file
+16 IF INSTIMEZONE'=""
KILL TZARRAY,ERR
DO GETS^DIQ(1.71,INSTIMEZONE_",","1*","IE","TZARRAY","ERR")
+17 SET FACTYP=$GET(INST(4,PARINST_",",13,"I"))
+18 ; Get data from the Facility Type file
+19 IF FACTYP'=""
KILL INSTFAC,ERR
DO GETS^DIQ(4.1,FACTYP_",",".01;3","IE","INSTFAC","ERR")
+20 SET FACARRY("Division",DCNT,"Institution","Inactive")=$GET(INST(4,PARINST_",",101,"I"))
+21 SET FACARRY("Division",DCNT,"Institution","Name")=$GET(INST(4,PARINST_",",.01,"I"))
+22 SET FACARRY("Division",DCNT,"Institution","StationNumber")=$GET(INST(4,PARINST_",",99,"I"))
+23 SET FACARRY("Division",DCNT,"FacilityType","Name")=$GET(INSTFAC(4.1,FACTYP_",",.01,"I"))
+24 SET FACARRY("Division",DCNT,"FacilityType","Status")=$GET(INSTFAC(4.1,FACTYP_",",3,"I"))
+25 SET FACARRY("Division",DCNT,"ParentFacility")=PARINST
+26 SET FACARRY("Division",DCNT,"Status")=$GET(INST(4,PARINST_",",11,"I"))
+27 SET FACARRY("Division",DCNT,"InactiveFacilityFlag")=$GET(INST(4,PARINST_",",101,"I"))
+28 SET FACARRY("Division",DCNT,"TimeZone")=$GET(INST(4,PARINST_",",800,"E"))
+29 IF $DATA(TZARRAY(1.711))>0
SET JJ=""
SET J=0
FOR
SET JJ=$ORDER(TZARRAY(1.711,JJ))
if JJ=""
QUIT
Begin DoDot:2
+30 SET J=J+1
+31 SET FACARRY("Division",DCNT,"TimeZoneDetails",J,"TimeFrame")=$GET(TZARRAY(1.711,JJ,.01,"E"))
+32 SET FACARRY("Division",DCNT,"TimeZoneDetails",J,"Offset")=$GET(TZARRAY(1.711,JJ,.02,"E"))
+33 SET FACARRY("Division",DCNT,"TimeZoneDetails",J,"TimeZoneCode")=$GET(TZARRAY(1.711,JJ,.03,"E"))
End DoDot:2
+34 SET FACARRY("Division",DCNT,"TimeZoneException")=$GET(INST(4,PARINST_",",802,"E"))
End DoDot:1
+35 IF '$DATA(FACARRY)
SET FACARRY("Division",1)=""
+36 QUIT