HLEVMST0 ;O-OIFO/LJA - Event Monitor MASTER JOB ;02/04/2004 14:42
 ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
 ;
UNQUEUE ; Unqueue master job...
 N DIFF,IOINHI,IOINORM,LAST0,LASTDT,LASTIEN,NEXTH,SECNEXT
 N SECNOW,TASKNO,ZTDTH,ZTSK
 ;
 S X="IOINHI;IOINORM" D ENDR^%ZISS
 ;
 D HDU
 D EXU
 ;
 W !
 ;
 S LASTDT=$O(^HLEV(776.2,"B",":"),-1)
 S LASTIEN=$O(^HLEV(776.2,"B",+LASTDT,":"),-1)
 S LAST0=$G(^HLEV(776.2,+LASTIEN,0)) I $P(LAST0,U,4)'="Q" D  QUIT  ;->
 .  D TELL("The most recently queued master job is no longer active...","1^2^999")
 ;
 S LASTSK=$P(LAST0,U,5) I LASTSK>0 D
 .  W !,"The current master job is task# ",$P(LAST0,U,5),", queued for "
 .  W $$FMTE^XLFDT(+$P(LAST0,U,6)),"."
 ;
 W !
 I '$$YN^HLCSRPT4("OK to stop master job now","No") D  QUIT  ;->
 .  W "     no action taken..."
 ;
 W "   Master job stopped..."
 W !!,IOINHI,"Important!!",IOINORM,"  You must remember to start a new master job!!"
 ;
 D UNQ^HLEVUTIL(+LASTIEN,+LASTSK,"Master job stopped by "_$P($G(^VA(200,+$G(DUZ),0)),U)_".")
 ;
 D TELL("","0^0^999")
 ;
 Q
 ;
HDU W @IOF,$$CJ^XLFSTR("Unqueue Master Job",IOM)
 W !,$$REPEAT^XLFSTR("=",IOM)
 QUIT
 ;
EXU N I,T F I=1:1 S T=$T(EXU+I) QUIT:T'[";;"  W !,$P(T,";;",2,99)
 ;;If a master job has been queued to a future time, it can be unqueued now.
 ;;
 ;;Note:  If you unqueue this task, no future master jobs will run until you
 ;;       manually start a new master job.  (Start new master jobs with the 
 ;;       '' menu option.)
 QUIT
 ;
MSTNOW ; Start queued master job now!
 N DIFF,LAST0,LASTDT,LASTIEN,NEXTH,SECNEXT,SECNOW,TASKNO,ZTDTH,ZTSK
 ;
 W @IOF,$$CJ^XLFSTR("Master Job ""Run Now"" Utility",IOM)
 W !,$$REPEAT^XLFSTR("=",IOM)
 W !
 ;
 S LASTDT=$O(^HLEV(776.2,"B",":"),-1) ; Last (probably queued) job time
 S LASTIEN=$O(^HLEV(776.2,"B",+LASTDT,":"),-1)
 S LAST0=$G(^HLEV(776.2,+LASTIEN,0)) I LAST0']"" D
 .  W !,"Couldn't find last master job entry..."
 ;
 S TASKNO=$P(LAST0,U,5) I '$D(^%ZTSK(+TASKNO)) D
 .  W !,"Couldn't find task",$S(TASKNO:"# "_TASKNO_"...",1:".")
 ;
 S TASK0=$G(^%ZTSK(+TASKNO,0)) I TASK0']""  D
 .  W !,"Couldn't find task# ",TASKNO,"'S zero node..."
 ;
 S NEXTH=$P(TASK0,U,6) I NEXTH'?1.N1","1.N D
 .  W !,"Invalid future queue time ($H)..."
 ;
 S SECNEXT=$$SEC(NEXTH)
 S SECNOW=$$SEC($H)
 ;
 S DIFF=SECNEXT-SECNOW
 I DIFF<60 D  QUIT  ;->
 .  I DIFF<1 W !,"Master job will start any moment!" QUIT  ;->
 .  W !,"Master job will start on its own in ",DIFF," seconds..."
 ;
 I '$D(^%ZTSCH(SECNEXT,TASKNO)) D
 .  W !,"Couldn't find ^%ZTSK(SEC,ZTSK) node..."
 ;
 W !,"This utility allows you to run the master job ahead of it's currently"
 W !,"scheduled time to run."
 ;
 W !!,"Master task# ",TASKNO," is queued to "
 W $$SDT^HLEVX001($$HTFM^XLFDT(NEXTH))
 W " and it will be started now..."
 ;
 W !
 I '$$YN^HLCSRPT4("OK to start now","No") D  QUIT  ;->
 .  W "     no action taken..."
 ;
 S ZTSK=TASKNO,ZTDTH=$H
 D REQ^%ZTLOAD
 ;
 W !!,"Master job requeued to 'now'..."
 ;
 Q
 ;
