source: ccr/trunk/p/C0CMXML.m@ 587

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

now handles multiple lines of text in DATA

File size: 3.4 KB
Line 
1C0CMXML ; ERX/GPL - MXML based XPath utilities;10/13/09 17:05
2 ;;0.1;C0P;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 Q
21 ;
22TEST ;
23 S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
24 K GARY
25 W $$FTG^%ZISH("/home/vademo2/EHR/p/","mxml-test.xml",$NA(@C0CXMLIN@(1)),3)
26 S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DocID: ",C0CDOCID
27 S REDUX="//ContinuityOfCareRecord/Body"
28 D XPATH(1,"/","GIDX","GARY",,REDUX)
29 Q
30 ;
31TEST2 ;
32 S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
33 D XPATH(1,"/","GIDX","GARY","",REDUX)
34 Q
35 ;
36XPATH(ZOID,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; RECURSIVE ROUTINE TO POPULATE
37 ; THE XPATH INDEX ZXIDX, PASSED BY NAME
38 ; THE XPATH ARRAY XPARY, PASSED BY NAME
39 ; ZOID IS THE STARTING OID
40 ; ZPATH IS THE STARTING XPATH, USUALLY "/"
41 ; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
42 ; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
43 I $G(ZREDUX)="" S ZREDUX=""
44 N NEWPATH
45 N NEWNUM S NEWNUM=""
46 I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
47 S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
48 I $G(ZREDUX)'="" D ; REDUX PROVIDED?
49 . N GT S GT=$P(NEWPATH,ZREDUX,2)
50 . I GT'="" S NEWPATH=GT
51 S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
52 N GD D DATA("GD",ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
53 I $D(GD(2)) M @ZXPARY@(NEWPATH)=GD ; IF MULITPLE DATA MERGE TO THE ARRAY
54 E I $D(GD(1)) S @ZXPARY@(NEWPATH)=GD(1) ; IF SINGLE VALUE, ADD TO ARRAY
55 N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
56 I ZFRST'=0 D ; THERE IS A CHILD
57 . N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
58 . D XPATH(ZFRST,NEWPATH,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; DO THE CHILD
59 N GNXT S GNXT=$$NXTSIB(ZOID)
60 I GNXT'=0 D ;
61 . D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; DO NEXT SIB
62 Q
63 ;
64PARSE(INXML,INDOC) ;CALL THE MXML PARSER ON INXML, PASSED BY NAME
65 ; INDOC IS PASSED AS THE DOCUMENT NAME - DON'T KNOW WHERE TO STORE THIS NOW
66 ; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY MXML
67 ;Q $$EN^MXMLDOM(INXML)
68 Q $$EN^MXMLDOM(INXML,"W")
69 ;
70ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
71 N ZN
72 S ZN=$$NXTSIB(ZOID)
73 I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
74 Q 0
75 ;
76FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
77 Q $$CHILD^MXMLDOM(C0CDOCID,ZOID)
78 ;
79TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
80 Q $$NAME^MXMLDOM(C0CDOCID,ZOID)
81 ;
82NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
83 Q $$SIBLING^MXMLDOM(C0CDOCID,ZOID)
84 ;
85DATA(ZT,ZOID) ; RETURNS DATA FOR THE NODE
86 ;N ZT,ZN S ZT=""
87 ;S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
88 ;Q $G(@C0CDOM@(ZOID,"T",1))
89 S ZN=$$TEXT^MXMLDOM(C0CDOCID,ZOID,ZT)
90 Q
91 ;
Note: See TracBrowser for help on using the repository browser.