Changeset 1630 for ccr/trunk


Ignore:
Timestamp:
Nov 14, 2013, 5:40:26 PM (11 years ago)
Author:
Sam Habiel
Message:

Two routines modified: C0CRXNRD and C0CRXNLK.

C0CRXNRD (loader utility):

  • Can now import RxNorm prescribably subset
  • Will import public domain by default except if RESTRICTED is passed to IMPORT as 1 (second parameter).

C0CRXNLK (lookup utilities):

  • FDB Unit Tests don't run if FDB from RxNorm isn't loaded.
  • New API: $$RXN2GCN - Get GCNs from RXNCUI (+UT).
  • New API: $$VUI2GCN - Get VUIDs from GCN (No UT supplied).
  • New API: $$RXN2NDC - Get NDCs for a given RxNorm CUI (+UT).
Location:
ccr/trunk/rxnorm/trunk/routines
Files:
3 edited

Legend:

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

    r1618 r1630  
    1 C0CRXNAD ; VEN/SMH - Add a drug to VISTA from RxNorm;2013-04-19  5:39 PM
    2  ;;1.0;RX NORM;;Apr 25, 2012;Build 99
    3  ; (C) 2013 Sam Habiel
    4  ; Proprietary Code. Don't use if license terms aren't supplied.
    5  ;
    6 ADDDRUG(RXN,NDC,BARCODE) ; Public Proc; Add Drug to Drug File
    7  ; Input: RXN - RxNorm Semantic Clinical Drug CUI by Value. Required.
    8  ; Input: NDC - Drug NDC by Value. Optional. Pass in 11 digit format without dashes.
    9  ; Input: BARCODE - Wand Barcode. Optional. Pass exactly as wand reads minus control characters.
    10  ; Output: Internal Entry Number
    11  ;
    12  ; Prelim Checks
    13  I '$G(RXN) S $EC=",U1," ; Required
    14  I $L($G(NDC)),$L(NDC)'=11 S $EC=",U1,"
    15  ;
    16  N PSSZ S PSSZ=1    ; Needed for the drug file to let me in!
    17  ;
    18  ; If RXN refers to a brand drug, get the generic instead.
    19  I $$ISBRAND^C0CRXNLK(RXN) S RXN=$$BR2GEN^C0CRXNLK(RXN)
    20  W !,"(debug) RxNorm is "_RXN,!
    21  ;
    22  ; Get first VUID for this RxNorm drug
    23  N VUID S VUID=+$$RXN2VUI^C0CRXNLK(RXN)
    24  Q:'VUID
    25  W "(debug) VUID for RxNorm CUI "_RXN_" is "_VUID,!
    26  ;
    27  ; IEN in 50.68
    28  N C0XVUID ; For Searching Compound Index
    29  S C0XVUID(1)=VUID
    30  S C0XVUID(2)=1
    31  N F5068IEN S F5068IEN=$$FIND1^DIC(50.68,"","XQ",.C0XVUID,"AMASTERVUID")
    32  Q:'F5068IEN
    33  W "F 50.68 IEN (debug): "_F5068IEN,!
    34  ;
    35  ; FDA Array
    36  N C0XFDA
    37  ;
    38  ; Name, shortened
    39  S C0XFDA(50,"+1,",.01)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,40)
    40  ;
    41  ; File BarCode as a Synonym for BCMA
    42  I $L($G(BARCODE)) D
    43  . S C0XFDA(50.1,"+2,+1,",.01)=BARCODE
    44  . S C0XFDA(50.1,"+2,+1,",1)="Q"
    45  ;
    46  ; Brand Names
    47  N BNS S BNS=$$RXN2BNS^C0CRXNLK(RXN) ; Brands
    48  I $L(BNS) N I F I=1:1:$L(BNS,U) D
    49  . N IENS S IENS=I+2
    50  . S C0XFDA(50.1,"+"_IENS_",+1,",.01)=$$UP^XLFSTR($E($P(BNS,U,I),1,40))
    51  . S C0XFDA(50.1,"+"_IENS_",+1,",1)="T"
    52  ;
    53  ; NDC (string)
    54  I $G(NDC) S C0XFDA(50,"+1,",31)=$E(NDC,1,5)_"-"_$E(NDC,6,9)_"-"_$E(NDC,10,11)
    55  ;
    56  ; Dispense Unit (string)
    57  S C0XFDA(50,"+1,",14.5)=$$GET1^DIQ(50.68,F5068IEN,"VA DISPENSE UNIT")
    58  ;
    59  ; National Drug File Entry (pointer to 50.6)
    60  S C0XFDA(50,"+1,",20)="`"_$$GET1^DIQ(50.68,F5068IEN,"VA GENERIC NAME","I")
    61  ;
    62  ; VA Product Name (string)
    63  S C0XFDA(50,"+1,",21)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,70)
    64  ;
    65  ; PSNDF VA PRODUCT NAME ENTRY (pointer to 50.68)
    66  S C0XFDA(50,"+1,",22)="`"_F5068IEN
    67  ;
    68  ; DEA, SPECIAL HDLG (string)
    69  D  ; From ^PSNMRG
    70  . N CS S CS=$$GET1^DIQ(50.68,F5068IEN,"CS FEDERAL SCHEDULE","I")
    71  . S CS=$S(CS?1(1"2n",1"3n"):+CS_"C",+CS=2!(+CS=3)&(CS'["C"):+CS_"A",1:CS)
    72  . S C0XFDA(50,"+1,",3)=CS
    73  ;
    74  ; NATIONAL DRUG CLASS (pointer to 50.605) (triggers VA Classification field)
    75  S C0XFDA(50,"+1,",25)="`"_$$GET1^DIQ(50.68,F5068IEN,"PRIMARY VA DRUG CLASS","I")
    76  ;
    77  ; Right Now, I don't file the following which ^PSNMRG does (cuz I don't need them)
    78  ; - Package Size (derived from NDC/UPN file)
    79  ; - Package Type (ditto)
    80  ; - CMOP ID (from $$PROD2^PSNAPIS)
    81  ; - National Formulary Indicator (from 50.68)
    82  ;
    83  ; Next Step is to kill Old OI if Dosage Form doesn't match
    84  ; Won't do that here as it's assumed any drugs that's added is new.
    85  ; This happens at ^PSNPSS
    86  ;
    87  ; Now add drug to drug file, as we need the IEN for the dosages call.
    88  N C0XERR,C0XIEN
    89  D UPDATE^DIE("E","C0XFDA","C0XIEN","C0XERR")
    90  S:$D(C0XERR) $EC=",U1,"
    91  ;
    92  ; Next Step: Kill off old doses and add new ones.
    93  D EN2^PSSUTIL(C0XIEN(1))
    94  ;
    95  ; Mark uses for the Drug; use the undocumented Silent call in PSSGIU
    96  N PSIUDA,PSIUX ; Expected Input variables
    97  S PSIUDA=C0XIEN(1),PSIUX="O^Outpatient Pharmacy" D ENS^PSSGIU
    98  S PSIUDA=C0XIEN(1),PSIUX="U^Unit Dose" D ENS^PSSGIU
    99  S PSIUDA=C0XIEN(1),PSIUX="X^Non-VA Med" D ENS^PSSGIU
    100  ;
    101  ; Get VA Generic text and VA Product pointer for Orderable Item creation plus dosage form information
    102  N VAGENP S VAGENP=$P(^PSDRUG(C0XIEN(1),"ND"),U) ; VA Generic Pointer
    103  N VAGEN S VAGEN=$$VAGN^PSNAPIS(VAGENP) ; VA Generic Full name
    104  N VAPRODP S VAPRODP=$P(^PSDRUG(C0XIEN(1),"ND"),U,3) ; VA Product Pointer
    105  N DOSAGE S DOSAGE=$$PSJDF^PSNAPIS(0,VAPRODP) ; IEN of dose form in 50.606 ^ Text
    106  N DOSEPTR S DOSEPTR=$P(DOSAGE,U) ; ditto
    107  N DOSEFORM S DOSEFORM=$P(DOSAGE,U,2) ;ditto
    108  ;
    109  ; Get the (possibly new) Orderable Item Text
    110  N VAG40 S VAG40=$E(VAGEN,1,40) ; Max length of .01 field
    111  ;
    112  ; See if there is an existing orderable item already. If so, populate the Pharmacy Orderable item on drug file.
    113  N OI S OI=$O(^PS(50.7,"ADF",VAG40,DOSEPTR,""))
    114  ;
    115  ; Otherwise, add a new one. (See MCHAN+12^PSSPOIMN)
    116  I 'OI D
    117  . N C0XFDA,C0XERR
    118  . S C0XFDA(50.7,"+1,",.01)=VAG40
    119  . S C0XFDA(50.7,"+1,",.02)=DOSEPTR
    120  . D UPDATE^DIE("",$NA(C0XFDA),$NA(OI),$NA(C0XERR))
    121  . I $D(C0XERR) S $EC=",U1,"
    122  . S OI=OI(1) ; For ease of use...
    123  . ; Next two statements: See FIN^PSSPOIM1 and MF^PSSDEE.
    124  . D EN^PSSPOIDT(OI) ; Update Indexes; activations, etc.
    125  . D EN2^PSSHL1(OI,"MUP") ; Send HL7 message to CPRS
    126  ;
    127  ; Finally, add the orderable Item to the drug file.
    128  N C0XFDA,C0XERR S C0XFDA(50,C0XIEN(1)_",",2.1)=OI ; Orderable Item
    129  D FILE^DIE("",$NA(C0XFDA),$NA(C0XERR))
    130  S:$D(C0XERR) $EC=",U1,"
    131  ;
    132 EX QUIT C0XIEN(1)
     1C0CRXNAD        ; VEN/SMH - Add a drug to VISTA from RxNorm;2013-04-19  5:39 PM
     2        ;;2.2;RXNORM FOR VISTA;;Nov 14, 2013;Build 8
     3        ; (C) 2013 Sam Habiel
     4        ; Proprietary Code. Don't use if license terms aren't supplied.
     5        ;
     6ADDDRUG(RXN,NDC,BARCODE)        ; Public Proc; Add Drug to Drug File
     7        ; Input: RXN - RxNorm Semantic Clinical Drug CUI by Value. Required.
     8        ; Input: NDC - Drug NDC by Value. Optional. Pass in 11 digit format without dashes.
     9        ; Input: BARCODE - Wand Barcode. Optional. Pass exactly as wand reads minus control characters.
     10        ; Output: Internal Entry Number
     11        ;
     12        ; Prelim Checks
     13        I '$G(RXN) S $EC=",U1," ; Required
     14        I $L($G(NDC)),$L(NDC)'=11 S $EC=",U1,"
     15        ;
     16        N PSSZ S PSSZ=1    ; Needed for the drug file to let me in!
     17        ;
     18        ; If RXN refers to a brand drug, get the generic instead.
     19        I $$ISBRAND^C0CRXNLK(RXN) S RXN=$$BR2GEN^C0CRXNLK(RXN)
     20        W !,"(debug) RxNorm is "_RXN,!
     21        ;
     22        ; Get first VUID for this RxNorm drug
     23        N VUID S VUID=+$$RXN2VUI^C0CRXNLK(RXN)
     24        Q:'VUID
     25        W "(debug) VUID for RxNorm CUI "_RXN_" is "_VUID,!
     26        ;
     27        ; IEN in 50.68
     28        N C0XVUID ; For Searching Compound Index
     29        S C0XVUID(1)=VUID
     30        S C0XVUID(2)=1
     31        N F5068IEN S F5068IEN=$$FIND1^DIC(50.68,"","XQ",.C0XVUID,"AMASTERVUID")
     32        Q:'F5068IEN
     33        W "F 50.68 IEN (debug): "_F5068IEN,!
     34        ;
     35        ; FDA Array
     36        N C0XFDA
     37        ;
     38        ; Name, shortened
     39        S C0XFDA(50,"+1,",.01)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,40)
     40        ;
     41        ; File BarCode as a Synonym for BCMA
     42        I $L($G(BARCODE)) D
     43        . S C0XFDA(50.1,"+2,+1,",.01)=BARCODE
     44        . S C0XFDA(50.1,"+2,+1,",1)="Q"
     45        ;
     46        ; Brand Names
     47        N BNS S BNS=$$RXN2BNS^C0CRXNLK(RXN) ; Brands
     48        I $L(BNS) N I F I=1:1:$L(BNS,U) D
     49        . N IENS S IENS=I+2
     50        . S C0XFDA(50.1,"+"_IENS_",+1,",.01)=$$UP^XLFSTR($E($P(BNS,U,I),1,40))
     51        . S C0XFDA(50.1,"+"_IENS_",+1,",1)="T"
     52        ;
     53        ; NDC (string)
     54        I $G(NDC) S C0XFDA(50,"+1,",31)=$E(NDC,1,5)_"-"_$E(NDC,6,9)_"-"_$E(NDC,10,11)
     55        ;
     56        ; Dispense Unit (string)
     57        S C0XFDA(50,"+1,",14.5)=$$GET1^DIQ(50.68,F5068IEN,"VA DISPENSE UNIT")
     58        ;
     59        ; National Drug File Entry (pointer to 50.6)
     60        S C0XFDA(50,"+1,",20)="`"_$$GET1^DIQ(50.68,F5068IEN,"VA GENERIC NAME","I")
     61        ;
     62        ; VA Product Name (string)
     63        S C0XFDA(50,"+1,",21)=$E($$GET1^DIQ(50.68,F5068IEN,.01),1,70)
     64        ;
     65        ; PSNDF VA PRODUCT NAME ENTRY (pointer to 50.68)
     66        S C0XFDA(50,"+1,",22)="`"_F5068IEN
     67        ;
     68        ; DEA, SPECIAL HDLG (string)
     69        D  ; From ^PSNMRG
     70        . N CS S CS=$$GET1^DIQ(50.68,F5068IEN,"CS FEDERAL SCHEDULE","I")
     71        . S CS=$S(CS?1(1"2n",1"3n"):+CS_"C",+CS=2!(+CS=3)&(CS'["C"):+CS_"A",1:CS)
     72        . S C0XFDA(50,"+1,",3)=CS
     73        ;
     74        ; NATIONAL DRUG CLASS (pointer to 50.605) (triggers VA Classification field)
     75        S C0XFDA(50,"+1,",25)="`"_$$GET1^DIQ(50.68,F5068IEN,"PRIMARY VA DRUG CLASS","I")
     76        ;
     77        ; Right Now, I don't file the following which ^PSNMRG does (cuz I don't need them)
     78        ; - Package Size (derived from NDC/UPN file)
     79        ; - Package Type (ditto)
     80        ; - CMOP ID (from $$PROD2^PSNAPIS)
     81        ; - National Formulary Indicator (from 50.68)
     82        ;
     83        ; Next Step is to kill Old OI if Dosage Form doesn't match
     84        ; Won't do that here as it's assumed any drugs that's added is new.
     85        ; This happens at ^PSNPSS
     86        ;
     87        ; Now add drug to drug file, as we need the IEN for the dosages call.
     88        N C0XERR,C0XIEN
     89        D UPDATE^DIE("E","C0XFDA","C0XIEN","C0XERR")
     90        S:$D(C0XERR) $EC=",U1,"
     91        ;
     92        ; Next Step: Kill off old doses and add new ones.
     93        D EN2^PSSUTIL(C0XIEN(1))
     94        ;
     95        ; Mark uses for the Drug; use the undocumented Silent call in PSSGIU
     96        N PSIUDA,PSIUX ; Expected Input variables
     97        S PSIUDA=C0XIEN(1),PSIUX="O^Outpatient Pharmacy" D ENS^PSSGIU
     98        S PSIUDA=C0XIEN(1),PSIUX="U^Unit Dose" D ENS^PSSGIU
     99        S PSIUDA=C0XIEN(1),PSIUX="X^Non-VA Med" D ENS^PSSGIU
     100        ;
     101        ; Get VA Generic text and VA Product pointer for Orderable Item creation plus dosage form information
     102        N VAGENP S VAGENP=$P(^PSDRUG(C0XIEN(1),"ND"),U) ; VA Generic Pointer
     103        N VAGEN S VAGEN=$$VAGN^PSNAPIS(VAGENP) ; VA Generic Full name
     104        N VAPRODP S VAPRODP=$P(^PSDRUG(C0XIEN(1),"ND"),U,3) ; VA Product Pointer
     105        N DOSAGE S DOSAGE=$$PSJDF^PSNAPIS(0,VAPRODP) ; IEN of dose form in 50.606 ^ Text
     106        N DOSEPTR S DOSEPTR=$P(DOSAGE,U) ; ditto
     107        N DOSEFORM S DOSEFORM=$P(DOSAGE,U,2) ;ditto
     108        ;
     109        ; Get the (possibly new) Orderable Item Text
     110        N VAG40 S VAG40=$E(VAGEN,1,40) ; Max length of .01 field
     111        ;
     112        ; See if there is an existing orderable item already. If so, populate the Pharmacy Orderable item on drug file.
     113        N OI S OI=$O(^PS(50.7,"ADF",VAG40,DOSEPTR,""))
     114        ;
     115        ; Otherwise, add a new one. (See MCHAN+12^PSSPOIMN)
     116        I 'OI D
     117        . N C0XFDA,C0XERR
     118        . S C0XFDA(50.7,"+1,",.01)=VAG40
     119        . S C0XFDA(50.7,"+1,",.02)=DOSEPTR
     120        . D UPDATE^DIE("",$NA(C0XFDA),$NA(OI),$NA(C0XERR))
     121        . I $D(C0XERR) S $EC=",U1,"
     122        . S OI=OI(1) ; For ease of use...
     123        . ; Next two statements: See FIN^PSSPOIM1 and MF^PSSDEE.
     124        . D EN^PSSPOIDT(OI) ; Update Indexes; activations, etc.
     125        . D EN2^PSSHL1(OI,"MUP") ; Send HL7 message to CPRS
     126        ;
     127        ; Finally, add the orderable Item to the drug file.
     128        N C0XFDA,C0XERR S C0XFDA(50,C0XIEN(1)_",",2.1)=OI ; Orderable Item
     129        D FILE^DIE("",$NA(C0XFDA),$NA(C0XERR))
     130        S:$D(C0XERR) $EC=",U1,"
     131        ;
     132EX      QUIT C0XIEN(1)
  • ccr/trunk/rxnorm/trunk/routines/C0CRXNLK.m

    r1617 r1630  
    1 C0CRXNLK        ; VEN/SMH - RxNorm Lookup Utilities ;2013-04-10  7:01 PM
    2         ;;1.0;RX NORM;;Apr 25, 2012;Build 99
     1C0CRXNLK        ; VEN/SMH - RxNorm Lookup Utilities ;2013-11-14  2:43 PM
     2        ;;2.2;RXNORM FOR VISTA;;Nov 14, 2013;Build 8
    33        ;(c) Sam Habiel 2013
    44        ; See accompanying license. Don't use otherwise.
     
    1010        QUIT
    1111        ;
    12 EXIST(RXN) ; $$ Public - Does this RxNorm CUI exist?
     12EXIST(RXN)      ; $$ Public - Does this RxNorm CUI exist?
    1313        ; Input: RxNorm CUI by value
    1414        ; Output: Extrinsic
     
    2222        Q ^(IEN)
    2323        ;
    24 GCN2RXNT ; @TEST - Test Get RxNorm CUI using GCN
     24GCN2RXNT        ; @TEST - Test Get RxNorm CUI using GCN
     25        Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
    2526        N L F L=1:1 N LN S LN=$T(GCN2RXND+L) Q:LN["<<END>>"  Q:LN=""  D
    2627        . N GCN S GCN=$P(LN,";",3)
     
    2930        QUIT
    3031        ;
    31 GCN2RXND ; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
     32GCN2RXND        ; @DATA - Data for Tests ;;GCN;EXPECTED RXNCUI
    3233        ;;16033;991632
    3334        ;;8208;310429
     
    3536        ;;18;197604
    3637        ;;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
    3766        ;;<<END>>
    3867        ;
     
    5079        Q C0PVUID
    5180        ;
    52 RXN2VUIT ; @TEST - Get VUIDs given RxNorm values
     81RXN2VUIT        ; @TEST - Get VUIDs given RxNorm values
    5382        N L F L=1:1 N LN S LN=$T(RXN2VUID+L) Q:LN["<<END>>"  Q:LN=""  D
    5483        . N RXN S RXN=$P(LN,";",3)
     
    5786        QUIT
    5887        ;
    59 RXN2VUID ; @DATA - Data items for previous test
     88RXN2VUID        ; @DATA - Data items for previous test
    6089        ;;991632;4006455
    6190        ;;310429;4002369^4013941
     
    76105        Q O
    77106        ;
    78 VUI2VAPT ; @TEST - Get VA Product IEN from VUID
     107VUI2VAPT        ; @TEST - Get VA Product IEN from VUID
    79108        N L F L=1:1 N LN S LN=$T(VUI2VAPD+L) Q:LN["<<END>>"  Q:LN=""  D
    80109        . N VUID S VUID=$P(LN,";",3)
     
    83112        QUIT
    84113        ;
    85 VUI2VAPD ; @DATA - Data for above test
     114VUI2VAPD        ; @DATA - Data for above test
    86115        ;;4006455;5932
    87116        ;;4002369;1784
     
    112141        ;
    113142        ;
    114 RXN2MEDS(RXNCUI) ; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
     143RXN2MEDS(RXNCUI)        ; $$ Public - Convert RxNorm value to currently existing drugs in File 50.
    115144        ; Input: SCD RXNCUI
    116145        ; Output; Caret delimited extrinsic
     
    123152        . N VUID S VUID=$P(VUIDS,U,I)
    124153        . N VAPRODS S VAPRODS=$$VUI2VAP(VUID) ; Get VA Product from VUID (multiple products per VUID)
    125         . I '$L(VAPRODS) S ^SAM(RXNCUI)="TELL SAM",DONE=1 QUIT  ; MUST EXIST. Every VUID must have a product to go with it.
     154        . I '$L(VAPRODS) S $ECODE=",U-NO-VA-PRODUCT-CORRUPT-NDF,"  ; MUST EXIST. Every VUID must have a product to go with it.
    126155        . N J F J=1:1:$L(VAPRODS,U) D  Q:DONE
    127156        . . N VAPROD S VAPROD=$P(VAPRODS,U,J)
     
    138167        ;
    139168FDI2RXNT        ; @TEST - Test Get RxNorm CUI for FDB Ingredient/Base
     169        Q:'$D(^C0CRXN(176.001,"STC","NDDF"))
    140170        D CHKEQ^XTMUNIT($$FDI2RXN(14739),1362160,"$$FDI2RXN failed")
    141171        QUIT
     
    162192        Q C0PIEN_"^"_C0P01
    163193        ;
    164 VIN2VAGT ; @TEST - Test Get VA Generic for VUID Ingredient
     194VIN2VAGT        ; @TEST - Test Get VA Generic for VUID Ingredient
    165195        D CHKEQ^XTMUNIT(+$$VIN2VAG(4023636),2832,"$$VIN2VAG failed")
    166196        QUIT
     
    202232        QUIT RXNS
    203233        ;
    204 MED2RXN(DA) ; $$ Public - Get RxNorm CUI for Drug
     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        N GCNS S GCNS=""
     240        N I F I=1:1:$L(RXNS,U) S GCNS=GCNS_$$RXN2GCN($P(RXNS,U,I))_U
     241        S GCNS=$E(GCNS,1,$L(GCNS)-1)
     242        QUIT GCNS
     243        ;
     244MED2RXN(DA)     ; $$ Public - Get RxNorm CUI for Drug
    205245        ; Input: DA - Medication IEN
    206246        ; Output: RXNCUIs delimited by ^
     
    212252        Q $$VUI2RXN(VUID)
    213253        ;
    214 MED2SCDN(DA) ; $$ Public - Medication to Semantic Clinical Drug Name
     254MED2SCDN(DA)    ; $$ Public - Medication to Semantic Clinical Drug Name
    215255        ; Input: DA - Medication IEN
    216256        ; Output: The Canonical Semantic Clinical Drug name
     
    239279        ; ---
    240280        ;
    241 NDC2RXN(NDC) ; $$ Public - Get RxCUI given the NDC
     281NDC2RXN(NDC)    ; $$ Public - Get RxCUI given the NDC
    242282        ; NB: Will only work if passed NDC is in 5-4-2 format.
    243283        ; Input: NDC By Value in 5-4-2 Format
     
    246286        N IEN S IEN=$O(^C0CRXN(176.002,"ASAA","RXNORM","NDC",NDC,"")) Q ^(IEN)
    247287        ;
    248 NDC2RXNT ; @TEST - Test Get RxCUI given the NDC
     288NDC2RXNT        ; @TEST - Test Get RxCUI given the NDC
    249289        D CHKEQ^XTMUNIT($$NDC2RXN("30142-0917-71"),198439,"$$NDC2RXN failed")
    250290        QUIT
     
    252292        ; ---
    253293        ;
    254 ISBRAND(RXN) ; $$ Public - Is this RxCUI for a brand drug?
     294ISBRAND(RXN)    ; $$ Public - Is this RxCUI for a brand drug?
    255295        ; Input: RxCUI
    256296        ; Output: 0 or 1
    257297        Q ''$D(^C0CRXN(176.001,"STC","RXNORM","SBD",RXN))
    258 ISBRANDT ; @TEST - Test Is this RxCUI for a brand drug?
     298ISBRANDT        ; @TEST - Test Is this RxCUI for a brand drug?
    259299        D CHKEQ^XTMUNIT($$ISBRAND(205535),1,"$$ISBRAND failed") ; Brand Prozac
    260300        D CHKEQ^XTMUNIT($$ISBRAND(310384),0,"$$ISBRAND failed") ; Generic Fluoxetine
     
    263303        ; ---
    264304        ;
    265 BR2GEN(RXN) ; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
     305BR2GEN(RXN)     ; $$ Public - Convert Brand RxCUI to Generic RxCUI (many to 1)
    266306        ; Input: RxCUI of Brand
    267307        ; Output: RxCUI of Generic
    268308        Q $O(^C0CRXN(176.005,"B",RXN,"has_tradename",""))
    269 BR2GENT ; @TEST - Test Convert Brand RxCUI to Generic RxCUI (many to 1)
     309BR2GENT ; @TEST - Test Convert Brand RxCUI to Generic RxCUI (many to 1)
    270310        D CHKEQ^XTMUNIT($$BR2GEN(205535),310384,"$$BR2GEN failed")
    271311        QUIT
     
    273313        ; ---
    274314        ;
    275 GEN2BR(RXN) ; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
     315GEN2BR(RXN)     ; $$ Public - Convert Generic RxCUI to Brand RxCUIs (1 to many).
    276316        N RTN S RTN="" ; Return
    277317        N I S I="" F  S I=$O(^C0CRXN(176.005,"B",RXN,"tradename_of",I)) Q:'I  S RTN=RTN_I_U
     
    279319        Q RTN
    280320        ;
    281 GEN2BRT ; @TEST - Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
     321GEN2BRT ; @TEST - Test Convert Generic RxCUI to Brand RxCUIs (1 to many).
    282322        D CHKTF^XTMUNIT($$GEN2BR(310384)[205535,"$$GEN2BR failed")
    283323        QUIT
     
    285325        ; ---
    286326        ;
    287 RXN2BNS(RXN) ; $$ Public - Get all Brand Names associated with an RXN
     327RXN2BNS(RXN)    ; $$ Public - Get all Brand Names associated with an RXN
    288328        N BNS S BNS=""
    289329        I $$ISBRAND(RXN) S RXN=$$BR2GEN(RXN)
     
    297337        . S BNS=BNS_$P(^C0CRXN(176.001,BNIEN,0),U,15)_U
    298338        QUIT $E(BNS,1,$L(BNS)-1)
    299 RXN2BNST ; @TEST - Test Get all Brand Names associated with an RXN
     339RXN2BNST        ; @TEST - Test Get all Brand Names associated with an RXN
    300340        D CHKTF^XTMUNIT($$RXN2BNS(205535)["Prozac","$$RXN2BNS failed")
    301341        QUIT
     342        ;
     343        ; ---
     344        ;
     345RXN2NDC(RXN)    ; Get NDC codes for RxNorm code
     346        N NDCS S NDCS=""
     347        N I F I=0:0 S I=$O(^C0CRXN(176.002,"ASAR","RXNORM","NDC",RXN,I)) Q:'I  S NDCS=NDCS_^(I)_"^"
     348        S $E(NDCS,$L(NDCS))=""
     349        QUIT NDCS
     350RXN2NDCT        ; @TEST - Test Get NDC codes for RxNorm code
     351        D CHKTF^XTMUNIT($$RXN2NDC(197379)["^"_16714003309,"$$RXN2NDC failed")
     352        QUIT
  • ccr/trunk/rxnorm/trunk/routines/C0CRXNRD.m

    r1615 r1630  
    1 C0CRXNRD        ; 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
     1C0CRXNRD        ; VEN/SMH - RxNorm Utilities: Routine to Read RxNorm files;2013-11-14  1:23 PM
     2        ;;2.2;RXNORM FOR VISTA;;Nov 14, 2013;Build 8
    33        ; (C) Sam Habiel 2013
    44        ; See license for terms of use.
    55        ;
    66        W "No entry from top" Q
    7 IMPORT(PATH) ; PUBLIC ENTRY POINT. Rest are private
     7IMPORT(PATH,RESTRICTED) ; PUBLIC ENTRY POINT. Rest are private
    88        I PATH="" QUIT
     9        S RESTRICTED=$G(RESTRICTED,0)
    910        S U="^"
    1011        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 SABS
     13        D SAB(PATH,.SABS) ; Load restriction values into SAB.     ; 176.006
     14        D CONSO(PATH,.SABS,RESTRICTED),SAT(PATH,.SABS,RESTRICTED) ; 176.001,176.002
     15        D STY(PATH),REL(PATH),DOC(PATH)                           ; 176.003-5
    1216        N ENDTIME S ENDTIME=$P($H,",")*24*60*60+$P($H,",",2)
    1317        W !,(ENDTIME-STARTTIME)/60_" minutes elapsed"
     
    2529        QUIT
    2630GETLINES(PATH,FILENAME) ; Get number of lines in a file
     31        N POP
    2732        D OPEN^%ZISH("FILE",PATH,FILENAME,"R")
     33        Q:POP
    2834        U IO
    2935        N I,LINE
     
    3137        D CLOSE^%ZISH("FILE")
    3238        Q I-1
    33 CONSO(PATH,INCRES)      ; Open and read concepts file: RXNCONSO.RRF
     39CONSO(PATH,SABS,RESTRICTED)     ; Open and read concepts file: RXNCONSO.RRF
    3440        ; PATH ByVal, path of RxNorm files
    35         ; INCRES ByVal, include restricted sources. 1 for yes, 0 for no
     41        ; SABS ByRef, arrays of SABS(SAB)=restriction level
     42        ; RESTRICTED ByVal, include restricted sources. 1 for yes, 0 for no
    3643        I PATH="" QUIT
    37         S INCRES=+$G(INCRES) ; if not passed, becomes zero.
    3844        N FILENAME S FILENAME="RXNCONSO.RRF"
    3945        D DELFILED(176.001) ; delete data
     
    4854        . IF $$STATUS^%ZISH QUIT
    4955        . I '(C0CCOUNT#1000) U $P W C0CCOUNT," of ",LINES," read ",! U IO ; update every 1000
     56        . ;
     57        . ; Deal with restriction level
     58        . N SAB S SAB=$P(LINE,"|",12)
     59        . I 'RESTRICTED,SABS(SAB) QUIT  ; If not include restricted, and SABS(SAB) is not zero, quit
     60        . ;
     61        . ; Save data
    5062        . 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
    5863EX      D CLOSE^%ZISH("FILE")
    5964        N DIK S DIK="^C0CRXN(176.001," D IXALL^DIK
     
    6166        ;
    6267        ;
    63 SAT(PATH)       ; Open and read Concept and Atom attributes: RXNSAT.RRF
     68SAT(PATH,SABS,RESTRICTED)       ; Open and read Concept and Atom attributes: RXNSAT.RRF
     69        ; PATH ByVal, path of RxNorm files
     70        ; SABS ByRef, arrays of SABS(SAB)=restriction level
     71        ; RESTRICTED ByVal, include restricted sources. 1 for yes, 0 for no
    6472        I PATH="" QUIT
    6573        N FILENAME S FILENAME="RXNSAT.RRF"
     
    8290        . S $P(LINE,"|",9)=RXCUI1
    8391        . ;
     92        . ; Deal with restricted sources
     93        . N SAB S SAB=$P(LINE,"|",10)
     94        . I 'RESTRICTED,SABS(SAB) QUIT  ; If not include restricted, and SABS(SAB) is not zero, quit
     95        . ;
    8496        . ; Save off
    8597        . S ^C0CRXN(176.002,C0CCOUNT,0)=$TR(LINE,"|^","^|")
     
    89101        ;
    90102        ;
    91 SAB(PATH)       ; Open the read RxNorm Sources file: RXNSAB.RRF
     103SAB(PATH,SABS)  ; Open the read RxNorm Sources file: RXNSAB.RRF
    92104        I PATH="" QUIT
    93105        N FILENAME S FILENAME="RXNSAB.RRF"
     
    109121EX3     D CLOSE^%ZISH("FILE")
    110122        N DIK S DIK="^C0CRXN(176.003," D IXALL^DIK
     123        N C0CI F C0CI=0:0 S C0CI=$O(^C0CRXN(176.003,C0CI)) Q:'C0CI  D
     124        . S SABS($$GET1^DIQ(176.003,C0CI,.01))=$$GET1^DIQ(176.003,C0CI,"SRL")
    111125        QUIT
    112126STY(PATH)       ; Open and read RxNorm Semantic types file: RXNSTY.RRF
Note: See TracChangeset for help on using the changeset viewer.