Download mcp/openfda.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 961 Bytes
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/93e7f22c8a06d6500b8b952902a1d54af6dd3307/mcp/openfda.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@93e7f22c8a06d6500b8b952902a1d54af6dd3307/mcp/openfda.py
-
curl -L -o openfda.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/93e7f22c8a06d6500b8b952902a1d54af6dd3307/mcp/openfda.py
961 Bytes
| # 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 [] | |