source: ePrescribing/trunk/p/C0PXEWD.m@ 1703

Last change on this file since 1703 was 1595, checked in by George Lilly, 12 years ago

initial release of ePrescribing

File size: 4.9 KB
Line 
1C0PXEWD ; ERX/GPL - EWD based XPath utilities; 10/11/09 ; 5/4/12 4:29pm
2 ;;1.0;C0P;;Apr 25, 2012;Build 103
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 ;
22 ; gpl July, 2010. This routine interfaces with EWD to generate an XPath
23 ; array from an XML file. It recursively visits the EWD DOM and creates
24 ; an XPath index, an XPath array of node values, and an XPath template
25 ; in three different variables. It is used to prepare incoming xml for
26 ; processing by applications.
27 ;
28TEST ;
29 D XPATH($$FIRST($$ID("CCR1")),"/","GIDX","GARY")
30 Q
31 ;
32TEST2 ;
33 S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
34 D XPATH($$FIRST($$ID("gpl")),"/","GIDX","GARY","",REDUX)
35 Q
36 ;
37XPATH(ZOID,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; RECURSIVE ROUTINE TO POPULATE
38 ; THE XPATH INDEX ZXIDX, PASSED BY NAME
39 ; THE XPATH ARRAY XPARY, PASSED BY NAME
40 ; ZOID IS THE STARTING OID
41 ; ZPATH IS THE STARTING XPATH, USUALLY "/"
42 ; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
43 ; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
44 I '$D(ZREDUX) S ZREDUX=""
45 N NEWPATH
46 N NEWNUM S NEWNUM=""
47 I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
48 S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
49 I $G(ZREDUX)'="" D ; REDUX PROVIDED?
50 . N GT S GT=$P(NEWPATH,ZREDUX,2)
51 . I GT'="" S NEWPATH=GT
52 S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
53 N GD D DATA("GD",ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
54 I $D(GD(2)) M @ZXPARY@(NEWPATH)=GD ; IF MULITPLE DATA MERGE TO THE ARRAY
55 E I $D(GD(1)) S @ZXPARY@(NEWPATH)=GD(1) ; IF SINGLE VALUE, ADD TO ARRAY
56 I GD'="" S @ZXPARY@(NEWPATH)=GD ; IF YES, ADD IT TO THE XPATH ARRAY
57 N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
58 I ZFRST'="" D ; THERE IS A CHILD
59 . N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
60 . D XPATH(ZFRST,NEWPATH,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; DO THE CHILD
61 N GNXT S GNXT=$$NXTSIB(ZOID)
62 I GNXT'="" D ; MOVE ON TO THE NEXT SIBLING
63 . D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; DO NEXT SIB
64 Q
65 ;
66PARSE(INXML,INDOC) ;CALL THE EWD PARSER ON INXML, PASSED BY NAME
67 ; INDOC IS PASSED AS THE DOCUMENT NAME TO EWD
68 ; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY EWD
69 N ZR
70 K ^CacheTempEWD($j) ; CLEAN OUT ANYTHING THAT MIGHT HAVE BEEN THERE
71 M ^CacheTempEWD($j)=@INXML ;
72 S ZR=$$parseDocument^%zewdHTMLParser(INDOC)
73 K ^CacheTempEWD($j) ;clean up after ourselves
74 Q ZR
75 ;
76DELETE(INDOC) ; DELETE A PARSED DOCUMENT FROM THE EWD DOM
77 ; AFTER IT'S NO LONGER NEEDED
78 N OK
79 S OK=$$removeDocument^%zewdDOM(INDOC)
80 Q OK
81 ;
82ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
83 N ZN
84 S ZN=$$NXTSIB(ZOID)
85 I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
86 Q 0
87 ;
88DETAIL(ZRTN,ZOID) ; RETURNS DETAIL FOR NODE ZOID IN ZRTN, PASSED BY NAME
89 N DET
90 D getElementDetails^%zewdXPath(ZOID,.DET)
91 M @ZRTN=DET
92 Q
93 ;
94ID(ZNAME) ;RETURNS THE docOID OF THE DOCUMENT NAMED ZNAME
95 Q $$getDocumentNode^%zewdDOM(ZNAME)
96 ;
97NAME(ZOID) ;RETURNS THE NAME OF THE DOCUMENAT WITH docOID ZOID
98 Q $$getDocumentName^%zewdDOM(ZOID)
99 ;
100FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
101 N GOID
102 S GOID=ZOID
103 S GOID=$$getFirstChild^%zewdDOM(GOID)
104 I GOID="" Q ""
105 I $$getNodeType^%zewdDOM(GOID)'=1 S GOID=$$NXTCHLD(GOID)
106 Q GOID
107 ;
108HASCHILD(ZOID) ; RETURNS TRUE IF ZOID HAS CHILD NODES
109 Q $$hasChildNodes^%zewdDOM(ZOID)
110 ;
111CHILDREN(ZRTN,ZOID) ;RETURNS CHILDREN OF ZOID IN ARRAY ZRTN, PASSED BY NAME
112 N childArray
113 d getChildrenInOrder^%zewdDOM(ZOID,.childArray)
114 m @ZRTN=childArray
115 q
116 ;
117TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
118 Q $$getName^%zewdDOM(ZOID)
119 ;
120NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
121 Q $$getNextSibling^%zewdDOM(ZOID)
122 ;
123NXTCHLD(ZOID) ; RETURNS THE NEXT CHILD IN PARENT ZPAR
124 N GOID
125 S GOID=$$getNextChild^%zewdDOM($$PARENT(ZOID),ZOID)
126 I GOID="" Q ""
127 I $$getNodeType^%zewdDOM(GOID)'=1 S GOID=$$NXTCHLD(GOID)
128 Q GOID
129 ;
130PARENT(ZOID) ; RETURNS PARENT OF ZOID
131 Q $$getParentNode^%zewdDOM(ZOID)
132 ;
133DATA(ZT,ZOID) ; RETURNS DATA FOR THE NODE
134 N ZT2
135 S ZT2=$$getElementText^%zewdDOM(ZOID,.ZT2)
136 M @ZT=ZT2
137 Q
138 ;Q $$getTextValue^%zewdXPath(ZOID)
139 ;Q $$getData^%zewdDOM(ZOID,.ZT)
140 ;
Note: See TracBrowser for help on using the repository browser.