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

BGP3UTL.m

Go to the documentation of this file.
BGP3UTL ; IHS/CMI/LAB - UTILITIES
 ;;13.0;IHS CLINICAL REPORTING;**1**;NOV 20, 2012;Build 7
 ;
VER() ;EP
 Q "CRS 2013 Version 13.0"
STMP ;EP
 Q:BGPTIME'=1
 I BGPLIST="P",$P(^AUPNPAT(DFN,0),U,14)'=BGPLPRV Q
 X ^BGPINDH(BGPIC,2) Q:'$T
 S BGPLIST(BGPIC)=$G(BGPLIST(BGPIC))+1
 NEW A
 I $P(^BGPINDH(BGPIC,0),U,2)=151 S A=BGPAGEE G SL
 I $P(^BGPINDH(BGPIC,0),U,2)=171 S A=BGPAGEE G SL
 S A=BGPAGEB
SL ;
 S ^XTMP("BGP3D",BGPJ,BGPH,"LIST",BGPIC,$S($P($G(^AUPNPAT(DFN,11)),U,18)]"":$P(^AUPNPAT(DFN,11),U,18),1:"UNKNOWN"),$P(^DPT(DFN,0),U,2),A,DFN)=$G(BGPVALUE)
 Q
D(D) ;EP
 I D="" Q ""
 Q (1700+$E(D,1,3))_$E(D,4,5)_$E(D,6,7)_$S($P(D,".",2)]"":$P(D,".",2),1:"")
JRNL ;EP
 N (DT,U,ZTQUEUED) S %=$$NOJOURN^ZIBGCHAR("BGPGPDCH"),%=$$NOJOURN^ZIBGCHAR("BGPGPDPH"),%=$$NOJOURN^ZIBGCHAR("BGPGPDBH"),%=$$NOJOURN^ZIBGCHAR("BGPHEDCB"),%=$$NOJOURN^ZIBGCHAR("BGPHEDPB"),%=$$NOJOURN^ZIBGCHAR("BGPHEDBB")
 S %=$$NOJOURN^ZIBGCHAR("BGPDATA"),%=$$NOJOURN^ZIBGCHAR("BGPGUI")
 S %=$$NOJOURN^ZIBGCHAR("BGPELDCH"),%=$$NOJOURN^ZIBGCHAR("BGPELDPH"),%=$$NOJOURN^ZIBGCHAR("BGPELDBH")
 S %=$$NOJOURN^ZIBGCHAR("BGPEOCB"),%=$$NOJOURN^ZIBGCHAR("BGPEOPB"),%=$$NOJOURN^ZIBGCHAR("BGPEOBB")
 S %=$$NOJOURN^ZIBGCHAR("BGPXPH")
 Q
DATE(D) ;EP
 I D="" Q ""
 Q $E(D,4,5)_"/"_$E(D,6,7)_"/"_$E(D,2,3)
 ;
EDT(D) ;EP
 I D="" Q ""
 Q $E(D,4,5)_"/"_$E(D,6,7)_"/"_(1700+$E(D,1,3))
 ;
SETHDR ;EP
 S BGPX="",$P(BGPX,U,1)="Site Name",$P(BGPX,U,2)="ASUFAC",$P(BGPX,U,3)="DB Id",$P(BGPX,U,4)="Date Report Run",$P(BGPX,U,5)="Current Report Begin Date",$P(BGPX,U,6)="Current Report End Date",$P(BGPX,U,7)="Previous Year Begin Date"
 S $P(BGPX,U,8)="Previous Year End Date",$P(BGPX,U,9)="Baseline Year Begin Date",$P(BGPX,U,10)="Baseline Year End Date"
 Q
