source: ccr/trunk/p/C0CXEWD.m@ 1693

Last change on this file since 1693 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/C0CXEWD.m1290
    /ccr/branches/ohum/p/C0CXEWD.m1291-1543
    /ccr/branches/ohum/p/p/C0CXEWD.m1287-1289
File size: 4.2 KB
Line 
1C0CXEWD ; C0C/GPL - EWD based XPath utilities; 10/11/09
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 Q
19 ;
20TEST ;
21 D XPATH($$FIRST($$ID("CCR1")),"/","GIDX","GARY")
22 Q
23 ;
24TEST2 ;
25 S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
26 D XPATH($$FIRST($$ID("gpl")),"/","GIDX","GARY","",REDUX)
27 Q
28 ;
29XPATH(ZOID,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; RECURSIVE ROUTINE TO POPULATE
30 ; THE XPATH INDEX ZXIDX, PASSED BY NAME
31 ; THE XPATH ARRAY XPARY, PASSED BY NAME
32 ; ZOID IS THE STARTING OID
33 ; ZPATH IS THE STARTING XPATH, USUALLY "/"
34 ; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
35 ; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
36 I '$D(ZREDUX) S ZREDUX=""
37 N NEWPATH
38 N NEWNUM S NEWNUM=""
39 I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
40 S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
41 I $G(ZREDUX)'="" D ; REDUX PROVIDED?
42 . N GT S GT=$P(NEWPATH,ZREDUX,2)
43 . I GT'="" S NEWPATH=GT
44 S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
45 N GD D DATA("GD",ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
46 I $D(GD(2)) M @ZXPARY@(NEWPATH)=GD ; IF MULITPLE DATA MERGE TO THE ARRAY
47 E I $D(GD(1)) S @ZXPARY@(NEWPATH)=GD(1) ; IF SINGLE VALUE, ADD TO ARRAY
48 I GD'="" S @ZXPARY@(NEWPATH)=GD ; IF YES, ADD IT TO THE XPATH ARRAY
49 N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
50 I ZFRST'="" D ; THERE IS A CHILD
51 . N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
52 . D XPATH(ZFRST,NEWPATH,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; DO THE CHILD
53 N GNXT S GNXT=$$NXTSIB(ZOID)
54 I GNXT'="" D ; MOVE ON TO THE NEXT SIBLING
55 . D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; DO NEXT SIB
56 Q
57 ;
58PARSE(INXML,INDOC) ;CALL THE EWD PARSER ON INXML, PASSED BY NAME
59 ; INDOC IS PASSED AS THE DOCUMENT NAME TO EWD
60 ; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY EWD
61 N ZR
62 M ^CacheTempEWD($j)=@INXML ;
63 S ZR=$$parseDocument^%zewdHTMLParser(INDOC)
64 Q ZR
65 ;
66ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
67 N ZN
68 S ZN=$$NXTSIB(ZOID)
69 I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
70 Q 0
71 ;
72DETAIL(ZRTN,ZOID) ; RETURNS DETAIL FOR NODE ZOID IN ZRTN, PASSED BY NAME
73 N DET
74 D getElementDetails^%zewdXPath(ZOID,.DET)
75 M @ZRTN=DET
76 Q
77 ;
78ID(ZNAME) ;RETURNS THE docOID OF THE DOCUMENT NAMED ZNAME
79 Q $$getDocumentNode^%zewdDOM(ZNAME)
80 ;
81NAME(ZOID) ;RETURNS THE NAME OF THE DOCUMENAT WITH docOID ZOID
82 Q $$getDocumentName^%zewdDOM(ZOID)
83 ;
84FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
85 N GOID
86 S GOID=ZOID
87 S GOID=$$getFirstChild^%zewdDOM(GOID)
88 I GOID="" Q ""
89 I $$getNodeType^%zewdDOM(GOID)'=1 S GOID=$$NXTCHLD(GOID)
90 Q GOID
91 ;
92HASCHILD(ZOID) ; RETURNS TRUE IF ZOID HAS CHILD NODES
93 Q $$hasChildNodes^%zewdDOM(ZOID)
94 ;
95CHILDREN(ZRTN,ZOID) ;RETURNS CHILDREN OF ZOID IN ARRAY ZRTN, PASSED BY NAME
96 N childArray
97 d getChildrenInOrder^%zewdDOM(ZOID,.childArray)
98 m @ZRTN=childArray
99 q
100 ;
101TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
102 Q $$getName^%zewdDOM(ZOID)
103 ;
104NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
105 Q $$getNextSibling^%zewdDOM(ZOID)
106 ;
107NXTCHLD(ZOID) ; RETURNS THE NEXT CHILD IN PARENT ZPAR
108 N GOID
109 S GOID=$$getNextChild^%zewdDOM($$PARENT(ZOID),ZOID)
110 I GOID="" Q ""
111 I $$getNodeType^%zewdDOM(GOID)'=1 S GOID=$$NXTCHLD(GOID)
112 Q GOID
113 ;
114PARENT(ZOID) ; RETURNS PARENT OF ZOID
115 Q $$getParentNode^%zewdDOM(ZOID)
116 ;
117DATA(ZT,ZOID) ; RETURNS DATA FOR THE NODE
118 N ZT2
119 S ZT2=$$getElementText^%zewdDOM(ZOID,.ZT2)
120 M @ZT=ZT2
121 Q
122 ;Q $$getTextValue^%zewdXPath(ZOID)
123 ;Q $$getData^%zewdDOM(ZOID,.ZT)
124 ;
Note: See TracBrowser for help on using the repository browser.