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

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

includes testing version of de-identification code

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