| [613] | 1 | RORTSK01 ;HCIOFO/SG - (SUB)TASK UTILITIES ; 1/22/06 8:05pm | 
|---|
|  | 2 | ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006 | 
|---|
|  | 3 | ; | 
|---|
|  | 4 | ; These utilities should be called only from the tasks and subtasks | 
|---|
|  | 5 | ; that are created and scheduled by the RORTSK API. | 
|---|
|  | 6 | ; | 
|---|
|  | 7 | ; The RORTSK local array is passed to the task. If the proxy task | 
|---|
|  | 8 | ; is used then it passes this array by reference into the entry | 
|---|
|  | 9 | ; point that implements the generic task or report. | 
|---|
|  | 10 | ; | 
|---|
|  | 11 | ; RORTSK(               Task Number | 
|---|
|  | 12 | ; | 
|---|
|  | 13 | ;   "PARAMS",...)       Report Parameters | 
|---|
|  | 14 | ;   "TPP-PREV")         Previous value of task progress percentage | 
|---|
|  | 15 | ; | 
|---|
|  | 16 | ; If the proxy task is used, additional nodes are created: | 
|---|
|  | 17 | ; | 
|---|
|  | 18 | ;   "EP")               Entry Point | 
|---|
|  | 19 | ;   "TYPE")             Type of the Task | 
|---|
|  | 20 | ;   "REGIEN")           Registry IEN | 
|---|
|  | 21 | ;   "REPORT")           Code of the Report | 
|---|
|  | 22 | ;   "SCHCODE")          Rescheduling Code | 
|---|
|  | 23 | ; | 
|---|
|  | 24 | ; See descriptions of the REPORT BUILDER field (10.01) of the | 
|---|
|  | 25 | ; ROR REPORT PARAMETERS file (#799.34) and the ROR REPORT SCHEDULE | 
|---|
|  | 26 | ; remote procedure for more details. | 
|---|
|  | 27 | ; | 
|---|
|  | 28 | Q | 
|---|
|  | 29 | ; | 
|---|
|  | 30 | ;***** DUMMY ENTRY POINT (TO AVOID CRASH DURING ALERT PROCESSING) | 
|---|
|  | 31 | ALERTRTN Q | 
|---|
|  | 32 | ; | 
|---|
|  | 33 | ;***** (SUB)TASK CLEANUP | 
|---|
|  | 34 | ; | 
|---|
|  | 35 | ; ERRCODE       Error code of the task | 
|---|
|  | 36 | ; [PARENT]      Parent task for the subtask | 
|---|
|  | 37 | ; | 
|---|
|  | 38 | ; Return Values: | 
|---|
|  | 39 | ;       <0  Error code | 
|---|
|  | 40 | ;        0  Ok | 
|---|
|  | 41 | ; | 
|---|
|  | 42 | EXIT(ERRCODE,PARENT) ; | 
|---|
|  | 43 | N IENS,RC,RORFDA,RORMSG,STATUS,TASKINFO,TASKNODE,TMP | 
|---|
|  | 44 | S RC=0,STATUS=$S(ERRCODE=-42:5,ERRCODE<0:101,1:3),ZTREQ="@" | 
|---|
|  | 45 | ;=== SUBTASK | 
|---|
|  | 46 | I $G(PARENT)  D  Q RC | 
|---|
|  | 47 | . ;--- Not implemented | 
|---|
|  | 48 | ;=== TASK | 
|---|
|  | 49 | S TASKNODE=$NA(^RORDATA(798.8,RORTSK)) | 
|---|
|  | 50 | S TMP=$$TASKINFO^RORTSK02(RORTSK,.TASKINFO) | 
|---|
|  | 51 | ;--- Report statistics | 
|---|
|  | 52 | D:+$G(TASKINFO(2))=2 | 
|---|
|  | 53 | . S TMP=+$G(TASKINFO(3))  ; Registry IEN | 
|---|
|  | 54 | . D:TMP>0 INC^RORTSK12(TMP,+$G(TASKINFO(4))) | 
|---|
|  | 55 | ;--- Send an alert to the user who has started the task | 
|---|
|  | 56 | S TMP=$G(TASKINFO(5))  ; Task Description | 
|---|
|  | 57 | D ORALERT^RORUTL18($$MSG^RORERR20(-101,,,RORTSK,TMP)) | 
|---|
|  | 58 | ;--- Update the task record | 
|---|
|  | 59 | S IENS=RORTSK_"," | 
|---|
|  | 60 | S RORFDA(798.8,IENS,2.01)=STATUS      ; Status | 
|---|
|  | 61 | S RORFDA(798.8,IENS,2.02)=$$NOW^XLFDT ; Completion Time | 
|---|
|  | 62 | S RORFDA(798.8,IENS,2.04)="@"         ; Job Number | 
|---|
|  | 63 | S RORFDA(798.8,IENS,4)="@"            ; Progress | 
|---|
|  | 64 | D FILE^DIE(,"RORFDA","RORMSG") | 
|---|
|  | 65 | S:$G(DIERR) RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS) | 
|---|
|  | 66 | ;--- Cleanup | 
|---|
|  | 67 | K @TASKNODE@("A"),@TASKNODE@("T") | 
|---|
|  | 68 | L -@TASKNODE@("T",0) | 
|---|
|  | 69 | Q RC | 
|---|
|  | 70 | ; | 
|---|
|  | 71 | ;***** INITIALIZES THE (SUB)TASK | 
|---|
|  | 72 | ; | 
|---|
|  | 73 | ; TASK          Task number | 
|---|
|  | 74 | ; [LOG]         Log IEN (returned by the $$LOGIEN^RORLOG function) | 
|---|
|  | 75 | ; [PARENT]      Parent task for the subtask | 
|---|
|  | 76 | ; | 
|---|
|  | 77 | ; Return Values: | 
|---|
|  | 78 | ;       <0  Error code | 
|---|
|  | 79 | ;        0  Ok | 
|---|
|  | 80 | ; | 
|---|
|  | 81 | INIT(TASK,LOG,PARENT) ; | 
|---|
|  | 82 | N I,RC,RORDTH,RORFDA,RORMSG,TASKNODE | 
|---|
|  | 83 | S RORDTH=$G(ZTDTH)  S:RORDTH'>0 RORDTH=$$NOW^XLFDT | 
|---|
|  | 84 | S RC=0,RORTSK=+TASK  K RORTSK("PREVTPP") | 
|---|
|  | 85 | ;=== SUBTASK | 
|---|
|  | 86 | I $G(PARENT)  S RC=0  D  Q RC | 
|---|
|  | 87 | . ;--- Not implemented | 
|---|
|  | 88 | ;=== TASK | 
|---|
|  | 89 | S TASKNODE=$NA(^RORDATA(798.8,RORTSK)) | 
|---|
|  | 90 | ;--- Schedule the next instance of the task (if requested) | 
|---|
|  | 91 | D:$G(RORTSK("SCHCODE"))'="" | 
|---|
|  | 92 | . N EP,TYPE,REGIEN,REPORT,SCHCODE | 
|---|
|  | 93 | . N ZTCPU,ZTDTH,ZTIO,ZTKIL,ZTPRI,ZTSAVE,ZTSYNC,ZTUCI | 
|---|
|  | 94 | . F I="EP","TYPE","REGIEN","REPORT","SCHCODE"  S @I=$G(RORTSK(I)) | 
|---|
|  | 95 | . Q:(TYPE'>0)!(EP="") | 
|---|
|  | 96 | . S ZTDTH=$$SCH^XLFDT(SCHCODE,RORDTH,1) | 
|---|
|  | 97 | . S TMP=$$CREATE^RORTSK(TYPE,EP,,REGIEN,REPORT,SCHCODE,.RORTSK) | 
|---|
|  | 98 | ;--- Wait until the task record is created | 
|---|
|  | 99 | S RC=$$TRWAIT(RORTSK)  Q:RC<0 RC | 
|---|
|  | 100 | ;--- Lock the task record | 
|---|
|  | 101 | L +@TASKNODE@("T",0):5 | 
|---|
|  | 102 | E  Q $$ERROR^RORERR(-11,,,,"the ROR TASK file") | 
|---|
|  | 103 | ;--- Clear the list of subtasks | 
|---|
|  | 104 | K @TASKNODE@("T") | 
|---|
|  | 105 | ;--- Update the task record | 
|---|
|  | 106 | S IENS=RORTSK_"," | 
|---|
|  | 107 | S RORFDA(798.8,IENS,2.01)=100         ; STATUS = 'Crashed' | 
|---|
|  | 108 | S RORFDA(798.8,IENS,2.03)=$G(LOG)     ; Log IEN | 
|---|
|  | 109 | S RORFDA(798.8,IENS,2.04)=$J          ; Job Number | 
|---|
|  | 110 | D FILE^DIE(,"RORFDA","RORMSG") | 
|---|
|  | 111 | S:$G(DIERR) RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS) | 
|---|
|  | 112 | Q RC | 
|---|
|  | 113 | ; | 
|---|
|  | 114 | ;***** TASK CONTROL FUNCTION | 
|---|
|  | 115 | ; | 
|---|
|  | 116 | ; [TPP]         Task/Section progress (0-1) | 
|---|
|  | 117 | ; | 
|---|
|  | 118 | ; Return Values: | 
|---|
|  | 119 | ;       <0  Error code | 
|---|
|  | 120 | ;        0  Ok | 
|---|
|  | 121 | ; | 
|---|
|  | 122 | LOOP(TPP) ; | 
|---|
|  | 123 | N ACTION,OFFSET,RC | 
|---|
|  | 124 | ;--- Update the task progress percentage | 
|---|
|  | 125 | D:$G(TPP)'="" | 
|---|
|  | 126 | . I TPP'<0,TPP'>1  D  S TPP=+$J(TPP,0,2) | 
|---|
|  | 127 | . . S TPP=TPP*$G(RORTSK("TPP-BASE"),100)+$G(RORTSK("TPP-OFFS")) | 
|---|
|  | 128 | . E  S TPP="" | 
|---|
|  | 129 | . Q:TPP=$G(RORTSK("TPP-PREV")) | 
|---|
|  | 130 | . S (^RORDATA(798.8,RORTSK,"P"),RORTSK("TPP-PREV"))=TPP | 
|---|
|  | 131 | ;--- Requested action | 
|---|
|  | 132 | S ACTION=$S($$S^%ZTLOAD:2,1:+$G(^RORDATA(798.8,RORTSK,"A"))) | 
|---|
|  | 133 | Q:'ACTION 0 | 
|---|
|  | 134 | ;=== SUSPEND THE TASK | 
|---|
|  | 135 | I ACTION=1  S RC=0  D  Q RC | 
|---|
|  | 136 | . N IENS,RORFDA,RORMSG | 
|---|
|  | 137 | . S IENS=RORTSK_"," | 
|---|
|  | 138 | . ;--- Update the task status | 
|---|
|  | 139 | . S RORFDA(798.8,IENS,2.01)=102      ; STATUS = 'Suspended' | 
|---|
|  | 140 | . D FILE^DIE(,"RORFDA","RORMSG") | 
|---|
|  | 141 | . S:$G(DIERR) RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS) | 
|---|
|  | 142 | . ;--- Suspension cycle | 
|---|
|  | 143 | . F  H 60  D  Q:ACTION'=1 | 
|---|
|  | 144 | . . S ACTION=$S($$S^%ZTLOAD:2,1:+$G(^RORDATA(798.8,RORTSK,"A"))) | 
|---|
|  | 145 | . ;--- Restore the default task status | 
|---|
|  | 146 | . S RORFDA(798.8,IENS,2.01)=100      ; STATUS = 'Crashed' | 
|---|
|  | 147 | . D FILE^DIE(,"RORFDA","RORMSG") | 
|---|
|  | 148 | . S:$G(DIERR) RC=$$DBS^RORERR("RORMSG",-9,,,798.8,IENS) | 
|---|
|  | 149 | ;=== STOP THE TASK | 
|---|
|  | 150 | I ACTION=2  D  Q $$ERROR^RORERR(-42) | 
|---|
|  | 151 | . S ZTSTOP=1 | 
|---|
|  | 152 | Q 0 | 
|---|
|  | 153 | ; | 
|---|
|  | 154 | ;***** RETURNS THE VALUE/ATTRIBUTE OF THE TASK PARAMETER | 
|---|
|  | 155 | PARAM(NAME,ATTR) ; | 
|---|
|  | 156 | Q:$G(ATTR)'="" $G(RORTSK("PARAMS",NAME,"A",ATTR)) | 
|---|
|  | 157 | Q $G(RORTSK("PARAMS",NAME)) | 
|---|
|  | 158 | ; | 
|---|
|  | 159 | ;***** TASK PROXY | 
|---|
|  | 160 | ; | 
|---|
|  | 161 | ; RORTSK("EP")  This node must contain name of the task entry point | 
|---|
|  | 162 | ;               ($$TAG^ROUTINE). The function should return either | 
|---|
|  | 163 | ;               a negative error code or zero. | 
|---|
|  | 164 | ; | 
|---|
|  | 165 | TASK ; | 
|---|
|  | 166 | N RORCACHE      ; Cache of element and attribute names | 
|---|
|  | 167 | N RORLOG        ; Log subsystem constants & variables | 
|---|
|  | 168 | N RORPARM       ; Application parameters | 
|---|
|  | 169 | ; | 
|---|
|  | 170 | N ACTIVITY,I,INFO,RC,REGLST,RORERRDL,TASKINFO,TMP,TRC | 
|---|
|  | 171 | S RORTSK=ZTSK | 
|---|
|  | 172 | ;--- Initialize constants and variables | 
|---|
|  | 173 | D INIT^RORUTL01("ROR") | 
|---|
|  | 174 | ;S RORPARM("DEBUG")=1 ; Remove the first ';' to start in debug mode | 
|---|
|  | 175 | S RORPARM("ERR")=1    ; Enable enhanced error processing | 
|---|
|  | 176 | S RORPARM("LOG")=1    ; Enable error recording | 
|---|
|  | 177 | ;--- Wait until the task record is created | 
|---|
|  | 178 | S TMP=$$TRWAIT(RORTSK) | 
|---|
|  | 179 | ;--- Get the task information | 
|---|
|  | 180 | S TRC=$$TASKINFO^RORTSK02(RORTSK,.TASKINFO,"E") | 
|---|
|  | 181 | ;--- Open a task log | 
|---|
|  | 182 | S TMP=$P($G(TASKINFO(3)),U,2)  S:TMP'="" REGLST(TMP)="" | 
|---|
|  | 183 | S ACTIVITY=$S(+$G(TASKINFO(2))=2:5,1:0) | 
|---|
|  | 184 | S TMP=$$SETUP^RORLOG(.REGLST) | 
|---|
|  | 185 | S RC=$$OPEN^RORLOG(.REGLST,ACTIVITY,"TASK #"_RORTSK_" STARTED") | 
|---|
|  | 186 | ;--- Abort the task if task information was not available | 
|---|
|  | 187 | I TRC<0  D:RC'<0  Q | 
|---|
|  | 188 | . S TMP=$$ERROR^RORERR(-56,,,,TRC,"$$TASKINFO^RORTSK02") | 
|---|
|  | 189 | . D CLOSE^RORLOG("TASK #"_RORTSK_" ABORTED") | 
|---|
|  | 190 | D | 
|---|
|  | 191 | . ;--- Record the task information (if available) | 
|---|
|  | 192 | . S I=0,TMP=$G(TASKINFO(5)) | 
|---|
|  | 193 | . S:TMP'="" I=I+1,INFO(I)="Description: '"_TMP_"'" | 
|---|
|  | 194 | . S TMP=$P($G(TASKINFO(8)),U,2) | 
|---|
|  | 195 | . S:TMP'="" I=I+1,INFO(I)="User:        '"_TMP_"'" | 
|---|
|  | 196 | . S TMP=$G(TASKINFO(14)) | 
|---|
|  | 197 | . S:TMP'="" I=I+1,INFO(I)="Comment:     '"_TMP_"'" | 
|---|
|  | 198 | . D:I LOG^RORLOG(2,"Task Information",,.INFO) | 
|---|
|  | 199 | . ;--- Verify the entry point | 
|---|
|  | 200 | . S RC=$$VERIFYEP^RORUTL01($G(RORTSK("EP")),1)  Q:RC<0 | 
|---|
|  | 201 | . ;--- Initialize the task | 
|---|
|  | 202 | . S RC=$$INIT(RORTSK,$$LOGIEN^RORLOG)  Q:RC<0 | 
|---|
|  | 203 | . K ACTIVITY,INFO,REGLST,TASKINFO,TMP | 
|---|
|  | 204 | . ;--- Call the entry point | 
|---|
|  | 205 | . X "S TRC="_RORTSK("EP")_"(.RORTSK)" | 
|---|
|  | 206 | ; | 
|---|
|  | 207 | ;--- Post-processing | 
|---|
|  | 208 | S TMP=$$EXIT(TRC) | 
|---|
|  | 209 | ;--- Close the log | 
|---|
|  | 210 | S TMP="TASK #"_RORTSK_$S(TRC<0:" ABORTED",1:" COMPLETED") | 
|---|
|  | 211 | D CLOSE^RORLOG(TMP) | 
|---|
|  | 212 | Q | 
|---|
|  | 213 | ; | 
|---|
|  | 214 | ;***** SETS THE BASE VALUE FOR THE PROGRESS INDICATOR | 
|---|
|  | 215 | ; | 
|---|
|  | 216 | ; BASE          Base value for the progress indicator (0-100) | 
|---|
|  | 217 | ; | 
|---|
|  | 218 | TPPSETUP(BASE) ; | 
|---|
|  | 219 | I $G(BASE)'>0  K RORTSK("TPP-BASE"),RORTSK("TPP-OFFS")  Q | 
|---|
|  | 220 | N TMP | 
|---|
|  | 221 | S RORTSK("TPP-OFFS")=$G(RORTSK("TPP-OFFS"))+$G(RORTSK("TPP-BASE")) | 
|---|
|  | 222 | S TMP=100-$G(RORTSK("TPP-OFFS")) | 
|---|
|  | 223 | S RORTSK("TPP-BASE")=$S(BASE<TMP:BASE,1:TMP) | 
|---|
|  | 224 | S TMP=$$LOOP(0) | 
|---|
|  | 225 | Q | 
|---|
|  | 226 | ; | 
|---|
|  | 227 | ;***** WAITS UNTIL THE TASK RECORD IS CREATED | 
|---|
|  | 228 | ; | 
|---|
|  | 229 | ; TASK          Task number | 
|---|
|  | 230 | ; | 
|---|
|  | 231 | ; Return Values: | 
|---|
|  | 232 | ;       <0  Error code | 
|---|
|  | 233 | ;        0  Ok | 
|---|
|  | 234 | ; | 
|---|
|  | 235 | TRWAIT(TASK) ; | 
|---|
|  | 236 | N I  F I=1:1:5  Q:$D(^RORDATA(798.8,TASK,0))  H 1 | 
|---|
|  | 237 | Q $S($D(^RORDATA(798.8,TASK,0)):0,1:$$ERROR^RORERR(-83,,,,TASK)) | 
|---|