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

SDES2UTIL1.m

Go to the documentation of this file.
SDES2UTIL1 ;ALB/MGD/TJB/MGD,TJB,BLB - SDES2 UTILITIES Continued ;FEB 08, 2024
 ;;5.3;Scheduling;**870,861,873,890**;Aug 13, 1993;Build 5
 ;;Per VHA Directive 6402, this routine should not be modified
 ;
 Q
VALBOOLEAN(SDERRORS,SDBOOLEAN,SDREQUIRED,SDERRORTEXT) ;
 ; SDERRORS = Array to hold any logged errors
 ; SDBOOLEAN = Boolean input array element to validate
 ; SDREQUIRED = 1:Required, 0:Optional, Defaults to 0
 ; SDERRORTEXT = Additional text to append to error message. This is normally the name of the input parameter element.
 ;
 I SDREQUIRED=0,SDBOOLEAN="" Q
 S SDREQUIRED=$S($G(SDREQUIRED)="":0,1:$G(SDREQUIRED))
 I SDREQUIRED=1,SDBOOLEAN="" D ERRLOG^SDESJSON(.SDERRORS,519,SDERRORTEXT)
 I SDBOOLEAN'="1",SDBOOLEAN'="0" D ERRLOG^SDESJSON(.SDERRORS,518,SDERRORTEXT)
 Q
 ;
GETRES(SDCL,INACT)  ; Extrinsic function to return resource for clinic - SDEC RESOURCE (409.831)
 ; SDCL = Clinic IEN from File 44
 ; INACT = If not null, skip check to see if resource is inactive
 ; Return value is the associated resource or the empty string
 ;
 ; SDHLN - Name of the Clinic from File 44
 ; SDI - Resource IEN from file 409.831
 ; SDRESTYP - RESOURCE TYPE, Field .012 from File 409.831
 N SDHLN,SDI,SDRESTYP,SDRES,SDRES1
 S (SDRES,SDRES1)=""
 S SDHLN=$$GET1^DIQ(44,SDCL_",",.01,"E")
 Q:SDHLN="" ""
 S SDI="" F  S SDI=$O(^SDEC(409.831,"ALOC",SDCL,SDI)) Q:SDI=""  D  Q:SDRES'=""
 .S SDRESTYP=$$GET1^DIQ(409.831,SDI_",",.012,"I")
 .I '$G(INACT) Q:$$GET1^DIQ(409.831,SDI_",",.02)="YES"
 .S:SDRES1="" SDRES1=SDI
 .Q:$P(SDRESTYP,";",2)'="SC("
 .S SDRES=SDI
 I SDRES="",SDRES1'="" S SDRES=SDRES1
 Q SDRES
 ;
GETGAF(DFN) ;
 N GAF,GAFR
 S GAF=$$NEWGAF^SDUTL2(DFN)
 S GAFR=""
 S:GAF="" GAF=-1
 S $P(GAFR,"|",1)=$S(+GAF:"New GAF Required",1:"No new GAF required")
 Q GAFR
 ;
