source: ccr/trunk/p/C0CFM2.m@ 414

Last change on this file since 414 was 404, checked in by George Lilly, 16 years ago

update copyright notice

File size: 11.2 KB
Line 
1C0CFM2 ; CCDCCR/GPL - CCR FILEMAN utilities; 12/6/08
2 ;;0.1;CCDCCR;nopatch;noreleasedate
3 ;Copyright 2009 George Lilly. Licensed under the terms of the GNU
4 ;General Public License See attached copy of the License.
5 ;
6 ;This program is free software; you can redistribute it and/or modify
7 ;it under the terms of the GNU General Public License as published by
8 ;the Free Software Foundation; either version 2 of the License, or
9 ;(at your option) any later version.
10 ;
11 ;This program is distributed in the hope that it will be useful,
12 ;but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;GNU General Public License for more details.
15 ;
16 ;You should have received a copy of the GNU General Public License along
17 ;with this program; if not, write to the Free Software Foundation, Inc.,
18 ;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ;
20 W "This is the CCR FILEMAN Utility Library ",!
21 ; THIS SET OF ROUTINES USE CCR E2 (^C0CE(, FILE 171.101) INSTEAD OF
22 ; CCR ELEMENTS (^C0C(179.201,
23 ; E2 IS A SIMPLIFICATION OF CCR ELEMENTS WHERE SUB-ELEMENTS ARE
24 ; AT THE TOP LEVEL. OCCURANCE, THE 4TH PART OF THE KEY IS NOW FREE TEXT
25 ; AND HAS THE FORM X;Y FOR SUB-ELEMENTS
26 ; ALL SUB-VARIABLES HAVE BEEN REMOVED
27 W !
28 Q
29 ;
30RIMTBL(ZWHICH) ; PUT ALL PATIENT IN RIMTBL ZWHICH INTO THE CCR ELEMENTS FILE
31 ;
32 I '$D(RIMBASE) D ASETUP^GPLRIMA ; FOR COMMAND LINE CALLS
33 N ZI,ZJ,ZC,ZPATBASE
34 S ZPATBASE=$NA(@RIMBASE@("RIMTBL","PATS",ZWHICH))
35 S ZI=""
36 F ZJ=0:0 D Q:$O(@ZPATBASE@(ZI))="" ; TIL END
37 . S ZI=$O(@ZPATBASE@(ZI))
38 . D PUTRIM(ZI) ; EXPORT THE PATIENT TO A FILE
39 Q
40 ;
41PUTRIM(DFN,ZWHICH) ;DFN IS PATIENT , WHICH IS ELEMENT TYPE
42 ;
43 S C0CGLB=$NA(^TMP("GPLRIM","VARS",DFN))
44 I '$D(ZWHICH) S ZWHICH="ALL"
45 I ZWHICH'="ALL" D ; SINGLE SECTION REQUESTED
46 . S C0CVARS=$NA(@C0CGLB@(ZWHICH))
47 . D PUTRIM1(DFN,ZWHICH,C0CVARS) ; IF ONE SECTION
48 E D ; MULTIPLE SECTIONS
49 . S C0CVARS=$NA(@C0CGLB)
50 . S C0CI=""
51 . F S C0CI=$O(@C0CVARS@(C0CI)) Q:C0CI="" D ;FOR EACH SECTION
52 . . S C0CVARSN=$NA(@C0CVARS@(C0CI)) ; GRAB ONE SECTION
53 . . D PUTRIM1(DFN,C0CI,C0CVARSN)
54 Q
55 ;
56PUTRIM1(DFN,ZZTYP,ZVARS) ; PUT ONE SECTION OF VARIABLES INTO CCR ELEMENTS
57 ; ZVARS IS PASSED BY NAME AN HAS THE FORM @ZVARS@(1,"VAR1")="VAL1"
58 S C0CX=0
59 F S C0CX=$O(@ZVARS@(C0CX)) Q:C0CX="" D ; FOR EACH OCCURANCE
60 . W "ZOCC=",C0CX,!
61 . K C0CMDO ; MULTIPLE SUBELEMENTS FOR THIS OCCURANCE PASSED BY NAME
62 . S C0CV=$NA(@ZVARS@(C0CX)) ; VARIABLES FOR THIS OCCURANCE
63 . D PUTELS(DFN,ZZTYP,C0CX,C0CV) ; PUT THEM TO THE CCR ELEMENTS FILE
64 . I $D(C0CMDO) D ; MULTIPLES TO HANDLE (THIS IS INSTEAD OF RECURSION :()
65 . . N ZZCNT,ZZC0CI,ZZVALS,ZT,ZZCNT,ZV
66 . . S ZZCNT=0
67 . . S ZZC0CI=0
68 . . S ZZVALS=$NA(@C0CMDO@("M")) ; LOCATION OF THIS MULTILPE
69 . . S ZT=$O(@ZZVALS@("")) ; ELEMENT TYPE OF MULTIPLE
70 . . S ZZVALS=$NA(@ZZVALS@(ZT)) ; PAST MULTIPLE TYPE INDICATOR
71 . . W "MULTIPLE:",ZZVALS,!
72 . . ;B
73 . . F S ZZC0CI=$O(@ZZVALS@(ZZC0CI)) Q:ZZC0CI="" D ; EACH MULTIPLE
74 . . . S ZZCNT=ZZCNT+1 ;INCREMENT COUNT
75 . . . W "COUNT:",ZZCNT,!
76 . . . S ZV=$NA(@ZZVALS@(ZZC0CI))
77 . . . D PUTELS(DFN,ZT,C0CX_";"_ZZCNT,ZV)
78 Q
79 ;
80PUTELS(DFN,ZTYPE,ZOCC,ZVALS) ; PUT CCR VALUES INTO THE CCR ELEMENTS FILE
81 ; 171.101, ^C0CE DFN IS THE PATIENT IEN PASSED BY VALUE
82 ; ZTYPE IS THE NODE TYPE IE RESULTS,PROBLEMS PASSED BY VALUE
83 ; ZOCC IS THE OCCURANCE NUMBER IE PROBLEM NUMBER 1,2,3 ETC
84 ; ZVALS ARE THE VARIABLES AND VALUES PASSED BY NAME AND IN THE FORM
85 ; @ZVALS@("VAR1")="VALUE1" FOR ALL VARIABLES IN THIS ELEMENT
86 ; AND @ZVALS@("M",SUBOCCUR,"VAR2")="VALUE2" FOR SUB VARIABLES
87 ;
88 N ZSRC,PATN,ZTYPN,XD0,ZTYP
89 S ZSRC=1 ; CCR SOURCE IS ASSUMED TO BE THIS EHR, WHICH IS ALWAYS SOURCE 1
90 ; PUT THIS IN PARAMETERS - SO SOURCE NUMBER FOR PROCESSING IN CONFIGURABLE
91 N C0CFPAT S C0CFPAT=171.101 ; FILE AT PATIENT LEVEL
92 N C0CFSRC S C0CFSRC=171.111 ; FILE AT CCR SOURCE LVL
93 N C0CFTYP S C0CFTYP=171.121 ; FILE AT ELEMENT TYPE LVL
94 N C0CFOCC S C0CFOCC=171.131 ; FILE AT OCCURANCE LVL
95 N C0CFVAR S C0CFVAR=171.1311 ; FILE AT VARIABLE LVL
96 ;FILE IS ^C0CE(PAT,1,SCR,1,TYP,1,OCC,1,VAR,1, ...
97 ; AND WE HAVE TO ADD THEM LEVEL AT A TIME I THINK
98 N C0CFDA
99 S C0CFDA(C0CFPAT,"?+1,",.01)=DFN
100 D UPDIE ; ADD THE PATIENT
101 S PATN=$O(^C0CE("B",DFN,"")) ; IEN FOR THE PATIENT
102 S C0CFDA(C0CFSRC,"?+1,"_PATN_",",.01)=ZSRC
103 D UPDIE ; ADD THE CCR SOURCE
104 N ZTYPN S ZTYPN=$O(^C0CDIC(170.101,"B",ZTYPE,"")) ; FIND THE ELE TYPE
105 S C0CFDA(C0CFTYP,"?+1,"_ZSRC_","_PATN_",",.01)=ZTYPN
106 D UPDIE ; ADD THE ELEMENT TYPE
107 S ZTYP=$O(^C0CE(PATN,1,ZSRC,1,"B",ZTYPN,"")) ; IEN OF ELEMENT TYPE
108 S C0CFDA(C0CFOCC,"?+1,"_ZTYP_","_ZSRC_","_PATN_",",.01)=" "_ZOCC ; STRING OCC
109 ; OCC IS PRECEDED BY " " TO FORCE STRING STORAGE AND PRESERVE
110 ; STRING COLLATION ON THE INDEX
111 D UPDIE ; ADD THE OCCURANCE
112 S ZD0=$O(^C0CE(PATN,1,ZSRC,1,ZTYP,1,"B"," "_ZOCC,""))
113 W "RECORD NUMBER: ",ZD0,!
114 ;I ZD0=32 B
115 ;I ZD0=31 B
116 N ZCNT,ZC0CI,ZVARN,C0CZ1
117 S ZCNT=0
118 S ZC0CI="" ;
119 F S ZC0CI=$O(@ZVALS@(ZC0CI)) Q:ZC0CI="" D ;
120 . I ZC0CI'="M" D ; NOT A SUBVARIABLE
121 . . S ZCNT=ZCNT+1 ;INCREMENT COUNT
122 . . S ZVARN=$$VARPTR(ZC0CI,ZTYPE) ;GET THE POINTER TO THE VAR IN THE CCR DICT
123 . . ; WILL ALLOW FOR LAYGO IF THE VARIABLE IS NOT FOUND
124 . . S C0CZ1=ZTYP_","_ZSRC_","_PATN_","
125 . . S C0CFDA(C0CFVAR,"?+"_ZCNT_","_ZD0_","_C0CZ1,.01)=ZVARN
126 . . S C0CFDA(C0CFVAR,"?+"_ZCNT_","_ZD0_","_C0CZ1,1)=@ZVALS@(ZC0CI)
127 . E D ; THIS IS A SUBELEMENT
128 . . ;PUT THE FOLLOWING BACK TO USE RECURSION
129 . . ;N ZZCNT,ZZC0CI,ZZVALS,ZT,ZZCNT,ZV
130 . . ;S ZZCNT=0
131 . . ;S ZZC0CI=0
132 . . ;S ZZVALS=$NA(@ZVALS@("M")) ; LOCATION OF THIS MULTILPE
133 . . ;S ZT=$O(@ZZVALS@("")) ; ELEMENT TYPE OF MULTIPLE
134 . . ;S ZZVALS=$NA(@ZZVALS@(ZT)) ; PAST MULTIPLE TYPE INDICATOR
135 . . ;W "MULTIPLE:",ZZVALS,!
136 . . ;B
137 . . ;F S ZZC0CI=$O(@ZZVALS@(ZZC0CI)) Q:ZZC0CI="" D ; EACH MULTIPLE
138 . . ;. S ZZCNT=ZZCNT+1 ;INCREMENT COUNT
139 . . ;. W "COUNT:",ZZCNT,!
140 . . ;. S ZV=$NA(@ZZVALS@(ZZC0CI))
141 . . ;. D PUTELS(DFN,ZT,ZOCC_";"_ZZCNT,ZV) ; PUT THIS BACK TO DEBUG RECURSION
142 . . S C0CMDO=ZVALS ; FLAG TO HANDLE MULTIPLES (INSTEAD OF RECURSION)
143 D UPDIE ; UPDATE
144 Q
145 ;
146UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
147 K ZERR
148 D CLEAN^DILF
149 D UPDATE^DIE("","C0CFDA","","ZERR")
150 I $D(ZERR) D ;
151 . W "ERROR",!
152 . ZWR ZERR
153 . B
154 K C0CFDA
155 Q
156 ;
157PUTELSOLD(DFN,ZTYPE,ZOCC,ZVALS) ; PUT CCR VALUES INTO THE CCR ELEMENTS FILE
158 ; 171.101, ^C0CE DFN IS THE PATIENT IEN PASSED BY VALUE
159 ; ZTYPE IS THE NODE TYPE IE RESULTS,PROBLEMS PASSED BY VALUE
160 ; ZOCC IS THE OCCURANCE NUMBER IE PROBLEM NUMBER 1,2,3 ETC
161 ; ZVALS ARE THE VARIABLES AND VALUES PASSED BY NAME AND IN THE FORM
162 ; @ZVALS@("VAR1")="VALUE1" FOR ALL VARIABLES IN THIS ELEMENT
163 ; AND @ZVALS@("M",SUBOCCUR,"VAR2")="VALUE2" FOR SUB VARIABLES
164 ;
165 S ZSRC=1 ; CCR SOURCE IS ASSUMED TO BE THIS EHR, WHICH IS ALWAYS SOURCE 1
166 ; PUT THIS IN PARAMETERS - SO SOURCE NUMBER FOR PROCESSING IN CONFIGURABLE
167 N ZF,ZFV S ZF=171.101 S ZFV=171.1011
168 ;S ZSUBF=171.20122 ;FILE AND SUBFILE NUMBERS
169 ;N ZSFV S ZSFV=171.201221 ; SUBFILE VARIABLE FILE NUMBER
170 N ZTYPN S ZTYPN=$O(^C0CDIC(170.101,"B",ZTYPE,""))
171 W "ZTYPE: ",ZTYPE," ",ZTYPN,!
172 N ZVARN ; IEN OF VARIABLE BEING PROCESSED
173 ;N C0CFDA ; FDA FOR CCR ELEMENT UPDATE
174 K C0CFDA
175 S C0CFDA(ZF,"?+1,",.01)=DFN
176 S C0CFDA(ZF,"?+1,",.02)=ZSRC
177 S C0CFDA(ZF,"?+1,",.03)=ZTYPN
178 S C0CFDA(ZF,"?+1,",.04)=" "_ZOCC ;CREATE OCCURANCE
179 K ZERR
180 ;B
181 D UPDATE^DIE("","C0CFDA","","ZERR") ;ASSIGN RECORD NUMBER
182 I $D(ZERR) B ;OOPS
183 K C0CFDA
184 S ZD0=$O(^C0CE("C",DFN,ZSRC,ZTYPN,ZOCC,""))
185 W "RECORD NUMBER: ",ZD0,!
186 ;B
187 S ZCNT=0
188 S ZC0CI="" ;
189 F S ZC0CI=$O(@ZVALS@(ZC0CI)) Q:ZC0CI="" D ;
190 . I ZC0CI'="M" D ; NOT A SUBVARIABLE
191 . . S ZCNT=ZCNT+1 ;INCREMENT COUNT
192 . . S ZVARN=$$VARPTR(ZC0CI,ZTYPE) ;GET THE POINTER TO THE VAR IN THE CCR DICT
193 . . ; WILL ALLOW FOR LAYGO IF THE VARIABLE IS NOT FOUND
194 . . S C0CFDA(ZFV,"?+"_ZCNT_","_ZD0_",",.01)=ZVARN
195 . . S C0CFDA(ZFV,"?+"_ZCNT_","_ZD0_",",1)=@ZVALS@(ZC0CI)
196 . . ;S C0CFDA(ZSFV,"+1,"_DFN_","_ZSRC_","_ZTYPN_","_ZOCC_",",.01)=ZVARN
197 . . ;S C0CFDA(ZSFV,"+1,"_DFN_","_ZSRC_","_ZTYPN_","_ZOCC_",",1)=@ZVALS@(ZC0CI)
198 ;S GT1(170,"?+1,",.01)="ZZZ NEW MEDVEHICLETEXT"
199 ;S GT1(170,"?+1,",12)="DIR"
200 ;S GT1(171.201221,"?+1,1,5,1,",.01)="ZZZ NEW MEDVEHICLETEXT"
201 ;S GT1(171.201221,"+1,1,5,1,",1)="THIRD NEW MED DIRECTION TEXT"
202 D CLEAN^DILF
203 D UPDATE^DIE("","C0CFDA","","ZERR")
204 I $D(ZERR) D ;
205 . W "ERROR",!
206 . ZWR ZERR
207 . B
208 K C0CFDA
209 Q
210 ;
211VARPTR(ZVAR,ZTYP) ;EXTRINSIC WHICH RETURNS THE POINTER TO ZVAR IN THE
212 ; CCR DICTIONARY. IT IS LAYGO, AS IT WILL ADD THE VARIABLE TO
213 ; THE CCR DICTIONARY IF IT IS NOT THERE. ZTYP IS REQUIRED FOR LAYGO
214 ;
215 N ZCCRD,ZVARN,C0CFDA2
216 S ZCCRD=170 ; FILE NUMBER FOR CCR DICTIONARY
217 S ZVARN=$O(^C0CDIC(170,"B",ZVAR,"")) ;FIND IEN OF VARIABLE
218 I ZVARN="" D ; VARIABLE NOT IN CCR DICTIONARY - ADD IT
219 . I '$D(ZTYP) D Q ; WON'T ADD A VARIABLE WITHOUT A TYPE
220 . . W "CANNOT ADD VARIABLE WITHOUT A TYPE: ",ZVAR,!
221 . S C0CFDA2(ZCCRD,"?+1,",.01)=ZVAR ; NAME OF NEW VARIABLE
222 . S C0CFDA2(ZCCRD,"?+1,",12)=ZTYP ; TYPE EXTERNAL OF NEW VARIABLE
223 . D CLEAN^DILF ;MAKE SURE ERRORS ARE CLEAN
224 . D UPDATE^DIE("E","C0CFDA2","","ZERR") ;ADD VAR TO CCR DICTIONARY
225 . I $D(ZERR) D ; LAYGO ERROR
226 . . W "ERROR ADDING "_ZC0CI_" TO CCR DICTIONARY",!
227 . E D ;
228 . . D CLEAN^DILF ; CLEAN UP
229 . . S ZVARN=$O(^C0CDIC(170,"B",ZVAR,"")) ;FIND IEN OF VARIABLE
230 . . W "ADDED ",ZVAR," TO CCR DICTIONARY, IEN:",ZVARN,!
231 Q ZVARN
232 ;
233BLDTYPS ; ROUTINE TO POPULATE THE CCR NODE TYPES FILE (^C0CDIC(170.101,)
234 ; THE CCR DICTIONARY (^C0CDIC(170, ) HAS MOST OF WHAT'S NEEDED
235 ;
236 N C0CDIC,C0CNODE ;
237 S C0CDIC=$$FILEREF^C0CRNF(170) ; CLOSED FILE REFERENCE TO THE CCR DICTIONARY
238 S C0CNODE=$$FILEREF^C0CRNF(170.101) ; CLOSED REF TO CCR NODE TYPE FILE
239 Q
240 ;
241FIXSEC ;FIX THE SECTION FIELD OF THE CCR DICTIONARY.. IT HAS BEEN REDEFINED
242 ; AS A POINTER TO CCR NODE TYPE INSTEAD OF BEING A SET
243 ; THE SET VALUES ARE PRESERVED IN ^KBAI("SECTION") TO FACILITATE THIS
244 ; CONVERSION
245 ;N C0CC,C0CI,C0CJ,C0CN,C0CZX
246 D FIELDS^C0CRNF("C0CC",170)
247 S C0CI=""
248 F S C0CI=$O(^KBAI("SECTION",C0CI)) Q:C0CI="" D ; EACH SECTION
249 . S C0CZX=""
250 . F S C0CZX=$O(^KBAI("SECTION",C0CI,C0CZX)) Q:C0CZX="" D ; EACH VARIABLE
251 . . W "SECTION ",C0CI," VAR ",C0CZX
252 . . S C0CV=$O(^C0CDIC(170.101,"B",C0CI,""))
253 . . W " TYPE: ",C0CV,!
254 . . D SETFDA("SECTION",C0CV)
255 . . ;ZWR C0CFDA
256 Q
257 ;
258SETFDA(C0CSN,C0CSV) ; INTERNAL ROUTINE TO MAKE AN FDA ENTRY FOR FIELD C0CSN
259 ; TO SET TO VALUE C0CSV.
260 ; C0CFDA,C0CC,C0CZX ARE ASSUMED FROM THE CALLING ROUTINE
261 ; C0CSN,C0CSV ARE PASSED BY VALUE
262 ;
263 N C0CSI,C0CSJ
264 S C0CSI=$$ZFILE(C0CSN,"C0CC") ; FILE NUMBER
265 S C0CSJ=$$ZFIELD(C0CSN,"C0CC") ; FIELD NUMBER
266 S C0CFDA(C0CSI,C0CZX_",",C0CSJ)=C0CSV
267 Q
268ZFILE(ZFN,ZTAB) ; EXTRINSIC TO RETURN FILE NUMBER FOR FIELD NAME PASSED
269 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 1 OF C0CA(ZFN)
270 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
271 I '$D(ZTAB) S ZTAB="C0CA"
272 N ZR
273 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",1)
274 E S ZR=""
275 Q ZR
276ZFIELD(ZFN,ZTAB) ;EXTRINSIC TO RETURN FIELD NUMBER FOR FIELD NAME PASSED
277 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 2 OF C0CA(ZFN)
278 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
279 I '$D(ZTAB) S ZTAB="C0CA"
280 N ZR
281 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",2)
282 E S ZR=""
283 Q ZR
284 ;
285ZVALUE(ZFN,ZTAB) ;EXTRINSIC TO RETURN VALUE FOR FIELD NAME PASSED
286 ; BY VALUE IN ZFN. FILE NUMBER IS PIECE 3 OF C0CA(ZFN)
287 ; IF ZTAB IS NULL, IT DEFAULTS TO C0CA
288 I '$D(ZTAB) S ZTAB="C0CA"
289 N ZR
290 I $D(@ZTAB@(ZFN)) S ZR=$P(@ZTAB@(ZFN),"^",3)
291 E S ZR=""
292 Q ZR
293 ;
Note: See TracBrowser for help on using the repository browser.