source: FOIAVistA/trunk/r/HEALTH_LEVEL_SEVEN-HL/HLEVAPI1.m@ 1783

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

initial load of FOIAVistA 6/30/08 version

File size: 8.3 KB
Line 
1HLEVAPI1 ;O-OIFO/LJA - Event Monitor APIs ;02/04/2004 14:42
2 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
3 ;
4SYSETUP ; Called by option's entry action...
5 N DATA,LAST,NEXT,STAT
6 ;
7 ; Make sure master job is current...
8 D CHECKMST^HLEVMST
9 ;
10 S DATA=$G(^HLEV(776.999,1,0)),LAST=$$LAST7762,NEXT=$$NEXT7762
11 ;
12 S STAT=$P(DATA,U,2)
13 S STAT="-------- Master job status is "_$S(STAT="A":"ACTIVE",STAT="I":"INACTIVE",1:"NOT SET YET")_" --------"
14 W !!!,$$CJ^XLFSTR(STAT,IOM)
15 S X=$$LAST7762 I X]"" W !,$$CJ^XLFSTR(X,IOM)
16 S X=$$NEXT7762 I X]"" W !,$$CJ^XLFSTR(X,IOM)
17 ;
18 S STAT=$P(DATA,U,6)
19 W !,$$CJ^XLFSTR("-------- Event monitoring status is "_$S(STAT="A":"ACTIVE",STAT="I":"INACTIVE",1:"NOT SET YET")_" --------",IOM)
20 ;
21 Q
22 ;
23LAST7762() ; Return d/h/m/s since last master job run...
24 N DATA,FIEN,IEN,LASTDT
25 ;
26 S LASTDT=":",FIEN=0
27 F S LASTDT=$O(^HLEV(776.2,"B",LASTDT),-1) Q:'LASTDT!(FIEN) D
28 . S IEN=":"
29 . F S IEN=$O(^HLEV(776.2,"B",+LASTDT,IEN),-1) Q:'IEN!(FIEN) D
30 . . S DATA=$G(^HLEV(776.2,+IEN,0)) QUIT:$P(DATA,U,4)'="F" ;->
31 . . S FIEN=IEN
32 ;
33 QUIT:'FIEN "Unknown last master job run time..." ;->
34 ;
35 QUIT $$DT7762(FIEN,0)
36 ;
37NEXT7762() ; Return d/h/m/s till next master job run...
38 N DATA,FIEN,IEN,LASTDT
39 ;
40 S LASTDT=":",FIEN=0
41 F S LASTDT=$O(^HLEV(776.2,"B",LASTDT),-1) Q:'LASTDT!(FIEN) D
42 . S IEN=":"
43 . F S IEN=$O(^HLEV(776.2,"B",+LASTDT,IEN),-1) Q:'IEN!(FIEN) D
44 . . S DATA=$G(^HLEV(776.2,+IEN,0)) QUIT:$P(DATA,U,4)'="Q" ;->
45 . . S FIEN=IEN
46 ;
47 QUIT:'FIEN "Unknown next master job run time..." ;->
48 ;
49 Q $$DT7762(+FIEN,1)
50 ;
51DT7762(FIEN,NXT) ; Called by $$LAST7762 & NEXT7762...
52 N DATA,DATE
53 S DATA=$G(^HLEV(776.2,+FIEN,0))
54 S DATE=$P(DATA,U,$S('NXT:2,1:6)) QUIT:DATE'?7N1"."1.N "" ;->
55 S DATE=$$DHMSFM^HLEVUTIL(DATE,$$NOW^XLFDT,1)
56 I 'NXT D QUIT DATE ;-> Last...
57 . I DATE["[" S DATE="Unknown last master job run..." QUIT ;->
58 . S DATE="Last master job run was "_DATE_" ago..."
59 I NXT D QUIT DATE ;-> Next...
60 . I DATE'["[" S DATE="Unknown next master job run..." QUIT ;->
61 . S DATE="Next run "_$S($P(DATA,U,5):"[task# "_$P(DATA,U,5)_"] ",1:"")_"is "_$P($P(DATE,"[",2),"]")_" in the future..."
62 Q ""
63 ;
64LOADALL(HLEVIENJ,SVSUB) ; Load all sections into global for mailing...
65 N NO,TXT
66 S SVSUB=$S($G(SVSUB)]"":SVSUB,1:"HLMAILMSG") ; Save Subscript...
67 D LOADDESC(HLEVIENJ,SVSUB) ; Short description of monitor.
68 D LOADCOMP(HLEVIENJ,SVSUB) ; Completed line...
69 D LOADBODY^HLEVAPI2(HLEVIENJ,SVSUB) ; Start/end/Status/Status-Appl...
70 S NO=0
71 F S NO=$O(HLEVTXT(NO)) Q:NO'>0 D
72 . S TXT=$G(HLEVTXT(NO)) QUIT:TXT']"" ;->
73 . S TXT=$$UP^XLFSTR($TR(TXT," ",""))
74 . I TXT="RUNDIARY" D LOADDGBL^HLEVAPI2(HLEVIENJ,50,SVSUB) QUIT ;->
75 . I TXT="MESSAGETEXT" D LOADDGBL^HLEVAPI2(HLEVIENJ,51,SVSUB) QUIT ;->
76 . I TXT="VARIABLEVALUE" D LOADVAR(HLEVIENJ,SVSUB) QUIT ;->
77 . KILL X S X="W "_TXT D ^DIM Q:'$D(X) ;->
78 . D LOADUSER(TXT,SVSUB)
79 Q
80 ;
81LOADUSER(GBL,SVSUB) ; Load user data into Mailman message...
82 N NO,TXT
83 ;
84 QUIT:$O(@GBL@(0))'>0 ;->
85 ;
86 S NO=0
87 F S NO=$O(@GBL@(NO)) Q:NO'>0 D
88 . S TXT=$G(@GBL@(NO))
89 . F D Q:TXT']""
90 . . D ADD($E(TXT,1,74))
91 . . S TXT=$E(TXT,75,999) QUIT:TXT']"" ;->
92 . . S TXT=" "_TXT
93 ;
94 Q
95 ;
96LOADDESC(HLEVIENJ,SVSUB) ; Load description if it exists...
97 N DESC,HLEVIENE
98 S SVSUB=$S($G(SVSUB)]"":SVSUB,1:"HLMAILMSG")
99 S HLEVIENE=$P($G(^HLEV(776,+HLEVIENJ,0)),U,3)
100 S DESC=$P($G(^HLEV(776,+$G(HLEVIENE),0)),U,3) QUIT:DESC']"" ;->
101 ; First line...
102 D ADD("Monitor description: "_DESC)
103 D ADD("")
104 Q
105 ;
106LOADCOMP(HLEVIENJ,SVSUB) ; Load generic event monitor info into XMTEXT...
107 N HLEVIENE,HLEVNM
108 S SVSUB=$S($G(SVSUB)]"":SVSUB,1:"HLMAILMSG")
109 S HLEVIENE=$P($G(^HLEV(776,+HLEVIENJ,0)),U,3)
110 S HLEVNM=$P($G(^HLEV(776.1,+HLEVIENE,0)),U)
111 ; First line...
112 D ADD("The '"_HLEVNM_"' event monitor has completed.")
113 D ADD("")
114 Q
115 ;
116LOADVAR(HLEVIENJ,SVSUB) ; Load variable names...
117 N CUT,MIEN,TXT,VAR
118 ;
119 QUIT:$O(^HLEV(776,+HLEVIENJ,52,0))'>0 ;->
120 ;
121 D ADD(""),ADD("Variable List"),ADD("-------------")
122 ;
123 S VAR=""
124 F S VAR=$O(^HLEV(776,+HLEVIENJ,52,"B",VAR)) Q:VAR']"" D
125 . S MIEN=0
126 . F S MIEN=$O(^HLEV(776,+HLEVIENJ,52,"B",VAR,MIEN)) Q:MIEN'>0 D
127 . . S TXT=$G(^HLEV(776,+HLEVIENJ,52,+MIEN,0)) QUIT:TXT']"" ;->
128 . . S TXT=$P(TXT,U)_$S($P(TXT,U,2)]"":"["_$P(TXT,U,2)_"]",1:"")_"="
129 . . S TXT(1)=$G(^HLEV(776,+HLEVIENJ,52,+MIEN,52))
130 . . I ($L(TXT)+$L(TXT(1)))<240 S TXT=TXT_TXT(1),TXT(1)=""
131 . . I TXT(1)]"" D
132 . . . S CUT(1)=$L(TXT),CUT(2)=$L(TXT(1)),CUT=240-CUT(1)
133 . . . S TXT=TXT_$E(TXT(1),1,CUT),TXT(1)=$E(TXT(1),CUT+1,999)
134 . . F D QUIT:TXT']""
135 . . . D ADD($E(TXT,1,74))
136 . . . S TXT=$E(TXT,75,999) QUIT:TXT']"" ;->
137 . . . S TXT=" "_TXT
138 . . . QUIT:TXT(1)']"" ;->
139 . . .
140 ;
141 Q
142 ;
143ADD(TXT) ; Add TXT to global to be mailed out...
144 ; SVSUB -- req
145 N NO
146 S NO=$O(^TMP($J,SVSUB,":"),-1)+1
147 S ^TMP($J,SVSUB,+NO)=TXT
148 Q
149 ;
150CURR(IEN776) ; Is job running and current?
151 N DATA,DIFF,STAT,TSTAMP
152 S DATA=$G(^HLEV(776,+IEN776,0))
153 S STAT=$P(DATA,U,4) QUIT:STAT'="R" "" ;->
154 S TSTAMP=$P(DATA,U,6) QUIT:TSTAMP'?7N1"."1.N "" ;->
155 S TSTAMP=$$FMTH^XLFDT(TSTAMP)
156 S DIFF=$$DIFFDH^HLCSFMN1(TSTAMP,$H) ; Difference...
157 I DIFF'?1.N1"^"2N1":"2N1":"2N QUIT "" ;-> DD^HH:MM:SS
158 I +DIFF>0 QUIT "" ;-> 1 or more days difference!
159 S DIFF=$P(DIFF,U,2) ; HH:MM:SS now...
160 ; If 1 or more hrs, or >15 minutes old...
161 I +DIFF!(+$P(DIFF,":",2)>15) QUIT "" ;->
162 Q 1
163 ;
164APPSTAT(STATUS) ; Fill in application status...
165 ; HLEVIENJ -- req
166 N DA,DIE,DR
167 ;
168 D DEBUG^HLEVAPI2("VARIABLE") ; Debug data created conditionally
169 ;
170 ; Stop all event monitoring to enable on-site debugging...
171 QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
172 ;
173 QUIT:$G(STATUS)']"" ;->
174 QUIT:$G(^HLEV(776,+$G(HLEVIENJ),0))']"" ;->
175 S DA=+HLEVIENJ,DIE=776,DR="5///"_$E(STATUS,1,10)
176 D ^DIE
177 Q
178 ;
179RUNDIARY(GBL) ; Move GBL data into RUN DIARY...
180 ; HLEVIENJ -- req
181 ;
182 D DEBUG^HLEVAPI2("VARIABLE") ; Debug data created conditionally
183 ;
184 ; Stop all event monitoring to enable on-site debugging...
185 QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
186 ;
187 D GBLMOVE(+$G(HLEVIENJ),50,$G(GBL))
188 Q
189 ;
190MSGTEXT(GBL) ; Mark event job entry to NOTIFY MAIL GROUP...
191 ; HLEVIENJ -- req
192 ;
193 D DEBUG^HLEVAPI2("VARIABLE") ; Debug data created conditionally
194 ;
195 ; Stop all event monitoring to enable on-site debugging...
196 QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
197 ;
198 D GBLMOVE(+$G(HLEVIENJ),51,$G(GBL))
199 Q
200 ;
201GBLMOVE(HLEVIENJ,SUB,GBL) ; Move GBL data into entry's WP text...
202 N CT,NO,NODE
203 ;
204 S SUB=$G(SUB) QUIT:SUB'=51&(SUB'=52) ;->
205 QUIT:$G(^HLEV(776,+HLEVIENJ,0))']"" ;->
206 ;
207 ; Add event text...
208 S NODE="^776.002",NO=0
209 F S NO=$O(@GBL@(NO)) Q:NO'>0 D
210 . S CT=$O(^HLEV(776,+HLEVIENJ,SUB,":"),-1)+1
211 . S ^HLEV(776,+HLEVIENJ,SUB,CT,0)=$G(@GBL@(+NO))
212 S CT=$O(^HLEV(776,+HLEVIENJ,SUB,":"),-1) QUIT:CT'>0 ;->
213 S $P(NODE,U,3)=CT,$P(NODE,U,4)=CT
214 S ^HLEV(776,+HLEVIENJ,SUB,0)=NODE
215 ;
216 Q
217 ;
218ONETIME ;Start a one-time run of event monitor (w/no master job)
219 N HLEVIENE,QTASK
220 W @IOF,$$CJ^XLFSTR("One-time Queueing of Event Monitor",IOM)
221 W !,$$REPEAT^XLFSTR("=",IOM)
222 W !,"Normally, the master job evaluates every event monitor and queues a background"
223 W !,"job for those events ready for a new ""run."" This option allows the running"
224 W !,"of an event monitor between ""normal"" runs."
225 W !!,"Do you want to start a new ""in-between"" run of a monitor? If so, select"
226 W !,"it now. If not, press RETURN to exit..."
227 W !
228 ;
229 S HLEVIENE=$$ASKIEN^HLEVREP(776.1) I HLEVIENE'>0 D QUIT ;->
230 . W " exiting..."
231 ;
232 W !
233 D ASKRUN(HLEVIENE)
234 ;
235 Q
236 ;
237ASKRUN(HLEVIENE) ; Ask if want to run a one-time...
238 N DATA,QTASK,QTIME
239 ;
240 I $P($G(^HLEV(776.1,+$G(HLEVIENE),0)),U,2)'="A" D QUIT ;->
241 . QUIT:$G(^HLEV(776.1,+$G(HLEVIENE),0))']"" ;->
242 . D TELL^HLEVMST0("Event monitor is INACTIVE!!","1,2,999")
243 ;
244 I $$YN^HLCSRPT4("Run monitor now","No") D QUIT ;->
245 . D QIT($$NOW^XLFDT) W " exiting..."
246 ;
247 W !!,"You may queue this monitor to run ""one-time"" in the future. If so, enter a"
248 W !,"future date/time now..."
249 W !
250 ;
251 F S QTIME=$$ASKDATE^HLEVAPI2("Enter future run time") D QUIT:QTIME?7N1"."1.N!(QTIME']"")
252 . QUIT:QTIME'?7N1"."1.N ;->
253 . I QTIME>$$NOW^XLFDT D QIT(QTIME) QUIT ;->
254 . S QTIME="REASK"
255 . W " enter a future time..."
256 ;
257 Q
258 ;
259QIT(QTIME) ; Queue it...
260 N QTASK
261 S QTASK=$$Q1TIME^HLEVAPI0(+HLEVIENE,0,QTIME)
262 I +QTASK>0 W !!," Queued task# ",+QTASK," [#",$P(QTASK,U,2),"]..."
263 I +QTASK'>0 W !!," Error occurred. No monitor ""run"" started..."
264 W !
265 F Q:($Y+3)>IOSL W !
266 S X=$$BTE^HLCSMON("Press RETURN to exit... ")
267 Q
268 ;
269EOR ;HLEVAPI1 - Event Monitor APIs ;5/16/03 14:42
Note: See TracBrowser for help on using the repository browser.