source: fmts/trunk/p/C0XOTLN.m@ 1699

Last change on this file since 1699 was 1612, checked in by George Lilly, 12 years ago

updates for NLMVS

File size: 8.1 KB
RevLine 
[1610]1C0XOTLN ; GPL - Fileman Triples Outline Processing ;2/20/13 17:05
2 ;;0.1;C0X;nopatch;noreleasedate;Build 7
3 ;Copyright 2013 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 ;
22roots(rtn) ; return the root subjects - defined by subjects with no parents
23 ; but with children
24 n sn,on,zi
25 s sn=$na(^C0X(101,"SOP")) ; subject index
26 S on=$na(^C0X(101,"OSP")) ; object index
27 s zi=""
28 f s zi=$o(@sn@(zi)) q:zi="" d ; for each subject
29 . i $d(@on@(zi)) q ; it is a child
30 . n zj s zj=""
31 . n hasChild s hasChild=0
32 . f s zj=$o(@sn@(zi,zj)) q:zj="" d ; for each object in this subject
33 . . i $d(@sn@(zj)) s hasChild=1
34 . s:hasChild rtn($$STR^C0XGET1(zi))=""
35 q
36 ;
37showorg ;
38 d roots(.g)
39 ;s DEBUG=1
40 d showlist(.g2,"g","*")
41 q
42 ;
43showlist(zrtn,lst,prefix) ;
44 n zi,zj,zk
45 w:$g(DEBUG) !,"entering showlist "_prefix_" ",$o(@lst@(""))
46 s zi=""
47 f s zi=$o(@lst@(zi)) q:zi="" d ;
48 . n zs s zs=$$NSP2^C0XUTIL(zi)
49 . ;w !,prefix_" ",zs
50 . n tr
51 . d triples^C0XGET1(.tr,zs,,,,"array")
52 . i '$d(tr) q ;
53 . s zj=""
54 . f s zj=$o(tr(zj)) q:zj="" d ;
55 . . w !,prefix_"* "_$$NSP2^C0XUTIL($p(tr(zj),"^",2))_" "
56 . . n isub s isub=$$isSubject($p(tr(zj),"^",3))
57 . . i isub d ;
58 . . . n tr2 s tr2($p(tr(zj),"^",3))=""
59 . . . d showlist(.zrtn,"tr2",prefix_"*")
60 . . i 'isub w $p(tr(zj),"^",3)
61 q
62 ;
63isSubject(zy) ; extrinsic which returns true if zy is a pointer to a subject
64 n zr s zr=0
65 i $d(^C0X(101,"SPO",$$IENOF^C0XF2N(zy))) s zr=1
66 q zr
67 ;
68 ; -- some python that does a tree
69 ;def tree(node, prefix='|--'):
70 ; txt=('' if (node.text is None) or (len(node.text) == 0) else node.text);
71 ; txt2 = txt.replace('\n','');
72 ; print prefix+cdautil.clean(node.tag)+' '+txt2;
73 ; for att in node.attrib:
74 ; print prefix+' : '+cdautil.clean2(att)+'^'+node.attrib[att];
75 ; for child in node:
76 ; tree(child,'| '+prefix );
77tree(where,prefix) ; show a tree starting at a node in MXML. node is passed by name
78 ;
79 i $g(prefix)="" s prefix="|--" ; starting prefix
80 i '$d(C0XJOB) s C0XJOB=$J
81 n node s node=$na(^TMP("MXMLDOM",C0XJOB,1,where))
82 n txt s txt=$$CLEAN($$ALLTXT(node))
83 w !,prefix_@node_" "_txt
84 n zi s zi=""
85 f s zi=$o(@node@("A",zi)) q:zi="" d ;
86 . w !,prefix_" : "_zi_"^"_$g(@node@("A",zi))
87 f s zi=$o(@node@("C",zi)) q:zi="" d ;
88 . d tree(zi,"| "_prefix)
89 q
90 ;
91show(what) ;
92 ;S C0XJOB=26295
93 I '$D(C0XJOB) S C0XJOB=$J
94 d tree(what)
95 q
96 ;
[1612]97tree2(where,prefix) ; show a tree starting at a node in MXML. node is passed by name
98 ; tree2 handles ConceptLists as tables
99 i $g(prefix)="" s prefix="|--" ; starting prefix
100 i '$d(C0XJOB) s C0XJOB=$J
101 n node s node=$na(^TMP("MXMLDOM",C0XJOB,1,where))
102 ;n txt s txt=$$CLEAN($$ALLTXT(node))
103 n txt d alltxt(.txt,node)
104 ;w !,prefix_@node_" "_txt
105 n zk s zk=""
106 f s zk=$o(txt(zk)) q:zk="" d ;
107 . i zk=1 d out(prefix_@node_" "_txt(zk)) q ;
108 . d out(prefix_txt(zk))
109 i @node["ns0:ConceptList" d q ;
110 . d clist(where,prefix)
111 n zi s zi=""
112 f s zi=$o(@node@("A",zi)) q:zi="" d ;
113 . ;w !,prefix_" : "_zi_"^"_$g(@node@("A",zi))
114 . d out(prefix_" : "_zi_"^"_$g(@node@("A",zi)))
115 n grpstart s grpstart=0
116 f s zi=$o(@node@("C",zi)) q:zi="" d ;
117 . i @node@("C",zi)="ns0:RevisionDate" d newgrp
118 . i @node@("C",zi)="ns0:Group" d group(zi) q ;
119 . d tree2(zi,"| "_prefix)
120 d:grpstart grpout
121 q
122 ;
123newgrp ; kill the group array for a new group
124 ;W !,"NEW GROUP"
125 k ^TMP("C0XNLMVS",$J,"GROUP")
126 q
127 ;
128group(where) ; add a group node to the group array
129 s grpstart=1
130 n gn s gn=$na(^TMP("C0XNLMVS",$J,"GROUP"))
131 n node s node=$na(^TMP("MXMLDOM",C0XJOB,1))
132 n gnum s gnum=$g(@node@(where,"A","ID"))
133 i gnum="" d q ;
134 . w !,"error finding group number ",where
135 n var s var=@node@(where,"A","displayName")
136 n valref s valref=$o(@node@(where,"C",""))
137 i valref="" d q ;
138 . w !,"error finding value reference ",where
139 n val s val=@node@(valref,"T",1)
140 s @gn@(gnum,var)=val
141 q
142 ;
143grpout ; output the group array
144 ;zwr ^TMP("C0XNLMVS",$J,*)
145 ;b
146 n gn s gn=$na(^TMP("C0XNLMVS",$J,"GROUP"))
147 n grp s grp=""
148 f s grp=$o(@gn@(grp)) q:grp="" d ;
149 . d out("--------------------------------------------------------------")
150 . n attr s attr=""
151 . f s attr=$o(@gn@(grp,attr)) q:attr="" d ;
152 . . d out(attr_": "_@gn@(grp,attr))
153 q
154 ;
155out(txt) ; add line to output array
156 s c0xout=$na(^TMP("C0XOUT",$J))
157 n cnt
158 s cnt=$o(@c0xout@(""),-1)
159 i cnt="" s cnt=0
160 s @c0xout@(cnt+1)=txt
161 q
162 ;
163clist(where,prefix,nohead)
164 n nd s nd=$na(^TMP("MXMLDOM",C0XJOB,1))
165 ;i '$d(nohead) s nohead=0
166 ;i 'nohead d ;
167 d out($j("Code",20)_$j("System",10)_$j("Description",20))
168 n zzi s zzi=""
169 f s zzi=$o(@nd@(where,"C",zzi)) q:zzi="" d ;
170 . n code,system,desc
171 . s code=$g(@nd@(zzi,"A","code"))
172 . s system=$g(@nd@(zzi,"A","codeSystemName"))
173 . s desc=$g(@nd@(zzi,"A","displayName"))
174 . d out($j(code,20)_$j(system,10)_" "_desc)
175 ;w @nd,":",@nd@("T",1)
176 q
177 ;
178alltxt(rtn,node) ; handle arrays of text
179 m rtn=@node@("T")
180 n zj s zj=""
181 f s zj=$o(rtn(zj)) q:zj="" d ;
182 . s rtn(zj)=$$CLEAN(rtn(zj))
183 . s rtn(zj)=$$LDBLNKS(rtn(zj))
184 . i rtn(zj)="" k rtn(zj)
185 . i (rtn(zj)=" ")&(zj>1) k rtn(zj)
186 q
187 ;
[1610]188ALLTXT(where) ; extrinsic which returns all text lines from the node .. concatinated
189 ; together
190 n zti s zti=""
191 n ztr s ztr=""
192 f s zti=$o(@where@("T",zti)) q:zti="" d ;
193 . s ztr=ztr_$g(@where@("T",zti))
194 q ztr
195 ;
196CLEAN(STR) ; extrinsic function; returns string - gpl borrowed from the CCR package
197 ;; Removes all non printable characters from a string.
198 ;; STR by Value
199 N TR,I
200 F I=0:1:31 S TR=$G(TR)_$C(I)
201 S TR=TR_$C(127)
202 N ZR S ZR=$TR(STR,TR)
203 S ZR=$$LDBLNKS(ZR) ; get rid of leading blanks
204 QUIT ZR
205 ;
206LDBLNKS(st) ; extrinsic which removes leading blanks from a string
[1611]207 n pos f pos=1:1:$l(st) q:$e(st,pos)'=" "
208 q $e(st,pos,$l(st))
[1610]209 ;
210VACCD ; set C0XJOB to the VA CCD
211 s C0XJOB=14921
212 q
213 ;
214NLMVS ; set C0XJOB to the NLM Values Set xml
215 s C0XJOB=26295
216 Q
217 ;
[1612]218contents(zrtn,ids) ; produce an agenda for the docId 1 in the MXML dom
[1610]219 ; generally, a first level index to the document
220 ; set C0XJOB if you want to use a different $J to locate the dom
221 ; zrtn passed by name
[1612]222 ; ids=1 names them by number ids=0 or null names them by displayname
[1610]223 ;s C0XJOB=26295
[1612]224 D NLMVS
[1610]225 n zi s zi=""
226 i '$d(docId) s docId=1
227 i '$D(C0XJOB) s C0XJOB=$J
228 n dom s dom=$na(^TMP("MXMLDOM",C0XJOB,docId))
229 f s zi=$o(@dom@(1,"C",zi)) q:zi="" d ;
[1612]230 . n zn ;
231 . d:$g(ids) ;
232 . . s zn=$tr($g(@dom@(zi,"A","ID")),".","-")_".txt"
233 . . s @zrtn@(zn,zi)=""
234 . d:'$g(ids) ;
235 . . s zn=$tr($g(@dom@(zi,"A","displayName"))," ","_")_".txt"
236 . . s zn=$tr(zn,"()","") ; get rid of parens for valid filename
237 . . s zn=$tr(zn,"/","-") ; get rid of slash for valid filename
238 . . s @zrtn@(zn,zi)=""
[1610]239 q
[1612]240 ;
241export ; exports separate files for each value set
242 ; one copy in a file with a text name based on the displayName
243 n g,zi,fname,where,dirname,gn
244 s gn=$na(^TMP("C0XOUT",$J))
245 s dirname="/home/wvehr2/valuesets/by-name/"
246 s zi=""
247 d contents("g") ; first with text names
248 f s zi=$o(g(zi)) q:zi="" d ;
249 . s fname=zi
250 . s where=$o(g(zi,""))
251 . k @gn
252 . d tree2(where,"| ")
253 . n gn2 s gn2=$na(@gn@(1)) ; name for gtf
254 . s ok=$$GTF^%ZISH(gn2,3,dirname,fname)
255 q
256 ;
257export2 ; exports separate files for each value set
258 ; one copy in a file with a numeric file name based on ID
259 n g,zi,fname,where,dirname,gn
260 s gn=$na(^TMP("C0XOUT",$J))
261 s dirname="/home/wvehr2/valuesets/by-id/"
262 s zi=""
263 d contents("g",1) ; with id names
264 f s zi=$o(g(zi)) q:zi="" d ;
265 . s fname=zi
266 . s where=$o(g(zi,""))
267 . k @gn
268 . d tree2(where,"| ")
269 . n gn2 s gn2=$na(@gn@(1)) ; name for gtf
270 . s ok=$$GTF^%ZISH(gn2,3,dirname,fname)
271 q
[1610]272 ;
Note: See TracBrowser for help on using the repository browser.