source: FOIAVistA/trunk/r/CLINICAL_CASE_REGISTRIES-ROR/RORTSK.m@ 996

Last change on this file since 996 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 6.5 KB
Line 
1RORTSK ;HCIOFO/SG - TASK MANAGER ; 1/22/06 6:26pm
2 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
3 ;
4 Q
5 ;
6 ;***** CREATES AND SCHEDULES A TASK
7 ;
8 ; TYPE Type of the task (1 - Generic, 2 - Report)
9 ;
10 ; ZTRTN The entry point TaskMan will DO to start the task.
11 ;
12 ; This parameter can also have the $$TAG^ROUTINE
13 ; format. In this case, the "proxy task" will be used.
14 ; The value of the parameter will be saved in the
15 ; RORTSK("EP") node and the "TASK^RORTSK01" will be
16 ; assigned to the ZTRTN variable. See the TASK^RORTSK01
17 ; for more details.
18 ;
19 ; [.PARAMS] Reference to a local variable that contains a list
20 ; of name-value pairs of the task parameters.
21 ; The parameters are passed to the task as sub-nodes
22 ; of the "PARAMS" node of the RORTSK local variable.
23 ;
24 ; Examples:
25 ;
26 ; PARAMS("NUM")=10 ==> RORTSK("PARAMS","NUM")=10
27 ; PARAMS("A(10)")="B" ==> RORTSK("PARAMS","A",10)="B"
28 ;
29 ; [REGIEN] Registry IEN (if $G(REGIEN)'>0 the task will not
30 ; be associated with any particular registry).
31 ;
32 ; [REPORT] Code of the report (if the TYPE = 2).
33 ;
34 ; [SCHCODE] Rescheduling code for the task. By default (if
35 ; $G(SCHCODE)=""), the task is executed once. See
36 ; description of the $$SCH^XLFDT function for
37 ; possible values of the parameter).
38 ;
39 ; [.RORTSKPP] Reference to a local variable that contains a task
40 ; descriptor with already prepared task parameters
41 ; (under the "PARAMS" subscript). These parameters
42 ; are copied into the new task descriptor "as is".
43 ;
44 ; All other input variables used by the %ZTLOAD (except the ZTRTN)
45 ; can be used to control the task. Modifications of the default
46 ; behavior of some of those variables are described below.
47 ;
48 ; [ZTDESC] Task description
49 ;
50 ; [ZTDTH] Date/time to start the task (FileMan). By default
51 ; (if $G(ZTDTH)=""), the task is scheduled to run
52 ; with a 3 second delay.
53 ;
54 ; [ZTIO] Output device. By default (if $G(ZTIO)=""), the
55 ; task is started without an output device.
56 ;
57 ; [ZTSAVE] List of variables that should be passed to the task.
58 ; The CREATE^RORTSK function adds the "RORTSK(" item
59 ; to the list if the task proxy is requested (see the
60 ; ZTRTN parameter for details) or the PARAMS parameter
61 ; is defined.
62 ;
63 ; Return values:
64 ; <0 Error code
65 ; >0 Task Number
66 ;
67CREATE(TYPE,ZTRTN,PARAMS,REGIEN,REPORT,SCHCODE,RORTSKPP) ;
68 N DESCR,IENS,RC,RORFDA,RORIEN,RORMSG,RORTSK,RPTIEN,TMP,ZTSK
69 S (RC,RPTIEN)=0
70 I $G(REGIEN)>0 D Q:RC<0 RC
71 . I TYPE=2 D I RPTIEN<0 S RC=RPTIEN Q
72 . . S RPTIEN=$$RPIEN^RORUTL08(REPORT,.DESCR)
73 E S REGIEN=0
74 ;--- Task parameters
75 M RORTSK("PARAMS")=RORTSKPP("PARAMS")
76 I $D(PARAMS)>1 D Q:RC<0 RC
77 . S RC=$$PARAMS^RORTSK03(.PARAMS)
78 . ;--- If there is the TASK_DESCR parameter in
79 . ; the list use its value as the task description
80 . ;--- (if the ZTDESC variable is not defined)
81 . S TMP=$$PARAM^RORTSK01("TASK_DESCR")
82 . S:TMP'="" DESCR=$E(TMP,1,200)
83 ;--- Registry IEN
84 D:'$D(RORTSK("PARAMS","REGIEN"))
85 . S RORTSK("PARAMS","REGIEN")=+$G(REGIEN)
86 ;--- Prepare the task description
87 I $G(ZTDESC)="" D Q:RC<0 RC
88 . I $G(DESCR)'="" S ZTDESC=DESCR Q
89 . S DESCR=$$EXTERNAL^DILFD(798.8,.02,,TYPE,"RORMSG")
90 . I $G(DIERR) D Q
91 . . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8)
92 . S (DESCR,ZTDESC)=DESCR_" Task started from the GUI"
93 E S DESCR=ZTDESC
94 S:$L(DESCR)>60 DESCR=$E(DESCR,1,57)_"..."
95 ;--- Check if the task proxy should be used
96 I $E(ZTRTN,1,2)="$$" D S ZTRTN="TASK^RORTSK01"
97 . S RORTSK("EP")=ZTRTN Q:$G(SCHCODE)=""
98 . F TMP="TYPE","REGIEN","REPORT","SCHCODE" D
99 . . S RORTSK(TMP)=$G(@TMP)
100 ;--- If the task is scheduled to run immediately, postpone the start
101 ;--- for 3 seconds to make sure that the task record is created
102 S TMP=$$NOW^XLFDT
103 I $G(ZTDTH)>0,$$FMDIFF^XLFDT(ZTDTH,TMP,2)>3
104 E S ZTDTH=$$FMADD^XLFDT(TMP,,,,3)
105 ;--- Schedule the task
106 S:'($D(ZTIO)#10) ZTIO=""
107 S ZTSAVE("RORTSK(")=""
108 D ^%ZTLOAD
109 Q:'$G(ZTSK) $$ERROR^RORERR(-82,,,,ZTRTN,ZTDTH)
110 S RORTSK=ZTSK
111 ;--- Prepare data for the record in the ROR TASK file
112 S IENS="+1,"
113 S (RORFDA(798.8,IENS,.01),RORIEN(1))=RORTSK ; Task Number
114 S RORFDA(798.8,IENS,.02)=+TYPE ; Type
115 D:REGIEN>0
116 . S RORFDA(798.8,IENS,.03)=+REGIEN ; Registry
117 . S:RPTIEN RORFDA(798.8,IENS,.04)=RPTIEN ; IEN of report par.
118 S RORFDA(798.8,IENS,.05)=DESCR ; Description
119 S TMP=$$PARAM^RORTSK01("TASK_COMMENT")
120 S:TMP'?." " RORFDA(798.8,IENS,1.01)=TMP ; Comment
121 ;--- Create the record
122 D UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
123 I $G(DIERR) D Q RC
124 . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
125 . ;--- Try to unschedule the task if the record has not been created
126 . S ZTSK=RORTSK D DQ^%ZTLOAD
127 Q RORTSK
128 ;
129 ;***** DEQUEUES AND/OR DELETES THE TASK
130 ;
131 ; TASK Task number
132 ;
133 ; [DELETE] Delete the task from the Taskman and the task
134 ; record from the ROR TASK file (#798.8) if this
135 ; parameter has a non-zero value.
136 ;
137 ; Return Values:
138 ; <0 Error code
139 ; 0 Ok
140 ; 1 No responce from the task
141 ;
142DEQUEUE(TASK,DELETE) ;
143 N DA,DIK,I,RC,STATUS,TASKNODE,ZTSK
144 S STATUS=+$$STATUS^RORTSK02(TASK,,1)
145 I STATUS<0 Q $S(STATUS=-83:0,1:STATUS)
146 S TASKNODE=$NA(^RORDATA(798.8,TASK))
147 ;--- Unschedule the task
148 I STATUS=1 S ZTSK=TASK D DQ^%ZTLOAD
149 ;--- Stop the task if it is running
150 S STATUS=+$$STATUS^RORTSK02(TASK)
151 S:(STATUS=2)!(STATUS=102) @TASKNODE@("A")=2
152 Q:'$G(DELETE) 0
153 ;--- Wait for a response from the task
154 S STATUS=+$$STATUS^RORTSK02(TASK,3) Q:STATUS<0 STATUS
155 Q:STATUS=103 1
156 ;--- Kill the REPORT ELEMENT multiple to avoid delays in ^DIK
157 K @TASKNODE@("RI")
158 ;--- Delete the task record
159 S DIK="^RORDATA(798.8,",DA=TASK D ^DIK
160 Q 0
161 ;
162 ;***** RESUMES THE TASK
163 ;
164 ; TASK Task number
165 ;
166 ; Return Values:
167 ; <0 Error code
168 ; 0 Ok
169 ;
170RESUME(TASK) ;
171 N STATUS
172 S STATUS=+$$STATUS^RORTSK02(TASK,,1) Q:STATUS<0 STATUS
173 K ^RORDATA(798.8,TASK,"A")
174 Q 0
175 ;
176 ;***** SUSPENDS THE TASK
177 ;
178 ; TASK Task number
179 ;
180 ; Return Values:
181 ; <0 Error code
182 ; 0 Ok
183 ;
184SUSPEND(TASK) ;
185 N STATUS
186 S STATUS=+$$STATUS^RORTSK02(TASK,,1) Q:STATUS<0 STATUS
187 S:(STATUS=1)!(STATUS=2) ^RORDATA(798.8,TASK,"A")=1
188 Q 0
Note: See TracBrowser for help on using the repository browser.