ONN1 ;EP
 K BGPEXCT
 S Y=$$OPEN^%ZISH(BGPUF,BGPFONN1,"W")
 I Y=1 W:'$D(ZTQUEUED) !!,"Cannot open host file." Q
 U IO
 S BGPP=0,BGPY=$O(^BGPCTRL("B","2013",0)),BGPX="",BGPEC=$P(^BGPCTRL(BGPY,0),U,2)
 F  S BGPP=$O(^BGPCTRL(BGPY,36,BGPP)) Q:BGPP'=+BGPP  D
 .S BGPPP1=$P(^BGPCTRL(BGPY,36,BGPP,0),U,1)
 .S BGPZ=$P(^BGPCTRL(BGPY,36,BGPP,0),U,2)
 .S $P(BGPX,U,BGPPP1)=BGPZ
 W BGPX,!
 K BGPX
 S BGPX="" S P=11 F  S $P(BGPX,U,P)="Current",P=P+9 Q:P>(BGPEC-8)
 S P=14 F  S $P(BGPX,U,P)="Previous",P=P+9 Q:P>(BGPEC-5)
 S P=17 F  S $P(BGPX,U,P)="Baseline",P=P+9 Q:P>(BGPEC+1)
 W BGPX,!
 K BGPX
 D SETHDR
 S P=11 F  S $P(BGPX,U,P)="Num",P=P+3 Q:P>(BGPEC-2)
 S P=12 F  S $P(BGPX,U,P)="Den",P=P+3 Q:P>(BGPEC-1)
 S P=13 F  S $P(BGPX,U,P)="%",P=P+3 Q:P>BGPEC
 W BGPX,!
 S BGPX=0 F  S BGPX=$O(BGPONN1(BGPX)) Q:BGPX'=+BGPX  W BGPONN1(BGPX),!
 K BGPONN1
 D ^%ZISC
ONN2 ;
 K BGPEXCT
 S Y=$$OPEN^%ZISH(BGPUF,BGPFONN2,"W")
 I Y=1 W:'$D(ZTQUEUED) !!,"Cannot open host file." Q
 U IO
 S BGPP=0,BGPY=$O(^BGPCTRL("B","2013",0)),BGPX="",BGPEC=$P(^BGPCTRL(BGPY,0),U,3)
 F  S BGPP=$O(^BGPCTRL(BGPY,37,BGPP)) Q:BGPP'=+BGPP  D
 .S BGPPP1=$P(^BGPCTRL(BGPY,37,BGPP,0),U,1)
 .S BGPZ=$P(^BGPCTRL(BGPY,37,BGPP,0),U,2)
 .S $P(BGPX,U,BGPPP1)=BGPZ
 W BGPX,!
 K BGPX
 S BGPX="" S P=11 F  S $P(BGPX,U,P)="Current",P=P+9 Q:P>(BGPEC-8)
 S P=14 F  S $P(BGPX,U,P)="Previous",P=P+9 Q:P>(BGPEC-5)
 S P=17 F  S $P(BGPX,U,P)="Baseline",P=P+9 Q:P>(BGPEC+1)
 W BGPX,!
 K BGPX
 D SETHDR
 S P=11 F  S $P(BGPX,U,P)="Num",P=P+3 Q:P>(BGPEC-2)
 S P=12 F  S $P(BGPX,U,P)="Den",P=P+3 Q:P>(BGPEC-1)
 S P=13 F  S $P(BGPX,U,P)="%",P=P+3 Q:P>BGPEC
 W BGPX,!
 S BGPX=0 F  S BGPX=$O(BGPONN2(BGPX)) Q:BGPX'=+BGPX  W BGPONN2(BGPX),!
 K BGPONN2
ONN3 ;
 K BGPEXCT
 S Y=$$OPEN^%ZISH(BGPUF,BGPFONN3,"W")
 I Y=1 W:'$D(ZTQUEUED) !!,"Cannot open host file." Q
 U IO
 S BGPP=0,BGPY=$O(^BGPCTRL("B","2013",0)),BGPX="",BGPEC=$P(^BGPCTRL(BGPY,0),U,21)
 F  S BGPP=$O(^BGPCTRL(BGPY,45,BGPP)) Q:BGPP'=+BGPP  D
 .S BGPPP1=$P(^BGPCTRL(BGPY,45,BGPP,0),U,1)
 .S BGPZ=$P(^BGPCTRL(BGPY,45,BGPP,0),U,2)
 .S $P(BGPX,U,BGPPP1)=BGPZ
 W BGPX,!
 K BGPX
 S BGPX="" S P=11 F  S $P(BGPX,U,P)="Current",P=P+9 Q:P>(BGPEC-8)
 S P=14 F  S $P(BGPX,U,P)="Previous",P=P+9 Q:P>(BGPEC-5)
 S P=17 F  S $P(BGPX,U,P)="Baseline",P=P+9 Q:P>(BGPEC+1)
 W BGPX,!
 K BGPX
 D SETHDR
 S P=11 F  S $P(BGPX,U,P)="Num",P=P+3 Q:P>(BGPEC-2)
 S P=12 F  S $P(BGPX,U,P)="Den",P=P+3 Q:P>(BGPEC-1)
 S P=13 F  S $P(BGPX,U,P)="%",P=P+3 Q:P>BGPEC
 W BGPX,!
 S BGPX=0 F  S BGPX=$O(BGPONN3(BGPX)) Q:BGPX'=+BGPX  W BGPONN3(BGPX),!
 K BGPONN3
