%ZTLOAD2 ;SEA/RDS-TaskMan: Queue, Part 2 ;12/10/08 07:23
;;8.0;KERNEL;**1,67,118,275,339,446**;Jul 10, 1995;Build 44
;
REJECT(MSG) ;GET--reject bad task
I '$D(ZTQUEUED) W !,"QUEUE INFORMATION MISSING - NOT QUEUED",!,MSG
G EXIT
;
BADDEV(MSG) ;GET--Reject task because of device issue.
I '$D(ZTQUEUED) W !,"Queueing not allowed to device -- NOT QUEUED",!,MSG
EXIT ;Report back to app.
S %ZTLOAD("ERROR")=MSG
Q
;
RESTRCT ;GET--flag tasks with output restricted from certain times; check.
I $D(ZTQUEUED) Q
S ZTNOGO=0
I ZTDTH="@" Q
I ZTDTH'?1.5N1","1.5N Q
S X=$$HTFM^%ZTLOAD7(ZTDTH) D ^XQ92 I X="" S ZTDTH="" W !,"Sorry--that time is restricted!",!,$C(7)
Q
;
ASK ;GET--ask for start time
N %DT,Y
I $D(ZTQUEUED) D:ZTDTH]"" Q
. S %DT="FRS",X=ZTDTH D ^%DT
. S ZTDTH=$$FMTH^%ZTLOAD7(+Y) I Y'>0 S ZTDTH=""
. Q
S ZTDTH="",%DT="AERSX",%DT("A")="Requested Start Time: ",%DT("B")="NOW",%DT(0)="NOW"
I $D(ZTNOGO) D I X="" Q
. S Y=+XQY D NEXT^XQ92 I X="" W !,"Output is never allowed from this option!",$C(7),$C(7) Q
. S %DT("B")=$$FMTE^%ZTLOAD7(X),%DT="AERSX"
. Q
I $D(ZTNOGO),'$D(XQNOGO) W !,"Output from this option is restricted during certain times."
F ZT=0:0 D ^%DT Q:(Y<0)!'$D(ZTNOGO) S ZT=Y,X=Y D ^XQ92 S Y=ZT Q:X]"" W !!,"That is a restricted time!",!,$C(7)
S:Y>0 ZTDTH=$$FMTH^%ZTLOAD7(+Y)
K %DT,%T,X5,ZT
Q
;
OPTION ;GET--get option data
S ZTA4=$G(ZTSAVE("XQY")) I 'ZTA4 S ZTA4=$G(XQY) I 'ZTA4 S ZTA4=""
S ZTA1="O" I 'ZTA4 S ZTA1="" Q
S ZTA5=$P($G(^DIC(19,ZTA4,0)),U)
Q
;
ZTKIL ;GET--convert forget time
S ZTKIL=$S(ZTKIL?5N:ZTKIL,ZTKIL?5N1","1.5N:ZTKIL,ZTKIL?7N.".".N:$$FMTH^%ZTLOAD7(ZTKIL),1:"")
Q
;
SPOOL ;DEVICE--for predefined ZTIO spool device, pick up IO("DOC") if missing
I $G(IO("DOC"))="" Q
I ZTIO[IO("DOC") Q
I $P(ZTIO,";",2)?.N D
.S ZTIO=$P(ZTIO,";")_";"_IO("DOC")_";"_$P(ZTIO,";",2,999)
E I $P(ZTIO,";",2)?1.2A1"-"1.ANP,$P(ZTIO,";",3)?.N D
.S ZTIO=$P(ZTIO,";",1,2)_";"_IO("DOC")_";"_$P(ZTIO,";",3,999)
Q
;
ASKSTOP ;e.f. Called from ASKSTOP^%ZTLOAD
;Ask a task to stop. Unschedule if not started.
N % S ZTSK=+$G(ZTSK) I ZTSK<1 Q "0^BAD TASK NUMBER"
L +^%ZTSK(ZTSK):10 I '$T Q "0^Busy"
S %=$$AKS
L -^%ZTSK(ZTSK)
Q %
;
AKS() ;Locked before called
N ZT1,ZT2,ZTDTH,%ZTIO
S ZTSK(0)=$G(^%ZTSK(ZTSK,0)),ZTSK(.1)=$G(^(.1))
I ZTSK(0)="" Q "1^Task missing"
S $P(^%ZTSK(ZTSK,.1),U,10)=$S($D(ZTNAME)#2:ZTNAME,1:$G(DUZ,.5))
I +ZTSK(.1)=6 Q "1^Finished running"
I +ZTSK(.1)=5 Q "2^Asked to stop"
S ZTDTH=$$H3^%ZTM($P(ZTSK(0),U,6))
K ^%ZTSCH(ZTDTH,ZTSK) ;Remove from schedule
S %ZTIO=$O(^%ZTSK(ZTSK,.26,"")) I %ZTIO]"" D DQ^%ZTM4 ;Remove from device lists.
Q "2^Unscheduled"
%ZTLOAD2 ;SEA/RDS-TaskMan: Queue, Part 2 ;12/10/08 07:23
+1 ;;8.0;KERNEL;**1,67,118,275,339,446**;Jul 10, 1995;Build 44
+2 ;
REJECT(MSG) ;GET--reject bad task
+1 IF '$DATA(ZTQUEUED)
WRITE !,"QUEUE INFORMATION MISSING - NOT QUEUED",!,MSG
+2 GOTO EXIT
+3 ;
BADDEV(MSG) ;GET--Reject task because of device issue.
+1 IF '$DATA(ZTQUEUED)
WRITE !,"Queueing not allowed to device -- NOT QUEUED",!,MSG
EXIT ;Report back to app.
+1 SET %ZTLOAD("ERROR")=MSG
+2 QUIT
+3 ;
RESTRCT ;GET--flag tasks with output restricted from certain times; check.
+1 IF $DATA(ZTQUEUED)
QUIT
+2 SET ZTNOGO=0
+3 IF ZTDTH="@"
QUIT
+4 IF ZTDTH'?1.5N1","1.5N
QUIT
+5 SET X=$$HTFM^%ZTLOAD7(ZTDTH)
DO ^XQ92
IF X=""
SET ZTDTH=""
WRITE !,"Sorry--that time is restricted!",!,$CHAR(7)
+6 QUIT
+7 ;
ASK ;GET--ask for start time
+1 NEW %DT,Y
+2 IF $DATA(ZTQUEUED)
IF ZTDTH]""
Begin DoDot:1
+3 SET %DT="FRS"
SET X=ZTDTH
DO ^%DT
+4 SET ZTDTH=$$FMTH^%ZTLOAD7(+Y)
IF Y'>0
SET ZTDTH=""
+5 QUIT
End DoDot:1
QUIT
+6 SET ZTDTH=""
SET %DT="AERSX"
SET %DT("A")="Requested Start Time: "
SET %DT("B")="NOW"
SET %DT(0)="NOW"
+7 IF $DATA(ZTNOGO)
Begin DoDot:1
+8 SET Y=+XQY
DO NEXT^XQ92
IF X=""
WRITE !,"Output is never allowed from this option!",$CHAR(7),$CHAR(7)
QUIT
+9 SET %DT("B")=$$FMTE^%ZTLOAD7(X)
SET %DT="AERSX"
+10 QUIT
End DoDot:1
IF X=""
QUIT
+11 IF $DATA(ZTNOGO)
IF '$DATA(XQNOGO)
WRITE !,"Output from this option is restricted during certain times."
+12 FOR ZT=0:0
DO ^%DT
IF (Y<0)!'$DATA(ZTNOGO)
QUIT
SET ZT=Y
SET X=Y
DO ^XQ92
SET Y=ZT
IF X]""
QUIT
WRITE !!,"That is a restricted time!",!,$CHAR(7)
+13 IF Y>0
SET ZTDTH=$$FMTH^%ZTLOAD7(+Y)
+14 KILL %DT,%T,X5,ZT
+15 QUIT
+16 ;
OPTION ;GET--get option data
+1 SET ZTA4=$GET(ZTSAVE("XQY"))
IF 'ZTA4
SET ZTA4=$GET(XQY)
IF 'ZTA4
SET ZTA4=""
+2 SET ZTA1="O"
IF 'ZTA4
SET ZTA1=""
QUIT
+3 SET ZTA5=$PIECE($GET(^DIC(19,ZTA4,0)),U)
+4 QUIT
+5 ;
ZTKIL ;GET--convert forget time
+1 SET ZTKIL=$SELECT(ZTKIL?5N:ZTKIL,ZTKIL?5N1","1.5N:ZTKIL,ZTKIL?7N.".".N:$$FMTH^%ZTLOAD7(ZTKIL),1:"")
+2 QUIT
+3 ;
SPOOL ;DEVICE--for predefined ZTIO spool device, pick up IO("DOC") if missing
+1 IF $GET(IO("DOC"))=""
QUIT
+2 IF ZTIO[IO("DOC")
QUIT
+3 IF $PIECE(ZTIO,";",2)?.N
Begin DoDot:1
+4 SET ZTIO=$PIECE(ZTIO,";")_";"_IO("DOC")_";"_$PIECE(ZTIO,";",2,999)
End DoDot:1
+5 IF '$TEST
IF $PIECE(ZTIO,";",2)?1.2A1"-"1.ANP
IF $PIECE(ZTIO,";",3)?.N
Begin DoDot:1
+6 SET ZTIO=$PIECE(ZTIO,";",1,2)_";"_IO("DOC")_";"_$PIECE(ZTIO,";",3,999)
End DoDot:1
+7 QUIT
+8 ;
ASKSTOP ;e.f. Called from ASKSTOP^%ZTLOAD
+1 ;Ask a task to stop. Unschedule if not started.
+2 NEW %
SET ZTSK=+$GET(ZTSK)
IF ZTSK<1
QUIT "0^BAD TASK NUMBER"
+3 LOCK +^%ZTSK(ZTSK):10
IF '$TEST
QUIT "0^Busy"
+4 SET %=$$AKS
+5 LOCK -^%ZTSK(ZTSK)
+6 QUIT %
+7 ;
AKS() ;Locked before called
+1 NEW ZT1,ZT2,ZTDTH,%ZTIO
+2 SET ZTSK(0)=$GET(^%ZTSK(ZTSK,0))
SET ZTSK(.1)=$GET(^(.1))
+3 IF ZTSK(0)=""
QUIT "1^Task missing"
+4 SET $PIECE(^%ZTSK(ZTSK,.1),U,10)=$SELECT($DATA(ZTNAME)#2:ZTNAME,1:$GET(DUZ,.5))
+5 IF +ZTSK(.1)=6
QUIT "1^Finished running"
+6 IF +ZTSK(.1)=5
QUIT "2^Asked to stop"
+7 SET ZTDTH=$$H3^%ZTM($PIECE(ZTSK(0),U,6))
+8 ;Remove from schedule
KILL ^%ZTSCH(ZTDTH,ZTSK)
+9 ;Remove from device lists.
SET %ZTIO=$ORDER(^%ZTSK(ZTSK,.26,""))
IF %ZTIO]""
DO DQ^%ZTM4
+10 QUIT "2^Unscheduled"