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

SDECXUTL.m

Go to the documentation of this file.
SDECXUTL ;DALLAS/JCH - SCHEDULING ENHANCEMENTS 3 UTILITIES ;11/03/14 10:59am
 ;;5.3;Scheduling;**628**;Aug 13, 1993;Build 371
 ;
PADDT(DATE) ; leading zeroes
 N COUNT,STRING,DELIM
 S DELIM=$S(DATE["/":"/",DATE["-":"-",1:"")
 I DELIM="" Q ""
 F COUNT=1:1:$L(DATE,DELIM) S $P(DATE,DELIM,COUNT)=$TR($J($P(DATE,DELIM,COUNT),2)," ",0)
 Q DATE
 ;
HFSOPEN(HANDLE) ; Open file
 Q:'$G(SDEBUG)
 I SDEBUG=2 S IO=0 Q
 N SDDIR,SDFILE,POP,ZX
 N SDDEL,SDLIST,SDIN,SDOUT
 S SDFILE="SDEC_VSE.XML"
 S SDDIR="USER$:[CHEY229]"
 S SDIN="SDIN",SDOUT="SDOUT",SDIN(SDFILE)=""
 S SDLIST=$$LIST^%ZISH(SDDIR,SDIN,SDOUT)
 I SDLIST S ZX=$$DEL^%ZISH(SDDIR,"SDIN")
 D OPEN^%ZISH(HANDLE,SDDIR,SDFILE,"W") I 'POP S IOM=132,IOSL=99999,IOST="P-DUMMY",IOF="""""" Q
 I POP D  Q
 .N SDDIR,SDFILE S POP=0
 .S SDDIR=$$DEFDIR^%ZISH()
 .S SDFILE="sdec_vse.xml"
 .D OPEN^%ZISH(HANDLE,SDDIR,SDFILE,"W")
 .Q:POP  S IOM=132,IOSL=99999
 Q
 ;
HFSCLOSE(HANDLE) ; Close file
 Q:'$G(SDEBUG)
 Q:($G(SDEBUG)=2)
 N SDDIR,SDFILE,SDDEL
 D CLOSE^%ZISH(HANDLE)
 K ^TMP("SDO",$J)
 Q
 ;
GETQUART(SDDT)  ; Return quarter
 K SDQUART N MONTH,YEAR
 S YEAR=$$FMTE^XLFDT($E(SDDT,1,3)_"0000")
 S MONTH=$E(SDDT,4,5)
 S SDQUART=$S(MONTH<4:"Q1",MONTH<7:"Q2",MONTH<10:"Q3",MONTH<13:"Q4",1:"Q0")
 ;S SDQUART=SDQUART_"-"_YEAR
 S SDQUART=YEAR_"-"_SDQUART
 Q SDQUART
 ;
DIVNAME(DIV) ; Division name
 K DIVNAME
 I DIV="All" Q DIV
 N DIE,DIQ,DIR,DA,X,Y,DIC,DR
 S DIQ(0)="I",DIC=40.8,DA=+$G(DIV),DR=".01"
 D GETS^DIQ(DIC,DA,DR,"I","DIVNAME")
 S DIVNAME=$G(DIVNAME(DIC,DA_",",.01,"I"))
 I DIVNAME="" S DIVNAME=$P($$SITE^VASITE,"^",2)
 Q $$SYMENC^MXMLUTL(DIVNAME)
 ;
OUTPUT(TEXT,PAD,SDLCNT,SDEBUG,CLNTAG,GRPFLG,DIVTAG,XMLNODE) ; Generic Set/Output
 I $G(XMLNODE)="" S XMLNODE=$S($G(SDFLTFLG):"FLTXML",1:"SDECXML")
 I TEXT["/Rg" S GRPFLG=0
 I TEXT["/Rs" S CLNTAG=0
 I TEXT["/Div" S DIVTAG=0
 I TEXT["&" N TMP S TMP=TEXT S TMP=$$PARSE^SDECXML(TEXT,"&","&"),TEXT=TMP
 I TEXT["'" N TMP S TMP=TEXT S TMP=$$PARSE^SDECXML(TEXT,"'","'"),TEXT=TMP
 S SDLCNT=$G(SDLCNT)+1
 I $G(SDEBUG) U IO W:(SDLCNT>1) ! W ?PAD,TEXT
 S ^XTMP("SDVSE",XMLNODE,SDLCNT)=TEXT
 Q
 ;
XDATE(DATE,DTINC) ; Date format
 N STRING
 I DATE["-" D  Q XDATE
 .N X1,X2
 .S X1=$P(DATE,"-"),X2=$P(DATE,"-",2)
 .S XDATE=$$PADDT^SDECXUTL($P($$FMTE^XLFDT(X1,5),"@"))_"-"_$$PADDT^SDECXUTL($P($$FMTE^XLFDT(X2,5),"@"))
 S XDATE=$$PADDT^SDECXUTL($P($$FMTE^XLFDT(DATE,5),"@"))
 Q XDATE
 ;
BEGEND(DATE,BEGDT,ENDDT,DTINC,SDACTDT) ; Accept activity Date, Set/Write formatted xml with begin and end dates
 N XDATE,ZDATE
 S BEGDT=DATE,ENDDT=DATE
 I DTINC="D" D  Q
 .S BEGDT=$$XDATE(DATE),ENDDT=$$XDATE(DATE)
 I DTINC="W" D  Q
 .S ENDDT=$$XDATE(DATE),BEGDT=$$XDATE($$FMADD^XLFDT(DATE,-6))
 I DTINC="M" D  Q
 .S BEGDT=$E(DATE,1,5)_"01"
 .S ENDDT=$E($$FMADD^XLFDT(BEGDT,32),1,5)_"01",ENDDT=$P($$FMADD^XLFDT(ENDDT,,-1),"@")
 .S BEGDT=$$XDATE(BEGDT),ENDDT=$$XDATE(ENDDT)
 I DTINC="Y" D  Q
 .S ENDDT=$$XDATE($$FMADD^XLFDT(SDACTDT,,,1)),BEGDT=$$XDATE($$FMADD^XLFDT(SDACTDT,-365))
 I DTINC="Q" D  Q
 .N QUART,QDATE,QYR
 .I $E($P(DATE,"-",2))="Q" S QDATE=$S(DATE["Q1":"0101",DATE["Q2":"0401",DATE["Q3":"0701",DATE["Q4":"1001",1:"") D
 ..N X,%DT S %DT="I",X=$E(QDATE,1,2)_"/"_$E(QDATE,3,4)_"/"_$P(DATE,"-") D ^%DT I Y S (ZDATE,DATE)=Y
 .S QUART=$S(SDDATE'["Q":$$GETQUART^SDCED1(DATE),1:SDDATE)
 .S BEGDT=$S(QUART["Q1":"0101",QUART["Q2":"0401",QUART["Q3":"0701",QUART["Q4":"1001",1:"")
 .S BEGDT=$E(DATE,1,3)_BEGDT
 .S ENDDT=$$FMADD^XLFDT(BEGDT,94),ENDDT=$E(ENDDT,1,5)_"01",ENDDT=$P($$FMADD^XLFDT(ENDDT,,-1),"@")
 .S BEGDT=$$XDATE(BEGDT),ENDDT=$$XDATE(ENDDT)
 Q
 ;
NODATA(RESULT,TEXT)  ; Return Empty set and queue new build when data build has not run for the day
 N SDFAC,SDLCNT,DATINC,SDDATE,SDFILT,XMLNODE
 I $G(TEXT)="" S TEXT="Resource Management Report Filters are compiling. Please try again later."
 S XMLNODE="NOFLTXML"
 S SDEBUG=$G(SDEBUG)
 S SDDATE=$$NOW^XLFDT,SDACTDT=$$FMTE^XLFDT(SDDATE)
 S SDFAC=$P($$SITE^VASITE,"^",2),SDLCNT=0,DATINC="Date"
 D QUEUE^SDCED
 D OUTPUT^SDECXUTL("<?xml version=""1.0"" encoding=""UTF-8""?>",0,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 S SDFILT=$$FAC^SDECXML(SDFAC) D SETFILT^SDECXML(.SDLCNT,SDFILT,2)
 D OUTPUT^SDECXUTL("<ReportType ReportType="""_TEXT_""">",4,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 D OUTPUT^SDECXUTL("<DateAggregate DateAgg="""">",6,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 D OUTPUT^SDECXUTL("</DateAggregate>",6,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 D OUTPUT^SDECXUTL("</ReportType>",4,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 D OUTPUT^SDECXUTL("</VAFacility>",2,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 S RESULT=$NAME(^XTMP("SDVSE",XMLNODE))
 Q
 ;
SUPPLY(SDSTPAR) ; SUPPLY
 I '$D(SDSTPAR) D GETCLNS^SDECSTP(.SDSTPAR)
 N GETSUP,SDBDATE,SDECLN,SDEDATE
 I $G(SDNODE)="" S SDNODE="SDCEX"
 N SDEXCLN,ACTIVE,SSDATE,TMPDT,SUPPLY,SDOW,NXTWK,SDSUPPLY
 S SUPPLY="",SDECLN=$G(SDECLN)
 S SDEDATE=DT,SDBDATE=$$FMADD^XLFDT(SDEDATE,-365)
 S SDEXCLN=$S($G(SDECLN):SDECLN-1,1:0)
 F  S SDEXCLN=$O(^SC(SDEXCLN)) Q:'SDEXCLN  D
 . Q:'$$ACTLOC^SDWU(SDEXCLN)
 . Q:$$NONCNT^SDCED(SDEXCLN)
 . S SDSUPPLY=""
 . S TMPDT=$P(SDBDATE,".") F  S SDSUPPLY=$$GETSUP2^SDCED2(SDEXCLN,TMPDT) Q:TMPDT>$P(SDEDATE,".")  D
 . . I $G(SDSUPPLY) D SET(SDEXCLN,TMPDT,SDSUPPLY,.SDSTPAR)
 . . S TMPDT=$$FMADD^XLFDT(TMPDT,1)
 Q
 ;
SET(SDEXCLN,TMPDT,SDSUPPLY,SDSTPAR)  ; Set supply
 N SDSGNM
 S SDSGNM="" D GETSCAT^SDCED(SDEXCLN,.SDSGNM,.SDSTPAR) ; Get Stop Code Group Name
 Q:SDSGNM="UNKNOWN"
 S ^TMP(SDNODE,$J,$E(SDSGNM),+SDEXCLN,TMPDT,0,"APP","SUP")=$FN(SDSUPPLY,",",2)
 Q
 ;
SDGRP(CLN,SDGRP) ; Get external stop code from clinic
 N STOPIEN,STOPGRP
 S SDGRP=""
 S STOPIEN=$$STOPIEN(CLN)
 I STOPIEN S SDGRP=$$STOPGRP(STOPIEN)
 I SDGRP="" S SDGRP="UNKNOWN"
 Q
 ;
STOPGRP(STP)  ; Get Stop Group number
 N DIE,DIQ,DIR,DA,X,Y,DIC,DR
 S DIQ(0)="I",DIC=40.7,DA=+$G(STP),DR=".01;1"
 D GETS^DIQ(DIC,DA,DR,"I","STOPGRP")
 S STOPGRP=$G(STOPGRP(DIC,DA_",",1,"I"))
 S STOPGRP=STOPGRP_"^"_$G(STOPGRP(DIC,DA_",",.01,"I"))
 Q STOPGRP
 ;
STOPIEN(CLN)  ; Get Stop IEN from clinic
 N DIE,DIQ,DIR,DA,X,Y,DIC,DR
 S DIQ(0)="I",DIC=44,DA=+$G(CLN),DR="8"
 D GETS^DIQ(DIC,DA,DR,"I","STOPIEN")
 S STOPIEN=$G(STOPIEN(DIC,DA_",",8,"I"))
 Q STOPIEN
 ;
GETSUPM(DATE,RPT) ; Get a months worth of supply for month containing DATE
 ; ^XTMP("SDCEX","Month","P",3140600,500,"APP","SUP")=543
 N FAC,MONTH
 S MONTH=$E(DATE,1,5)_"00",FAC=+$$SITE^VASITE
 S MONTHSUP=+$G(^XTMP("SDCEX","Month",RPT,MONTH,FAC,"APP","SUP"))
 Q MONTHSUP
 ;
GETDEMM(DATE,RPT)  ; Total Monthly Demand
 N FAC,MONTH
 S MONTH=$E(DATE,1,5)_"00",FAC=+$$SITE^VASITE
 S MONTHDEM=+$G(^XTMP("SDCEX","Month",RPT,MONTH,FAC,"APP","DEM"))
 Q MONTHDEM
 Q
 ;
SETSDREC(SDLCNT,SDRPTYP,START,XMLNODE)  ; Monthly supply and Demand
 ; Get previous 12 months, write total supply and demand for each month
 N TMPDT,X,Y,SDDEM,SDSUP,MONTH,I,MONTHDEM,MONTHSUP
 S TMPDT=$S($G(START)?7N:START,1:$$NOW^XLFDT)
 D OUTPUT^SDECXUTL("<chartData>",4,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 S MONTH=$E(TMPDT,1,5)_"00"
 F I=1:1:12 D
 .S SDDEM=$$MONDEM($$GETDEMM(TMPDT,SDRPTYP),MONTH)
 .D OUTPUT^SDECXUTL("<"_SDDEM_"/>",5,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 .S SDSUP=$$MONSUP($$GETSUPM(TMPDT,SDRPTYP),MONTH)
 .D OUTPUT^SDECXUTL("<"_SDSUP_"/>",5,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 .S TMPDT=$$FMADD^XLFDT(TMPDT,-32)
 .S MONTH=$E(TMPDT,1,5)_"00"
 D OUTPUT^SDECXUTL("</chartData>",4,.SDLCNT,SDEBUG,.CLNTAG,.GRPFLG,.DIVTAG,XMLNODE)
 Q
 ;
MONDEM(DEM,MONTH,SDLCNT) ; Demand
 N TMPMON,TMPLEN
 S DEM=DEM/60
 S TMPMON=$$FMTE^XLFDT(MONTH,1),TMPLEN=$L(TMPMON)
 S TMPMON=$P(TMPMON," ")_"-"_$E(TMPMON,TMPLEN-1,TMPLEN)
 S MONTH=TMPMON
 S STRING="cR Name=""TotalDemand"" cMonth="""_$$FMTE^XLFDT(MONTH,2)_""" Vt=""Actual"" cVl="""_+$P(DEM,".")_""""
 Q STRING
MONSUP(SUP,MONTH) ; Supply
 N TMPMON,TMPLEN
 S TMPMON=$$FMTE^XLFDT(MONTH,1),TMPLEN=$L(TMPMON)
 S TMPMON=$P(TMPMON," ")_"-"_$E(TMPMON,TMPLEN-1,TMPLEN)
 S MONTH=TMPMON
 S STRING="cR Name=""TotalSupply"" cMonth="""_$$FMTE^XLFDT(MONTH,2)_""" Vt=""Actual"" cVl="""_+$P(SUP,".")_""""
 Q STRING
 ; 
GETDIVCL(SDNODE,DATINC,SDRPTYP,SDAT,SDFAC,DIV,DIVCLNAR)  ; Get clinics in division DIV
 N TMPGRP,TMPCLN
 S TMPGRP=0 F  S TMPGRP=$O(^XTMP(SDNODE,DATINC,SDRPTYP,SDAT,SDFAC,DIV,TMPGRP)) Q:TMPGRP=""  D
 .Q:TMPGRP="APP"
 .S TMPCLN="" F  S TMPCLN=$O(^XTMP(SDNODE,DATINC,SDRPTYP,SDAT,SDFAC,DIV,TMPGRP,TMPCLN)) Q:TMPCLN=""  D
 ..Q:TMPCLN="APP"
 ..S DIVCLNAR(DIV,TMPCLN)=""
 Q
 ;
DTNAM(DTINC,DTNAM)  ; Get date name from abbreviation
 S DTNAM=""
 N NAME F NAME="Year","Quarter","Month","Week","Date" Q:DTNAM]""  I $E(NAME)=DTINC S DTNAM=NAME
 Q
 ;
 ;
SDETFM(DATE) ; Convert ext date to fm
 N X,Y,DATNAM
 S SDINTDT=""
 I ($G(DATE)?7N)!($G(DATE)?7N1"."1.N) Q
 S X=DATE D ^%DT I Y>0 S SDINTDT=+Y
 S DATE=$S($G(SDINTDT):SDINTDT,1:DATE)
 Q