source: FOIAVistA/trunk/r/CLINICAL_CASE_REGISTRIES-ROR/RORHDT05.m@ 1166

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

initial load of FOIAVistA 6/30/08 version

File size: 4.0 KB
Line 
1RORHDT05 ;HCIOFO/SG - HISTORICAL DATA EXTRACTION FUNCTIONS ; 1/22/06 12:01pm
2 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
3 ;
4 Q
5 ;
6 ;***** ADDS A RECORD TO THE 'ERROR' MULTIPLE OF THE TASK RECORD
7 ;
8 ; HDEIEN Data Extract IEN
9 ; TASKIEN Task IEN
10 ; PTIEN Patient IEN
11 ;
12 ; Return Values:
13 ; <0 Error code
14 ; 0 Ok
15 ;
16ADDERR(HDEIEN,TASKIEN,PTIEN) ;
17 N IENS,RC,RORFDA,RORIEN,RORMSG
18 S IENS="+1,"_(+TASKIEN)_","_(+HDEIEN)_",",RORIEN(1)=+PTIEN
19 S RORFDA(799.641,IENS,.01)=+PTIEN
20 D UPDATE^DIE(,"RORFDA","RORIEN","RORMSG")
21 Q $$DBS^RORERR("RORMSG",-9,,,799.641,IENS)
22 ;
23 ;***** DELETES RECORDS FROM THE 'ERROR' MULTIPLE OF THE TASK RECORD
24 ;
25 ; HDEIEN Data Extract IEN
26 ; TASKIEN Task IEN
27 ;
28 ; This functions deletes all erroneous records from the ERROR
29 ; multiple of the task record that have been re-extracted without
30 ; errors. So, there is no reason to keep them anymore.
31 ;
32 ; Return Values:
33 ; <0 Error code
34 ; 0 Ok
35 ;
36CLRERRS(HDEIEN,TASKIEN) ;
37 N I,IEN,RC,RORFDA,RORMSG,SFI
38 S SFI=","_(+TASKIEN)_","_(+HDEIEN)_",",RC=0
39 S IEN=""
40 F D Q:(RC<0)!(IEN="")
41 . F I=1:1:10 S IEN=$O(^TMP("RORHDT",$J,"PR",IEN)) Q:IEN="" D
42 . . S:^TMP("RORHDT",$J,"PR",IEN)'<0 RORFDA(799.641,IEN_SFI,.01)="@"
43 . Q:$D(RORFDA)<10
44 . D FILE^DIE(,"RORFDA","RORMSG")
45 . S:$G(DIERR) RC=$$DBS^RORERR("RORMSG",-9,,,799.641)
46 Q $S(RC<0:RC,1:0)
47 ;
48 ;***** COMMITS HL7 DATA TO THE OUTPUT FILE
49 ;
50 ; OUTDIR Output directory
51 ; FILE Output file name
52 ;
53 ; Return Values:
54 ; <0 Error code
55 ; 0 Ok
56 ;
57COMMIT(OUTDIR,FILE) ;
58 N CR,I,J,POP,RC
59 Q:$D(^TMP("HLS",$J))<10 0
60 S CR=$C(13),RC=0
61 ;--- Create the file and write the BHS segment (if necessary)
62 I $G(RORHDT("BHS")) D Q:RC<0 RC K RORHDT("BHS")
63 . D OPEN^%ZISH("HL7FILE",OUTDIR,FILE,"WB")
64 . I $G(POP) S RC=$$ERROR^RORERR(-34,,OUTDIR_FILE) Q
65 . S I=$G(ROREXT("HL7DT")) U IO
66 . W $$BHS^RORHL7A($G(ROREXT("HL7MID")),I,"HISTORICAL DATA"),$C(13)
67 ;--- Write the segments
68 S I=0
69 F S I=$O(^TMP("HLS",$J,I)) Q:I="" D
70 . W ^TMP("HLS",$J,I) S J=""
71 . F S J=$O(^TMP("HLS",$J,I,J)) Q:J="" W ^(J)
72 . W CR
73 Q 0
74 ;
75 ;***** DELETES THE OLD OUTPUT HOST FILE(S)
76 ;
77 ; OUTDIR Output directory
78 ; FILE Output file name
79 ;
80 ; Return Values:
81 ; <0 Error code
82 ; 0 Ok
83 ;
84DELFILES(OUTDIR,FILE) ;
85 N RC,RORDST,RORSRC Q:FILE="" 0
86 S RORSRC(FILE_"*")=""
87 Q:'$$LIST^%ZISH(OUTDIR,"RORSRC","RORDST") 0
88 I '$$DEL^%ZISH(OUTDIR,"RORDST") D Q RC
89 . S RC=$$ERROR^RORERR(-56,,,,0,"$$DEL^%ZISH")
90 Q 0
91 ;
92 ;***** LOADS DATA EXTRACTION PARAMETERS
93 ;
94 ; HDEIEN Data Extract IEN
95 ;
96 ; [.BDT] Start date of the data extract
97 ; [.EDT] End date of the data extract
98 ; [.OUTDIR] Output directory
99 ;
100 ; Return Values:
101 ; <0 Error code
102 ; 0 Ok
103 ;
104HDEPARM(HDEIEN,BDT,EDT,OUTDIR) ;
105 N IENS,RC,RORBUF,RORMSG,TMP
106 S IENS=(+HDEIEN)_","
107 ;--- Get data from the registry descriptor
108 D GETS^DIQ(799.6,IENS,".03;.04;2","I","RORBUF","RORMSG")
109 Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,798.1,IENS)
110 S BDT=$G(RORBUF(799.6,IENS,.03,"I"))
111 S EDT=$G(RORBUF(799.6,IENS,.04,"I"))
112 S OUTDIR=$G(RORBUF(799.6,IENS,2,"I"))
113 I (BDT'>0)!(EDT'>0)!(BDT>EDT) D Q RC
114 . S RC=$$ERROR^RORERR(-32,,,,BDT,EDT)
115 Q 0
116 ;
117 ;***** LOADS TASK PARAMETERS
118 ;
119 ; HDEIEN Data Extract IEN
120 ; TASKIEN Task IEN
121 ;
122 ; [.RBIEN] Start record IEN
123 ; [.REIEN] End record IEN
124 ; [.FILE] File name
125 ;
126 ; Return Values:
127 ; <0 Error code
128 ; 0 Ok
129 ;
130TASKPARM(HDEIEN,TASKIEN,RBIEN,REIEN,FILE) ;
131 N IENS,RC,ROOT,RORBUF,RORMSG,TMP
132 ;--- Load data from the task record
133 S IENS=(+TASKIEN)_","_(+HDEIEN)_","
134 D GETS^DIQ(799.64,IENS,".01;.04;.05","I","RORBUF","RORMSG")
135 Q:$G(DIERR) $$DBS^RORERR("RORMSG",-9,,,799.64,IENS)
136 S RBIEN=$G(RORBUF(799.64,IENS,.01,"I"))
137 S FILE=$G(RORBUF(799.64,IENS,.05,"I"))
138 ;--- Get the end record IEN from the next task record
139 S ROOT=$$ROOT^DILFD(799.64,","_(+HDEIEN)_",",1)
140 S REIEN=$O(@ROOT@("B",RBIEN))
141 ;--- If an IEN of the record is available from the previous run,
142 ; use it as start record IEN
143 S TMP=$G(RORBUF(799.64,IENS,.04,"I"))
144 S:TMP>0 RBIEN=TMP
145 Q 0
Note: See TracBrowser for help on using the repository browser.