-
Notifications
You must be signed in to change notification settings - Fork 0
OpenFDA_Client
A Python client for querying adverse events from the FDA Adverse Event Reporting System (FAERS) database.
Drug interaction checking benefits from real-world adverse event data to provide additional safety context:
- How often do patients take these drugs together in practice?
- What adverse reactions are commonly reported with this combination?
- Are there patterns of serious events worth noting?
This complements interaction databases by adding post-market surveillance data that reflects actual patient experiences.
Normalized drug ingredient names from RxNorm:
- Generic names: "warfarin", "aspirin"
- Standardized forms: "acetaminophen", "ibuprofen"
- Must be at least 2 drugs for combination analysis
- Query FAERS database for reports containing all specified drugs
- PubChem synonym fallback when no reports found
- Aggregate statistics from matching adverse event reports
- Extract common reaction patterns and severity indicators
- Email notifications for failed adverse event lookups
- Return structured summary for clinical context
- When: Automatic fallback when no FAERS reports found with original drug names
- Process: Retrieves up to 3 synonyms per drug, tests all combinations
- Purpose: Finds adverse event reports using alternative drug names when standardized names don't match FAERS data
For more details about PubChem integration, refer to the PubChem section.
Success (reports found):
{
"adverse_events": {
"drugs": ["warfarin", "aspirin"],
"n_reports": 584860,
"sample_size": 100
}
}
No Reports Found:
{
"drugs": ["drug1", "drug2"],
"n_reports": 0,
"reason": "No reports found after synonym search"
}
from src.clients.openfda import get_adverse_event_context_safe
context = await get_adverse_event_context_safe(ingredient_names)
adverse_events = context["adverse_events"] # Function returns wrapped dict
if adverse_events['n_reports'] > 0:
print(f"Found {adverse_events['n_reports']} reports")
print(f"Common reactions: {adverse_events['top_reactions']}")
else:
print("No adverse events reported for this combination")
Two interfaces available:
-
get_adverse_event_context()
: RaisesOpenFDAError
on API failures -
get_adverse_event_context_safe()
: Never raises exceptions, returns empty data structure
Default settings:
- 30 second timeout for slow OpenFDA responses
- 3 retries with exponential backoff
- 100 report limit for statistical sampling
- Provider: U.S. Food and Drug Administration
- Cost: Free
- Rate Limits: About 240 requests/min without API key; higher with key
- Registration: Optional (API key recommended for production use)
-
Base URL:
https://api.fda.gov/drug/event.json
- Coverage: Adverse event reports from 2004-present
- Update Frequency: Quarterly releases
- Data Lag: May lag 3+ months behind current date
- Report Types: Voluntary submissions from healthcare professionals, consumers, and manufacturers
Uses patient.drug.medicinalproduct
field with AND logic:
patient.drug.medicinalproduct:"warfarin"+patient.drug.medicinalproduct:"aspirin"
-
Association ≠ causation
Example: A patient on aspirin + warfarin has a GI bleed. The report links the drugs and the event, but the bleed might stem from an ulcer or alcohol use.
-
Polypharmacy & confounders
Example: A case listing acetaminophen, aspirin, hydrocodone, and ruxolitinib shows low platelets. It’s impossible to tell which drug—or the underlying disease—was responsible.
-
Unclear timing & dosing
Example: A report lists aspirin and acetaminophen, but doesn’t say if they were taken together or weeks apart.
-
No denominator for risk
Example: 100 liver injury reports for acetaminophen could mean “100 out of millions” (rare) or “100 out of hundreds” (common). The database doesn’t provide exposure numbers.
-
Biased & incomplete reporting
Example: Mild headaches from aspirin rarely get reported, but severe GI bleeds almost always do—skewing the data toward serious outcomes.
# Complete workflow: RxNorm → DDInter → OpenFDA
normalized_drugs = [await normalize_drug_safe(drug) for drug in user_drugs]
ingredient_names = [drug["in"] for drug in normalized_drugs]
# Get interaction data
interactions = await check_drug_interactions(ingredient_names)
# Get adverse event context
adverse_events = await get_adverse_event_context_safe(ingredient_names)