HLEVMST ;O-OIFO/LJA - Event Monitor MASTER JOB ;02/04/2004 14:42
;;1.6;HEALTH LEVEL SEVEN;**109,173,176**;Oct 13, 1995;Build 4
;;Per VA Directive 6402, this routine should not be modified.
;
; Calling STARTJOB always queues a new master job NOW...
;
MSTENV ; Display environment to user...
;
;
; Collect Master Job Information
;
;
; Collect Active Event Monitors
;
;
Q
;
CHECKMST ; Called from outside Event Monitoring, from the Link Manager,
; to see if the master job needs to be started. (See ^HLCSLM.)
; When the Link Manager calls here, two actions potentially occur:
;
; * Check is made whether this CHECKMST code has been run before,
; and if so, how long ago. This check is performed by $$TIMECHK.
; * If never run, or if run more than four hours ago, CHECKMST is run.
;
; CHECKMST checks whether a master job is running, or is properly
; queued. If not, it queues a master job.
;
N LAPSE,LASTDT,LASTIEN,NODE,PAR0,RUNOW,RUNTIME,X
;
QUIT:'$$TIMECHK ;->
;
; Set last check time for later use by $$TIMECHK...
S HLEVLCHK(1)=$$SEC^HLEVMST0($H)
;
; Parameter status check...
S PAR0=$G(^HLEV(776.999,1,0)) Q:PAR0']"" ;->
I $P(PAR0,U,2)'="A" D QUIT ;-> Not ACTIVE...
. D SHOWQUIT("Master job not started. Parameter STATUS is INACTIVE...")
;
; Lapse (since last run) check...
S LAPSE=$P(PAR0,U,3) I LAPSE'>0 D QUIT ;->
. D SHOWQUIT("Master job not started. Master Job Interval not set up...")
; Get IEN for last master job run
S LASTDT=$O(^HLEV(776.2,"B",":"),-1)
S LASTIEN=$O(^HLEV(776.2,"B",+LASTDT,":"),-1)
;
I LASTIEN'>0 D STARTJOB QUIT ;->
S NODE=$G(^HLEV(776.2,+LASTIEN,0))
S X=$P(NODE,U,4) I X="E"!(X="P") D STARTJOB QUIT ;->
S RUNTIME=$P(NODE,U,6) ; Queue time for last run...
S RUNOW=$$RUNEV^HLEVAPI0(RUNTIME,LAPSE+15) ; No start unless 15" overdue
I RUNOW D STARTJOB QUIT ;-> 15" overdue!! So, start master job
D SHOWQUIT("Master job not started. Not time yet...")
;
Q
;
TIMECHK() ; Every loop in the Link Manager code in HLCSLM results in one
; call being made to CHECKMST^HLEVMST. The CHECKMST subroutine in turn
; calls here to ensure that the Event Monitor's master job is running
; properly. However, the CHECKMST subroutine should be run by HLCSLM
; only once every four hours. The code in this subroutine uses
; HLEVLCHK(#) variables to ensure that this every four hour rule is
; followed. (HLEVLCHK is newed at the top of HLCSLM.)
;
; Set the time NOW in seconds...
S HLEVLCHK(0)=$$SEC^HLEVMST0($H)
;
; This is the time of last check. Make sure it exists...
S HLEVLCHK(1)=$G(HLEVLCHK(1))
;
; If no check every made, make a check now...
I HLEVLCHK(1)'>0 QUIT 1 ;->
;
; Set the number seconds between NOW and time of last check...
S HLEVLCHK(3)=HLEVLCHK(0)-HLEVLCHK(1) ; DIFF = NOW - LAST CHECK
;
; If less than 4 hours since last check, quit w/no check...
QUIT:HLEVLCHK(3)<(60*60*4) "" ;->
;
Q 1 ; Check should be made...
;
SHOWQUIT(TXT) QUIT:$D(ZTQUEUED) ;->
W !!,TXT,!
Q
;
STARTJOB ; Start a new job with optional display to screen...
N JOBS
S JOBS=$$NEWMSTR(0,1) QUIT:$D(ZTQUEUED) ;->
W !!,"New master job queued to task# ",+JOBS,"..."
W !,"Entry #",$P(JOBS,U,2)," created in HL7 Monitor Master Job file..."
Q
;
MASTER ; Whenever a master job starts, here's where it's queued...
; HLEVIENM - req
;
N D,D0,DA,DIE,DR,FLD,NOEVCHK,NOPURG,NOW,RES,ZTSKMST
;
S ZTREQ="@",NOW=$$NOW^XLFDT
;
S ZTSKMST=$G(ZTSK) QUIT:ZTSKMST'>0 ;->
;
QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']"" ;->
;
; Check parameter...
I $P($G(^HLEV(776.999,1,0)),U,2)'="A" D QUIT ;->
. F FLD=2,3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
. D UPDFLDM(+HLEVIENM,4,"A")
;
; Give (possibly just executed) $$NEWMSTR(0) DIE call time to execute...
H 2
;
; Queue next job...
S NEWJOB=$$NEWMSTR(1)
;
; What if job requested to stop?
I $P($G(^HLEV(776.2,+HLEVIENM,0)),U,4)="S" D QUIT ;->
. F FLD=2,3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
. D UPDFLDM(+HLEVIENM,4,"A")
;
; Mark entry to show it successfully started...
D UPDFLDM(+HLEVIENM,4,"R")
F FLD=3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
D UPDFLDM(+HLEVIENM,50,"Queued job started at "_$$NOW^XLFDT)
;
; Work starts here...
KILL NOEVCHK
S NOEVCHK=0
D EVENTCHK^HLEVAPI0(+HLEVIENM)
;
; Purge MONITOR and MASTER entries...
D PURGEALL^HLEVUTIL(+HLEVIENM)
;
; Mark ERROR any monitors still RUNNING by not current..
D MARKERR^HLEVAPI3
;
; Done...
D UPDFLDM(+HLEVIENM,2,$$NOW^XLFDT)
D UPDFLDM(+HLEVIENM,4,"F")
D UPDFLDM(+HLEVIENM,50,"Queued job finished at "_$$NOW^XLFDT)
D UPDFLDM(+HLEVIENM,50,"# events checked = "_$G(NOEVCHK))
S RES=""
F S RES=$O(NOEVCHK(RES)) Q:RES']"" D
. 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.")
. I RES="M" S RES(1)=" M code check failed."
. S RES(1)="#"_NOEVCHK(RES)_" Events"_RES(1)
. D UPDFLDM(+HLEVIENM,50,RES(1))
;
Q
;
NEWMSTR(FUTURE,SILENT) ; Create a new master job...
;
; If FUTURE=0, then master job will be queued for NOW...
; If FUTURE=1, then master job will be q'd for CUTMIN in future...
;
N CUTMIN,DA,DIC,DIE,DD,DO,DR,HLEVIENM,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSK,HLNOW,HLEN,HLCNT
;
; Should this process be silent?
S SILENT=$S($G(SILENT)>0:1,1:0)
;
; Check parameter...
I $P($G(^HLEV(776.999,1,0)),U,2)'="A" D QUIT "" ;->
. QUIT:$D(ZTQUEUED)!(SILENT) ;->
. W !!,"Exiting! Master job not started. Parameter turned off..."
. H 2
;
; Make master stub entry...
S X=$$NOW^XLFDT,DIC="^HLEV(776.2,",DIC(0)="L"
D FILE^DICN
S HLEVIENM=$S(+Y>0:+Y,1:"") I HLEVIENM'>0 D QUIT "" ;->
. QUIT:$D(ZTQUEUED)!(SILENT) ;->
. W !!,"Exiting! Master job not started. Stub record creation failed..."
. H 2
;
; Get CUTMIN and queue new job...
S CUTMIN=$H ; Default to NOW...
I $G(FUTURE) D
. S CUTMIN=$O(^HLEV(776.999,":"),-1),CUTMIN=$P($G(^HLEV(776.999,+CUTMIN,0)),U,3)
. S CUTMIN=$S(CUTMIN:CUTMIN,1:60) ; Default to 60 minutes between jobs...
. S CUTMIN=$$FMTH^XLFDT($$FMADD^XLFDT($$NOW^XLFDT,0,0,CUTMIN))
S ZTIO="",ZTDTH=CUTMIN,ZTDESC="HL Master Job - Event Monitoring"
S ZTRTN="MASTER^HLEVMST"
S ZTSAVE("HLEVIENM")=""
D ^%ZTLOAD
;
; Store task #, etc...
KILL DA,DD,DIC,DO,X,Y
S DA=+HLEVIENM,DIE=776.2,DR="4///Q;5///"_ZTSK_";6////"_$$HTFM^XLFDT(CUTMIN)_";7////"_+DUZ
D ^DIE
;
I '$D(ZTQUEUED)&('SILENT) D
. W !!,"Master job created. Task# ",ZTSK,", and Event# ",HLEVIENM,"..."
. H 2
;
D CHKMLT(ZTSK,HLEVIENM) ;Remove duplicate Master Jobs
QUIT $G(ZTSK)_U_HLEVIENM
;
UPDFLDM(HLEVIENM,FLD,VAL) ; Update a specific piece in 776.2...
N D,D0,DA,DI,DIE,DR
;
QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']""!($G(VAL)']"") ;->
;
; Call call here to store one 50 diary entry. (Required that
; FLD=50 and VAL=Text to store on line. Must call here one time
; for every line to be stored.)
I FLD=50 D QUIT ;-> Call call here to store one 50 diary entry
. S NODE=$G(^HLEV(776.2,+HLEVIENM,50,0))
. S:NODE']"" NODE="^776.201^^"
. S CT=$O(^HLEV(776.2,+HLEVIENM,50,":"),-1)+1
. S $P(NODE,U,3)=CT,$P(NODE,U,4)=CT
. S ^HLEV(776.2,+HLEVIENM,50,0)=NODE
. S ^HLEV(776.2,+HLEVIENM,50,+CT,0)=VAL
;
I FLD=51 QUIT ;-> Not allowed!
;
; Store zero node information...
S DA=+HLEVIENM,DIE=776.2,DR=FLD_"///"_VAL
D ^DIE
;
Q
;
STAMPM(HLEVIENM) ; Update TIMESTAMP field in event..
N D,D0,DA,DI,DIE,DR
QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']"" ;->
S DA=+HLEVIENM,DIE=776.2,DR="3////"_$$NOW^XLFDT
D ^DIE
Q
;
PURGEM(HLEVIENM) ; Purge master job entries...
N CUTIME,IENM,LOOPTM,NOPURG,RETHRM,HLPRGTM
;
; Check parameter...
QUIT:$P($G(^HLEV(776.999,1,0)),U,2)'="A" "" ;->
;
S NOPURG=0
;
; Get retention time (HR) for master job data...
S RETHRM=$O(^HLEV(776.999,":"),-1)
S RETHRM=$P($G(^HLEV(776.999,+RETHRM,0)),U,5)
S RETHRM=$S(RETHRM>0:RETHRM,1:96) ; Default to 96 hours
S HLPRGTM=$$FMADD^XLFDT($$NOW^XLFDT,0,-RETHRM)
;
; Cutoff time...
S CUTIME=$$FMADD^XLFDT($$NOW^XLFDT,0,-RETHRM)
;
F S CUTIME=$O(^HLEV(776.2,"B",CUTIME),-1) Q:CUTIME'>0 D
. S IEN=0
. F S IEN=$O(^HLEV(776.2,"B",CUTIME,IEN)) Q:IEN'>0 D
. . QUIT:IEN=HLEVIENM ;-> Don't delete yourself!!
. . S NOPURG=NOPURG+1
. . D PURGEME^HLEVUTIL(+IEN) ; Delete events in master job...
. . D DELETE^HLEVUTIL(776.2,+IEN)
;
Q NOPURG
;
CHKMLT(HLTSK,HLNWIEN) ;Check if multiple Master Jobs running; remove duplicate jobs - HL*1.6*173
N HLSTSK,HLIEN,HLIENS,HLNWIENS,HLQTM,HLNWQTM,HLRSN
Q:'HLTSK Q:'HLNWIEN ;Quit if no new job run
S HLNWIENS=HLNWIEN_",",HLRSN="Remove Duplicate Master Job"
S HLNOW=$$NOW^XLFDT,HLIEN=0 F S HLIEN=$O(^HLEV(776.2,HLIEN)) Q:'HLIEN D
.S HLIENS=HLIEN_"," I $$GET1^DIQ(776.2,HLIENS,6,"I")>HLNOW D
..Q:$$GET1^DIQ(776.2,HLIENS,4,"I")='"Q" ;Quit if job not queued
..S HLSTSK=$$GET1^DIQ(776.2,HLIENS,5) I HLSTSK'=HLTSK Q:$G(ZTSKMST)=HLSTSK D
...S HLQTM=$$GET1^DIQ(776.2,HLIENS,6),HLNWQTM=$$GET1^DIQ(776.2,HLNWIENS,6) Q:HLQTM>HLNWQTM
...D UNQ^HLEVUTIL(HLIEN,HLSTSK,HLRSN)
Q
;
EOR ;HLEVMST - Event Monitor MASTER JOB ;5/16/03 14:42
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HHLEVMST 9375 printed Nov 22, 2024@17:07:53 Page 2
HLEVMST ;O-OIFO/LJA - Event Monitor MASTER JOB ;02/04/2004 14:42
+1 ;;1.6;HEALTH LEVEL SEVEN;**109,173,176**;Oct 13, 1995;Build 4
+2 ;;Per VA Directive 6402, this routine should not be modified.
+3 ;
+4 ; Calling STARTJOB always queues a new master job NOW...
+5 ;
MSTENV ; Display environment to user...
+1 ;
+2 ;
+3 ; Collect Master Job Information
+4 ;
+5 ;
+6 ; Collect Active Event Monitors
+7 ;
+8 ;
+9 QUIT
+10 ;
CHECKMST ; Called from outside Event Monitoring, from the Link Manager,
+1 ; to see if the master job needs to be started. (See ^HLCSLM.)
+2 ; When the Link Manager calls here, two actions potentially occur:
+3 ;
+4 ; * Check is made whether this CHECKMST code has been run before,
+5 ; and if so, how long ago. This check is performed by $$TIMECHK.
+6 ; * If never run, or if run more than four hours ago, CHECKMST is run.
+7 ;
+8 ; CHECKMST checks whether a master job is running, or is properly
+9 ; queued. If not, it queues a master job.
+10 ;
+11 NEW LAPSE,LASTDT,LASTIEN,NODE,PAR0,RUNOW,RUNTIME,X
+12 ;
+13 ;->
if '$$TIMECHK
QUIT
+14 ;
+15 ; Set last check time for later use by $$TIMECHK...
+16 SET HLEVLCHK(1)=$$SEC^HLEVMST0($HOROLOG)
+17 ;
+18 ; Parameter status check...
+19 ;->
SET PAR0=$GET(^HLEV(776.999,1,0))
if PAR0']""
QUIT
+20 ;-> Not ACTIVE...
IF $PIECE(PAR0,U,2)'="A"
Begin DoDot:1
+21 DO SHOWQUIT("Master job not started. Parameter STATUS is INACTIVE...")
End DoDot:1
QUIT
+22 ;
+23 ; Lapse (since last run) check...
+24 ;->
SET LAPSE=$PIECE(PAR0,U,3)
IF LAPSE'>0
Begin DoDot:1
+25 DO SHOWQUIT("Master job not started. Master Job Interval not set up...")
End DoDot:1
QUIT
+26 ; Get IEN for last master job run
+27 SET LASTDT=$ORDER(^HLEV(776.2,"B",":"),-1)
+28 SET LASTIEN=$ORDER(^HLEV(776.2,"B",+LASTDT,":"),-1)
+29 ;
+30 ;->
IF LASTIEN'>0
DO STARTJOB
QUIT
+31 SET NODE=$GET(^HLEV(776.2,+LASTIEN,0))
+32 ;->
SET X=$PIECE(NODE,U,4)
IF X="E"!(X="P")
DO STARTJOB
QUIT
+33 ; Queue time for last run...
SET RUNTIME=$PIECE(NODE,U,6)
+34 ; No start unless 15" overdue
SET RUNOW=$$RUNEV^HLEVAPI0(RUNTIME,LAPSE+15)
+35 ;-> 15" overdue!! So, start master job
IF RUNOW
DO STARTJOB
QUIT
+36 DO SHOWQUIT("Master job not started. Not time yet...")
+37 ;
+38 QUIT
+39 ;
TIMECHK() ; Every loop in the Link Manager code in HLCSLM results in one
+1 ; call being made to CHECKMST^HLEVMST. The CHECKMST subroutine in turn
+2 ; calls here to ensure that the Event Monitor's master job is running
+3 ; properly. However, the CHECKMST subroutine should be run by HLCSLM
+4 ; only once every four hours. The code in this subroutine uses
+5 ; HLEVLCHK(#) variables to ensure that this every four hour rule is
+6 ; followed. (HLEVLCHK is newed at the top of HLCSLM.)
+7 ;
+8 ; Set the time NOW in seconds...
+9 SET HLEVLCHK(0)=$$SEC^HLEVMST0($HOROLOG)
+10 ;
+11 ; This is the time of last check. Make sure it exists...
+12 SET HLEVLCHK(1)=$GET(HLEVLCHK(1))
+13 ;
+14 ; If no check every made, make a check now...
+15 ;->
IF HLEVLCHK(1)'>0
QUIT 1
+16 ;
+17 ; Set the number seconds between NOW and time of last check...
+18 ; DIFF = NOW - LAST CHECK
SET HLEVLCHK(3)=HLEVLCHK(0)-HLEVLCHK(1)
+19 ;
+20 ; If less than 4 hours since last check, quit w/no check...
+21 ;->
if HLEVLCHK(3)<(60*60*4)
QUIT ""
+22 ;
+23 ; Check should be made...
QUIT 1
+24 ;
SHOWQUIT(TXT) ;->
if $DATA(ZTQUEUED)
QUIT
+1 WRITE !!,TXT,!
+2 QUIT
+3 ;
STARTJOB ; Start a new job with optional display to screen...
+1 NEW JOBS
+2 ;->
SET JOBS=$$NEWMSTR(0,1)
if $DATA(ZTQUEUED)
QUIT
+3 WRITE !!,"New master job queued to task# ",+JOBS,"..."
+4 WRITE !,"Entry #",$PIECE(JOBS,U,2)," created in HL7 Monitor Master Job file..."
+5 QUIT
+6 ;
MASTER ; Whenever a master job starts, here's where it's queued...
+1 ; HLEVIENM - req
+2 ;
+3 NEW D,D0,DA,DIE,DR,FLD,NOEVCHK,NOPURG,NOW,RES,ZTSKMST
+4 ;
+5 SET ZTREQ="@"
SET NOW=$$NOW^XLFDT
+6 ;
+7 ;->
SET ZTSKMST=$GET(ZTSK)
if ZTSKMST'>0
QUIT
+8 ;
+9 ;->
if $GET(^HLEV(776.2,+$GET(HLEVIENM),0))']""
QUIT
+10 ;
+11 ; Check parameter...
+12 ;->
IF $PIECE($GET(^HLEV(776.999,1,0)),U,2)'="A"
Begin DoDot:1
+13 FOR FLD=2,3,8
DO UPDFLDM(+HLEVIENM,FLD,NOW)
+14 DO UPDFLDM(+HLEVIENM,4,"A")
End DoDot:1
QUIT
+15 ;
+16 ; Give (possibly just executed) $$NEWMSTR(0) DIE call time to execute...
+17 HANG 2
+18 ;
+19 ; Queue next job...
+20 SET NEWJOB=$$NEWMSTR(1)
+21 ;
+22 ; What if job requested to stop?
+23 ;->
IF $PIECE($GET(^HLEV(776.2,+HLEVIENM,0)),U,4)="S"
Begin DoDot:1
+24 FOR FLD=2,3,8
DO UPDFLDM(+HLEVIENM,FLD,NOW)
+25 DO UPDFLDM(+HLEVIENM,4,"A")
End DoDot:1
QUIT
+26 ;
+27 ; Mark entry to show it successfully started...
+28 DO UPDFLDM(+HLEVIENM,4,"R")
+29 FOR FLD=3,8
DO UPDFLDM(+HLEVIENM,FLD,NOW)
+30 DO UPDFLDM(+HLEVIENM,50,"Queued job started at "_$$NOW^XLFDT)
+31 ;
+32 ; Work starts here...
+33 KILL NOEVCHK
+34 SET NOEVCHK=0
+35 DO EVENTCHK^HLEVAPI0(+HLEVIENM)
+36 ;
+37 ; Purge MONITOR and MASTER entries...
+38 DO PURGEALL^HLEVUTIL(+HLEVIENM)
+39 ;
+40 ; Mark ERROR any monitors still RUNNING by not current..
+41 DO MARKERR^HLEVAPI3
+42 ;
+43 ; Done...
+44 DO UPDFLDM(+HLEVIENM,2,$$NOW^XLFDT)
+45 DO UPDFLDM(+HLEVIENM,4,"F")
+46 DO UPDFLDM(+HLEVIENM,50,"Queued job finished at "_$$NOW^XLFDT)
+47 DO UPDFLDM(+HLEVIENM,50,"# events checked = "_$GET(NOEVCHK))
+48 SET RES=""
+49 FOR
SET RES=$ORDER(NOEVCHK(RES))
if RES']""
QUIT
Begin DoDot:1
+50 SET RES(1)=$SELECT(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 disposi
tion.")
+51 IF RES="M"
SET RES(1)=" M code check failed."
+52 SET RES(1)="#"_NOEVCHK(RES)_" Events"_RES(1)
+53 DO UPDFLDM(+HLEVIENM,50,RES(1))
End DoDot:1
+54 ;
+55 QUIT
+56 ;
NEWMSTR(FUTURE,SILENT) ; Create a new master job...
+1 ;
+2 ; If FUTURE=0, then master job will be queued for NOW...
+3 ; If FUTURE=1, then master job will be q'd for CUTMIN in future...
+4 ;
+5 NEW CUTMIN,DA,DIC,DIE,DD,DO,DR,HLEVIENM,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSK,HLNOW,HLEN,HLCNT
+6 ;
+7 ; Should this process be silent?
+8 SET SILENT=$SELECT($GET(SILENT)>0:1,1:0)
+9 ;
+10 ; Check parameter...
+11 ;->
IF $PIECE($GET(^HLEV(776.999,1,0)),U,2)'="A"
Begin DoDot:1
+12 ;->
if $DATA(ZTQUEUED)!(SILENT)
QUIT
+13 WRITE !!,"Exiting! Master job not started. Parameter turned off..."
+14 HANG 2
End DoDot:1
QUIT ""
+15 ;
+16 ; Make master stub entry...
+17 SET X=$$NOW^XLFDT
SET DIC="^HLEV(776.2,"
SET DIC(0)="L"
+18 DO FILE^DICN
+19 ;->
SET HLEVIENM=$SELECT(+Y>0:+Y,1:"")
IF HLEVIENM'>0
Begin DoDot:1
+20 ;->
if $DATA(ZTQUEUED)!(SILENT)
QUIT
+21 WRITE !!,"Exiting! Master job not started. Stub record creation failed..."
+22 HANG 2
End DoDot:1
QUIT ""
+23 ;
+24 ; Get CUTMIN and queue new job...
+25 ; Default to NOW...
SET CUTMIN=$HOROLOG
+26 IF $GET(FUTURE)
Begin DoDot:1
+27 SET CUTMIN=$ORDER(^HLEV(776.999,":"),-1)
SET CUTMIN=$PIECE($GET(^HLEV(776.999,+CUTMIN,0)),U,3)
+28 ; Default to 60 minutes between jobs...
SET CUTMIN=$SELECT(CUTMIN:CUTMIN,1:60)
+29 SET CUTMIN=$$FMTH^XLFDT($$FMADD^XLFDT($$NOW^XLFDT,0,0,CUTMIN))
End DoDot:1
+30 SET ZTIO=""
SET ZTDTH=CUTMIN
SET ZTDESC="HL Master Job - Event Monitoring"
+31 SET ZTRTN="MASTER^HLEVMST"
+32 SET ZTSAVE("HLEVIENM")=""
+33 DO ^%ZTLOAD
+34 ;
+35 ; Store task #, etc...
+36 KILL DA,DD,DIC,DO,X,Y
+37 SET DA=+HLEVIENM
SET DIE=776.2
SET DR="4///Q;5///"_ZTSK_";6////"_$$HTFM^XLFDT(CUTMIN)_";7////"_+DUZ
+38 DO ^DIE
+39 ;
+40 IF '$DATA(ZTQUEUED)&('SILENT)
Begin DoDot:1
+41 WRITE !!,"Master job created. Task# ",ZTSK,", and Event# ",HLEVIENM,"..."
+42 HANG 2
End DoDot:1
+43 ;
+44 ;Remove duplicate Master Jobs
DO CHKMLT(ZTSK,HLEVIENM)
+45 QUIT $GET(ZTSK)_U_HLEVIENM
+46 ;
UPDFLDM(HLEVIENM,FLD,VAL) ; Update a specific piece in 776.2...
+1 NEW D,D0,DA,DI,DIE,DR
+2 ;
+3 ;->
if $GET(^HLEV(776.2,+$GET(HLEVIENM),0))']""!($GET(VAL)']"")
QUIT
+4 ;
+5 ; Call call here to store one 50 diary entry. (Required that
+6 ; FLD=50 and VAL=Text to store on line. Must call here one time
+7 ; for every line to be stored.)
+8 ;-> Call call here to store one 50 diary entry
IF FLD=50
Begin DoDot:1
+9 SET NODE=$GET(^HLEV(776.2,+HLEVIENM,50,0))
+10 if NODE']""
SET NODE="^776.201^^"
+11 SET CT=$ORDER(^HLEV(776.2,+HLEVIENM,50,":"),-1)+1
+12 SET $PIECE(NODE,U,3)=CT
SET $PIECE(NODE,U,4)=CT
+13 SET ^HLEV(776.2,+HLEVIENM,50,0)=NODE
+14 SET ^HLEV(776.2,+HLEVIENM,50,+CT,0)=VAL
End DoDot:1
QUIT
+15 ;
+16 ;-> Not allowed!
IF FLD=51
QUIT
+17 ;
+18 ; Store zero node information...
+19 SET DA=+HLEVIENM
SET DIE=776.2
SET DR=FLD_"///"_VAL
+20 DO ^DIE
+21 ;
+22 QUIT
+23 ;
STAMPM(HLEVIENM) ; Update TIMESTAMP field in event..
+1 NEW D,D0,DA,DI,DIE,DR
+2 ;->
if $GET(^HLEV(776.2,+$GET(HLEVIENM),0))']""
QUIT
+3 SET DA=+HLEVIENM
SET DIE=776.2
SET DR="3////"_$$NOW^XLFDT
+4 DO ^DIE
+5 QUIT
+6 ;
PURGEM(HLEVIENM) ; Purge master job entries...
+1 NEW CUTIME,IENM,LOOPTM,NOPURG,RETHRM,HLPRGTM
+2 ;
+3 ; Check parameter...
+4 ;->
if $PIECE($GET(^HLEV(776.999,1,0)),U,2)'="A"
QUIT ""
+5 ;
+6 SET NOPURG=0
+7 ;
+8 ; Get retention time (HR) for master job data...
+9 SET RETHRM=$ORDER(^HLEV(776.999,":"),-1)
+10 SET RETHRM=$PIECE($GET(^HLEV(776.999,+RETHRM,0)),U,5)
+11 ; Default to 96 hours
SET RETHRM=$SELECT(RETHRM>0:RETHRM,1:96)
+12 SET HLPRGTM=$$FMADD^XLFDT($$NOW^XLFDT,0,-RETHRM)
+13 ;
+14 ; Cutoff time...
+15 SET CUTIME=$$FMADD^XLFDT($$NOW^XLFDT,0,-RETHRM)
+16 ;
+17 FOR
SET CUTIME=$ORDER(^HLEV(776.2,"B",CUTIME),-1)
if CUTIME'>0
QUIT
Begin DoDot:1
+18 SET IEN=0
+19 FOR
SET IEN=$ORDER(^HLEV(776.2,"B",CUTIME,IEN))
if IEN'>0
QUIT
Begin DoDot:2
+20 ;-> Don't delete yourself!!
if IEN=HLEVIENM
QUIT
+21 SET NOPURG=NOPURG+1
+22 ; Delete events in master job...
DO PURGEME^HLEVUTIL(+IEN)
+23 DO DELETE^HLEVUTIL(776.2,+IEN)
End DoDot:2
End DoDot:1
+24 ;
+25 QUIT NOPURG
+26 ;
CHKMLT(HLTSK,HLNWIEN) ;Check if multiple Master Jobs running; remove duplicate jobs - HL*1.6*173
+1 NEW HLSTSK,HLIEN,HLIENS,HLNWIENS,HLQTM,HLNWQTM,HLRSN
+2 ;Quit if no new job run
if 'HLTSK
QUIT
if 'HLNWIEN
QUIT
+3 SET HLNWIENS=HLNWIEN_","
SET HLRSN="Remove Duplicate Master Job"
+4 SET HLNOW=$$NOW^XLFDT
SET HLIEN=0
FOR
SET HLIEN=$ORDER(^HLEV(776.2,HLIEN))
if 'HLIEN
QUIT
Begin DoDot:1
+5 SET HLIENS=HLIEN_","
IF $$GET1^DIQ(776.2,HLIENS,6,"I")>HLNOW
Begin DoDot:2
+6 ;Quit if job not queued
if $$GET1^DIQ(776.2,HLIENS,4,"I")='"Q"
QUIT
+7 SET HLSTSK=$$GET1^DIQ(776.2,HLIENS,5)
IF HLSTSK'=HLTSK
if $GET(ZTSKMST)=HLSTSK
QUIT
Begin DoDot:3
+8 SET HLQTM=$$GET1^DIQ(776.2,HLIENS,6)
SET HLNWQTM=$$GET1^DIQ(776.2,HLNWIENS,6)
if HLQTM>HLNWQTM
QUIT
+9 DO UNQ^HLEVUTIL(HLIEN,HLSTSK,HLRSN)
End DoDot:3
End DoDot:2
End DoDot:1
+10 QUIT
+11 ;
EOR ;HLEVMST - Event Monitor MASTER JOB ;5/16/03 14:42