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

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