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

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

reorganizing MXML routines

File size: 7.0 KB
Line 
1C0CMXML ; GPL - MXML based XPath utilities;10/13/09 17:05
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 ; THIS FILE CONTAINS THE XPATH CREATOR, THE PARSE CALL TO THE MXML PARSER
22 ; AND THE OUTXML XML GENERATOR THAT OUTPUTS XML FROM AN MXML DOM
23 ; FOR CCD SPECIFIC ROUTINES, SEE C0CMCCD
24 ; FOR TEMPLATE FILE RELATED ROUTINES, SEE C0CMXP
25 ;
26TEST ;
27 S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
28 K GARY
29 W $$FTG^%ZISH("/home/vademo2/EHR/p/","mxml-test.xml",$NA(@C0CXMLIN@(1)),3)
30 S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DocID: ",C0CDOCID
31 S REDUX="//ContinuityOfCareRecord/Body"
32 D XPATH(1,"/","GIDX","GARY",,REDUX)
33 Q
34 ;
35TEST2 ;
36 S REDUX="//soap:Envelope/soap:Body/GetPatientFullMedicationHistory5Response/GetPatientFullMedicationHistory5Result/patientDrugDetail"
37 D XPATH(1,"/","GIDX","GARY","",REDUX)
38 Q
39 ;
40TEST3
41 S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
42 K GARY,GTMP,GIDX
43 K @C0CXMLIN
44 W $$FTG^%ZISH("/home/vademo2/CCR/","SampleCCDDocument.xml",$NA(@C0CXMLIN@(1)),3)
45 D CLEANARY^C0CMCCD("GTMP",C0CXMLIN) ; REMOVE CONTROL CHARACTERS
46 K @C0CXMLIN
47 M @C0CXMLIN=GTMP
48 K GTMP
49 D STRIPTXT^C0CMCCD("GTMP",C0CXMLIN)
50 K @C0CXMLIN
51 M @C0CXMLIN=GTMP
52 K GTMP
53 S C0CDOCID=$$PARSCCD^C0CMCCD(C0CXMLIN,"W") W !,"DocID: ",C0CDOCID
54 S REDUX="//ClinicalDocument/component/structuredBody"
55 D FINDTID^C0CMCCD ; FIND THE TEMPLATE IDS
56 D FINDALT^C0CMCCD ; FIND ALTERNATE TAGS
57 D SETCBK^C0CMCCD ; SET THE CALLBACK ROUTINE FOR TAGS
58 D XPATH(1,"/","GIDX","GARY",,REDUX)
59 K C0CCBK("TAG")
60 D SEPARATE^C0CMCCD("GARY2","GARY") ; SEPARATE FOR EASIER BROWSING
61 ;S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DOCID: ",C0CDOCID ;CALL REGULAR PARSER
62 ;D XPATH(1,"/","GIDX2","GARY2",,REDUX)
63 Q
64 ;
65TEST4 ; TEST OF OUTPUTING AN XML FILE FROM THE DOM .. this one is the CCR
66 ;
67 D TEST ; SET UP THE DOM
68 D START^C0CMXMLB($$TAG(1),,"G")
69 D NDOUT($$FIRST(1))
70 D END^C0CMXMLB ;END THE DOCUMENT
71 M ZCCR=^TMP("MXMLBLD",$J)
72 ZWR ZCCR
73 Q
74 ;
75TEST5 ; SAME AS TEST4, BUT THIS TIME THE CCD
76 S C0CXMLIN=$NA(^TMP("C0CMXML",$J))
77 K GARY,GTMP,GIDX
78 K @C0CXMLIN
79 W $$FTG^%ZISH("/home/vademo2/CCR/","SampleCCDDocument.xml",$NA(@C0CXMLIN@(1)),3)
80 D CLEANARY^C0CMCCD("GTMP",C0CXMLIN) ; REMOVE CONTROL CHARACTERS
81 K @C0CXMLIN
82 M @C0CXMLIN=GTMP
83 K GTMP
84 D STRIPTXT^C0CMCCD("GTMP",C0CXMLIN)
85 K @C0CXMLIN
86 M @C0CXMLIN=GTMP
87 K GTMP
88 S C0CDOCID=$$PARSE(C0CXMLIN) W !,"DOCID: ",C0CDOCID ;CALL REGULAR PARSER
89 ;D XPATH(1,"/","GIDX2","GARY2",,REDUX)
90 D OUTXML("ZCCD",C0CDOCID)
91 ;D START^C0CMXMLB($$TAG(1),,"G")
92 ;D NDOUT($$FIRST(1))
93 ;D END^C0CMXMLB ;EOND THE DOCUMENT
94 ;M ZCCD=^TMP("MXMLBLD",$J)
95 ZWR ZCCD(1:30)
96 Q
97 ;
98XPATH(ZOID,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; RECURSIVE ROUTINE TO POPULATE
99 ; THE XPATH INDEX ZXIDX, PASSED BY NAME
100 ; THE XPATH ARRAY XPARY, PASSED BY NAME
101 ; ZOID IS THE STARTING OID
102 ; ZPATH IS THE STARTING XPATH, USUALLY "/"
103 ; ZNUM IS THE MULTIPLE NUMBER [x], USUALLY NULL WHEN ON THE TOP NODE
104 ; ZREDUX IS THE XPATH REDUCTION STRING, TAKEN OUT OF EACH XPATH IF PRESENT
105 I $G(ZREDUX)="" S ZREDUX=""
106 N NEWPATH
107 N NEWNUM S NEWNUM=""
108 I $G(ZNUM)>0 S NEWNUM="["_ZNUM_"]"
109 S NEWPATH=ZPATH_"/"_$$TAG(ZOID)_NEWNUM ; CREATE THE XPATH FOR THIS NODE
110 I $G(ZREDUX)'="" D ; REDUX PROVIDED?
111 . N GT S GT=$P(NEWPATH,ZREDUX,2)
112 . I GT'="" S NEWPATH=GT
113 S @ZXIDX@(NEWPATH)=ZOID ; ADD THE XPATH FOR THIS NODE TO THE XPATH INDEX
114 N GD D DATA("GD",ZOID) ; SEE IF THERE IS DATA FOR THIS NODE
115 I $D(GD(2)) M @ZXPARY@(NEWPATH)=GD ; IF MULITPLE DATA MERGE TO THE ARRAY
116 E I $D(GD(1)) S @ZXPARY@(NEWPATH)=GD(1) ; IF SINGLE VALUE, ADD TO ARRAY
117 N ZFRST S ZFRST=$$FIRST(ZOID) ; SET FIRST CHILD
118 I ZFRST'=0 D ; THERE IS A CHILD
119 . N ZNUM
120 . N ZMULT S ZMULT=$$ISMULT(ZFRST) ; IS FIRST CHILD A MULTIPLE
121 . D XPATH(ZFRST,NEWPATH,ZXIDX,ZXPARY,$S(ZMULT:1,1:""),ZREDUX) ; DO THE CHILD
122 N GNXT S GNXT=$$NXTSIB(ZOID)
123 I $$TAG(GNXT)'=$$TAG(ZOID) S ZNUM="" ; RESET COUNTING AFTER MULTIPLES
124 I GNXT'=0 D ;
125 . N ZMULT S ZMULT=$$ISMULT(GNXT) ; IS THE SIBLING A MULTIPLE?
126 . I (ZNUM="")&(ZMULT) D ; SIBLING IS FIRST OF MULTIPLES
127 . . N ZNUM S ZNUM=1 ;
128 . . D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,ZNUM,ZREDUX) ; DO NEXT SIB
129 . E D XPATH(GNXT,ZPATH,ZXIDX,ZXPARY,$S(ZNUM>0:ZNUM+1,1:""),ZREDUX) ; DO NEXT SIB
130 Q
131 ;
132PARSE(INXML,INDOC) ;CALL THE MXML PARSER ON INXML, PASSED BY NAME
133 ; INDOC IS PASSED AS THE DOCUMENT NAME - DON'T KNOW WHERE TO STORE THIS NOW
134 ; EXTRINSIC WHICH RETURNS THE DOCID ASSIGNED BY MXML
135 ;Q $$EN^MXMLDOM(INXML)
136 Q $$EN^MXMLDOM(INXML,"W")
137 ;
138ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
139 N ZN
140 ;I $$TAG(ZOID)["entry" B
141 S ZN=$$NXTSIB(ZOID)
142 I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
143 Q 0
144 ;
145FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
146 Q $$CHILD^MXMLDOM(C0CDOCID,ZOID)
147 ;
148PARENT(ZOID) ;RETURNS THE OID OF THE PARENT OF ZOID
149 Q $$PARENT^MXMLDOM(C0CDOCID,ZOID)
150 ;
151ATT(RTN,NODE) ;GET ATTRIBUTES FOR ZOID
152 S HANDLE=C0CDOCID
153 K @RTN
154 D GETTXT^MXMLDOM("A")
155 Q
156 ;
157TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
158 ;I ZOID=149 B ;GPLTEST
159 N X,Y
160 S Y=""
161 S X=$G(C0CCBK("TAG")) ;IS THERE A CALLBACK FOR THIS ROUTINE
162 I X'="" X X ; EXECUTE THE CALLBACK, SHOULD SET Y
163 I Y="" S Y=$$NAME^MXMLDOM(C0CDOCID,ZOID)
164 Q Y
165 ;
166NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
167 Q $$SIBLING^MXMLDOM(C0CDOCID,ZOID)
168 ;
169DATA(ZT,ZOID) ; RETURNS DATA FOR THE NODE
170 ;N ZT,ZN S ZT=""
171 ;S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
172 ;Q $G(@C0CDOM@(ZOID,"T",1))
173 S ZN=$$TEXT^MXMLDOM(C0CDOCID,ZOID,ZT)
174 Q
175 ;
176OUTXML(ZRTN,INID) ; USES C0CMXMLB (MXMLBLD) TO OUTPUT XML FROM AN MXMLDOM
177 ;
178 S C0CDOCID=INID
179 D START^C0CMXMLB($$TAG(1),,"G")
180 D NDOUT($$FIRST(1))
181 D END^C0CMXMLB ;END THE DOCUMENT
182 M @ZRTN=^TMP("MXMLBLD",$J)
183 K ^TMP("MXMLBLD",$J),^TMP("MXMLDOM",$J)
184 Q
185 ;
186NDOUT(ZOID) ;CALLBACK ROUTINE - IT IS RECURSIVE
187 N ZI S ZI=$$FIRST(ZOID)
188 I ZI'=0 D ; THERE IS A CHILD
189 . N ZATT D ATT("ZATT",ZOID) ; THESE ARE THE ATTRIBUTES MOVED TO ZATT
190 . D MULTI^C0CMXMLB("",$$TAG(ZOID),.ZATT,"NDOUT^C0CMXML(ZI)") ;HAVE CHILDREN
191 E D ; NO CHILD - IF NO CHILDREN, A NODE HAS DATA, IS AN ENDPOINT
192 . ;W "DOING",ZOID,!
193 . N ZD D DATA("ZD",ZOID) ;NODES WITHOUT CHILDREN HAVE DATA
194 . N ZATT D ATT("ZATT",ZOID) ;ATTRIBUTES
195 . D ITEM^C0CMXMLB("",$$TAG(ZOID),.ZATT,$G(ZD(1))) ;NO CHILDREN
196 I $$NXTSIB(ZOID)'=0 D ; THERE IS A SIBLING
197 . D NDOUT($$NXTSIB(ZOID)) ;RECURSE FOR SIBLINGS
198 Q
199 ;
200UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
201 K ZERR
202 D CLEAN^DILF
203 D UPDATE^DIE("","C0CFDA","","ZERR")
204 I $D(ZERR) D ;
205 . W "ERROR",!
206 . ZWR ZERR
207 . B
208 K C0CFDA
209 Q
210 ;
Note: See TracBrowser for help on using the repository browser.