-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api-simple.mjs
More file actions
67 lines (55 loc) · 2.18 KB
/
Copy pathtest-api-simple.mjs
File metadata and controls
67 lines (55 loc) · 2.18 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
async function testClinicalTrialsAPI() {
console.log('\n=== Testing ClinicalTrials.gov API ===\n');
console.log('1. Searching for "lung cancer" trials...');
try {
const params = new URLSearchParams({
"query.cond": "lung cancer",
"filter.overallStatus": "RECRUITING",
pageSize: "5",
countTotal: "true",
format: "json",
});
const res = await fetch(
`https://clinicaltrials.gov/api/v2/studies?${params.toString()}`
);
if (!res.ok) {
throw new Error(`API error: ${res.status}`);
}
const data = await res.json();
console.log('✓ Found', data.totalCount, 'total trials');
console.log('✓ Retrieved', data.studies?.length || 0, 'studies in this batch');
if (data.studies && data.studies.length > 0) {
const study = data.studies[0];
const proto = study.protocolSection;
const id = proto?.identificationModule;
const elig = proto?.eligibilityModule;
console.log('\n2. First trial details:');
console.log(' NCT ID:', id?.nctId);
console.log(' Title:', id?.briefTitle?.substring(0, 60) + '...');
console.log(' Phase:', proto?.designModule?.phases?.join(', ') || 'N/A');
console.log(' Status:', proto?.statusModule?.overallStatus);
console.log(' Min age:', elig?.minimumAge);
console.log(' Max age:', elig?.maximumAge);
console.log(' Sex:', elig?.sex);
console.log(' Criteria length:', elig?.eligibilityCriteria?.length || 0, 'chars');
}
console.log('\n3. Testing geographic search (Toronto, 100km)...');
const geoParams = new URLSearchParams({
"query.cond": "lung cancer",
"filter.overallStatus": "RECRUITING",
"filter.geo": "distance(43.6532,-79.3832,100km)",
pageSize: "5",
format: "json",
});
const geoRes = await fetch(
`https://clinicaltrials.gov/api/v2/studies?${geoParams.toString()}`
);
const geoData = await geoRes.json();
console.log('✓ Found', geoData.totalCount, 'trials near Toronto (100km)');
console.log('\n✅ All API tests passed!\n');
} catch (err) {
console.error('❌ API test failed:', err.message);
process.exit(1);
}
}
testClinicalTrialsAPI();