source: FOIAVistA/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLEVMST.m@ 1800

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

initial load of FOIAVistA 6/30/08 version

File size: 8.0 KB
Line 
1HLEVMST ;O-OIFO/LJA - Event Monitor MASTER JOB ;02/04/2004 14:42
2 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
3 ;
4 ; Calling STARTJOB always queues a new master job NOW...
5 ;
6MSTENV ; Display environment to user...
7 ;
8 ;
9 ; Collect Master Job Information
10 ;
11 ;
12 ; Collect Active Event Monitors
13 ;
14 ;
15 Q
16 ;
17CHECKMST ; Called from outside Event Monitoring, from the Link Manager,
18 ; to see if the master job needs to be started. (See ^HLCSLM.)
19 ; When the Link Manager calls here, two actions potentially occur:
20 ;
21 ; * Check is made whether this CHECKMST code has been run before,
22 ; and if so, how long ago. This check is performed by $$TIMECHK.
23 ; * If never run, or if run more than four hours ago, CHECKMST is run.
24 ;
25 ; CHECKMST checks whether a master job is running, or is properly
26 ; queued. If not, it queues a master job.
27 ;
28 N LAPSE,LASTDT,LASTIEN,NODE,PAR0,RUNOW,RUNTIME,X
29 ;
30 QUIT:'$$TIMECHK ;->
31 ;
32 ; Set last check time for later use by $$TIMECHK...
33 S HLEVLCHK(1)=$$SEC^HLEVMST0($H)
34 ;
35 ; Parameter status check...
36 S PAR0=$G(^HLEV(776.999,1,0)) Q:PAR0']"" ;->
37 I $P(PAR0,U,2)'="A" D QUIT ;-> Not ACTIVE...
38 . D SHOWQUIT("Master job not started. Parameter STATUS is INACTIVE...")
39 ;
40 ; Lapse (since last run) check...
41 S LAPSE=$P(PAR0,U,3) I LAPSE'>0 D QUIT ;->
42 . D SHOWQUIT("Master job not started. Master Job Interval not set up...")
43 ; Get IEN for last master job run
44 S LASTDT=$O(^HLEV(776.2,"B",":"),-1)
45 S LASTIEN=$O(^HLEV(776.2,"B",+LASTDT,":"),-1)
46 ;
47 I LASTIEN'>0 D STARTJOB QUIT ;->
48 S NODE=$G(^HLEV(776.2,+LASTIEN,0))
49 S X=$P(NODE,U,4) I X="E"!(X="P") D STARTJOB QUIT ;->
50 S RUNTIME=$P(NODE,U,6) ; Queue time for last run...
51 S RUNOW=$$RUNEV^HLEVAPI0(RUNTIME,LAPSE+15) ; No start unless 15" overdue
52 I RUNOW D STARTJOB QUIT ;-> 15" overdue!! So, start master job
53 D SHOWQUIT("Master job not started. Not time yet...")
54 ;
55 Q
56 ;
57TIMECHK() ; Every loop in the Link Manager code in HLCSLM results in one
58 ; call being made to CHECKMST^HLEVMST. The CHECKMST subroutine in turn
59 ; calls here to ensure that the Event Monitor's master job is running
60 ; properly. However, the CHECKMST subroutine should be run by HLCSLM
61 ; only once every four hours. The code in this subroutine uses
62 ; HLEVLCHK(#) variables to ensure that this every four hour rule is
63 ; followed. (HLEVLCHK is newed at the top of HLCSLM.)
64 ;
65 ; Set the time NOW in seconds...
66 S HLEVLCHK(0)=$$SEC^HLEVMST0($H)
67 ;
68 ; This is the time of last check. Make sure it exists...
69 S HLEVLCHK(1)=$G(HLEVLCHK(1))
70 ;
71 ; If no check every made, make a check now...
72 I HLEVLCHK(1)'>0 QUIT 1 ;->
73 ;
74 ; Set the number seconds between NOW and time of last check...
75 S HLEVLCHK(3)=HLEVLCHK(0)-HLEVLCHK(1) ; DIFF = NOW - LAST CHECK
76 ;
77 ; If less than 4 hours since last check, quit w/no check...
78 QUIT:HLEVLCHK(3)<(60*60*4) "" ;->
79 ;
80 Q 1 ; Check should be made...
81 ;
82SHOWQUIT(TXT) QUIT:$D(ZTQUEUED) ;->
83 W !!,TXT,!
84 Q
85 ;
86STARTJOB ; Start a new job with optional display to screen...
87 N JOBS
88 S JOBS=$$NEWMSTR(0,1) QUIT:$D(ZTQUEUED) ;->
89 W !!,"New master job queued to task# ",+JOBS,"..."
90 W !,"Entry #",$P(JOBS,U,2)," created in HL7 Monitor Master Job file..."
91 Q
92 ;
93MASTER ; Whenever a master job starts, here's where it's queued...
94 ; HLEVIENM - req
95 ;
96 N D,D0,DA,DIE,DR,FLD,NOEVCHK,NOPURG,NOW,RES,ZTSKMST
97 ;
98 S ZTREQ="@",NOW=$$NOW^XLFDT
99 ;
100 S ZTSKMST=$G(ZTSK) QUIT:ZTSKMST'>0 ;->
101 ;
102 QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']"" ;->
103 ;
104 ; Check parameter...
105 I $P($G(^HLEV(776.999,1,0)),U,2)'="A" D QUIT ;->
106 . F FLD=2,3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
107 . D UPDFLDM(+HLEVIENM,4,"A")
108 ;
109 ; Give (possibly just executed) $$NEWMSTR(0) DIE call time to execute...
110 H 2
111 ;
112 ; Queue next job...
113 S NEWJOB=$$NEWMSTR(1)
114 ;
115 ; What if job requested to stop?
116 I $P($G(^HLEV(776.2,+HLEVIENM,0)),U,4)="S" D QUIT ;->
117 . F FLD=2,3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
118 . D UPDFLDM(+HLEVIENM,4,"A")
119 ;
120 ; Mark entry to show it successfully started...
121 D UPDFLDM(+HLEVIENM,4,"R")
122 F FLD=3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
123 D UPDFLDM(+HLEVIENM,50,"Queued job started at "_$$NOW^XLFDT)
124 ;
125 ; Work starts here...
126 KILL NOEVCHK
127 S NOEVCHK=0
128 D EVENTCHK^HLEVAPI0(+HLEVIENM)
129 ;
130 ; Purge MONITOR and MASTER entries...
131 D PURGEALL^HLEVUTIL(+HLEVIENM)
132 ;
133 ; Mark ERROR any monitors still RUNNING by not current..
134 D MARKERR^HLEVAPI3
135 ;
136 ; Done...
137 D UPDFLDM(+HLEVIENM,2,$$NOW^XLFDT)
138 D UPDFLDM(+HLEVIENM,4,"F")
139 D UPDFLDM(+HLEVIENM,50,"Queued job finished at "_$$NOW^XLFDT)
140 D UPDFLDM(+HLEVIENM,50,"# events checked = "_$G(NOEVCHK))
141 S RES=""
142 F S RES=$O(NOEVCHK(RES)) Q:RES']"" D
143 . S RES(1)=$S(RES="E":" were not queued (too early.)",RES="I":" were not queued (inactivated.)",RES="Q":" were queued to execute.",RES="R":" Previous job still running.",RES="X":" errored, for some reason.",1:" have unknown disposition.")
144 . I RES="M" S RES(1)=" M code check failed."
145 . S RES(1)="#"_NOEVCHK(RES)_" Events"_RES(1)
146 . D UPDFLDM(+HLEVIENM,50,RES(1))
147 ;
148 Q
149 ;
150NEWMSTR(FUTURE,SILENT) ; Create a new master job...
151 ;
152 ; If FUTURE=0, then master job will be queued for NOW...
153 ; If FUTURE=1, then master job will be q'd for CUTMIN in future...
154 ;
155 N CUTMIN,DA,DIC,DIE,DD,DO,DR,HLEVIENM,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSK
156 ;
157 ; Should this process be silent?
158 S SILENT=$S($G(SILENT)>0:1,1:0)
159 ;
160 ; Check parameter...
161 I $P($G(^HLEV(776.999,1,0)),U,2)'="A" D QUIT "" ;->
162 . QUIT:$D(ZTQUEUED)!(SILENT) ;->
163 . W !!,"Exiting! Master job not started. Parameter turned off..."
164 . H 2
165 ;
166 ; Make master stub entry...
167 S X=$$NOW^XLFDT,DIC="^HLEV(776.2,",DIC(0)="L"
168 D FILE^DICN
169 S HLEVIENM=$S(+Y>0:+Y,1:"") I HLEVIENM'>0 D QUIT "" ;->
170 . QUIT:$D(ZTQUEUED)!(SILENT) ;->
171 . W !!,"Exiting! Master job not started. Stub record creation failed..."
172 . H 2
173 ;
174 ; Get CUTMIN and queue new job...
175 S CUTMIN=$H ; Default to NOW...
176 I $G(FUTURE) D
177 . S CUTMIN=$O(^HLEV(776.999,":"),-1),CUTMIN=$P($G(^HLEV(776.999,+CUTMIN,0)),U,3)
178 . S CUTMIN=$S(CUTMIN:CUTMIN,1:60) ; Default to 60 minutes between jobs...
179 . S CUTMIN=$$FMTH^XLFDT($$FMADD^XLFDT($$NOW^XLFDT,0,0,CUTMIN))
180 S ZTIO="",ZTDTH=CUTMIN,ZTDESC="HL Master Job - Event Monitoring"
181 S ZTRTN="MASTER^HLEVMST"
182 S ZTSAVE("HLEVIENM")=""
183 D ^%ZTLOAD
184 ;
185 ; Store task #, etc...
186 KILL DA,DD,DIC,DO,X,Y
187 S DA=+HLEVIENM,DIE=776.2,DR="4///Q;5///"_ZTSK_";6////"_$$HTFM^XLFDT(CUTMIN)_";7////"_+DUZ
188 D ^DIE
189 ;
190 I '$D(ZTQUEUED)&('SILENT) D
191 . W !!,"Master job created. Task# ",ZTSK,", and Event# ",HLEVIENM,"..."
192 . H 2
193 ;
194 QUIT $G(ZTSK)_U_HLEVIENM
195 ;
196UPDFLDM(HLEVIENM,FLD,VAL) ; Update a specific piece in 776.2...
197 N D,D0,DA,DI,DIE,DR
198 ;
199 QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']""!($G(VAL)']"") ;->
200 ;
201 ; Call call here to store one 50 diary entry. (Required that
202 ; FLD=50 and VAL=Text to store on line. Must call here one time
203 ; for every line to be stored.)
204 I FLD=50 D QUIT ;-> Call call here to store one 50 diary entry
205 . S NODE=$G(^HLEV(776.2,+HLEVIENM,50,0))
206 . S:NODE']"" NODE="^776.201^^"
207 . S CT=$O(^HLEV(776.2,+HLEVIENM,50,":"),-1)+1
208 . S $P(NODE,U,3)=CT,$P(NODE,U,4)=CT
209 . S ^HLEV(776.2,+HLEVIENM,50,0)=NODE
210 . S ^HLEV(776.2,+HLEVIENM,50,+CT,0)=VAL
211 ;
212 I FLD=51 QUIT ;-> Not allowed!
213 ;
214 ; Store zero node information...
215 S DA=+HLEVIENM,DIE=776.2,DR=FLD_"///"_VAL
216 D ^DIE
217 ;
218 Q
219 ;
220STAMPM(HLEVIENM) ; Update TIMESTAMP field in event..
221 N D,D0,DA,DI,DIE,DR
222 QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']"" ;->
223 S DA=+HLEVIENM,DIE=776.2,DR="3////"_$$NOW^XLFDT
224 D ^DIE
225 Q
226 ;
227PURGEM(HLEVIENM) ; Purge master job entries...
228 N CUTIME,IENM,LOOPTM,NOPURG,RETHRM
229 ;
230 ; Check parameter...
231 QUIT:$P($G(^HLEV(776.999,1,0)),U,2)'="A" "" ;->
232 ;
233 S NOPURG=0
234 ;
235 ; Get retention time (HR) for master job data...
236 S RETHRM=$O(^HLEV(776.999,":"),-1)
237 S RETHRM=$P($G(^HLEV(776.999,+RETHRM,0)),U,5)
238 S RETHRM=$S(RETHRM>0:RETHRM,1:96) ; Default to 96 hours
239 ;
240 ; Cutoff time...
241 S CUTIME=$$FMADD^XLFDT($$NOW^XLFDT,0,-RETHRM)
242 ;
243 F S CUTIME=$O(^HLEV(776.2,"B",CUTIME),-1) Q:CUTIME'>0 D
244 . S IEN=0
245 . F S IEN=$O(^HLEV(776.2,"B",CUTIME,IEN)) Q:IEN'>0 D
246 . . QUIT:IEN=HLEVIENM ;-> Don't delete yourself!!
247 . . S NOPURG=NOPURG+1
248 . . D PURGEME^HLEVUTIL(+IEN) ; Delete events in master job...
249 . . D DELETE^HLEVUTIL(776.2,+IEN)
250 ;
251 Q NOPURG
252 ;
253EOR ;HLEVMST - Event Monitor MASTER JOB ;5/16/03 14:42
Note: See TracBrowser for help on using the repository browser.