Working with Drugs
Learn how to work with drug information in the system.
Overview
The drugs table contains all drugs in the system, including:
- Active and inactive drugs
- Prescribable and non-prescribable medications
- Brand name drugs
- Generic drugs
This tutorial will guide you through understanding the drug data structure and how to work with drug information effectively.
Drug ID Structure
All drugs in the system have two important identifiers:
drug_id: The unique identifier for the specific drug productclinical_drug_id: The identifier representing the clinical drug (ingredient, dose form, and strength combination)
Understanding the Relationship
The relationship between drug_id and clinical_drug_id depends on whether the drug is generic or brand:
- Generic drugs: For generic drugs, the
drug_idwill be the same as theclinical_drug_id - Brand name drugs: For brand name drugs, the
clinical_drug_idwill be different from thedrug_id
Important: Just because a brand drug has a
clinical_drug_iddoes not mean it necessarily has a generic alternative. The clinical drug ID represents the actual drug ingredient, dose form, and strength that is having a clinical effect on the body, regardless of whether the drug is brand or generic.
Using Clinical Drug ID for Mapping
Since all drugs (both brand and generic) have a clinical_drug_id, you should use this ID (not drug_id) when mapping to other parts of the knowledge graph, such as:
- Ingredient tables
- Clinical effect mappings
- Other downstream relationships
Example: When joining to ingredient tables, always use clinical_drug_id instead of drug_id.
Brand vs Generic Drugs
The system distinguishes between brand name drugs and generic drugs using the is_brand column.
Brand Name Drugs
For brand name drugs:
is_brand = true- The
brand_namecolumn will contain the single brand name - The
available_brand_namescolumn will beNULL
Generic/Non-Brand Drugs
For non-brand drugs:
is_brand = false- The
brand_namecolumn will beNULL - The
available_brand_namescolumn may contain a comma-separated list of available brand names (if any exist)
Linking Drugs to NDCs
When linking drugs to NDCs (National Drug Codes), the choice of identifier depends on your use case:
Using drug_id (Most Common)
Generally, linking is done with drug_id since an NDC can specifically represent a brand product versus a generic product. This approach gives you precise package-to-drug mappings and preserves the distinction between brand and generic products.
Using clinical_drug_id (Aggregation Use Cases)
If you want to know how many NDCs there are for a given drug regardless of whether it's brand or generic, you can link the two tables based on clinical_drug_id. This aggregates all NDCs (both brand and generic) that represent the same clinical drug.
Example: If you're analyzing market coverage or want to see all available package options for a specific clinical drug formulation, using clinical_drug_id will give you the complete picture across all manufacturers and brand/generic variations.
Dose Form and Route Information
Dose Form
Dose form information is available directly at the drug level in the drugs table. This provides convenient access to how the medication is formulated (e.g., tablet, capsule, injection).
Route Information
Route information (e.g., oral, intravenous, topical) is planned for inclusion at the drug level. However, RxNorm does not provide direct mappings to route information, so the system will need to:
- Join to other data sources (such as the FDA NDC Directory), or
- Create custom mappings
Route information will be added in a future update.
Ingredients
Ingredient Information at Drug Level
For convenience, ingredient information is included directly at the drug level. However, for detailed ingredient analysis, it's recommended to work with the dedicated ingredients table.
Handling Multiple Ingredients
Some "pack" type drugs can have multiple different ingredient identifiers. Currently, the system handles this by:
- Pipe-delimiting the ingredient IDs
- Pipe-delimiting the ingredient names
Note: For more information on packs and kits, see Working with drug product data.
Future updates will account for these multi-ingredient drugs differently, providing better structured access to pack and kit information.
Filtering Drugs
The drugs table includes helpful filters for common use cases:
Active Filter
The active column allows you to filter for only active drugs, excluding inactive or discontinued medications.
Prescribable Filter
The prescribable column allows you to filter for only prescribable medications, excluding non-prescribable items.
Note: These filters come directly from RxNorm and are renamed from their original column naming conventions for clarity.
Example Queries
-- Get only active, prescribable drugs
SELECT * FROM drugs
WHERE active = true AND prescribable = true;
-- Get all brand name drugs that are active
SELECT * FROM drugs
WHERE is_brand = true AND active = true;
Best Practices
- Always use
clinical_drug_idwhen joining to ingredient tables or other downstream relationships - Use
drug_idwhen linking to NDCs to preserve brand vs. generic distinctions, or when you need to identify the specific drug product - Use
clinical_drug_idwhen linking to NDCs if you want to aggregate across all brand and generic variations of a clinical drug - Check
is_brandto understand whether you're working with a brand or generic drug - Use
activeandprescribablefilters to narrow your results to relevant medications - For detailed ingredient analysis, join to the
ingredientstable rather than relying solely on drug-level ingredient fields - Be aware of pipe-delimited values in ingredient fields for pack/kit drugs
Working with drug data doesn't have to be complicated. Put this guide to use with the CodeRx Drug Database—get instant access to comprehensive drug information, complete RxNorm mappings, and all the relationships you need to build powerful applications. With weekly updates and standardized identifiers, you can focus on building your solution instead of wrestling with data complexity. Start your 30-day free trial today and experience how easy drug data can be.