source: WorldVistAEHR/trunk/r/CAPACITY_MANAGEMENT_TOOLS-KMPD-KMPL/KMPDHU01.m@ 1361

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

initial load of WorldVistAEHR

File size: 6.9 KB
Line 
1KMPDHU01 ;OAK/RAK - CM Tools HL7 Utility ;6/21/05 10:12
2 ;;2.0;CAPACITY MANAGEMENT TOOLS;**4**;Mar 22, 2002
3 ;
4WEEKLY(KMPDT,KMPDPRGE) ;-- compress daily stats to weekly
5 ;-----------------------------------------------------------------------
6 ; KMPDT.... Compression date in internal fileman formt. This date
7 ; must be a Sunday. It represents the date from which the
8 ; previous weeks data should be compressed.
9 ; Example: if KMPDT = 2981011 then compression will begin
10 ; on 2981010 (KMPDT-1)
11 ; KMPDPRGE. 0 - do not purge data from file #8973.1
12 ; 1 - purge data from file #8973.1
13 ;
14 ; Every Sunday compress the daily stats in file #8973.1 into weekly
15 ; and upload the data to the CM RUM National Database
16 ;-----------------------------------------------------------------------
17 ;
18 Q:'$G(KMPDT)
19 S KMPDPRGE=+$G(KMPDPRGE)
20 ;
21 N DATA,DATE,DDLDT,DELDATE,EN,END,HOURS,I,IEN,J,NM,PT,SITE,STR,START,SYNC
22 ;
23 ; quit if not sunday.
24 Q:$$DOW^XLFDT(KMPDT,1)
25 ; storage processed
26 K ^TMP($J),^TMP("KMPDHU01",$J)
27 ; site info.
28 S SITE=$$SITE^VASITE Q:SITE=""
29 S DATE=KMPDT
30 S (START,END)="",STR=$$NOW^XLFDT
31 ; days to keep - this is represented by 'weeks to keep' in file #8973
32 ; so must be converted to days
33 S DDLDT=$P($G(^KMPD(8973,1,3)),U,11)*7
34 S:'DDLDT DDLDT=14
35 ; Date to begin deletion.
36 S DELDATE=$$FMADD^XLFDT(KMPDT,-DDLDT)
37 ;
38 W:'$D(ZTQUEUED) !,"Compressing data into weekly format..."
39 ; Reverse $order to get previous dates.
40 F S DATE=$O(^KMPD(8973.1,"B",DATE),-1) Q:'DATE D
41 .; If DATE is saturday set START and END dates and kill TMPARRY.
42 .I $$DOW^XLFDT(DATE,1)=6 D
43 ..S END=DATE,START=$$FMADD^XLFDT(DATE,-6)
44 ..K ^TMP($J)
45 .Q:'START
46 .S SYNC=0
47 .F S SYNC=$O(^KMPD(8973.1,"ASYNC",DATE,SYNC)) Q:'SYNC S IEN=0 D
48 ..F S IEN=$O(^KMPD(8973.1,"ASYNC",DATE,SYNC,IEN)) Q:'IEN D
49 ...Q:'$D(^KMPD(8973.1,IEN,0))
50 ...; data nodes into DATA() array.
51 ...S DATA(0)=^KMPD(8973.1,IEN,0) F I=1,1.1,1.2,2,2.1,2.2,5.1:.1:5.5,5.7,5.8,5.9,99,99.2,99.3,99.5 S DATA(I)=$G(^(I))
52 ...; quit if data has already been sent to national database
53 ...Q:$P(DATA(0),U,2)
54 ...; quit if no namespace or protocol
55 ...S NM=$P(DATA(0),U,3),PT=$P(DATA(0),U,5) Q:NM=""!(PT="")
56 ...; change first piece to start date (this is for national database)
57 ...S $P(DATA(0),U)=START
58 ...; second piece not applicable to national database
59 ...S $P(DATA(0),U,2)=""
60 ...D @$S(SYNC=2:"ASYNC(IEN,NM,PT,.DATA)",1:"SYNC(IEN,NM,PT,.DATA)")
61 ...; add to processed array.
62 ...S ^TMP("KMPDHU01",$J,IEN)=""
63 .;
64 .; Back to DATE level.
65 .; If START then transmit data.
66 .I DATE=START I $D(^TMP($J)) D TRANSMIT K ^TMP($J)
67 ;
68 D:$D(^TMP($J)) TRANSMIT
69 K ^TMP($J)
70 ;
71 ; update field .02 (SENT TO CM NATIONAL DATABASE) to 'YES' for all
72 ; processed entries.
73 W:'$D(ZTQUEUED) !!,"Updating records to reflect transmission..."
74 S IEN=0
75 F S IEN=$O(^TMP("KMPDHU01",$J,IEN)) Q:'IEN D
76 .K FDA,ERROR W:'$D(ZTQUEUED) "."
77 .S FDA($J,8973.1,IEN_",",.02)=1
78 .D FILE^DIE("","FDA($J)","ERROR")
79 ;
80 K ^TMP("KMPDHU01",$J)
81 ;
82 S STR=$$NOW^XLFDT
83 ; leave two complete weeks of data in file #8973.1
84 D:KMPDPRGE PURGE^KMPDUTL3(DELDATE)
85 D STRSTP^KMPDUTL2(3,2,2,STR)
86 ;
87 W:'$D(ZTQUEUED) !!,"Finished!"
88 ;
89 Q
90 ;
91ASYNC(IEN,NM,PR,DATA) ; compile asynchronous stats
92 ;-----------------------------------------------------------------------
93 ; IEN..... Ien for file #8973.1 (CM HL7 DATA)
94 ; NM...... Namespace (free text)
95 ; PR...... Protocol (free text)
96 ; DATA().. Array containing node data for file #8973.1 (CM HL7 DATA)
97 ;-----------------------------------------------------------------------
98 Q:'$G(IEN)
99 Q:$G(NM)=""
100 Q:$G(PR)=""
101 Q:'$D(DATA)
102 N CS,I,J
103 ; quit if no contact site
104 S CS=$P(DATA(99.2),U,12) Q:CS=""
105 S ^TMP($J,START,NM,PR,CS,0)=DATA(0)
106 ; node 99.1 is for national database (end date^facility name)
107 S DATA(99.1)=END_"^"_$P(SITE,U,2)_"^"_$P(SITE,U,3)
108 ; pieces 6 through 13 of node 99.2 contain text
109 F I=6:1:13 S $P(^TMP($J,START,NM,PR,CS,99.2),U,I)=$P(DATA(99.2),U,I)
110 W:'$D(ZTQUEUED) "."
111 F I=0:0 S I=$O(DATA(I)) Q:'I D
112 .; 99.1 data not to be totalled
113 .I I=99.1 F J=1:1:3 S $P(^TMP($J,START,NM,PR,CS,I),U,J)=$P(DATA(I),U,J)
114 .; Add data to get weekly totals.
115 .E F J=1:1:$S($E(I)=5:24,I=99:6,I=99.2:3,I=99.3:9,99.5:3,1:9) D
116 ..S $P(^TMP($J,START,NM,PR,CS,I),U,J)=$P($G(^TMP($J,START,NM,PR,CS,I)),U,J)+$P(DATA(I),U,J)
117 ;
118 Q
119 ;
120SYNC(IEN,NM,PR,DATA) ; compile asynchronous stats
121 ;-----------------------------------------------------------------------
122 ; IEN..... Ien for file #8973.1 (CM HL7 DATA)
123 ; NM...... Namespace (free text)
124 ; PR...... Protocol (free text)
125 ; DATA().. Array containing node data for file #8973.1 (CM HL7 DATA)
126 ;-----------------------------------------------------------------------
127 Q:'$G(IEN)
128 Q:$G(NM)=""
129 Q:$G(PR)=""
130 Q:'$D(DATA)
131 N I,J
132 S ^TMP($J,START,NM,PR,0)=DATA(0)
133 ; node 99.1 is for national database (end date^facility name)
134 S DATA(99.1)=END_"^"_$P(SITE,U,2)_"^"_$P(SITE,U,3)
135 ; pieces 6 through 13 of node 99.2 contain text
136 F I=6:1:13 S $P(^TMP($J,START,NM,PR,99.2),U,I)=$P(DATA(99.2),U,I)
137 W:'$D(ZTQUEUED) "."
138 F I=0:0 S I=$O(DATA(I)) Q:'I D
139 .; 99.1 data not to be totalled
140 .I I=99.1 F J=1:1:3 S $P(^TMP($J,START,NM,PR,I),U,J)=$P(DATA(I),U,J)
141 .; Add data to get weekly totals.
142 .E F J=1:1:$S(I=99:6,1:9) D
143 ..S $P(^TMP($J,START,NM,PR,I),U,J)=$P($G(^TMP($J,START,NM,PR,I)),U,J)+$P(DATA(I),U,J)
144 Q
145 ;
146TRANSMIT ;-- format TMPARRY data, put into e-mail and send to cm.
147 ;
148 Q:'$D(^TMP($J))
149 ;
150 N C,CPU,HRSDAYS,I,IEN,LN,N,P,S,TL,TRANSTO,XMSUB,X,XMTEXT,XMY,XMZ,Y,Z
151 ;
152 K ^TMP("KMPDHU01-2",$J)
153 ;
154 S LN=0
155 ; version and patch info
156 S LN=LN+1,^TMP("KMPDHU01-2",$J,LN)="VERSION="_$$VERSION^KMPDUTL
157 ; system information
158 S LN=LN+1,^TMP("KMPDHU01-2",$J,LN)="SYSINFO="_$$SYSINFO^KMPDUTL1()
159 ; send cpu data to national database
160 D CPU^KMPDUTL5(.CPU) I $D(CPU) S I="" F S I=$O(CPU(I)) Q:I="" D
161 .S LN=LN+1,^TMP("KMPDHU01-2",$J,LN)="CPU="_I_U_CPU(I)
162 ;
163 W:'$D(ZTQUEUED) !!,"Formatting ",$$FMTE^XLFDT($G(START))," data for mail delivery..."
164 ; reformat so that data is in ^TMP("KMPR UPLOAD",$J,LN)= format.
165 S IEN=0,S=""
166 F S S=$O(^TMP($J,S)) Q:S="" S N="" W "." D
167 .F S N=$O(^TMP($J,S,N)) Q:N="" S P="" D
168 ..F S P=$O(^TMP($J,S,N,P)) Q:P="" S I="",IEN=IEN+1 D
169 ...; synchronous data
170 ...F S I=$O(^TMP($J,S,N,P,I)) Q:(+I)'=I S LN=LN+1 D
171 ....S ^TMP("KMPDHU01-2",$J,LN)=IEN_","_I_")="_^TMP($J,S,N,P,I)
172 ...; asynchronous data
173 ...S C="-"
174 ...F S C=$O(^TMP($J,S,N,P,C)) Q:C="" S I="",IEN=IEN+1 D
175 ....F S I=$O(^TMP($J,S,N,P,C,I)) Q:(+I)'=I S LN=LN+1 D
176 .....S ^TMP("KMPDHU01-2",$J,LN)=IEN_","_I_")="_^TMP($J,S,N,P,C,I)
177 ;
178 ; quit if no data to transmit.
179 Q:'$D(^TMP("KMPDHU01-2",$J))
180 S TL=$G(^KMPD(8973,"TEST LAB"))
181 S TL=$S(TL:"TESTLAB-",1:"")
182 ; send packman message.
183 S XMTEXT="^TMP(""KMPDHU01-2"","_$J_","
184 S XMSUB="CM HL7 DATA~"_TL_$P(SITE,U,2)_" ("_$P(SITE,U,3)_")~"_$$FMTE^XLFDT(START)
185 D TRANSTO^KMPDUTL7(1,3,.TRANSTO)
186 Q:'$D(TRANSTO) S I=""
187 F S I=$O(TRANSTO(I)) Q:I="" S XMY(I)=""
188 D ^XMD
189 W:'$D(ZTQUEUED) !,"Message #",$G(XMZ)," sent..."
190 K ^TMP("KMPDHU01-2",$J)
191 ;
192 Q
Note: See TracBrowser for help on using the repository browser.