STARTMST ; Start brand new master job now (interactively)!
 N DIFF,IOINHI,IOINORM,LAST0,LASTDT,LASTIEN,NEXTH,SECNEXT
 N SECNOW,TASKNO,ZTDTH,ZTSK
 ;
 S LASTDT=$O(^HLEV(776.2,"B",":"),-1)
 S LASTIEN=$O(^HLEV(776.2,"B",+LASTDT,":"),-1)
 S LAST0=$G(^HLEV(776.2,+LASTIEN,0))
 S TASKNO=$P(LAST0,U,5)
 ;
 ; If this option is accessed by queued background job, just unqueue
 ; everything to make sure, and start a new master job for NOW...
 I $D(ZTQUEUED) D  QUIT  ;->
 .  D UNQ^HLEVUTIL(+LASTIEN,+TASKNO,"Reboot unqueue/requeue master job.")
 .  D STARTJOB^HLEVMST
 ;
 S X="IOINHI;IOINORM" D ENDR^%ZISS
 ;
 D HD
 D EX
 ;
 W !
 ;
 I $P(LAST0,U,4)="Q" D  QUIT  ;->
 .  D TELL("It appears as if task# "_$P(LAST0,U,5)_" has already been queued.","1^2^999")
 ;
 I $P(LAST0,U,5)>0 D
 .  W !!,"The ",IOINHI,"last",IOINORM
 .  W " master job was task# ",$P(LAST0,U,5),", queued "
 .  W $$FMTE^XLFDT(+LAST0),"."
 ;
 W !
 I '$$YN^HLCSRPT4("OK to start a "_IOINHI_"new"_IOINORM_" master task now","No") D  QUIT  ;->
 .  W "     no action taken..."
 ;
 D STARTJOB^HLEVMST
 ;
 D TELL("Press RETURN to exit... ","0^0^999")
 ;
 Q
 ;
HD W @IOF,$$CJ^XLFSTR("Master Job Start",IOM)
 W !,$$REPEAT^XLFSTR("=",IOM)
 QUIT
 ;
EX N I,T F I=1:1 S T=$T(EX+I) QUIT:T'[";;"  W !,$P(T,";;",2,99)
 ;;This option will queue a new master job task if no master job is currently
 ;;running and no master job is queued for the future.
 ;;
 ;;Note:  A master job is queued every time the event monitoring software is
 ;;       installed, and every time the system is rebooted.  So, normally it
 ;;       is not necessary to use this option to create a new master job.  
 ;;       (The most common reason for using this option is if the queued
 ;;       master job was 'dequeued'.)
 QUIT
 ;
SEC(HORO) ; Convert $H to seconds...
 QUIT:HORO'?5.N1","1.N "" ;->
 QUIT ((86400*+HORO)+$P(HORO,",",2))
 ;
SECTHORO(SEC) ; Convert seconds to $H...
 N DAYS,SECH
 QUIT:SEC'?1.N "" ;->
 S DAYS=SEC\86400,SECH=SEC#86400
 QUIT DAYS_","_SECH
 ;
