HLCSFMN1 ;ALB/JRP - UTILITIES FOR FILER MONITOR;18-MAY-95
 ;;1.6;HEALTH LEVEL SEVEN;;Oct 13, 1995
GETINFO(FLRTYPE,OUTARR) ;Get filer information
 ;INPUT  : FLRTYPE - Flag indicating type of filer to get info on
 ;                   IN = Incoming filer (default)
 ;                   OUT = Outgoing filer
 ;         OUTARR - Array to put filer information into (full global ref)
 ;OUTPUT : X - Number of outgoing filers running
 ;         OUTARR(PtrSubEntry) = TaskNumber ^ Last$H ^ StopFlag ^
 ;                               Printable$H ^ ErrorMessage
 ;           PtrSubEntry = Pointer to subentry in file 869.3
 ;           TaskNumber = Task number of filer
 ;           Last$H = Last known $H (field #.03 of subentry)
 ;           StopFlag = Whether or not filer has been asked to stop
 ;                      (field #.02 of subentry)
 ;                      Yes - Filer has been asked to stop
 ;                      No - Filer has not been asked to stop
 ;                      Error - Task stopped due to error
 ;           Printable$H = Last$H in printable format
 ;           ErrorMessage = Printable error message - only used when
 ;                          task stopped due to error
 ;NOTES  : OUTARR() will be initialized (KILLed) on entry
 ;
 ;Check input
 Q:($G(OUTARR)="") 0
 S FLRTYPE=$G(FLRTYPE)
 S:(FLRTYPE'="OUT") FLRTYPE="IN"
 ;Declare variables
 N PTRSUB,FLRINFO,FLRDH,PRTDH,STOPFLAG,COUNT,ZTSK,TMP
 ;Get filer data
 K @OUTARR
 D GETFLRS^HLCSUTL2(FLRTYPE,OUTARR)
 ;Count number of filers
 S PTRSUB=""
 F COUNT=0:1 S PTRSUB=+$O(@OUTARR@(PTRSUB)) Q:('PTRSUB)  D
 .;Convert data
 .S FLRINFO=@OUTARR@(PTRSUB)
 .;Convert stop flag to printable format
 .S STOPFLAG=+$P(FLRINFO,"^",3)
 .S $P(FLRINFO,"^",3)=$S(STOPFLAG:"Yes",1:"No")
 .;Convert $H to printable format
 .S FLRDH=$P(FLRINFO,"^",2)
 .S PRTDH=""
 .S:(FLRDH'="") PRTDH=$$DH4PRT(FLRDH)
 .S $P(FLRINFO,"^",4)=PRTDH
 .;Get task's status
 .K ZTSK
 .S ZTSK=+FLRINFO
 .D STAT^%ZTLOAD
 .;Problem with task
 .I (ZTSK(1)'=2) D
 ..;Determine error message
 ..S TMP=$S(FLRTYPE="OUT":"Outgoing ",1:"Incoming ")
 ..;Task no longer defined
 ..S:(ZTSK(1)=0) TMP="** "_TMP_"filer is no longer defined **"
 ..;Task hasn't started yet
 ..S:(ZTSK(1)=1) TMP=TMP_"filer has not started yet"
 ..;Task finished
 ..S:(ZTSK(1)=3) TMP=TMP_"filer stopped but didn't delete itself"
 ..;Task not scheduled
 ..S:(ZTSK(1)=4) TMP="** "_TMP_"filer has not been [re]scheduled **"
 ..;Task errored out
 ..S:(ZTSK(1)=5) TMP="** "_TMP_"filer has stopped due to error **"
 ..;Store error message
 ..S $P(FLRINFO,"^",5)=TMP
 ..;Use 'Error' for stop flag - don't change if filer hasn't started yet
 ..S:(ZTSK(1)'=1) $P(FLRINFO,"^",3)="Error"
 .;Store converted data
 .S @OUTARR@(PTRSUB)=FLRINFO
 ;Return info
 Q COUNT
DIFFDH(DH1,DH2) ;DETERMINE DIFFERENCES BETWEEN TWO VALUES OF $H
 ;INPUT  : DH1 - Beginning $H (defaults to current $H)
 ;         DH2 - Ending $H (defaults to current $H)
 ;OUTPUT : Days ^ Time
 ;           Days = Number of days between DH1 & DH2
 ;           Time = Rest of time between DH1 & DH2 => HH:MM:SS
 ;NOTES  : Difference calculated by subtracting DH1 from DH2
 ;
 ;Check input
 S DH1=$G(DH1)
 S:(DH1="") DH1=$H
 S DH2=$G(DH2)
 S:(DH2="") DH2=$H
 ;Declare variables
 N DAY1,DAY2,DAYDIF,TIME1,TIME2,TIMEDIF,NEGATE,%
 ;Break out day & seconds from $H
 S DAY1=+$P(DH1,",",1)
 S DAY2=+$P(DH2,",",1)
 S TIME1=+$P(DH1,",",2)
 S TIME2=+$P(DH2,",",2)
 ;Make sure DH2 is after DH1
 S NEGATE=0
 I ((DAY1>DAY2)!((DAY1=DAY2)&(TIME1>TIME2))) D
 .;Switch date/time
 .S NEGATE=DAY2
 .S DAY2=DAY1
 .S DAY1=NEGATE
 .S NEGATE=TIME2
 .S TIME2=TIME1
 .S TIME1=NEGATE
 .;Negate answer when done
 .S NEGATE=1
 ;Determine day difference
 S DAYDIF=DAY2-DAY1
 ;Determine time difference
 ;Same day - just subtract time
 S:('DAYDIF) TIMEDIF=TIME2-TIME1
 ;Different day - special case exists
 I (DAYDIF) D
 .;Seconds not different by 24 hours
 .I (TIME2<TIME1) D  Q
 ..;Convert one day from difference to seconds
 ..S DAYDIF=DAYDIF-1
 ..;Add to ending time
 ..S TIME2=TIME2+86400
 ..;Subtract times
 ..S TIMEDIF=TIME2-TIME1
 .;Seconds different by 24 hours
 .S TIMEDIF=TIME2-TIME1
 ;Convert seconds to time
 S %=TIMEDIF
 D S^%DTC
 S %=%_"000000"
 S TIMEDIF=$E(%,2,3)_":"_$E(%,4,5)_":"_$E(%,6,7)
 ;Negate results (if needed)
 I (NEGATE) D
 .S DAYDIF=0-DAYDIF
 .;Don't negate 00:00:00
 .F %=1:1:4 Q:($P(TIMEDIF,":",%))
 .S:(%'=4) TIMEDIF="-"_TIMEDIF
 Q DAYDIF_"^"_TIMEDIF
DH4PRT(DH) ;CONVERT $H TO PRINTABLE FORMAT
 ;INPUT  : DH - $H (defaults to current $H)
 ;OUTPUT : Printable format of $H => DD-MMM-YY @ HH:MM:SS
 ;
 ;Check input
 S DH=$G(DH)
 S:(DH="") DH=$H
 ;Declare variables
 N %H,Y,X,%,CNVDATE,CNVTIME
 ;Convert $H to external format
 S %H=DH
 D YX^%DTC
 ;Convert to print format
 S CNVDATE=$P(Y,"@",1)
 S %=%_"000000"
 S CNVTIME=$E(%,2,3)_":"_$E(%,4,5)_":"_$E(%,6,7)
 S Y=$E(X,6,7)_"-"_$P(CNVDATE," ",1)_"-"_$E(X,2,3)_" @ "_CNVTIME
 Q Y
GETATTR ;GET SCREEN ATTRIBUTES USED BY MONITOR
 ;INPUT  : IOST(0) - Terminal type [as set by entry into DHCP]
 ;OUTPUT : The following screen attributes will be defined
 ;           IOINORM - Normal intensity
 ;           IOINHI  - High Intensity (bold)
 ;           IOUON   - Underline on
 ;           IOUOFF  - Underline off
 ;           IOBON   - Blink on
 ;           IOBOFF  - Blink off
 ;           IORVON  - Reverse video on
 ;           IORVOFF - Reverse video off
 ;           IOHOME - Move cursor to home
 ;           IOELEOL - Erase from cursor to end of line
 ;
 ;NOTES  : If IOST(0) is not defined, a call to HOME^%ZIS will be made
 ;
 ;Check for IOST(0)
 D:('$D(IOST(0))) HOME^%ZIS
 ;Declare variables
 N X
 ;Get screen attributes
 S X="IOINORM;IOINHI;IOUON;IOUOFF;IOBON;IOBOFF;IORVON;IORVOFF;IOHOME;IOELEOL"
 D ENDR^%ZISS
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HHLCSFMN1   5897     printed  Sep 23, 2025@19:32:35                                                                                                                                                                                                    Page 2
HLCSFMN1  ;ALB/JRP - UTILITIES FOR FILER MONITOR;18-MAY-95
 +1       ;;1.6;HEALTH LEVEL SEVEN;;Oct 13, 1995
GETINFO(FLRTYPE,OUTARR) ;Get filer information
 +1       ;INPUT  : FLRTYPE - Flag indicating type of filer to get info on
 +2       ;                   IN = Incoming filer (default)
 +3       ;                   OUT = Outgoing filer
 +4       ;         OUTARR - Array to put filer information into (full global ref)
 +5       ;OUTPUT : X - Number of outgoing filers running
 +6       ;         OUTARR(PtrSubEntry) = TaskNumber ^ Last$H ^ StopFlag ^
 +7       ;                               Printable$H ^ ErrorMessage
 +8       ;           PtrSubEntry = Pointer to subentry in file 869.3
 +9       ;           TaskNumber = Task number of filer
 +10      ;           Last$H = Last known $H (field #.03 of subentry)
 +11      ;           StopFlag = Whether or not filer has been asked to stop
 +12      ;                      (field #.02 of subentry)
 +13      ;                      Yes - Filer has been asked to stop
 +14      ;                      No - Filer has not been asked to stop
 +15      ;                      Error - Task stopped due to error
 +16      ;           Printable$H = Last$H in printable format
 +17      ;           ErrorMessage = Printable error message - only used when
 +18      ;                          task stopped due to error
 +19      ;NOTES  : OUTARR() will be initialized (KILLed) on entry
 +20      ;
 +21      ;Check input
 +22       if ($GET(OUTARR)="")
               QUIT 0
 +23       SET FLRTYPE=$GET(FLRTYPE)
 +24       if (FLRTYPE'="OUT")
               SET FLRTYPE="IN"
 +25      ;Declare variables
 +26       NEW PTRSUB,FLRINFO,FLRDH,PRTDH,STOPFLAG,COUNT,ZTSK,TMP
 +27      ;Get filer data
 +28       KILL @OUTARR
 +29       DO GETFLRS^HLCSUTL2(FLRTYPE,OUTARR)
 +30      ;Count number of filers
 +31       SET PTRSUB=""
 +32       FOR COUNT=0:1
               SET PTRSUB=+$ORDER(@OUTARR@(PTRSUB))
               if ('PTRSUB)
                   QUIT 
               Begin DoDot:1
 +33      ;Convert data
 +34               SET FLRINFO=@OUTARR@(PTRSUB)
 +35      ;Convert stop flag to printable format
 +36               SET STOPFLAG=+$PIECE(FLRINFO,"^",3)
 +37               SET $PIECE(FLRINFO,"^",3)=$SELECT(STOPFLAG:"Yes",1:"No")
 +38      ;Convert $H to printable format
 +39               SET FLRDH=$PIECE(FLRINFO,"^",2)
 +40               SET PRTDH=""
 +41               if (FLRDH'="")
                       SET PRTDH=$$DH4PRT(FLRDH)
 +42               SET $PIECE(FLRINFO,"^",4)=PRTDH
 +43      ;Get task's status
 +44               KILL ZTSK
 +45               SET ZTSK=+FLRINFO
 +46               DO STAT^%ZTLOAD
 +47      ;Problem with task
 +48               IF (ZTSK(1)'=2)
                       Begin DoDot:2
 +49      ;Determine error message
 +50                       SET TMP=$SELECT(FLRTYPE="OUT":"Outgoing ",1:"Incoming ")
 +51      ;Task no longer defined
 +52                       if (ZTSK(1)=0)
                               SET TMP="** "_TMP_"filer is no longer defined **"
 +53      ;Task hasn't started yet
 +54                       if (ZTSK(1)=1)
                               SET TMP=TMP_"filer has not started yet"
 +55      ;Task finished
 +56                       if (ZTSK(1)=3)
                               SET TMP=TMP_"filer stopped but didn't delete itself"
 +57      ;Task not scheduled
 +58                       if (ZTSK(1)=4)
                               SET TMP="** "_TMP_"filer has not been [re]scheduled **"
 +59      ;Task errored out
 +60                       if (ZTSK(1)=5)
                               SET TMP="** "_TMP_"filer has stopped due to error **"
 +61      ;Store error message
 +62                       SET $PIECE(FLRINFO,"^",5)=TMP
 +63      ;Use 'Error' for stop flag - don't change if filer hasn't started yet
 +64                       if (ZTSK(1)'=1)
                               SET $PIECE(FLRINFO,"^",3)="Error"
                       End DoDot:2
 +65      ;Store converted data
 +66               SET @OUTARR@(PTRSUB)=FLRINFO
               End DoDot:1
 +67      ;Return info
 +68       QUIT COUNT
DIFFDH(DH1,DH2) ;DETERMINE DIFFERENCES BETWEEN TWO VALUES OF $H
 +1       ;INPUT  : DH1 - Beginning $H (defaults to current $H)
 +2       ;         DH2 - Ending $H (defaults to current $H)
 +3       ;OUTPUT : Days ^ Time
 +4       ;           Days = Number of days between DH1 & DH2
 +5       ;           Time = Rest of time between DH1 & DH2 => HH:MM:SS
 +6       ;NOTES  : Difference calculated by subtracting DH1 from DH2
 +7       ;
 +8       ;Check input
 +9        SET DH1=$GET(DH1)
 +10       if (DH1="")
               SET DH1=$HOROLOG
 +11       SET DH2=$GET(DH2)
 +12       if (DH2="")
               SET DH2=$HOROLOG
 +13      ;Declare variables
 +14       NEW DAY1,DAY2,DAYDIF,TIME1,TIME2,TIMEDIF,NEGATE,%
 +15      ;Break out day & seconds from $H
 +16       SET DAY1=+$PIECE(DH1,",",1)
 +17       SET DAY2=+$PIECE(DH2,",",1)
 +18       SET TIME1=+$PIECE(DH1,",",2)
 +19       SET TIME2=+$PIECE(DH2,",",2)
 +20      ;Make sure DH2 is after DH1
 +21       SET NEGATE=0
 +22       IF ((DAY1>DAY2)!((DAY1=DAY2)&(TIME1>TIME2)))
               Begin DoDot:1
 +23      ;Switch date/time
 +24               SET NEGATE=DAY2
 +25               SET DAY2=DAY1
 +26               SET DAY1=NEGATE
 +27               SET NEGATE=TIME2
 +28               SET TIME2=TIME1
 +29               SET TIME1=NEGATE
 +30      ;Negate answer when done
 +31               SET NEGATE=1
               End DoDot:1
 +32      ;Determine day difference
 +33       SET DAYDIF=DAY2-DAY1
 +34      ;Determine time difference
 +35      ;Same day - just subtract time
 +36       if ('DAYDIF)
               SET TIMEDIF=TIME2-TIME1
 +37      ;Different day - special case exists
 +38       IF (DAYDIF)
               Begin DoDot:1
 +39      ;Seconds not different by 24 hours
 +40               IF (TIME2<TIME1)
                       Begin DoDot:2
 +41      ;Convert one day from difference to seconds
 +42                       SET DAYDIF=DAYDIF-1
 +43      ;Add to ending time
 +44                       SET TIME2=TIME2+86400
 +45      ;Subtract times
 +46                       SET TIMEDIF=TIME2-TIME1
                       End DoDot:2
                       QUIT 
 +47      ;Seconds different by 24 hours
 +48               SET TIMEDIF=TIME2-TIME1
               End DoDot:1
 +49      ;Convert seconds to time
 +50       SET %=TIMEDIF
 +51       DO S^%DTC
 +52       SET %=%_"000000"
 +53       SET TIMEDIF=$EXTRACT(%,2,3)_":"_$EXTRACT(%,4,5)_":"_$EXTRACT(%,6,7)
 +54      ;Negate results (if needed)
 +55       IF (NEGATE)
               Begin DoDot:1
 +56               SET DAYDIF=0-DAYDIF
 +57      ;Don't negate 00:00:00
 +58               FOR %=1:1:4
                       if ($PIECE(TIMEDIF,"
                           QUIT 
 +59               if (%'=4)
                       SET TIMEDIF="-"_TIMEDIF
               End DoDot:1
 +60       QUIT DAYDIF_"^"_TIMEDIF
DH4PRT(DH) ;CONVERT $H TO PRINTABLE FORMAT
 +1       ;INPUT  : DH - $H (defaults to current $H)
 +2       ;OUTPUT : Printable format of $H => DD-MMM-YY @ HH:MM:SS
 +3       ;
 +4       ;Check input
 +5        SET DH=$GET(DH)
 +6        if (DH="")
               SET DH=$HOROLOG
 +7       ;Declare variables
 +8        NEW %H,Y,X,%,CNVDATE,CNVTIME
 +9       ;Convert $H to external format
 +10       SET %H=DH
 +11       DO YX^%DTC
 +12      ;Convert to print format
 +13       SET CNVDATE=$PIECE(Y,"@",1)
 +14       SET %=%_"000000"
 +15       SET CNVTIME=$EXTRACT(%,2,3)_":"_$EXTRACT(%,4,5)_":"_$EXTRACT(%,6,7)
 +16       SET Y=$EXTRACT(X,6,7)_"-"_$PIECE(CNVDATE," ",1)_"-"_$EXTRACT(X,2,3)_" @ "_CNVTIME
 +17       QUIT Y
GETATTR   ;GET SCREEN ATTRIBUTES USED BY MONITOR
 +1       ;INPUT  : IOST(0) - Terminal type [as set by entry into DHCP]
 +2       ;OUTPUT : The following screen attributes will be defined
 +3       ;           IOINORM - Normal intensity
 +4       ;           IOINHI  - High Intensity (bold)
 +5       ;           IOUON   - Underline on
 +6       ;           IOUOFF  - Underline off
 +7       ;           IOBON   - Blink on
 +8       ;           IOBOFF  - Blink off
 +9       ;           IORVON  - Reverse video on
 +10      ;           IORVOFF - Reverse video off
 +11      ;           IOHOME - Move cursor to home
 +12      ;           IOELEOL - Erase from cursor to end of line
 +13      ;
 +14      ;NOTES  : If IOST(0) is not defined, a call to HOME^%ZIS will be made
 +15      ;
 +16      ;Check for IOST(0)
 +17       if ('$DATA(IOST(0)))
               DO HOME^%ZIS
 +18      ;Declare variables
 +19       NEW X
 +20      ;Get screen attributes
 +21       SET X="IOINORM;IOINHI;IOUON;IOUOFF;IOBON;IOBOFF;IORVON;IORVOFF;IOHOME;IOELEOL"
 +22       DO ENDR^%ZISS
 +23       QUIT