source: ccr/trunk/p/C0CMCCD.m@ 728

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

template generation tools

File size: 9.6 KB
RevLine 
[630]1C0CMCCD ; GPL - MXML based CCD 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 ;
22PARSCCD(DOC,OPTION) ; THIS WAS COPIED FROM EN^MXMLDOM TO CUSTIMIZE FOR
23 ; PROCESSING CCDS
24 N CBK,SUCCESS,LEVEL,NODE,HANDLE
25 K ^TMP("MXMLERR",$J)
26 L +^TMP("MXMLDOM",$J):5
27 E Q 0
28 S HANDLE=$O(^TMP("MXMLDOM",$J,""),-1)+1,^(HANDLE)=""
29 L -^TMP("MXMLDOM",$J)
[639]30 S CBK("STARTELEMENT")="STARTELE^C0CMCCD" ; ONLY THIS ONE IS CHANGED ;GPL
[630]31 S CBK("ENDELEMENT")="ENDELE^MXMLDOM"
32 S CBK("COMMENT")="COMMENT^MXMLDOM"
33 S CBK("CHARACTERS")="CHAR^MXMLDOM"
34 S CBK("ENDDOCUMENT")="ENDDOC^MXMLDOM"
35 S CBK("ERROR")="ERROR^MXMLDOM"
36 S (SUCCESS,LEVEL,LEVEL(0),NODE)=0,OPTION=$G(OPTION,"V1")
37 D EN^MXMLPRSE(DOC,.CBK,OPTION)
38 D:'SUCCESS DELETE^MXMLDOM(HANDLE)
39 Q $S(SUCCESS:HANDLE,1:0)
40 ; Start element
41 ; Create new child node and push info on stack
42STARTELE(ELE,ATTR) ; COPIED FROM STARTELE^MXMLDOM AND MODIFIED TO TREAT
43 ; ATTRIBUTES AS SUBELEMENTS TO MAKE CCD XPATH PROCESSING EASIER
44 N PARENT
45 S PARENT=LEVEL(LEVEL),NODE=NODE+1
46 S:PARENT ^TMP("MXMLDOM",$J,HANDLE,PARENT,"C",NODE)=ELE
47 S LEVEL=LEVEL+1,LEVEL(LEVEL)=NODE,LEVEL(LEVEL,0)=ELE
48 S ^TMP("MXMLDOM",$J,HANDLE,NODE)=ELE,^(NODE,"P")=PARENT
49 ;M ^("A")=ATTR
50 N ZI S ZI="" ; INDEX FOR ATTR
51 F S ZI=$O(ATTR(ZI)) Q:ZI="" D ; FOR EACH ATTRIBUTE
52 . N ELE,TXT ; ABOUT TO RECURSE
53 . S ELE=ZI ; TAG
54 . S TXT=ATTR(ZI) ; DATA
55 . D STARTELE(ELE,"") ; CREATE A NEW SUBNODE
56 . D TXT^MXMLDOM("T") ; INSERT DATA TO TAG
57 . D ENDELE^MXMLDOM(ELE) ; POP BACK UP A LEVEL
58 Q
59 ;
[639]60ISMULT(ZOID) ; RETURN TRUE IF ZOID IS ONE OF A MULTIPLE
61 N ZN
62 ;I $$TAG(ZOID)["entry" B
63 S ZN=$$NXTSIB(ZOID)
64 I ZN'="" Q $$TAG(ZOID)=$$TAG(ZN) ; IF TAG IS THE SAME AS NEXT SIB TAG
65 Q 0
66 ;
67FIRST(ZOID) ;RETURNS THE OID OF THE FIRST CHILD OF ZOID
68 Q $$CHILD^MXMLDOM(C0CDOCID,ZOID)
69 ;
70PARENT(ZOID) ;RETURNS THE OID OF THE PARENT OF ZOID
71 Q $$PARENT^MXMLDOM(C0CDOCID,ZOID)
72 ;
73ATT(RTN,NODE) ;GET ATTRIBUTES FOR ZOID
74 S HANDLE=C0CDOCID
75 K @RTN
76 D GETTXT^MXMLDOM("A")
77 Q
78 ;
79TAG(ZOID) ; RETURNS THE XML TAG FOR THE NODE
80 ;I ZOID=149 B ;GPLTEST
81 N X,Y
82 S Y=""
83 S X=$G(C0CCBK("TAG")) ;IS THERE A CALLBACK FOR THIS ROUTINE
84 I X'="" X X ; EXECUTE THE CALLBACK, SHOULD SET Y
85 I Y="" S Y=$$NAME^MXMLDOM(C0CDOCID,ZOID)
86 Q Y
87 ;
88NXTSIB(ZOID) ; RETURNS THE NEXT SIBLING
89 Q $$SIBLING^MXMLDOM(C0CDOCID,ZOID)
90 ;
91DATA(ZT,ZOID) ; RETURNS DATA FOR THE NODE
92 ;N ZT,ZN S ZT=""
93 ;S C0CDOM=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
94 ;Q $G(@C0CDOM@(ZOID,"T",1))
95 S ZN=$$TEXT^MXMLDOM(C0CDOCID,ZOID,ZT)
96 Q
97 ;
[630]98CLEANARY(OUTARY,INARY) ; GOES THROUGH AN ARRAY AND CALLS CLEAN ON EACH NODE
99 ; INARY AND OUTARY PASSED BY NAME
100 N ZI S ZI=""
101 F S ZI=$O(@INARY@(ZI)) Q:ZI="" D ; FOR EACH NODE
102 . S @OUTARY@(ZI)=$$CLEAN(@INARY@(ZI)) ; CLEAN THE NODE
103 Q
104 ;
105CLEAN(STR) ; extrinsic function; returns string
106 ;; Removes all non printable characters from a string.
107 ;; STR by Value
108 N TR,I
109 F I=0:1:31 S TR=$G(TR)_$C(I)
110 S TR=TR_$C(127)
111 QUIT $TR(STR,TR)
112 ;
113STRIPTXT(OUTARY,ZARY) ; STRIPS THE "TEXT" PORTION OUT OF AN XML FILE
114 ; THIS IS USED TO DELETE THE NARATIVE HTML OUT OF THE CCD XML FILES BECAUSE
115 ; THEY DO NOT WORK RIGHT WITH THE PARSER
116 ;N ZWRK,ZBLD,ZI ; WORK ARRAY,BUILD ARRAY, AND COUNTER
117 S ZI=$O(@ZARY@("")) ; GET FIRST LINE NUMBER
118 D C0CBEGIN("ZWRK",ZI) ; INSERT FIRST LINE IN WORK ARRAY
119 F S ZI=$O(@ZARY@(ZI)) Q:ZI="" D ; FOR EACH LINE OF THE ARRAY
120 . I $O(@ZARY@(ZI))="" D Q ; AT THE END
121 . . D C0CEND("ZWRK",ZI) ; INCLUDE LAST LINE IN WORK ARRAY
122 . I ZI=1 D C0CBEGIN("ZWRK",ZI) ; START WITH FIRST LINE
123 . I @ZARY@(ZI)["<text" D C0CEND("ZWRK",ZI-1) ;PREV LINE IS AN END
124 . I @ZARY@(ZI)["</text>" D C0CBEGIN("ZWRK",ZI+1) ;NEXT LINE IS A BEGIN
125 S ZI=""
126 F S ZI=$O(ZWRK(ZI)) Q:ZI="" D ; MAKE A BUILD LIST FROM THE WORK ARRAY
127 . D QUEUE^C0CXPATH("ZBLD",ZARY,$P(ZWRK(ZI),"^",1),$P(ZWRK(ZI),"^",2))
128 D BUILD^C0CXPATH("ZBLD",OUTARY) ; BUILD NEW ARRAY WITHOUT TEXT SECTIONS
129 K @OUTARY@(0) ; GET RID OF THE LINE COUNT
130 Q
131 ;
132C0CBEGIN(ZA,LN) ; INSERTS A BEGIN LINE LN INTO ARRAY ZWRK, PASSED BY NAME
133 N ZI
134 S ZI=$O(@ZA@(""),-1)
135 I ZI="" S ZI=1
136 E S ZI=ZI+1 ; INCREMENT COUNT IN WORK ARRAY
137 S $P(@ZA@(ZI),"^",1)=LN
138 Q
139 ;
140C0CEND(ZB,LN) ; INSERTS AN END LINE LN INTO ARRAY ZWRK, PASSED BY NAME
141 N ZI
142 S ZI=$O(@ZB@(""),-1)
143 I ZI="" S ZI=1
144 S $P(@ZB@(ZI),"^",2)=LN
145 Q
146 ;
147SEPARATE(OUTARY,INARY) ; SEPARATES XPATH VARIABLES ACCORDING TO THEIR
148 ; ROOT ; /Problems/etc/etc goes to @OUTARY@("Problems","/Problems/etc/etc")
149 S ZI=""
150 F S ZI=$O(@INARY@(ZI)) Q:ZI="" D ; FOR EACH ELEMENT OF THE ARRAY
151 . S ZJ=$P(ZI,"/",2) ;
152 . I ZJ="" S ZJ=$P(ZI,"/",3) ;
153 . S @OUTARY@(ZJ,ZI)=@INARY@(ZI)
154 Q
155 ;
156FINDTID ; FIND TEMPLATE IDS IN DOM 1
157 S C0CDOCID=1
158 S ZD=$NA(^TMP("MXMLDOM",$J,C0CDOCID))
159 S ZN=""
160 S CURSEC=""
161 S TID=""
162 F S ZN=$O(@ZD@(ZN)) Q:ZN="" D ;
163 . I $$TAG(ZN)="root" D ;
164 . . I $$TAG($$PARENT(ZN))="templateId" D ; ONLY LOOKING FOR TEMPLATES
165 . . . S ZG=$$PARENT($$PARENT(ZN))
166 . . . S ZG2=$$PARENT(ZG) ;COMPONENT THAT HOLDS THIS SECTION
167 . . . S CMT=$G(@ZD@(ZG,"X",1))
168 . . . I CMT="" S CMT="?"
169 . . . I $$TAG(ZG)="section" D ;START OF A SECTION
170 . . . . S CURSEC=$$PARENT(ZG)
171 . . . . S SECCMT=$G(@ZD@(CURSEC,"X",1))
172 . . . . I SECCMT="" S SECCMT="?"
173 . . . . S SECTID=$G(@ZD@(ZN,"T",1)) ;SECTION TEMPLATE ID
174 . . . S TID=$G(@ZD@(ZN,"T",1)) ;TEMPLATE ID
175 . . . I CURSEC'="" D ; IF WE ARE IN A SECTION
176 . . . . S CCDDIR(ZG2,CURSEC,$$TAG(ZG2),CMT,SECCMT)=TID
177 . . . . S DOMMAP(ZG2)=CURSEC_U_$$TAG(ZG2)_U_TID_U_SECTID
178 . . . W !,$$TAG(ZG2)," ",$G(@ZD@(ZG,"X",1))
179 . . . W " root ",ZN," ",@ZD@(ZN,"T",1)
180 Q
181 ;
182FINDALT ; PROCESS THE DOMMAP AND FIND THE ALT TAGS FOR COMPONENTS
183 ;
184 S ZI=""
185 F S ZI=$O(DOMMAP(ZI)) Q:ZI="" D ; FOR EACH NODE IN THE MAP
186 . S ZJ=DOMMAP(ZI) ;
187 . S PARNODE=$P(ZJ,U,1) ;PARENT NODE
188 . S TAG=$P(ZJ,U,2) ;THIS TAG
189 . S TID=$P(ZJ,U,3) ;THIS TEMPLATE ID
190 . S PARTID=$P(ZJ,U,4) ;PARENT TEMPLATE ID
191 . S ZIEN=$O(^C0CXDS(178.101,"TID",TID,"")) ;THIS NODE IEN
192 . S PARIEN=$O(^C0CXDS(178.101,"TID",PARTID,"")) ;PARENT NODE IEN
193 . I ZI=PARNODE D ; IF THIS IS A SECTION NODE
194 . . S ALTTAG=$$GET1^DIQ(178.101,PARIEN_",",.03) ;ALT TAG FIELD FOR PARENT
195 . . S NAME=$$GET1^DIQ(178.101,ZIEN_",",.01) ;NAME OF THIS NODE'S TEMPLATE
196 . . W ZI," ",TAG," ",ALTTAG," ",NAME,!
197 . . S C0CTAGS(ZI)=ALTTAG
198 . E D ; NOT A SECTION NODE
199 . . N ZJ S ZJ=""
200 . . S ZJ=$O(^C0CXDS(178.101,"D",PARIEN,ZIEN,"")) ;A WHEREUSED POINTER?
201 . . I ZJ'="" D ; THERE IS A NEW LABEL FOR THIS NODE
202 . . . N ZK
203 . . . S ZK=$$GET1^DIQ(178.111,ZJ_","_ZIEN_",",2)
204 . . . I ZK'="" D ;
205 . . . . W "FOUND ",ZK,!
206 . . . . S C0CTAGS(ZI)=ZK ; NEW TAG FOR INTERSECTION
207 Q
208 ;
209ALTTAG(NODE) ; SET Y EQUAL TO THE ALT TAG FOUND IN C0CTAGS IF NODE IF FOUND
210 ;
211 S Y=$G(C0CTAGS(NODE))
212 Q
213 ;
214SETCBK ; SET THE TAG CALLBACK FOR XPATH PROCESSSING OF THE CCD
[639]215 S C0CCBK("TAG")="D ALTTAG^C0CMCCD(ZOID)"
[630]216 Q
217 ;
[647]218OUTCCD(GARYIN) ; OUTPUT THE PARSED CCD TO A TEXT FILE
219 ;D TEST3^C0CMXML
[630]220 N ZT S ZT=$NA(^TMP("CCDOUT",$J))
221 N ZI,ZJ
222 S ZI=1 S ZJ=""
223 K @ZT
[647]224 F S ZJ=$O(GARYIN(ZJ)) Q:ZJ="" D ;
225 . S @ZT@(ZI)=ZJ_"^"_GARYIN(ZJ)
[630]226 . S ZI=ZI+1
227 S ONAME=$NA(@ZT@(1))
228 W $$OUTPUT^C0CXPATH(ONAME,"CCDOUT.txt","/home/vademo2/CCR")
229 K @ZT
230 Q
231 ;
232GENXDS(ZD) ; GENERATE THE XDS PROTOTYPE RECORDS FROM A CCDDIR ARRAY
233 ; ARRAY ELEMENTS LOOK LIKE:
234 ; CCDDIR(1659,1634,"observation"," Result observaion template "," Vital signs section template ")="2.16.840.1.113883.10.20.1.31"
235 ;or CCDDIR(cur node,section node,cur tag,cur name,sec name)=templateId
236 S ZF=178.101 ; FILE NUMBER FOR THE C0C XDS PROTOTYPE FILE
237 S ZI=$Q(@ZD@("")) ;FIRST ARRAY ELEMENT
238 S DONE=0
239 F Q:DONE D ;
240 . W @ZI,!
241 . S ZJ=$QS(ZI,5)
242 . S ZJ=$E(ZJ,2,$L(ZJ)) ;STRIP THE LEADING SPACE
243 . S C0CFDA(ZF,"?+1,",.01)=ZJ
244 . S C0CFDA(ZF,"?+1,",.02)=$QS(ZI,4) ; TAG FOR THIS TEMPLATE
245 . S C0CFDA(ZF,"?+1,",1)=@ZI
246 . D UPDIE
247 . S ZI=$Q(@ZI)
248 . I ZI="" S DONE=1
249 Q
250 ;
251WHRUSD(ZD) ; UPDATE THE C0C XDS FILE WITH WHERE USED DATA FROM
252 ; CCDDIR PASS BY NAME
253 ; ARRAY ELEMENTS LOOK LIKE:
254 ; CCDDIR(1634," Vital signs section template ",1659,"observation"," Result observaion template ")="2.16.840.1.113883.10.20.1.31"
255 ;or CCDDIR(section node,sec name, cur node,cur tag,cur name)=templateId
256 S ZF=178.101 ; FILE NUMBER FOR THE C0C XDS PROTOTYPE FILE
257 S ZSF=178.111 ; WHERE USED SUBFILE OF C0C XDS PROTOTYPE FILE
258 S ZI=$Q(@ZD@("")) ;FIRST ARRAY ELEMENT
259 S DONE=0
260 F Q:DONE D ;
261 . W @ZI
262 . S ZIEN=$O(^C0CXDS(178.101,"TID",@ZI,"")) ; IEN FOR THIS NODE'S TEMPLATE
263 . W " IEN:",ZIEN
264 . S ZJ=$QS(ZI,2)
265 . S ZJ=$E(ZJ,2,$L(ZJ)) ;STRIP THE LEADING SPACE
266 . S ZPIEN=$O(^C0CXDS(178.101,"B",ZJ,"")) ; PARENT IEN
267 . W " PARENT IEN:",ZPIEN
268 . S ZTAG=$QS(ZI,4) ; TAG FOR THIS TEMPLATE
269 . W " TAG:",ZTAG,!
270 . I ZIEN'=ZPIEN D ; ONLY FOR CHILD TEMPLATES
271 . . S C0CFDA(ZSF,"?+1,"_ZIEN_",",.01)=ZPIEN ; NEW SUBFILE ENTRY WITH PAR PTR
272 . . S C0CFDA(ZSF,"?+1,"_ZIEN_",",1)=ZTAG ; TAG FOR NEW ENTRY
273 . . D UPDIE
274 . ;S C0CFDA(ZF,"?+1,",1)=@ZI
275 . ;D UPDIE
276 . S ZI=$Q(@ZI)
277 . I ZI="" S DONE=1
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) D ;
285 . W "ERROR",!
286 . ZWR ZERR
287 . B
288 K C0CFDA
289 Q
290 ;
Note: See TracBrowser for help on using the repository browser.