Changeset 1665 for ccr/trunk/rxnorm


Ignore:
Timestamp:
Mar 5, 2015, 2:22:22 PM (10 years ago)
Author:
Sam Habiel
Message:

Extra NDC resolution functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ccr/trunk/rxnorm/trunk/routines/C0CRXNLK.m

    r1642 r1665  
    1 C0CRXNLK        ; VEN/SMH - RxNorm Lookup Utilities ;2014-07-22  2:27 PM
    2         ;;2.3;RXNORM FOR VISTA;;Jul 22, 2014;Build 10
    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         ;
    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^XTMUNIT($$GCN2RXN(GCN),RXN,"Translation from GCN to RXCUI failed")
    30         QUIT
    31         ;
    32 GCN2RXND        ; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
    33         ;;16033;991632
    34         ;;8208;310429
    35         ;;1275;628953
    36         ;;18;197604
    37         ;;346;884173
    38         ;;<<END>>
    39         ;
    40         ;
    41         ;
    42 RXN2GCN(RXNCUI) ; $$ Public - Get GCN(s) given an RxNorm Number
    43         ; Input: RXNCUI by Value
    44         ; Output: Caret delimited Extrinsic
    45         N GCNS S GCNS=""
    46         N I S I=""
    47         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
    48         S GCNS=$E(GCNS,1,$L(GCNS)-1) ; remove trailing ^
    49         Q GCNS
    50         ;
    51 RXN2GCNT        ; @TEST - Test Get GCN from RXNCUI
    52         Q:'$D(^C0CRXN(176.001,"STX","NDDF"))
    53         N L F L=1:1 N LN S LN=$T(RXN2GCND+L) Q:LN["<<END>>"  Q:LN=""  D
    54         . N RXN S RXN=$P(LN,";",3)
    55         . N GCN S GCN=$P(LN,";",4)
    56         . D CHKEQ^XTMUNIT($$RXN2GCN(RXN),GCN,"Translation from RXCUI to GCN failed")
    57         QUIT
    58         ;
    59         ;
    60 RXN2GCND        ; @DATA - Data for Tests ;;RXNORM CUI;Expected GCN; Human Readable Drug name for dear reader
    61         ;;998689;5145;Acetabulol 200mg tab
    62         ;;745679;5037;Albuterol Inhaler
    63         ;;197320;2536;Allopurinol 300mg tab
    64         ;;993691;3948^46236;Bupropion 75mg tab
    65         ;;197591;3768;Diazepam 5mg tab
    66         ;;<<END>>
    67         ;
    68         ;
    69         ;
    70 RXN2VUI(RXNCUI) ; $$ Public - Get VUID(s) for given RXNCUI for Clinical Drug
    71         ; Input: RXNCUI by Value
    72         ; Output: Caret delimited extrinsic. Should not be more than 2 entries.
    73         N C0PVUID S C0PVUID=""
    74         N I S I=""
    75         F  S I=$O(^C0CRXN(176.001,"STX","VANDF","CD",RXNCUI,I)) Q:I=""  S C0PVUID=C0PVUID_^(I)_U
    76         S C0PVUID=$E(C0PVUID,1,$L(C0PVUID)-1) ; remove trailing ^
    77         ; TODO: Return only the quantified form using:
    78         ; I $O(^C0CRXN(176.005,"RXCUIREL",RXN,"has_quantified_form","")) N QF S QF=$O(^("")) Q $O(^C0CRXN(176.001,"RXN2VUID",QF,""))
    79         Q C0PVUID
    80         ;
    81 RXN2VUIT        ; @TEST - Get VUIDs given RxNorm values
    82         N L F L=1:1 N LN S LN=$T(RXN2VUID+L) Q:LN["<<END>>"  Q:LN=""  D
    83         . N RXN S RXN=$P(LN,";",3)
    84         . N VUIDS S VUIDS=$P(LN,";",4)
    85         . D CHKEQ^XTMUNIT($$RXN2VUI(RXN),VUIDS,"Translation from RXNCUI to VUID failed")
    86         QUIT
    87         ;
    88 RXN2VUID        ; @DATA - Data items for previous test
    89         ;;991632;4006455
    90         ;;310429;4002369^4013941
    91         ;;628953;4000874^4000856^4013966^4015798^4015799
    92         ;;197604;4003335^4015937
    93         ;;884173;4002469^4013919
    94         ;;<<END>>
    95         ;
    96         ;
    97         ;
    98 VUI2VAP(VUID)   ; $$ Public - Get VA Product IEN(s) from VUID
    99         ; Input VUID by Value
    100         ; Output: Extrinsic
    101         D FIND^DIC(50.68,,"@","QP",VUID,,"AVUID") ; Find all in VUID index
    102         N O S O="" ; Output
    103         N I F I=0:0 S I=$O(^TMP("DILIST",$J,I)) Q:'I  S O=O_^(I,0)_U ; Concat results together
    104         S O=$E(O,1,$L(O)-1) ; remove trailing ^
    105         Q O
    106         ;
    107 VUI2VAPT        ; @TEST - Get VA Product IEN from VUID
    108         N L F L=1:1 N LN S LN=$T(VUI2VAPD+L) Q:LN["<<END>>"  Q:LN=""  D
    109         . N VUID S VUID=$P(LN,";",3)
    110         . N VAP S VAP=$P(LN,";",4)
    111         . D CHKEQ^XTMUNIT($$VUI2VAP(VUID),VAP,"Translation from VUID to VA PRODUCT failed")
    112         QUIT
    113         ;
    114 VUI2VAPD        ; @DATA - Data for above test
    115         ;;4006455;5932
    116         ;;4002369;1784
    117         ;;4000874;252
    118         ;;4003335;2756
    119         ;;4002469;1884
    120         ;;4009488;9046^10090
    121         ;;<<END>>
    122         ;
    123         ;
    124         ;
    125 VAP2MED(VAPROD) ; $$ Public - Get Drug(s) using VA Product IEN
    126         ; Un-Unit-testable: Drug files differ between sites.
    127         ; Input: VA Product IEN By Value
    128         ; OUtput: Caret delimited extrinsic
    129         ; This code inspired from PSNAPIs
    130         ; WHY THE HELL WOULD I USE A TEXT INDEX?
    131         ; It's my only option. Creating new xrefs on the drug file doesn't help
    132         ; as they are not filled out when adding a drug (IX[ALL]^DIK isn't called).
    133         N MEDS S MEDS="" ; result
    134         N PN,PN1 ; Product Name, abbreviated product name.
    135         S PN=$P(^PSNDF(50.68,VAPROD,0),"^"),PN1=$E(PN,1,30)
    136         N P50 S P50=0 ; looper through VAPN index which is DRUG file entry
    137         F  S P50=$O(^PSDRUG("VAPN",PN1,P50)) Q:'P50  D  ; for each text match
    138         . I $P(^PSDRUG(P50,"ND"),"^",3)=VAPROD S MEDS=$G(MEDS)_P50_U  ; check that the VA PRODUCT pointer is the same as ours.
    139         S:MEDS MEDS=$E(MEDS,1,$L(MEDS)-1) ; remove trailing ^
    140         Q MEDS
    141         ;
    142         ;
    143 RXN2MEDS(RXNCUI)        ; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
    144         ; Input: SCD RXNCUI
    145         ; Output; Caret delimited extrinsic
    146         ; Un-unit testable
    147         N VUIDS S VUIDS=$$RXN2VUI(RXNCUI) ; Get VUID from RXNCUI (multiple VUIDs per CUI)
    148         Q:'VUIDS ""
    149         N MEDS S MEDS=""
    150         N DONE S DONE=0
    151         N I F I=1:1:$L(VUIDS,U) D  Q:DONE
    152         . N VUID S VUID=$P(VUIDS,U,I)
    153         . N VAPRODS S VAPRODS=$$VUI2VAP(VUID) ; Get VA Product from VUID (multiple products per VUID)
    154         . I '$L(VAPRODS) S $ECODE=",U-NO-VA-PRODUCT-CORRUPT-NDF,"  ; MUST EXIST. Every VUID must have a product to go with it.
    155         . N J F J=1:1:$L(VAPRODS,U) D  Q:DONE
    156         . . N VAPROD S VAPROD=$P(VAPRODS,U,J)
    157         . . S MEDS=$$VAP2MED(VAPROD) ; Get Meds from VA Product
    158         . . I $L(MEDS) S DONE=1
    159         QUIT MEDS
    160         ;
    161 FDI2RXN(BASE)   ; $$ Public - Get RxNorm CUI for FDB Ingredient/Base
    162         ; ^C0CRXN(176.001,"STC","NDDF","IN","014739",1000870)=1362160
    163         ; Input: BASE By Value
    164         ; Output: RxNorm CUI
    165         S BASE=$$RJ^XLFSTR(BASE,6,0) ; pad to six digits by zeros (123 becomes 000123)
    166         N IEN S IEN=$O(^C0CRXN(176.001,"STC","NDDF","IN",BASE,"")) Q ^(IEN)
    167         ;
    168 FDI2RXNT        ; @TEST - Test Get RxNorm CUI for FDB Ingredient/Base
    169         Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
    170         D CHKEQ^XTMUNIT($$FDI2RXN(14739),1362160,"$$FDI2RXN failed")
    171         QUIT
    172         ;
    173         ;
    174         ;
    175 RXN2VIN(RXNCUI) ; $$ Public - Get VUID Ingredient for RxNorm CUI
    176         ; ^C0CRXN(176.001,"STX","VANDF","IN",1366467,1008555)=4031768
    177         ; Input: RXNCUI By Value
    178         ; Output: VUID
    179         N IEN S IEN=$O(^C0CRXN(176.001,"STX","VANDF","IN",RXNCUI,"")) Q ^(IEN)
    180         ;
    181 RXN2VINT        ; @TEST - Test Get VUID Ingredient for RxNorm CUI
    182         D CHKEQ^XTMUNIT($$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^XTMUNIT(+$$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)   ; $$ Public - Get RXNCUI for VUID (any VUID type)
    221         ; Input: VUID By Value
    222         ; Output: RXNCUIs delimited by ^
    223         ; Get all entries whose code is the VUID and are in the VA NDF which are clinical drugs
    224         D FIND^DIC(176.001,,"@;.01","PQX",VUID,,"CODE","I $P(^(0),U,12,13)=""VANDF^CD""")
    225         ; Deserialise it into a single string
    226         ; ^TMP("DILIST",4844,0)="1^*^0^"
    227         ; ^TMP("DILIST",4844,0,"MAP")="IEN^.01"
    228         ; ^TMP("DILIST",4844,1,0)="1006351^1364462"
    229         N RXNS S RXNS=""
    230         N I F I=0:0 S I=$O(^TMP("DILIST",$J,I)) Q:'I  S RXNS=RXNS_$P(^(I,0),U,2)_U
    231         S RXNS=$E(RXNS,1,$L(RXNS)-1)
    232         QUIT RXNS
    233         ;
    234 VUI2GCN(VUID)   ; $$ Public - Get GCNs for a given VUID (any VUID type)
    235         ; Input: VUID by Value
    236         ; Output: GCNs delimited by ^
    237         ; TODO: Unit Test
    238         N RXNS S RXNS=$$VUI2RXN(VUID)
    239         Q:RXNS="" ""  ; VUID not a drug or ingredient (can be food)
    240         N GCNS S GCNS=""
    241         N I F I=1:1:$L(RXNS,U) S GCNS=GCNS_$$RXN2GCN($P(RXNS,U,I))_U
    242         S GCNS=$E(GCNS,1,$L(GCNS)-1)
    243         QUIT GCNS
    244         ;
    245 MED2RXN(DA)     ; $$ Public - Get RxNorm CUI for Drug
    246         ; Input: DA - Medication IEN
    247         ; Output: RXNCUIs delimited by ^
    248         N ND S ND=$G(^PSDRUG(DA,"ND")) ; ND Node
    249         N VAP S VAP=$P(ND,U,3) ; VA Product Pointer
    250         Q:'VAP ""  ; quit if empty
    251         N VUID S VUID=+^PSNDF(50.68,VAP,"VUID")  ; Get VUID
    252         I 'VUID S $EC=",U1," ; Must exist
    253         Q $$VUI2RXN(VUID)
    254         ;
    255 MED2SCDN(DA)    ; $$ Public - Medication to Semantic Clinical Drug Name
    256         ; Input: DA - Medication IEN
    257         ; Output: The Canonical Semantic Clinical Drug name
    258         N RXNCUI S RXNCUI=$$MED2RXN(DA)
    259         Q:'RXNCUI ""
    260         N IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCD",RXNCUI,""))  ; Let's try generic drug
    261         I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SBD",RXNCUI,""))  ; Let's try non-bioequivalent Brands then
    262         I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","GPCK",RXNCUI,"")) ; Let's try a Generic combination package
    263         I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCDF",RXNCUI,"")) ; Let's try a Clinical Drug and Form (Like Metamucil)
    264         Q:'IEN "" ; Apparently not every VUID has a corresponding RXNCUI SCD.
    265         Q $P(^C0CRXN(176.001,IEN,0),U,15)
    266         ;
    267 RXN2NDI(RXNCUI) ; $$ Public - Get NDDF Ingredient for RXNCUI
    268         ; Input: RXNCUI By Value
    269         ; Output: NDDF Base code
    270         ; TODO:Not tested...
    271         N IEN S IEN=$O(^C0CRXN(176.001,"STX","NDDF","IN",RXNCUI,"")) Q ^(IEN)
    272         ;
    273 VIN2NDI(VUID)   ; $$ Public - Get NDDF Ingredient for VUID
    274         ; NB: WILL ONLY WORK IF VUID IS AN INGREDIENT VUID, NOT A CLINICAL DRUG
    275         ; Input: VUID By Value
    276         ; Output: NDDF Base code
    277         ; TODO:Not tested...
    278         Q $$RXN2NDI($$VUI2RXN(VUID))
    279         ;
    280         ; ---
    281         ;
    282 NDC2RXN(NDC)    ; $$ Public - Get RxCUI given the NDC
    283         ; NB: Will only work if passed NDC is in 5-4-2 format.
    284         ; Input: NDC By Value in 5-4-2 Format
    285         ; Output: RxNorm Code.
    286         S NDC=$TR(NDC,"-")
    287         N IEN S IEN=$O(^C0CRXN(176.002,"ASAA","RXNORM","NDC",NDC,"")) Q ^(IEN)
    288         ;
    289 NDC2RXNT        ; @TEST - Test Get RxCUI given the NDC
    290         D CHKEQ^XTMUNIT($$NDC2RXN("30142-0917-71"),198439,"$$NDC2RXN failed")
    291         QUIT
    292         ;
    293         ; ---
    294         ;
    295 ISBRAND(RXN)    ; $$ Public - Is this RxCUI for a brand drug?
    296         ; Input: RxCUI
    297         ; Output: 0 or 1
    298         Q ''$D(^C0CRXN(176.001,"STC","RXNORM","SBD",RXN))
    299 ISBRANDT        ; @TEST - Test Is this RxCUI for a brand drug?
    300         D CHKEQ^XTMUNIT($$ISBRAND(205535),1,"$$ISBRAND failed") ; Brand Prozac
    301         D CHKEQ^XTMUNIT($$ISBRAND(310384),0,"$$ISBRAND failed") ; Generic Fluoxetine
    302         QUIT
    303         ;
    304         ; ---
    305         ;
    306 BR2GEN(RXN)     ; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
    307         ; Input: RxCUI of Brand
    308         ; Output: RxCUI of Generic
    309         Q $O(^C0CRXN(176.005,"B",RXN,"has_tradename",""))
    310 BR2GENT ; @TEST - Test Convert Brand RxCUI to Generic RxCUI (many to 1)
    311         D CHKEQ^XTMUNIT($$BR2GEN(205535),310384,"$$BR2GEN failed")
    312         QUIT
    313         ;
    314         ; ---
    315         ;
    316 GEN2BR(RXN)     ; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
    317         N RTN S RTN="" ; Return
    318         N I S I="" F  S I=$O(^C0CRXN(176.005,"B",RXN,"tradename_of",I)) Q:'I  S RTN=RTN_I_U
    319         S RTN=$E(RTN,1,$L(RTN)-1)
    320         Q RTN
    321         ;
    322 GEN2BRT ; @TEST - Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
    323         D CHKTF^XTMUNIT($$GEN2BR(310384)[205535,"$$GEN2BR failed")
    324         QUIT
    325         ;
    326         ; ---
    327         ;
    328 RXN2BNS(RXN)    ; $$ Public - Get all Brand Names associated with an RXN
    329         N BNS S BNS=""
    330         I $$ISBRAND(RXN) S RXN=$$BR2GEN(RXN)
    331         N ALLBN S ALLBN=$$GEN2BR(RXN)
    332         Q:ALLBN="" ""
    333         N BNNO F BNNO=1:1:$L(ALLBN,U) D
    334         . N EACHBN S EACHBN=$P(ALLBN,U,BNNO)
    335         . N BNRXCUI S BNRXCUI=$O(^C0CRXN(176.005,"B",EACHBN,"ingredient_of",""))
    336         . Q:BNRXCUI=""
    337         . N BNIEN S BNIEN=$O(^C0CRXN(176.001,"B",BNRXCUI,""))
    338         . S BNS=BNS_$P(^C0CRXN(176.001,BNIEN,0),U,15)_U
    339         QUIT $E(BNS,1,$L(BNS)-1)
    340 RXN2BNST        ; @TEST - Test Get all Brand Names associated with an RXN
    341         D CHKTF^XTMUNIT($$RXN2BNS(205535)["Prozac","$$RXN2BNS failed")
    342         QUIT
    343         ;
    344         ; ---
    345         ;
    346 RXN2NDC(RXN)    ; Get NDC codes for RxNorm code
    347         N NDCS S NDCS=""
    348         N I F I=0:0 S I=$O(^C0CRXN(176.002,"ASAR","RXNORM","NDC",RXN,I)) Q:'I  S NDCS=NDCS_^(I)_"^"
    349         S $E(NDCS,$L(NDCS))=""
    350         QUIT NDCS
    351 RXN2NDCT        ; @TEST - Test Get NDC codes for RxNorm code
    352         D CHKTF^XTMUNIT($$RXN2NDC(197379)["^"_16714003309,"$$RXN2NDC failed")
    353         QUIT
     1C0CRXNLK ; VEN/SMH - RxNorm Lookup Utilities ;2014-07-22  2:27 PM
     2 ;;2.3;RXNORM FOR VISTA;;Jul 22, 2014;Build 16
     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 ;
     12EXIST(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 ;
     17GCN2RXN(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 ;
     24GCN2RXNT ; @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^XTMUNIT($$GCN2RXN(GCN),RXN,"Translation from GCN to RXCUI failed")
     30 QUIT
     31 ;
     32GCN2RXND ; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
     33 ;;16033;991632
     34 ;;8208;310429
     35 ;;1275;628953
     36 ;;18;197604
     37 ;;346;884173
     38 ;;<<END>>
     39 ;
     40 ;
     41 ;
     42RXN2GCN(RXNCUI) ; $$ Public - Get GCN(s) given an RxNorm Number
     43 ; Input: RXNCUI by Value
     44 ; Output: Caret delimited Extrinsic
     45 N GCNS S GCNS=""
     46 N I S I=""
     47 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
     48 S GCNS=$E(GCNS,1,$L(GCNS)-1) ; remove trailing ^
     49 Q GCNS
     50 ;
     51RXN2GCNT ; @TEST - Test Get GCN from RXNCUI
     52 Q:'$D(^C0CRXN(176.001,"STX","NDDF"))
     53 N L F L=1:1 N LN S LN=$T(RXN2GCND+L) Q:LN["<<END>>"  Q:LN=""  D
     54 . N RXN S RXN=$P(LN,";",3)
     55 . N GCN S GCN=$P(LN,";",4)
     56 . D CHKEQ^XTMUNIT($$RXN2GCN(RXN),GCN,"Translation from RXCUI to GCN failed")
     57 QUIT
     58 ;
     59 ;
     60RXN2GCND ; @DATA - Data for Tests ;;RXNORM CUI;Expected GCN; Human Readable Drug name for dear reader
     61 ;;998689;5145;Acetabulol 200mg tab
     62 ;;745679;5037;Albuterol Inhaler
     63 ;;197320;2536;Allopurinol 300mg tab
     64 ;;993691;3948^46236;Bupropion 75mg tab
     65 ;;197591;3768;Diazepam 5mg tab
     66 ;;<<END>>
     67 ;
     68 ;
     69 ;
     70RXN2VUI(RXNCUI) ; $$ Public - Get VUID(s) for given RXNCUI for Clinical Drug
     71 ; Input: RXNCUI by Value
     72 ; Output: Caret delimited extrinsic. Should not be more than 2 entries.
     73 N C0PVUID S C0PVUID=""
     74 N I S I=""
     75 F  S I=$O(^C0CRXN(176.001,"STX","VANDF","CD",RXNCUI,I)) Q:I=""  S C0PVUID=C0PVUID_^(I)_U
     76 S C0PVUID=$E(C0PVUID,1,$L(C0PVUID)-1) ; remove trailing ^
     77 ; TODO: Return only the quantified form using:
     78 ; I $O(^C0CRXN(176.005,"RXCUIREL",RXN,"has_quantified_form","")) N QF S QF=$O(^("")) Q $O(^C0CRXN(176.001,"RXN2VUID",QF,""))
     79 Q C0PVUID
     80 ;
     81RXN2VUIT ; @TEST - Get VUIDs given RxNorm values
     82 N L F L=1:1 N LN S LN=$T(RXN2VUID+L) Q:LN["<<END>>"  Q:LN=""  D
     83 . N RXN S RXN=$P(LN,";",3)
     84 . N VUIDS S VUIDS=$P(LN,";",4)
     85 . D CHKEQ^XTMUNIT($P($$RXN2VUI(RXN),U),$P(VUIDS,U),"Translation from RXNCUI to VUID failed")
     86 QUIT
     87 ;
     88RXN2VUID ; @DATA - Data items for previous test
     89 ;;991632;4006455
     90 ;;310429;4002369^4013941
     91 ;;628953;4000874^4000856^4013966^4015798^4015799
     92 ;;197604;4003335^4015937
     93 ;;884173;4002469^4013919
     94 ;;<<END>>
     95 ;
     96 ;
     97 ;
     98VUI2VAP(VUID) ; $$ Public - Get VA Product IEN(s) from VUID
     99 ; Input VUID by Value
     100 ; Output: Extrinsic
     101 D FIND^DIC(50.68,,"@","QP",VUID,,"AVUID") ; Find all in VUID index
     102 N O S O="" ; Output
     103 N I F I=0:0 S I=$O(^TMP("DILIST",$J,I)) Q:'I  S O=O_^(I,0)_U ; Concat results together
     104 S O=$E(O,1,$L(O)-1) ; remove trailing ^
     105 Q O
     106 ;
     107VUI2VAPT ; @TEST - Get VA Product IEN from VUID
     108 N L F L=1:1 N LN S LN=$T(VUI2VAPD+L) Q:LN["<<END>>"  Q:LN=""  D
     109 . N VUID S VUID=$P(LN,";",3)
     110 . N VAP S VAP=$P(LN,";",4)
     111 . D CHKEQ^XTMUNIT($$VUI2VAP(VUID),VAP,"Translation from VUID to VA PRODUCT failed")
     112 QUIT
     113 ;
     114VUI2VAPD ; @DATA - Data for above test
     115 ;;4006455;5932
     116 ;;4002369;1784
     117 ;;4000874;252
     118 ;;4003335;2756
     119 ;;4002469;1884
     120 ;;4009488;9046^10090
     121 ;;<<END>>
     122 ;
     123 ;
     124 ;
     125VAP2MED(VAPROD) ; $$ Public - Get Drug(s) using VA Product IEN
     126 ; Un-Unit-testable: Drug files differ between sites.
     127 ; Input: VA Product IEN By Value
     128 ; OUtput: Caret delimited extrinsic
     129 ; This code inspired from PSNAPIs
     130 ; WHY THE HELL WOULD I USE A TEXT INDEX?
     131 ; It's my only option. Creating new xrefs on the drug file doesn't help
     132 ; as they are not filled out when adding a drug (IX[ALL]^DIK isn't called).
     133 N MEDS S MEDS="" ; result
     134 N PN,PN1 ; Product Name, abbreviated product name.
     135 S PN=$P(^PSNDF(50.68,VAPROD,0),"^"),PN1=$E(PN,1,30)
     136 N P50 S P50=0 ; looper through VAPN index which is DRUG file entry
     137 F  S P50=$O(^PSDRUG("VAPN",PN1,P50)) Q:'P50  D  ; for each text match
     138 . I $P(^PSDRUG(P50,"ND"),"^",3)=VAPROD S MEDS=$G(MEDS)_P50_U  ; check that the VA PRODUCT pointer is the same as ours.
     139 S:MEDS MEDS=$E(MEDS,1,$L(MEDS)-1) ; remove trailing ^
     140 Q MEDS
     141 ;
     142 ;
     143RXN2MEDS(RXNCUI) ; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
     144 ; Input: SCD RXNCUI
     145 ; Output; Caret delimited extrinsic
     146 ; Un-unit testable
     147 N VUIDS S VUIDS=$$RXN2VUI(RXNCUI) ; Get VUID from RXNCUI (multiple VUIDs per CUI)
     148 Q:'VUIDS ""
     149 N MEDS S MEDS=""
     150 N DONE S DONE=0
     151 N I F I=1:1:$L(VUIDS,U) D  Q:DONE
     152 . N VUID S VUID=$P(VUIDS,U,I)
     153 . N VAPRODS S VAPRODS=$$VUI2VAP(VUID) ; Get VA Product from VUID (multiple products per VUID)
     154 . I '$L(VAPRODS) S $ECODE=",U-NO-VA-PRODUCT-CORRUPT-NDF,"  ; MUST EXIST. Every VUID must have a product to go with it.
     155 . N J F J=1:1:$L(VAPRODS,U) D  Q:DONE
     156 . . N VAPROD S VAPROD=$P(VAPRODS,U,J)
     157 . . S MEDS=$$VAP2MED(VAPROD) ; Get Meds from VA Product
     158 . . I $L(MEDS) S DONE=1
     159 QUIT MEDS
     160 ;
     161FDI2RXN(BASE) ; $$ Public - Get RxNorm CUI for FDB Ingredient/Base
     162 ; ^C0CRXN(176.001,"STC","NDDF","IN","014739",1000870)=1362160
     163 ; Input: BASE By Value
     164 ; Output: RxNorm CUI
     165 S BASE=$$RJ^XLFSTR(BASE,6,0) ; pad to six digits by zeros (123 becomes 000123)
     166 N IEN S IEN=$O(^C0CRXN(176.001,"STC","NDDF","IN",BASE,"")) Q ^(IEN)
     167 ;
     168FDI2RXNT ; @TEST - Test Get RxNorm CUI for FDB Ingredient/Base
     169 Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
     170 D CHKEQ^XTMUNIT($$FDI2RXN(14739),1362160,"$$FDI2RXN failed")
     171 QUIT
     172 ;
     173 ;
     174 ;
     175RXN2VIN(RXNCUI) ; $$ Public - Get VUID Ingredient for RxNorm CUI
     176 ; ^C0CRXN(176.001,"STX","VANDF","IN",1366467,1008555)=4031768
     177 ; Input: RXNCUI By Value
     178 ; Output: VUID
     179 N IEN S IEN=$O(^C0CRXN(176.001,"STX","VANDF","IN",RXNCUI,"")) Q ^(IEN)
     180 ;
     181RXN2VINT ; @TEST - Test Get VUID Ingredient for RxNorm CUI
     182 D CHKEQ^XTMUNIT($$RXN2VIN(1366467),4031768,"$$RXN2VIN failed")
     183 QUIT
     184 ;
     185 ;
     186 ;
     187VIN2VAG(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 ;
     194VIN2VAGT ; @TEST - Test Get VA Generic for VUID Ingredient
     195 D CHKEQ^XTMUNIT(+$$VIN2VAG(4023636),2832,"$$VIN2VAG failed")
     196 QUIT
     197 ;
     198 ;
     199 ;
     200FDI2VAG(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 ;
     206VIN2DIN(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 ;
     214FDI2DIN(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 ;
     220VUI2RXN(VUID) ; $$ Public - Get RXNCUI for VUID (any VUID type)
     221 ; Input: VUID By Value
     222 ; Output: RXNCUIs delimited by ^
     223 ; Get all entries whose code is the VUID and are in the VA NDF which are clinical drugs
     224 D FIND^DIC(176.001,,"@;.01","PQX",VUID,,"CODE","I $P(^(0),U,12,13)=""VANDF^CD""")
     225 ; Deserialise it into a single string
     226 ; ^TMP("DILIST",4844,0)="1^*^0^"
     227 ; ^TMP("DILIST",4844,0,"MAP")="IEN^.01"
     228 ; ^TMP("DILIST",4844,1,0)="1006351^1364462"
     229 N RXNS S RXNS=""
     230 N I F I=0:0 S I=$O(^TMP("DILIST",$J,I)) Q:'I  S RXNS=RXNS_$P(^(I,0),U,2)_U
     231 S RXNS=$E(RXNS,1,$L(RXNS)-1)
     232 QUIT RXNS
     233 ;
     234VUI2GCN(VUID) ; $$ Public - Get GCNs for a given VUID (any VUID type)
     235 ; Input: VUID by Value
     236 ; Output: GCNs delimited by ^
     237 ; TODO: Unit Test
     238 N RXNS S RXNS=$$VUI2RXN(VUID)
     239 Q:RXNS="" ""  ; VUID not a drug or ingredient (can be food)
     240 N GCNS S GCNS=""
     241 N I F I=1:1:$L(RXNS,U) S GCNS=GCNS_$$RXN2GCN($P(RXNS,U,I))_U
     242 S GCNS=$E(GCNS,1,$L(GCNS)-1)
     243 QUIT GCNS
     244 ;
     245MED2RXN(DA) ; $$ Public - Get RxNorm CUI for Drug
     246 ; Input: DA - Medication IEN
     247 ; Output: RXNCUIs delimited by ^
     248 N ND S ND=$G(^PSDRUG(DA,"ND")) ; ND Node
     249 N VAP S VAP=$P(ND,U,3) ; VA Product Pointer
     250 Q:'VAP ""  ; quit if empty
     251 N VUID S VUID=+^PSNDF(50.68,VAP,"VUID")  ; Get VUID
     252 I 'VUID S $EC=",U1," ; Must exist
     253 Q $$VUI2RXN(VUID)
     254 ;
     255MED2SCDN(DA) ; $$ Public - Medication to Semantic Clinical Drug Name
     256 ; Input: DA - Medication IEN
     257 ; Output: The Canonical Semantic Clinical Drug name
     258 N RXNCUI S RXNCUI=$$MED2RXN(DA)
     259 Q:'RXNCUI ""
     260 N IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCD",RXNCUI,""))  ; Let's try generic drug
     261 I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SBD",RXNCUI,""))  ; Let's try non-bioequivalent Brands then
     262 I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","GPCK",RXNCUI,"")) ; Let's try a Generic combination package
     263 I 'IEN S IEN=$O(^C0CRXN(176.001,"STC","RXNORM","SCDF",RXNCUI,"")) ; Let's try a Clinical Drug and Form (Like Metamucil)
     264 Q:'IEN "" ; Apparently not every VUID has a corresponding RXNCUI SCD.
     265 Q $P(^C0CRXN(176.001,IEN,0),U,15)
     266 ;
     267RXN2NDI(RXNCUI) ; $$ Public - Get NDDF Ingredient for RXNCUI
     268 ; Input: RXNCUI By Value
     269 ; Output: NDDF Base code
     270 ; TODO:Not tested...
     271 N IEN S IEN=$O(^C0CRXN(176.001,"STX","NDDF","IN",RXNCUI,"")) Q ^(IEN)
     272 ;
     273VIN2NDI(VUID) ; $$ Public - Get NDDF Ingredient for VUID
     274 ; NB: WILL ONLY WORK IF VUID IS AN INGREDIENT VUID, NOT A CLINICAL DRUG
     275 ; Input: VUID By Value
     276 ; Output: NDDF Base code
     277 ; TODO:Not tested...
     278 Q $$RXN2NDI($$VUI2RXN(VUID))
     279 ;
     280 ; ---
     281 ;
     282NDC2RXN(NDC) ; $$ Public - Get RxCUI given the NDC
     283 ; NB: Will only work if passed NDC is in 5-4-2 format.
     284 ; Input: NDC By Value in 5-4-2 Format
     285 ; Output: RxNorm Code.
     286 S NDC=$TR(NDC,"-")
     287 N IEN S IEN=$O(^C0CRXN(176.002,"ASAA","RXNORM","NDC",NDC,"")) Q ^(IEN)
     288 ;
     289NDC2RXNT ; @TEST - Test Get RxCUI given the NDC & Get RxCUI given the 50.67 NDC
     290 D CHKEQ^XTMUNIT($$NDC2RXN("30142-0917-71"),198439,"$$NDC2RXN failed")
     291 D CHKEQ^XTMUNIT($$NDC2RXN2("000031868518","VANDF"),996520,"$$NDC2RXN2 failed")
     292 QUIT
     293 ;
     294NDC2RXN2(NDC,SOURCE) ; $$ Public - Get RxCUI given the source
     295 ; Input: NDC in any format according to source
     296 ; Output: RxNorm Code
     297 I SOURCE="" QUIT ""
     298 N IEN S IEN=$O(^C0CRXN(176.002,"ASAA",SOURCE,"NDC",NDC,"")) Q:IEN ^(IEN)  Q ""
     299 QUIT
     300 ; ---
     301 ;
     302ISBRAND(RXN) ; $$ Public - Is this RxCUI for a brand drug?
     303 ; Input: RxCUI
     304 ; Output: 0 or 1
     305 Q ''$D(^C0CRXN(176.001,"STC","RXNORM","SBD",RXN))
     306ISBRANDT ; @TEST - Test Is this RxCUI for a brand drug?
     307 D CHKEQ^XTMUNIT($$ISBRAND(205535),1,"$$ISBRAND failed") ; Brand Prozac
     308 D CHKEQ^XTMUNIT($$ISBRAND(310384),0,"$$ISBRAND failed") ; Generic Fluoxetine
     309 QUIT
     310 ;
     311 ; ---
     312 ;
     313BR2GEN(RXN) ; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
     314 ; Input: RxCUI of Brand
     315 ; Output: RxCUI of Generic
     316 Q $O(^C0CRXN(176.005,"B",RXN,"has_tradename",""))
     317BR2GENT ; @TEST - Test Convert Brand RxCUI to Generic RxCUI (many to 1)
     318 D CHKEQ^XTMUNIT($$BR2GEN(205535),310384,"$$BR2GEN failed")
     319 QUIT
     320 ;
     321 ; ---
     322 ;
     323GEN2BR(RXN) ; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
     324 N RTN S RTN="" ; Return
     325 N I S I="" F  S I=$O(^C0CRXN(176.005,"B",RXN,"tradename_of",I)) Q:'I  S RTN=RTN_I_U
     326 S RTN=$E(RTN,1,$L(RTN)-1)
     327 Q RTN
     328 ;
     329GEN2BRT ; @TEST - Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
     330 D CHKTF^XTMUNIT($$GEN2BR(310384)[205535,"$$GEN2BR failed")
     331 QUIT
     332 ;
     333 ; ---
     334 ;
     335RXN2BNS(RXN) ; $$ Public - Get all Brand Names associated with an RXN
     336 N BNS S BNS=""
     337 I $$ISBRAND(RXN) S RXN=$$BR2GEN(RXN)
     338 N ALLBN S ALLBN=$$GEN2BR(RXN)
     339 Q:ALLBN="" ""
     340 N BNNO F BNNO=1:1:$L(ALLBN,U) D
     341 . N EACHBN S EACHBN=$P(ALLBN,U,BNNO)
     342 . N BNRXCUI S BNRXCUI=$O(^C0CRXN(176.005,"B",EACHBN,"ingredient_of",""))
     343 . Q:BNRXCUI=""
     344 . N BNIEN S BNIEN=$O(^C0CRXN(176.001,"B",BNRXCUI,""))
     345 . S BNS=BNS_$P(^C0CRXN(176.001,BNIEN,0),U,15)_U
     346 QUIT $E(BNS,1,$L(BNS)-1)
     347RXN2BNST ; @TEST - Test Get all Brand Names associated with an RXN
     348 D CHKTF^XTMUNIT($$RXN2BNS(205535)["Prozac","$$RXN2BNS failed")
     349 QUIT
     350 ;
     351 ; ---
     352 ;
     353RXN2NDC(RXN) ; Get NDC codes for RxNorm code
     354 N NDCS S NDCS=""
     355 N I F I=0:0 S I=$O(^C0CRXN(176.002,"ASAR","RXNORM","NDC",RXN,I)) Q:'I  S NDCS=NDCS_^(I)_"^"
     356 S $E(NDCS,$L(NDCS))=""
     357 QUIT NDCS
     358RXN2NDCT ; @TEST - Test Get NDC codes for RxNorm code
     359 D CHKTF^XTMUNIT($$RXN2NDC(197379)["^"_16714003309,"$$RXN2NDC failed")
     360 QUIT
Note: See TracChangeset for help on using the changeset viewer.