source: smart/trunk/p/C0SNHIN.m@ 1672

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

Updated license for routines

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