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

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