- RORTSK ;HCIOFO/SG - TASK MANAGER ; 1/22/06 6:26pm
- ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
- ;
- Q
- ;
- ;***** CREATES AND SCHEDULES A TASK
- ;
- ; TYPE Type of the task (1 - Generic, 2 - Report)
- ;
- ; ZTRTN The entry point TaskMan will DO to start the task.
- ;
- ; This parameter can also have the $$TAG^ROUTINE
- ; format. In this case, the "proxy task" will be used.
- ; The value of the parameter will be saved in the
- ; RORTSK("EP") node and the "TASK^RORTSK01" will be
- ; assigned to the ZTRTN variable. See the TASK^RORTSK01
- ; for more details.
- ;
- ; [.PARAMS] Reference to a local variable that contains a list
- ; of name-value pairs of the task parameters.
- ; The parameters are passed to the task as sub-nodes
- ; of the "PARAMS" node of the RORTSK local variable.
- ;
- ; Examples:
- ;
- ; PARAMS("NUM")=10 ==> RORTSK("PARAMS","NUM")=10
- ; PARAMS("A(10)")="B" ==> RORTSK("PARAMS","A",10)="B"
- ;
- ; [REGIEN] Registry IEN (if $G(REGIEN)'>0 the task will not
- ; be associated with any particular registry).
- ;
- ; [REPORT] Code of the report (if the TYPE = 2).
- ;
- ; [SCHCODE] Rescheduling code for the task. By default (if
- ; $G(SCHCODE)=""), the task is executed once. See
- ; description of the $$SCH^XLFDT function for
- ; possible values of the parameter).
- ;
- ; [.RORTSKPP] Reference to a local variable that contains a task
- ; descriptor with already prepared task parameters
- ; (under the "PARAMS" subscript). These parameters
- ; are copied into the new task descriptor "as is".
- ;
- ; All other input variables used by the %ZTLOAD (except the ZTRTN)
- ; can be used to control the task. Modifications of the default
- ; behavior of some of those variables are described below.
- ;
- ; [ZTDESC] Task description
- ;
- ; [ZTDTH] Date/time to start the task (FileMan). By default
- ; (if $G(ZTDTH)=""), the task is scheduled to run
- ; with a 3 second delay.
- ;
- ; [ZTIO] Output device. By default (if $G(ZTIO)=""), the
- ; task is started without an output device.
- ;
- ; [ZTSAVE] List of variables that should be passed to the task.
- ; The CREATE^RORTSK function adds the "RORTSK(" item
- ; to the list if the task proxy is requested (see the
- ; ZTRTN parameter for details) or the PARAMS parameter
- ; is defined.
- ;
- ; Return values:
- ; <0 Error code
- ; >0 Task Number
- ;
- CREATE(TYPE,ZTRTN,PARAMS,REGIEN,REPORT,SCHCODE,RORTSKPP) ;
- N DESCR,IENS,RC,RORFDA,RORIEN,RORMSG,RORTSK,RPTIEN,TMP,ZTSK
- S (RC,RPTIEN)=0
- I $G(REGIEN)>0 D Q:RC<0 RC
- . I TYPE=2 D I RPTIEN<0 S RC=RPTIEN Q
- . . S RPTIEN=$$RPIEN^RORUTL08(REPORT,.DESCR)
- E S REGIEN=0
- ;--- Task parameters
- M RORTSK("PARAMS")=RORTSKPP("PARAMS")
- I $D(PARAMS)>1 D Q:RC<0 RC
- . S RC=$$PARAMS^RORTSK03(.PARAMS)
- . ;--- If there is the TASK_DESCR parameter in
- . ; the list use its value as the task description
- . ;--- (if the ZTDESC variable is not defined)
- . S TMP=$$PARAM^RORTSK01("TASK_DESCR")
- . S:TMP'="" DESCR=$E(TMP,1,200)
- ;--- Registry IEN
- D:'$D(RORTSK("PARAMS","REGIEN"))
- . S RORTSK("PARAMS","REGIEN")=+$G(REGIEN)
- ;--- Prepare the task description
- I $G(ZTDESC)="" D Q:RC<0 RC
- . I $G(DESCR)'="" S ZTDESC=DESCR Q
- . S DESCR=$$EXTERNAL^DILFD(798.8,.02,,TYPE,"RORMSG")
- . I $G(DIERR) D Q
- . . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8)
- . S (DESCR,ZTDESC)=DESCR_" Task started from the GUI"
- E S DESCR=ZTDESC
- S:$L(DESCR)>60 DESCR=$E(DESCR,1,57)_"..."
- ;--- Check if the task proxy should be used
- I $E(ZTRTN,1,2)="$$" D S ZTRTN="TASK^RORTSK01"
- . S RORTSK("EP")=ZTRTN Q:$G(SCHCODE)=""
- . F TMP="TYPE","REGIEN","REPORT","SCHCODE" D
- . . S RORTSK(TMP)=$G(@TMP)
- ;--- If the task is scheduled to run immediately, postpone the start
- ;--- for 3 seconds to make sure that the task record is created
- S TMP=$$NOW^XLFDT
- I $G(ZTDTH)>0,$$FMDIFF^XLFDT(ZTDTH,TMP,2)>3
- E S ZTDTH=$$FMADD^XLFDT(TMP,,,,3)
- ;--- Schedule the task
- S:'($D(ZTIO)#10) ZTIO=""
- S ZTSAVE("RORTSK(")=""
- D ^%ZTLOAD
- Q:'$G(ZTSK) $$ERROR^RORERR(-82,,,,ZTRTN,ZTDTH)
- S RORTSK=ZTSK
- ;--- Prepare data for the record in the ROR TASK file
- S IENS="+1,"
- S (RORFDA(798.8,IENS,.01),RORIEN(1))=RORTSK ; Task Number
- S RORFDA(798.8,IENS,.02)=+TYPE ; Type
- D:REGIEN>0
- . S RORFDA(798.8,IENS,.03)=+REGIEN ; Registry
- . S:RPTIEN RORFDA(798.8,IENS,.04)=RPTIEN ; IEN of report par.
- S RORFDA(798.8,IENS,.05)=DESCR ; Description
- S TMP=$$PARAM^RORTSK01("TASK_COMMENT")
- S:TMP'?." " RORFDA(798.8,IENS,1.01)=TMP ; Comment
- ;--- Create the record
- D UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
- I $G(DIERR) D Q RC
- . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
- . ;--- Try to unschedule the task if the record has not been created
- . S ZTSK=RORTSK D DQ^%ZTLOAD
- Q RORTSK
- ;
- ;***** DEQUEUES AND/OR DELETES THE TASK
- ;
- ; TASK Task number
- ;
- ; [DELETE] Delete the task from the Taskman and the task
- ; record from the ROR TASK file (#798.8) if this
- ; parameter has a non-zero value.
- ;
- ; Return Values:
- ; <0 Error code
- ; 0 Ok
- ; 1 No responce from the task
- ;
- DEQUEUE(TASK,DELETE) ;
- N DA,DIK,I,RC,STATUS,TASKNODE,ZTSK
- S STATUS=+$$STATUS^RORTSK02(TASK,,1)
- I STATUS<0 Q $S(STATUS=-83:0,1:STATUS)
- S TASKNODE=$NA(^RORDATA(798.8,TASK))
- ;--- Unschedule the task
- I STATUS=1 S ZTSK=TASK D DQ^%ZTLOAD
- ;--- Stop the task if it is running
- S STATUS=+$$STATUS^RORTSK02(TASK)
- S:(STATUS=2)!(STATUS=102) @TASKNODE@("A")=2
- Q:'$G(DELETE) 0
- ;--- Wait for a response from the task
- S STATUS=+$$STATUS^RORTSK02(TASK,3) Q:STATUS<0 STATUS
- Q:STATUS=103 1
- ;--- Kill the REPORT ELEMENT multiple to avoid delays in ^DIK
- K @TASKNODE@("RI")
- ;--- Delete the task record
- S DIK="^RORDATA(798.8,",DA=TASK D ^DIK
- Q 0
- ;
- ;***** RESUMES THE TASK
- ;
- ; TASK Task number
- ;
- ; Return Values:
- ; <0 Error code
- ; 0 Ok
- ;
- RESUME(TASK) ;
- N STATUS
- S STATUS=+$$STATUS^RORTSK02(TASK,,1) Q:STATUS<0 STATUS
- K ^RORDATA(798.8,TASK,"A")
- Q 0
- ;
- ;***** SUSPENDS THE TASK
- ;
- ; TASK Task number
- ;
- ; Return Values:
- ; <0 Error code
- ; 0 Ok
- ;
- SUSPEND(TASK) ;
- N STATUS
- S STATUS=+$$STATUS^RORTSK02(TASK,,1) Q:STATUS<0 STATUS
- S:(STATUS=1)!(STATUS=2) ^RORDATA(798.8,TASK,"A")=1
- Q 0
- --- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORTSK 6793 printed Feb 18, 2025@23:09:51 Page 2
- RORTSK ;HCIOFO/SG - TASK MANAGER ; 1/22/06 6:26pm
- +1 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
- +2 ;
- +3 QUIT
- +4 ;
- +5 ;***** CREATES AND SCHEDULES A TASK
- +6 ;
- +7 ; TYPE Type of the task (1 - Generic, 2 - Report)
- +8 ;
- +9 ; ZTRTN The entry point TaskMan will DO to start the task.
- +10 ;
- +11 ; This parameter can also have the $$TAG^ROUTINE
- +12 ; format. In this case, the "proxy task" will be used.
- +13 ; The value of the parameter will be saved in the
- +14 ; RORTSK("EP") node and the "TASK^RORTSK01" will be
- +15 ; assigned to the ZTRTN variable. See the TASK^RORTSK01
- +16 ; for more details.
- +17 ;
- +18 ; [.PARAMS] Reference to a local variable that contains a list
- +19 ; of name-value pairs of the task parameters.
- +20 ; The parameters are passed to the task as sub-nodes
- +21 ; of the "PARAMS" node of the RORTSK local variable.
- +22 ;
- +23 ; Examples:
- +24 ;
- +25 ; PARAMS("NUM")=10 ==> RORTSK("PARAMS","NUM")=10
- +26 ; PARAMS("A(10)")="B" ==> RORTSK("PARAMS","A",10)="B"
- +27 ;
- +28 ; [REGIEN] Registry IEN (if $G(REGIEN)'>0 the task will not
- +29 ; be associated with any particular registry).
- +30 ;
- +31 ; [REPORT] Code of the report (if the TYPE = 2).
- +32 ;
- +33 ; [SCHCODE] Rescheduling code for the task. By default (if
- +34 ; $G(SCHCODE)=""), the task is executed once. See
- +35 ; description of the $$SCH^XLFDT function for
- +36 ; possible values of the parameter).
- +37 ;
- +38 ; [.RORTSKPP] Reference to a local variable that contains a task
- +39 ; descriptor with already prepared task parameters
- +40 ; (under the "PARAMS" subscript). These parameters
- +41 ; are copied into the new task descriptor "as is".
- +42 ;
- +43 ; All other input variables used by the %ZTLOAD (except the ZTRTN)
- +44 ; can be used to control the task. Modifications of the default
- +45 ; behavior of some of those variables are described below.
- +46 ;
- +47 ; [ZTDESC] Task description
- +48 ;
- +49 ; [ZTDTH] Date/time to start the task (FileMan). By default
- +50 ; (if $G(ZTDTH)=""), the task is scheduled to run
- +51 ; with a 3 second delay.
- +52 ;
- +53 ; [ZTIO] Output device. By default (if $G(ZTIO)=""), the
- +54 ; task is started without an output device.
- +55 ;
- +56 ; [ZTSAVE] List of variables that should be passed to the task.
- +57 ; The CREATE^RORTSK function adds the "RORTSK(" item
- +58 ; to the list if the task proxy is requested (see the
- +59 ; ZTRTN parameter for details) or the PARAMS parameter
- +60 ; is defined.
- +61 ;
- +62 ; Return values:
- +63 ; <0 Error code
- +64 ; >0 Task Number
- +65 ;
- CREATE(TYPE,ZTRTN,PARAMS,REGIEN,REPORT,SCHCODE,RORTSKPP) ;
- +1 NEW DESCR,IENS,RC,RORFDA,RORIEN,RORMSG,RORTSK,RPTIEN,TMP,ZTSK
- +2 SET (RC,RPTIEN)=0
- +3 IF $GET(REGIEN)>0
- Begin DoDot:1
- +4 IF TYPE=2
- Begin DoDot:2
- +5 SET RPTIEN=$$RPIEN^RORUTL08(REPORT,.DESCR)
- End DoDot:2
- IF RPTIEN<0
- SET RC=RPTIEN
- QUIT
- End DoDot:1
- if RC<0
- QUIT RC
- +6 IF '$TEST
- SET REGIEN=0
- +7 ;--- Task parameters
- +8 MERGE RORTSK("PARAMS")=RORTSKPP("PARAMS")
- +9 IF $DATA(PARAMS)>1
- Begin DoDot:1
- +10 SET RC=$$PARAMS^RORTSK03(.PARAMS)
- +11 ;--- If there is the TASK_DESCR parameter in
- +12 ; the list use its value as the task description
- +13 ;--- (if the ZTDESC variable is not defined)
- +14 SET TMP=$$PARAM^RORTSK01("TASK_DESCR")
- +15 if TMP'=""
- SET DESCR=$EXTRACT(TMP,1,200)
- End DoDot:1
- if RC<0
- QUIT RC
- +16 ;--- Registry IEN
- +17 if '$DATA(RORTSK("PARAMS","REGIEN"))
- Begin DoDot:1
- +18 SET RORTSK("PARAMS","REGIEN")=+$GET(REGIEN)
- End DoDot:1
- +19 ;--- Prepare the task description
- +20 IF $GET(ZTDESC)=""
- Begin DoDot:1
- +21 IF $GET(DESCR)'=""
- SET ZTDESC=DESCR
- QUIT
- +22 SET DESCR=$$EXTERNAL^DILFD(798.8,.02,,TYPE,"RORMSG")
- +23 IF $GET(DIERR)
- Begin DoDot:2
- +24 SET RC=$$DBS^RORERR("RORMSG",-9,,,798.8)
- End DoDot:2
- QUIT
- +25 SET (DESCR,ZTDESC)=DESCR_" Task started from the GUI"
- End DoDot:1
- if RC<0
- QUIT RC
- +26 IF '$TEST
- SET DESCR=ZTDESC
- +27 if $LENGTH(DESCR)>60
- SET DESCR=$EXTRACT(DESCR,1,57)_"..."
- +28 ;--- Check if the task proxy should be used
- +29 IF $EXTRACT(ZTRTN,1,2)="$$"
- Begin DoDot:1
- +30 SET RORTSK("EP")=ZTRTN
- if $GET(SCHCODE)=""
- QUIT
- +31 FOR TMP="TYPE","REGIEN","REPORT","SCHCODE"
- Begin DoDot:2
- +32 SET RORTSK(TMP)=$GET(@TMP)
- End DoDot:2
- End DoDot:1
- SET ZTRTN="TASK^RORTSK01"
- +33 ;--- If the task is scheduled to run immediately, postpone the start
- +34 ;--- for 3 seconds to make sure that the task record is created
- +35 SET TMP=$$NOW^XLFDT
- +36 IF $GET(ZTDTH)>0
- IF $$FMDIFF^XLFDT(ZTDTH,TMP,2)>3
- +37 IF '$TEST
- SET ZTDTH=$$FMADD^XLFDT(TMP,,,,3)
- +38 ;--- Schedule the task
- +39 if '($DATA(ZTIO)#10)
- SET ZTIO=""
- +40 SET ZTSAVE("RORTSK(")=""
- +41 DO ^%ZTLOAD
- +42 if '$GET(ZTSK)
- QUIT $$ERROR^RORERR(-82,,,,ZTRTN,ZTDTH)
- +43 SET RORTSK=ZTSK
- +44 ;--- Prepare data for the record in the ROR TASK file
- +45 SET IENS="+1,"
- +46 ; Task Number
- SET (RORFDA(798.8,IENS,.01),RORIEN(1))=RORTSK
- +47 ; Type
- SET RORFDA(798.8,IENS,.02)=+TYPE
- +48 if REGIEN>0
- Begin DoDot:1
- +49 ; Registry
- SET RORFDA(798.8,IENS,.03)=+REGIEN
- +50 ; IEN of report par.
- if RPTIEN
- SET RORFDA(798.8,IENS,.04)=RPTIEN
- End DoDot:1
- +51 ; Description
- SET RORFDA(798.8,IENS,.05)=DESCR
- +52 SET TMP=$$PARAM^RORTSK01("TASK_COMMENT")
- +53 ; Comment
- if TMP'?." "
- SET RORFDA(798.8,IENS,1.01)=TMP
- +54 ;--- Create the record
- +55 DO UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
- +56 IF $GET(DIERR)
- Begin DoDot:1
- +57 SET RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
- +58 ;--- Try to unschedule the task if the record has not been created
- +59 SET ZTSK=RORTSK
- DO DQ^%ZTLOAD
- End DoDot:1
- QUIT RC
- +60 QUIT RORTSK
- +61 ;
- +62 ;***** DEQUEUES AND/OR DELETES THE TASK
- +63 ;
- +64 ; TASK Task number
- +65 ;
- +66 ; [DELETE] Delete the task from the Taskman and the task
- +67 ; record from the ROR TASK file (#798.8) if this
- +68 ; parameter has a non-zero value.
- +69 ;
- +70 ; Return Values:
- +71 ; <0 Error code
- +72 ; 0 Ok
- +73 ; 1 No responce from the task
- +74 ;
- DEQUEUE(TASK,DELETE) ;
- +1 NEW DA,DIK,I,RC,STATUS,TASKNODE,ZTSK
- +2 SET STATUS=+$$STATUS^RORTSK02(TASK,,1)
- +3 IF STATUS<0
- QUIT $SELECT(STATUS=-83:0,1:STATUS)
- +4 SET TASKNODE=$NAME(^RORDATA(798.8,TASK))
- +5 ;--- Unschedule the task
- +6 IF STATUS=1
- SET ZTSK=TASK
- DO DQ^%ZTLOAD
- +7 ;--- Stop the task if it is running
- +8 SET STATUS=+$$STATUS^RORTSK02(TASK)
- +9 if (STATUS=2)!(STATUS=102)
- SET @TASKNODE@("A")=2
- +10 if '$GET(DELETE)
- QUIT 0
- +11 ;--- Wait for a response from the task
- +12 SET STATUS=+$$STATUS^RORTSK02(TASK,3)
- if STATUS<0
- QUIT STATUS
- +13 if STATUS=103
- QUIT 1
- +14 ;--- Kill the REPORT ELEMENT multiple to avoid delays in ^DIK
- +15 KILL @TASKNODE@("RI")
- +16 ;--- Delete the task record
- +17 SET DIK="^RORDATA(798.8,"
- SET DA=TASK
- DO ^DIK
- +18 QUIT 0
- +19 ;
- +20 ;***** RESUMES THE TASK
- +21 ;
- +22 ; TASK Task number
- +23 ;
- +24 ; Return Values:
- +25 ; <0 Error code
- +26 ; 0 Ok
- +27 ;
- RESUME(TASK) ;
- +1 NEW STATUS
- +2 SET STATUS=+$$STATUS^RORTSK02(TASK,,1)
- if STATUS<0
- QUIT STATUS
- +3 KILL ^RORDATA(798.8,TASK,"A")
- +4 QUIT 0
- +5 ;
- +6 ;***** SUSPENDS THE TASK
- +7 ;
- +8 ; TASK Task number
- +9 ;
- +10 ; Return Values:
- +11 ; <0 Error code
- +12 ; 0 Ok
- +13 ;
- SUSPEND(TASK) ;
- +1 NEW STATUS
- +2 SET STATUS=+$$STATUS^RORTSK02(TASK,,1)
- if STATUS<0
- QUIT STATUS
- +3 if (STATUS=1)!(STATUS=2)
- SET ^RORDATA(798.8,TASK,"A")=1
- +4 QUIT 0