source: WorldVistAEHR/trunk/r/ORDER_ENTRY_RESULTS_REPORTING-OR-OCX--ORRC--ORRJ/ORWGTASK.m@ 700

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

initial load of WorldVistAEHR

File size: 8.3 KB
RevLine 
[613]1ORWGTASK ; SLC/STAFF - Graph Task ;3/17/08 10:48
2 ;;3.0;ORDER ENTRY/RESULTS REPORTING;**243**;Dec 17, 1997;Build 242
3 ;
4SETLAST(PAT) ; from ORWGAPI - set whenever patient is graphed
5 N NOW,USER
6 S PAT=+$G(PAT)
7 S USER=+$G(DUZ)
8 S NOW=$$NOW^ORWGAPIX
9 I USER,PAT D
10 . S ^XTMP("ORGDATA","TP",PAT)=NOW
11 . S ^XTMP("ORGDATA","TP",PAT,"U",USER)=NOW
12 . S ^XTMP("ORGDATA","TU",USER)=NOW
13 . D COUNT("G",PAT,USER)
14 Q
15 ;
16INIT(OK) ; from ORMTIM02 - run by ORMTIME (OK=0)
17 N BACKTO,CNT,DFN,ITEM,LASTDFN,NOW,PURGE,TASKED,TIME
18 S OK=+$G(OK,0)
19 I $G(^XTMP("ORGRAPH","FORCE"))="ON" D ; set in ORY243 (post-init v27)
20 . S OK=1
21 . D CLEANALL
22 I 'OK D ; unless forced, run one time on Saturday
23 . I $P($G(^XTMP("ORGRAPH",0)),U,2)=DT Q
24 . I $E(DT,6)="0",$$DOW^XLFDT(DT)="Saturday",$L($G(^XTMP("ORGRAPH",0))) D Q ; cleanup on 1st Sat of the month
25 .. S OK=1
26 .. D CLEANALL
27 . I $$DOW^XLFDT(DT)="Saturday",$L($G(^XTMP("ORGRAPH",0))) S OK=1 Q
28 I 'OK Q
29 S BACKTO=$$FMADD^XLFDT(DT,-30) ;clear old data on non-graphed patients backto this date
30 S PURGE=$$FMADD^XLFDT(DT,180) ; when to purge XTMP nodes
31 S NOW=$$NOW^ORWGAPIX
32 S ^XTMP("ORGDATA",0)=PURGE_U_DT_U_"CPRS Graphing - Patient Data Cache Stats"_U_NOW
33 S ^XTMP("ORGRAPH",0)=PURGE_U_DT_U_"CPRS Graphing - Patient Data Cache"
34 S CNT=0
35 S LASTDFN=0
36 S DFN=""
37 F S DFN=$O(^XTMP("ORGDATA","TP",DFN)) Q:DFN="" D
38 . S TIME=$O(^XTMP("ORGDATA","TP",DFN))
39 . I '$L(TIME) Q
40 . I TIME<BACKTO D CLRDATA(DFN) Q
41 . S ^XTMP("ORGRAPH","QUEUE",NOW_"^0^"_DFN)=NOW ; put patients to update on queue
42 . S LASTDFN=DFN
43 . S CNT=CNT+1
44 . S OK=1
45 D UPDATE(.TASKED,LASTDFN,0,0) ; last patient starts the updates
46 S ^XTMP("ORGRAPH","INIT")=NOW_U_$$NOW^ORWGAPIX_U_CNT
47 S ^XTMP("ORGDATA",0)=^XTMP("ORGDATA",0)_U_$$NOW^ORWGAPIX_U_CNT
48 Q
49 ;
50CLEANALL ;
51 K ^XTMP("ORGDATA")
52 K ^XTMP("ORGRAPH")
53 Q
54 ;
55CLRDATA(DFN) ;
56 N PATUSER,USER
57 S USER=.9
58 F S USER=$O(^XTMP("ORGDATA","TP",DFN,"U",USER)) Q:USER<1 D
59 . S PATUSER=DFN_U_USER
60 . K ^XTMP("ORGRAPH","ALL DATA",PATUSER)
61 . K ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
62 . K ^XTMP("ORGRAPH","ALL LABS",PATUSER)
63 . K ^XTMP("ORGRAPH","OLD DATA",DFN)
64 . K ^XTMP("ORGRAPH","OLD LABS",DFN)
65 K ^XTMP("ORGDATA","TP",DFN)
66 Q
67 ;
68UPDATE(TASKED,DFN,USER,OLDDFN) ; from ORWGAPI
69 ; whenever patient is selected
70 ; to update, cache must exist and user/patient combo has used graphs
71 ;D CLEANALL Q ; ******** temporary disabled BA 1/16/08 *********
72 N NOW,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSAVE K ZTSAVE
73 ;S ^XTMP("ZZZBOB")=$G(TASKED)_U_$G(DFN)_U_$G(USER)_U_$G(OLDDFN)
74 S TASKED=-1 ; cache turned off
75 I '$L($G(^XTMP("ORGRAPH",0))) Q
76 S TASKED=0 ; not building cache
77 I USER,DFN D COUNT("P",DFN,USER)
78 I USER,'$G(^XTMP("ORGDATA","TU",USER)) Q ; user must use graphing to cache
79 I USER,OLDDFN D CLEARPT(OLDDFN,USER)
80 I 'DFN Q
81 I '$G(^XTMP("ORGDATA","TP",DFN)) Q ; patient must be used with graphing to cache
82 I USER,'$G(^XTMP("ORGDATA","TP",DFN,"U",USER)) Q ; pat/user combo to cache **** comment this out for better graph speed - but more cache
83 S TASKED=1 ; building cache
84 S NOW=$$NOW^ORWGAPIX
85 I USER D CLEARPT(DFN,USER)
86 S ZTIO="ORWG GRAPHING RESOURCE",ZTDTH=$H,ZTDESC="process graph data"
87 S ZTSAVE("ORMTIME")=$$MNOW
88 S ZTSAVE("ORPAT")=DFN
89 S ZTSAVE("ORTSTMP")=NOW
90 S ZTSAVE("ORUSER")=USER
91 S ZTRTN="UP^ORWGTASK"
92 D ^%ZTLOAD
93 Q
94 ;
95COUNT(EVENT,DFN,USER) ;
96 I EVENT="P" D Q
97 . S ^("C")=1+$G(^XTMP("ORGDATA","P",DFN,"C"))
98 . S ^(USER)=1+$G(^XTMP("ORGDATA","P",DFN,"C-U",USER))
99 . S ^("C")=1+$G(^XTMP("ORGDATA","U",USER,"C"))
100 . S ^(DFN)=1+$G(^XTMP("ORGDATA","U",USER,"C-P",DFN))
101 I EVENT="G" D Q
102 . S ^("CG")=1+$G(^XTMP("ORGDATA","P",DFN,"CG"))
103 . S ^(USER)=1+$G(^XTMP("ORGDATA","P",DFN,"CG-U",USER))
104 . S ^("CG")=1+$G(^XTMP("ORGDATA","U",USER,"CG"))
105 . S ^(DFN)=1+$G(^XTMP("ORGDATA","U",USER,"CG-P",DFN))
106 Q
107 ;
108CLEARPT(DFN,USER) ;
109 N PATUSER
110 S PATUSER=DFN_U_USER
111 K ^XTMP("ORGRAPH","ALL DATA",PATUSER)
112 K ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
113 K ^XTMP("ORGRAPH","ALL LABS",PATUSER)
114 Q
115 ;
116UP ; dequeued from ORWGTASK
117 ; ORUSER, ORPAT, ORTSTMP were saved
118 N GNOW,GSTAMP,NOW,STAMP
119 S STAMP=ORTSTMP_U_ORUSER_U_ORPAT
120 S GSTAMP=ORMTIME_U_ORUSER_U_ORPAT
121 S NOW=$$NOW^ORWGAPIX
122 S GNOW=$$MNOW
123 I $D(ZTQUEUED) S ZTREQ="@"
124 S ^XTMP("ORGRAPH","QUEUE",STAMP)=NOW_U_ORMTIME
125 S ^XTMP("ORGDATA","Q",GSTAMP)=GSTAMP
126 S ^XTMP("ORGDATA","QT",ORUSER_U_ORPAT)=ORMTIME
127 D GSTAMP(GSTAMP,ORMTIME,GNOW,4)
128 I 'ORUSER S $P(^XTMP("ORGRAPH","INIT"),U,4)=NOW
129 I $G(^XTMP("ORGRAPH","STATUS"))'="ACTIVE" D START
130 S ^XTMP("ORGRAPH","STATUS")="INACTIVE"
131 Q
132 ;
133START ;
134 S ^XTMP("ORGRAPH","STATUS")="ACTIVE"
135 N COUNT,MAX,NEXT,STOP,TIMES
136 S MAX=5
137 S COUNT=0
138 S STOP=0
139 S NEXT=""
140 F S NEXT=$O(^XTMP("ORGRAPH","QUEUE",NEXT)) D Q:STOP
141 . I NEXT="" D Q
142 .. H 1
143 .. S COUNT=COUNT+1
144 .. I COUNT>MAX S STOP=1 Q
145 . S TIMES=^XTMP("ORGRAPH","QUEUE",NEXT)
146 . K ^XTMP("ORGRAPH","QUEUE",NEXT)
147 . D PROCESS(NEXT,TIMES)
148 . K ^XTMP("ORGRAPH","QUEUE",NEXT)
149 Q
150 ;
151PROCESS(NEXT,TIMES) ;
152 N DFN,GSTAMP,IN,OUT,TSTMP,USER
153 S TSTMP=+$P(NEXT,U)
154 S USER=+$P(NEXT,U,2)
155 S DFN=$P(NEXT,U,3)
156 S GSTAMP=$P(TIMES,U,2)_U_USER_U_DFN
157 D ALL(GSTAMP,DFN,USER)
158 I 'USER S $P(^XTMP("ORGRAPH","INIT"),U,5)=$$NOW^ORWGAPIX
159 Q
160 ;
161ALL(GSTAMP,DFN,USER) ;
162 N BACKTO,CNT,LASTDATE,NUM,PATUSER,PREV,START,TIMED,TIMEI,TIMEL,TIMEZ,TYPE
163 K ^TMP("ORGAI",$J),^TMP("ORGI",$J),^TMP("ORGT",$J)
164 S START=$$NOW^ORWGAPIX
165 S DFN=+$G(DFN) I 'DFN Q
166 S USER=+$G(USER)
167 S PATUSER=DFN_U_USER
168 S TIMEI=START
169 D GSTAMP(GSTAMP,+GSTAMP,$$MNOW,5)
170 S GTIME=$$MNOW
171 D TYPES^ORWGAPI("ORGT",DFN)
172 I '$L($O(^TMP("ORGT",$J,""))) Q
173 S NUM=""
174 F S NUM=$O(^TMP("ORGT",$J,NUM)) Q:NUM="" D
175 . S TYPE=$P(^TMP("ORGT",$J,NUM),U)
176 . K ^TMP("ORGI",$J)
177 . S CNT=0
178 . D ITEMS^ORWGAPIR("ORGI",DFN,TYPE,3,,,.CNT,2)
179 . M ^TMP("ORGAI",$J)=^TMP("ORGI",$J)
180 K ^TMP("ORGI",$J)
181 S PREV=1
182 I '$D(^XTMP("ORGRAPH","OLD DATA",DFN)) S PREV=0
183 I '$D(^XTMP("ORGRAPH","OLD LABS",DFN)) S PREV=0
184 I USER D ; user is 0 when doing init
185 . L +^XTMP("ORGRAPH","ALL ITEMS",PATUSER):1 I '$T Q
186 . M ^XTMP("ORGRAPH","ALL ITEMS",PATUSER)=^TMP("ORGAI",$J)
187 . L -^XTMP("ORGRAPH","ALL ITEMS",PATUSER)
188 S LASTDATE=+$G(^XTMP("ORGRAPH","LAST BUILD",DFN))
189 I 'LASTDATE S LASTDATE=DT
190 S BACKTO=$$FMADD^XLFDT(LASTDATE,-30) ; *** backto value is 30 days ********************
191 S TIMED=$$NOW^ORWGAPIX
192 D GETDATA("DATA",GSTAMP,GTIME,PATUSER,START,BACKTO)
193 S TIMEL=$$NOW^ORWGAPIX
194 D GETDATA("LABS",GSTAMP,GTIME,PATUSER,START,BACKTO)
195 S TIMEZ=$$NOW^ORWGAPIX
196 S ^XTMP("ORGRAPH","LAST BUILD",DFN)=DT
197 K ^TMP("ORGAI",$J),^TMP("ORGI",$J),^TMP("ORGT",$J)
198 Q
199 ;
200GETDATA(TYPES,GSTAMP,GTIME,PATUSER,START,BACKTO) ;
201 N ALLSUBS,CNT,DATA,DFN,NUM,NUM1,OLDSUBS,SUB,TYPEITEM,USER
202 K ^TMP("ORGD",$J),^TMP("ORGID",$J),^TMP("ORGNI",$J)
203 S OLDSUBS="OLD "_TYPES
204 S ALLSUBS="ALL "_TYPES
205 S DFN=+PATUSER
206 S USER=+$P(PATUSER,U,2)
207 S SIZE=0
208 I $D(^XTMP("ORGRAPH",OLDSUBS,DFN)) D
209 . S SUB=""
210 . F S SUB=$O(^TMP("ORGAI",$J,SUB)) Q:SUB="" D
211 .. S TYPEITEM=$G(^TMP("ORGAI",$J,SUB))
212 .. I TYPES="DATA",$P(TYPEITEM,U)=63 Q
213 .. I TYPES="LABS",$P(TYPEITEM,U)'=63 Q
214 .. I $P(TYPEITEM,U,6)>BACKTO S ^TMP("ORGNI",$J,SUB)=TYPEITEM
215 . S CNT=0
216 . S NUM=""
217 . F S NUM=$O(^TMP("ORGNI",$J,NUM)) Q:NUM="" D
218 .. S TYPEITEM=^TMP("ORGNI",$J,NUM)
219 .. D SIZE(TYPEITEM,START,DFN,BACKTO,.SIZE)
220 . D GSTAMP(GSTAMP,GTIME,$$MNOW,6)
221 . S $P(^XTMP("ORGDATA","Q",GSTAMP),U,16)=SIZE+$P(^XTMP("ORGDATA","Q",GSTAMP),U,16)
222 E D
223 . S NUM=""
224 . F S NUM=$O(^TMP("ORGAI",$J,NUM)) Q:NUM="" D
225 .. S TYPEITEM=^TMP("ORGAI",$J,NUM)
226 .. I TYPES="DATA",$P(TYPEITEM,U)=63 Q
227 .. I TYPES="LABS",$P(TYPEITEM,U)'=63 Q
228 .. D SIZE(TYPEITEM,START,DFN,2700101,.SIZE)
229 . D GSTAMP(GSTAMP,GTIME,$$MNOW,7)
230 . S $P(^XTMP("ORGDATA","Q",GSTAMP),U,17)=SIZE+$P(^XTMP("ORGDATA","Q",GSTAMP),U,17)
231 S GTIME=$$MNOW
232 M ^XTMP("ORGRAPH",OLDSUBS,DFN)=^TMP("ORGD",$J)
233 I USER D ; user is 0 when doing init
234 . L +^XTMP("ORGRAPH",ALLSUBS,PATUSER):1 I '$T Q
235 . M ^XTMP("ORGRAPH",ALLSUBS,PATUSER)=^XTMP("ORGRAPH",OLDSUBS,DFN)
236 . L -^XTMP("ORGRAPH",ALLSUBS,PATUSER)
237 K ^TMP("ORGD",$J),^TMP("ORGID",$J),^TMP("ORGNI",$J)
238 D GSTAMP(GSTAMP,GTIME,$$MNOW,8)
239 Q
240 ;
241SIZE(TYPEITEM,START,DFN,BACKTO,SIZE) ;
242 N DATA,NUM
243 K ^TMP("ORGID",$J)
244 D ITEMDATA^ORWGAPI("ORGID",TYPEITEM,START,DFN,BACKTO)
245 S NUM=""
246 F S NUM=$O(^TMP("ORGID",$J,NUM)) Q:NUM="" D
247 . S DATA=^TMP("ORGID",$J,NUM)
248 . S ^TMP("ORGD",$J,$P(DATA,U,1,3))=DATA
249 . S SIZE=$L(DATA)+SIZE
250 Q
251 ;
252RESOURCE ; from ORWGAPIU on post init, setup graphing resource device
253 N X
254 S X=$$RES^XUDHSET("ORWG GRAPHING RESOURCE",,3,"CPRS GUI graphing data retrieval")
255 Q
256 ;
257GSTAMP(GSTAMP,TIME1,TIME2,PIECE) ;
258 S $P(^XTMP("ORGDATA","Q",GSTAMP),"^",PIECE)=TIME2-TIME1
259 Q
260 ;
261MNOW() ;
262 Q $$ZZ^ORWGAPIX
263 ;
264CLEAN ;
265 K ^XTMP("ORGRAPH")
266 Q
267 ;
Note: See TracBrowser for help on using the repository browser.