source: ccr/trunk/rxnorm/trunk/routines/C0CRXNRD.m@ 1615

Last change on this file since 1615 was 1615, checked in by Sam Habiel, 11 years ago

Moved routines, exported globals as ZWR format

File size: 5.9 KB
Line 
1C0CRXNRD ; VEN/SMH - RxNorm Utilities: Routine to Read RxNorm files;2013-03-06 4:32 PM
2 ;;2.0;RX NORM;;May 11, 2012;Build 50
3 ; (C) Sam Habiel 2013
4 ; See license for terms of use.
5 ;
6 W "No entry from top" Q
7IMPORT(PATH) ; PUBLIC ENTRY POINT. Rest are private
8 I PATH="" QUIT
9 S U="^"
10 N STARTTIME S STARTTIME=$P($H,",")*24*60*60+$P($H,",",2)
11 D SAB(PATH),CONSO(PATH),SAT(PATH),STY(PATH),REL(PATH),DOC(PATH)
12 N ENDTIME S ENDTIME=$P($H,",")*24*60*60+$P($H,",",2)
13 W !,(ENDTIME-STARTTIME)/60_" minutes elapsed"
14 QUIT
15 ;
16 ; Everything is private from down on...
17DELFILED(FN) ; Delete file data; PEP procedure; only for RxNorm files
18 ; FN is Filenumber passed by Value
19 QUIT:$E(FN,1,3)'=176 ; Quit if not RxNorm files
20 N ROOT S ROOT=$$ROOT^DILFD(FN,"",1) ; global root
21 N ZERO S ZERO=@ROOT@(0) ; Save zero node
22 S $P(ZERO,U,3,9999)="" ; Remove entry # and last edited
23 K @ROOT ; Kill the file -- so sad!
24 S @ROOT@(0)=ZERO ; It riseth again!
25 QUIT
26GETLINES(PATH,FILENAME) ; Get number of lines in a file
27 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
28 U IO
29 N I,LINE
30 F I=1:1 R LINE:0 Q:$$STATUS^%ZISH
31 D CLOSE^%ZISH("FILE")
32 Q I-1
33CONSO(PATH,INCRES) ; Open and read concepts file: RXNCONSO.RRF
34 ; PATH ByVal, path of RxNorm files
35 ; INCRES ByVal, include restricted sources. 1 for yes, 0 for no
36 I PATH="" QUIT
37 S INCRES=+$G(INCRES) ; if not passed, becomes zero.
38 N FILENAME S FILENAME="RXNCONSO.RRF"
39 D DELFILED(176.001) ; delete data
40 N LINES S LINES=$$GETLINES(PATH,FILENAME)
41 N POP
42 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
43 IF POP D EN^DDIOL("Error reading file..., Please check...") G EX
44 N C0CCOUNT
45 F C0CCOUNT=1:1 D Q:$$STATUS^%ZISH
46 . U IO
47 . N LINE R LINE:0
48 . IF $$STATUS^%ZISH QUIT
49 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
50 . S ^C0CRXN(176.001,C0CCOUNT,0)=$TR(LINE,"|^","^|")
51 . ; TODO Implement Filtering:
52 . ; If the source is a restricted source, decide what to do based on what's asked.
53 . ; N SRCIEN S SRCIEN=$$FIND1^DIC(176.003,"","QX",SAB,"B") ; SrcIEN in RXNORM SOURCES file
54 . ; N RESTRIC S RESTRIC=$$GET1^DIQ(176.003,SRCIEN,14,"I") ; 14 is restriction field; values 0-4
55 . ; If RESTRIC is zero, then it's unrestricted. Everything else is restricted.
56 . ; If user didn't ask to include restricted sources, and the source is restricted, then quit
57 . ; I 'INCRES,RESTRIC QUIT
58EX D CLOSE^%ZISH("FILE")
59 N DIK S DIK="^C0CRXN(176.001," D IXALL^DIK
60 QUIT
61 ;
62 ;
63SAT(PATH) ; Open and read Concept and Atom attributes: RXNSAT.RRF
64 I PATH="" QUIT
65 N FILENAME S FILENAME="RXNSAT.RRF"
66 D DELFILED(176.002) ; delete data
67 N LINES S LINES=$$GETLINES(PATH,FILENAME)
68 N POP
69 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
70 IF POP W "Error reading file..., Please check...",! G EX2
71 N C0CCOUNT F C0CCOUNT=1:1 Q:$$STATUS^%ZISH D
72 . U IO
73 . N LINE R LINE:0
74 . IF $$STATUS^%ZISH QUIT
75 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
76 . ;
77 . ; We switch around the fields .01 and .09 because the .01 isn't always present; where as .09 is required
78 . N RXCUI1,ATN9
79 . S RXCUI1=$P(LINE,"|",1)
80 . S ATN9=$P(LINE,"|",9)
81 . S $P(LINE,"|",1)=ATN9
82 . S $P(LINE,"|",9)=RXCUI1
83 . ;
84 . ; Save off
85 . S ^C0CRXN(176.002,C0CCOUNT,0)=$TR(LINE,"|^","^|")
86EX2 D CLOSE^%ZISH("FILE")
87 N DIK S DIK="^C0CRXN(176.002," D IXALL^DIK
88 QUIT
89 ;
90 ;
91SAB(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
92 I PATH="" QUIT
93 N FILENAME S FILENAME="RXNSAB.RRF"
94 D DELFILED(176.003) ; delete data
95 N POP
96 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
97 IF POP W "Error reading file..., Please check...",! G EX3
98 N I F I=1:1 Q:$$STATUS^%ZISH D
99 . U IO
100 . N LINE R LINE:0
101 . IF $$STATUS^%ZISH QUIT
102 . U $P W I,! U IO ; Write I to the screen, then go back to reading the file
103 . ; Switch pieces 1 and 4 because 4 is always defined. Goes into .01 field.
104 . N VCUI S VCUI=$P(LINE,"|",1)
105 . N RSAB S RSAB=$P(LINE,"|",4)
106 . S $P(LINE,"|",1)=RSAB
107 . S $P(LINE,"|",4)=VCUI
108 . S ^C0CRXN(176.003,I,0)=$TR(LINE,"^|","|^")
109EX3 D CLOSE^%ZISH("FILE")
110 N DIK S DIK="^C0CRXN(176.003," D IXALL^DIK
111 QUIT
112STY(PATH) ; Open and read RxNorm Semantic types file: RXNSTY.RRF
113 I PATH="" QUIT
114 N FILENAME S FILENAME="RXNSTY.RRF"
115 D DELFILED(176.004) ; delete data
116 N LINES S LINES=$$GETLINES(PATH,FILENAME) ; Get # of lines
117 N POP
118 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
119 IF POP W "Error reading file..., Please check...",! G EX4
120 N I F I=1:1 Q:$$STATUS^%ZISH D
121 . U IO
122 . N LINE R LINE:0
123 . IF $$STATUS^%ZISH QUIT
124 . I '(I#1000) U $P W I," of ",LINES," read ",! U IO ; update every 1000
125 . S ^C0CRXN(176.004,I,0)=$TR(LINE,"^|","|^")
126EX4 D CLOSE^%ZISH("FILE")
127 N DIK S DIK="^C0CRXN(176.004," D IXALL^DIK
128 QUIT
129 ;
130REL(PATH) ; Open and read RxNorm Relationships file: RXNREL.RRF
131 I PATH="" QUIT
132 N FILENAME S FILENAME="RXNREL.RRF"
133 D DELFILED(176.005) ; delete data
134 N LINES S LINES=$$GETLINES(PATH,FILENAME) ; Get # of lines
135 N POP
136 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
137 IF POP W "Error reading file..., Please check...",! G EX5
138 N I F I=1:1 Q:$$STATUS^%ZISH D
139 . U IO
140 . N LINE R LINE:0
141 . IF $$STATUS^%ZISH QUIT
142 . I '(I#1000) U $P W I," of ",LINES," read ",! U IO ; update every 1000
143 . ; swap RXCUI1 location with SAB b/c SAB is required so can be .01 field
144 . N RXCUI1 S RXCUI1=$P(LINE,"|",1)
145 . N SAB S SAB=$P(LINE,"|",11)
146 . S $P(LINE,"|",1)=SAB
147 . S $P(LINE,"|",11)=RXCUI1
148 . S ^C0CRXN(176.005,I,0)=$TR(LINE,"^|","|^")
149EX5 D CLOSE^%ZISH("FILE")
150 N DIK S DIK="^C0CRXN(176.005," D IXALL^DIK
151 QUIT
152DOC(PATH) ; Open the read RxNorm Abbreviation Documentation file: RXNDOC.RRF
153 I PATH="" QUIT
154 N FILENAME S FILENAME="RXNDOC.RRF"
155 D DELFILED(176.006) ; delete data
156 N LINES S LINES=$$GETLINES(PATH,FILENAME) ; Get # of lines
157 N POP
158 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
159 IF POP W "Error reading file..., Please check...",! G EX6
160 N I F I=1:1 Q:$$STATUS^%ZISH D
161 . U IO
162 . N LINE R LINE:0
163 . IF $$STATUS^%ZISH QUIT
164 . I '(I#1000) U $P W I," of ",LINES," read ",! U IO ; update every 1000
165 . S ^C0CRXN(176.006,I,0)=$TR(LINE,"^|","|^")
166EX6 D CLOSE^%ZISH("FILE")
167 N DIK S DIK="^C0CRXN(176.006," D IXALL^DIK
168 QUIT
Note: See TracBrowser for help on using the repository browser.