TELL(TXTINFO,ACT,TXTBT) ; Print TXTINFO, FF to bottom, and $$BTE(TXTBT)...
 ;
 ; ACT = #1 ^ #2 ^ #3 ^ #4 -> Controls pre-$$BTE positioning...
 ;
 ;       #1 => 0 = Spaces before printing TXTINFO (See #2). 
 ;             1 = Lines before printing TXTINFO (see #2).  [DEFAULT]
 ;       #2 => # = # Spaces (if #1=0) or lines (if #1=1-DEFAULT)
 ;       #3 => # = # lines before printing TXTBT (see #4).
 ;                 (# lines printed will never exceed IOSL unless
 ;                 overridden by #4.  Entering #3=999 just ensures that
 ;                 line feeds will be issued until cursor is at bottom
 ;                 of screen.
 ;       #4 => # = # lines that **must** be printed before TXTBT.
 ;
 ; Examples...
 ;
 ; 0^3^999^5 - Prints 3 spaces, TXTINFO and FFs to bottom.  If the 
 ;             screen was full when TELL was called, only one FF would
 ;             normally be issued (minimum, for spacing purposes).
 ;             However, the '5' ensures that at least 5 LFs are issued.
 ;             Then, TXTBT printed.
 ;
 ; 1^2^2     - Prints 2 LFs, TXTINFO, and 2 LFs, then TXTBT.  (If the
 ;             screen was full when TELL called, only 1 LF would be
 ;             printed before printing TXTBT.)
 ;
 N I,X
 ;
 S ACT=$G(ACT),TXTINFO=$G(TXTINFO)
 S TXTBT=$S($G(TXTBT)]"":TXTBT,1:"Press RETURN to exit... ")
 ;
 ; Default to line feeds...
 S:$P(ACT,U)'=0&($P(ACT,U)'=1) $P(ACT,U)=1
 ;
 ; Default to 1 line feed or 3 spaces...
 S:$P(ACT,U,2)'?1.N $P(ACT,U,2)=$S(+ACT=0:3,1:1)
 ;
 ; Default to bottom of form trailing lines...
 S:$P(ACT,U,3)'?1.N $P(ACT,U,3)=999
 ;
 ; Default to minimum lines after printing TXTINFO...
 S:$P(ACT,U,4)'?1.N $P(ACT,U,4)=1
 ;
 I +ACT=0 X "F I=1:1:$P(ACT,U,2) W "" """ W TXTINFO
 I +ACT=1 X "F I=1:1:$P(ACT,U,2) W !" W TXTINFO
 ;
 S ACT=$P(ACT,U,3,4)
 ;
 ; If positive, always issue at least one line feed...
 I ACT W ! S $P(ACT,U)=$P(ACT,U)-1
 ;
 F I=1:1:ACT Q:($Y+3)>IOSL&(ACT>$P(ACT,U,2))  W !
 ;
 S X=$$BTE^HLCSMON(TXTBT)
 ;
 Q
 ;
EOR ;HLEVMST0 - Event Monitor MASTER JOB ;5/16/03 14:42
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HHLEVMST0   7196     printed  Sep 23, 2025@19:33:52                                                                                                                                                                                                    Page 2
HLEVMST0  ;O-OIFO/LJA - Event Monitor MASTER JOB ;02/04/2004 14:42
 +1       ;;1.6;HEALTH LEVEL SEVEN;**109**;Oct 13, 1995
 +2       ;
UNQUEUE   ; Unqueue master job...
 +1        NEW DIFF,IOINHI,IOINORM,LAST0,LASTDT,LASTIEN,NEXTH,SECNEXT
 +2        NEW SECNOW,TASKNO,ZTDTH,ZTSK
 +3       ;
 +4        SET X="IOINHI;IOINORM"
           DO ENDR^%ZISS
 +5       ;
 +6        DO HDU
 +7        DO EXU
 +8       ;
 +9        WRITE !
 +10      ;
 +11       SET LASTDT=$ORDER(^HLEV(776.2,"B",":"),-1)
 +12       SET LASTIEN=$ORDER(^HLEV(776.2,"B",+LASTDT,":"),-1)
 +13      ;->
           SET LAST0=$GET(^HLEV(776.2,+LASTIEN,0))
           IF $PIECE(LAST0,U,4)'="Q"
               Begin DoDot:1
 +14               DO TELL("The most recently queued master job is no longer active...","1^2^999")
               End DoDot:1
               QUIT 
 +15      ;
 +16       SET LASTSK=$PIECE(LAST0,U,5)
           IF LASTSK>0
               Begin DoDot:1
 +17               WRITE !,"The current master job is task# ",$PIECE(LAST0,U,5),", queued for "
 +18               WRITE $$FMTE^XLFDT(+$PIECE(LAST0,U,6)),"."
               End DoDot:1
 +19      ;
 +20       WRITE !
 +21      ;->
           IF '$$YN^HLCSRPT4("OK to stop master job now","No")
               Begin DoDot:1
 +22               WRITE "     no action taken..."
               End DoDot:1
               QUIT 
 +23      ;
 +24       WRITE "   Master job stopped..."
 +25       WRITE !!,IOINHI,"Important!!",IOINORM,"  You must remember to start a new master job!!"
 +26      ;
 +27       DO UNQ^HLEVUTIL(+LASTIEN,+LASTSK,"Master job stopped by "_$PIECE($GET(^VA(200,+$GET(DUZ),0)),U)_".")
 +28      ;
 +29       DO TELL("","0^0^999")
 +30      ;
 +31       QUIT 
 +32      ;
