%ZTLOAD3 ;SEA/RDS - TaskMan: Task Requeue ;07/29/08 11:46
;;8.0;KERNEL;**67,127,136,192,446**;JUL 10, 1995;Build 35
;
INPUT ;check for error conditions
N %H,%T,X,X1,Y,ZT,ZT1,ZT2,ZT3,ZTH,ZTL,ZTOS,ZTREC,ZTREC1,ZTREC2,ZTREC25
S ZTSK=$G(ZTSK) K ZTSK(0),ZTREQ ;Kill ZTREQ so we don't kill the entry
L +^%ZTSK(ZTSK):9 S ZTREC=$G(^%ZTSK(ZTSK,0)) I ZTREC="" G BAD
I $D(ZTDTH)#2,ZTDTH]"",ZTDTH'?1.5N1","1.5N,ZTDTH'?7N.".".N,ZTDTH'="@","SHD"'[$E(ZTDTH,$L(ZTDTH)) G BAD
;
DQ ;make sure task is not pending
D UNSCH^%ZTLOAD6
I $D(^%ZTSK(ZTSK,0))[0 G BAD
;
ZTDTH ;determine task's next start time
S:$P(ZTREC,"^",16)="" $P(ZTREC,"^",16)=$P(ZTREC,"^",5) ;Save original create time
S $P(ZTREC,"^",5)=$H ;Set a new create time
I $D(ZTDTH)[0 S ZTDTH=$P(ZTREC,"^",6) G ZTRTN ;Use original time.
I ZTDTH="" S ZTDTH=$H G ZTRTN
I ZTDTH?1.5N1","1.5N G ZTRTN
I ZTDTH?7N.".".N S ZTDTH=$$FMTH^%ZTLOAD7(ZTDTH) G ZTRTN
I ZTDTH="@" G ZTRTN
S ZTH=$$H3^%ZTM($P(ZTREC,"^",6)),ZTL=$E(ZTDTH,$L(ZTDTH)) ;From start time
DT I ZTL="S" S ZTH=ZTH+ZTDTH
I ZTL="H" S ZTH=(ZTDTH*3600)+ZTH
I ZTL="D" S ZTH=(ZTDTH*86400)+ZTH
DTX I ZTH<$$H3^%ZTM($H) G DT
S ZTDTH=$$H0^%ZTM(ZTH)
;
ZTRTN ;determine whether entry point should change
I $D(ZTRTN)[0 G ZTIO
I ZTRTN="" G ZTIO
I ZTRTN'[U S ZTRTN=U_ZTRTN
S ZT=$P(ZTREC,U,1,2)
I ZT'=ZTRTN S $P(ZTREC,U,1,2)=ZTRTN I ZT="ZTSK^XQ1" S $P(ZTREC,U,7,9)="R^^"
;
ZTIO ;determine whether i/o device should change
N ZTREC2,ZTREC25
S ZTREC2=$G(^%ZTSK(ZTSK,.2)),ZT=$P(ZTREC2,U)
I $D(ZTIO)[0 G ZTIO1
I ZTIO="" G ZTIO1
I $P(ZTIO,";")'=$P(ZT,";") S $P(ZTREC2,U,6)="",ZTREC25=""
I ZTIO="@" S $P(ZTREC2,U)="" G ZTIO1
I ZTIO'=ZT S $P(ZTREC2,U)=ZTIO
;
ZTIO1 ;set hunt group suppression flag
S $P(ZTREC2,U,5)=$S($D(ZTIO(1))[0:"",ZTIO(1)="D":"DIRECT",1:"")
;
ZTDESC ;determine whether description should change
I $S($D(ZTDESC)[0:1,ZTDESC="":1,1:0) S ZTDESC=$G(^%ZTSK(ZTSK,.03))
I ZTDESC=""!(ZTDESC="No Description (%ZTLOAD)") S ZTDESC="No Description (REQ~%ZTLOAD)"
S ^%ZTSK(ZTSK,.03)=ZTDESC
;
RECORD ;record changes in Task File entry
I $D(ZTREC2)#2 S ^%ZTSK(ZTSK,.2)=ZTREC2
I $D(ZTREC25)#2 S ^%ZTSK(ZTSK,.25)=ZTREC25
I ZTDTH'="@" S $P(ZTREC,U,6)=ZTDTH ;Reset the Scheduled time piece
S ^%ZTSK(ZTSK,0)=ZTREC
S $P(^%ZTSK(ZTSK,.1),U,1,3)=$S(ZTDTH'="@":"1^"_$H_"^REQUEUED",1:"H^"_$H_"^EDITED BUT NOT REQUEUED")
;
ZTSAVE ;See if new data to save
K %H,%T,X,X1,Y,ZT,ZT1,ZT2,ZT3,ZTH,ZTL,ZTOS,ZTREC,ZTREC1,ZTREC2,ZTREC25
K ZTDESC,ZTIO,ZTRTN
I $D(ZTSAVE) K:$G(ZTSAVE)="KILL" ^%ZTSK(ZTSK,.3) D ZTSAVE^%ZTLOAD1
SCHED ;schedule task, cleanup, quit
I ZTDTH'="@" L +^%ZTSCH("SCHQ"):6 S ZT=$$H3^%ZTLOAD1(ZTDTH),^%ZTSK(ZTSK,.04)=ZT,^%ZTSCH(ZT,ZTSK)="" L -^%ZTSCH("SCHQ")
K %X,%Y,X,X1,Y,ZT1,ZT2,ZT3,ZTDTH,ZTSAVE
L -^%ZTSK(ZTSK) S ZTSK(0)=1
Q
;
BAD L -^%ZTSK(ZTSK) S ZTSK(0)=0
Q
REQP(ZT1) ;Reschedule a persistent task. Called from ZTM
N ZTSK,ZT2,ZT3,ZTDTH,ZTSAVE S ZTDTH=$H,ZTSK=ZT1
L +^%ZTSK(ZTSK):20 Q:'$T
I $D(^%ZTSK(ZTSK,0))[0 Q ;Should tell someone
G SCHED
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HZTLOAD3 3059 printed Nov 22, 2024@17:26:08 Page 2
%ZTLOAD3 ;SEA/RDS - TaskMan: Task Requeue ;07/29/08 11:46
+1 ;;8.0;KERNEL;**67,127,136,192,446**;JUL 10, 1995;Build 35
+2 ;
INPUT ;check for error conditions
+1 NEW %H,%T,X,X1,Y,ZT,ZT1,ZT2,ZT3,ZTH,ZTL,ZTOS,ZTREC,ZTREC1,ZTREC2,ZTREC25
+2 ;Kill ZTREQ so we don't kill the entry
SET ZTSK=$GET(ZTSK)
KILL ZTSK(0),ZTREQ
+3 LOCK +^%ZTSK(ZTSK):9
SET ZTREC=$GET(^%ZTSK(ZTSK,0))
IF ZTREC=""
GOTO BAD
+4 IF $DATA(ZTDTH)#2
IF ZTDTH]""
IF ZTDTH'?1.5N1","1.5N
IF ZTDTH'?7N.".".N
IF ZTDTH'="@"
IF "SHD"'[$EXTRACT(ZTDTH,$LENGTH(ZTDTH))
GOTO BAD
+5 ;
DQ ;make sure task is not pending
+1 DO UNSCH^%ZTLOAD6
+2 IF $DATA(^%ZTSK(ZTSK,0))[0
GOTO BAD
+3 ;
ZTDTH ;determine task's next start time
+1 ;Save original create time
if $PIECE(ZTREC,"^",16)=""
SET $PIECE(ZTREC,"^",16)=$PIECE(ZTREC,"^",5)
+2 ;Set a new create time
SET $PIECE(ZTREC,"^",5)=$HOROLOG
+3 ;Use original time.
IF $DATA(ZTDTH)[0
SET ZTDTH=$PIECE(ZTREC,"^",6)
GOTO ZTRTN
+4 IF ZTDTH=""
SET ZTDTH=$HOROLOG
GOTO ZTRTN
+5 IF ZTDTH?1.5N1","1.5N
GOTO ZTRTN
+6 IF ZTDTH?7N.".".N
SET ZTDTH=$$FMTH^%ZTLOAD7(ZTDTH)
GOTO ZTRTN
+7 IF ZTDTH="@"
GOTO ZTRTN
+8 ;From start time
SET ZTH=$$H3^%ZTM($PIECE(ZTREC,"^",6))
SET ZTL=$EXTRACT(ZTDTH,$LENGTH(ZTDTH))
DT IF ZTL="S"
SET ZTH=ZTH+ZTDTH
+1 IF ZTL="H"
SET ZTH=(ZTDTH*3600)+ZTH
+2 IF ZTL="D"
SET ZTH=(ZTDTH*86400)+ZTH
DTX IF ZTH<$$H3^%ZTM($HOROLOG)
GOTO DT
+1 SET ZTDTH=$$H0^%ZTM(ZTH)
+2 ;
ZTRTN ;determine whether entry point should change
+1 IF $DATA(ZTRTN)[0
GOTO ZTIO
+2 IF ZTRTN=""
GOTO ZTIO
+3 IF ZTRTN'[U
SET ZTRTN=U_ZTRTN
+4 SET ZT=$PIECE(ZTREC,U,1,2)
+5 IF ZT'=ZTRTN
SET $PIECE(ZTREC,U,1,2)=ZTRTN
IF ZT="ZTSK^XQ1"
SET $PIECE(ZTREC,U,7,9)="R^^"
+6 ;
ZTIO ;determine whether i/o device should change
+1 NEW ZTREC2,ZTREC25
+2 SET ZTREC2=$GET(^%ZTSK(ZTSK,.2))
SET ZT=$PIECE(ZTREC2,U)
+3 IF $DATA(ZTIO)[0
GOTO ZTIO1
+4 IF ZTIO=""
GOTO ZTIO1
+5 IF $PIECE(ZTIO,";")'=$PIECE(ZT,";")
SET $PIECE(ZTREC2,U,6)=""
SET ZTREC25=""
+6 IF ZTIO="@"
SET $PIECE(ZTREC2,U)=""
GOTO ZTIO1
+7 IF ZTIO'=ZT
SET $PIECE(ZTREC2,U)=ZTIO
+8 ;
ZTIO1 ;set hunt group suppression flag
+1 SET $PIECE(ZTREC2,U,5)=$SELECT($DATA(ZTIO(1))[0:"",ZTIO(1)="D":"DIRECT",1:"")
+2 ;
ZTDESC ;determine whether description should change
+1 IF $SELECT($DATA(ZTDESC)[0:1,ZTDESC="":1,1:0)
SET ZTDESC=$GET(^%ZTSK(ZTSK,.03))
+2 IF ZTDESC=""!(ZTDESC="No Description (%ZTLOAD)")
SET ZTDESC="No Description (REQ~%ZTLOAD)"
+3 SET ^%ZTSK(ZTSK,.03)=ZTDESC
+4 ;
RECORD ;record changes in Task File entry
+1 IF $DATA(ZTREC2)#2
SET ^%ZTSK(ZTSK,.2)=ZTREC2
+2 IF $DATA(ZTREC25)#2
SET ^%ZTSK(ZTSK,.25)=ZTREC25
+3 ;Reset the Scheduled time piece
IF ZTDTH'="@"
SET $PIECE(ZTREC,U,6)=ZTDTH
+4 SET ^%ZTSK(ZTSK,0)=ZTREC
+5 SET $PIECE(^%ZTSK(ZTSK,.1),U,1,3)=$SELECT(ZTDTH'="@":"1^"_$HOROLOG_"^REQUEUED",1:"H^"_$HOROLOG_"^EDITED BUT NOT REQUEUED")
+6 ;
ZTSAVE ;See if new data to save
+1 KILL %H,%T,X,X1,Y,ZT,ZT1,ZT2,ZT3,ZTH,ZTL,ZTOS,ZTREC,ZTREC1,ZTREC2,ZTREC25
+2 KILL ZTDESC,ZTIO,ZTRTN
+3 IF $DATA(ZTSAVE)
if $GET(ZTSAVE)="KILL"
KILL ^%ZTSK(ZTSK,.3)
DO ZTSAVE^%ZTLOAD1
SCHED ;schedule task, cleanup, quit
+1 IF ZTDTH'="@"
LOCK +^%ZTSCH("SCHQ"):6
SET ZT=$$H3^%ZTLOAD1(ZTDTH)
SET ^%ZTSK(ZTSK,.04)=ZT
SET ^%ZTSCH(ZT,ZTSK)=""
LOCK -^%ZTSCH("SCHQ")
+2 KILL %X,%Y,X,X1,Y,ZT1,ZT2,ZT3,ZTDTH,ZTSAVE
+3 LOCK -^%ZTSK(ZTSK)
SET ZTSK(0)=1
+4 QUIT
+5 ;
BAD LOCK -^%ZTSK(ZTSK)
SET ZTSK(0)=0
+1 QUIT
REQP(ZT1) ;Reschedule a persistent task. Called from ZTM
+1 NEW ZTSK,ZT2,ZT3,ZTDTH,ZTSAVE
SET ZTDTH=$HOROLOG
SET ZTSK=ZT1
+2 LOCK +^%ZTSK(ZTSK):20
if '$TEST
QUIT
+3 ;Should tell someone
IF $DATA(^%ZTSK(ZTSK,0))[0
QUIT
+4 GOTO SCHED