Update mcp/ctgov.py
Browse files- mcp/ctgov.py +18 -10
mcp/ctgov.py
CHANGED
|
@@ -1,13 +1,21 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
_BASE = "https://clinicaltrials.gov/api/v2/studies"
|
| 4 |
|
| 5 |
-
async def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ClinicalTrials.gov v2 async helper.
|
| 2 |
+
Docs: https://clinicaltrials.gov/api/gui/ref/api_urls#v2
|
| 3 |
+
Provides `search_trials_v2` which returns a list of study dicts.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import httpx, asyncio
|
| 7 |
+
from typing import List, Dict
|
| 8 |
|
| 9 |
_BASE = "https://clinicaltrials.gov/api/v2/studies"
|
| 10 |
|
| 11 |
+
async def search_trials_v2(query: str, *, max_n: int = 20) -> List[Dict]:
|
| 12 |
+
"""Search CT.gov v2 endpoint and return list of studies."""
|
| 13 |
+
params = {
|
| 14 |
+
"query": query,
|
| 15 |
+
"pageSize": max_n,
|
| 16 |
+
"fields": "nctId,briefTitle,phase,status,startDate,conditions,interventions",
|
| 17 |
+
}
|
| 18 |
+
async with httpx.AsyncClient(timeout=15) as client:
|
| 19 |
+
resp = await client.get(_BASE, params=params)
|
| 20 |
+
resp.raise_for_status()
|
| 21 |
+
return resp.json().get("studies", [])
|