HDU        WRITE @IOF,$$CJ^XLFSTR("Unqueue Master Job",IOM)
 +1        WRITE !,$$REPEAT^XLFSTR("=",IOM)
 +2        QUIT 
 +3       ;
EXU        NEW I,T
           FOR I=1:1
               SET T=$TEXT(EXU+I)
               if T'[";;"
                   QUIT 
               WRITE !,$PIECE(T,";;",2,99)
 +1       ;;If a master job has been queued to a future time, it can be unqueued now.
 +2       ;;
 +3       ;;Note:  If you unqueue this task, no future master jobs will run until you
 +4       ;;       manually start a new master job.  (Start new master jobs with the 
 +5       ;;       '' menu option.)
 +6        QUIT 
 +7       ;
MSTNOW    ; Start queued master job now!
 +1        NEW DIFF,LAST0,LASTDT,LASTIEN,NEXTH,SECNEXT,SECNOW,TASKNO,ZTDTH,ZTSK
 +2       ;
 +3        WRITE @IOF,$$CJ^XLFSTR("Master Job ""Run Now"" Utility",IOM)
 +4        WRITE !,$$REPEAT^XLFSTR("=",IOM)
 +5        WRITE !
 +6       ;
 +7       ; Last (probably queued) job time
           SET LASTDT=$ORDER(^HLEV(776.2,"B",":"),-1)
 +8        SET LASTIEN=$ORDER(^HLEV(776.2,"B",+LASTDT,":"),-1)
 +9        SET LAST0=$GET(^HLEV(776.2,+LASTIEN,0))
           IF LAST0']""
               Begin DoDot:1
 +10               WRITE !,"Couldn't find last master job entry..."
               End DoDot:1
 +11      ;
 +12       SET TASKNO=$PIECE(LAST0,U,5)
           IF '$DATA(^%ZTSK(+TASKNO))
               Begin DoDot:1
 +13               WRITE !,"Couldn't find task",$SELECT(TASKNO:"# "_TASKNO_"...",1:".")
               End DoDot:1
 +14      ;
 +15       SET TASK0=$GET(^%ZTSK(+TASKNO,0))
           IF TASK0']""
               Begin DoDot:1
 +16               WRITE !,"Couldn't find task# ",TASKNO,"'S zero node..."
               End DoDot:1
 +17      ;
 +18       SET NEXTH=$PIECE(TASK0,U,6)
           IF NEXTH'?1.N1","1.N
               Begin DoDot:1
 +19               WRITE !,"Invalid future queue time ($H)..."
               End DoDot:1
 +20      ;
 +21       SET SECNEXT=$$SEC(NEXTH)
 +22       SET SECNOW=$$SEC($HOROLOG)
 +23      ;
 +24       SET DIFF=SECNEXT-SECNOW
 +25      ;->
           IF DIFF<60
               Begin DoDot:1
 +26      ;->
                   IF DIFF<1
                       WRITE !,"Master job will start any moment!"
                       QUIT 
 +27               WRITE !,"Master job will start on its own in ",DIFF," seconds..."
               End DoDot:1
               QUIT 
 +28      ;
 +29       IF '$DATA(^%ZTSCH(SECNEXT,TASKNO))
               Begin DoDot:1
 +30               WRITE !,"Couldn't find ^%ZTSK(SEC,ZTSK) node..."
               End DoDot:1
 +31      ;
 +32       WRITE !,"This utility allows you to run the master job ahead of it's currently"
 +33       WRITE !,"scheduled time to run."
 +34      ;
 +35       WRITE !!,"Master task# ",TASKNO," is queued to "
 +36       WRITE $$SDT^HLEVX001($$HTFM^XLFDT(NEXTH))
 +37       WRITE " and it will be started now..."
 +38      ;
 +39       WRITE !
 +40      ;->
           IF '$$YN^HLCSRPT4("OK to start now","No")
               Begin DoDot:1
 +41               WRITE "     no action taken..."
               End DoDot:1
               QUIT 
 +42      ;
 +43       SET ZTSK=TASKNO
           SET ZTDTH=$HOROLOG
 +44       DO REQ^%ZTLOAD
 +45      ;
 +46       WRITE !!,"Master job requeued to 'now'..."
 +47      ;
 +48       QUIT 
 +49      ;
