File size: 961 Bytes
29102f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# mcp/openfda.py
import httpx
OPENFDA_DRUG_EVENT = "https://api.fda.gov/drug/event.json"
async def fetch_drug_safety(drug: str, max_results: int = 3):
"""Fetch recent adverse event reports for the drug from OpenFDA."""
params = {"search": f'patient.drug.medicinalproduct:"{drug}"', "limit": max_results}
async with httpx.AsyncClient() as client:
try:
resp = await client.get(OPENFDA_DRUG_EVENT, params=params)
results = resp.json().get("results", [])
output = []
for ev in results:
output.append({
"safety_report_id": ev.get("safetyreportid"),
"serious": ev.get("serious"),
"reactions": [r["reactionmeddrapt"] for r in ev.get("patient", {}).get("reaction", [])],
"receivedate": ev.get("receivedate"),
})
return output
except Exception:
return []
|