RORTSK02 ;HCIOFO/SG - TASK MANAGER UTILITIES ; 1/23/06 8:11am
;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
;
Q
;
;***** RETURNS A LIST OF USER'S TASKS
;
; .TASKLIST Reference to a local array that the task
; list is returned to
;
; [REGIEN] Registry IEN
;
; [TYPE] Type of the task (1 - Generic, 2 - Report)
;
; [.FROM] Where to start/continue the list generation.
; By defualt (if $G(FROM)'>0), the extraction starts
; from the beginning of the user's task list.
;
; NOTE: The task, which number is passed via this
; parameter, is not included in the report.
;
; After the call, this parameter contains the last
; extracted task number or an empty string if there
; are no more tasks.
;
; [NUMBER] Maximum number of tasks returned by the function.
; By default (if $G(NUMBER)'>0), all task numbers
; (starting from the point indicated by the FROM
; parameter if it is defined) are retrieved.
;
; [USER] A user IEN (DUZ). By default (if $G(USER)'>0),
; the curent user's DUZ is used.
;
; Return values:
; <0 Error code
; 0 No tasks have been found
; >0 Number of tasks
;
LIST(TASKLIST,REGIEN,TYPE,FROM,NUMBER,USER) ;
N DIR,NTSK,RC,ROOT,RORBUF,SCR,TASK K TASKLIST
S ROOT=$$ROOT^DILFD(798.8,,1)
S USER=$S($G(USER)>0:+USER,1:+$G(DUZ))
S DIR=$S($$UP^XLFSTR($G(NUMBER))["B":-1,1:1)
S NUMBER=$S($G(NUMBER)>0:+NUMBER,1:999999)
;--- Generate a screen logic
S SCR="I 1"
S:$G(REGIEN)>0 SCR=SCR_","_"$P(RORBUF,U,3)="_(+REGIEN)
S:$G(TYPE)>0 SCR=SCR_","_"$P(RORBUF,U,2)="_(+TYPE)
;--- Generate the output list
S TASK=$S($G(FROM)>0:FROM,1:""),NTSK=0
F S TASK=$O(@ROOT@("U",USER,TASK),DIR) Q:TASK="" D Q:NTSK'<NUMBER
. S RORBUF=$G(@ROOT@(TASK,0)) X SCR E Q
. S NTSK=NTSK+1,TASKLIST(TASK)=""
S FROM=TASK
Q NTSK
;
;***** PURGES THE OLD TASKS
;
; [DKEEP] Days to keep the old tasks (by default = 15)
;
; Return Values:
; <0 Error code
; 0 Ok
;
PURGE(DKEEP) ;
N DA,DATE,DIK,FROM,RC,STATUS,TASK,TASKINFO
S ROOT=$$ROOT^DILFD(798.8,,1),DIK=$$OREF^DILF(ROOT)
S FROM=$$FMADD^XLFDT($$DT^XLFDT,1-$G(DKEEP,15))
;---
S DATE=FROM,RC=0
F S DATE=$O(@ROOT@("ACDT",DATE),-1) Q:DATE="" D
. S TASK=""
. F S TASK=$O(@ROOT@("ACDT",DATE,TASK),-1) Q:TASK="" D
. . Q:$$TASKINFO(TASK,.TASKINFO)<0
. . S STATUS=+TASKINFO(6)
. . ;--- Do not delete pending, running and suspended tasks
. . Q:(STATUS=1)!(STATUS=2)!(STATUS=102)
. . ;--- If task is completed, use its completion
. . ;--- date instead of the creation date
. . I TASKINFO(9)>DATE Q:TASKINFO(9)'<FROM
. . ;--- Delete the record
. . S DA=TASK D ^DIK
;---
Q $S(RC<0:RC,1:0)
;
;***** RETURNS STATUS OF THE TASK
;
; TASK Task number
; [LTO] LOCK timeout (0 by default)
; [UNDEF83] Return the error -83 if there is no task record.
; By default (if +$G(UNDEF83)=0), zero is returned.
;
; Return Values:
; <0 Error code
; 0 Undefined task/Unknown Status
; >0 Status (Code^Description)
;
; 1 Active: Pending
; 2 Active: Running
; 3 Inactive: Finished
; 4 Inactive: Available
; 5 Inactive: Interrupted
;
; 100 Inactive: Crashed
; 101 Inactive: Errors
; 102 Active: Suspended
; 103 Active: Stopping
;
STATUS(TASK,LTO,UNDEF83) ;
N ACTION,IENS,RORBUF,RORMSG,STATUS,TASKNODE,TMS,ZTSK
Q:TASK'>0 $$ERROR^RORERR(-85,,,,TASK)
S TASKNODE=$NA(^RORDATA(798.8,TASK))
Q:'$D(@TASKNODE) $S($G(UNDEF83):-83,1:0)
;--- Get internal value of the STATUS field (2.01)
S STATUS=+$G(@TASKNODE@(2))
;--- Lock the record and check if the task is running
L +@TASKNODE@("T",0):$G(LTO,0)
E S TMS="" D Q:TMS'="" TMS
. S ACTION=+$G(@TASKNODE@("A"))
. I ACTION=2 S TMS="103^Active: Stopping" Q
. I STATUS=100 S TMS="2^Active: Running" Q
. I STATUS=102 S TMS="102^Active: Suspended" Q
D
. ;--- Try to get status from the Taskman
. S ZTSK=TASK D STAT^%ZTLOAD
. S TMS=$S($G(ZTSK(0)):+$G(ZTSK(1)),1:0)
. ;--- Pending or Available
. I (TMS=1)!(TMS=4) S STATUS=TMS_U_$G(ZTSK(2)) Q
. ;--- Running (actually, crashed ;-)
. I TMS=2 S STATUS=100 Q
. ;--- Finished, Interrupted or Undefined
. I 'STATUS S:TMS STATUS=TMS_U_$G(ZTSK(2)) Q
. ;--- If the task record is not locked and the STATUS field shows
. ; 'Suspended' (102) then the task probably crashed while it
. ;--- was in the suspended state
. S:STATUS=102 STATUS=100
;--- Get the external value of the STATUS field (if necessary)
I STATUS>0 D:$P(STATUS,U,2)=""
. S $P(STATUS,U,2)=$$EXTERNAL^DILFD(798.8,2.01,,STATUS,"RORMSG")
. S:$G(DIERR) STATUS=$$DBS^RORERR("RORMSG",-9,,,798.8)
;
;--- Unlock the task record
L -@TASKNODE@("T",0)
Q $TR(STATUS,">",":")
;
;***** RETURNS THE TASK INFORMATION
;
; TASK Task number
;
; .INFO Reference to a local variable (output):
;
; INFO(
; OFFSET+1) Task Number
; OFFSET+2) Task Type (internal^external)
; OFFSET+3) Registry (IEN^Name)
; OFFSET+4) Report (Code^Name)
; OFFSET+5) Description
; OFFSET+6) Task Status (internal^external)
; OFFSET+7) Creation Time (internal)
; OFFSET+8) User (DUZ^Name)
; OFFSET+9) Completion Time (internal)
; OFFSET+10) Progress Percentage
; OFFSET+11) Scheduled to Run at (internal)
; OFFSET+12) Task Log IEN
; OFFSET+13) Job Number
; OFFSET+14) User Comment
;
; [FLAGS] Characters controlling behavior of the function
; (they can be combined):
; E Return external values also (when applicable)
;
; [OFFSET] A number that is added to all subscripts in the
; destination array (by default, it is zero).
;
; Return Values:
; <0 Error code
; 0 Ok
;
TASKINFO(TASK,INFO,FLAGS,OFFSET) ;
N I,IENS,RORBUF,RORMSG,TMP
S FLAGS=$$UP^XLFSTR($G(FLAGS))
S OFFSET=$S($G(OFFSET)>0:+OFFSET,1:0)
;--- Clear the output array
K:'OFFSET INFO S TMP=$$TIN
F I=1:1:TMP S INFO(OFFSET+I)=""
;--- Get the task status
S TMP=$$STATUS(TASK,,1) Q:TMP<0 TMP
S INFO(OFFSET+1)=TASK
S INFO(OFFSET+6)=$S(FLAGS["E":TMP,1:+TMP)
;--- Load the task record
S IENS=TASK_",",I=$S(FLAGS["E":"EIN",1:"IN")
S TMP=".02;.03;.04;.05;.07;.08;1.01;2.02;2.03;2.04;4"
D GETS^DIQ(798.8,IENS,TMP,I,"RORBUF","RORMSG")
I $G(DIERR) D Q RC
. S RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
;--- Format the output array
Q $$FRMTI^RORTSK03(OFFSET,.INFO,IENS,.RORBUF,FLAGS)
;
;***** RETURNS NUMBER OF NODES IN THE TASK INFORMATION ARRAY
TIN() Q 14
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORTSK02 7163 printed Oct 16, 2024@17:44:22 Page 2
RORTSK02 ;HCIOFO/SG - TASK MANAGER UTILITIES ; 1/23/06 8:11am
+1 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
+2 ;
+3 QUIT
+4 ;
+5 ;***** RETURNS A LIST OF USER'S TASKS
+6 ;
+7 ; .TASKLIST Reference to a local array that the task
+8 ; list is returned to
+9 ;
+10 ; [REGIEN] Registry IEN
+11 ;
+12 ; [TYPE] Type of the task (1 - Generic, 2 - Report)
+13 ;
+14 ; [.FROM] Where to start/continue the list generation.
+15 ; By defualt (if $G(FROM)'>0), the extraction starts
+16 ; from the beginning of the user's task list.
+17 ;
+18 ; NOTE: The task, which number is passed via this
+19 ; parameter, is not included in the report.
+20 ;
+21 ; After the call, this parameter contains the last
+22 ; extracted task number or an empty string if there
+23 ; are no more tasks.
+24 ;
+25 ; [NUMBER] Maximum number of tasks returned by the function.
+26 ; By default (if $G(NUMBER)'>0), all task numbers
+27 ; (starting from the point indicated by the FROM
+28 ; parameter if it is defined) are retrieved.
+29 ;
+30 ; [USER] A user IEN (DUZ). By default (if $G(USER)'>0),
+31 ; the curent user's DUZ is used.
+32 ;
+33 ; Return values:
+34 ; <0 Error code
+35 ; 0 No tasks have been found
+36 ; >0 Number of tasks
+37 ;
LIST(TASKLIST,REGIEN,TYPE,FROM,NUMBER,USER) ;
+1 NEW DIR,NTSK,RC,ROOT,RORBUF,SCR,TASK
KILL TASKLIST
+2 SET ROOT=$$ROOT^DILFD(798.8,,1)
+3 SET USER=$SELECT($GET(USER)>0:+USER,1:+$GET(DUZ))
+4 SET DIR=$SELECT($$UP^XLFSTR($GET(NUMBER))["B":-1,1:1)
+5 SET NUMBER=$SELECT($GET(NUMBER)>0:+NUMBER,1:999999)
+6 ;--- Generate a screen logic
+7 SET SCR="I 1"
+8 if $GET(REGIEN)>0
SET SCR=SCR_","_"$P(RORBUF,U,3)="_(+REGIEN)
+9 if $GET(TYPE)>0
SET SCR=SCR_","_"$P(RORBUF,U,2)="_(+TYPE)
+10 ;--- Generate the output list
+11 SET TASK=$SELECT($GET(FROM)>0:FROM,1:"")
SET NTSK=0
+12 FOR
SET TASK=$ORDER(@ROOT@("U",USER,TASK),DIR)
if TASK=""
QUIT
Begin DoDot:1
+13 SET RORBUF=$GET(@ROOT@(TASK,0))
XECUTE SCR
IF '$TEST
QUIT
+14 SET NTSK=NTSK+1
SET TASKLIST(TASK)=""
End DoDot:1
if NTSK'<NUMBER
QUIT
+15 SET FROM=TASK
+16 QUIT NTSK
+17 ;
+18 ;***** PURGES THE OLD TASKS
+19 ;
+20 ; [DKEEP] Days to keep the old tasks (by default = 15)
+21 ;
+22 ; Return Values:
+23 ; <0 Error code
+24 ; 0 Ok
+25 ;
PURGE(DKEEP) ;
+1 NEW DA,DATE,DIK,FROM,RC,STATUS,TASK,TASKINFO
+2 SET ROOT=$$ROOT^DILFD(798.8,,1)
SET DIK=$$OREF^DILF(ROOT)
+3 SET FROM=$$FMADD^XLFDT($$DT^XLFDT,1-$GET(DKEEP,15))
+4 ;---
+5 SET DATE=FROM
SET RC=0
+6 FOR
SET DATE=$ORDER(@ROOT@("ACDT",DATE),-1)
if DATE=""
QUIT
Begin DoDot:1
+7 SET TASK=""
+8 FOR
SET TASK=$ORDER(@ROOT@("ACDT",DATE,TASK),-1)
if TASK=""
QUIT
Begin DoDot:2
+9 if $$TASKINFO(TASK,.TASKINFO)<0
QUIT
+10 SET STATUS=+TASKINFO(6)
+11 ;--- Do not delete pending, running and suspended tasks
+12 if (STATUS=1)!(STATUS=2)!(STATUS=102)
QUIT
+13 ;--- If task is completed, use its completion
+14 ;--- date instead of the creation date
+15 IF TASKINFO(9)>DATE
if TASKINFO(9)'<FROM
QUIT
+16 ;--- Delete the record
+17 SET DA=TASK
DO ^DIK
End DoDot:2
End DoDot:1
+18 ;---
+19 QUIT $SELECT(RC<0:RC,1:0)
+20 ;
+21 ;***** RETURNS STATUS OF THE TASK
+22 ;
+23 ; TASK Task number
+24 ; [LTO] LOCK timeout (0 by default)
+25 ; [UNDEF83] Return the error -83 if there is no task record.
+26 ; By default (if +$G(UNDEF83)=0), zero is returned.
+27 ;
+28 ; Return Values:
+29 ; <0 Error code
+30 ; 0 Undefined task/Unknown Status
+31 ; >0 Status (Code^Description)
+32 ;
+33 ; 1 Active: Pending
+34 ; 2 Active: Running
+35 ; 3 Inactive: Finished
+36 ; 4 Inactive: Available
+37 ; 5 Inactive: Interrupted
+38 ;
+39 ; 100 Inactive: Crashed
+40 ; 101 Inactive: Errors
+41 ; 102 Active: Suspended
+42 ; 103 Active: Stopping
+43 ;
STATUS(TASK,LTO,UNDEF83) ;
+1 NEW ACTION,IENS,RORBUF,RORMSG,STATUS,TASKNODE,TMS,ZTSK
+2 if TASK'>0
QUIT $$ERROR^RORERR(-85,,,,TASK)
+3 SET TASKNODE=$NAME(^RORDATA(798.8,TASK))
+4 if '$DATA(@TASKNODE)
QUIT $SELECT($GET(UNDEF83):-83,1:0)
+5 ;--- Get internal value of the STATUS field (2.01)
+6 SET STATUS=+$GET(@TASKNODE@(2))
+7 ;--- Lock the record and check if the task is running
+8 LOCK +@TASKNODE@("T",0):$GET(LTO,0)
+9 IF '$TEST
SET TMS=""
Begin DoDot:1
+10 SET ACTION=+$GET(@TASKNODE@("A"))
+11 IF ACTION=2
SET TMS="103^Active: Stopping"
QUIT
+12 IF STATUS=100
SET TMS="2^Active: Running"
QUIT
+13 IF STATUS=102
SET TMS="102^Active: Suspended"
QUIT
End DoDot:1
if TMS'=""
QUIT TMS
+14 Begin DoDot:1
+15 ;--- Try to get status from the Taskman
+16 SET ZTSK=TASK
DO STAT^%ZTLOAD
+17 SET TMS=$SELECT($GET(ZTSK(0)):+$GET(ZTSK(1)),1:0)
+18 ;--- Pending or Available
+19 IF (TMS=1)!(TMS=4)
SET STATUS=TMS_U_$GET(ZTSK(2))
QUIT
+20 ;--- Running (actually, crashed ;-)
+21 IF TMS=2
SET STATUS=100
QUIT
+22 ;--- Finished, Interrupted or Undefined
+23 IF 'STATUS
if TMS
SET STATUS=TMS_U_$GET(ZTSK(2))
QUIT
+24 ;--- If the task record is not locked and the STATUS field shows
+25 ; 'Suspended' (102) then the task probably crashed while it
+26 ;--- was in the suspended state
+27 if STATUS=102
SET STATUS=100
End DoDot:1
+28 ;--- Get the external value of the STATUS field (if necessary)
+29 IF STATUS>0
if $PIECE(STATUS,U,2)=""
Begin DoDot:1
+30 SET $PIECE(STATUS,U,2)=$$EXTERNAL^DILFD(798.8,2.01,,STATUS,"RORMSG")
+31 if $GET(DIERR)
SET STATUS=$$DBS^RORERR("RORMSG",-9,,,798.8)
End DoDot:1
+32 ;
+33 ;--- Unlock the task record
+34 LOCK -@TASKNODE@("T",0)
+35 QUIT $TRANSLATE(STATUS,">",":")
+36 ;
+37 ;***** RETURNS THE TASK INFORMATION
+38 ;
+39 ; TASK Task number
+40 ;
+41 ; .INFO Reference to a local variable (output):
+42 ;
+43 ; INFO(
+44 ; OFFSET+1) Task Number
+45 ; OFFSET+2) Task Type (internal^external)
+46 ; OFFSET+3) Registry (IEN^Name)
+47 ; OFFSET+4) Report (Code^Name)
+48 ; OFFSET+5) Description
+49 ; OFFSET+6) Task Status (internal^external)
+50 ; OFFSET+7) Creation Time (internal)
+51 ; OFFSET+8) User (DUZ^Name)
+52 ; OFFSET+9) Completion Time (internal)
+53 ; OFFSET+10) Progress Percentage
+54 ; OFFSET+11) Scheduled to Run at (internal)
+55 ; OFFSET+12) Task Log IEN
+56 ; OFFSET+13) Job Number
+57 ; OFFSET+14) User Comment
+58 ;
+59 ; [FLAGS] Characters controlling behavior of the function
+60 ; (they can be combined):
+61 ; E Return external values also (when applicable)
+62 ;
+63 ; [OFFSET] A number that is added to all subscripts in the
+64 ; destination array (by default, it is zero).
+65 ;
+66 ; Return Values:
+67 ; <0 Error code
+68 ; 0 Ok
+69 ;
TASKINFO(TASK,INFO,FLAGS,OFFSET) ;
+1 NEW I,IENS,RORBUF,RORMSG,TMP
+2 SET FLAGS=$$UP^XLFSTR($GET(FLAGS))
+3 SET OFFSET=$SELECT($GET(OFFSET)>0:+OFFSET,1:0)
+4 ;--- Clear the output array
+5 if 'OFFSET
KILL INFO
SET TMP=$$TIN
+6 FOR I=1:1:TMP
SET INFO(OFFSET+I)=""
+7 ;--- Get the task status
+8 SET TMP=$$STATUS(TASK,,1)
if TMP<0
QUIT TMP
+9 SET INFO(OFFSET+1)=TASK
+10 SET INFO(OFFSET+6)=$SELECT(FLAGS["E":TMP,1:+TMP)
+11 ;--- Load the task record
+12 SET IENS=TASK_","
SET I=$SELECT(FLAGS["E":"EIN",1:"IN")
+13 SET TMP=".02;.03;.04;.05;.07;.08;1.01;2.02;2.03;2.04;4"
+14 DO GETS^DIQ(798.8,IENS,TMP,I,"RORBUF","RORMSG")
+15 IF $GET(DIERR)
Begin DoDot:1
+16 SET RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
End DoDot:1
QUIT RC
+17 ;--- Format the output array
+18 QUIT $$FRMTI^RORTSK03(OFFSET,.INFO,IENS,.RORBUF,FLAGS)
+19 ;
+20 ;***** RETURNS NUMBER OF NODES IN THE TASK INFORMATION ARRAY
TIN() QUIT 14