STARTMST  ; Start brand new master job now (interactively)!
 +1        NEW DIFF,IOINHI,IOINORM,LAST0,LASTDT,LASTIEN,NEXTH,SECNEXT
 +2        NEW SECNOW,TASKNO,ZTDTH,ZTSK
 +3       ;
 +4        SET LASTDT=$ORDER(^HLEV(776.2,"B",":"),-1)
 +5        SET LASTIEN=$ORDER(^HLEV(776.2,"B",+LASTDT,":"),-1)
 +6        SET LAST0=$GET(^HLEV(776.2,+LASTIEN,0))
 +7        SET TASKNO=$PIECE(LAST0,U,5)
 +8       ;
 +9       ; If this option is accessed by queued background job, just unqueue
 +10      ; everything to make sure, and start a new master job for NOW...
 +11      ;->
           IF $DATA(ZTQUEUED)
               Begin DoDot:1
 +12               DO UNQ^HLEVUTIL(+LASTIEN,+TASKNO,"Reboot unqueue/requeue master job.")
 +13               DO STARTJOB^HLEVMST
               End DoDot:1
               QUIT 
 +14      ;
 +15       SET X="IOINHI;IOINORM"
           DO ENDR^%ZISS
 +16      ;
 +17       DO HD
 +18       DO EX
 +19      ;
 +20       WRITE !
 +21      ;
 +22      ;->
           IF $PIECE(LAST0,U,4)="Q"
               Begin DoDot:1
 +23               DO TELL("It appears as if task# "_$PIECE(LAST0,U,5)_" has already been queued.","1^2^999")
               End DoDot:1
               QUIT 
 +24      ;
 +25       IF $PIECE(LAST0,U,5)>0
               Begin DoDot:1
 +26               WRITE !!,"The ",IOINHI,"last",IOINORM
 +27               WRITE " master job was task# ",$PIECE(LAST0,U,5),", queued "
 +28               WRITE $$FMTE^XLFDT(+LAST0),"."
               End DoDot:1
 +29      ;
 +30       WRITE !
 +31      ;->
           IF '$$YN^HLCSRPT4("OK to start a "_IOINHI_"new"_IOINORM_" master task now","No")
               Begin DoDot:1
 +32               WRITE "     no action taken..."
               End DoDot:1
               QUIT 
 +33      ;
 +34       DO STARTJOB^HLEVMST
 +35      ;
 +36       DO TELL("Press RETURN to exit... ","0^0^999")
 +37      ;
 +38       QUIT 
 +39      ;
HD         WRITE @IOF,$$CJ^XLFSTR("Master Job Start",IOM)
 +1        WRITE !,$$REPEAT^XLFSTR("=",IOM)
 +2        QUIT 
 +3       ;
EX         NEW I,T
           FOR I=1:1
               SET T=$TEXT(EX+I)
               if T'[";;"
                   QUIT 
               WRITE !,$PIECE(T,";;",2,99)
 +1       ;;This option will queue a new master job task if no master job is currently
 +2       ;;running and no master job is queued for the future.
 +3       ;;
 +4       ;;Note:  A master job is queued every time the event monitoring software is
 +5       ;;       installed, and every time the system is rebooted.  So, normally it
 +6       ;;       is not necessary to use this option to create a new master job.  
 +7       ;;       (The most common reason for using this option is if the queued
 +8       ;;       master job was 'dequeued'.)
 +9        QUIT 
 +10      ;