ONNC D ^%ZISC
 D ONN4^BGP3UTL3
 Q
GNT1 ;EP - area export file
 K BGPEXCT
 I '$G(BGPAREAA) G Q1
 S Y=$$OPEN^%ZISH(BGPUF,BGPFGNT1,"W")
 I Y=1 W:'$D(ZTQUEUED) !!,"Cannot open host file." Q
 U IO
 S BGPP=0,BGPY=$O(^BGPCTRL("B","2013",0)),BGPX="",BGPEC=$P(^BGPCTRL(BGPY,0),U,4)
 F  S BGPP=$O(^BGPCTRL(BGPY,38,BGPP)) Q:BGPP'=+BGPP  D
 .S BGPPP1=$P(^BGPCTRL(BGPY,38,BGPP,0),U,1)
 .S BGPZ=$P(^BGPCTRL(BGPY,38,BGPP,0),U,2)
 .S $P(BGPX,U,BGPPP1)=BGPZ
 W BGPX,!
 K BGPX
 S BGPX="" S P=11 F  S $P(BGPX,U,P)="Current",P=P+9 Q:P>(BGPEC-8)
 S P=14 F  S $P(BGPX,U,P)="Previous",P=P+9 Q:P>(BGPEC-5)
 S P=17 F  S $P(BGPX,U,P)="Baseline",P=P+9 Q:P>(BGPEC+1)
 W BGPX,!
 K BGPX
 D SETHDR
 S P=11 F  S $P(BGPX,U,P)="Num",P=P+3 Q:P>(BGPEC-2)
 S P=12 F  S $P(BGPX,U,P)="Den",P=P+3 Q:P>(BGPEC-1)
 S P=13 F  S $P(BGPX,U,P)="%",P=P+3 Q:P>BGPEC
 W BGPX,!
 K BGPX
 S BGPX=0 F  S BGPX=$O(BGPEI(BGPX)) Q:BGPX'=+BGPX  W BGPEI(BGPX),!
 D ^%ZISC
Q1 ;
 K BGPEI
GNT2 ;
 K BGPEXCT
 I '$G(BGPAREAA) G Q2
 S Y=$$OPEN^%ZISH(BGPUF,BGPFGNT2,"W")
 I Y=1 W:'$D(ZTQUEUED) !!,"Cannot open host file." Q
 U IO
 S BGPP=0,BGPY=$O(^BGPCTRL("B","2013",0)),BGPX="",BGPEC=$P(^BGPCTRL(BGPY,0),U,16)
 F  S BGPP=$O(^BGPCTRL(BGPY,40,BGPP)) Q:BGPP'=+BGPP  D
 .S BGPPP1=$P(^BGPCTRL(BGPY,40,BGPP,0),U,1)
 .S BGPZ=$P(^BGPCTRL(BGPY,40,BGPP,0),U,2)
 .S $P(BGPX,U,BGPPP1)=BGPZ
 W BGPX,!
 K BGPX
 S BGPX="" S P=11 F  S $P(BGPX,U,P)="Current",P=P+9 Q:P>(BGPEC-8)
 S P=14 F  S $P(BGPX,U,P)="Previous",P=P+9 Q:P>(BGPEC-5)
 S P=17 F  S $P(BGPX,U,P)="Baseline",P=P+9 Q:P>(BGPEC+1)
 W BGPX,!
 K BGPX
 D SETHDR
 S P=11 F  S $P(BGPX,U,P)="Num",P=P+3 Q:P>(BGPEC-2)
 S P=12 F  S $P(BGPX,U,P)="Den",P=P+3 Q:P>(BGPEC-1)
 S P=13 F  S $P(BGPX,U,P)="%",P=P+3 Q:P>BGPEC
 W BGPX,!
 K BGPX
 S BGPX=0 F  S BGPX=$O(BGPEI2(BGPX)) Q:BGPX'=+BGPX  W BGPEI2(BGPX),!
