[1730] | 1 | C0CRXNLK ; VEN/SMH - RxNorm Lookup Utilities ;2014-07-22 2:27 PM
|
---|
| 2 | ;;2.5;RXNORM FOR VISTA;;Apr 27, 2016;Build 16
|
---|
| 3 | ;(c) Sam Habiel 2016
|
---|
| 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^%ut($T(+0),2)
|
---|
| 10 | QUIT
|
---|
| 11 | ;
|
---|
| 12 | EXIST(RXN) ; $$ Public - Does this RxNorm CUI exist?
|
---|
| 13 | ; Input: RxNorm CUI by value
|
---|
| 14 | ; Output: Extrinsic
|
---|
| 15 | Q ''$D(^C0CRXN(176.001,"B",RXN))
|
---|
| 16 | ;
|
---|
| 17 | GCN2RXN(GCN) ; $$ Public - Get RxNorm CUI using GCN
|
---|
| 18 | ; Input: GCN by Value
|
---|
| 19 | ; Output: Extrinsic
|
---|
| 20 | S GCN=$$RJ^XLFSTR(GCN,6,0) ; pad to six digits by zeros (123 becomes 000123)
|
---|
| 21 | N IEN S IEN=$O(^C0CRXN(176.001,"STC","NDDF","CDC",GCN,"")) ; Get Entry
|
---|
| 22 | Q ^(IEN)
|
---|
| 23 | ;
|
---|
| 24 | GCN2RXNT ; @TEST Test Get RxNorm CUI using GCN
|
---|
| 25 | Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
|
---|
| 26 | N L F L=1:1 N LN S LN=$T(GCN2RXND+L) Q:LN["<<END>>" Q:LN="" D
|
---|
| 27 | . N GCN S GCN=$P(LN,";",3)
|
---|
| 28 | . N RXN S RXN=$P(LN,";",4)
|
---|
| 29 | . D CHKEQ^%ut($$GCN2RXN(GCN),RXN,"Translation from GCN to RXCUI failed")
|
---|
| 30 | QUIT
|
---|
| 31 | ;
|
---|
| 32 | GCN2RXND ; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
|
---|
| 33 | ;;8208;310429
|
---|
| 34 | ;;1275;628953
|
---|
| 35 | ;;18;197604
|
---|
| 36 | ;;346;884173
|
---|
| 37 | ;;<<END>>
|
---|
| 38 | ;
|
---|
| 39 | ;
|
---|
| 40 | ;
|
---|
| 41 | RXN2GCN(RXNCUI) ; $$ Public - Get GCN(s) given an RxNorm Number
|
---|
| 42 | ; Input: RXNCUI by Value
|
---|
| 43 | ; Output: Caret delimited Extrinsic
|
---|
| 44 | N GCNS S GCNS=""
|
---|
| 45 | N I S I=""
|
---|
| 46 | F S I=$O(^C0CRXN(176.001,"STX","NDDF","CDC",RXNCUI,I)) Q:I="" S GCNS=GCNS_+^(I)_U ; + b/c we want the GCN w/o leading zeros
|
---|
| 47 | S GCNS=$E(GCNS,1,$L(GCNS)-1) ; remove trailing ^
|
---|
| 48 | Q GCNS
|
---|
| 49 | ;
|
---|
| 50 | RXN2GCNT ; @TEST Test Get GCN from RXNCUI
|
---|
| 51 | Q:'$D(^C0CRXN(176.001,"STX","NDDF"))
|
---|
| 52 | N L F L=1:1 N LN S LN=$T(RXN2GCND+L) Q:LN["<<END>>" Q:LN="" D
|
---|
| 53 | . N RXN S RXN=$P(LN,";",3)
|
---|
| 54 | . N GCN S GCN=$P(LN,";",4)
|
---|
| 55 | . D CHKEQ^%ut($$RXN2GCN(RXN),GCN,"Translation from RXCUI to GCN failed")
|
---|
| 56 | QUIT
|
---|
| 57 | ;
|
---|
| 58 | ;
|
---|
| 59 | RXN2GCND ; @DATA - Data for Tests ;;RXNORM CUI;Expected GCN; Human Readable Drug name for dear reader
|
---|
| 60 | ;;998689;5145;Acetabulol 200mg tab
|
---|
| 61 | ;;745679;28090;Albuterol Inhaler
|
---|
| 62 | ;;197320;2536;Allopurinol 300mg tab
|
---|
| 63 | ;;993691;46236;Bupropion 75mg tab
|
---|
| 64 | ;;197591;3768;Diazepam 5mg tab
|
---|
| 65 | ;;<<END>>
|
---|
| 66 | ;
|
---|
| 67 | ;
|
---|
| 68 | ;
|
---|
| 69 | RXN2VUI(RXNCUI) ; $$ Public - Get VUID(s) for given RXNCUI for Clinical Drug
|
---|
| 70 | ; Input: RXNCUI by Value
|
---|
| 71 | ; Output: Caret delimited extrinsic. Should not be more than 2 entries.
|
---|
| 72 | N C0PVUID S C0PVUID=""
|
---|
| 73 | N I S I=""
|
---|
| 74 | F S I=$O(^C0CRXN(176.001,"STX","VANDF","CD",RXNCUI,I)) Q:I="" S C0PVUID=C0PVUID_^(I)_U
|
---|
| 75 | S C0PVUID=$E(C0PVUID,1,$L(C0PVUID)-1) ; remove trailing ^
|
---|
| 76 | ; TODO: Return only the quantified form using:
|
---|
| 77 | ; I $O(^C0CRXN(176.005,"RXCUIREL",RXN,"has_quantified_form","")) N QF S QF=$O(^("")) Q $O(^C0CRXN(176.001,"RXN2VUID",QF,""))
|
---|
| 78 | Q C0PVUID
|
---|
| 79 | ;
|
---|
| 80 | RXN2VUIT ; @TEST Get VUIDs given RxNorm values
|
---|
| 81 | N L F L=1:1 N LN S LN=$T(RXN2VUID+L) Q:LN["<<END>>" Q:LN="" D
|
---|
| 82 | . N RXN S RXN=$P(LN,";",3)
|
---|
| 83 | . N VUIDS S VUIDS=$P(LN,";",4)
|
---|
| 84 | . D CHKEQ^%ut($P($$RXN2VUI(RXN),U),$P(VUIDS,U),"Translation from RXNCUI to VUID failed")
|
---|
| 85 | QUIT
|
---|
| 86 | ;
|
---|
| 87 | RXN2VUID ; @DATA - Data items for previous test
|
---|
| 88 | ;;310429;4002369^4013941
|
---|
| 89 | ;;628953;4000856^4013966^4015798^4015799
|
---|
| 90 | ;;197604;4003335^4015937
|
---|
| 91 | ;;884173;4002469^4013919^4032795
|
---|
| 92 | ;;<<END>>
|
---|
| 93 | ;
|
---|
| 94 | ;
|
---|
| 95 | ;
|
---|
| 96 | VUI2VAP(VUID) ; $$ Public - Get VA Product IEN(s) from VUID
|
---|
| 97 | ; Input VUID by Value
|
---|
| 98 | ; Output: Extrinsic
|
---|
| 99 | D FIND^DIC(50.68,,"@","QP",VUID,,"AVUID") ; Find all in VUID index
|
---|
| 100 | N O S O="" ; Output
|
---|
| 101 | N I F I=0:0 S I=$O(^TMP("DILIST",$J,I)) Q:'I S O=O_^(I,0)_U ; Concat results together
|
---|
| 102 | S O=$E(O,1,$L(O)-1) ; remove trailing ^
|
---|
| 103 | Q O
|
---|
| 104 | ;
|
---|
| 105 | VUI2VAPT ; @TEST Get VA Product IEN from VUID
|
---|
| 106 | N L F L=1:1 N LN S LN=$T(VUI2VAPD+L) Q:LN["<<END>>" Q:LN="" D
|
---|
| 107 | . N VUID S VUID=$P(LN,";",3)
|
---|
| 108 | . N VAP S VAP=$P(LN,";",4)
|
---|
| 109 | . D CHKEQ^%ut($$VUI2VAP(VUID),VAP,"Translation from VUID to VA PRODUCT failed")
|
---|
| 110 | QUIT
|
---|
| 111 | ;
|
---|
| 112 | VUI2VAPD ; @DATA - Data for above test
|
---|
| 113 | ;;4006455;5932
|
---|
| 114 | ;;4002369;1784
|
---|
| 115 | ;;4000874;252
|
---|
| 116 | ;;4003335;2756
|
---|
| 117 | ;;4002469;1884
|
---|
| 118 | ;;4009488;9046^10090
|
---|
| 119 | ;;<<END>>
|
---|
| 120 | ;
|
---|
| 121 | ;
|
---|
| 122 | ;
|
---|
| 123 | VAP2MED(VAPROD) ; $$ Public - Get Drug(s) using VA Product IEN
|
---|
| 124 | ; Un-Unit-testable: Drug files differ between sites.
|
---|
| 125 | ; Input: VA Product IEN By Value
|
---|
| 126 | ; OUtput: Caret delimited extrinsic
|
---|
| 127 | ; This code inspired from PSNAPIs
|
---|
| 128 | ; WHY THE HELL WOULD I USE A TEXT INDEX?
|
---|
| 129 | ; It's my only option. Creating new xrefs on the drug file doesn't help
|
---|
| 130 | ; as they are not filled out when adding a drug (IX[ALL]^DIK isn't called).
|
---|
| 131 | N MEDS S MEDS="" ; result
|
---|
| 132 | N PN,PN1 ; Product Name, abbreviated product name.
|
---|
| 133 | S PN=$P(^PSNDF(50.68,VAPROD,0),"^"),PN1=$E(PN,1,30)
|
---|
| 134 | N P50 S P50=0 ; looper through VAPN index which is DRUG file entry
|
---|
| 135 | F S P50=$O(^PSDRUG("VAPN",PN1,P50)) Q:'P50 D ; for each text match
|
---|
| 136 | . I $P(^PSDRUG(P50,"ND"),"^",3)=VAPROD S MEDS=$G(MEDS)_P50_U ; check that the VA PRODUCT pointer is the same as ours.
|
---|
| 137 | S:MEDS MEDS=$E(MEDS,1,$L(MEDS)-1) ; remove trailing ^
|
---|
| 138 | Q MEDS
|
---|
| 139 | ;
|
---|
| 140 | ;
|
---|
| 141 | RXN2MEDS(RXNCUI) ; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
|
---|
| 142 | ; Input: SCD RXNCUI
|
---|
| 143 | ; Output; Caret delimited extrinsic
|
---|
| 144 | ; Un-unit testable
|
---|
| 145 | N VUIDS S VUIDS=$$RXN2VUI(RXNCUI) ; Get VUID from RXNCUI (multiple VUIDs per CUI)
|
---|
| 146 | Q:'VUIDS ""
|
---|
| 147 | N MEDS S MEDS=""
|
---|
| 148 | N DONE S DONE=0
|
---|
| 149 | N I F I=1:1:$L(VUIDS,U) D Q:DONE
|
---|
| 150 | . N VUID S VUID=$P(VUIDS,U,I)
|
---|
| 151 | . N VAPRODS S VAPRODS=$$VUI2VAP(VUID) ; Get VA Product from VUID (multiple products per VUID)
|
---|
| 152 | . I '$L(VAPRODS) S $ECODE=",U-NO-VA-PRODUCT-CORRUPT-NDF," ; MUST EXIST. Every VUID must have a product to go with it.
|
---|
| 153 | . N J F J=1:1:$L(VAPRODS,U) D Q:DONE
|
---|
| 154 | . . N VAPROD S VAPROD=$P(VAPRODS,U,J)
|
---|
| 155 | . . S MEDS=$$VAP2MED(VAPROD) ; Get Meds from VA Product
|
---|
| 156 | . . I $L(MEDS) S DONE=1
|
---|
| 157 | QUIT MEDS
|
---|
| 158 | ;
|
---|
| 159 | FDI2RXN(BASE) ; $$ Public - Get RxNorm CUI for FDB Ingredient/Base
|
---|
| 160 | ; ^C0CRXN(176.001,"STC","NDDF","IN","014739",1000870)=1362160
|
---|
| 161 | ; Input: BASE By Value
|
---|
| 162 | ; Output: RxNorm CUI
|
---|
| 163 | S BASE=$$RJ^XLFSTR(BASE,6,0) ; pad to six digits by zeros (123 becomes 000123)
|
---|
| 164 | N IEN S IEN=$O(^C0CRXN(176.001,"STC","NDDF","IN",BASE,"")) Q ^(IEN)
|
---|
| 165 | ;
|
---|
| 166 | FDI2RXNT ; @TEST Test Get RxNorm CUI for FDB Ingredient/Base
|
---|
| 167 | Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
|
---|
| 168 | D CHKEQ^%ut($$FDI2RXN(14739),1362160,"$$FDI2RXN failed")
|
---|
| 169 | QUIT
|
---|
| 170 | ;
|
---|
| 171 | ;
|
---|
| 172 | ;
|
---|
| 173 | RXN2VIN(RXNCUI) ; $$ Public - Get VUID Ingredient for RxNorm CUI
|
---|
| 174 | ; ^C0CRXN(176.001,"STX","VANDF","IN",1366467,1008555)=4031768
|
---|
| 175 | ; Input: RXNCUI By Value
|
---|
| 176 | ; Output: VUID
|
---|
| 177 | N IEN S IEN=$O(^C0CRXN(176.001,"STX","VANDF","IN",RXNCUI,""))
|
---|
| 178 | I IEN Q ^(IEN)
|
---|
| 179 | E Q ""
|
---|
| 180 | ;
|
---|
| 181 | RXN2VINT ; @TEST Test Get VUID Ingredient for RxNorm CUI
|
---|
| 182 | D CHKEQ^%ut($$RXN2VIN(1366467),4031768,"$$RXN2VIN failed")
|
---|
| 183 | QUIT
|
---|
| 184 | ;
|
---|
| 185 | ;
|
---|
| 186 | ;
|
---|
| 187 | VIN2VAG(VUID) ; $$ Public - Get VA Generic for VUID Ingredient
|
---|
| 188 | ; Input: VUID By Value
|
---|
| 189 | ; Output: IEN^VA Generic Name (i.e. .01 field value)
|
---|
| 190 | N C0PIEN S C0PIEN=$$FIND1^DIC(50.6,"","QX",VUID,"AVUID")
|
---|
| 191 | N C0P01 S C0P01=$$GET1^DIQ(50.6,C0PIEN,.01)
|
---|
| 192 | Q C0PIEN_"^"_C0P01
|
---|
| 193 | ;
|
---|
| 194 | VIN2VAGT ; @TEST Test Get VA Generic for VUID Ingredient
|
---|
| 195 | D CHKEQ^%ut(+$$VIN2VAG(4023636),2832,"$$VIN2VAG failed")
|
---|
| 196 | QUIT
|
---|
| 197 | ;
|
---|
| 198 | ;
|
---|
| 199 | ;
|
---|
| 200 | FDI2VAG(BASE) ; $$ Public - Get VA Generic for FDB Ingredient/Base
|
---|
| 201 | ; TODO:Not tested...
|
---|
| 202 | ; Input: BASE By Value
|
---|
| 203 | ; Output: IEN^VA Generic Name (i.e. .01 field value)
|
---|
| 204 | Q $$VIN2VAG($$RXN2VIN($$FDI2RXN(BASE)))
|
---|
| 205 | ;
|
---|
| 206 | VIN2DIN(VUID) ; $$ Public - Get Drug Ingredient for VUID Ingredient
|
---|
| 207 | ; TODO:Not tested...
|
---|
| 208 | ; Input: VUID By Value
|
---|
| 209 | ; Output: IEN^Drug Ingredient Name (i.e. .01 field value)
|
---|
| 210 | N C0PIEN S C0PIEN=$$FIND1^DIC(50.416,"","QX",VUID,"AVUID")
|
---|
| 211 | N C0P01 S C0P01=$$GET1^DIQ(50.416,C0PIEN,.01)
|
---|
| 212 | Q C0PIEN_"^"_C0P01
|
---|
| 213 | ;
|
---|
| 214 | FDI2DIN(BASE) ; $$ Public - Get Drug Ingredient for FDB Ingredient/Base
|
---|
| 215 | ; TODO:Not tested...
|
---|
| 216 | ; Input: BASE By Value
|
---|
| 217 | ; Output: IEN^Drug Ingredient Name (i.e. .01 field value)
|
---|
| 218 | Q $$VIN2DIN($$RXN2VIN($$FDI2RXN(BASE)))
|
---|
| 219 | ;
|
---|
| 220 | VUI2RXN(VUID,TTY) ; $$ Public Stephanie's Unified VUID searcher. Get RXNCUI given VUID
|
---|
| 221 | ;GIVEN A VUID IN ONE OF SEVERAL FILES RETURN THE ASSOCIATED RXNORM CODE IN 176.001
|
---|
| 222 | ; TTY="IN", "CD", or "PT"
|
---|
| 223 | ; IN = DRUG INGRIDENT FILE & VA GENERIC file
|
---|
| 224 | ; CD = VA PRODUCT FILE
|
---|
| 225 | ; PT = VA DRUG CLASS
|
---|
| 226 | ;
|
---|
| 227 | ; SAB="VANDF"
|
---|
| 228 | ; CODE=VUID
|
---|
| 229 | ;
|
---|
| 230 | I $O(^C0CRXN(176.001,"STC","VANDF",TTY,VUID,"")) Q ^($O(^("")))
|
---|
| 231 | Q ""
|
---|
| 232 | ;
|
---|
| 233 | VUI2RXNT ; @TEST VUID to RxNorm CUI tests
|
---|
| 234 | D CHKEQ^%ut($$VUI2RXN(4010151,"CD"),314231)
|
---|
| 235 | D CHKEQ^%ut($$VUI2RXN(4020940,"IN"),16681)
|
---|
| 236 | D CHKEQ^%ut($$VUI2RXN(4021568,"PT"),883)
|
---|
| 237 | D CHKEQ^%ut($$VUI2RXN(1234234,"CD"),"")
|
---|
| 238 | QUIT
|
---|
| 239 | ;
|
---|
| 240 | VUI2GCN(VUID) ; $$ Public - Get GCNs for a given VUID (any VUID type)
|
---|
| 241 | ; Input: VUID by Value
|
---|
| 242 | ; Output: GCNs delimited by ^
|
---|
| 243 | ; TODO: Unit Test
|
---|
| 244 | N RXNS S RXNS=$$VUI2RXN(VUID,"AB")
|
---|
| 245 | Q:RXNS="" "" ; VUID not a drug or ingredient (can be food)
|
---|
| 246 | N GCNS S GCNS=""
|
---|
| 247 | N I F I=1:1:$L(RXNS,U) S GCNS=GCNS_$$RXN2GCN($P(RXNS,U,I))_U
|
---|
| 248 | S GCNS=$E(GCNS,1,$L(GCNS)-1)
|
---|
| 249 | QUIT GCNS
|
---|
| 250 | ;
|
---|
| 251 | MED2RXN(DA) ; $$ Public - Get RxNorm CUI for Drug
|
---|
| 252 | ; Input: DA - Medication IEN
|
---|
| 253 | ; Output: RXNCUIs delimited by ^
|
---|
| 254 | N ND S ND=$G(^PSDRUG(DA,"ND")) ; ND Node
|
---|
| 255 | N VAP S VAP=$P(ND,U,3) ; VA Product Pointer
|
---|
| 256 | Q:'VAP "" ; quit if empty
|
---|
| 257 | N VUID S VUID=+^PSNDF(50.68,VAP,"VUID") ; Get VUID
|
---|
| 258 | I 'VUID S $EC=",U1," ; Must exist
|
---|
| 259 | Q $$VUI2RXN(VUID,"AB")
|
---|
| 260 | ;
|
---|
| 261 | MED2SCDN(DA) ; $$ Public - Medication to Semantic Clinical Drug Name
|
---|
| 262 | ; Input: DA - Medication IEN
|
---|
| 263 | ; Output: The Canonical Semantic Clinical Drug name
|
---|
| 264 | N RXNCUI S RXNCUI=$$MED2RXN(DA)
|
---|
| 265 | Q:'RXNCUI ""
|
---|
| 266 | Q $$SCDNAME(RXNCUI)
|
---|
| 267 | ;
|
---|
| 268 | SCDNAME(RXNCUI) ; $$ Public - Semantic Clinical Drug Name for RxNorm CUI
|
---|
| 269 | N IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCD",RXNCUI,"")) ; Let's try generic drug
|
---|
| 270 | I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SBD",RXNCUI,"")) ; Let's try non-bioequivalent Brands then
|
---|
| 271 | I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","GPCK",RXNCUI,"")) ; Let's try a Generic combination package
|
---|
| 272 | I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCDF",RXNCUI,"")) ; Let's try a Clinical Drug and Form (Like Metamucil)
|
---|
| 273 | Q:'IEN "" ; Apparently not every VUID has a corresponding RXNCUI SCD.
|
---|
| 274 | Q $P(^C0CRXN(176.001,IEN,0),U,15)
|
---|
| 275 | ;
|
---|
| 276 | ANYNAME(RXNCUI) ; $$ Public - Get the RxNorm name, no matter what it is
|
---|
| 277 | N RESULT S RESULT=""
|
---|
| 278 | N TTY S TTY=""
|
---|
| 279 | F S TTY=$O(^C0CRXN(176.001,"STC","RXNORM",TTY)) Q:TTY="" D Q:RESULT]""
|
---|
| 280 | . N IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM",TTY,RXNCUI,""))
|
---|
| 281 | . Q:'IEN
|
---|
| 282 | . S RESULT=$P(^C0CRXN(176.001,IEN,0),U,15)
|
---|
| 283 | QUIT RESULT
|
---|
| 284 | ;
|
---|
| 285 | RXN2NDI(RXNCUI) ; $$ Public - Get NDDF Ingredient for RXNCUI
|
---|
| 286 | ; Input: RXNCUI By Value
|
---|
| 287 | ; Output: NDDF Base code
|
---|
| 288 | ; TODO:Not tested...
|
---|
| 289 | N IEN S IEN=$O(^C0CRXN(176.001,"STX","NDDF","IN",RXNCUI,"")) Q ^(IEN)
|
---|
| 290 | ;
|
---|
| 291 | VIN2NDI(VUID) ; $$ Public - Get NDDF Ingredient for VUID
|
---|
| 292 | ; NB: WILL ONLY WORK IF VUID IS AN INGREDIENT VUID, NOT A CLINICAL DRUG
|
---|
| 293 | ; Input: VUID By Value
|
---|
| 294 | ; Output: NDDF Base code
|
---|
| 295 | ; TODO:Not tested...
|
---|
| 296 | Q $$RXN2NDI($$VUI2RXN(VUID,"IN"))
|
---|
| 297 | ;
|
---|
| 298 | ; ---
|
---|
| 299 | ;
|
---|
| 300 | NDC2RXN(NDC) ; $$ Public - Get RxCUI given the NDC
|
---|
| 301 | ; NB: Will only work if passed NDC is in 5-4-2 format.
|
---|
| 302 | ; Input: NDC By Value in 5-4-2 Format
|
---|
| 303 | ; Output: RxNorm Code.
|
---|
| 304 | S NDC=$TR(NDC,"-")
|
---|
| 305 | N IEN S IEN=$O(^C0CRXN(176.002,"ASAA","RXNORM","NDC",NDC,"")) Q ^(IEN)
|
---|
| 306 | ;
|
---|
| 307 | NDC2RXNT ; @TEST Test Get RxCUI given the NDC & Get RxCUI given the 50.67 NDC
|
---|
| 308 | D CHKEQ^%ut($$NDC2RXN("30142-0917-71"),198439,"$$NDC2RXN failed")
|
---|
| 309 | D CHKEQ^%ut($$NDC2RXN2("000031868518","VANDF"),996520,"$$NDC2RXN2 failed")
|
---|
| 310 | QUIT
|
---|
| 311 | ;
|
---|
| 312 | NDC2RXN2(NDC,SOURCE) ; $$ Public - Get RxCUI given the source
|
---|
| 313 | ; Input: NDC in any format according to source
|
---|
| 314 | ; Output: RxNorm Code
|
---|
| 315 | I SOURCE="" QUIT ""
|
---|
| 316 | N IEN S IEN=$O(^C0CRXN(176.002,"ASAA",SOURCE,"NDC",NDC,"")) Q:IEN ^(IEN) Q ""
|
---|
| 317 | QUIT
|
---|
| 318 | ; ---
|
---|
| 319 | ;
|
---|
| 320 | ISBRAND(RXN) ; $$ Public - Is this RxCUI for a brand drug?
|
---|
| 321 | ; Input: RxCUI
|
---|
| 322 | ; Output: 0 or 1
|
---|
| 323 | Q ''$D(^C0CRXN(176.001,"STC","RXNORM","SBD",RXN))
|
---|
| 324 | ISBRANDT ; @TEST Test Is this RxCUI for a brand drug?
|
---|
| 325 | D CHKEQ^%ut($$ISBRAND(205535),1,"$$ISBRAND failed") ; Brand Prozac
|
---|
| 326 | D CHKEQ^%ut($$ISBRAND(310384),0,"$$ISBRAND failed") ; Generic Fluoxetine
|
---|
| 327 | QUIT
|
---|
| 328 | ;
|
---|
| 329 | ; ---
|
---|
| 330 | ;
|
---|
| 331 | BR2GEN(RXN) ; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
|
---|
| 332 | ; Input: RxCUI of Brand
|
---|
| 333 | ; Output: RxCUI of Generic
|
---|
| 334 | Q $O(^C0CRXN(176.005,"B",RXN,"has_tradename",""))
|
---|
| 335 | BR2GENT ; @TEST Test Convert Brand RxCUI to Generic RxCUI (many to 1)
|
---|
| 336 | D CHKEQ^%ut($$BR2GEN(205535),310384,"$$BR2GEN failed")
|
---|
| 337 | QUIT
|
---|
| 338 | ;
|
---|
| 339 | ; ---
|
---|
| 340 | ;
|
---|
| 341 | GEN2BR(RXN) ; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
|
---|
| 342 | N RTN S RTN="" ; Return
|
---|
| 343 | N I S I="" F S I=$O(^C0CRXN(176.005,"B",RXN,"tradename_of",I)) Q:'I S RTN=RTN_I_U
|
---|
| 344 | S RTN=$E(RTN,1,$L(RTN)-1)
|
---|
| 345 | Q RTN
|
---|
| 346 | ;
|
---|
| 347 | GEN2BRT ; @TEST Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
|
---|
| 348 | D CHKTF^%ut($$GEN2BR(310384)[205535,"$$GEN2BR failed")
|
---|
| 349 | QUIT
|
---|
| 350 | ;
|
---|
| 351 | ; ---
|
---|
| 352 | ;
|
---|
| 353 | RXN2BNS(RXN) ; $$ Public - Get all Brand Names associated with an RXN
|
---|
| 354 | N BNS S BNS=""
|
---|
| 355 | I $$ISBRAND(RXN) S RXN=$$BR2GEN(RXN)
|
---|
| 356 | N ALLBN S ALLBN=$$GEN2BR(RXN)
|
---|
| 357 | Q:ALLBN="" ""
|
---|
| 358 | N BNNO F BNNO=1:1:$L(ALLBN,U) D
|
---|
| 359 | . N EACHBN S EACHBN=$P(ALLBN,U,BNNO)
|
---|
| 360 | . N BNRXCUI S BNRXCUI=$O(^C0CRXN(176.005,"B",EACHBN,"ingredient_of",""))
|
---|
| 361 | . Q:BNRXCUI=""
|
---|
| 362 | . N BNIEN S BNIEN=$O(^C0CRXN(176.001,"B",BNRXCUI,""))
|
---|
| 363 | . S BNS=BNS_$P(^C0CRXN(176.001,BNIEN,0),U,15)_U
|
---|
| 364 | QUIT $E(BNS,1,$L(BNS)-1)
|
---|
| 365 | RXN2BNST ; @TEST Test Get all Brand Names associated with an RXN
|
---|
| 366 | D CHKTF^%ut($$RXN2BNS(205535)["Prozac","$$RXN2BNS failed")
|
---|
| 367 | QUIT
|
---|
| 368 | ;
|
---|
| 369 | ; ---
|
---|
| 370 | ;
|
---|
| 371 | RXN2NDC(RXN) ; $$ Public - Get NDC codes for RxNorm code
|
---|
| 372 | N NDCS S NDCS=""
|
---|
| 373 | N I F I=0:0 S I=$O(^C0CRXN(176.002,"ASAR","RXNORM","NDC",RXN,I)) Q:'I S NDCS=NDCS_^(I)_"^"
|
---|
| 374 | S $E(NDCS,$L(NDCS))=""
|
---|
| 375 | QUIT NDCS
|
---|
| 376 | RXN2NDCT ; @TEST Test Get NDC codes for RxNorm code
|
---|
| 377 | D CHKTF^%ut($$RXN2NDC(197379)["^"_16714003309,"$$RXN2NDC failed")
|
---|
| 378 | QUIT
|
---|
| 379 | ;
|
---|
| 380 | LVUID(RXN) ; $$ Public - Locate VUID, given RxNorm. Iterative Search
|
---|
| 381 | ; ^C0CRXN(176.001,"STC","RXNORM","IN",46239,IEN
|
---|
| 382 | N TTY S TTY=""
|
---|
| 383 | N intermediateRxCUI
|
---|
| 384 | N finalVUID
|
---|
| 385 | i '$$EXIST(RXN) q "0^not found in RxNorm"
|
---|
| 386 | ;
|
---|
| 387 | F S TTY=$O(^C0CRXN(176.001,"STC","RXNORM",TTY)) Q:TTY="" D q:$g(intermediateRxCUI) q:$g(finalVUID)
|
---|
| 388 | . N IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM",TTY,RXN,""))
|
---|
| 389 | . I 'IEN quit ; s err="0^not found in RxNorm" quit
|
---|
| 390 | . ; W ^C0CRXN(176.001,IEN,0),!
|
---|
| 391 | . I TTY="BN" s intermediateRxCUI=$$BR2GEN(RXN) quit ; try searching with generic
|
---|
| 392 | . I TTY="IN"!(TTY="MIN") s finalVUID=$$RXN2VIN(RXN) quit ; match VUID
|
---|
| 393 | . I TTY="PIN" s intermediateRxCUI=$$formOf(RXN) quit ; try searching with ingredient
|
---|
| 394 | . I TTY="SCD" d
|
---|
| 395 | .. s finalVUID=$$RXN2VUI(RXN)
|
---|
| 396 | .. i finalVUID="" s finalVUID=$$containerOf(RXN)
|
---|
| 397 | .. I finalVUID="" s finalVUID=$$tradeName(RXN)
|
---|
| 398 | . I TTY="GPCK" d
|
---|
| 399 | .. s finalVUID=$$tradeName(RXN)
|
---|
| 400 | i $get(intermediateRxCUI) q $$LVUID(intermediateRxCUI) ; recurse
|
---|
| 401 | i $get(finalVUID) quit finalVUID
|
---|
| 402 | quit "0^no mapping found in RxNorm"
|
---|
| 403 | ;
|
---|
| 404 | formOf(RXN) ; RXN is form of result
|
---|
| 405 | q $o(^C0CRXN(176.005,"B",RXN,"has_form",""))
|
---|
| 406 | containerOf(RXN) ; loop through all contains and see if one hits it.
|
---|
| 407 | n container
|
---|
| 408 | n vuid s vuid=""
|
---|
| 409 | f container=0:0 s container=$o(^C0CRXN(176.005,"B",RXN,"contains",container)) q:'container d q:$g(vuid)
|
---|
| 410 | . s vuid=$$RXN2VUI(container)
|
---|
| 411 | quit vuid
|
---|
| 412 | tradeName(RXN) ; loop through all tradenames and see if there's a match
|
---|
| 413 | n vuid s vuid=""
|
---|
| 414 | n tncui f tncui=0:0 s tncui=$o(^C0CRXN(176.005,"B",RXN,"tradename_of",tncui)) q:'tncui d q:$g(vuid)
|
---|
| 415 | . s vuid=$$RXN2VUI(tncui)
|
---|
| 416 | quit vuid
|
---|
| 417 | ;
|
---|
| 418 | loopVUIDs ; [Public] Paste VUIDs to get the RxNorm Numbers
|
---|
| 419 | ; ZEXCEPT: DTIME
|
---|
| 420 | n rxn
|
---|
| 421 | f r rxn:$g(DTIME,300) q:rxn="" q:rxn=$c(4) d
|
---|
| 422 | . w "|"
|
---|
| 423 | . w $$LVUID(rxn),"|",$$ANYNAME(rxn),!
|
---|
| 424 | quit
|
---|