source: FOIAVistA/trunk/r/CLINICAL_CASE_REGISTRIES-ROR/RORTSK02.m@ 1611

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

initial load of FOIAVistA 6/30/08 version

File size: 6.8 KB
Line 
1RORTSK02 ;HCIOFO/SG - TASK MANAGER UTILITIES ; 1/23/06 8:11am
2 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
3 ;
4 Q
5 ;
6 ;***** RETURNS A LIST OF USER'S TASKS
7 ;
8 ; .TASKLIST Reference to a local array that the task
9 ; list is returned to
10 ;
11 ; [REGIEN] Registry IEN
12 ;
13 ; [TYPE] Type of the task (1 - Generic, 2 - Report)
14 ;
15 ; [.FROM] Where to start/continue the list generation.
16 ; By defualt (if $G(FROM)'>0), the extraction starts
17 ; from the beginning of the user's task list.
18 ;
19 ; NOTE: The task, which number is passed via this
20 ; parameter, is not included in the report.
21 ;
22 ; After the call, this parameter contains the last
23 ; extracted task number or an empty string if there
24 ; are no more tasks.
25 ;
26 ; [NUMBER] Maximum number of tasks returned by the function.
27 ; By default (if $G(NUMBER)'>0), all task numbers
28 ; (starting from the point indicated by the FROM
29 ; parameter if it is defined) are retrieved.
30 ;
31 ; [USER] A user IEN (DUZ). By default (if $G(USER)'>0),
32 ; the curent user's DUZ is used.
33 ;
34 ; Return values:
35 ; <0 Error code
36 ; 0 No tasks have been found
37 ; >0 Number of tasks
38 ;
39LIST(TASKLIST,REGIEN,TYPE,FROM,NUMBER,USER) ;
40 N DIR,NTSK,RC,ROOT,RORBUF,SCR,TASK K TASKLIST
41 S ROOT=$$ROOT^DILFD(798.8,,1)
42 S USER=$S($G(USER)>0:+USER,1:+$G(DUZ))
43 S DIR=$S($$UP^XLFSTR($G(NUMBER))["B":-1,1:1)
44 S NUMBER=$S($G(NUMBER)>0:+NUMBER,1:999999)
45 ;--- Generate a screen logic
46 S SCR="I 1"
47 S:$G(REGIEN)>0 SCR=SCR_","_"$P(RORBUF,U,3)="_(+REGIEN)
48 S:$G(TYPE)>0 SCR=SCR_","_"$P(RORBUF,U,2)="_(+TYPE)
49 ;--- Generate the output list
50 S TASK=$S($G(FROM)>0:FROM,1:""),NTSK=0
51 F S TASK=$O(@ROOT@("U",USER,TASK),DIR) Q:TASK="" D Q:NTSK'<NUMBER
52 . S RORBUF=$G(@ROOT@(TASK,0)) X SCR E Q
53 . S NTSK=NTSK+1,TASKLIST(TASK)=""
54 S FROM=TASK
55 Q NTSK
56 ;
57 ;***** PURGES THE OLD TASKS
58 ;
59 ; [DKEEP] Days to keep the old tasks (by default = 15)
60 ;
61 ; Return Values:
62 ; <0 Error code
63 ; 0 Ok
64 ;
65PURGE(DKEEP) ;
66 N DA,DATE,DIK,FROM,RC,STATUS,TASK,TASKINFO
67 S ROOT=$$ROOT^DILFD(798.8,,1),DIK=$$OREF^DILF(ROOT)
68 S FROM=$$FMADD^XLFDT($$DT^XLFDT,1-$G(DKEEP,15))
69 ;---
70 S DATE=FROM,RC=0
71 F S DATE=$O(@ROOT@("ACDT",DATE),-1) Q:DATE="" D
72 . S TASK=""
73 . F S TASK=$O(@ROOT@("ACDT",DATE,TASK),-1) Q:TASK="" D
74 . . Q:$$TASKINFO(TASK,.TASKINFO)<0
75 . . S STATUS=+TASKINFO(6)
76 . . ;--- Do not delete pending, running and suspended tasks
77 . . Q:(STATUS=1)!(STATUS=2)!(STATUS=102)
78 . . ;--- If task is completed, use its completion
79 . . ;--- date instead of the creation date
80 . . I TASKINFO(9)>DATE Q:TASKINFO(9)'<FROM
81 . . ;--- Delete the record
82 . . S DA=TASK D ^DIK
83 ;---
84 Q $S(RC<0:RC,1:0)
85 ;
86 ;***** RETURNS STATUS OF THE TASK
87 ;
88 ; TASK Task number
89 ; [LTO] LOCK timeout (0 by default)
90 ; [UNDEF83] Return the error -83 if there is no task record.
91 ; By default (if +$G(UNDEF83)=0), zero is returned.
92 ;
93 ; Return Values:
94 ; <0 Error code
95 ; 0 Undefined task/Unknown Status
96 ; >0 Status (Code^Description)
97 ;
98 ; 1 Active: Pending
99 ; 2 Active: Running
100 ; 3 Inactive: Finished
101 ; 4 Inactive: Available
102 ; 5 Inactive: Interrupted
103 ;
104 ; 100 Inactive: Crashed
105 ; 101 Inactive: Errors
106 ; 102 Active: Suspended
107 ; 103 Active: Stopping
108 ;
109STATUS(TASK,LTO,UNDEF83) ;
110 N ACTION,IENS,RORBUF,RORMSG,STATUS,TASKNODE,TMS,ZTSK
111 Q:TASK'>0 $$ERROR^RORERR(-85,,,,TASK)
112 S TASKNODE=$NA(^RORDATA(798.8,TASK))
113 Q:'$D(@TASKNODE) $S($G(UNDEF83):-83,1:0)
114 ;--- Get internal value of the STATUS field (2.01)
115 S STATUS=+$G(@TASKNODE@(2))
116 ;--- Lock the record and check if the task is running
117 L +@TASKNODE@("T",0):$G(LTO,0)
118 E S TMS="" D Q:TMS'="" TMS
119 . S ACTION=+$G(@TASKNODE@("A"))
120 . I ACTION=2 S TMS="103^Active: Stopping" Q
121 . I STATUS=100 S TMS="2^Active: Running" Q
122 . I STATUS=102 S TMS="102^Active: Suspended" Q
123 D
124 . ;--- Try to get status from the Taskman
125 . S ZTSK=TASK D STAT^%ZTLOAD
126 . S TMS=$S($G(ZTSK(0)):+$G(ZTSK(1)),1:0)
127 . ;--- Pending or Available
128 . I (TMS=1)!(TMS=4) S STATUS=TMS_U_$G(ZTSK(2)) Q
129 . ;--- Running (actually, crashed ;-)
130 . I TMS=2 S STATUS=100 Q
131 . ;--- Finished, Interrupted or Undefined
132 . I 'STATUS S:TMS STATUS=TMS_U_$G(ZTSK(2)) Q
133 . ;--- If the task record is not locked and the STATUS field shows
134 . ; 'Suspended' (102) then the task probably crashed while it
135 . ;--- was in the suspended state
136 . S:STATUS=102 STATUS=100
137 ;--- Get the external value of the STATUS field (if necessary)
138 I STATUS>0 D:$P(STATUS,U,2)=""
139 . S $P(STATUS,U,2)=$$EXTERNAL^DILFD(798.8,2.01,,STATUS,"RORMSG")
140 . S:$G(DIERR) STATUS=$$DBS^RORERR("RORMSG",-9,,,798.8)
141 ;
142 ;--- Unlock the task record
143 L -@TASKNODE@("T",0)
144 Q $TR(STATUS,">",":")
145 ;
146 ;***** RETURNS THE TASK INFORMATION
147 ;
148 ; TASK Task number
149 ;
150 ; .INFO Reference to a local variable (output):
151 ;
152 ; INFO(
153 ; OFFSET+1) Task Number
154 ; OFFSET+2) Task Type (internal^external)
155 ; OFFSET+3) Registry (IEN^Name)
156 ; OFFSET+4) Report (Code^Name)
157 ; OFFSET+5) Description
158 ; OFFSET+6) Task Status (internal^external)
159 ; OFFSET+7) Creation Time (internal)
160 ; OFFSET+8) User (DUZ^Name)
161 ; OFFSET+9) Completion Time (internal)
162 ; OFFSET+10) Progress Percentage
163 ; OFFSET+11) Scheduled to Run at (internal)
164 ; OFFSET+12) Task Log IEN
165 ; OFFSET+13) Job Number
166 ; OFFSET+14) User Comment
167 ;
168 ; [FLAGS] Characters controlling behavior of the function
169 ; (they can be combined):
170 ; E Return external values also (when applicable)
171 ;
172 ; [OFFSET] A number that is added to all subscripts in the
173 ; destination array (by default, it is zero).
174 ;
175 ; Return Values:
176 ; <0 Error code
177 ; 0 Ok
178 ;
179TASKINFO(TASK,INFO,FLAGS,OFFSET) ;
180 N I,IENS,RORBUF,RORMSG,TMP
181 S FLAGS=$$UP^XLFSTR($G(FLAGS))
182 S OFFSET=$S($G(OFFSET)>0:+OFFSET,1:0)
183 ;--- Clear the output array
184 K:'OFFSET INFO S TMP=$$TIN
185 F I=1:1:TMP S INFO(OFFSET+I)=""
186 ;--- Get the task status
187 S TMP=$$STATUS(TASK,,1) Q:TMP<0 TMP
188 S INFO(OFFSET+1)=TASK
189 S INFO(OFFSET+6)=$S(FLAGS["E":TMP,1:+TMP)
190 ;--- Load the task record
191 S IENS=TASK_",",I=$S(FLAGS["E":"EIN",1:"IN")
192 S TMP=".02;.03;.04;.05;.07;.08;1.01;2.02;2.03;2.04;4"
193 D GETS^DIQ(798.8,IENS,TMP,I,"RORBUF","RORMSG")
194 I $G(DIERR) D Q RC
195 . S RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS)
196 ;--- Format the output array
197 Q $$FRMTI^RORTSK03(OFFSET,.INFO,IENS,.RORBUF,FLAGS)
198 ;
199 ;***** RETURNS NUMBER OF NODES IN THE TASK INFORMATION ARRAY
200TIN() Q 14
Note: See TracBrowser for help on using the repository browser.