-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathebm.html
More file actions
703 lines (641 loc) · 34.6 KB
/
Copy pathebm.html
File metadata and controls
703 lines (641 loc) · 34.6 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vibe Rounds - EBM Query Generator — Case → Critical Appraisal Queries</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
:root{
--paper:#F7FAFB;
--card:#FFFFFF;
--ink:#0B2530;
--line:#DCE7EA;
--line-soft:#E9F1F3;
--accent:#0891B2;
--accent-dark:#0A6E85;
--accent-soft:#E3F4F8;
--alert:#C2410C;
--alert-soft:#FCE9DD;
--muted:#5B7480;
--tab-inactive:#EEF4F6;
--radius:10px;
--body-font:'Inter',sans-serif;
}
html{transition:background .15s ease;}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
background:var(--paper);
color:var(--ink);
font-family:var(--body-font);
font-size:15px;
line-height:1.5;
-webkit-font-smoothing:antialiased;
}
::selection{background:var(--accent-soft);}
a{color:var(--accent-dark);}
.wrap{max-width:960px;margin:0 auto;padding:28px 20px 80px;}
header.top{
display:flex;align-items:center;justify-content:space-between;
padding-bottom:18px;margin-bottom:28px;
flex-wrap:wrap;gap:10px;
}
header.top .brand{display:flex;align-items:center;gap:10px;}
header.top h1{
font-family:var(--body-font);font-weight:800;
font-size:24px;margin:0;letter-spacing:-0.02em;color:var(--ink);
}
header.top .rx{
font-family:var(--body-font);font-weight:600;font-size:11.5px;color:#fff;
background:var(--accent);border-radius:20px;padding:4px 11px;
letter-spacing:.01em;
}
header.top .tagline{font-size:12.5px;color:var(--muted);font-family:var(--body-font);font-weight:500;}
header.top .top-right{display:flex;flex-direction:column;align-items:flex-end;gap:8px;}
.top-links{display:flex;gap:8px;font-family:var(--body-font);flex-wrap:wrap;justify-content:flex-end;}
.top-links a{
display:inline-flex;align-items:center;gap:5px;
font-size:12.5px;font-weight:700;color:var(--accent-dark);
background:var(--accent-soft);border:1px solid var(--line);
border-radius:999px;padding:6px 13px;text-decoration:none;
}
.top-links a:hover{background:var(--accent);color:#fff;border-color:var(--accent);}
.step{margin-bottom:20px;}
.step-label{
font-family:var(--body-font);font-size:12.5px;letter-spacing:.08em;
text-transform:uppercase;color:var(--ink);font-weight:700;
display:flex;align-items:center;gap:10px;margin-bottom:0;
background:var(--card);border:1px solid var(--line);border-radius:var(--radius) var(--radius) 0 0;
padding:14px 20px;transition:box-shadow .15s ease,border-color .15s ease,color .15s ease;
}
.step-label.collapsed{border-radius:var(--radius);}
.step-label .num{
width:24px;height:24px;border-radius:50%;background:var(--accent);color:#fff;
display:inline-flex;align-items:center;justify-content:center;font-size:12px;flex-shrink:0;font-weight:700;
}
.step-label.collapsible{cursor:pointer;user-select:none;}
.step-label.collapsible:hover{color:var(--accent-dark);box-shadow:0 6px 16px -10px rgba(11,37,48,.3);}
.collapse-arrow{font-size:11px;margin-left:auto;transition:transform .15s ease;color:var(--muted);padding-left:8px;}
.step-label.collapsed .collapse-arrow{transform:rotate(-90deg);}
.card.collapsed{display:none;}
.card{
background:var(--card);
border:1px solid var(--line);border-top:none;
border-radius:0 0 var(--radius) var(--radius);
padding:22px 22px 20px;
box-shadow:0 1px 2px rgba(11,37,48,.04), 0 8px 24px -16px rgba(11,37,48,.08);
}
textarea, input[type=text], input[type=password], select{
width:100%;
font-family:var(--body-font);
font-size:14px;
background:var(--card);
border:1px solid var(--line);
border-radius:var(--radius);
padding:9px 11px;
color:var(--ink);
}
textarea:focus, input:focus, select:focus, button:focus-visible{
outline:2px solid var(--accent);outline-offset:1px;
}
textarea{resize:vertical;min-height:90px;line-height:1.5;}
label{font-size:12.5px;color:var(--muted);display:block;margin-bottom:4px;font-weight:500;}
.hint{font-size:12px;color:var(--muted);margin-top:6px;}
.upload-row{margin-top:14px;padding-top:14px;border-top:1px dashed var(--line);}
.upload-row label{margin-bottom:6px;}
.upload-row input[type=file]{
width:100%;font-family:var(--body-font);font-size:12.5px;color:var(--muted);
border:1px dashed var(--line);border-radius:var(--radius);padding:8px 10px;background:var(--paper);
}
.upload-row input[type=file]::file-selector-button{
font-family:var(--body-font);font-weight:600;font-size:12px;color:#fff;
background:var(--accent);border:none;border-radius:999px;padding:6px 13px;margin-right:10px;cursor:pointer;
}
.tabrow{display:flex;gap:4px;background:var(--tab-inactive);padding:4px;border-radius:999px;margin-bottom:16px;width:fit-content;flex-wrap:wrap;}
.tabrow .tab{
font-family:var(--body-font);font-weight:600;font-size:12.5px;
padding:7px 16px;
background:transparent;
border:none;border-radius:999px;
cursor:pointer;color:var(--muted);
transition:background .12s,color .12s;
}
.tabrow .tab.active{
background:var(--accent);color:#fff;
}
.providerpane{padding:0;background:transparent;}
.providerpane .row{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:10px;}
@media(max-width:600px){.providerpane .row{grid-template-columns:1fr;}}
.key-status{font-size:12px;font-family:var(--body-font);font-weight:500;margin-top:8px;}
.key-status.ok{color:var(--accent-dark);}
.key-status.empty{color:var(--muted);}
details.settings summary{
cursor:pointer;font-size:12.5px;color:var(--accent-dark);font-weight:600;
list-style:none;display:flex;align-items:center;gap:6px;
}
details.settings summary::-webkit-details-marker{display:none;}
details.settings summary::before{content:"▸";font-size:10px;}
details.settings[open] summary::before{content:"▾";}
details.settings{margin-top:10px;}
.mode-hint{font-size:12.5px;color:var(--muted);margin:10px 0 12px;}
.checklist{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:10px;margin:14px 0;}
.qtype{
background:var(--card);border:1.5px solid var(--line);
border-radius:var(--radius);
padding:12px 13px;cursor:pointer;transition:border-color .12s,box-shadow .12s,transform .06s;
font-family:var(--body-font);
box-shadow:0 1px 2px rgba(11,37,48,.04);
display:flex;align-items:flex-start;gap:9px;
}
.qtype:hover{border-color:var(--accent);transform:translateY(-1px);box-shadow:0 6px 16px -8px rgba(8,145,178,.35);}
.qtype input{margin-top:3px;flex-shrink:0;}
.qtype .qname{font-weight:700;font-size:13.5px;color:var(--ink);}
.qtype .qdesc{font-size:11.5px;color:var(--muted);line-height:1.4;margin-top:2px;}
button{
font-family:var(--body-font);font-weight:700;font-size:13px;
background:var(--accent);color:#fff;border:none;
border-radius:999px;padding:10px 18px;cursor:pointer;
transition:background .12s, transform .06s;
}
button:hover{background:var(--accent-dark);}
button.secondary{background:transparent;color:var(--muted);border:1.5px solid var(--line);}
button.secondary:hover{background:var(--tab-inactive);color:var(--ink);border-color:var(--line);}
button:disabled{opacity:.5;cursor:not-allowed;}
.banner{
font-size:12.5px;color:var(--ink);border:1px solid var(--line-soft);
background:var(--accent-soft);padding:11px 14px;border-radius:var(--radius);margin-bottom:24px;
}
.banner strong{color:var(--accent-dark);}
.error-note{font-size:12.5px;color:var(--alert);background:var(--alert-soft);border:1px solid #f0c8ac;border-radius:var(--radius);padding:9px 12px;margin-bottom:10px;display:none;}
.error-note.show{display:block;}
.typing{font-family:var(--body-font);font-size:12px;color:var(--muted);font-weight:500;}
.typing::after{content:'';animation:dots 1.2s steps(4,end) infinite;}
@keyframes dots{0%{content:'';}25%{content:'.';}50%{content:'..';}75%{content:'...';}}
footer{margin-top:50px;font-size:11.5px;color:var(--muted);text-align:center;font-family:var(--body-font);font-weight:500;}
.legal-note{
margin-top:16px;
font-size:11.5px;color:var(--muted);text-align:center;
line-height:1.6;font-family:var(--body-font);
}
.legal-note em{font-style:italic;}
#workspace{margin-top:30px;}
.ws-header{
display:flex;justify-content:space-between;align-items:center;
padding-bottom:12px;margin-bottom:14px;flex-wrap:wrap;gap:10px;
}
.ws-header .wtitle{font-family:var(--body-font);font-size:18px;font-weight:800;color:var(--ink);}
.ws-header .wsub{font-size:12px;color:var(--muted);font-family:var(--body-font);font-weight:500;}
.ws-actions button{margin-left:8px;}
@media(max-width:600px){
header.top h1{font-size:20px;}
.ws-header{flex-direction:column;align-items:flex-start;gap:10px;}
.ws-actions{display:flex;flex-wrap:wrap;gap:8px;}
.ws-actions button{margin-left:0;}
}
.transcript{
border:1px solid var(--line);border-radius:var(--radius);
background:var(--card);
box-shadow:0 1px 2px rgba(11,37,48,.04), 0 8px 24px -16px rgba(11,37,48,.08);
min-height:120px;max-height:640px;overflow-y:auto;
padding:16px;margin-bottom:12px;
}
.empty-note{color:var(--muted);font-size:13.5px;font-style:italic;}
.result-card{
border:1px solid var(--line);border-left:4px solid var(--accent);
border-radius:8px;padding:14px 16px;margin-bottom:14px;background:var(--accent-soft);
}
.result-card h3{margin:0 0 6px;font-size:14px;color:var(--accent-dark);font-family:var(--body-font);}
.result-card .meta{font-size:11.5px;color:var(--muted);margin-bottom:8px;font-family:var(--body-font);}
.result-card pre{
white-space:pre-wrap;word-wrap:break-word;font-family:var(--body-font);
font-size:13.5px;margin:0;color:var(--ink);line-height:1.55;
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
.vr-suitebar{
background: linear-gradient(160deg, #EFF6FF 0%, #F0FDFA 65%);
border-bottom: 1px solid #E2E8F0;
padding: 12px 20px;
display: flex; align-items: center; justify-content: space-between;
flex-wrap: wrap; gap: 10px 16px;
}
.vr-suitebar .vr-brand{
font-family: 'DM Mono','IBM Plex Mono',monospace;
font-weight: 700; font-size: 14px; letter-spacing: -0.01em;
color: #0F172A; text-decoration: none; display:flex; align-items:center; gap:0;
}
.vr-suitebar .vr-brand span{ color: #0891B2; }
.vr-suitebar .vr-nav{ display:flex; gap:6px; flex-wrap:wrap; }
.vr-suitebar .vr-nav a{
font-family:'DM Mono','IBM Plex Mono',monospace; font-size:11px; letter-spacing:.04em; text-transform:uppercase;
color:#475569; text-decoration:none; padding:6px 10px; border-radius:999px;
border:1px solid #E2E8F0; background:#FFFFFF; transition:.15s ease;
}
.vr-suitebar .vr-nav a:hover{ color:#fff; background:#0891B2; border-color:#0891B2; }
.vr-suitebar .vr-nav a.active{ color:#fff; background:#0E7490; border-color:#0E7490; }
@media (max-width:640px){
.vr-suitebar{ padding:10px 14px; }
.vr-suitebar .vr-nav a{ padding:5px 8px; font-size:10px; }
}
</style>
</head>
<body>
<header class="vr-suitebar">
<a class="vr-brand" href="https://avi33tbtt.github.io/">Vibe<span>Rounds</span></a>
<nav class="vr-nav">
<a href="https://avi33tbtt.github.io/home.html">Home</a>
<a href="https://avi33tbtt.github.io/bench.html">Case Bench</a>
<a href="https://avi33tbtt.github.io/bench_lite.html">Bench Lite</a>
<a href="https://avi33tbtt.github.io/case-simulator.html">Case Simulator</a>
<a href="https://avi33tbtt.github.io/case-practice.html">Clinical Practice</a>
<a href="https://avi33tbtt.github.io/clinical-polemos.html">Clinical Polemos</a>
<a href="https://avi33tbtt.github.io/case-lens.html">Case Lens</a>
<a href="https://avi33tbtt.github.io/sdm-lens.html">SDM Lens</a>
<a href="https://avi33tbtt.github.io/ebm.html" class="active">EBM Query Generator</a>
<a href="https://avi33tbtt.github.io/ccos-builder.html">CCOS Builder</a>
</nav>
</header>
<div class="wrap">
<header class="top">
<div class="brand">
<h1>Vibe Rounds - EBM Query Generator</h1>
<span class="rx">Rx: questions, not answers</span>
</div>
<div class="top-right">
<div class="tagline">clinical reasoning aid · not for patient care</div>
<div class="top-links">
<a href="https://avi33tbtt.github.io/" target="_blank" rel="noopener">Project website</a>
<a href="https://avi33tbtt.github.io/ebm/" target="_blank" rel="noopener">EBM for Techies course</a>
<a href="https://www.linkedin.com/in/dravinashkumargupta/" target="_blank" rel="noopener">Dr. Avinash — LinkedIn</a>
</div>
</div>
</header>
<div class="banner"><strong>Educational use only.</strong> Companion module for the <a href="https://avi33tbtt.github.io/ebm/" target="_blank" rel="noopener">Evidence-Based Medicine for Techies course</a>, restructured in the Vibe Rounds module format. Load a de-identified case once, then generate a structured set of critical-appraisal queries — question type, study design, PICO(T), search string, and appraisal-checklist pointer — without answering the clinical question itself. Your API key is stored only in this browser's local storage and sent directly from your browser to your chosen provider — never through any server of ours.</div>
<!-- STEP 1: MODEL -->
<div class="step">
<div class="step-label collapsible" id="label-model"><span class="num">1</span>Model<span class="collapse-arrow" id="arrow-model">▾</span></div>
<div class="card" id="card-model">
<div class="tabrow" id="providerTabs">
<div class="tab active" data-provider="claude">Claude</div>
<div class="tab" data-provider="gemini">Gemini</div>
<div class="tab" data-provider="openai">ChatGPT</div>
<div class="tab" data-provider="other">Other</div>
</div>
<div class="providerpane">
<div class="row" id="endpointRow" style="display:none;">
<div style="grid-column:1/-1;">
<label for="apiEndpoint">API endpoint (OpenAI-compatible chat/completions URL)</label>
<input type="text" id="apiEndpoint" placeholder="https://api.groq.com/openai/v1/chat/completions">
</div>
</div>
<div class="row">
<div>
<label id="apiKeyLabel" for="apiKey">Claude API key</label>
<input type="password" id="apiKey" placeholder="sk-ant-...">
</div>
<div>
<label for="modelName">Model name</label>
<input type="text" id="modelName" placeholder="claude-sonnet-4-6">
</div>
</div>
<div class="key-status empty" id="keyStatus">No key saved for this provider yet.</div>
<details class="settings">
<summary>Where do I get a key?</summary>
<div class="hint" style="margin-top:8px;" id="keyHelp"></div>
</details>
</div>
</div>
</div>
<!-- STEP 2: CASE -->
<div class="step">
<div class="step-label collapsible" id="label-case"><span class="num">2</span>Case<span class="collapse-arrow" id="arrow-case">▾</span></div>
<div class="card" id="card-case">
<label for="caseText">Paste the de-identified case — vignette, SOAP summary, discharge letter</label>
<textarea id="caseText" placeholder="Paste case text here, e.g. '62-year-old woman with type 2 diabetes and hypertension presents with 3 months of exertional dyspnea...'"></textarea>
<div class="hint">Use only de-identified case data. <a href="#" id="sampleCaseBtn" style="font-weight:600;color:var(--accent-dark);text-decoration:none;">Try a sample case →</a></div>
<div class="upload-row">
<label for="caseFile">Or upload a case file — PDF, Word (.doc/.docx), or plain text (.txt), max 10MB</label>
<input type="file" id="caseFile" accept=".pdf,.doc,.docx,.txt">
<div class="hint" id="uploadStatus"></div>
</div>
</div>
</div>
<!-- STEP 3: GENERATE QUERIES -->
<div class="step">
<div class="step-label collapsible" id="label-queries"><span class="num">3</span>Generate EBM Queries<span class="collapse-arrow" id="arrow-queries">▾</span></div>
<div class="card" id="card-queries">
<div class="mode-hint">Choose the decision point(s) this case raises. Each becomes a separate query thread with its own question type, study design, PICO(T), search string, and appraisal-checklist pointer.</div>
<div class="checklist" id="questionTypeList">
<label class="qtype"><input type="checkbox" value="Therapy" checked><span><span class="qname">Therapy</span><br><span class="qdesc">Does a treatment/intervention work? → RCT, systematic review</span></span></label>
<label class="qtype"><input type="checkbox" value="Diagnosis"><span><span class="qname">Diagnosis</span><br><span class="qdesc">Can a test result be trusted? → cross-sectional vs. gold standard</span></span></label>
<label class="qtype"><input type="checkbox" value="Prognosis"><span><span class="qname">Prognosis</span><br><span class="qdesc">What's likely to happen over time? → cohort study</span></span></label>
<label class="qtype"><input type="checkbox" value="Harm"><span><span class="qname">Harm</span><br><span class="qdesc">Does an exposure/drug cause harm? → cohort or case-control</span></span></label>
<label class="qtype"><input type="checkbox" value="Cost-effectiveness"><span><span class="qname">Cost-effectiveness</span><br><span class="qdesc">Is it worth the money/resources? → economic evaluation</span></span></label>
<label class="qtype"><input type="checkbox" value="Guideline"><span><span class="qname">Guideline check</span><br><span class="qdesc">Should we follow a recommendation? → GRADE-based guideline</span></span></label>
</div>
<button class="secondary" id="selectAllTypesBtn">Select all question types</button>
<button id="runGenerateBtn" style="margin-top:14px;">▶ Generate queries</button>
</div>
</div>
<!-- STEP 4: CLOSURE / REVIEW -->
<div class="step">
<div class="step-label collapsible" id="label-closure"><span class="num">4</span>Closure / Review<span class="collapse-arrow" id="arrow-closure">▾</span></div>
<div class="card" id="card-closure">
<div class="mode-hint">Run after at least one query thread has produced output — these consolidate everything generated so far.</div>
<button id="stressTestBtn">▶ Stress-Test Queries</button>
<button id="patientPriorityBtn" style="margin-left:8px;">▶ Restate Patient Priority</button>
</div>
</div>
<!-- WORKSPACE / RESULTS -->
<div id="workspace">
<div class="ws-header">
<div>
<div class="wtitle">Results</div>
<div class="wsub">Every output requires independent clinical verification.</div>
</div>
<div class="ws-actions">
<button class="secondary" id="readAloudBtn">🔊 Read aloud</button>
<button class="secondary" id="stopReadBtn">⏹ Stop</button>
<button class="secondary" id="downloadBtn">Download .txt</button>
<button class="secondary" id="resetRunBtn">Reset run</button>
</div>
</div>
<div class="error-note" id="errorNote"></div>
<div class="transcript" id="resultsBody">
<p class="empty-note">No outputs yet — run a query generation or a Closure/Review step above to see results here.</p>
</div>
</div>
<div class="legal-note">
<em>"To be used on personal responsibility and only for learning. Not to be used for clinical purpose."</em><br>
<b>The LLM drafts. You verify every number and citation against the source.</b>
</div>
<footer>Vibe Rounds - EBM Query Generator · runs entirely in your browser · bring your own key ·
See <a href="https://avi33tbtt.github.io/">avi33tbtt.github.io</a> for the full module library.</footer>
</div>
<script>
const PROVIDERS = {
claude: {
label: 'Claude',
keyPlaceholder: 'sk-ant-...',
modelPlaceholder: 'claude-sonnet-4-6',
help: 'Create a key at <a href="https://console.anthropic.com/settings/keys" target="_blank">console.anthropic.com</a>. Paste the model name exactly as shown there — model names change over time, so if a call fails, double check the current model string.'
},
gemini: {
label: 'Gemini',
keyPlaceholder: 'AIza...',
modelPlaceholder: 'gemini-2.5-flash',
help: 'Create a key at <a href="https://aistudio.google.com/app/apikey" target="_blank">aistudio.google.com/app/apikey</a>. Check the current model name in Google AI Studio if a call fails.'
},
openai: {
label: 'ChatGPT',
keyPlaceholder: 'sk-...',
modelPlaceholder: 'gpt-4o-mini',
help: 'Create a key at <a href="https://platform.openai.com/api-keys" target="_blank">platform.openai.com/api-keys</a>. Check the current model name in the OpenAI docs if a call fails.'
},
other: {
label: 'Other',
keyPlaceholder: 'API key (leave blank if none)',
modelPlaceholder: 'model-name-as-required-by-provider',
needsEndpoint: true,
help: 'Works with any provider that exposes an OpenAI-compatible <code>/chat/completions</code> endpoint — Groq, Together AI, Mistral, DeepSeek, xAI (Grok), Perplexity, OpenRouter, Fireworks, local servers like Ollama or LM Studio, and more. Paste the full endpoint URL, the key that provider gave you, and the exact model name it expects.'
}
};
const $ = (id) => document.getElementById(id);
const state = { provider: 'claude' };
function wireCollapse(labelId, cardId){
const label = $(labelId), card = $(cardId);
label.addEventListener('click', () => {
card.classList.toggle('collapsed');
label.classList.toggle('collapsed');
});
}
wireCollapse('label-model','card-model');
wireCollapse('label-case','card-case');
wireCollapse('label-queries','card-queries');
wireCollapse('label-closure','card-closure');
function loadKeys(){ try{ return JSON.parse(localStorage.getItem('ebm_qgen_keys')||'{}'); }catch(e){ return {}; } }
function saveKeys(k){ localStorage.setItem('ebm_qgen_keys', JSON.stringify(k)); }
function loadModels(){ try{ return JSON.parse(localStorage.getItem('ebm_qgen_models')||'{}'); }catch(e){ return {}; } }
function saveModels(m){ localStorage.setItem('ebm_qgen_models', JSON.stringify(m)); }
function loadEndpoints(){ try{ return JSON.parse(localStorage.getItem('ebm_qgen_endpoints')||'{}'); }catch(e){ return {}; } }
function saveEndpoints(e){ localStorage.setItem('ebm_qgen_endpoints', JSON.stringify(e)); }
function refreshProviderUI(){
const p = PROVIDERS[state.provider];
$('apiKeyLabel').textContent = p.label + ' API key';
$('apiKey').placeholder = p.keyPlaceholder;
$('modelName').placeholder = p.modelPlaceholder;
$('endpointRow').style.display = p.needsEndpoint ? 'flex' : 'none';
$('keyHelp').innerHTML = p.help;
const keys = loadKeys(), models = loadModels(), endpoints = loadEndpoints();
$('apiKey').value = keys[state.provider] || '';
$('modelName').value = models[state.provider] || '';
$('apiEndpoint').value = endpoints[state.provider] || '';
const status = $('keyStatus');
if(keys[state.provider]){
status.textContent = 'A key is saved for ' + p.label + ' in this browser.';
status.className = 'key-status ok';
} else {
status.textContent = 'No key saved for this provider yet.';
status.className = 'key-status empty';
}
}
document.querySelectorAll('#providerTabs .tab').forEach(tab => {
tab.addEventListener('click', () => {
document.querySelectorAll('#providerTabs .tab').forEach(t=>t.classList.remove('active'));
tab.classList.add('active');
state.provider = tab.dataset.provider;
refreshProviderUI();
});
});
function persistField(kind, loader, saver, field){
field.addEventListener('input', () => {
const obj = loader();
obj[state.provider] = field.value.trim();
saver(obj);
if(kind==='key') refreshProviderUI();
});
}
persistField('key', loadKeys, saveKeys, $('apiKey'));
persistField('model', loadModels, saveModels, $('modelName'));
persistField('endpoint', loadEndpoints, saveEndpoints, $('apiEndpoint'));
refreshProviderUI();
const SAMPLE_CASE = `62-year-old woman with type 2 diabetes and hypertension presents with 3 months of\n`+
`exertional dyspnea and bilateral ankle swelling. Echocardiogram shows LVEF 38%.\n`+
`Currently on metformin, lisinopril 10mg, and amlodipine. She is asking whether starting\n`+
`an SGLT2 inhibitor is worth it, and says her main priority is "staying out of the hospital\n`+
`and being able to walk my dog without stopping to catch my breath."`;
$('sampleCaseBtn').addEventListener('click', (e) => { e.preventDefault(); $('caseText').value = SAMPLE_CASE; });
$('caseFile').addEventListener('change', async () => {
const f = $('caseFile').files[0];
if(!f) return;
const status = $('uploadStatus');
if(f.size > 10*1024*1024){ status.textContent = 'File too large (max 10MB).'; return; }
if(f.type === 'text/plain' || f.name.endsWith('.txt')){
const text = await f.text();
$('caseText').value = text;
status.textContent = 'Loaded ' + f.name;
} else {
status.textContent = f.name + ' selected — for PDF/Word, paste the extracted text into the case box if it does not load automatically.';
}
});
$('selectAllTypesBtn').addEventListener('click', () => {
document.querySelectorAll('#questionTypeList input[type=checkbox]').forEach(cb => cb.checked = true);
});
const resultsBody = $('resultsBody');
let resultCount = 0;
function clearEmptyNote(){
const note = resultsBody.querySelector('.empty-note');
if(note) note.remove();
}
function addResultCard(title, metaText, bodyText){
clearEmptyNote();
resultCount++;
const card = document.createElement('div');
card.className = 'result-card';
card.innerHTML = `<h3></h3><div class="meta"></div><pre></pre>`;
card.querySelector('h3').textContent = title;
card.querySelector('.meta').textContent = metaText;
card.querySelector('pre').textContent = bodyText;
resultsBody.appendChild(card);
card.scrollIntoView({behavior:'smooth', block:'nearest'});
}
function buildQueryPrompt(caseText, types){
return `You are acting as an EBM (Evidence-Based Medicine) research assistant, following the framework in the "Evidence-Based Medicine for Techies" course. Here is a de-identified patient case:\n\n${caseText}\n\nGenerate a structured list of critical-appraisal / EBM queries that arise from this case, focused on these question types: ${types.join(', ')}. Do not answer the clinical question itself, do not recommend treatment, and do not fabricate any statistic, trial name, or citation. Produce the QUESTIONS and SEARCH STRINGS this case needs answered — not the answers.\n\nFor each query, tag it with:\n1. EBM question type (Therapy / Diagnosis / Prognosis / Harm / Cost-effectiveness / Guideline)\n2. Best study design to answer it\n3. Draft PICO(T) breakdown\n4. Draft PubMed-ready search string\n5. Which appraisal checklist applies once evidence is found\n\nThen list, separately, anything in the case that is missing or ambiguous and would change the PICO if clarified.\n\nEnd with the patient's own stated priority or value (if present in the case) restated in one sentence.`;
}
function buildStressTestPrompt(){
const priorOutputs = Array.from(resultsBody.querySelectorAll('pre')).map(p=>p.textContent).join('\n---\n');
return `Given these previously generated EBM queries and conclusions:\n\n${priorOutputs}\n\nFor each major conclusion or query thread, add one adversarial stress-test query: "What is the strongest argument that this conclusion is wrong or overstated, given the evidence?" Keep it concise, one per thread.`;
}
function buildPatientPriorityPrompt(){
const caseText = $('caseText').value.trim();
return `From this case, extract and restate — in exactly one sentence, as closely as possible to the patient's own words — the patient's own stated priority or value:\n\n${caseText}`;
}
async function callModel(prompt){
const keys = loadKeys(), models = loadModels(), endpoints = loadEndpoints();
const apiKey = keys[state.provider];
const model = models[state.provider] || PROVIDERS[state.provider].modelPlaceholder;
if(!apiKey && state.provider !== 'other'){
throw new Error('No API key saved for ' + PROVIDERS[state.provider].label + '. Add one in Section 1.');
}
const msgs = [{role:'user', content: prompt}];
if(state.provider === 'claude') return callClaude(apiKey, model, msgs);
if(state.provider === 'gemini') return callGemini(apiKey, model, msgs);
if(state.provider === 'other') return callCustom(endpoints['other'], apiKey, model, msgs);
return callOpenAI(apiKey, model, msgs);
}
async function callClaude(apiKey, model, msgs){
const res = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey,
'anthropic-version': '2023-06-01',
'anthropic-dangerous-direct-browser-access': 'true'
},
body: JSON.stringify({ model: model, max_tokens: 4096, messages: msgs })
});
if(!res.ok){ const t = await res.text(); throw new Error(res.status + ' ' + t.slice(0,200)); }
const data = await res.json();
return (data.content||[]).map(b=>b.text||'').join('\n').trim();
}
async function callGemini(apiKey, model, msgs){
const contents = msgs.map(m => ({ role: m.role==='assistant'?'model':'user', parts:[{text:m.content}] }));
const res = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(model)}:generateContent?key=${encodeURIComponent(apiKey)}`, {
method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ contents })
});
if(!res.ok){ const t = await res.text(); throw new Error(res.status + ' ' + t.slice(0,200)); }
const data = await res.json();
const parts = (data.candidates && data.candidates[0] && data.candidates[0].content && data.candidates[0].content.parts) || [];
return parts.map(p=>p.text||'').join('\n').trim();
}
async function callCustom(endpoint, apiKey, model, msgs){
if(!endpoint) throw new Error('No API endpoint set for this provider.');
const headers = {'Content-Type':'application/json'};
if(apiKey) headers['Authorization'] = 'Bearer ' + apiKey;
const res = await fetch(endpoint, { method:'POST', headers, body: JSON.stringify({ model, messages: msgs, max_tokens: 4096 }) });
if(!res.ok){ const t = await res.text(); throw new Error(res.status + ' ' + t.slice(0,200)); }
const data = await res.json();
if(data.choices && data.choices[0] && data.choices[0].message) return (data.choices[0].message.content||'').trim();
if(data.message && data.message.content) return data.message.content.trim();
if(typeof data.content === 'string') return data.content.trim();
return JSON.stringify(data).slice(0,500);
}
async function callOpenAI(apiKey, model, msgs){
const res = await fetch('https://api.openai.com/v1/chat/completions', {
method:'POST',
headers:{'Content-Type':'application/json','Authorization':'Bearer '+apiKey},
body: JSON.stringify({ model, messages: msgs, max_tokens: 4096 })
});
if(!res.ok){ const t = await res.text(); throw new Error(res.status + ' ' + t.slice(0,200)); }
const data = await res.json();
return ((data.choices && data.choices[0] && data.choices[0].message && data.choices[0].message.content) || '').trim();
}
async function runWithButton(btn, promptFn, titleFn){
const original = btn.textContent;
btn.disabled = true;
btn.innerHTML = '<span class="typing">Working</span>';
$('errorNote').classList.remove('show');
try{
const prompt = promptFn();
const out = await callModel(prompt);
addResultCard(titleFn(), new Date().toLocaleString(), out || '(empty response)');
}catch(err){
$('errorNote').textContent = 'Request failed: ' + err.message + ' — check your API key, model name, and that the provider allows browser requests.';
$('errorNote').classList.add('show');
}finally{
btn.disabled = false;
btn.textContent = original;
}
}
$('runGenerateBtn').addEventListener('click', () => {
const caseText = $('caseText').value.trim();
if(!caseText){ alert('Paste or load a case first (Section 2).'); return; }
const types = Array.from(document.querySelectorAll('#questionTypeList input:checked')).map(cb=>cb.value);
if(types.length===0){ alert('Select at least one question type.'); return; }
runWithButton($('runGenerateBtn'), () => buildQueryPrompt(caseText, types), () => 'EBM Query Set — ' + types.join(', '));
});
$('stressTestBtn').addEventListener('click', () => {
if(resultCount===0){ alert('Generate at least one query set first.'); return; }
runWithButton($('stressTestBtn'), buildStressTestPrompt, () => 'Stress-Test Queries');
});
$('patientPriorityBtn').addEventListener('click', () => {
const caseText = $('caseText').value.trim();
if(!caseText){ alert('Paste or load a case first (Section 2).'); return; }
runWithButton($('patientPriorityBtn'), buildPatientPriorityPrompt, () => 'Patient Priority Restated');
});
$('resetRunBtn').addEventListener('click', () => {
resultsBody.innerHTML = '<p class="empty-note">No outputs yet — run a query generation or a Closure/Review step above to see results here.</p>';
resultCount = 0;
$('errorNote').classList.remove('show');
});
$('downloadBtn').addEventListener('click', () => {
const text = Array.from(resultsBody.querySelectorAll('.result-card')).map(c=>{
const h = c.querySelector('h3').textContent;
const meta = c.querySelector('.meta').textContent;
const body = c.querySelector('pre').textContent;
return `${h}\n${meta}\n\n${body}\n`;
}).join('\n=====================================\n\n');
if(!text){ alert('Nothing to download yet.'); return; }
const brandedText = window.vrBrandText ? window.vrBrandText(text) : text;
const blob = new Blob([brandedText], {type:'text/plain;charset=utf-8'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
const stamp = new Date().toISOString().slice(0,19).replace(/[:T]/g,'-');
a.href = url; a.download = 'ebm-case-queries-' + stamp + '.txt';
document.body.appendChild(a); a.click(); document.body.removeChild(a);
URL.revokeObjectURL(url);
if(typeof trackEvent === 'function') trackEvent('download_queries', {resultCount: resultCount});
});
$('readAloudBtn').addEventListener('click', () => {
const text = Array.from(resultsBody.querySelectorAll('pre')).map(p=>p.textContent).join('. ');
if(!text){ alert('Nothing to read yet.'); return; }
window.speechSynthesis.cancel();
window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
});
$('stopReadBtn').addEventListener('click', () => window.speechSynthesis.cancel());
</script>
</body>
</html>