Q2 ;
 K BGPEI2
 D ^%ZISC
Q3 ;
 D GNT3^BGP3UTLC
 Q
GS ;EP
 K ^TMP($J)
 L +^BGPDATA:300 E  W:'$D(ZTQUEUED) "Unable to lock global" Q
 ;NOTE:  Kill of unscripted global.  Export to area.  Using standard name.
 S BGPENDN=$S($P(^BGPSITE(DUZ(2),0),U,11)=0:88887,1:99998)
 K ^BGPDATA S X="",C=0 F  S X=$O(^BGPGPDCH(BGPRPT,X)) Q:X'=+X!(X>BGPENDN)  D
 .I $G(^BGPGPDCH(BGPRPT,X))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",8)=^BGPGPDCH(BGPRPT,X)
 .S X2="" F  S X2=$O(^BGPGPDCH(BGPRPT,X,X2)) Q:X2'=+X2  D
 ..I $G(^BGPGPDCH(BGPRPT,X,X2))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",8)=^BGPGPDCH(BGPRPT,X,X2)
 ..S X3="" F  S X3=$O(^BGPGPDCH(BGPRPT,X,X2,X3)) Q:X3'=+X3  D
 ...I $G(^BGPGPDCH(BGPRPT,X,X2,X3))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3,$P(^BGPDATA(C),"|",8)=^BGPGPDCH(BGPRPT,X,X2,X3)
 ...S X4="" F  S X4=$O(^BGPGPDCH(BGPRPT,X,X2,X3,X4)) Q:X4'=+X4  D
 ....I $G(^BGPGPDCH(BGPRPT,X,X2,X3,X4))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3,$P(^BGPDATA(C),"|",4)=X4,$P(^BGPDATA(C),"|",8)=^BGPGPDCH(BGPRPT,X,X2,X3,X4)
 ....S X5="" F  S X5=$O(^BGPGPDCH(BGPRPT,X,X2,X3,X4,X5)) Q:X5'=+X5  D
 .....I $G(^BGPGPDCH(BGPRPT,X,X2,X3,X4,X5))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3
 .....S $P(^BGPDATA(C),"|",4)=X4,$P(^BGPDATA(C),"|",5)=X5,$P(^BGPDATA(C),"|",8)=^BGPGPDCH(BGPRPT,X,X2,X3,X4,X5)
 S X=0 F  S X=$O(^BGPDATA(X)) Q:X'=+X  S ^BGPDATA(X)="BGPGPDCH"_"|"_^BGPDATA(X)
PRGS ;
 S S=C+1,X="" F  S X=$O(^BGPGPDPH(BGPRPT,X)) Q:X'=+X!(X>99998)  D
 .I $G(^BGPGPDPH(BGPRPT,X))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",8)=^BGPGPDPH(BGPRPT,X)
 .S X2="" F  S X2=$O(^BGPGPDPH(BGPRPT,X,X2)) Q:X2'=+X2  D
 ..I $G(^BGPGPDPH(BGPRPT,X,X2))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",8)=^BGPGPDPH(BGPRPT,X,X2)
 ..S X3="" F  S X3=$O(^BGPGPDPH(BGPRPT,X,X2,X3)) Q:X3'=+X3  D
 ...I $G(^BGPGPDPH(BGPRPT,X,X2,X3))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3,$P(^BGPDATA(C),"|",8)=^BGPGPDPH(BGPRPT,X,X2,X3)
 ...S X4="" F  S X4=$O(^BGPGPDPH(BGPRPT,X,X2,X3,X4)) Q:X4'=+X4  D
 ....I $G(^BGPGPDPH(BGPRPT,X,X2,X3,X4))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3,$P(^BGPDATA(C),"|",4)=X4,$P(^BGPDATA(C),"|",8)=^BGPGPDPH(BGPRPT,X,X2,X3,X4)
 ....S X5="" F  S X5=$O(^BGPGPDPH(BGPRPT,X,X2,X3,X4,X5)) Q:X5'=+X5  D
 .....I $G(^BGPGPDPH(BGPRPT,X,X2,X3,X4,X5))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3
 .....S $P(^BGPDATA(C),"|",4)=X4,$P(^BGPDATA(C),"|",5)=X5,$P(^BGPDATA(C),"|",8)=^BGPGPDPH(BGPRPT,X,X2,X3,X4,X5)
 S X=S-1 F  S X=$O(^BGPDATA(X)) Q:X'=+X  S ^BGPDATA(X)="BGPGPDPH"_"|"_^BGPDATA(X)
