source: ccr/trunk/p/C0CMXP.m@ 719

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

some parse debugging updates

File size: 8.5 KB
Line 
1C0CMXP ; GPL - MXML based XPath utilities;12/04/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 ;
22INITXPF(ARY) ;INITIAL XML/XPATH FILE ARRAY
23 ; DON'T USE THIS ONE ... USE INITFARY^C0CSOAP("FARY") INSTEAD
24 D INITFARY^C0CSOAP(ARY) ;
25 Q
26 S @ARY@("XML FILE NUMBER")=178.101
27 S @ARY@("XML SOURCE FIELD")=2.1
28 S @ARY@("XML TEMPLATE FIELD")=3
29 S @ARY@("XPATH BINDING SUBFILE")=178.1014
30 S @ARY@("REDUX FIELD")=2.5
31 Q
32 ;
33SETXPF(ARY) ; SET FILE AND FIELD VARIABLES FROM XPF ARRAY
34 ;
35 S C0CXPF=@ARY@("XML FILE NUMBER")
36 S C0CXFLD=@ARY@("XML")
37 S C0CXTFLD=@ARY@("TEMPLATE XML")
38 S C0CXPBF=@ARY@("BINDING SUBFILE NUMBER")
39 S C0CRDUXF=@ARY@("XPATH REDUCTION STRING")
40 Q
41 ;
42ADDXP(INARY,TID,FARY) ;ADD XPATH .01 FIELD TO BINDING SUBFILE OF TEMPLATE TID
43 I '$D(FARY) D ;
44 . S FARY="FARY" ; FILE ARRAY
45 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
46 D SETXPF(FARY) ;SET FILE VARIABLES
47 N C0CA,C0CB
48 S C0CA="" S C0CB=0
49 F S C0CA=$O(@INARY@(C0CA)) Q:C0CA="" D ; FOR EACH XPATH
50 . S C0CB=C0CB+1 ; COUNT OF XPATHS
51 . S C0CFDA(C0CXPBF,"?+"_C0CB_","_TID_",",.01)=C0CA
52 . D UPDIE ; CREATE THE BINDING SUBFILE FOR THIS XPATH
53 Q
54 ;
55FIXICD9 ; FIX THE ICD9RESULT XML
56 D GETXML("GPL","ICD9RESULT") ; GET SOME BAD XML OUT OF THE FILE
57 S ZI=""
58 S G=""
59 F S ZI=$O(GPL(ZI)) Q:ZI="" D ; FOR EACH LINE
60 . S G=G_GPL(ZI) ; MAKE ONE BIG STRING OF XML
61 D NORMAL^C0CSOAP("G2","G") ;NO NORMALIZE IT BACK INTO AN ARRAY
62 D ADDXML("G2","ICD9RESULT") ; AND PUT IT BACK
63 Q
64ADDXML(INXML,TEMPID,INFARY) ;ADD XML TO A TEMPLATE ID TEMPID
65 ; INXML IS PASSED BY NAME
66 I '$D(INFARY) D ;
67 . S INFARY="FARY" ; FILE ARRAY
68 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
69 I +TEMPID=0 S TEMPID=$$RESTID^C0CSOAP(TEMPID,INFARY) ;RESOLVE TEMPLATE NAME
70 D SETXPF(INFARY) ;SET FILE VARIABLES
71 D WP^DIE(C0CXPF,TEMPID_",",C0CXFLD,,INXML)
72 Q
73 ;
74ADDTEMP(INXML,TEMPID,INFARY) ;ADD XML TEMPLATE TO TEMPLATE RECORD TEMPID
75 ;
76 I '$D(INFARY) D ;
77 . S INFARY="FARY" ; FILE ARRAY
78 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
79 I +TEMPID=0 S TEMPID=$$RESTID^C0CSOAP(TEMPID,INFARY) ;RESOLVE TEMPLATE NAME
80 D SETXPF(INFARY) ;SET FILE VARIABLES
81 D WP^DIE(C0CXPF,TEMPID_",",C0CXTFLD,,INXML)
82 Q
83 ;
84GETXML(OUTXML,TEMPID,INFARY) ;GET THE XML FROM TEMPLATE TEMPID
85 ;
86 I '$D(INFARY) D ;
87 . S INFARY="FARY" ; FILE ARRAY
88 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
89 D SETXPF(INFARY) ;SET FILE VARIABLES
90 I +TEMPID=0 S TEMPID=$$RESTID^C0CSOAP(TEMPID,INFARY) ;RESOLVE TEMPLATE NAME
91 I $$GET1^DIQ(C0CXPF,TEMPID_",",C0CXFLD,,OUTXML)'=OUTXML D Q ;
92 . W "ERROR RETRIEVING TEMPLATE",!
93 Q
94 ;
95GETTEMP(OUTXML,TEMPID,FARY) ;GET THE TEMPLATE XML FROM TEMPLATE TEMPID
96 ;
97 I '$D(FARY) D ;
98 . S FARY="FARY" ; FILE ARRAY
99 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
100 D SETXPF(FARY) ;SET FILE VARIABLES
101 I $$GET1^DIQ(C0CXPF,TEMPID_",",C0CXTFLD,,OUTXML)'=OUTXML D Q ;
102 . W "ERROR RETRIEVING TEMPLATE",!
103 Q
104 ;
105COMPILE(TID,UFARY) ; COMPILES AN XML TEMPLATE AND GENERATES XPATH BINDINGS
106 ; UFARY IF SPECIFIED WILL REDIRECT THE XML FILE TO USE
107 ; INTID IS THE IEN OF THE RECORD TO USE IN THE XML FILE
108 ; XML IS PULLED FROM THE "XML" FIELD AND THE COMPILED RESULT PUT
109 ; IN THE "XML TEMPLATE" FIELD. ALL XPATHS USED IN THE TEMPLATE
110 ; WILL BE POPULATED TO THE XPATH BINDINGS SUBFILE AS .01
111 I '$D(UFARY) D ;
112 . S UFARY="DEFFARY" ; FILE ARRAY
113 . ;D INITXPF("UFARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
114 . D INITFARY^C0CSOAP(UFARY)
115 D SETXPF(UFARY) ;SET FILE VARIABLES
116 I +TID=0 S INTID=$$RESTID^C0CSOAP(TID,UFARY)
117 E S INTID=TID
118 ;B
119 ;N C0CXML,C0CREDUX,C0CTEMP,C0CIDX
120 D GETXML("C0CXML",INTID,UFARY)
121 S C0CREDUX=$$GET1^DIQ(C0CXPF,INTID_",",C0CRDUXF,"E") ;XPATH REDUCTION STRING
122 D MKTPLATE("C0CTEMP","C0CIDX","C0CXML",C0CREDUX) ; CREATE TEMPLATE AND IDX
123 D ADDTEMP("C0CTEMP",INTID,UFARY) ; WRITE THE TEMPLATE TO FILE
124 D ADDXP("C0CIDX",INTID,UFARY) ;CREATE XPATH SUBFILE ENTRIES FOR EVERY XPATH
125 Q
126 ;
127MKTPLATE(OUTT,OUTIDX,INXML,REDUX) ;MAKE A TEMPLATE FROM INXML, RETURNED IN OUTT
128 ; BOTH PASSED BY NAME. THE REDUX XPATH REDUCTION STRING IS USED IF PASSED
129 ; OUTIDX IS AN ARRAY OF THE XPATHS USED IN MAKING THE TEMPLATE
130 ;
131 S C0CXLOC=$NA(^TMP("C0CXML",$J))
132 K @C0CXLOC
133 M @C0CXLOC=@INXML
134 S C0CDOCID=$$PARSE^C0CMXML(C0CXLOC,"C0CMKT")
135 K @C0CXLOC
136 S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
137 ;N GIDX,GIDX2,GARY,GARY2
138 I '$D(REDUX) S REDUX=""
139 D XPATH^C0CMXML(1,"/","GIDX","GARY",,REDUX)
140 D INVERT("GIDX2","GIDX") ;MAKE ARRAY TO LOOK UP XPATH BY NODE
141 N ZI,ZD S ZI=""
142 F S ZI=$O(@C0CDOM@(ZI)) Q:ZI="" D ; FOR EACH NODE IN THE DOM
143 . K ZD ;FOR DATA
144 . D DATA^C0CMXML("ZD",ZI) ;SEE IF THERE IS DATA FOR THIS NODE
145 . I $D(ZD(1)) D ; IF YES
146 . . ;I ZI<3 B ;W !,ZD(1)
147 . . K @C0CDOM@(ZI,"T") ; KILL THE DATA
148 . . N ZXPATH
149 . . S ZXPATH=$G(GIDX2(ZI)) ;FIND AN XPATH FOR THIS NODE
150 . . S @C0CDOM@(ZI,"T",1)="@@"_ZXPATH_"@@"
151 . . I ZXPATH'="" S @OUTIDX@(ZXPATH)="" ; PASS BACK XPATH USED IN IDX
152 D OUTXML^C0CMXML(OUTT,C0CDOCID)
153 Q
154 ;
155INVERT(OUTX,INX) ;INVERTS AN XPATH INDEX RETURNING @OUTX@(x)=XPath from
156 ; @INX@(XPath)=x
157 N ZI S ZI=""
158 F S ZI=$O(@INX@(ZI)) Q:ZI="" D ;FOR EACH XPATH IN THE INPUT
159 . S @OUTX@(@INX@(ZI))=ZI ; SET INVERTED ENTRY
160 Q
161 ;
162DEMUX(OUTX,INX) ;PARSES XPATH PASSED BY VALUE IN INX TO REMOVE [x] MULTIPLES
163 ; RETURNS OUTX: MULTIPLE^SUBMULTIPLE^XPATH
164 N ZX,ZY,ZZ,ZZ1,ZMULT,ZSUB
165 S (ZMULT,ZSUB)=""
166 S ZX=$P(INX,"[",2)
167 I ZX'="" D ; THERE IS A [x] MULTIPLE
168 . S ZY=$P(INX,"[",1) ;FIRST PART OF XPATH
169 . S ZMULT=$P(ZX,"]",1) ; NUMBER OF THE MULTIPLE
170 . S ZX=ZY_$P(ZX,"]",2) ; REST OF THE XPATH
171 . I $P(ZX,"[",2)'="" D ; A SUB MULTIPLE EXISTS
172 . . S ZZ=$P(ZX,"[",1) ; FIRST PART OF XPATH
173 . . S ZX=$P(ZX,"[",2) ; DELETE THE [
174 . . S ZSUB=$P(ZX,"]",1) ; NUMBER OF THE SUBMULTIPLE
175 . . S ZX=ZZ_$P(ZX,"]",2) ; REST OF THE XPATH
176 E S ZX=INX ;NO MULTIPLE HERE
177 S @OUTX=ZMULT_"^"_ZSUB_"^"_ZX ;RETURN MULTIPLE^SUBMULTIPLE^XPATH
178 Q
179 ;
180DEMUXARY(OARY,IARY,DEPTH) ;CONVERT AN XPATH ARRAY PASSED AS IARY TO
181 ; FORMAT @OARY@(x,variablename) where x is the first multiple
182 ; IF DEPTH=2, THE LAST 2 PARTS OF THE XPATH WILL BE USED
183 N ZI,ZJ,ZK,ZL,ZM S ZI=""
184 F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ;
185 . D DEMUX^C0CMXP("ZJ",ZI)
186 . S ZK=$P(ZJ,"^",3)
187 . S ZM=$RE($P($RE(ZK),"/",1))
188 . I $G(DEPTH)=2 D ;LAST TWO PARTS OF XPATH USED FOR THE VARIABLE NAME
189 . . S ZM=$RE($P($RE(ZK),"/",2))_ZM
190 . S ZL=$P(ZJ,"^",1)
191 . I ZL="" S ZL=1
192 . I $D(@OARY@(ZL,ZM)) D ;IT'S A DUP
193 . . S @OARY@(ZL,ZM_"[2]")=@IARY@(ZI)
194 . E S @OARY@(ZL,ZM)=@IARY@(ZI)
195 Q
196 ;
197DEMUXXP1(OARY,IARY) ;IARY IS INCOMING XPATH ARRAY
198 ; BOTH IARY AND OARY ARE PASSED BY NAME
199 ; RETURNS A SIMPLE XPATH ARRAY WITHOUT MULTIPLES. DUPLICATES ARE REMOVED
200 N ZI,ZJ,ZK
201 S ZI=""
202 F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ; FOR EACH XPATH IN IARY
203 . D DEMUX^C0CMXP("ZJ",ZI)
204 . S ZK=$P(ZJ,"^",3) ;THE XPATH
205 . S @OARY@(ZK)=@IARY@(ZI) ;THE RESULT. DUPLICATES WILL NOT SHOW
206 . ; CAUTION, IF THERE ARE MULTIPLES, ONLY THE DATA FOR THE LAST
207 . ; MULTIPLE WILL BE INCLUDED IN THE OUTPUT ARRAY, ASSIGNED TO THE
208 . ; COMMON XPATH
209 Q
210 ;
211DEMUXXP2(OARY,IARY) ; IARY AND OARY ARE PASSED BY NAME
212 ; IARY IS AN XPATH ARRAY THAT MAY CONTAIN MULTIPLES
213 ; OARY IS THE OUTPUT ARRAY WHERE MULTIPLES ARE RETURNED IN THE FORM
214 ; @OARY@(x,Xpath)=data or @OARY@(x,y,Xpath)=data WHERE x AND y ARE
215 ; THE MULTIPLES AND Xpath IS THE BASE XPATH WITHOUT [x] AND [y]
216 ;
217 N ZI,ZJ,ZK,ZX,ZY,ZP
218 S ZI=""
219 F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ; FOR EACH INPUT XPATH
220 . D DEMUX("ZJ",ZI) ; PULL OUT THE MULTIPLES
221 . S ZX=$P(ZJ,"^",1) ;x
222 . S ZY=$P(ZJ,"^",2) ;y
223 . S ZP=$P(ZJ,"^",3) ;Xpath
224 . I ZX="" S ZX=1 ; NO MULTIPLE WILL STORE IN x=1
225 . I ZY'="" D ;IS THERE A y?
226 . . S @OARY@(ZX,ZY,ZP)=@IARY@(ZI)
227 . E D ;NO y
228 . . S @OARY@(ZX,ZP)=@IARY@(ZI)
229 Q
230 ;
231UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
232 K ZERR
233 D CLEAN^DILF
234 D UPDATE^DIE("","C0CFDA","","ZERR")
235 I $D(ZERR) D ;
236 . W "ERROR",!
237 . ZWR ZERR
238 . B
239 K C0CFDA
240 Q
241 ;
Note: See TracBrowser for help on using the repository browser.