source: ccr/trunk/p/C0CRXNRD.m@ 1588

Last change on this file since 1588 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/C0CRXNRD.m1290
    /ccr/branches/ohum/p/C0CRXNRD.m1291-1543
    /ccr/branches/ohum/p/p/C0CRXNRD.m1287-1289
File size: 6.0 KB
Line 
1C0CRXNRD ; WV/SMH - CCR/CCD PROJECT: Routine to Read RxNorm files;11/15/08
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ; Copyright Sam Habiel 2008.
4 ;
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.
9 ;
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.
14 ;
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/>.
17 ;
18 W "No entry from top" Q
19IMPORT(PATH) ; Main entry point
20 I PATH="" QUIT
21 D READSRC(PATH),READCON(PATH),READNDC(PATH)
22 QUIT
23 ;
24DELFILED(FN) ; Delete file data; PEP procedure; only for RxNorm files
25 ; FN is Filenumber passed by Value
26 QUIT:$E(FN,1,3)'=176 ; Quit if not RxNorm files
27 D CLEAN^DILF ; Clean FM variables
28 N ROOT S ROOT=$$ROOT^DILFD(FN,"",1) ; global root
29 N ZERO S ZERO=@ROOT@(0) ; Save zero node
30 S $P(ZERO,U,3,9999)="" ; Remove entry # and last edited
31 K @ROOT ; Kill the file -- so sad!
32 S @ROOT@(0)=ZERO ; It riseth again!
33 QUIT
34GETLINES(PATH,FILENAME) ; Get number of lines in a file
35 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
36 U IO
37 N I
38 F I=1:1 R LINE:0 Q:$$STATUS^%ZISH
39 D CLOSE^%ZISH("FILE")
40 Q I-1
41READCON(PATH,INCRES) ; Open and read concepts file: RXNCONSO.RRF; EP
42 ; PATH ByVal, path of RxNorm files
43 ; INCRES ByVal, include restricted sources. 1 for yes, 0 for no
44 I PATH="" QUIT
45 S INCRES=+$G(INCRES) ; if not passed, becomes zero.
46 N FILENAME S FILENAME="RXNCONSO.RRF"
47 D DELFILED(176.001) ; delete data
48 N LINES S LINES=$$GETLINES(PATH,FILENAME)
49 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
50 IF POP D EN^DDIOL("Error reading file..., Please check...") G EX
51 N C0CCOUNT
52 F C0CCOUNT=1:1 D Q:$$STATUS^%ZISH
53 . U IO
54 . N LINE R LINE:0
55 . IF $$STATUS^%ZISH QUIT
56 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
57 . N RXCUI,RXAUI,SAB,TTY,CODE,STR ; Fileman fields numbers below
58 . S RXCUI=$P(LINE,"|",1) ; .01
59 . S RXAUI=$P(LINE,"|",8) ; 1
60 . S SAB=$P(LINE,"|",12) ; 2
61 . ; If the source is a restricted source, decide what to do based on what's asked.
62 . N SRCIEN S SRCIEN=$$FIND1^DIC(176.003,"","QX",SAB,"B") ; SrcIEN in RXNORM SOURCES file
63 . N RESTRIC S RESTRIC=$$GET1^DIQ(176.003,SRCIEN,14,"I") ; 14 is restriction field; values 0-4
64 . ; If RESTRIC is zero, then it's unrestricted. Everything else is restricted.
65 . ; If user didn't ask to include restricted sources, and the source is restricted, then quit
66 . I 'INCRES,RESTRIC QUIT
67 . S TTY=$P(LINE,"|",13) ; 3
68 . S CODE=$P(LINE,"|",14) ; 4
69 . S STR=$P(LINE,"|",15) ; 5
70 . ; Remove embedded "^"
71 . S STR=$TR(STR,"^")
72 . ; Convert STR into an array of 80 characters on each line
73 . N STRLINE S STRLINE=$L(STR)\80+1
74 . ; In each line, chop 80 characters off, reset STR to be the rest
75 . N J F J=1:1:STRLINE S STR(J)=$E(STR,1,80) S STR=$E(STR,81,$L(STR))
76 . ; Now, construct the FDA array
77 . N RXNFDA
78 . S RXNFDA(176.001,"+1,",.01)=RXCUI
79 . S RXNFDA(176.001,"+1,",1)=RXAUI
80 . S RXNFDA(176.001,"+1,",2)=SAB
81 . S RXNFDA(176.001,"+1,",3)=TTY
82 . S RXNFDA(176.001,"+1,",4)=CODE
83 . N RXNIEN S RXNIEN(1)=C0CCOUNT
84 . D UPDATE^DIE("","RXNFDA","RXNIEN")
85 . I $D(^TMP("DIERR",$J)) D EN^DDIOL("ERROR") G EX
86 . ; Now, file WP field STR
87 . D WP^DIE(176.001,C0CCOUNT_",",5,,$NA(STR))
88EX D CLOSE^%ZISH("FILE")
89 QUIT
90READNDC(PATH) ; Open and read NDC/RxNorm/VANDF relationship file: RXNSAT.RRF
91 I PATH="" QUIT
92 N FILENAME S FILENAME="RXNSAT.RRF"
93 D DELFILED(176.002) ; delete data
94 N LINES S LINES=$$GETLINES(PATH,FILENAME)
95 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
96 IF POP W "Error reading file..., Please check...",! G EX2
97 F C0CCOUNT=1:1 Q:$$STATUS^%ZISH D
98 . U IO
99 . N LINE R LINE:0
100 . IF $$STATUS^%ZISH QUIT
101 . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
102 . IF LINE'["NDC|RXNORM" QUIT
103 . ; Otherwise, we are good to go
104 . N RXCUI,NDC ; Fileman fields below
105 . S RXCUI=$P(LINE,"|",1) ; .01
106 . S NDC=$P(LINE,"|",11) ; 2
107 . ; Using classic call to update.
108 . N DIC,X,DA,DR
109 . K DO
110 . S DIC="^C0CRXN(176.002,",DIC(0)="F",X=RXCUI,DIC("DR")="2////"_NDC
111 . D FILE^DICN
112 . I Y<1 U $P W !,"THERE IS TROUBLE IN RIVER CITY",! G EX2
113EX2 D CLOSE^%ZISH("FILE")
114 QUIT
115READSRC(PATH) ; Open the read RxNorm Sources file: RXNSAB.RRF
116 I PATH="" QUIT
117 N FILENAME S FILENAME="RXNSAB.RRF"
118 D DELFILED(176.003) ; delete data
119 D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
120 IF POP W "Error reading file..., Please check...",! G EX3
121 F I=1:1 Q:$$STATUS^%ZISH D
122 . U IO
123 . N LINE R LINE:0
124 . IF $$STATUS^%ZISH QUIT
125 . U $P W I,! U IO ; Write I to the screen, then go back to reading the file
126 . N VCUI,RCUI,VSAB,RSAB,SON,SF,SVER,SRL,SCIT ; Fileman fields numbers below
127 . S VCUI=$P(LINE,"|",1) ; .01
128 . S RCUI=$P(LINE,"|",2) ; 2
129 . S VSAB=$P(LINE,"|",3) ; 3
130 . S RSAB=$P(LINE,"|",4) ; 4
131 . S SON=$P(LINE,"|",5) ; 5
132 . S SF=$P(LINE,"|",6) ; 6
133 . S SVER=$P(LINE,"|",7) ; 7
134 . S SRL=$P(LINE,"|",14) ; 14
135 . S SCIT=$P(LINE,"|",25) ; 25
136 . ; Remove embedded "^"
137 . S SCIT=$TR(SCIT,"^")
138 . ; Convert SCIT into an array of 80 characters on each line
139 . ; In each line, chop 80 characters off, reset SCIT to be the rest
140 . N SCITLINE S SCITLINE=$L(SCIT)\80+1
141 . F J=1:1:SCITLINE S SCIT(J)=$E(SCIT,1,80) S SCIT=$E(SCIT,81,$L(SCIT))
142 . ; Now, construct the FDA array
143 . N RXNFDA
144 . S RXNFDA(176.003,"+"_I_",",.01)=VCUI
145 . S RXNFDA(176.003,"+"_I_",",2)=RCUI
146 . S RXNFDA(176.003,"+"_I_",",3)=VSAB
147 . S RXNFDA(176.003,"+"_I_",",4)=RSAB
148 . S RXNFDA(176.003,"+"_I_",",5)=SON
149 . S RXNFDA(176.003,"+"_I_",",6)=SF
150 . S RXNFDA(176.003,"+"_I_",",7)=SVER
151 . S RXNFDA(176.003,"+"_I_",",14)=SRL
152 . D UPDATE^DIE("","RXNFDA")
153 . I $D(^TMP("DIERR",$J)) U $P W "ERR" G EX
154 . ; Now, file WP field SCIT
155 . D WP^DIE(176.003,I_",",25,,$NA(SCIT))
156EX3 D CLOSE^%ZISH("FILE")
157 Q
Note: See TracBrowser for help on using the repository browser.