| 1 | ROREXT ;HCIOFO/SG - DATA EXTRACTION & TRANSMISSION ; 11/1/05 3:08pm
 | 
|---|
| 2 |  ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
 | 
|---|
| 3 |  ;
 | 
|---|
| 4 |  ; ROREXT -------------- DATA EXTRACTION DESCRIPTOR
 | 
|---|
| 5 |  ;
 | 
|---|
| 6 |  ; ROREXT("DTAR",        Data is extracted only in those areas that
 | 
|---|
| 7 |  ;                       are listed here. If a data area time frame
 | 
|---|
| 8 |  ;                       is provided, then it is merged with the
 | 
|---|
| 9 |  ;                       regular time frame(s) for that area.
 | 
|---|
| 10 |  ;   DataArea)           "" or Data Area Time Frame
 | 
|---|
| 11 |  ;                         ^01: Start Date (FileMan)
 | 
|---|
| 12 |  ;                         ^02: End Date   (FileMan)
 | 
|---|
| 13 |  ;
 | 
|---|
| 14 |  ; ROREXT("DXBEG")       Start date of the data extraction (opt'l)
 | 
|---|
| 15 |  ;                       If this node is defined and greater than
 | 
|---|
| 16 |  ;                       zero, data extraction starts from this date
 | 
|---|
| 17 |  ;                       (instead of individual start date for each
 | 
|---|
| 18 |  ;                       patient in the registry).
 | 
|---|
| 19 |  ;
 | 
|---|
| 20 |  ; ROREXT("DXEND")       End date of the data extraction
 | 
|---|
| 21 |  ;                       (these nodes are set by $$PREPARE^ROREXPR).
 | 
|---|
| 22 |  ;
 | 
|---|
| 23 |  ; ROREXT("EXTRDAYS")    Extraction period for a new patient
 | 
|---|
| 24 |  ;
 | 
|---|
| 25 |  ; ROREXT("FLAGS")       Flags to control processing (see the
 | 
|---|
| 26 |  ;                       TASK^ROR for possible values).
 | 
|---|
| 27 |  ;
 | 
|---|
| 28 |  ; ROREXT("HDTIEN")      When a historical data extraction is
 | 
|---|
| 29 |  ;                       performed, this node stores IEN of
 | 
|---|
| 30 |  ;                       the record of the ROR HISTORICAL DATA
 | 
|---|
| 31 |  ;                       EXTRACTION file (#799.6).
 | 
|---|
| 32 |  ;
 | 
|---|
| 33 |  ; ROREXT("HL7BUF")      Closed root of the buffer where the HL7
 | 
|---|
| 34 |  ;                       message is constructed. By default, the
 | 
|---|
| 35 |  ;                       ^TMP("HLS",$J) is used.
 | 
|---|
| 36 |  ;
 | 
|---|
| 37 |  ; ROREXT("HL7CNT")      Counter of the messages in the batch
 | 
|---|
| 38 |  ; ROREXT("HL7DT")       Date of the batch message creation (FileMan)
 | 
|---|
| 39 |  ; ROREXT("HL7MID")      Message ID of the "stub" message
 | 
|---|
| 40 |  ; ROREXT("HL7MTIEN")    IEN in the File #772 for the "stub" message
 | 
|---|
| 41 |  ; ROREXT("HL7PROT")     Name of the event driver protocol
 | 
|---|
| 42 |  ;
 | 
|---|
| 43 |  ; ROREXT("HL7PTR")      Subscript of the last occupied sub-node of
 | 
|---|
| 44 |  ;                       the message buffer (see the "HL7BUF").
 | 
|---|
| 45 |  ;                       Value of the variable is incremented before
 | 
|---|
| 46 |  ;                       storing the segment.
 | 
|---|
| 47 |  ;
 | 
|---|
| 48 |  ; ROREXT("HL7SID",
 | 
|---|
| 49 |  ;   SegName)            The next value of the Set ID for this kind
 | 
|---|
| 50 |  ;                       of segments. The $$CREATE^RORHL7 function
 | 
|---|
| 51 |  ;                       resets the Set ID's to 1 for all supported
 | 
|---|
| 52 |  ;                       segments.
 | 
|---|
| 53 |  ;
 | 
|---|
| 54 |  ; ROREXT("HL7SIZE")     Current size of the HL7 batch
 | 
|---|
| 55 |  ;                         ^1: Current size (in bytes)
 | 
|---|
| 56 |  ;                         ^2: 1 if maximum size has been reached
 | 
|---|
| 57 |  ;
 | 
|---|
| 58 |  ; ROREXT("LD",
 | 
|---|
| 59 |  ;   1)                  Number of lag days for the data extraction
 | 
|---|
| 60 |  ;
 | 
|---|
| 61 |  ; ROREXT("MAXHL7SIZE")  Maximum size (in bytes) of an HL7 message
 | 
|---|
| 62 |  ;
 | 
|---|
| 63 |  ; ROREXT("MSGBLD",
 | 
|---|
| 64 |  ;   RegIEN)             Message builder call-back entry point (opt'l)
 | 
|---|
| 65 |  ;
 | 
|---|
| 66 |  ; ROREXT("NBM")         Number of batch messages generated for
 | 
|---|
| 67 |  ;                       the current protocol
 | 
|---|
| 68 |  ;
 | 
|---|
| 69 |  ; ROREXT("PATCH",
 | 
|---|
| 70 |  ;   PatchName)          Defined if the patch is installed
 | 
|---|
| 71 |  ;
 | 
|---|
| 72 |  ; ROREXT("SUSPEND")     DATA EXTRACTION SUSPENSION PARAMETERS
 | 
|---|
| 73 |  ;                         ^1: Suspension start time (FileMan)
 | 
|---|
| 74 |  ;                         ^2: Suspension end time (FileMan)
 | 
|---|
| 75 |  ;
 | 
|---|
| 76 |  ;                       For example, to suspend the data extraction
 | 
|---|
| 77 |  ;                       from 7:00 until 18:00 this node should have
 | 
|---|
| 78 |  ;                       the following value: ".07^.18".
 | 
|---|
| 79 |  ;
 | 
|---|
| 80 |  ; ROREXT("VERSION")     ROR version/patch installed at the site
 | 
|---|
| 81 |  ;                         ^1: Version number (e.g. 1.0)
 | 
|---|
| 82 |  ;                         ^2: Latest patch number (e.g. 5)
 | 
|---|
| 83 |  ;                         ^3: Patch installation date (FileMan)
 | 
|---|
| 84 |  ;
 | 
|---|
| 85 |  ; RORHL --------------- HL7 ENVIRONMENT VARIABLES
 | 
|---|
| 86 |  ;
 | 
|---|
| 87 |  ; RORHL                 This local array contains HL7 environment
 | 
|---|
| 88 |  ;                       variables initialized by INIT^HLFNC2 ("FS",
 | 
|---|
| 89 |  ;                       "ECH" and others).
 | 
|---|
| 90 |  ;
 | 
|---|
| 91 |  ; RORLRC -------------- LIST OF EXTRACTED LAB RESULTS
 | 
|---|
| 92 |  ;
 | 
|---|
| 93 |  ; RORLRC(               Either a list of codes of a Lab results to
 | 
|---|
| 94 |  ;                       extract or "*" for all results (see the LA7SC
 | 
|---|
| 95 |  ;                       parameter of the GCPR^LA7QRY entry point)
 | 
|---|
| 96 |  ;   Seq#)               Lab result code
 | 
|---|
| 97 |  ;                         ^1: Result code
 | 
|---|
| 98 |  ;                         ^2: Coding system ("LN" or "NLT")
 | 
|---|
| 99 |  ;
 | 
|---|
| 100 |  Q
 | 
|---|
| 101 |  ;
 | 
|---|
| 102 |  ;***** PERFORMS THE DATA EXTRACTION
 | 
|---|
| 103 |  ;
 | 
|---|
| 104 |  ; .REGLST       Reference to a local array containing registry
 | 
|---|
| 105 |  ;               names as subscripts and registry IENs as values
 | 
|---|
| 106 |  ;
 | 
|---|
| 107 |  ; [DXBEG]       Data extraction start date (individual start
 | 
|---|
| 108 |  ;               date for each patient by default).
 | 
|---|
| 109 |  ;               Time part of the parameter value is ignored.
 | 
|---|
| 110 |  ;
 | 
|---|
| 111 |  ; [SUSPEND]     Subtask suspension parameters:
 | 
|---|
| 112 |  ;               See description of the ROREXT("SUSPEND") node
 | 
|---|
| 113 |  ;               for details.
 | 
|---|
| 114 |  ;
 | 
|---|
| 115 |  ; [FLAGS]       Flags to control processing.
 | 
|---|
| 116 |  ;               See description of the TASK^ROR for
 | 
|---|
| 117 |  ;               possible values of the flags.
 | 
|---|
| 118 |  ;
 | 
|---|
| 119 |  ; Return Values:
 | 
|---|
| 120 |  ;       <0  Error code (see MSGLIST^RORERR20)
 | 
|---|
| 121 |  ;        0  Ok
 | 
|---|
| 122 |  ;
 | 
|---|
| 123 | EXTRACT(REGLST,DXBEG,SUSPEND,FLAGS) ;
 | 
|---|
| 124 |  N ROREXT        ; Data extraction descriptor
 | 
|---|
| 125 |  N ROREXTSV      ; Backup copy of the descriptor
 | 
|---|
| 126 |  ;
 | 
|---|
| 127 |  N CNT,ERRCNT,PGRLST,RC,REGIEN,REGNAME,RORGLST,RORMSG,RORPROT,TMP,ZTDESC,ZTDTH,ZTRTN,ZTSAVE
 | 
|---|
| 128 |  D CLEAR^RORERR("EXTRACT^ROREXT")
 | 
|---|
| 129 |  S (ERRCNT,RC)=0
 | 
|---|
| 130 |  ;
 | 
|---|
| 131 |  ;=== Prepare the common parameters
 | 
|---|
| 132 |  S:$G(DXBEG)>0 ROREXT("DXBEG")=DXBEG
 | 
|---|
| 133 |  S ROREXT("FLAGS")=$$UP^XLFSTR($G(FLAGS))
 | 
|---|
| 134 |  ;--- Enable task suspension if requested
 | 
|---|
| 135 |  I $G(SUSPEND)>0  S:ROREXT("FLAGS")["X" ROREXT("SUSPEND")=SUSPEND
 | 
|---|
| 136 |  ;
 | 
|---|
| 137 |  ;=== Group the registries by the HL7 protocol name
 | 
|---|
| 138 |  S REGNAME=""
 | 
|---|
| 139 |  F  S REGNAME=$O(REGLST(REGNAME))  Q:REGNAME=""  D
 | 
|---|
| 140 |  . ;--- Get the registry IEN
 | 
|---|
| 141 |  . S REGIEN=+REGLST(REGNAME)
 | 
|---|
| 142 |  . I REGIEN'>0  D  Q:REGIEN'>0
 | 
|---|
| 143 |  . . S REGIEN=$$REGIEN^RORUTL02(REGNAME)
 | 
|---|
| 144 |  . ;--- Get the HL7 protocol name
 | 
|---|
| 145 |  . S RORPROT=$$GET1^DIQ(798.1,REGIEN_",",13,"E",,"RORMSG")
 | 
|---|
| 146 |  . D:$G(DIERR) DBS^RORERR("RORMSG",-9,,,798.1,REGIEN_",")
 | 
|---|
| 147 |  . I RORPROT=""  D  S ERRCNT=ERRCNT+1  Q
 | 
|---|
| 148 |  . . D ERROR^RORERR(-25,,REGNAME)
 | 
|---|
| 149 |  . ;--- Create the reference
 | 
|---|
| 150 |  . S PGRLST(RORPROT,REGNAME)=REGIEN
 | 
|---|
| 151 |  ;
 | 
|---|
| 152 |  ;=== Data extraction
 | 
|---|
| 153 |  M ROREXTSV=ROREXT
 | 
|---|
| 154 |  S RORPROT="",RC=0
 | 
|---|
| 155 |  F CNT=1:1  S RORPROT=$O(PGRLST(RORPROT))  Q:RORPROT=""  D  Q:RC<0
 | 
|---|
| 156 |  . ;--- Prepare the task-specific parameters
 | 
|---|
| 157 |  . K RORGLST  M RORGLST=PGRLST(RORPROT)
 | 
|---|
| 158 |  . S ROREXT("HL7PROT")=RORPROT
 | 
|---|
| 159 |  . ;--- Single-task data extraction (if requested)
 | 
|---|
| 160 |  . I ROREXT("FLAGS")["S"  D  Q
 | 
|---|
| 161 |  . . S TMP=$$INTEXT^ROREXT01(.RORGLST)
 | 
|---|
| 162 |  . . I TMP<0  S:TMP=-42 RC=TMP  S ERRCNT=ERRCNT+1
 | 
|---|
| 163 |  . . K ROREXT  M ROREXT=ROREXTSV
 | 
|---|
| 164 |  . ;--- Otherwise, start a separate task
 | 
|---|
| 165 |  . S ZTRTN="TASK^ROREXT",ZTIO=""
 | 
|---|
| 166 |  . S ZTDTH=$$FMADD^XLFDT($$NOW^XLFDT,,,,(CNT-1)*30)
 | 
|---|
| 167 |  . S ZTDESC="CCR Data Extraction ("_RORPROT_")"
 | 
|---|
| 168 |  . F TMP="ROREXT(","RORGLST(","RORPARM("  S ZTSAVE(TMP)=""
 | 
|---|
| 169 |  . D ^%ZTLOAD
 | 
|---|
| 170 |  . ;--- Log the action
 | 
|---|
| 171 |  . D LOG^RORERR(-94,,,ZTSK)
 | 
|---|
| 172 |  ;
 | 
|---|
| 173 |  ;=== Error processing
 | 
|---|
| 174 |  Q $S(RC<0:RC,ERRCNT>0:-43,1:0)
 | 
|---|
| 175 |  ;
 | 
|---|
| 176 |  ;***** ENTRY POINT FOR DATA EXTRACTION TASK
 | 
|---|
| 177 |  ;
 | 
|---|
| 178 |  ; ROREXT        Data extraction descriptor
 | 
|---|
| 179 |  ; RORGLST       List of registry names and IENs
 | 
|---|
| 180 |  ; RORPARM       Task-wide constants and variables
 | 
|---|
| 181 |  ;
 | 
|---|
| 182 | TASK ;
 | 
|---|
| 183 |  N RORERRDL      ; Default error location
 | 
|---|
| 184 |  N RORERROR      ; Error processing data
 | 
|---|
| 185 |  ;
 | 
|---|
| 186 |  N RC,TMP  K ZTREQ
 | 
|---|
| 187 |  ;--- Initialize the variables
 | 
|---|
| 188 |  D CLEAR^RORERR("TASK^ROREXT",1)
 | 
|---|
| 189 |  ;--- Disable debug output (task has no output device)
 | 
|---|
| 190 |  S:$G(RORPARM("DEBUG"))>1 RORPARM("DEBUG")=1
 | 
|---|
| 191 |  ;--- Data extraction
 | 
|---|
| 192 |  S RC=$$INTEXT^ROREXT01(.RORGLST,ZTSK)
 | 
|---|
| 193 |  ;--- Error processing and notifications
 | 
|---|
| 194 |  S:RC<0 ZTSTOP=1
 | 
|---|
| 195 |  I RC=-42  D ALERT^RORUTL01(.RORGLST,-42)  Q
 | 
|---|
| 196 |  D:RC<0 ALERT^RORUTL01(.RORGLST,-43,,,,"data extraction")
 | 
|---|
| 197 |  S ZTREQ="@"
 | 
|---|
| 198 |  Q
 | 
|---|