source: ccr/trunk/rxnorm/trunk/routines/C0CRXNLK.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: 9.7 KB
Line 
1C0CRXNLK ; VEN/SMH - RxNorm Lookup Utilities ;2013-04-08 5:00 PM
2 ;;1.0;RX NORM;;Apr 25, 2012;Build 99
3 ;(c) Sam Habiel 2013
4 ; See accompanying license. Don't use otherwise.
5 ;
6 S IO=$P
7 N DIQUIET S DIQUIET=1
8 D DT^DICRW
9 D EN^XTMUNIT($T(+0),1)
10 QUIT
11 ;
12GCN2RXN(GCN) ; $$ Public - Get RxNorm CUI using GCN
13 ; Input: GCN by Value
14 ; Output: Extrinsic
15 S GCN=$$RJ^XLFSTR(GCN,6,0) ; pad to six digits by zeros (123 becomes 000123)
16 N IEN S IEN=$O(^C0CRXN(176.001,"STC","NDDF","CDC",GCN,"")) ; Get Entry
17 Q ^(IEN)
18 ;
19GCN2RXNT ; @TEST - Test Get RxNorm CUI using GCN
20 N L F L=1:1 N LN S LN=$T(GCN2RXND+L) Q:LN["<<END>>" Q:LN="" D
21 . N GCN S GCN=$P(LN,";",3)
22 . N RXN S RXN=$P(LN,";",4)
23 . D CHKEQ^XTMUNIT($$GCN2RXN(GCN),RXN,"Translation from GCN to RXCUI failed")
24 QUIT
25 ;
26GCN2RXND ; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
27 ;;16033;991632
28 ;;8208;310429
29 ;;1275;628953
30 ;;18;197604
31 ;;346;884173
32 ;;<<END>>
33 ;
34 ;
35 ;
36RXN2VUI(RXNCUI) ; $$ Public - Get VUID(s) for given RXNCUI for Clinical Drug
37 ; Input: RXNCUI by Value
38 ; Output: Caret delimited extrinsic. Should not be more than 2 entries.
39 N C0PVUID S C0PVUID=""
40 N I S I=""
41 F S I=$O(^C0CRXN(176.001,"STX","VANDF","CD",RXNCUI,I)) Q:I="" S C0PVUID=C0PVUID_^(I)_U
42 S C0PVUID=$E(C0PVUID,1,$L(C0PVUID)-1) ; remove trailing ^
43 ; TODO: Return only the quantified form using:
44 ; I $O(^C0CRXN(176.005,"RXCUIREL",RXN,"has_quantified_form","")) N QF S QF=$O(^("")) Q $O(^C0CRXN(176.001,"RXN2VUID",QF,""))
45 Q C0PVUID
46 ;
47RXN2VUIT ; @TEST - Get VUIDs given RxNorm values
48 N L F L=1:1 N LN S LN=$T(RXN2VUID+L) Q:LN["<<END>>" Q:LN="" D
49 . N RXN S RXN=$P(LN,";",3)
50 . N VUIDS S VUIDS=$P(LN,";",4)
51 . D CHKEQ^XTMUNIT($$RXN2VUI(RXN),VUIDS,"Translation from RXNCUI to VUID failed")
52 QUIT
53 ;
54RXN2VUID ; @DATA - Data items for previous test
55 ;;991632;4006455
56 ;;310429;4002369^4013941
57 ;;628953;4000874^4000856^4013966^4015798^4015799
58 ;;197604;4003335^4015937
59 ;;884173;4002469^4013919
60 ;;<<END>>
61 ;
62 ;
63 ;
64VUI2VAP(VUID) ; $$ Public - Get VA Product IEN from VUID
65 ; Input VUID by Value
66 ; Output: Extrinsic
67 Q $$FIND1^DIC(50.68,"","QX",VUID,"AVUID")
68 ;
69VUI2VAPT ; @TEST - Get VA Product IEN from VUID
70 N L F L=1:1 N LN S LN=$T(VUI2VAPD+L) Q:LN["<<END>>" Q:LN="" D
71 . N VUID S VUID=$P(LN,";",3)
72 . N VAP S VAP=$P(LN,";",4)
73 . D CHKEQ^XTMUNIT($$VUI2VAP(VUID),VAP,"Translation from VUID to VA PRODUCT failed")
74 QUIT
75 ;
76VUI2VAPD ; @DATA - Data for above test
77 ;;4006455;5932
78 ;;4002369;1784
79 ;;4000874;252
80 ;;4003335;2756
81 ;;4002469;1884
82 ;;<<END>>
83 ;
84 ;
85 ;
86VAP2MED(VAPROD) ; $$ Public - Get Drug(s) using VA Product IEN
87 ; Un-Unit-testable: Drug files differ between sites.
88 ; Input: VA Product IEN By Value
89 ; OUtput: Caret delimited extrinsic
90 ; This code inspired from PSNAPIs
91 ; WHY THE HELL WOULD I USE A TEXT INDEX?
92 ; It's my only option. Creating new xrefs on the drug file doesn't help
93 ; as they are not filled out when adding a drug (IX[ALL]^DIK isn't called).
94 N MEDS S MEDS="" ; result
95 N PN,PN1 ; Product Name, abbreviated product name.
96 S PN=$P(^PSNDF(50.68,VAPROD,0),"^"),PN1=$E(PN,1,30)
97 N P50 S P50=0 ; looper through VAPN index which is DRUG file entry
98 F S P50=$O(^PSDRUG("VAPN",PN1,P50)) Q:'P50 D ; for each text match
99 . I $P(^PSDRUG(P50,"ND"),"^",3)=VAPROD S MEDS=$G(MEDS)_P50_U ; check that the VA PRODUCT pointer is the same as ours.
100 S:MEDS MEDS=$E(MEDS,1,$L(MEDS)-1) ; remove trailing ^
101 Q MEDS
102 ;
103 ;
104RXN2MEDS(RXNCUI) ; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
105 ; Input: SCD RXNCUI
106 ; Output; Caret delimited extrinsic
107 ; Un-unit testable
108 N VUIDS S VUIDS=$$RXN2VUI(RXNCUI) ; Get VUID from RXNCUI
109 ; TODO: Decide which VUID to use!
110 N VAPROD S VAPROD=$$VUI2VAP(VUIDS) ; Get VA Product from VUID
111 N MEDS S MEDS=$$VAP2MED(VAPROD) ; Get Meds from VA Product
112 QUIT MEDS
113 ;
114FDI2RXN(BASE) ; $$ Public - Get RxNorm CUI for FDB Ingredient/Base
115 ; ^C0CRXN(176.001,"STC","NDDF","IN","014739",1000870)=1362160
116 ; Input: BASE By Value
117 ; Output: RxNorm CUI
118 S BASE=$$RJ^XLFSTR(BASE,6,0) ; pad to six digits by zeros (123 becomes 000123)
119 N IEN S IEN=$O(^C0CRXN(176.001,"STC","NDDF","IN",BASE,"")) Q ^(IEN)
120 ;
121FDI2RXNT ; @TEST - Test Get RxNorm CUI for FDB Ingredient/Base
122 D CHKEQ^XTMUNIT($$FDI2RXN(14739),1362160,"$$FDI2RXN failed")
123 QUIT
124 ;
125 ;
126 ;
127RXN2VIN(RXNCUI) ; $$ Public - Get VUID Ingredient for RxNorm CUI
128 ; ^C0CRXN(176.001,"STX","VANDF","IN",1366467,1008555)=4031768
129 ; Input: RXNCUI By Value
130 ; Output: VUID
131 N IEN S IEN=$O(^C0CRXN(176.001,"STX","VANDF","IN",RXNCUI,"")) Q ^(IEN)
132 ;
133RXN2VINT ; @TEST - Test Get VUID Ingredient for RxNorm CUI
134 D CHKEQ^XTMUNIT($$RXN2VIN(1366467),4031768,"$$RXN2VIN failed")
135 QUIT
136 ;
137 ;
138 ;
139VIN2VAG(VUID) ; $$ Public - Get VA Generic for VUID Ingredient
140 ; Input: VUID By Value
141 ; Output: IEN^VA Generic Name (i.e. .01 field value)
142 N C0PIEN S C0PIEN=$$FIND1^DIC(50.6,"","QX",VUID,"AVUID")
143 N C0P01 S C0P01=$$GET1^DIQ(50.6,C0PIEN,.01)
144 Q C0PIEN_"^"_C0P01
145 ;
146VIN2VAGT ; @TEST - Test Get VA Generic for VUID Ingredient
147 D CHKEQ^XTMUNIT(+$$VIN2VAG(4023636),2832,"$$VIN2VAG failed")
148 QUIT
149 ;
150 ;
151 ;
152FDI2VAG(BASE) ; $$ Public - Get VA Generic for FDB Ingredient/Base
153 ; TODO:Not tested...
154 ; Input: BASE By Value
155 ; Output: IEN^VA Generic Name (i.e. .01 field value)
156 Q $$VIN2VAG($$RXN2VIN($$FDI2RXN(BASE)))
157 ;
158VIN2DIN(VUID) ; $$ Public - Get Drug Ingredient for VUID Ingredient
159 ; TODO:Not tested...
160 ; Input: VUID By Value
161 ; Output: IEN^Drug Ingredient Name (i.e. .01 field value)
162 N C0PIEN S C0PIEN=$$FIND1^DIC(50.416,"","QX",VUID,"AVUID")
163 N C0P01 S C0P01=$$GET1^DIQ(50.416,C0PIEN,.01)
164 Q C0PIEN_"^"_C0P01
165 ;
166FDI2DIN(BASE) ; $$ Public - Get Drug Ingredient for FDB Ingredient/Base
167 ; TODO:Not tested...
168 ; Input: BASE By Value
169 ; Output: IEN^Drug Ingredient Name (i.e. .01 field value)
170 Q $$VIN2DIN($$RXN2VIN($$FDI2RXN(BASE)))
171 ;
172VUI2RXN(VUID) ; $$ Public - Get RXNCUI for VUID (any VUID type)
173 ; Input: VUID By Value
174 ; Output: RXNCUIs delimited by ^
175 ; Get all entries whose code is the VUID and are in the VA NDF which are clinical drugs
176 D FIND^DIC(176.001,,"@;.01","PQX",VUID,,"CODE","I $P(^(0),U,12,13)=""VANDF^CD""")
177 ; Deserialise it into a single string
178 ; ^TMP("DILIST",4844,0)="1^*^0^"
179 ; ^TMP("DILIST",4844,0,"MAP")="IEN^.01"
180 ; ^TMP("DILIST",4844,1,0)="1006351^1364462"
181 N RXNS S RXNS=""
182 N I F I=0:0 S I=$O(^TMP("DILIST",$J,I)) Q:'I S RXNS=RXNS_$P(^(I,0),U,2)_U
183 S RXNS=$E(RXNS,1,$L(RXNS)-1)
184 QUIT RXNS
185 ;
186MED2RXN(DA) ; $$ Public - Get RxNorm CUI for Drug
187 ; Input: DA - Medication IEN
188 ; Output: RXNCUIs delimited by ^
189 N ND S ND=$G(^PSDRUG(DA,"ND")) ; ND Node
190 N VAP S VAP=$P(ND,U,3) ; VA Product Pointer
191 Q:'VAP "" ; quit if empty
192 N VUID S VUID=+^PSNDF(50.68,VAP,"VUID") ; Get VUID
193 I 'VUID S $EC=",U1," ; Must exist
194 Q $$VUI2RXN(VUID)
195 ;
196MED2SCDN(DA) ; $$ Public - Medication to Semantic Clinical Drug Name
197 ; Input: DA - Medication IEN
198 ; Output: The Canonical Semantic Clinical Drug name
199 N RXNCUI S RXNCUI=$$MED2RXN(DA)
200 Q:'RXNCUI ""
201 N IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCD",RXNCUI,"")) ; Let's try generic drug
202 I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SBD",RXNCUI,"")) ; Let's try non-bioequivalent Brands then
203 I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","GPCK",RXNCUI,"")) ; Let's try a Generic combination package
204 I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCDF",RXNCUI,"")) ; Let's try a Clinical Drug and Form (Like Metamucil)
205 Q:'IEN "" ; Apparently not every VUID has a corresponding RXNCUI SCD.
206 Q $P(^C0CRXN(176.001,IEN,0),U,15)
207 ;
208RXN2NDI(RXNCUI) ; $$ Public - Get NDDF Ingredient for RXNCUI
209 ; Input: RXNCUI By Value
210 ; Output: NDDF Base code
211 ; TODO:Not tested...
212 N IEN S IEN=$O(^C0CRXN(176.001,"STX","NDDF","IN",RXNCUI,"")) Q ^(IEN)
213 ;
214VIN2NDI(VUID) ; $$ Public - Get NDDF Ingredient for VUID
215 ; NB: WILL ONLY WORK IF VUID IS AN INGREDIENT VUID, NOT A CLINICAL DRUG
216 ; Input: VUID By Value
217 ; Output: NDDF Base code
218 ; TODO:Not tested...
219 Q $$RXN2NDI($$VUI2RXN(VUID))
220 ;
221 ; ---
222 ;
223NDC2RXN(NDC) ; $$ Public - Get RxCUI given the NDC
224 ; NB: Will only work if passed NDC is in 5-4-2 format.
225 ; Input: NDC By Value in 5-4-2 Format
226 ; Output: RxNorm Code.
227 S NDC=$TR(NDC,"-")
228 N IEN S IEN=$O(^C0CRXN(176.002,"ASAA","RXNORM","NDC",NDC,"")) Q ^(IEN)
229 ;
230NDC2RXNT ; @TEST - Test Get RxCUI given the NDC
231 D CHKEQ^XTMUNIT($$NDC2RXN("30142-0917-71"),198439,"$$NDC2RXN failed")
232 QUIT
233 ;
234 ; ---
235 ;
236ISBRAND(RXN) ; $$ Public - Is this RxCUI for a brand drug?
237 ; Input: RxCUI
238 ; Output: 0 or 1
239 Q ''$D(^C0CRXN(176.001,"STC","RXNORM","SBD",RXN))
240ISBRANDT ; @TEST - Test Is this RxCUI for a brand drug?
241 D CHKEQ^XTMUNIT($$ISBRAND(205535),1,"$$ISBRAND failed") ; Brand Prozac
242 D CHKEQ^XTMUNIT($$ISBRAND(310384),0,"$$ISBRAND failed") ; Generic Fluoxetine
243 QUIT
244 ;
245 ; ---
246 ;
247BR2GEN(RXN) ; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
248 ; Input: RxCUI of Brand
249 ; Output: RxCUI of Generic
250 Q $O(^C0CRXN(176.005,"B",RXN,"has_tradename",""))
251BR2GENT ; @TEST - Test Convert Brand RxCUI to Generic RxCUI (many to 1)
252 D CHKEQ^XTMUNIT($$BR2GEN(205535),310384,"$$BR2GEN failed")
253 QUIT
254 ;
255 ; ---
256 ;
257GEN2BR(RXN) ; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
258 N RTN S RTN="" ; Return
259 N I S I="" F S I=$O(^C0CRXN(176.005,"B",RXN,"tradename_of",I)) Q:'I S RTN=RTN_I_U
260 S RTN=$E(RTN,1,$L(RTN)-1)
261 Q RTN
262 ;
263GEN2BRT ; @TEST - Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
264 D CHKTF^XTMUNIT($$GEN2BR(310384)[205535,"$$GEN2BR failed")
265 QUIT
266 ;
267 ; ---
268 ;
269RXN2BNS(RXN) ; $$ Public - Get all Brand Names associated with an RXN
270 N BNS S BNS=""
271 I $$ISBRAND(RXN) S RXN=$$BR2GEN(RXN)
272 N ALLBN S ALLBN=$$GEN2BR(RXN)
273 N BNNO F BNNO=1:1:$L(ALLBN,U) D
274 . N EACHBN S EACHBN=$P(ALLBN,U,BNNO)
275 . N BNRXCUI S BNRXCUI=$O(^C0CRXN(176.005,"B",EACHBN,"ingredient_of",""))
276 . Q:BNRXCUI=""
277 . N BNIEN S BNIEN=$O(^C0CRXN(176.001,"B",BNRXCUI,""))
278 . S BNS=BNS_$P(^C0CRXN(176.001,BNIEN,0),U,15)_U
279 QUIT $E(BNS,1,$L(BNS)-1)
280RXN2BNST ; @TEST - Test Get all Brand Names associated with an RXN
281 D CHKTF^XTMUNIT($$RXN2BNS(205535)["Prozac","$$RXN2BNS failed")
282 QUIT
Note: See TracBrowser for help on using the repository browser.