-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-parser-comparison.mjs
More file actions
153 lines (125 loc) · 4.64 KB
/
Copy pathtest-parser-comparison.mjs
File metadata and controls
153 lines (125 loc) · 4.64 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { parseCriteriaText } from './src/lib/criteria-parser.ts';
import { writeFileSync } from 'fs';
async function fetchAndParseTrial(condition) {
const params = new URLSearchParams({
"query.cond": condition,
"filter.overallStatus": "RECRUITING",
pageSize: "1",
format: "json",
});
const res = await fetch(
`https://clinicaltrials.gov/api/v2/studies?${params.toString()}`
);
const data = await res.json();
if (!data.studies || data.studies.length === 0) {
return null;
}
const trial = data.studies[0];
const proto = trial.protocolSection;
return {
nctId: proto?.identificationModule?.nctId,
title: proto?.identificationModule?.briefTitle,
condition: condition,
phase: proto?.designModule?.phases?.join(', ') || 'N/A',
sponsor: proto?.sponsorCollaboratorsModule?.leadSponsor?.name,
criteriaText: proto?.eligibilityModule?.eligibilityCriteria,
minAge: proto?.eligibilityModule?.minimumAge,
maxAge: proto?.eligibilityModule?.maximumAge,
sex: proto?.eligibilityModule?.sex,
};
}
async function main() {
console.log('\n=== Comparing Criteria Parser Across Cancer Types ===\n');
const conditions = [
'breast cancer',
'pancreatic cancer',
'melanoma'
];
const results = [];
for (const condition of conditions) {
console.log(`Fetching trial for: ${condition}...`);
const trial = await fetchAndParseTrial(condition);
if (!trial) {
console.log(` ❌ No trials found for ${condition}`);
continue;
}
console.log(` ✓ Found: ${trial.nctId}`);
const parsed = parseCriteriaText(trial.criteriaText || '');
const inclusions = parsed.filter(c => c.type === 'inclusion');
const exclusions = parsed.filter(c => c.type === 'exclusion');
results.push({
trial,
parsed,
inclusions,
exclusions,
});
console.log(` ✓ Parsed: ${parsed.length} criteria (${inclusions.length} inc, ${exclusions.length} exc)`);
}
// Generate markdown report
let report = '# Criteria Parser - Cancer Type Comparison\n\n';
report += `**Generated:** ${new Date().toISOString()}\n\n`;
report += `**Purpose:** Verify the criteria parser works correctly across different cancer types\n\n`;
report += `**Cost:** $0 (no LLM calls)\n\n`;
report += '---\n\n';
results.forEach(({ trial, parsed, inclusions, exclusions }, index) => {
report += `## ${index + 1}. ${trial.condition.toUpperCase()}\n\n`;
report += `**Trial:** [${trial.nctId}](https://clinicaltrials.gov/study/${trial.nctId})\n\n`;
report += `**Title:** ${trial.title}\n\n`;
report += `**Phase:** ${trial.phase}\n\n`;
report += `**Sponsor:** ${trial.sponsor}\n\n`;
report += `**Demographics:**\n`;
report += `- Age: ${trial.minAge || 'N/A'} to ${trial.maxAge || 'N/A'}\n`;
report += `- Sex: ${trial.sex}\n\n`;
report += `**Parsed Criteria:** ${parsed.length} total (${inclusions.length} inclusion, ${exclusions.length} exclusion)\n\n`;
report += `### Inclusion Criteria (${inclusions.length})\n\n`;
inclusions.forEach(c => {
report += `**[${c.id}]** ${c.rawText}\n\n`;
});
report += `### Exclusion Criteria (${exclusions.length})\n\n`;
exclusions.forEach(c => {
report += `**[${c.id}]** ${c.rawText}\n\n`;
});
report += '---\n\n';
});
// Add statistics
report += '## Parser Statistics\n\n';
report += '| Cancer Type | Trial ID | Total Criteria | Inclusions | Exclusions |\n';
report += '|-------------|----------|----------------|------------|------------|\n';
results.forEach(({ trial, parsed, inclusions, exclusions }) => {
report += `| ${trial.condition} | ${trial.nctId} | ${parsed.length} | ${inclusions.length} | ${exclusions.length} |\n`;
});
report += '\n## Validation\n\n';
let allValid = true;
results.forEach(({ trial, parsed }) => {
const ids = new Set();
let hasDuplicates = false;
parsed.forEach(c => {
if (ids.has(c.id)) {
hasDuplicates = true;
allValid = false;
}
ids.add(c.id);
});
if (hasDuplicates) {
report += `- ❌ ${trial.nctId}: Duplicate IDs found\n`;
} else {
report += `- ✅ ${trial.nctId}: All IDs unique\n`;
}
});
if (allValid) {
report += '\n**Overall:** ✅ All validations passed\n';
}
// Save to file
const filename = 'PARSER_COMPARISON.md';
writeFileSync(filename, report);
console.log(`\n✅ Report generated: ${filename}`);
console.log(`\nSummary:`);
results.forEach(({ trial, parsed }) => {
console.log(` ${trial.condition}: ${parsed.length} criteria parsed`);
});
console.log('\n');
}
main().catch(err => {
console.error('❌ Error:', err);
process.exit(1);
});