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

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

template generation tools

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