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

RORTSK.m

Go to the documentation of this file.
  1. RORTSK ;HCIOFO/SG - TASK MANAGER ; 1/22/06 6:26pm
  1. ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
  1. ;
  1. Q
  1. ;
  1. ;***** CREATES AND SCHEDULES A TASK
  1. ;
  1. ; TYPE Type of the task (1 - Generic, 2 - Report)
  1. ;
  1. ; ZTRTN The entry point TaskMan will DO to start the task.
  1. ;
  1. ; This parameter can also have the $$TAG^ROUTINE
  1. ; format. In this case, the "proxy task" will be used.
  1. ; The value of the parameter will be saved in the
  1. ; RORTSK("EP") node and the "TASK^RORTSK01" will be
  1. ; assigned to the ZTRTN variable. See the TASK^RORTSK01
  1. ; for more details.
  1. ;
  1. ; [.PARAMS] Reference to a local variable that contains a list
  1. ; of name-value pairs of the task parameters.
  1. ; The parameters are passed to the task as sub-nodes
  1. ; of the "PARAMS" node of the RORTSK local variable.
  1. ;
  1. ; Examples:
  1. ;
  1. ; PARAMS("NUM")=10 ==> RORTSK("PARAMS","NUM")=10
  1. ; PARAMS("A(10)")="B" ==> RORTSK("PARAMS","A",10)="B"
  1. ;
  1. ; [REGIEN] Registry IEN (if $G(REGIEN)'>0 the task will not
  1. ; be associated with any particular registry).
  1. ;
  1. ; [REPORT] Code of the report (if the TYPE = 2).
  1. ;
  1. ; [SCHCODE] Rescheduling code for the task. By default (if
  1. ; $G(SCHCODE)=""), the task is executed once. See
  1. ; description of the $$SCH^XLFDT function for
  1. ; possible values of the parameter).
  1. ;
  1. ; [.RORTSKPP] Reference to a local variable that contains a task
  1. ; descriptor with already prepared task parameters
  1. ; (under the "PARAMS" subscript). These parameters
  1. ; are copied into the new task descriptor "as is".
  1. ;
  1. ; All other input variables used by the %ZTLOAD (except the ZTRTN)
  1. ; can be used to control the task. Modifications of the default
  1. ; behavior of some of those variables are described below.
  1. ;
  1. ; [ZTDESC] Task description
  1. ;
  1. ; [ZTDTH] Date/time to start the task (FileMan). By default
  1. ; (if $G(ZTDTH)=""), the task is scheduled to run
  1. ; with a 3 second delay.
  1. ;
  1. ; [ZTIO] Output device. By default (if $G(ZTIO)=""), the
  1. ; task is started without an output device.
  1. ;
  1. ; [ZTSAVE] List of variables that should be passed to the task.
  1. ; The CREATE^RORTSK function adds the "RORTSK(" item
  1. ; to the list if the task proxy is requested (see the
  1. ; ZTRTN parameter for details) or the PARAMS parameter
  1. ; is defined.
  1. ;
  1. ; Return values:
  1. ; <0 Error code
  1. ; >0 Task Number
  1. ;
  1. CREATE(TYPE,ZTRTN,PARAMS,REGIEN,REPORT,SCHCODE,RORTSKPP) ;
  1. N DESCR,IENS,RC,RORFDA,RORIEN,RORMSG,RORTSK,RPTIEN,TMP,ZTSK
  1. S (RC,RPTIEN)=0
  1. I $G(REGIEN)>0 D Q:RC<0 RC
  1. . I TYPE=2 D I RPTIEN<0 S RC=RPTIEN Q
  1. . . S RPTIEN=$$RPIEN^RORUTL08(REPORT,.DESCR)
  1. E S REGIEN=0
  1. ;--- Task parameters
  1. M RORTSK("PARAMS")=RORTSKPP("PARAMS")
  1. I $D(PARAMS)>1 D Q:RC<0 RC
  1. . S RC=$$PARAMS^RORTSK03(.PARAMS)
  1. . ;--- If there is the TASK_DESCR parameter in
  1. . ; the list use its value as the task description
  1. . ;--- (if the ZTDESC variable is not defined)
  1. . S TMP=$$PARAM^RORTSK01("TASK_DESCR")
  1. . S:TMP'="" DESCR=$E(TMP,1,200)
  1. ;--- Registry IEN
  1. D:'$D(RORTSK("PARAMS","REGIEN"))
  1. . S RORTSK("PARAMS","REGIEN")=+$G(REGIEN)
  1. ;--- Prepare the task description
  1. I $G(ZTDESC)="" D Q:RC<0 RC
  1. . I $G(DESCR)'="" S ZTDESC=DESCR Q
  1. . S DESCR=$$EXTERNAL^DILFD(798.8,.02,,TYPE,"RORMSG")
  1. . I $G(DIERR) D Q
  1. . . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8)
  1. . S (DESCR,ZTDESC)=DESCR_" Task started from the GUI"
  1. E S DESCR=ZTDESC
  1. S:$L(DESCR)>60 DESCR=$E(DESCR,1,57)_"..."
  1. ;--- Check if the task proxy should be used
  1. I $E(ZTRTN,1,2)="$$" D S ZTRTN="TASK^RORTSK01"
  1. . S RORTSK("EP")=ZTRTN Q:$G(SCHCODE)=""
  1. . F TMP="TYPE","REGIEN","REPORT","SCHCODE" D
  1. . . S RORTSK(TMP)=$G(@TMP)
  1. ;--- If the task is scheduled to run immediately, postpone the start
  1. ;--- for 3 seconds to make sure that the task record is created
  1. S TMP=$$NOW^XLFDT
  1. I $G(ZTDTH)>0,$$FMDIFF^XLFDT(ZTDTH,TMP,2)>3
  1. E S ZTDTH=$$FMADD^XLFDT(TMP,,,,3)
  1. ;--- Schedule the task
  1. S:'($D(ZTIO)#10) ZTIO=""
  1. S ZTSAVE("RORTSK(")=""
  1. D ^%ZTLOAD
  1. Q:'$G(ZTSK) $$ERROR^RORERR(-82,,,,ZTRTN,ZTDTH)
  1. S RORTSK=ZTSK
  1. ;--- Prepare data for the record in the ROR TASK file
  1. S IENS="+1,"
  1. S (RORFDA(798.8,IENS,.01),RORIEN(1))=RORTSK ; Task Number
  1. S RORFDA(798.8,IENS,.02)=+TYPE ; Type
  1. D:REGIEN>0
  1. . S RORFDA(798.8,IENS,.03)=+REGIEN ; Registry
  1. . S:RPTIEN RORFDA(798.8,IENS,.04)=RPTIEN ; IEN of report par.
  1. S RORFDA(798.8,IENS,.05)=DESCR ; Description
  1. S TMP=$$PARAM^RORTSK01("TASK_COMMENT")
  1. S:TMP'?." " RORFDA(798.8,IENS,1.01)=TMP ; Comment
  1. ;--- Create the record
  1. D UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
  1. I $G(DIERR) D Q RC
  1. . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
  1. . ;--- Try to unschedule the task if the record has not been created
  1. . S ZTSK=RORTSK D DQ^%ZTLOAD
  1. Q RORTSK
  1. ;
  1. ;***** DEQUEUES AND/OR DELETES THE TASK
  1. ;
  1. ; TASK Task number
  1. ;
  1. ; [DELETE] Delete the task from the Taskman and the task
  1. ; record from the ROR TASK file (#798.8) if this
  1. ; parameter has a non-zero value.
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ; 1 No responce from the task
  1. ;
  1. DEQUEUE(TASK,DELETE) ;
  1. N DA,DIK,I,RC,STATUS,TASKNODE,ZTSK
  1. S STATUS=+$$STATUS^RORTSK02(TASK,,1)
  1. I STATUS<0 Q $S(STATUS=-83:0,1:STATUS)
  1. S TASKNODE=$NA(^RORDATA(798.8,TASK))
  1. ;--- Unschedule the task
  1. I STATUS=1 S ZTSK=TASK D DQ^%ZTLOAD
  1. ;--- Stop the task if it is running
  1. S STATUS=+$$STATUS^RORTSK02(TASK)
  1. S:(STATUS=2)!(STATUS=102) @TASKNODE@("A")=2
  1. Q:'$G(DELETE) 0
  1. ;--- Wait for a response from the task
  1. S STATUS=+$$STATUS^RORTSK02(TASK,3) Q:STATUS<0 STATUS
  1. Q:STATUS=103 1
  1. ;--- Kill the REPORT ELEMENT multiple to avoid delays in ^DIK
  1. K @TASKNODE@("RI")
  1. ;--- Delete the task record
  1. S DIK="^RORDATA(798.8,",DA=TASK D ^DIK
  1. Q 0
  1. ;
  1. ;***** RESUMES THE TASK
  1. ;
  1. ; TASK Task number
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. RESUME(TASK) ;
  1. N STATUS
  1. S STATUS=+$$STATUS^RORTSK02(TASK,,1) Q:STATUS<0 STATUS
  1. K ^RORDATA(798.8,TASK,"A")
  1. Q 0
  1. ;
  1. ;***** SUSPENDS THE TASK
  1. ;
  1. ; TASK Task number
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. SUSPEND(TASK) ;
  1. N STATUS
  1. S STATUS=+$$STATUS^RORTSK02(TASK,,1) Q:STATUS<0 STATUS
  1. S:(STATUS=1)!(STATUS=2) ^RORDATA(798.8,TASK,"A")=1
  1. Q 0