BLGS ;
 S S=C+1,X="" F  S X=$O(^BGPGPDBH(BGPRPT,X)) Q:X'=+X!(X>99998)  D
 .I $G(^BGPGPDBH(BGPRPT,X))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",8)=^BGPGPDBH(BGPRPT,X)
 .S X2="" F  S X2=$O(^BGPGPDBH(BGPRPT,X,X2)) Q:X2'=+X2  D
 ..I $G(^BGPGPDBH(BGPRPT,X,X2))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",8)=^BGPGPDBH(BGPRPT,X,X2)
 ..S X3="" F  S X3=$O(^BGPGPDBH(BGPRPT,X,X2,X3)) Q:X3'=+X3  D
 ...I $G(^BGPGPDBH(BGPRPT,X,X2,X3))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3,$P(^BGPDATA(C),"|",8)=^BGPGPDBH(BGPRPT,X,X2,X3)
 ...S X4="" F  S X4=$O(^BGPGPDBH(BGPRPT,X,X2,X3,X4)) Q:X4'=+X4  D
 ....I $G(^BGPGPDBH(BGPRPT,X,X2,X3,X4))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3,$P(^BGPDATA(C),"|",4)=X4,$P(^BGPDATA(C),"|",8)=^BGPGPDBH(BGPRPT,X,X2,X3,X4)
 ....S X5="" F  S X5=$O(^BGPGPDBH(BGPRPT,X,X2,X3,X4,X5)) Q:X5'=+X5  D
 .....I $G(^BGPGPDBH(BGPRPT,X,X2,X3,X4,X5))]"" S C=C+1,$P(^BGPDATA(C),"|")=X,$P(^BGPDATA(C),"|",2)=X2,$P(^BGPDATA(C),"|",3)=X3
 .....S $P(^BGPDATA(C),"|",4)=X4,$P(^BGPDATA(C),"|",5)=X5,$P(^BGPDATA(C),"|",8)=^BGPGPDBH(BGPRPT,X,X2,X3,X4,X5)
 S X=S-1 F  S X=$O(^BGPDATA(X)) Q:X'=+X  S ^BGPDATA(X)="BGPGPDBH"_"|"_^BGPDATA(X)
 I $G(BGPAMEX) D AUTOEX^BGP3AUEX Q  ;AUTO
 NEW XBGL S XBGL="BGPDATA"
 S F="BG130"_$P(^AUTTLOC(DUZ(2),0),U,10)_"."_$S(BGPRTYPE=7:"ONM",1:"")_BGPRPT
 NEW XBFN,XBMED,XBF,XBFLT
 S XBMED="F",XBFN=F,XBTLE="SAVE OF CRS DATA BY - "_$P(^VA(200,DUZ,0),U),XBF=0,XBFLT=1
 S XBUF=BGPUF D ^XBGSAVE
 L -^BGPDATA
 K ^TMP($J),^BGPDATA ;NOTE:  kill of unsubscripted global for use in export to area.
 Q
