2009-10-14 08:41:00 -04:00
|
|
|
C0CMXML ; ERX/GPL - MXML based XPath utilities;10/13/09 17:05
|
|
|
|
;;0.1;C0P;nopatch;noreleasedate
|
|
|
|
;Copyright 2009 George Lilly. Licensed under the terms of the GNU
|
|
|
|
;General Public License See attached copy of the License.
|
|
|
|
;
|
|
|
|
;This program is free software; you can redistribute it and/or modify
|
|
|
|
;it under the terms of the GNU General Public License as published by
|
|
|
|
;the Free Software Foundation; either version 2 of the License, or
|
|
|
|
;(at your option) any later version.
|
|
|
|
;
|
|
|
|
;This program is distributed in the hope that it will be useful,
|
|
|
|
;but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;GNU General Public License for more details.
|
|
|
|
;
|
|
|
|
;You should have received a copy of the GNU General Public License along
|
|
|
|
;with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
;
|
|
|
|
Q
|
|
|
|
;
|
|
|
|
TEST ;
|
|
|
|
S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
|
|
|
|
K GARY
|
|
|
|
W $$FTG^%ZISH("/home/vademo2/EHR/p/","mxml-test.xml",$NA(@C0CXMLIN@(1)),3)
|
|
|
|
S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DocID: ",C0CDOCID
|
|
|
|
S REDUX="//ContinuityOfCareRecord/Body"
|
|
|
|
D XPATH(1,"/","GIDX","GARY",,REDUX)
|
|
|
|
Q
|
|
|
|
;
|
|
|
|
TEST2 ;
|
|
|
|
S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
|
|
|
|
D XPATH(1,"/","GIDX","GARY","",REDUX)
|
|
|
|
Q
|
|
|
|
;
|
|
|
|
XPATH(ZOID,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; RECURSIVE ROUTINE TO POPULATE
|
|
|
|
; THE XPATH INDEX ZXIDX, PASSED BY NAME
|
|
|
|
; THE XPATH ARRAY XPARY, PASSED BY NAME
|
|
|
|
; ZOID IS THE STARTING OID
|
|
|
|
; ZPATH IS THE STARTING XPATH, USUALLY "/"
|
|
|
|
; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
|
|
|
|
; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
|
|
|
|
I $G(ZREDUX)="" S ZREDUX=""
|
|
|
|
N NEWPATH
|
|
|
|
N NEWNUM S NEWNUM=""
|
|
|
|
I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
|
|
|
|
S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
|
|
|
|
I $G(ZREDUX)'="" D ; REDUX PROVIDED?
|
|
|
|
. N GT S GT=$P(NEWPATH,ZREDUX,2)
|
|
|
|
. I GT'="" S NEWPATH=GT
|
|
|
|
S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
|
|
|
|
N GD D DATA("GD",ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
|
|
|
|
I $D(GD(2)) M @ZXPARY@(NEWPATH)=GD ; IF MULITPLE DATA MERGE TO THE ARRAY
|
|
|
|
E I $D(GD(1)) S @ZXPARY@(NEWPATH)=GD(1) ; IF SINGLE VALUE, ADD TO ARRAY
|
|
|
|
N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
|
|
|
|
I ZFRST'=0 D ; THERE IS A CHILD
|
|
|
|
. N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
|
|
|
|
. D XPATH(ZFRST,NEWPATH,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; DO THE CHILD
|
|
|
|
N GNXT S GNXT=$$NXTSIB(ZOID)
|
|
|
|
I GNXT'=0 D ;
|
|
|
|
. D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; DO NEXT SIB
|
|
|
|
Q
|
|
|
|
;
|
|
|
|
PARSE(INXML,INDOC) ;CALL THE MXML PARSER ON INXML, PASSED BY NAME
|
|
|
|
; INDOC IS PASSED AS THE DOCUMENT NAME - DON'T KNOW WHERE TO STORE THIS NOW
|
|
|
|
; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY MXML
|
|
|
|
;Q $$EN^MXMLDOM(INXML)
|
|
|
|
Q $$EN^MXMLDOM(INXML,"W")
|
|
|
|
;
|
|
|
|
ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
|
|
|
|
N ZN
|
|
|
|
S ZN=$$NXTSIB(ZOID)
|
|
|
|
I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
|
|
|
|
Q 0
|
|
|
|
;
|
|
|
|
FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
|
|
|
|
Q $$CHILD^MXMLDOM(C0CDOCID,ZOID)
|
|
|
|
;
|
|
|
|
TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
|
|
|
|
Q $$NAME^MXMLDOM(C0CDOCID,ZOID)
|
|
|
|
;
|
|
|
|
NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
|
|
|
|
Q $$SIBLING^MXMLDOM(C0CDOCID,ZOID)
|
|
|
|
;
|
|
|
|
DATA(ZT,ZOID) ; RETURNS DATA FOR THE NODE
|
|
|
|
;N ZT,ZN S ZT=""
|
|
|
|
;S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
|
|
|
|
;Q $G(@C0CDOM@(ZOID,"T",1))
|
|
|
|
S ZN=$$TEXT^MXMLDOM(C0CDOCID,ZOID,ZT)
|
|
|
|
Q
|
|
|
|
;
|