Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: HLEVMST

HLEVMST.m

Go to the documentation of this file.
  1. HLEVMST ;O-OIFO/LJA - Event Monitor MASTER JOB ;02/04/2004 14:42
  1. ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
  1. ;
  1. ; Calling STARTJOB always queues a new master job NOW...
  1. ;
  1. MSTENV ; Display environment to user...
  1. ;
  1. ;
  1. ; Collect Master Job Information
  1. ;
  1. ;
  1. ; Collect Active Event Monitors
  1. ;
  1. ;
  1. Q
  1. ;
  1. CHECKMST ; Called from outside Event Monitoring, from the Link Manager,
  1. ; to see if the master job needs to be started. (See ^HLCSLM.)
  1. ; When the Link Manager calls here, two actions potentially occur:
  1. ;
  1. ; * Check is made whether this CHECKMST code has been run before,
  1. ; and if so, how long ago. This check is performed by $$TIMECHK.
  1. ; * If never run, or if run more than four hours ago, CHECKMST is run.
  1. ;
  1. ; CHECKMST checks whether a master job is running, or is properly
  1. ; queued. If not, it queues a master job.
  1. ;
  1. N LAPSE,LASTDT,LASTIEN,NODE,PAR0,RUNOW,RUNTIME,X
  1. ;
  1. QUIT:'$$TIMECHK ;->
  1. ;
  1. ; Set last check time for later use by $$TIMECHK...
  1. S HLEVLCHK(1)=$$SEC^HLEVMST0($H)
  1. ;
  1. ; Parameter status check...
  1. S PAR0=$G(^HLEV(776.999,1,0)) Q:PAR0']"" ;->
  1. I $P(PAR0,U,2)'="A" D QUIT ;-> Not ACTIVE...
  1. . D SHOWQUIT("Master job not started. Parameter STATUS is INACTIVE...")
  1. ;
  1. ; Lapse (since last run) check...
  1. S LAPSE=$P(PAR0,U,3) I LAPSE'>0 D QUIT ;->
  1. . D SHOWQUIT("Master job not started. Master Job Interval not set up...")
  1. ; Get IEN for last master job run
  1. S LASTDT=$O(^HLEV(776.2,"B",":"),-1)
  1. S LASTIEN=$O(^HLEV(776.2,"B",+LASTDT,":"),-1)
  1. ;
  1. I LASTIEN'>0 D STARTJOB QUIT ;->
  1. S NODE=$G(^HLEV(776.2,+LASTIEN,0))
  1. S X=$P(NODE,U,4) I X="E"!(X="P") D STARTJOB QUIT ;->
  1. S RUNTIME=$P(NODE,U,6) ; Queue time for last run...
  1. S RUNOW=$$RUNEV^HLEVAPI0(RUNTIME,LAPSE+15) ; No start unless 15" overdue
  1. I RUNOW D STARTJOB QUIT ;-> 15" overdue!! So, start master job
  1. D SHOWQUIT("Master job not started. Not time yet...")
  1. ;
  1. Q
  1. ;
  1. 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
  1. ; calls here to ensure that the Event Monitor's master job is running
  1. ; properly. However, the CHECKMST subroutine should be run by HLCSLM
  1. ; only once every four hours. The code in this subroutine uses
  1. ; HLEVLCHK(#) variables to ensure that this every four hour rule is
  1. ; followed. (HLEVLCHK is newed at the top of HLCSLM.)
  1. ;
  1. ; Set the time NOW in seconds...
  1. S HLEVLCHK(0)=$$SEC^HLEVMST0($H)
  1. ;
  1. ; This is the time of last check. Make sure it exists...
  1. S HLEVLCHK(1)=$G(HLEVLCHK(1))
  1. ;
  1. ; If no check every made, make a check now...
  1. I HLEVLCHK(1)'>0 QUIT 1 ;->
  1. ;
  1. ; Set the number seconds between NOW and time of last check...
  1. S HLEVLCHK(3)=HLEVLCHK(0)-HLEVLCHK(1) ; DIFF = NOW - LAST CHECK
  1. ;
  1. ; If less than 4 hours since last check, quit w/no check...
  1. QUIT:HLEVLCHK(3)<(60*60*4) "" ;->
  1. ;
  1. Q 1 ; Check should be made...
  1. ;
  1. SHOWQUIT(TXT) QUIT:$D(ZTQUEUED) ;->
  1. W !!,TXT,!
  1. Q
  1. ;
  1. STARTJOB ; Start a new job with optional display to screen...
  1. N JOBS
  1. S JOBS=$$NEWMSTR(0,1) QUIT:$D(ZTQUEUED) ;->
  1. W !!,"New master job queued to task# ",+JOBS,"..."
  1. W !,"Entry #",$P(JOBS,U,2)," created in HL7 Monitor Master Job file..."
  1. Q
  1. ;
  1. MASTER ; Whenever a master job starts, here's where it's queued...
  1. ; HLEVIENM - req
  1. ;
  1. N D,D0,DA,DIE,DR,FLD,NOEVCHK,NOPURG,NOW,RES,ZTSKMST
  1. ;
  1. S ZTREQ="@",NOW=$$NOW^XLFDT
  1. ;
  1. S ZTSKMST=$G(ZTSK) QUIT:ZTSKMST'>0 ;->
  1. ;
  1. QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']"" ;->
  1. ;
  1. ; Check parameter...
  1. I $P($G(^HLEV(776.999,1,0)),U,2)'="A" D QUIT ;->
  1. . F FLD=2,3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
  1. . D UPDFLDM(+HLEVIENM,4,"A")
  1. ;
  1. ; Give (possibly just executed) $$NEWMSTR(0) DIE call time to execute...
  1. H 2
  1. ;
  1. ; Queue next job...
  1. S NEWJOB=$$NEWMSTR(1)
  1. ;
  1. ; What if job requested to stop?
  1. I $P($G(^HLEV(776.2,+HLEVIENM,0)),U,4)="S" D QUIT ;->
  1. . F FLD=2,3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
  1. . D UPDFLDM(+HLEVIENM,4,"A")
  1. ;
  1. ; Mark entry to show it successfully started...
  1. D UPDFLDM(+HLEVIENM,4,"R")
  1. F FLD=3,8 D UPDFLDM(+HLEVIENM,FLD,NOW)
  1. D UPDFLDM(+HLEVIENM,50,"Queued job started at "_$$NOW^XLFDT)
  1. ;
  1. ; Work starts here...
  1. KILL NOEVCHK
  1. S NOEVCHK=0
  1. D EVENTCHK^HLEVAPI0(+HLEVIENM)
  1. ;
  1. ; Purge MONITOR and MASTER entries...
  1. D PURGEALL^HLEVUTIL(+HLEVIENM)
  1. ;
  1. ; Mark ERROR any monitors still RUNNING by not current..
  1. D MARKERR^HLEVAPI3
  1. ;
  1. ; Done...
  1. D UPDFLDM(+HLEVIENM,2,$$NOW^XLFDT)
  1. D UPDFLDM(+HLEVIENM,4,"F")
  1. D UPDFLDM(+HLEVIENM,50,"Queued job finished at "_$$NOW^XLFDT)
  1. D UPDFLDM(+HLEVIENM,50,"# events checked = "_$G(NOEVCHK))
  1. S RES=""
  1. F S RES=$O(NOEVCHK(RES)) Q:RES']"" D
  1. . 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.")
  1. . I RES="M" S RES(1)=" M code check failed."
  1. . S RES(1)="#"_NOEVCHK(RES)_" Events"_RES(1)
  1. . D UPDFLDM(+HLEVIENM,50,RES(1))
  1. ;
  1. Q
  1. ;
  1. NEWMSTR(FUTURE,SILENT) ; Create a new master job...
  1. ;
  1. ; If FUTURE=0, then master job will be queued for NOW...
  1. ; If FUTURE=1, then master job will be q'd for CUTMIN in future...
  1. ;
  1. N CUTMIN,DA,DIC,DIE,DD,DO,DR,HLEVIENM,X,Y,ZTDESC,ZTDTH,ZTIO,ZTRTN,ZTSK
  1. ;
  1. ; Should this process be silent?
  1. S SILENT=$S($G(SILENT)>0:1,1:0)
  1. ;
  1. ; Check parameter...
  1. I $P($G(^HLEV(776.999,1,0)),U,2)'="A" D QUIT "" ;->
  1. . QUIT:$D(ZTQUEUED)!(SILENT) ;->
  1. . W !!,"Exiting! Master job not started. Parameter turned off..."
  1. . H 2
  1. ;
  1. ; Make master stub entry...
  1. S X=$$NOW^XLFDT,DIC="^HLEV(776.2,",DIC(0)="L"
  1. D FILE^DICN
  1. S HLEVIENM=$S(+Y>0:+Y,1:"") I HLEVIENM'>0 D QUIT "" ;->
  1. . QUIT:$D(ZTQUEUED)!(SILENT) ;->
  1. . W !!,"Exiting! Master job not started. Stub record creation failed..."
  1. . H 2
  1. ;
  1. ; Get CUTMIN and queue new job...
  1. S CUTMIN=$H ; Default to NOW...
  1. I $G(FUTURE) D
  1. . S CUTMIN=$O(^HLEV(776.999,":"),-1),CUTMIN=$P($G(^HLEV(776.999,+CUTMIN,0)),U,3)
  1. . S CUTMIN=$S(CUTMIN:CUTMIN,1:60) ; Default to 60 minutes between jobs...
  1. . S CUTMIN=$$FMTH^XLFDT($$FMADD^XLFDT($$NOW^XLFDT,0,0,CUTMIN))
  1. S ZTIO="",ZTDTH=CUTMIN,ZTDESC="HL Master Job - Event Monitoring"
  1. S ZTRTN="MASTER^HLEVMST"
  1. S ZTSAVE("HLEVIENM")=""
  1. D ^%ZTLOAD
  1. ;
  1. ; Store task #, etc...
  1. KILL DA,DD,DIC,DO,X,Y
  1. S DA=+HLEVIENM,DIE=776.2,DR="4///Q;5///"_ZTSK_";6////"_$$HTFM^XLFDT(CUTMIN)_";7////"_+DUZ
  1. D ^DIE
  1. ;
  1. I '$D(ZTQUEUED)&('SILENT) D
  1. . W !!,"Master job created. Task# ",ZTSK,", and Event# ",HLEVIENM,"..."
  1. . H 2
  1. ;
  1. QUIT $G(ZTSK)_U_HLEVIENM
  1. ;
  1. UPDFLDM(HLEVIENM,FLD,VAL) ; Update a specific piece in 776.2...
  1. N D,D0,DA,DI,DIE,DR
  1. ;
  1. QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']""!($G(VAL)']"") ;->
  1. ;
  1. ; Call call here to store one 50 diary entry. (Required that
  1. ; FLD=50 and VAL=Text to store on line. Must call here one time
  1. ; for every line to be stored.)
  1. I FLD=50 D QUIT ;-> Call call here to store one 50 diary entry
  1. . S NODE=$G(^HLEV(776.2,+HLEVIENM,50,0))
  1. . S:NODE']"" NODE="^776.201^^"
  1. . S CT=$O(^HLEV(776.2,+HLEVIENM,50,":"),-1)+1
  1. . S $P(NODE,U,3)=CT,$P(NODE,U,4)=CT
  1. . S ^HLEV(776.2,+HLEVIENM,50,0)=NODE
  1. . S ^HLEV(776.2,+HLEVIENM,50,+CT,0)=VAL
  1. ;
  1. I FLD=51 QUIT ;-> Not allowed!
  1. ;
  1. ; Store zero node information...
  1. S DA=+HLEVIENM,DIE=776.2,DR=FLD_"///"_VAL
  1. D ^DIE
  1. ;
  1. Q
  1. ;
  1. STAMPM(HLEVIENM) ; Update TIMESTAMP field in event..
  1. N D,D0,DA,DI,DIE,DR
  1. QUIT:$G(^HLEV(776.2,+$G(HLEVIENM),0))']"" ;->
  1. S DA=+HLEVIENM,DIE=776.2,DR="3////"_$$NOW^XLFDT
  1. D ^DIE
  1. Q
  1. ;
  1. PURGEM(HLEVIENM) ; Purge master job entries...
  1. N CUTIME,IENM,LOOPTM,NOPURG,RETHRM
  1. ;
  1. ; Check parameter...
  1. QUIT:$P($G(^HLEV(776.999,1,0)),U,2)'="A" "" ;->
  1. ;
  1. S NOPURG=0
  1. ;
  1. ; Get retention time (HR) for master job data...
  1. S RETHRM=$O(^HLEV(776.999,":"),-1)
  1. S RETHRM=$P($G(^HLEV(776.999,+RETHRM,0)),U,5)
  1. S RETHRM=$S(RETHRM>0:RETHRM,1:96) ; Default to 96 hours
  1. ;
  1. ; Cutoff time...
  1. S CUTIME=$$FMADD^XLFDT($$NOW^XLFDT,0,-RETHRM)
  1. ;
  1. F S CUTIME=$O(^HLEV(776.2,"B",CUTIME),-1) Q:CUTIME'>0 D
  1. . S IEN=0
  1. . F S IEN=$O(^HLEV(776.2,"B",CUTIME,IEN)) Q:IEN'>0 D
  1. . . QUIT:IEN=HLEVIENM ;-> Don't delete yourself!!
  1. . . S NOPURG=NOPURG+1
  1. . . D PURGEME^HLEVUTIL(+IEN) ; Delete events in master job...
  1. . . D DELETE^HLEVUTIL(776.2,+IEN)
  1. ;
  1. Q NOPURG
  1. ;
  1. EOR ;HLEVMST - Event Monitor MASTER JOB ;5/16/03 14:42