SEC(HORO) ; Convert $H to seconds...
 +1       ;->
           if HORO'?5.N1","1.N
               QUIT ""
 +2        QUIT ((86400*+HORO)+$PIECE(HORO,",",2))
 +3       ;
SECTHORO(SEC) ; Convert seconds to $H...
 +1        NEW DAYS,SECH
 +2       ;->
           if SEC'?1.N
               QUIT ""
 +3        SET DAYS=SEC\86400
           SET SECH=SEC#86400
 +4        QUIT DAYS_","_SECH
 +5       ;
TELL(TXTINFO,ACT,TXTBT) ; Print TXTINFO, FF to bottom, and $$BTE(TXTBT)...
 +1       ;
 +2       ; ACT = #1 ^ #2 ^ #3 ^ #4 -> Controls pre-$$BTE positioning...
 +3       ;
 +4       ;       #1 => 0 = Spaces before printing TXTINFO (See #2). 
 +5       ;             1 = Lines before printing TXTINFO (see #2).  [DEFAULT]
 +6       ;       #2 => # = # Spaces (if #1=0) or lines (if #1=1-DEFAULT)
 +7       ;       #3 => # = # lines before printing TXTBT (see #4).
 +8       ;                 (# lines printed will never exceed IOSL unless
 +9       ;                 overridden by #4.  Entering #3=999 just ensures that
 +10      ;                 line feeds will be issued until cursor is at bottom
 +11      ;                 of screen.
 +12      ;       #4 => # = # lines that **must** be printed before TXTBT.
 +13      ;
 +14      ; Examples...
 +15      ;
 +16      ; 0^3^999^5 - Prints 3 spaces, TXTINFO and FFs to bottom.  If the 
 +17      ;             screen was full when TELL was called, only one FF would
 +18      ;             normally be issued (minimum, for spacing purposes).
 +19      ;             However, the '5' ensures that at least 5 LFs are issued.
 +20      ;             Then, TXTBT printed.
 +21      ;
 +22      ; 1^2^2     - Prints 2 LFs, TXTINFO, and 2 LFs, then TXTBT.  (If the
 +23      ;             screen was full when TELL called, only 1 LF would be
 +24      ;             printed before printing TXTBT.)
 +25      ;
 +26       NEW I,X
 +27      ;
 +28       SET ACT=$GET(ACT)
           SET TXTINFO=$GET(TXTINFO)
 +29       SET TXTBT=$SELECT($GET(TXTBT)]"":TXTBT,1:"Press RETURN to exit... ")
 +30      ;
 +31      ; Default to line feeds...
 +32       if $PIECE(ACT,U)'=0&($PIECE(ACT,U)'=1)
               SET $PIECE(ACT,U)=1
 +33      ;
 +34      ; Default to 1 line feed or 3 spaces...
 +35       if $PIECE(ACT,U,2)'?1.N
               SET $PIECE(ACT,U,2)=$SELECT(+ACT=0:3,1:1)
 +36      ;
 +37      ; Default to bottom of form trailing lines...
 +38       if $PIECE(ACT,U,3)'?1.N
               SET $PIECE(ACT,U,3)=999
 +39      ;
 +40      ; Default to minimum lines after printing TXTINFO...
 +41       if $PIECE(ACT,U,4)'?1.N
               SET $PIECE(ACT,U,4)=1
 +42      ;
 +43       IF +ACT=0
               XECUTE "F I=1:1:$P(ACT,U,2) W "" """
               WRITE TXTINFO
 +44       IF +ACT=1
               XECUTE "F I=1:1:$P(ACT,U,2) W !"
               WRITE TXTINFO
 +45      ;
 +46       SET ACT=$PIECE(ACT,U,3,4)
 +47      ;
 +48      ; If positive, always issue at least one line feed...
 +49       IF ACT
               WRITE !
               SET $PIECE(ACT,U)=$PIECE(ACT,U)-1
 +50      ;
 +51       FOR I=1:1:ACT
               if ($Y+3)>IOSL&(ACT>$PIECE(ACT,U,2))
                   QUIT 
               WRITE !
 +52      ;
 +53       SET X=$$BTE^HLCSMON(TXTBT)
 +54      ;
 +55       QUIT 
 +56      ;
EOR       ;HLEVMST0 - Event Monitor MASTER JOB ;5/16/03 14:42