-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 60c2387
Showing
5 changed files
with
451 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
clinicaltrialsapi.straive.app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright 2024 Anand S | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
const BASE = "https://clinicaltrials.gov/api/v2"; | ||
|
||
async function run(path, params = {}) { | ||
const url = `${BASE}${path}${params ? `?${new URLSearchParams(params)}` : ""}`; | ||
const res = await fetch(url); | ||
if (!res.ok) throw new Error(`API Error ${res.status}: ${await res.text()}`); | ||
return res.json(); | ||
} | ||
|
||
function addFields(params) { | ||
if (!params.fields) params.fields = []; | ||
for (const module of ["identificationModule", "statusModule"]) { | ||
const field = `protocolSection.${module}`; | ||
if (!params.fields.includes(field)) params.fields.push(field); | ||
} | ||
return params; | ||
} | ||
|
||
export const api = { | ||
studies: (params) => run("/studies", { pageSize: 10, ...addFields(params) }), | ||
study: ({ nctId }) => run(`/studies/${nctId}`), | ||
studiesMetadata: () => run("/studies/metadata"), | ||
studiesSearchAreas: () => run("/studies/search-areas"), | ||
studiesEnums: () => run("/studies/enums"), | ||
statsSize: (params) => run("/stats/size", params), | ||
statsFieldValues: (params) => run("/stats/field/values", params), | ||
statsFieldSizes: (params) => run("/stats/field/sizes", params), | ||
}; | ||
|
||
export const tools = { | ||
studies: { | ||
name: "studies", | ||
description: "Search clinical trials with filters. Use AND, OR, NOT, and parentheses for grouping.", | ||
parameters: { | ||
type: "object", | ||
required: ["fields"], | ||
properties: { | ||
"query.cond": { type: "string", description: "Search for condition or disease" }, | ||
"query.term": { | ||
type: "string", | ||
description: "Search other terms like age, phase, design, sponsor, keyword, etc.", | ||
}, | ||
"query.locn": { type: "string", description: "Search for location (country, state, city, facility)" }, | ||
"query.titles": { type: "string", description: "Search in title" }, | ||
"query.intr": { type: "string", description: "Search in interventions, Arm Groups" }, | ||
"query.outc": { type: "string", description: "Search in outcome measures" }, | ||
"query.spons": { type: "string", description: "Search sponsors / collaborators" }, | ||
// "query.lead": { type: "string", description: 'Searches "LeadSponsorName" field' }, | ||
// "query.id": { type: "string", description: "Study IDs query" }, | ||
"query.patient": { type: "string", description: "Search all patient details" }, | ||
"filter.overallStatus": { | ||
type: "array", | ||
items: { type: "string" }, | ||
description: | ||
"Can be ACTIVE_NOT_RECRUITING, COMPLETED, ENROLLING_BY_INVITATION, NOT_YET_RECRUITING, RECRUITING, SUSPENDED, TERMINATED, WITHDRAWN, AVAILABLE, NO_LONGER_AVAILABLE, TEMPORARILY_NOT_AVAILABLE, APPROVED_FOR_MARKETING, WITHHELD, UNKNOWN", | ||
}, | ||
// "filter.geo": { type: "string", description: "Geo-function filter. Format: distance(lat, long, dist)" }, | ||
// "filter.ids": { | ||
// type: "array", | ||
// items: { type: "string" }, | ||
// description: "List of NCT IDs", | ||
// }, | ||
// "filter.advanced": { type: "string", description: "Essie expression filter. Examples: AREA[StartDate]2022" }, | ||
// "filter.synonyms": { | ||
// type: "array", | ||
// items: { type: "string" }, | ||
// description: "Comma- or pipe-separated area:synonym_id pairs", | ||
// }, | ||
// "postFilter.overallStatus": { | ||
// type: "array", | ||
// items: { type: "string" }, | ||
// description: "Status filter. Examples: NOT_YET_RECRUITING, RECRUITING", | ||
// }, | ||
// "postFilter.geo": { | ||
// type: "string", | ||
// description: "Geo-function filter. Examples: distance(39.0035707,-77.1013313,50mi)", | ||
// }, | ||
// "postFilter.ids": { | ||
// type: "array", | ||
// items: { type: "string" }, | ||
// description: "NCT ID filter. Examples: [ NCT04852770, NCT01728545 ]", | ||
// }, | ||
// "postFilter.advanced": { | ||
// type: "string", | ||
// description: "Essie expression filter. Examples: AREA[StartDate]2022", | ||
// }, | ||
// "postFilter.synonyms": { | ||
// type: "array", | ||
// items: { type: "string" }, | ||
// description: "Area:synonym_id pairs filter", | ||
// }, | ||
// aggFilters: { type: "string", description: "Aggregation filter. Format: filter_id:option keys" }, | ||
// geoDecay: { | ||
// type: "string", | ||
// description: "Proximity factor for geo-filtering. Examples: func:linear,scale:100km", | ||
// }, | ||
fields: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
enum: [ | ||
"protocolSection.identificationModule", | ||
"protocolSection.statusModule", | ||
"protocolSection.sponsorCollaboratorsModule", | ||
"protocolSection.oversightModule", | ||
"protocolSection.descriptionModule", | ||
"protocolSection.designModule", | ||
"protocolSection.eligibilityModule", | ||
"protocolSection.ipdSharingStatementModule", | ||
], | ||
}, | ||
description: "Pick ALL modules relevant to answering the question", | ||
}, | ||
sort: { | ||
type: "array", | ||
items: { type: "string" }, | ||
maxItems: 2, | ||
description: "Sorting options. Examples: @relevance, LastUpdatePostDate, EnrollmentCount:desc, NumArmGroups", | ||
}, | ||
// countTotal: { type: "boolean", description: "Returns totalCount with the first page if true" }, | ||
// page: { | ||
// type: "integer", | ||
// description: "Page number for pagination", | ||
// default: 1, | ||
// }, | ||
// pageSize: { | ||
// type: "integer", | ||
// description: "Results per page (max 1000)", | ||
// default: 1000, | ||
// }, | ||
// fields: { | ||
// type: "array", | ||
// items: { type: "string" }, | ||
// description: "Specific fields to return in the response", | ||
// }, | ||
}, | ||
}, | ||
}, | ||
study: { | ||
name: "study", | ||
description: "Get a single study by NCT ID", | ||
parameters: { | ||
type: "object", | ||
properties: { | ||
nctId: { type: "string", description: "NCT ID" }, | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Clinical Trials API Agent</title> | ||
<link rel="icon" href="https://raw.githubusercontent.com/gramener/assets/main/straive-favicon.svg"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"> | ||
<style> | ||
.narrative { | ||
max-width: 40rem; | ||
} | ||
|
||
.pre-wrap { | ||
white-space: pre-wrap; | ||
} | ||
|
||
#summary details { | ||
margin-bottom: 1.5rem; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
|
||
<nav class="navbar navbar-expand-lg bg-body-tertiary" data-bs-theme="dark"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand" href=".">Clinical Trials API Agent</a> | ||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
<div class="nav-item dropdown ms-auto" role="group" aria-label="Toggle dark mode" title="Toggle Dark Mode"> | ||
<button class="dark-theme-toggle btn btn-outline-light dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" aria-label="Toggle theme (auto)"> | ||
<i class="bi bi-circle-half"></i> <span class="d-lg-none ms-2">Toggle theme</span> | ||
</button> | ||
<ul class="dropdown-menu dropdown-menu-end"> | ||
<li><button class="dropdown-item" data-bs-theme-value="light"><i class="me-2 bi bi-sun-fill"></i> Light</button></li> | ||
<li><button class="dropdown-item" data-bs-theme-value="dark"><i class="me-2 bi bi-moon-stars-fill"></i> Dark</button></li> | ||
<li><button class="dropdown-item" data-bs-theme-value="auto"><i class="me-2 bi bi-circle-half"></i> Auto</button></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<div class="container"> | ||
<h1 class="display-1 my-4 text-center">Clinical Trials API Agent</h1> | ||
<h2 class="display-6 text-center">Answer questions from the <a href="https://www.clinicaltrials.gov/data-api/api">ClinicalTrials.gov API</a></h2> | ||
<div class="mx-auto my-3 narrative"> | ||
<p>This application is designed for the Clinical Trials API Agent, allowing users to answer questions based on the <a href="https://www.clinicaltrials.gov/data-api/api">ClinicalTrials.gov API</a>.</p> | ||
<p>Enter a question below. The agent will:</p> | ||
<ul> | ||
<li>Convert the question into a structured query</li> | ||
<li>Fetch the relevant studies from the ClinicalTrials.gov API</li> | ||
<li>Show the summary of these studies</li> | ||
<li>Create a plan to answer the question using the data</li> | ||
<li>Present a final answer, citing studies to support the answer</li> | ||
</ul> | ||
</div> | ||
|
||
<form id="query-form" class="d-flex gap-2"> | ||
<div class="flex-grow-1"> | ||
<input type="text" class="form-control" id="query" placeholder="Enter your question here" aria-label="Question" list="sample-questions"> | ||
<datalist id="sample-questions"> | ||
<option value="What are inclusion-exclusion criteria for a diabetes trial on 65+ patients?"> | ||
<option value="What are primary and secondary outcomes for breast cancer patients?"> | ||
<option value="Which interventions are being tested in 50+ Alzheimer's patients?"> | ||
<option value="What are the eligibility criteria for pediatric asthma trials?"> | ||
<option value="What is the average duration of depression medications trials?"> | ||
</datalist> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</form> | ||
|
||
<div id="search-params" class="my-3 table-responsive"></div> | ||
<div id="error" class="narrative mx-auto my-5"></div> | ||
<div id="summary" class="narrative mx-auto my-5"></div> | ||
</div> | ||
|
||
<div class="container-fluid"> | ||
<div id="search-documents" class="my-3 table-responsive"></div> | ||
</div> | ||
|
||
<footer class="my-5 vh-100 d-flex align-items-center justify-content-center"> | ||
<h1 class="display-4">Designed by <a href="https://gramener.com/" class="text-reset link-offset-3 link-underline link-underline-opacity-25">Gramener</a></h1> | ||
</footer> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" type="module"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@gramex/[email protected]/dist/dark-theme.js" type="module"></script> | ||
<script src="script.js" type="module"></script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.