source: ccr/branches/ohum/p/C0CXEWD.m@ 1293

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

updates to web services support

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