source: WorldVistAEHR/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLUOPTF2.m@ 1582

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

initial load of WorldVistAEHR

File size: 6.8 KB
Line 
1HLUOPTF2 ;ALB/CJM-HL7 -Fast Purge ;02/04/2004
2 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
3 ;
4FAST1 ;entry point for FAST PURGE 1, called by the Event Monitor
5 I '$$COUNT D PURGE
6 Q
7FAST2 ;entry point for FAST PURGE 2, called by the Event Monitor
8 I $$COUNT=1 D PURGE
9 Q
10 ;
11START ;Interactive entry point, asks user whether or not to queue the Fast Purge
12 ;
13 N ASK,STOP
14 S STOP=1
15 S ASK=$$ASKYESNO^HLEMU("Do you want to queue the Fast Purge so that it operates in the background","YES")
16 I ASK D
17 .N ZTRTN,ZTDESC,ZTSAVE,ZTIO,ZTSK
18 .S ZTRTN="PURGE^HLUOPTF2"
19 .S ZTDESC="HL7 FAST PURGE UTILITY"
20 .S ZTIO=""
21 .S ZTSAVE("STOP")=1
22 .D ^%ZTLOAD
23 .W !,$S($D(ZTSK):"HL7 FAST PURGE UTILITY QUEUED, TASK="_ZTSK,1:"REQUEST CANCELLED")
24 E I ASK=0 D
25 .W !,"Starting Fast Purge....",!
26 .D PURGE
27 K ^TMP("HLEVFLAG",$J)
28 Q
29STOP ;
30 ;entry point to ask the Fast Purge Job to stop
31 I $$COUNT>$G(^XTMP("HL7 FAST PURGE JOBS","STOP")),$$I^HLEMU($NA(^XTMP("HL7 FAST PURGE JOBS","STOP")),1)
32 Q
33COUNT() ;
34 ;returns the number of Fast Purge Jobs that are running
35 N COUNT,I
36 S COUNT=0
37 F I=1:1:20 D
38 .L ^XTMP("HL7 FAST PURGE JOBS",I):0
39 .I '$T D
40 ..S COUNT=COUNT+1
41 .E D
42 ..L -^XTMP("HL7 FAST PURGE JOBS",I)
43 Q COUNT
44 ;
45PURGE ;entry point for the FAST PURGE
46 ;
47 ;Variables:
48 ; CHECKAT - next time to check in with TaskMan, Job Monitor, andEvent Logging, set every 10 minutes
49 ; HOUR - the date and time to 1 hour precision that this process is currently purging, each hour is locked before purging
50 ; IEN772 - entry in file 772 identified for purging
51 ; IEN773 - entry in file 773 identified for purging
52 ; LASTCHK - a simple count, the time is checked everytime this count reaches 500 - for efficiency, do not want to check the time after purging every entry
53 ; CNT773 - count to report for EVENT LOGGING of entries purged (file 773)
54 ; CNT772 - count to report for EVENT LOGGING of entries purged (file 772)
55 ; QUIT - set to 1 when signaled to stop via TaskMan
56 ; TIME - time currently being processed on the AI x-ref, file 773
57 ;
58 ;
59 I $G(STOP)=1 D
60 .;setting this flag allows the job to run outside of Process Monitorng
61 .S ^TMP("HLEVFLAG",$J)="STOP"
62 ;
63 N LCNT,CNT773,CNT772,HOUR,LASTCHK,TIME,IEN772,IEN773,CHECKAT,QUIT,VAR,I
64 S (TIME,HOUR,CNT773,CNT772,LCOUNT,QUIT)=0
65 ;
66 D START^HLEVAPI(.VAR)
67 ;
68 S CHECKAT=$$FMADD^XLFDT($$NOW^XLFDT,,,10)
69 ;
70 ;let everyone know that there is 1 more purge job running - maximum of 20 Fast Purges running at once
71 F I=1:1:20 L ^XTMP("HL7 FAST PURGE JOBS",I):0 Q:$T
72 ;
73 ;loop until signaled to stop or there is no work for a while
74 I $T F D Q:QUIT
75 .S:'TIME HOUR=$$FINDHOUR(HOUR) S:HOUR TIME=HOUR-.00000001
76 .;
77 .;wasn't able to get an hour to lock
78 .I 'HOUR D Q
79 ..;
80 ..;if there has been no work for a while then quit
81 ..I $$NOW^XLFDT>CHECKAT,CNT773<2000 D
82 ...S QUIT=$$CHECKIN(.CHECKAT,.CNT773,.CNT772,.LCOUNT)
83 ...S QUIT=1
84 ..E D
85 ...S QUIT=$$CHECKIN(.CHECKAT,.CNT773,.CNT772,.LCOUNT)
86 ...D EVENT(.CNT773,.CNT772)
87 ...Q:QUIT
88 ...D PAUSE
89 .;
90 .;at this point, an hour has been locked, so delete all the entries for that hour
91 .F S TIME=$O(^HLMA("AI",TIME)) D Q:'TIME Q:QUIT
92 ..I ('TIME)!($E(TIME,1,10)>HOUR) S TIME=0 Q
93 ..S LCOUNT=LCOUNT+1
94 ..I LCOUNT>500 S QUIT=$$CHECKIN(.CHECKAT,.CNT773,.CNT772,.LCOUNT) Q:QUIT
95 ..S (IEN772,IEN773)=0
96 ..F S IEN773=$O(^HLMA("AI",TIME,773,IEN773)) Q:'IEN773 D
97 ...S CNT773=CNT773+1
98 ...D DEL773^HLUOPT3(IEN773)
99 ...;
100 ..F S IEN772=$O(^HLMA("AI",TIME,772,IEN772)) Q:'IEN772 D
101 ...S CNT772=CNT772+1
102 ...D DEL772^HLUOPT3(IEN772)
103 ..;
104 ..; make sure that no more records are on this x-ref for that time - could only happen in the case of corruption of some sort
105 ..K ^HLMA("AI",TIME)
106 ;
107 ;unlock the last hour currently being held
108 L:HOUR -^HLMA("AI",HOUR)
109 ;
110 ;let everyone know that there is 1 less purge job running
111 F I=1:1:20 L -^XTMP("HL7 FAST PURGE JOBS",I)
112 D CHECKOUT^HLEVAPI
113 K ^TMP("HLEVFLAG",$J)
114 Q
115 ;
116PAUSE ;sleep for 10 SECONDS
117 H 10
118 Q
119 ;
120CHECKIN(CHECKAT,CNT773,CNT772,LCOUNT) ;
121 ;if NOW>CHECKAT then:
122 ; 1) check in with TaskMan
123 ; 2) send a new event to the event monitor
124 ; 3) reset CHECKAT for 10 minutes in the future
125 ; 4) as an alternative to TaskMan, check if special Stop Fast Purge option has been used
126 ;
127 ;Input:
128 ; CHECKAT - the end of the current 10 minute time period
129 ; CNT773 - number of records in file 773 purged since the last time Event Logging was updated
130 ; CNT772 - number of records in file 772 purged since the last time Event Logging was updated
131 ;Output:
132 ; Function returns 1 if the Fast Purge should stop, 0 otherwise
133 ; LCOUNT is reset to 0 **pass by reference**
134 ; CNT773 and CNT772 are set to 0 if reported to Event Logging **pass by reference**
135 ; CHECKAT is reset to 10 minute sin the future if the time is up **pass by reference**
136 ;
137 N NOW,QUIT
138 S QUIT=0
139 ;
140 S NOW=$$NOW^XLFDT
141 I NOW>CHECKAT D
142 .D EVENT(.CNT773,.CNT772)
143 .S CHECKAT=$$FMADD^XLFDT(NOW,,,10)
144 .I '$D(ZTQUEUED) D
145 ..W "."
146 .E D
147 ..;check in with the Job Monitor
148 ..D CHECKIN^HLEVAPI
149 ..S QUIT=$$S^ZTLOAD
150 ..S:QUIT ZTSTOP=1
151 ;
152 ;Check if the special option has been used to stop the purge
153 I $G(^XTMP("HL7 FAST PURGE JOBS","STOP"))>0 D
154 .S QUIT=1
155 .I $$I^HLEMU($NA(^XTMP("HL7 FAST PURGE JOBS","STOP")),-1)
156 ;
157 S LCOUNT=0
158 Q QUIT
159 ;
160FINDHOUR(HOUR) ;
161 ;Finds the next dt/tm to the hour on the AI x-ref of file 773 that can be locked, returns 0 on failure
162 N QUIT,NOW
163 S QUIT=0
164 ;
165 ;unlock the last hour currently being held
166 L:HOUR -^HLMA("AI",HOUR)
167 ;
168 S NOW=$$NOW^XLFDT
169 ;
170 ;if this is the first time through then start with the first entry on the x-ref
171 I 'HOUR D Q:QUIT HOUR
172 .S HOUR=$O(^HLMA("AI",0))
173 .;
174 .;any records to purge?
175 .I 'HOUR S QUIT=1 Q
176 .;
177 .;if so, quit if the next purgeable record is for the future
178 .I HOUR>NOW S HOUR=0 Q
179 .;
180 .S HOUR=$E(HOUR,1,10)
181 .L +^HLMA("AI",+HOUR):0 S:$T QUIT=1
182 ;
183 S HOUR=$E(HOUR,1,10)
184 F D Q:QUIT
185 .;
186 .;look for the next entry at least 1 hour in the future
187 .S HOUR=$$FMADD^XLFDT(HOUR,,1)-.000000001
188 .S HOUR=$E($O(^HLMA("AI",HOUR)),1,10)
189 .I 'HOUR S QUIT=1 Q
190 .;
191 .;I the hour is in the future then the entries can not yet be purged
192 .I (HOUR>NOW) S HOUR=0,QUIT=1 Q
193 .;
194 .;check if this hour can be locked, if so this is the hour to be purged
195 .L +^HLMA("AI",+HOUR):0 I $T S QUIT=1
196 ;
197 Q HOUR
198 ;
199EVENT(CNT773,CNT772) ;
200 ;add the last number of records purged to event logging
201 N EVENT
202 I CNT773 D
203 .S EVENT=$$EVENT^HLEME("773 PURGE","HEALTH LEVEL SEVEN")
204 .I CNT773>1,$$INC^HLEME(EVENT,CNT773-1)
205 .S CNT773=0
206 I CNT772 D
207 .S EVENT=$$EVENT^HLEME("772 PURGE","HEALTH LEVEL SEVEN")
208 .I CNT772>1,$$INC^HLEME(EVENT,CNT772-1)
209 .S CNT772=0
210 Q
211 ;
212CHECK1() ;called by the Master Job to determine whether
213 ;FAST HL7 PURGE #1 should run.
214 ;Output:
215 ; function returns 1 if yes, 0 if no
216 ;
217 I $$COUNT^HLEVAPI3("FAST HL7 PURGE #1")
218 Q '$T
219 ;
220CHECK2() ;called by the Master Job to determine whether
221 ;FAST HL7 PURGE #2 should run.
222 ;Output:
223 ; function returns 1 if yes, 0 if no
224 ;
225 I $$COUNT^HLEVAPI3("FAST HL7 PURGE #1"),'$$COUNT^HLEVAPI3("FAST HL7 PURGE #2")
226 Q $T
Note: See TracBrowser for help on using the repository browser.