source: WorldVistAEHR/trunk/r/DSS_EXTRACTS-ECX/ECXAMOV.m@ 701

Last change on this file since 701 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 9.1 KB
Line 
1ECXAMOV ;ALB/JAP - MOV Extract Audit Report ;Oct 10, 1997
2 ;;3.0;DSS EXTRACTS;**8,33**;Dec 22, 1997
3 ;
4EN ;entry point for MOV extract audit report
5 N %X,%Y,X,Y,DIC,DA,DR,DIQ,DIR
6 S ECXERR=0
7 ;ecxaud=0 for 'extract' audit
8 S ECXHEAD="MOV",ECXAUD=0
9 W !!,"Setup for ",ECXHEAD," Extract Audit Report --",!!
10 ;select extract
11 D AUDIT^ECXUTLA(ECXHEAD,.ECXERR,.ECXARRAY,ECXAUD)
12 Q:ECXERR
13 ;determine if facility is multidivisional
14 S DIC="^DG(43,",DA=1,DR="11;",DIQ="ECX",DIQ(0)="I" D EN^DIQ1
15 I +ECX(43,1,11,"I")=0 S ECXALL=1
16 I +ECX(43,1,11,"I")=1 D
17 .W !!
18 .S DIR(0)="Y",DIR("A")="Do you want the "_ECXHEAD_" extract audit report for all divisions"
19 .S DIR("B")="NO" D ^DIR K DIR
20 .I $G(DIRUT) S ECXERR=1 Q
21 .;if y=0 i.e., 'no', then ecxall=0 i.e., 'selected'
22 .S ECXALL=Y
23 I ECXERR=1 D Q
24 .W !!,?5,"Try again later... exiting.",!
25 .D AUDIT^ECXKILL
26 ;select divisions/sites; all divisions if ecxall=1
27 S X=ECXARRAY("START") D ^%DT S ECXSTART=Y S X=ECXARRAY("END") D ^%DT S ECXEND=Y
28 D MOV^ECXDVSN(.ECXDIV,ECXALL,ECXSTART,ECXEND,.ECXERR)
29 I ECXERR=1 D Q
30 .W !!,?5,"Try again later... exiting.",!
31 .D AUDIT^ECXKILL
32 ;determine output device and queue if requested
33 W !
34 S ECXPGM="PROCESS^ECXAMOV",ECXDESC="MOV Extract Audit Report"
35 S ECXSAVE("ECXHEAD")="",ECXSAVE("ECXALL")="",ECXSAVE("ECXDIV(")="",ECXSAVE("ECXARRAY(")=""
36 W !!,?5,"The format of this report requires a page or screen",!,?5,"width of 132 characters.",!
37 D DEVICE^ECXUTLA(ECXPGM,ECXDESC,.ECXSAVE)
38 I ECXSAVE("POP")=1 D Q
39 .W !!,?5,"Try again later... exiting.",!
40 .D AUDIT^ECXKILL
41 I ECXSAVE("ZTSK")=0 D
42 .K ECXSAVE,ECXPGM,ECXDESC
43 .D PROCESS^ECXAMOV
44 I IO'=IO(0) D ^%ZISC
45 D HOME^%ZIS
46 D AUDIT^ECXKILL
47 Q
48 ;
49PROCESS ;process data in file #727.808
50 N X,Y,W,JJ,DATE,DATA,DIV,IEN,MOV,TL,ORDER,SORD,GTOT,STOT,WARD,TMOV,QQFLG,CNT,LINETOT
51 K ^TMP($J,"ECXWARD"),^TMP($J,"ECXORDER"),^TMP($J,"MISWRD")
52 S (CNT,QQFLG)=0
53 S ECXEXT=ECXARRAY("EXTRACT"),ECXDEF=ECXARRAY("DEF")
54 S X=ECXARRAY("START") D ^%DT S ECXSTART=Y S X=ECXARRAY("END") D ^%DT S ECXEND=Y
55 ;get run date in external format
56 D NOW^%DTC S Y=$E(%,1,12) D DD^%DT S ECXRUN=Y
57 ;get ward info in ^tmp($j,"ecxward" and ^tmp($j,"ecxorder"
58 D WARDS^ECXUTLA(ECXALL,.ECXDIV)
59 ;setup up ^tmp($j,"mov", for legend
60 S JJ=0 F S JJ=$O(^DG(405.2,JJ)) Q:+JJ<1 S MOV=JJ D
61 .S DATA=^DG(405.2,JJ,0),NM=$P(DATA,U,1),TYPE=$P(DATA,U,2)
62 .S ^TMP($J,"MOV",TYPE,JJ)=NM
63 F JJ=1:1:MOV S $P(TL,U,JJ)=0
64 S W="" F S W=$O(^TMP($J,"ECXWARD",W)) Q:W="" D
65 .S DIV=$P(^TMP($J,"ECXWARD",W),U,3) I '$D(GTOT(DIV)) F JJ=1:1:MOV S $P(GTOT(DIV),U,JJ)=0
66 .S ^TMP($J,"TL",W)=TL
67 .S ORDER="" D
68 ..F S ORDER=$O(^TMP($J,"ECXORDER",DIV,ORDER)) Q:ORDER="" I $D(^(ORDER,1)) D
69 ...F JJ=1:1:MOV S $P(STOT(DIV,ORDER),U,JJ)=0
70 ;get records in date range and ward set
71 S IEN="" F S IEN=$O(^ECX(727.808,"AC",ECXEXT,IEN)) Q:IEN="" D Q:QQFLG
72 .S DATA=^ECX(727.808,IEN,0),DATE=$P(DATA,U,9),WARD=$P(DATA,U,15),TMOV=$P(DATA,U,19)
73 .;convert free text date to fm internal format date
74 .S $E(DATE,1,2)=$E(DATE,1,2)-17
75 .Q:$L(DATE)<7 Q:(DATE<ECXSTART) Q:(DATE>ECXEND)
76 .;track missing wards
77 .I WARD="" D Q
78 ..S ^TMP($J,"MISWRD")=$G(^TMP($J,"MISWRD"))+1,^("MISWRD",IEN)=""
79 .;if ward is among those selected, then tally movement data
80 .I $D(^TMP($J,"TL",WARD)) D
81 ..S $P(^TMP($J,"TL",WARD),U,TMOV)=$P(^TMP($J,"TL",WARD),U,TMOV)+1
82 ..S ORDER=$P(^TMP($J,"ECXWARD",WARD),U,1),DIV=$P(^(WARD),U,3),$P(GTOT(DIV),U,TMOV)=$P(GTOT(DIV),U,TMOV)+1
83 ..S SORD=ORDER-.01,SORD=$O(STOT(DIV,SORD)) I +SORD S $P(STOT(DIV,SORD),U,TMOV)=$P(STOT(DIV,SORD),U,TMOV)+1
84 ..S CNT=CNT+1 I $D(ZTQUEUED),(CNT>499),'(CNT#500),$$S^%ZTLOAD S QQFLG=1,ZTSTOP=1 K ZTREQ
85 ;after all the extract records are processed, set totals into ^tmp($j,"ecxorder"
86 I $D(ZTQUEUED),$$S^%ZTLOAD S ZTSTOP=1 K ZTREQ Q
87 S W="" F S W=$O(^TMP($J,"TL",W)) Q:W="" S TL(W)=^(W) D
88 .S ORDER=$P(^TMP($J,"ECXWARD",W),U,1),DIV=$P(^(W),U,3)
89 .S LINETOT=0 F JJ=1:1:MOV S $P(^TMP($J,"ECXORDER",DIV,ORDER),U,JJ+2)=$P(TL(W),U,JJ),LINETOT=LINETOT+$P(TL(W),U,JJ)
90 .K TL(W)
91 .;don't keep inactive wards unless there is movement data
92 .I ORDER>999990,LINETOT=0 K ^TMP($J,"ECXORDER",DIV,ORDER)
93 .I $D(^TMP($J,"ECXORDER",DIV,ORDER,1)) D
94 ..;don't do group total on inactive/unordered wards
95 ..I ORDER>999990 K ^TMP($J,"ECXORDER",DIV,ORDER,1) Q
96 ..F JJ=1:1:MOV S $P(^TMP($J,"ECXORDER",DIV,ORDER,1),U,JJ+2)=$P(STOT(DIV,ORDER),U,JJ)
97 D PRINT
98 D AUDIT^ECXKILL
99 Q
100 ;
101PRINT ;print the movement data by division and ward order
102 N JJ,SS,LN,NM,TNM,PG,QFLG,WRDNM,WRDTOT,GRPNM,GRPTOT,DIVTOT,DATA,DATA1
103 N TYPE,DIC,DA,DR,DIR,DIRUT,DTOUT,DUOUT,W1,W2,ADMDT,IEN,FAC
104 U IO
105 I $D(ZTQUEUED),$$S^%ZTLOAD S ZTSTOP=1 K ZTREQ Q
106 S (QFLG,PG)=0,$P(LN,"-",132)="",DIV=""
107 F S DIV=$O(GTOT(DIV)) Q:DIV="" D Q:QFLG
108 .F TYPE=2,3 S TNM=$S(TYPE=2:"Transfer",TYPE=3:"Discharge",1:"") D HEADER Q:QFLG S MOV="",DIVTOT=0 D Q:QFLG
109 ..F S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" S DIVTOT=DIVTOT+$P(GTOT(DIV),U,MOV)
110 ..I DIVTOT=0 D Q
111 ...W !!,"No "_TNM_" data extracted for this medical center division.",!
112 ..S ORDER="" F S ORDER=$O(^TMP($J,"ECXORDER",DIV,ORDER)) Q:ORDER="" D Q:QFLG
113 ...S DATA=^TMP($J,"ECXORDER",DIV,ORDER) K DATA1 I $D(^(ORDER,1)) S DATA1=^(1)
114 ...S WRDNM=$P(DATA,U,2)
115 ...I TYPE=3 S WRDNM=$P(WRDNM,"<",1),WRDNM=$E(WRDNM,1,14)
116 ...I TYPE=2 D
117 ....S W1=$P(WRDNM,"<",1),W2=$P(WRDNM,"<",2)
118 ....S:W2="" WRDNM=$E(W1,1,14) S:W2]"" WRDNM=$$LJ^XLFSTR($E(W1,1,12),12," ")_" <"_W2
119 ...D:($Y+3>IOSL) HEADER Q:QFLG
120 ...W !,WRDNM S TAB=$S(TYPE=2:20,1:10),LINETOT=0
121 ...F S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" D
122 ....S WRDTOT=$P(DATA,U,2+MOV),TAB=TAB+6 W ?TAB,$$RJ^XLFSTR(WRDTOT,5," ") S LINETOT=LINETOT+WRDTOT
123 ...S TAB=TAB+8 W ?TAB,$$RJ^XLFSTR(LINETOT,5," ")
124 ...;if data1 exists, then this is the end of a ward group so print group totals
125 ...I $G(DATA1) D Q:QFLG
126 ....S GRPNM=$P(DATA1,U,2) D:($Y+3>IOSL) HEADER Q:QFLG
127 ....W !,?18,$E(LN,1,113)
128 ....D:($Y+3>IOSL) HEADER Q:QFLG W !,"Ward group "_GRPNM_" subtotals:",!
129 ....D:($Y+3>IOSL) HEADER Q:QFLG
130 ....S TAB=$S(TYPE=2:20,1:10),LINETOT=0
131 ....F S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" D
132 .....S GRPTOT=$P(DATA1,U,2+MOV),TAB=TAB+6 W ?TAB,$$RJ^XLFSTR(GRPTOT,5," ") S LINETOT=LINETOT+GRPTOT
133 ....S TAB=TAB+8 W ?TAB,$$RJ^XLFSTR(LINETOT,5," ")
134 ....D:($Y+3>IOSL) HEADER Q:QFLG
135 ....W !!
136 ..Q:QFLG
137 ..D:($Y+3>IOSL) HEADER Q:QFLG W !!,"Division "_$P(ECXDIV(DIV),U,2)_" Grand Totals:",!
138 ..D:($Y+3>IOSL) HEADER Q:QFLG
139 ..S TAB=$S(TYPE=2:20,1:10),LINETOT=0
140 ..F S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" D
141 ...S GTOT=$P(GTOT(DIV),U,MOV),TAB=TAB+6 W ?TAB,$$RJ^XLFSTR(GTOT,5," ") S LINETOT=LINETOT+GTOT
142 ..S TAB=TAB+8 W ?TAB,$$RJ^XLFSTR(LINETOT,5," ")
143 ..I $E(IOST)'="C" D LEGEND
144 ;print patients with missing wards
145 I $D(^TMP($J,"MISWRD")) D
146 .S DIV="MISWRD",ECXDIV(DIV)="^^^^^*** MISSING WARDS ***^",TYPE=0
147 .D HEADER S WRDTOT=$G(^TMP($J,"MISWRD"))
148 .W !,?5,"MISSING WARD",?45,$$RJ^XLFSTR(WRDTOT,5," "),!!
149 .D HEAD S IEN=""
150 .F S IEN=$O(^TMP($J,"MISWRD",IEN)) Q:'IEN D I QFLG Q
151 ..S DATA=$G(^ECX(727.808,IEN,0)),ADMDT=$P(DATA,U,11) Q:DATA=""
152 ..S FAC=$P(DATA,U,4) S:FAC'="" FAC=$$GET1^DIQ(42,FAC,.01,"E")
153 ..W !?2,$P(DATA,U,7),?8,$P(DATA,U,5),?25,$E(FAC,1,14),?45
154 ..W $E(ADMDT,5,6)_"/"_$E(ADMDT,7,8)_"/"_$E(ADMDT,1,4)," "
155 ..W $E($P(DATA,U,22),1,2)_":"_$E($P(DATA,U,22),3,4)
156 ..D:($Y+3>IOSL) HEADER,HEAD Q:QFLG
157 I $E(IOST)'="C" D
158 .W @IOF S PG=PG+1
159 .W !,ECXARRAY("TYPE")_" ("_ECXHEAD_") Extract Audit Report"
160 .W !,"DSS Extract Log #: "_ECXEXT
161 .W !,"Date Range of Audit: "_ECXARRAY("START")_" to "_ECXARRAY("END")
162 .W !,"Report Run Date/Time: "_ECXRUN,?120,"Page: ",PG
163 .W !!,LN,!!
164 .S DIC="^ECX(727.1,",DA=ECXARRAY("DEF"),DR="1" D EN^DIQ
165 I $E(IOST)="C",'QFLG D
166 .S SS=22-$Y F JJ=1:1:SS W !
167 .S DIR(0)="E" W ! D ^DIR K DIR
168 Q
169 ;
170HEAD ;header for missing wards
171 W !,?2,"NAME",?8,"PATIENT DFN",?25,"FACILITY",?45,"ADMISSION DATE"
172 W !,?2,"====",?8,"===========",?25,"========",?45,"=============="
173 Q
174 ;
175HEADER ;header and page control
176 N JJ,SS,TAB,DSSID
177 I $E(IOST)="C" D
178 .S SS=22-$Y F JJ=1:1:SS W !
179 .I PG>0 S DIR(0)="E" W ! D ^DIR K DIR S:'Y QFLG=1
180 Q:QFLG
181 S DSSID=$P(ECXDIV(DIV),U,6)
182 W:$Y!($E(IOST)="C") @IOF S PG=PG+1
183 W !,ECXARRAY("TYPE")_" ("_ECXHEAD_") Extract Audit Report"
184 W !,"DSS Extract Log #: "_ECXEXT
185 W !,"Date Range of Audit: "_ECXARRAY("START")_" to "_ECXARRAY("END")
186 W !,"Report Run Date/Time: "_ECXRUN
187 I DSSID="" W !,"Medical Center Division: "_$P(ECXDIV(DIV),U,2)_" ("_$P(ECXDIV(DIV),U,3)_")",?120,"Page: "_PG
188 I DSSID]"" W !,"Medical Center Division: "_$P(ECXDIV(DIV),U,2)_" ("_$P(ECXDIV(DIV),U,3)_")"_" <"_DSSID_">",?120,"Page: "_PG
189 S TAB=$S(TYPE=2:28,1:20) W !!
190 I TYPE=2 W "Ward <DSS Dept.>",?TAB,"MAS Movement ("_TNM_") Types",!
191 I TYPE=3 W "Ward",?TAB,"MAS Movement ("_TNM_") Types",!
192 S MOV="",TAB=$S(TYPE=0:40,TYPE=2:20,1:10)
193 F S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" S TAB=TAB+6 W ?TAB,$$RJ^XLFSTR(MOV,5," ")
194 S TAB=TAB+8 W ?TAB,$$RJ^XLFSTR("Total",5," ")
195 W !,LN,!
196 Q
197 ;
198LEGEND ;print legend for each report type
199 N MOV,MOVNM
200 D:($Y+10>IOSL) HEADER
201 W !!,TNM_" Movements Legend --"
202 S MOV="" F S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" D Q:MOV=""
203 .S MOVNM=^TMP($J,"MOV",TYPE,MOV) W !,MOV,?4,"= ",$E(MOVNM,1,32)
204 .S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" S MOVNM=^(MOV) W ?41,MOV,?44,"= ",$E(MOVNM,1,32)
205 .S MOV=$O(^TMP($J,"MOV",TYPE,MOV)) Q:MOV="" S MOVNM=^(MOV) W ?81,MOV,?84,"= ",$E(MOVNM,1,32)
206 Q
Note: See TracBrowser for help on using the repository browser.