source: ccr/trunk/p/C0CFM3.m@ 1755

Last change on this file since 1755 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

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