ETHNLIST(ETHNICITY,DFN) ;get ethnicity list
 ;INPUT:
 ;  DFN = Patient ID pointer to PATIENT file
 ;RETURN:
 ;   PETH   - Patient Ethnicity list separated by pipe |
 ;               Pointer to ETHNICITY file 10.2
 ;   PETHN  - Patient Ethnicity names separated by pipe |
 N SDI,SDID,PETH,PETHN
 S (PETH,PETHN)=""
 S SDI=0 F  S SDI=$O(^DPT(DFN,.06,SDI)) Q:SDI'>0  D
 .S SDID=$P($G(^DPT(DFN,.06,SDI,0)),U,1)
 .S PETH=$S(PETH'="":PETH_"|",1:"")_SDID
 .S PETHN=$S(PETHN'="":PETHN_"|",1:"")_$P($G(^DIC(10.2,SDID,0)),U,1)
 S ETHNICITY("NAMES")=PETHN
 S ETHNICITY("IENS")=PETH
 Q
RACELIST(RACELST,DFN) ;get list of race information for given patient
 ;INPUT:
 ;  DFN = Patient ID pointer to PATIENT file
 ;RETURN:
 ;   RACEIEN  - Patient race list separated by pipe |
 ;               Pointer to RACE file 10
 ;   RACENAM  - Patient race names separated by pipe |
 N SDI,SDID,RACEIEN,RACENAM
 S (RACEIEN,RACENAM)=""
 S SDI=0 F  S SDI=$O(^DPT(DFN,.02,SDI)) Q:SDI'>0  D
 .S SDID=$P($G(^DPT(DFN,.02,SDI,0)),U,1)
 .S RACEIEN=$S(RACEIEN'="":RACEIEN_"|",1:"")_SDID
 .S RACENAM=$S(RACENAM'="":RACENAM_"|",1:"")_$P($G(^DIC(10,SDID,0)),U,1)
 S RACELST("NAMES")=RACENAM
 S RACELST("IENS")=RACEIEN
 Q
 ;
HRN(DFN) ;Health Record Number
 N X
 S X=$G(^AUPNPAT(DFN,41,+$G(DUZ(2)),0))
 Q $S($P(X,U,3):"",1:$P(X,U,2))
 ;
FLAGS(DFN,FNUM) ;get PRF flags
 ;INPUT:
 ; DFN  - Patient ID
 ; FNUM - PRF Flag file ID  26.15=PRF NATIONAL FLAG  26.11=PRF LOCAL FLAG
 ;RETURN:
 ;  Each | piece contains the following ;; pieces:
 ;   1. PRFAID   - PRF Assignment ID pointer to PRF ASSIGNMENT file (#26.13)
 ;   2. PRFSTAT  - PRF Assignment Status 0=INACTIVE 1=ACTIVE
 ;   3. PRFLID   - PRF Local Flag ID pointer to PRF LOCAL FLAG file (#26.11)
 ;   4. PRFLNAME - PRF Local Flag name
 ;   5. PRFLSTAT - PRF Local Flag status  0=INACTIVE 1=ACTIVE
 ;
 N PRFAID,PRFID,PRFLST,RET,STAT
 S RET=""
 S DFN=$G(DFN)
 Q:DFN="" ""
 Q:'$D(^DPT(DFN,0)) ""
 S FNUM=$G(FNUM)
 Q:(FNUM'=26.15)&(FNUM'=26.11) ""
 D FLST(.PRFLIST,FNUM)
 S PRFID="" F  S PRFID=$O(PRFLIST(PRFID)) Q:PRFID=""  D
 .S PRFAID="" F  S PRFAID=$O(^DGPF(26.13,"AFLAG",PRFID,DFN,PRFAID)) Q:PRFAID=""  D
 ..S STAT="" S STAT=$$GET1^DIQ(26.13,PRFAID_",",.03,"I") Q:STAT'=1
 ..S RET=RET_$S(RET'="":"|",1:"")_PRFAID_";;"_STAT_";;"_+PRFID_";;"_$P(PRFLIST(PRFID),U,1)_";;"_$P(PRFLIST(PRFID),U,2)
 Q RET
FLST(PRFLIST,FNUM)  ;build flag list
 N PRFID,PRFN
 K PRFLIST
 S PRFN="" F  S PRFN=$O(^DGPF(FNUM,"B",PRFN)) Q:PRFN=""  D
 .S PRFID="" F  S PRFID=$O(^DGPF(FNUM,"B",PRFN,PRFID)) Q:PRFID=""  D
 ..S PRFLIST(PRFID_";DGPF("_FNUM_",")=$$GET1^DIQ(FNUM,PRFID_",",.01)_U_$$GET1^DIQ(FNUM,PRFID_",",.02,"I")
 Q
 ;
CHECKDURATION(T1,T2,SLT) ;Ensure the appointment lengths align with the time segment
 N H1,H2,M1,M2,SDL,SD1
 S H1=$E(T1,1,2),H2=$E(T2,1,2),M1=$E(T1,3,4),M2=$E(T2,3,4)
 S:M1=0 M1=60,H1=H1-1
 S:M2=0 M2=60,H2=H2-1
 S SD1=M2-M1+((H2-H1)*60),SDL=SD1\SLT
 I SDL*SLT'=+SD1 Q 0
 Q 1
 ;
CREATE(DA,STARTDAY,SLT,DOW,INDEFINITEUNTIL,DATES,TIMES,SDDISPPERHR,SDRETURN,ERRORS) ;
 ;DA = Clinic IEN  (SDCLINIC)
 ;SLT - Appointment length
 N D0,X,CNT,STARTTIME,T1,T2,NSL,CTR,DR,HY,MAX,SC,SD,SDREB,SDSTRTDT,SDZQ,ST,STR,Y1,INDEFINITELY,STIME,SDRETURN
 N POP,LT,H1,H2,M1,M2,SDTOP,SDREACT,X,SI,ZDX,DH,DO,D,Y,SDEL,HSI,SDJJ,HHY,SDIN,SDRE,SDRE1,I,OK,X1,X2,A,SDA1,SDSOH,RETURN
 S POP=0
 S STARTTIME=STARTDAY*100
 S (HSI,SI)=$G(SDDISPPERHR,4)
 S:SI=1 SI=4,HSI=1
 S:SI=2 SI=4,HSI=2
 ;
 ;S DIC(0)="MAQEZL",(DIC,DIE)="^SC("_DA_",""T"",",DIC("W")=$P($T(DOW),";",3)
 S:'$D(^SC(DA,"T",0)) ^SC(DA,"T",0)="^44.002D"
 ;
 S D0=""
 F  S (SD,D0)=$O(DATES(D0)) Q:D0=""  D  Q:POP
 .Q:D0?7"9"
 .S (CNT,INDEFINITELY)=0
 .I $O(DATES(D0))?7"9" S INDEFINITELY=1
 .S STARTTIME=""
 .F  S STARTTIME=$O(TIMES(STARTTIME)) Q:STARTTIME=""  D  Q:POP
 ..S X=TIMES(STARTTIME)
 ..S T2=$P($P(X,"^",1),"-",2)
 ..S NSL=$P(X,"^",2)
 ..S T1=STARTTIME
 ..D G3  ;Set up time slots in the T node
 .;
 .D:'POP G5  ;Set up pattern for the date
 K DATES,TIMES
 Q
 ;
G3 ;
 ;
 ;
 S SDTOP=1 ;????
 S SDZQ=1
 ;
 S LT=T2,H1=$E(T1,1,2),H2=$E(T2,1,2),M1=$E(T1,3,4),M2=$E(T2,3,4)
 S M2=M2-SLT
G3A I M2<0 S M2=M2+60,H2=H2-1 G G3A
 S:M2?1N M2="0"_M2 S:H2?1N H2="0"_H2
G4 S CNT=CNT+1,^SC(DA,"T",D0,2,CNT,0)=H1_M1_"^"_NSL
 S M1=M1+SLT
G4A I M1>59 S M1=M1-60,H1=H1+1 G G4A
 S:M1?1N M1="0"_M1 S:H1?1N H1="0"_H1
 I (H1_M1)>(H2_M2) Q
 G G4
 Q
 ;
G5 ;
 S SDEL=0
 G:'CNT DEL1:'$D(SDREACT),DEL1:'$D(SDTOP)&$D(SDREACT)&'CNT,C^SDB
 S ^SC(DA,"T",D0,0)=D0,^SC(DA,"T",D0,2,0)="^44.004A^"_CNT_"^"_CNT
 S X=^SC(DA,"T",0),^SC(DA,"T",0)="^44.002D^"_D0_"^"_($P(X,"^",4)+1)
 S DH=SLT*SI\60
 F ZDX=CNT:0 S ZDX=$O(^SC(DA,"T",D0,2,ZDX)) Q:ZDX=""  K ^SC(DA,"T",D0,2,ZDX)
 F X=0:0 S X=$O(^SC(DA,"T",D0,2,X)) Q:X=""  D
 .S Y=^SC(DA,"T",D0,2,X,0)
 .F D=1:1:DH S Y(Y#100*SI\60+(Y\100*SI)-(STARTDAY*SI)+D)=$S($P(Y,U,2):$E("123456789jklmnopqrstuvwxyz",$P(Y,U,2)),1:0)
 S (DH,DO,X)=""
 I $D(Y)=1 S SDEL=1 G D
 I $D(HSI) I HSI=1!(HSI=2) D CKSI1
 F Y=1:1 S DH=$D(Y(Y)),X=X_$S('DH&D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A,"T"_DOW,D0,1)="",^SC(DA,"T"_DOW,D0,0)=D0 D TX
 S ^SC(DA,"T"_DOW,DO,1)=DH,^SC(DA,"T"_DOW,DO,0)=DO D TX
 S X=D0 D B1^SDB1 S MAX=$$DAYSINFUTURE(DA,SD),SC=DA,SDSTRTDT=SD
 Q:'CNT
 D OVR^SDAUT1 I $G(DO)'=9999999 S SDRETURN("ClinicAvailability","DateIndefiniteScheduleEnds")=$$FMTISO^SDAMUTDT($G(DO)) S INDEFINITEUNTIL=$$FMTISO^SDAMUTDT($G(DO)) Q:'SDZQ
 Q
 ;
DAYSINFUTURE(CLINICIEN,STARTDATE) ;
 N FUTUREBOOKINGNUM,FUTUREBOOKDATE,HOLIDAYFILEDATE
 ;
 S FUTUREBOOKINGNUM=$S($$GET1^DIQ(44,CLINICIEN,2002,"I"):$$GET1^DIQ(44,CLINICIEN,2002,"I"),1:390)
 S FUTUREBOOKDATE=$$FMADD^XLFDT(STARTDATE,FUTUREBOOKINGNUM)
 S HOLIDAYFILEDATE="",HOLIDAYFILEDATE=$O(^HOLIDAY("B",HOLIDAYFILEDATE),-1)
 ;
 I FUTUREBOOKDATE<HOLIDAYFILEDATE Q FUTUREBOOKINGNUM
 Q $$FMDIFF^XLFDT(HOLIDAYFILEDATE,STARTDATE)
 ;
1 I SDEL S POP=0 D APPCK I POP D DELERR G OVR
11 G:$D(^HOLIDAY(D,0))&('SDSOH) OVR
 S POP=0
 D:$D(SDIN) CHK2
 G:POP OVR
 S (POP,SDREB)=0
 S %=1
 D APPCK
 I POP D APPERR G:(%-1) OVR S SDREB=1
 S X=D,DO=X+1,^SC(DA,"ST",X,9)=D,SDREACT=1
 S:'$D(^SC(DA,"ST",0)) ^SC(DA,"ST",0)="^44.005DA^^" D B1^SDB1  ;
OVR ;
 I D#100<22 S D=D+7 S POP=0 D:$D(SDIN) CHK2 Q
 S X1=D,X2=7 D C^%DTC S D=X S POP=0 D:$D(SDIN) CHK2 Q
 ;
APPCK ;
 Q
APPERR ;
 N %
 Q
DELERR ;
 S Y=D
CHK1 Q:'$D(SDIN)
 I Y=SDIN S POP=1
 Q
 ;
CHK2 ;
 I SDIN<D,SDRE,SDRE'>D K SDIN Q
 I SDIN<D,SDRE=0 S POP=1 Q
 I SDIN<D,SDRE>D S POP=2,D=SDRE,X=D F I=0:1:6 D DOW^SDM0 Q:Y=DOW  S X1=D,X2=1 D C^%DTC S D=X
 S Y=SDIN D DTS^SDUTL S Y1=Y,Y=SDRE1 D DTS^SDUTL W:POP=2&('CTR) !!,"    Clinic is inactive from ",Y1," to ",Y,! S:POP=2 CTR=1
 Q
OB ;
 S SDSLOT=$E(STR,$F(STR,ST)-2)
 I SDSLOT?1P,SDSLOT'?1" " S ^SC(DA,"S",DR,1,Y,"OB")="O" K SDSLOT Q
 K ^SC(DA,"S",DR,1,Y,"OB"),SDSLOT
 Q
TX ;
 S:'$D(^SC(DA,"T"_DOW,0)) ^SC(DA,"T"_DOW,0)="^44.0"_$S(DOW<4:DOW+6,DOW<6:"0"_DOW+4,1:"001")_"A^^" Q
 ;
ERRLOG(ERNUM,OPTIONALTXT) ;
 S POP=1
 D ERRLOG^SDESJSON(.SDRETURN,$G(ERNUM),$G(OPTIONALTXT))
 Q
BUILDER ;
 N JSONERR
 S JSONERR=""
 D ENCODE^SDESJSON(.SDRETURN,.RETURN,.JSONERR)
 Q
 ;