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

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

template generation tools

File size: 6.1 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 ;
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 Q
29 ;
30SETXPF(ARY) ; SET FILE AND FIELD VARIABLES FROM XPF ARRAY
31 ;
32 S C0CXPF=@ARY@("XML FILE NUMBER")
33 S C0CXFLD=@ARY@("XML SOURCE FIELD")
34 S C0CXTFLD=@ARY@("XML TEMPLATE FIELD")
35 S C0CXPBF=@ARY@("XPATH BINDING SUBFILE")
36 Q
37 ;
38ADDXP(INARY,TID,FARY) ;ADD XPATH .01 FIELD TO BINDING SUBFILE OF TEMPLATE TID
39 I '$D(FARY) D ;
40 . S FARY="FARY" ; FILE ARRAY
41 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
42 D SETXPF(FARY) ;SET FILE VARIABLES
43 N C0CA,C0CB
44 S C0CA="" S C0CB=0
45 F S C0CA=$O(@INARY@(C0CA)) Q:C0CA="" D ; FOR EACH XPATH
46 . S C0CB=C0CB+1 ; COUNT OF XPATHS
47 . S C0CFDA(C0CXPBF,"?+"_C0CB_","_TID_",",.01)=C0CA
48 . D UPDIE ; CREATE THE BINDING SUBFILE FOR THIS XPATH
49 Q
50 ;
51ADDXML(INXML,TEMPID,FARY) ;ADD XML TO A TEMPLATE ID TEMPID
52 ; INXML IS PASSED BY NAME
53 I '$D(FARY) D ;
54 . S FARY="FARY" ; FILE ARRAY
55 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
56 D SETXPF(FARY) ;SET FILE VARIABLES
57 D WP^DIE(C0CXPF,TEMPID_",",C0CXFLD,,INXML)
58 Q
59 ;
60ADDTEMP(INXML,TEMPID,FARY) ;ADD XML TEMPLATE TO TEMPLATE RECORD TEMPID FIELD 3
61 ;
62 I '$D(FARY) D ;
63 . S FARY="FARY" ; FILE ARRAY
64 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
65 D SETXPF(FARY) ;SET FILE VARIABLES
66 D WP^DIE(C0CXPF,TEMPID_",",C0CXTFLD,,INXML)
67 Q
68 ;
69GETXML(OUTXML,TEMPID,FARY) ;GET THE XML FROM TEMPLATE TEMPID
70 ;
71 I '$D(FARY) D ;
72 . S FARY="FARY" ; FILE ARRAY
73 . D INITXPF("FARY") ;IF FILE ARRAY NOT PASSED, INITIALIZE
74 D SETXPF(FARY) ;SET FILE VARIABLES
75 I $$GET1^DIQ(C0CXPF,TEMPID_",",C0CXFLD,,OUTXML)'=OUTXML D Q ;
76 . W "ERROR RETRIEVING TEMPLATE",!
77 Q
78 ;
79MKTPLATE(OUTT,INXML,REDUX) ;MAKE A TEMPLATE FROM INXML, RETURNED IN OUTT
80 ; BOTH PASSED BY NAME
81 ;
82 S C0CDOCID=$$PARSE^C0CMXML(INXML,"C0CMKT")
83 S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
84 ;N GIDX,GIDX2,GARY,GARY2
85 I '$D(REDUX) S REDUX=""
86 D XPATH^C0CMXML(1,"/","GIDX","GARY",,REDUX)
87 D INVERT("GIDX2","GIDX") ;MAKE ARRAY TO LOOK UP XPATH BY NODE
88 N ZI,ZD S ZI=""
89 F S ZI=$O(@C0CDOM@(ZI)) Q:ZI="" D ; FOR EACH NODE IN THE DOM
90 . K ZD ;FOR DATA
91 . D DATA^C0CMXML("ZD",ZI) ;SEE IF THERE IS DATA FOR THIS NODE
92 . I $D(ZD(1)) D ; IF YES
93 . . W !,ZD(1)
94 . . K @C0CDOM@(ZI,"T") ; KILL THE DATA
95 . . S @C0CDOM@(ZI,"T",1)="@@"_$G(GIDX2(ZI))_"@@"
96 D OUTXML^C0CMXML(OUTT,C0CDOCID)
97 Q
98 ;
99INVERT(OUTX,INX) ;INVERTS AN XPATH INDEX RETURNING @OUTX@(x)=XPath from
100 ; @INX@(XPath)=x
101 N ZI S ZI=""
102 F S ZI=$O(@INX@(ZI)) Q:ZI="" D ;FOR EACH XPATH IN THE INPUT
103 . S @OUTX@(@INX@(ZI))=ZI ; SET INVERTED ENTRY
104 Q
105 ;
106DEMUX(OUTX,INX) ;PARSES XPATH PASSED BY VALUE IN INX TO REMOVE [x] MULTIPLES
107 ; RETURNS OUTX: MULTIPLE^SUBMULTIPLE^XPATH
108 N ZX,ZY,ZZ,ZZ1,ZMULT,ZSUB
109 S (ZMULT,ZSUB)=""
110 S ZX=$P(INX,"[",2)
111 I ZX'="" D ; THERE IS A [x] MULTIPLE
112 . S ZY=$P(INX,"[",1) ;FIRST PART OF XPATH
113 . S ZMULT=$P(ZX,"]",1) ; NUMBER OF THE MULTIPLE
114 . S ZX=ZY_$P(ZX,"]",2) ; REST OF THE XPATH
115 . I $P(ZX,"[",2)'="" D ; A SUB MULTIPLE EXISTS
116 . . S ZZ=$P(ZX,"[",1) ; FIRST PART OF XPATH
117 . . S ZX=$P(ZX,"[",2) ; DELETE THE [
118 . . S ZSUB=$P(ZX,"]",1) ; NUMBER OF THE SUBMULTIPLE
119 . . S ZX=ZZ_$P(ZX,"]",2) ; REST OF THE XPATH
120 E S ZX=INX ;NO MULTIPLE HERE
121 S @OUTX=ZMULT_"^"_ZSUB_"^"_ZX ;RETURN MULTIPLE^SUBMULTIPLE^XPATH
122 Q
123 ;
124DEMUXARY(OARY,IARY,DEPTH) ;CONVERT AN XPATH ARRAY PASSED AS IARY TO
125 ; FORMAT @OARY@(x,variablename) where x is the first multiple
126 ; IF DEPTH=2, THE LAST 2 PARTS OF THE XPATH WILL BE USED
127 N ZI,ZJ,ZK,ZL,ZM S ZI=""
128 F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ;
129 . D DEMUX^C0CMXP("ZJ",ZI)
130 . S ZK=$P(ZJ,"^",3)
131 . S ZM=$RE($P($RE(ZK),"/",1))
132 . I $G(DEPTH)=2 D ;LAST TWO PARTS OF XPATH USED FOR THE VARIABLE NAME
133 . . S ZM=$RE($P($RE(ZK),"/",2))_ZM
134 . S ZL=$P(ZJ,"^",1)
135 . I ZL="" S ZL=0
136 . I $D(@OARY@(ZL,ZM)) D ;IT'S A DUP
137 . . S @OARY@(ZL,ZM_"[2]")=@IARY@(ZI)
138 . E S @OARY@(ZL,ZM)=@IARY@(ZI)
139 Q
140 ;
141DEMUXXP1(OARY,IARY) ;IARY IS INCOMING XPATH ARRAY
142 ; BOTH IARY AND OARY ARE PASSED BY NAME
143 ; RETURNS A SIMPLE XPATH ARRAY WITHOUT MULTIPLES. DUPLICATES ARE REMOVED
144 N ZI,ZJ,ZK
145 S ZI=""
146 F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ; FOR EACH XPATH IN IARY
147 . D DEMUX^C0CMXP("ZJ",ZI)
148 . S ZK=$P(ZJ,"^",3) ;THE XPATH
149 . S @OARY@(ZK)=@IARY@(ZI) ;THE RESULT. DUPLICATES WILL NOT SHOW
150 . ; CAUTION, IF THERE ARE MULTIPLES, ONLY THE DATA FOR THE LAST
151 . ; MULTIPLE WILL BE INCLUDED IN THE OUTPUT ARRAY, ASSIGNED TO THE
152 . ; COMMON XPATH
153 Q
154 ;
155DEMUXXP2(OARY,IARY) ; IARY AND OARY ARE PASSED BY NAME
156 ; IARY IS AN XPATH ARRAY THAT MAY CONTAIN MULTIPLES
157 ; OARY IS THE OUTPUT ARRAY WHERE MULTIPLES ARE RETURNED IN THE FORM
158 ; @OARY@(x,Xpath)=data or @OARY@(x,y,Xpath)=data WHERE x AND y ARE
159 ; THE MULTIPLES AND Xpath IS THE BASE XPATH WITHOUT [x] AND [y]
160 ;
161 N ZI,ZJ,ZK,ZX,ZY,ZP
162 S ZI=""
163 F S ZI=$O(@IARY@(ZI)) Q:ZI="" D ; FOR EACH INPUT XPATH
164 . D DEMUX("ZJ",ZI) ; PULL OUT THE MULTIPLES
165 . S ZX=$P(ZJ,"^",1) ;x
166 . S ZY=$P(ZJ,"^",2) ;y
167 . S ZP=$P(ZJ,"^",3) ;Xpath
168 . I ZX="" S ZX=1 ; NO MULTIPLE WILL STORE IN x=1
169 . I ZY'="" D ;IS THERE A y?
170 . . S @OARY@(ZX,ZY,ZP)=@IARY@(ZI)
171 . E D ;NO y
172 . . S @OARY@(ZX,ZP)=@IARY@(ZI)
173 Q
174 ;
175UPDIE ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
176 K ZERR
177 D CLEAN^DILF
178 D UPDATE^DIE("","C0CFDA","","ZERR")
179 I $D(ZERR) D ;
180 . W "ERROR",!
181 . ZWR ZERR
182 . B
183 K C0CFDA
184 Q
185 ;
Note: See TracBrowser for help on using the repository browser.