Create clinicaltrials.py
Browse files- mcp/clinicaltrials.py +23 -0
mcp/clinicaltrials.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# mcp/clinicaltrials.py
|
2 |
+
"""
|
3 |
+
ClinicalTrials.gov helper – fetch recent trials for a keyword.
|
4 |
+
"""
|
5 |
+
|
6 |
+
import httpx, datetime
|
7 |
+
from typing import List
|
8 |
+
|
9 |
+
BASE = "https://clinicaltrials.gov/api/query/study_fields"
|
10 |
+
|
11 |
+
async def search_trials(term: str, max_studies: int = 10) -> List[dict]:
|
12 |
+
today = datetime.date.today().isoformat()
|
13 |
+
params = {
|
14 |
+
"expr": term,
|
15 |
+
"fields": "NCTId,BriefTitle,Condition,InterventionName,Phase,OverallStatus,StartDate",
|
16 |
+
"max_rnk": max_studies,
|
17 |
+
"fmt": "json",
|
18 |
+
"min_rnk": 1
|
19 |
+
}
|
20 |
+
async with httpx.AsyncClient(timeout=20) as client:
|
21 |
+
r = await client.get(BASE, params=params)
|
22 |
+
r.raise_for_status()
|
23 |
+
return r.json()["StudyFieldsResponse"]["StudyFields"]
|