source: ccr/trunk/p/C0CNHIN.m@ 1588

Last change on this file since 1588 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/C0CNHIN.m1290
    /ccr/branches/ohum/p/C0CNHIN.m1291-1543
    /ccr/branches/ohum/p/p/C0CNHIN.m1287-1289
File size: 10.1 KB
Line 
1C0CNHIN ; GPL - PROCESSING FOR OUTPUT OF NHINV ROUTINES;6/3/11 17:05
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ;Copyright 2011 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 Q
19EN(ZRTN,ZDFN,ZPART,KEEP) ; GENERATE AN NHIN ARRAY FOR A PATIENT
20 ;
21 K GARY,GNARY,GIDX,C0CDOCID
22 N GN
23 K ^TMP("NHINV",$J) ; CLEAN UP FROM LAST CALL
24 K ^TMP("MXMLDOM",$J) ; CLEAN UP DOM
25 K ^TMP("MXMLERR",$J) ; CLEAN UP MXML ERRORS
26 D GET^NHINV(.GN,ZDFN,ZPART) ; CALL NHINV ROUTINES TO PULL XML
27 S GN=$P(GN,")",1)_")" ; CUT OFF THE REST OF LINE PROTOCOL
28 S C0CDOCID=$$PARSE(GN,"NHINARRAY") ; PARSE WITH MXML
29 D DOMO^C0CDOM(C0CDOCID,"/","ZRTN","GIDX","GARY",,"/results/") ; BLD ARRAYS
30 I '$G(KEEP) K GIDX,GARY ; GET RID OF THE ARRAYS UNLESS KEEP=1
31 ;D PROCESS("ZRTN",GN,"/result/",$G(KEEP))
32 Q
33 ;
34PQRI(ZOUT,KEEP) ; RETURN THE NHIN ARRAY FOR THE PQRI XML TEMPLATE
35 ;
36 N ZG
37 S ZG=$NA(^TMP("PQRIXML",$J))
38 K @ZG
39 D GETXML^C0CMXP(ZG,"PQRIXML") ; GET THE XML FROM C0C MISC XML
40 N C0CDOCID
41 S C0CDOCID=$$PARSE^C0CDOM(ZG,"PQRIXML") ; PARSE THE XML
42 D DOMO^C0CDOM(C0CDOCID,"/","ZOUT","GIDX","GARY",,"//submission") ; BLD ARRAYS
43 I '$G(KEEP) K GIDX,GARY ; GET RID OF THE ARRAYS UNLESS KEEP=1
44 Q
45 ;
46PQRI2(ZRTN) ; RETURN THE NHIN ARRAY FOR PQRI ONE MEASURE
47 ;
48 ;N GG
49 D GETXML^C0CMXP("GG","PQRI ONE MEASURE")
50 D PROCESS(ZRTN,"GG","root",1)
51 Q
52 ;
53PROCESS(ZRSLT,ZXML,ZREDUCE,KEEP) ; PARSE AND RUN DOMO ON XML
54 ; ZRTN IS PASSED BY REFERENCE
55 ; ZXML IS PASSED BY NAME
56 ; IF KEEP IS 1, GARY AND GIDX ARE NOT KILLED
57 ;
58 N GN
59 S GN=$NA(^TMP("C0CPROCESS",$J))
60 K @GN
61 M @GN=@ZXML
62 S C0CDOCID=$$PARSE(GN,"NHINARRAY") ; PARSE WITH MXML
63 K @GN
64 D DOMO^C0CDOM(C0CDOCID,"/","ZRSLT","GIDX","GARY",,$G(ZREDUCE)) ; BLD ARRAYS
65 I '$G(KEEP) K GIDX,GARY ; GET RID OF THE ARRAYS UNLESS KEEP=1
66 Q
67 ;
68LOADSMRT ;
69 ;
70 K ^GPL("SMART")
71 S GN=$NA(^GPL("SMART",1))
72 I $$FTG^%ZISH("/home/george/","alex-lewis2.xml",GN,2) W !,"SMART FILE LOADED"
73 Q
74 ;
75SMART ; TRY IT WITH SMART
76 ;
77 S GN=$NA(^GPL("SMART"))
78 ;K ^TMP("MXMLDOM",$J)
79 K ^TMP("MXMLERR",$J)
80 S C0CDOCID=$$PARSE(GN,"SMART")
81 D DOMO^C0CDOM(C0CDOCID,"/","GNARY","GIDX","GARY",,"//rdf:RDF/")
82 ;K ^TMP("MXMLDOM",$J) ;CLEAN UP... IT'S BIG
83 Q
84 ;
85CCR ; TRY IT WITH A CCR
86 ;
87 S GN=$NA(^GPL("CCR"))
88 ;K ^TMP("MXMLDOM",$J)
89 K ^TMP("MXMLERR",$J)
90 S C0CDOCID=$$PARSE(GN,"CCR")
91 D DOMO^C0CDOM(C0CDOCID,"/","GNARY","GIDX","GARY",,"//ContinuityOfCareRecord/Body/")
92 ;K ^TMP("MXMLDOM",$J) ;CLEAN UP... IT'S BIG
93 Q
94 ;
95MED ; TRY IT WITH A CCR MED SECTION
96 ;
97 S GN=$NA(^GPL("MED"))
98 K ^TMP("MXMLDOM",$J)
99 K ^TMP("MXMLERR",$J)
100 S C0CDOCID=$$PARSE(GN,"MED")
101 D DOMO^C0CDOM(C0CDOCID,"/","GNARY","GIDX","GARY",,"//Medications/")
102 ;K ^TMP("MXMLDOM",$J) ;CLEAN UP... IT'S BIG
103 Q
104 ;
105CCD ; TRY IT WITH A CCD
106 ;
107 S GN=$NA(^GPL("CCD"))
108 ;K ^TMP("MXMLDOM",$J)
109 K ^TMP("MXMLERR",$J)
110 S C0CDOCID=$$PARSE(GN,"CCD")
111 D DOMO^C0CDOM(C0CDOCID,"/","GNARY","GIDX","GARY",,"//ClinicalDocument/component/structuredBody/")
112 ;K ^TMP("MXMLDOM",$J) ;CLEAN UP... IT'S BIG
113 Q
114 ;
115TEST1 ; TEST NHINV OUTPUT IN ^GPL("NIHIN")
116 ; PARSED WITH MXML
117 ; RUN THROUGH XPATH
118 K GARY,GIDX,C0CDOCID
119 S GN=$NA(^GPL("NHIN"))
120 ;S GN=$NA(^GPL("DOMI"))
121 S C0CDOCID=$$PARSE(GN,"GPLTEST")
122 D DOMO^C0CDOM(C0CDOCID,"/","GNARY","GIDX","GARY",,"/results/")
123 K ^GPL("GNARY")
124 M ^GPL("GNARY")=GNARY
125 Q
126 ;
127TEST2 ; PUT GNARY THROUGH DOMI AND STORE XML IN ^GPL("DOMI")
128 ;
129 S GN=$NA(^GPL("GNARY"))
130 S C0CDOCID=$$DOMI^C0CDOM(GN,,"results")
131 D OUTXML^C0CDOM("G",C0CDOCID)
132 K ^GPL("DOMI")
133 M ^GPL("DOMI")=G
134 Q
135 ;
136TEST3 ; TEST NHINV OUTPUT IN ^GPL("NIHIN")
137 ; PARSED WITH MXML
138 ; RUN THROUGH XPATH
139 K GARY,GIDX,C0CDOCID
140 ;S GN=$NA(^GPL("NHIN"))
141 S GN=$NA(^GPL("DOMI"))
142 S C0CDOCID=$$PARSE(GN,"GPLTEST")
143 D DOMO^C0CDOM(C0CDOCID,"/","GNARY","GIDX","GARY",,"/results/")
144 Q
145 ;
146DOMO(ZOID,ZPATH,ZNARY,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; RECURSIVE ROUTINE TO POPULATE
147 ; THE XPATH INDEX ZXIDX, PASSED BY NAME
148 ; THE XPATH ARRAY XPARY, PASSED BY NAME
149 ; ZOID IS THE STARTING OID
150 ; ZPATH IS THE STARTING XPATH, USUALLY "/"
151 ; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
152 ; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
153 I $G(ZREDUX)="" S ZREDUX=""
154 N NEWPATH,NARY ; NEWPATH IS AN XPATH NARY IS AN NHIN MUMPS ARRAY
155 N NEWNUM S NEWNUM=""
156 I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
157 S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
158 I $G(ZREDUX)'="" D ; REDUX PROVIDED?
159 . N GT S GT=$P(NEWPATH,ZREDUX,2)
160 . I GT'="" S NEWPATH=GT
161 S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
162 N GA D ATT("GA",ZOID) ; GET ATTRIBUTES FOR THIS NODE
163 I $D(GA) D ; PROCESS THE ATTRIBUTES
164 . N ZI S ZI=""
165 . F S ZI=$O(GA(ZI)) Q:ZI="" D ; FOR EACH ATTRIBUTE
166 . . N ZP S ZP=NEWPATH_"/"_ZI ; PATH FOR ATTRIBUTE
167 . . S @ZXPARY@(ZP)=GA(ZI) ; ADD THE ATTRIBUTE XPATH TO THE XP ARRAY
168 . . I GA(ZI)'="" D ADDNARY(ZP,GA(ZI)) ; ADD THE NHIN ARRAY VALUE
169 N GD D DATA("GD",ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
170 I $D(GD(2)) D ;
171 . M @ZXPARY@(NEWPATH)=GD ; IF MULITPLE DATA MERGE TO THE ARRAY
172 E I $D(GD(1)) D ;
173 . S @ZXPARY@(NEWPATH)=GD(1) ; IF SINGLE VALUE, ADD TO ARRAY
174 . I GD(1)'="" D ADDNARY(NEWPATH,GD(1)) ; ADD TO NHIN ARRAY
175 N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
176 I ZFRST'=0 D ; THERE IS A CHILD
177 . N ZNUM
178 . N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
179 . D DOMO(ZFRST,NEWPATH,ZNARY,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; THE CHILD
180 N GNXT S GNXT=$$NXTSIB(ZOID)
181 I $$TAG(GNXT)'=$$TAG(ZOID) S ZNUM="" ; RESET COUNTING AFTER MULTIPLES
182 I GNXT'=0 D ;
183 . N ZMULT S ZMULT=$$ISMULT(GNXT) ; IS THE SIBLING A MULTIPLE?
184 . I (ZNUM="")&(ZMULT) D ; SIBLING IS FIRST OF MULTIPLES
185 . . N ZNUM S ZNUM=1 ;
186 . . D DOMO(GNXT,ZPATH,ZNARY,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; DO NEXT SIB
187 . E D DOMO(GNXT,ZPATH,ZNARY,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; SIB
188 Q
189 ;
190ADDNARY(ZXP,ZVALUE) ; ADD AN NHIN ARRAY VALUE TO ZNARY
191 ;
192 N ZZI,ZZJ,ZZN
193 S ZZI=$P(ZXP,"/",1) ; FIRST PIECE OF XPATH ARRAY
194 I ZZI="" Q ; DON'T ADD THIS ONE .. PROBABLY THE //results NODE
195 S ZZJ=$P(ZXP,ZZI_"/",2) ; REST OF XPATH ARRAY
196 S ZZJ=$TR(ZZJ,"/",".") ; REPLACE / WITH .
197 I ZZI'["]" D ; A SINGLETON
198 . S ZZN=1
199 E D ; THERE IS AN [x] OCCURANCE
200 . S ZZN=$P($P(ZZI,"[",2),"]",1) ; PULL OUT THE OCCURANCE
201 . S ZZI=$P(ZZI,"[",1) ; TAKE OUT THE [X]
202 I ZZJ'="" S @ZNARY@(ZZI,ZZN,ZZJ)=ZVALUE
203 Q
204 ;
205PARSE(INXML,INDOC) ;CALL THE MXML PARSER ON INXML, PASSED BY NAME
206 ; INDOC IS PASSED AS THE DOCUMENT NAME - DON'T KNOW WHERE TO STORE THIS NOW
207 ; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY MXML
208 ;Q $$EN^MXMLDOM(INXML)
209 Q $$EN^MXMLDOM(INXML,"W")
210 ;
211ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
212 N ZN
213 ;I $$TAG(ZOID)["entry" B
214 S ZN=$$NXTSIB(ZOID)
215 I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
216 Q 0
217 ;
218FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
219 Q $$CHILD^MXMLDOM(C0CDOCID,ZOID)
220 ;
221PARENT(ZOID) ;RETURNS THE OID OF THE PARENT OF ZOID
222 Q $$PARENT^MXMLDOM(C0CDOCID,ZOID)
223 ;
224ATT(RTN,NODE) ;GET ATTRIBUTES FOR ZOID
225 S HANDLE=C0CDOCID
226 K @RTN
227 D GETTXT^MXMLDOM("A")
228 Q
229 ;
230TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
231 ;I ZOID=149 B ;GPLTEST
232 N X,Y
233 S Y=""
234 S X=$G(C0CCBK("TAG")) ;IS THERE A CALLBACK FOR THIS ROUTINE
235 I X'="" X X ; EXECUTE THE CALLBACK, SHOULD SET Y
236 I Y="" S Y=$$NAME^MXMLDOM(C0CDOCID,ZOID)
237 Q Y
238 ;
239NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
240 Q $$SIBLING^MXMLDOM(C0CDOCID,ZOID)
241 ;
242DATA(ZT,ZOID) ; RETURNS DATA FOR THE NODE
243 ;N ZT,ZN S ZT=""
244 ;S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
245 ;Q $G(@C0CDOM@(ZOID,"T",1))
246 S ZN=$$TEXT^MXMLDOM(C0CDOCID,ZOID,ZT)
247 Q
248 ;
249OUTXML(ZRTN,INID) ; USES C0CMXMLB (MXMLBLD) TO OUTPUT XML FROM AN MXMLDOM
250 ;
251 S C0CDOCID=INID
252 D START^C0CMXMLB($$TAG(1),,"G")
253 D NDOUT($$FIRST(1))
254 D END^C0CMXMLB ;END THE DOCUMENT
255 M @ZRTN=^TMP("MXMLBLD",$J)
256 K ^TMP("MXMLBLD",$J)
257 Q
258 ;
259NDOUT(ZOID) ;CALLBACK ROUTINE - IT IS RECURSIVE
260 N ZI S ZI=$$FIRST(ZOID)
261 I ZI'=0 D ; THERE IS A CHILD
262 . N ZATT D ATT("ZATT",ZOID) ; THESE ARE THE ATTRIBUTES MOVED TO ZATT
263 . D MULTI^C0CMXMLB("",$$TAG(ZOID),.ZATT,"NDOUT^C0CMXML(ZI)") ;HAVE CHILDREN
264 E D ; NO CHILD - IF NO CHILDREN, A NODE HAS DATA, IS AN ENDPOINT
265 . ;W "DOING",ZOID,!
266 . N ZD D DATA("ZD",ZOID) ;NODES WITHOUT CHILDREN HAVE DATA
267 . N ZATT D ATT("ZATT",ZOID) ;ATTRIBUTES
268 . D ITEM^C0CMXMLB("",$$TAG(ZOID),.ZATT,$G(ZD(1))) ;NO CHILDREN
269 I $$NXTSIB(ZOID)'=0 D ; THERE IS A SIBLING
270 . D NDOUT($$NXTSIB(ZOID)) ;RECURSE FOR SIBLINGS
271 Q
272 ;
273WNHIN(ZDFN) ; WRITES THE XML OUTPUT OF GET^NHINV TO AN XML FILE
274 ;
275 N GN,GN2
276 D GET^NHINV(.GN,ZDFN) ; EXTRACT THE XML
277 S GN2=$NA(@GN@(1))
278 W $$OUTPUT^C0CXPATH(GN2,"nhin_"_ZDFN_".xml","/home/wvehr3-09/")
279 Q
280 ;
281TESTNARY ; TEST MAKING A NHIN ARRAY
282 N ZI S ZI=""
283 N ZH ; DOM HANDLE
284 D TEST1 ; PARSE AN NHIN RESULT INTO THE DOM
285 S ZH=C0CDOCID ; SET THE HANDLE
286 N ZD S ZD=$NA(^TMP("MXMLDOM",$J,ZH))
287 F S ZI=$O(@ZD@(ZI)) Q:ZI="" D ; FOR EACH NODE
288 . N ZATT
289 . D MNARY(.ZATT,ZH,ZI)
290 . N ZPRE,ZN
291 . S ZPRE=$$PRE(ZI)
292 . S ZN=$P(ZPRE,",",2)
293 . S ZPRE=$P(ZPRE,",",1)
294 . ;I $D(ZATT) ZWR ZATT
295 . N ZJ S ZJ=""
296 . F S ZJ=$O(ZATT(ZJ)) Q:ZJ="" D ; FOR EACH ATTRIBUTE
297 . . W ZPRE_"["_ZN_"]"_$$TAG(ZI)_"."_ZJ_"="_ZATT(ZJ),!
298 . . S GOUT(ZPRE,ZN,$$TAG(ZI)_"."_ZJ)=ZATT(ZJ)
299 Q
300 ;
301PRE(ZNODE) ; EXTRINSIC WHICH RETURNS THE PREFIX FOR A NODE
302 ;
303 N GI,GI2,GPT,GJ,GN
304 S GI=$$PARENT(ZNODE) ; PARENT NODE
305 I GI=0 Q "" ; NO PARENT
306 S GPT=$$TAG(GI) ; TAG OF PARENT
307 S GI2=$$PARENT(GI) ; PARENT OF PARENT
308 I (GI2'=0)&($$TAG(GI2)'="results") S GPT=$$TAG(GI2)_"."_GPT
309 S GJ=$$FIRST(GI) ; NODE OF FIRST SIB
310 I GJ=ZNODE Q:$$TAG(GI)_",1"
311 F GN=2:1 Q:GJ=ZNODE D ;
312 . S GJ=$$NXTSIB(GJ) ; NEXT SIBLING
313 Q GPT_","_GN
314 ;
315MNARY(ZRTN,ZHANDLE,ZOID) ; MAKE A NHIN ARRAY FROM A DOM NODE
316 ; RETURNED IN ZRTN, PASSED BY REFERENCE
317 ; ZHANDLE IS THE DOM DOCUMENT ID
318 ; ZOID IS THE DOM NODE
319 D ATT("ZRTN",ZOID)
320 Q
321 ;
Note: See TracBrowser for help on using the repository browser.