REPORT ;EP
 S BGPRPT="",BGPERR=""
 I '$D(BGPGUI) W !!
 ;3 files must have the same ien
 L +^BGPGPDCH:30 I '$T S BGPERR="Unable to lock global." G REPORTX
 L +^BGPGPDPH:30 I '$T S BGPERR="Unable to lock global." G REPORTX
 L +^BGPGPDBH:30 I '$T S BGPERR="Unable to lock global." G REPORTX
 D GETIEN
 I 'BGPIEN S BGPERR="Error in control files!" S BGPRPT="" G REPORTX
 S DINUM=BGPIEN
 I $G(BGPNPL) S BGPRTYPE=4
 S BGPR12=$S($G(BGPYGPU):9,1:BGPRTYPE)
 K DIC S X=BGPBD,DIC(0)="L",DIC="^BGPGPDCH(",DLAYGO=90550.03,DIADD=1,DIC("DR")=".02////"_BGPED_";.03////"_BGPPBD_";.04////"_BGPPED_";.05////"_BGPBBD_";.06////"_BGPBED_";.07////"_$G(BGPPER)_";.08////"_$G(BGPQTR)
 S DIC("DR")=DIC("DR")_";.09////"_$P(^AUTTLOC(DUZ(2),0),U,10)_";.11////"_$E($P(^AUTTLOC(DUZ(2),0),U,10),1,4)_";.12////"_BGPR12_";.13////"_DT_";.14////"_BGPBEN_";.15////"_$P($G(^AUTTLOC(DUZ(2),1)),U,3)_";.16///"_$P(^BGPSITE(DUZ(2),0),U,4)
 S DIC("DR")=DIC("DR")_";.17///"_$P(^BGPSITE(DUZ(2),0),U,6)_";.18///"_$S($G(BGPTAXI):$P(^ATXAX(BGPTAXI,0),U),1:"")_";.19///"_$P(^BGPSITE(DUZ(2),0),U,13)
 D ^DIC K DIC,DA,DR,DIADD,DLAYGO I Y=-1 S BGPERR="UNABLE TO CREATE REPORT FILE ENTRY!" S BGPQUIT=1 G REPORTX
 S BGPRPT=+Y
 K DIC S X=BGPBD,DIC(0)="L",DIC="^BGPGPDPH(",DLAYGO=90550.04,DIADD=1,DIC("DR")=".02////"_BGPED_";.03////"_BGPPBD_";.04////"_BGPPED_";.05////"_BGPBBD_";.06////"_BGPBED_";.07////"_$G(BGPPER)_";.08////"_$G(BGPQTR)
 S DIC("DR")=DIC("DR")_";.09////"_$P(^AUTTLOC(DUZ(2),0),U,10)_";.11////"_$E($P(^AUTTLOC(DUZ(2),0),U,10),1,4)_";.12////"_BGPR12_";.13////"_DT_";.14////"_BGPBEN_";.15////"_$P($G(^AUTTLOC(DUZ(2),1)),U,3)_";.16///"_$P(^BGPSITE(DUZ(2),0),U,4)
 S DIC("DR")=DIC("DR")_";.17///"_$P(^BGPSITE(DUZ(2),0),U,6)_";.18///"_$S($G(BGPTAXI):$P(^ATXAX(BGPTAXI,0),U),1:"")_";.19///"_$P(^BGPSITE(DUZ(2),0),U,13)
 S DINUM=BGPRPT D ^DIC K DIC,DA,DR,DIADD,DLAYGO,DINUM I Y=-1 S BGPERR="UNABLE TO CREATE REPORT FILE ENTRY!" S BGPQUIT=1 G REPORTX
 S BGPRPTP=+Y
 K DIC S X=BGPBD,DIC(0)="L",DIC="^BGPGPDBH(",DLAYGO=90550.05,DIADD=1,DIC("DR")=".02////"_BGPED_";.03////"_BGPPBD_";.04////"_BGPPED_";.05////"_BGPBBD_";.06////"_BGPBED_";.07////"_$G(BGPPER)_";.08////"_$G(BGPQTR)
 S DIC("DR")=DIC("DR")_";.09////"_$P(^AUTTLOC(DUZ(2),0),U,10)_";.11////"_$E($P(^AUTTLOC(DUZ(2),0),U,10),1,4)_";.12////"_BGPR12_";.13////"_DT_";.14////"_BGPBEN_";.15////"_$P($G(^AUTTLOC(DUZ(2),1)),U,3)_";.16///"_$P(^BGPSITE(DUZ(2),0),U,4)
 S DIC("DR")=DIC("DR")_";.17///"_$P(^BGPSITE(DUZ(2),0),U,6)_";.18///"_$S($G(BGPTAXI):$P(^ATXAX(BGPTAXI,0),U),1:"")_";.19///"_$P(^BGPSITE(DUZ(2),0),U,13)
 S DINUM=BGPRPT D ^DIC K DIC,DA,DR,DIADD,DLAYGO I Y=-1 S BGPERR="UNABLE TO CREATE REPORT FILE ENTRY!" S BGPQUIT=1 G REPORTX
 S BGPRPTB=+Y
 ;
 K ^BGPGPDCH(BGPRPT,9999)
 S C=0,X="" F  S X=$O(BGPTAX(X)) Q:X=""  S C=C+1 S ^BGPGPDCH(BGPRPT,9999,C,0)=X,^BGPGPDCH(BGPRPT,9999,"B",X,C)=""
 S ^BGPGPDCH(BGPRPT,9999,0)="^90550.12999A^"_C_"^"_C
 K ^BGPGPDCH(BGPRPT,1111)
 I $G(BGPMFITI) S C=0,X="" F  S X=$O(^ATXAX(BGPMFITI,21,"B",X)) Q:X=""  S C=C+1,Y=$P($G(^DIC(4,X,0)),U) S ^BGPGPDCH(BGPRPT,1111,C,0)=Y,^BGPGPDCH(BGPRPT,1111,"B",Y,C)=""
 S ^BGPGPDCH(BGPRPT,1111,0)="^90550.031111^"_C_"^"_C
 S ^BGPGPDCH(BGPRPT,99999,0)="^90550.129999A^0^0"
 S ^BGPGPDPH(BGPRPT,99999,0)="^90550.139999A^0^0"
 S ^BGPGPDBH(BGPRPT,99999,0)="^90550.149999A^0^0"
