Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: RORTSK02

RORTSK02.m

Go to the documentation of this file.
  1. RORTSK02 ;HCIOFO/SG - TASK MANAGER UTILITIES ; 1/23/06 8:11am
  1. ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
  1. ;
  1. Q
  1. ;
  1. ;***** RETURNS A LIST OF USER'S TASKS
  1. ;
  1. ; .TASKLIST Reference to a local array that the task
  1. ; list is returned to
  1. ;
  1. ; [REGIEN] Registry IEN
  1. ;
  1. ; [TYPE] Type of the task (1 - Generic, 2 - Report)
  1. ;
  1. ; [.FROM] Where to start/continue the list generation.
  1. ; By defualt (if $G(FROM)'>0), the extraction starts
  1. ; from the beginning of the user's task list.
  1. ;
  1. ; NOTE: The task, which number is passed via this
  1. ; parameter, is not included in the report.
  1. ;
  1. ; After the call, this parameter contains the last
  1. ; extracted task number or an empty string if there
  1. ; are no more tasks.
  1. ;
  1. ; [NUMBER] Maximum number of tasks returned by the function.
  1. ; By default (if $G(NUMBER)'>0), all task numbers
  1. ; (starting from the point indicated by the FROM
  1. ; parameter if it is defined) are retrieved.
  1. ;
  1. ; [USER] A user IEN (DUZ). By default (if $G(USER)'>0),
  1. ; the curent user's DUZ is used.
  1. ;
  1. ; Return values:
  1. ; <0 Error code
  1. ; 0 No tasks have been found
  1. ; >0 Number of tasks
  1. ;
  1. LIST(TASKLIST,REGIEN,TYPE,FROM,NUMBER,USER) ;
  1. N DIR,NTSK,RC,ROOT,RORBUF,SCR,TASK K TASKLIST
  1. S ROOT=$$ROOT^DILFD(798.8,,1)
  1. S USER=$S($G(USER)>0:+USER,1:+$G(DUZ))
  1. S DIR=$S($$UP^XLFSTR($G(NUMBER))["B":-1,1:1)
  1. S NUMBER=$S($G(NUMBER)>0:+NUMBER,1:999999)
  1. ;--- Generate a screen logic
  1. S SCR="I 1"
  1. S:$G(REGIEN)>0 SCR=SCR_","_"$P(RORBUF,U,3)="_(+REGIEN)
  1. S:$G(TYPE)>0 SCR=SCR_","_"$P(RORBUF,U,2)="_(+TYPE)
  1. ;--- Generate the output list
  1. S TASK=$S($G(FROM)>0:FROM,1:""),NTSK=0
  1. F S TASK=$O(@ROOT@("U",USER,TASK),DIR) Q:TASK="" D Q:NTSK'<NUMBER
  1. . S RORBUF=$G(@ROOT@(TASK,0)) X SCR E Q
  1. . S NTSK=NTSK+1,TASKLIST(TASK)=""
  1. S FROM=TASK
  1. Q NTSK
  1. ;
  1. ;***** PURGES THE OLD TASKS
  1. ;
  1. ; [DKEEP] Days to keep the old tasks (by default = 15)
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. PURGE(DKEEP) ;
  1. N DA,DATE,DIK,FROM,RC,STATUS,TASK,TASKINFO
  1. S ROOT=$$ROOT^DILFD(798.8,,1),DIK=$$OREF^DILF(ROOT)
  1. S FROM=$$FMADD^XLFDT($$DT^XLFDT,1-$G(DKEEP,15))
  1. ;---
  1. S DATE=FROM,RC=0
  1. F S DATE=$O(@ROOT@("ACDT",DATE),-1) Q:DATE="" D
  1. . S TASK=""
  1. . F S TASK=$O(@ROOT@("ACDT",DATE,TASK),-1) Q:TASK="" D
  1. . . Q:$$TASKINFO(TASK,.TASKINFO)<0
  1. . . S STATUS=+TASKINFO(6)
  1. . . ;--- Do not delete pending, running and suspended tasks
  1. . . Q:(STATUS=1)!(STATUS=2)!(STATUS=102)
  1. . . ;--- If task is completed, use its completion
  1. . . ;--- date instead of the creation date
  1. . . I TASKINFO(9)>DATE Q:TASKINFO(9)'<FROM
  1. . . ;--- Delete the record
  1. . . S DA=TASK D ^DIK
  1. ;---
  1. Q $S(RC<0:RC,1:0)
  1. ;
  1. ;***** RETURNS STATUS OF THE TASK
  1. ;
  1. ; TASK Task number
  1. ; [LTO] LOCK timeout (0 by default)
  1. ; [UNDEF83] Return the error -83 if there is no task record.
  1. ; By default (if +$G(UNDEF83)=0), zero is returned.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Undefined task/Unknown Status
  1. ; >0 Status (Code^Description)
  1. ;
  1. ; 1 Active: Pending
  1. ; 2 Active: Running
  1. ; 3 Inactive: Finished
  1. ; 4 Inactive: Available
  1. ; 5 Inactive: Interrupted
  1. ;
  1. ; 100 Inactive: Crashed
  1. ; 101 Inactive: Errors
  1. ; 102 Active: Suspended
  1. ; 103 Active: Stopping
  1. ;
  1. STATUS(TASK,LTO,UNDEF83) ;
  1. N ACTION,IENS,RORBUF,RORMSG,STATUS,TASKNODE,TMS,ZTSK
  1. Q:TASK'>0 $$ERROR^RORERR(-85,,,,TASK)
  1. S TASKNODE=$NA(^RORDATA(798.8,TASK))
  1. Q:'$D(@TASKNODE) $S($G(UNDEF83):-83,1:0)
  1. ;--- Get internal value of the STATUS field (2.01)
  1. S STATUS=+$G(@TASKNODE@(2))
  1. ;--- Lock the record and check if the task is running
  1. L +@TASKNODE@("T",0):$G(LTO,0)
  1. E S TMS="" D Q:TMS'="" TMS
  1. . S ACTION=+$G(@TASKNODE@("A"))
  1. . I ACTION=2 S TMS="103^Active: Stopping" Q
  1. . I STATUS=100 S TMS="2^Active: Running" Q
  1. . I STATUS=102 S TMS="102^Active: Suspended" Q
  1. D
  1. . ;--- Try to get status from the Taskman
  1. . S ZTSK=TASK D STAT^%ZTLOAD
  1. . S TMS=$S($G(ZTSK(0)):+$G(ZTSK(1)),1:0)
  1. . ;--- Pending or Available
  1. . I (TMS=1)!(TMS=4) S STATUS=TMS_U_$G(ZTSK(2)) Q
  1. . ;--- Running (actually, crashed ;-)
  1. . I TMS=2 S STATUS=100 Q
  1. . ;--- Finished, Interrupted or Undefined
  1. . I 'STATUS S:TMS STATUS=TMS_U_$G(ZTSK(2)) Q
  1. . ;--- If the task record is not locked and the STATUS field shows
  1. . ; 'Suspended' (102) then the task probably crashed while it
  1. . ;--- was in the suspended state
  1. . S:STATUS=102 STATUS=100
  1. ;--- Get the external value of the STATUS field (if necessary)
  1. I STATUS>0 D:$P(STATUS,U,2)=""
  1. . S $P(STATUS,U,2)=$$EXTERNAL^DILFD(798.8,2.01,,STATUS,"RORMSG")
  1. . S:$G(DIERR) STATUS=$$DBS^RORERR("RORMSG",-9,,,798.8)
  1. ;
  1. ;--- Unlock the task record
  1. L -@TASKNODE@("T",0)
  1. Q $TR(STATUS,">",":")
  1. ;
  1. ;***** RETURNS THE TASK INFORMATION
  1. ;
  1. ; TASK Task number
  1. ;
  1. ; .INFO Reference to a local variable (output):
  1. ;
  1. ; INFO(
  1. ; OFFSET+1) Task Number
  1. ; OFFSET+2) Task Type (internal^external)
  1. ; OFFSET+3) Registry (IEN^Name)
  1. ; OFFSET+4) Report (Code^Name)
  1. ; OFFSET+5) Description
  1. ; OFFSET+6) Task Status (internal^external)
  1. ; OFFSET+7) Creation Time (internal)
  1. ; OFFSET+8) User (DUZ^Name)
  1. ; OFFSET+9) Completion Time (internal)
  1. ; OFFSET+10) Progress Percentage
  1. ; OFFSET+11) Scheduled to Run at (internal)
  1. ; OFFSET+12) Task Log IEN
  1. ; OFFSET+13) Job Number
  1. ; OFFSET+14) User Comment
  1. ;
  1. ; [FLAGS] Characters controlling behavior of the function
  1. ; (they can be combined):
  1. ; E Return external values also (when applicable)
  1. ;
  1. ; [OFFSET] A number that is added to all subscripts in the
  1. ; destination array (by default, it is zero).
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. TASKINFO(TASK,INFO,FLAGS,OFFSET) ;
  1. N I,IENS,RORBUF,RORMSG,TMP
  1. S FLAGS=$$UP^XLFSTR($G(FLAGS))
  1. S OFFSET=$S($G(OFFSET)>0:+OFFSET,1:0)
  1. ;--- Clear the output array
  1. K:'OFFSET INFO S TMP=$$TIN
  1. F I=1:1:TMP S INFO(OFFSET+I)=""
  1. ;--- Get the task status
  1. S TMP=$$STATUS(TASK,,1) Q:TMP<0 TMP
  1. S INFO(OFFSET+1)=TASK
  1. S INFO(OFFSET+6)=$S(FLAGS["E":TMP,1:+TMP)
  1. ;--- Load the task record
  1. S IENS=TASK_",",I=$S(FLAGS["E":"EIN",1:"IN")
  1. S TMP=".02;.03;.04;.05;.07;.08;1.01;2.02;2.03;2.04;4"
  1. D GETS^DIQ(798.8,IENS,TMP,I,"RORBUF","RORMSG")
  1. I $G(DIERR) D Q RC
  1. . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
  1. ;--- Format the output array
  1. Q $$FRMTI^RORTSK03(OFFSET,.INFO,IENS,.RORBUF,FLAGS)
  1. ;
  1. ;***** RETURNS NUMBER OF NODES IN THE TASK INFORMATION ARRAY
  1. TIN() Q 14