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

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