REPORTX ;
 I BGPERR]"" W !!,BGPERR
 I $G(BGPNPL) S BGPRTYPE=$S($G(BGPONMR):7,1:1)
 D ^XBFMK
 K DIC,DIADD,DLAYGO,DR,DA,DD,X,Y,DINUM
 L -^BGPGPDCH
 L -^BGPGPDPH
 L -^BGPGPDBH
 Q
GETIEN ;EP - Get next ien available in all 3 files
 S BGPF=90550.03 D ENT
 S BGPF=90550.04 D ENT
 S BGPF=90550.05 D ENT
 S BGPIEN=$P(^BGPGPDCH(0),U,3)+1
S I $D(^BGPGPDPH(BGPIEN))!($D(^BGPGPDBH(BGPIEN))) S BGPIEN=BGPIEN+1 G S
 Q
 ;
ENT ;
 NEW GBL,NXT,CTR,XBHI,XBX,XBY,ANS
 S GBL=^DIC(BGPF,0,"GL")
 S GBL=GBL_"NXT)"
 S (XBHI,NXT,CTR)=0
 F L=0:0 S NXT=$O(@(GBL)) Q:NXT'=+NXT  S XBHI=NXT,CTR=CTR+1 ;W:'(CTR#50) "."
 S NXT="",XBX=$O(@(GBL)),XBX=^(0),XBY=$P(XBX,U,4),XBX=$P(XBX,U,3)
 S NXT=0,$P(@(GBL),U,3)=XBHI,$P(^(0),U,4)=CTR
 ;
EOJ ;
 KILL ANS,XBHI,XBX,XBY,CTR,DIC,FILE,GBL,L,NXT,BGPF
 Q
 ;
LZERO(V,L) ;EP
 NEW %,I
 S %=$L(V),Z=L-% F I=1:1:Z S V="0"_V
 Q V
RZERO(V,L) ;EP
 NEW %,I
 S %=$L(V),Z=L-% F I=1:1:Z S V=V_"0"
 Q V
XTMP(N,D) ;EP
 Q:$G(N)=""
 S ^XTMP(N,0)=$$FMADD^XLFDT(DT,14)_"^"_DT_"^"_$G(D)
 Q