File size: 37,962 Bytes
b4806b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
#!/usr/bin/env python3
"""Regenerate all 25 task JSONs with difficulty-varied note elements.

Distribution:
  Basic  (3 notes)  β€” 5 tasks   (straightforward, guideline-driven)
  Medium (4-5 notes) β€” 10 tasks  (requires some clinical reasoning)
  Hard   (6-7 notes) β€” 10 tasks  (time-sensitive, multi-system, high-acuity)
"""
import json, os

TASKS_DIR = os.path.join(os.path.dirname(__file__), '..', 'tasks', 'examples')

# ──────────────────── BASIC (3 note elements) ────────────────────

tasks = [
    # ── 1. CAP (basic: stable patient, established dx, monitoring) ──
    {
        "file": "cap-pneumonia-followup.json",
        "id": "cap-pneumonia-followup",
        "title": "CAP β€” antibiotic stewardship and imaging follow-up",
        "patient_id": "pat-1002",
        "encounter_id": "enc-1002",
        "role": "Attending Physician",
        "objective": "As the attending physician, review the chest imaging and culture results, document the antibiotic course and respiratory status, order a follow-up chest X-ray, then sign the encounter.",
        "required_orders": ["Chest X-ray"],
        "required_note_elements": [
            "Antibiotic exposure",
            "Respiratory symptoms",
            "Follow-up plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Chest X-ray": 0.20,
                "note_element:Antibiotic exposure": 0.20,
                "note_element:Respiratory symptoms": 0.15,
                "note_element:Follow-up plan": 0.15,
                "encounter_signed": 0.30
            }
        }
    },
    # ── 2. MRSA cellulitis (basic: skin infection, allergy check) ──
    {
        "file": "mrsa-cellulitis.json",
        "id": "mrsa-cellulitis",
        "title": "MRSA cellulitis β€” empiric coverage with allergy consideration",
        "patient_id": "pat-1014",
        "encounter_id": "enc-1014",
        "role": "Attending Physician",
        "objective": "As the attending physician, review inflammatory markers and drug allergies, place vancomycin and wound culture orders, document the MRSA risk, antibiotic choice, and allergy consideration, then sign the encounter.",
        "required_orders": ["Vancomycin IV", "Wound culture"],
        "required_note_elements": [
            "MRSA risk factors",
            "Antibiotic selection",
            "Allergy consideration"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Vancomycin IV": 0.18,
                "order:Wound culture": 0.12,
                "note_element:MRSA risk factors": 0.15,
                "note_element:Antibiotic selection": 0.15,
                "note_element:Allergy consideration": 0.12,
                "encounter_signed": 0.28
            }
        }
    },
    # ── 3. Hip fracture (basic: clear imaging, consult, reversal) ──
    {
        "file": "hip-fracture.json",
        "id": "hip-fracture",
        "title": "Hip fracture β€” anticoagulation reversal for surgical clearance",
        "patient_id": "pat-1018",
        "encounter_id": "enc-1018",
        "role": "Attending Physician",
        "objective": "As the attending physician, review the fracture imaging and supratherapeutic INR, place vitamin K reversal and orthopedic consult, document the fracture type, reversal plan, and surgical disposition, then sign the encounter.",
        "required_orders": ["Vitamin K IV", "Orthopedic surgery consult"],
        "required_note_elements": [
            "Fracture type",
            "Anticoagulation reversal",
            "Surgical planning"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Vitamin K IV": 0.18,
                "order:Orthopedic surgery consult": 0.14,
                "note_element:Fracture type": 0.15,
                "note_element:Anticoagulation reversal": 0.13,
                "note_element:Surgical planning": 0.12,
                "encounter_signed": 0.28
            }
        }
    },
    # ── 4. Post-op ileus (basic: clear post-surgical, supportive care) ──
    {
        "file": "postop-ileus.json",
        "id": "postop-ileus",
        "title": "Post-op ileus β€” decompression and electrolyte correction",
        "patient_id": "pat-1025",
        "encounter_id": "enc-1025",
        "role": "Attending Physician",
        "objective": "As the attending physician, review post-operative labs and imaging, place NGT decompression and IV potassium repletion, document the bowel status, electrolyte plan, and NPO rationale, then sign the encounter.",
        "required_orders": ["Nasogastric tube placement", "Potassium chloride IV"],
        "required_note_elements": [
            "Bowel function status",
            "Electrolyte correction",
            "NPO status"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Nasogastric tube placement": 0.18,
                "order:Potassium chloride IV": 0.12,
                "note_element:Bowel function status": 0.15,
                "note_element:Electrolyte correction": 0.13,
                "note_element:NPO status": 0.12,
                "encounter_signed": 0.30
            }
        }
    },
    # ── 5. C. diff colitis (basic: guideline-driven severity & tx) ──
    {
        "file": "cdiff-colitis.json",
        "id": "cdiff-colitis",
        "title": "C. difficile colitis β€” severity-guided oral vancomycin",
        "patient_id": "pat-1021",
        "encounter_id": "enc-1021",
        "role": "Attending Physician",
        "objective": "As the attending physician, review C. diff PCR and severity markers (WBC, creatinine), place oral vancomycin and CT abdomen, document the severity classification, prior antibiotic exposure, and treatment plan, then sign the encounter.",
        "required_orders": ["Vancomycin oral", "CT abdomen pelvis"],
        "required_note_elements": [
            "C. diff severity",
            "Prior antibiotic exposure",
            "Oral vancomycin plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Vancomycin oral": 0.18,
                "order:CT abdomen pelvis": 0.12,
                "note_element:C. diff severity": 0.18,
                "note_element:Prior antibiotic exposure": 0.12,
                "note_element:Oral vancomycin plan": 0.12,
                "encounter_signed": 0.28
            }
        }
    },

    # ──────────────────── MEDIUM (4-5 note elements) ────────────────────

    # ── 6. AKI chart review (medium: 4 notes) ──
    {
        "file": "aki-chart-review.json",
        "id": "aki-chart-review",
        "title": "AKI chart review β€” fluid resuscitation and renal monitoring",
        "patient_id": "pat-1001",
        "encounter_id": "enc-1001",
        "role": "Attending Physician",
        "objective": "As the attending physician, review the creatinine trend and urine output, assess volume status, place IV fluid and repeat BMP orders, document your renal assessment with differential, then sign the encounter.",
        "required_orders": ["Basic metabolic panel", "Normal saline bolus"],
        "required_note_elements": [
            "Creatinine trend",
            "Volume assessment",
            "Urine output",
            "AKI differential diagnosis"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Normal saline bolus": 0.15,
                "order:Basic metabolic panel": 0.08,
                "note_element:Creatinine trend": 0.15,
                "note_element:Volume assessment": 0.13,
                "note_element:Urine output": 0.10,
                "note_element:AKI differential diagnosis": 0.14,
                "encounter_signed": 0.25
            }
        }
    },
    # ── 7. Upper GI bleed (medium: 5 notes) ──
    {
        "file": "upper-gi-bleed.json",
        "id": "upper-gi-bleed",
        "title": "Upper GI bleed β€” transfusion and acid suppression",
        "patient_id": "pat-1005",
        "encounter_id": "enc-1005",
        "role": "Attending Physician",
        "objective": "As the attending physician, review hemoglobin trend and coag panel, place PRBC transfusion and IV pantoprazole, document the bleed severity, hemodynamics, and GI consultation need, then sign the encounter.",
        "required_orders": ["Packed red blood cells", "Pantoprazole IV"],
        "required_note_elements": [
            "Hemoglobin trend",
            "Hemodynamic status",
            "Glasgow-Blatchford score",
            "Transfusion plan",
            "GI consultation indication"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Packed red blood cells": 0.15,
                "order:Pantoprazole IV": 0.08,
                "note_element:Hemoglobin trend": 0.12,
                "note_element:Hemodynamic status": 0.10,
                "note_element:Glasgow-Blatchford score": 0.10,
                "note_element:Transfusion plan": 0.10,
                "note_element:GI consultation indication": 0.10,
                "encounter_signed": 0.25
            }
        }
    },
    # ── 8. COPD exacerbation (medium: 4 notes) ──
    {
        "file": "copd-exacerbation.json",
        "id": "copd-exacerbation",
        "title": "COPD exacerbation β€” systemic steroids and bronchodilators",
        "patient_id": "pat-1006",
        "encounter_id": "enc-1006",
        "role": "Attending Physician",
        "objective": "As the attending physician, review the ABG showing hypercapnic respiratory failure, place IV steroids and nebulizer, document the respiratory acidosis, ABG findings, oxygen needs, and steroid plan, then sign the encounter.",
        "required_orders": ["Methylprednisolone IV", "Albuterol nebulizer"],
        "required_note_elements": [
            "Respiratory acidosis",
            "ABG interpretation",
            "Oxygen requirements",
            "Steroid plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Methylprednisolone IV": 0.15,
                "order:Albuterol nebulizer": 0.10,
                "note_element:Respiratory acidosis": 0.14,
                "note_element:ABG interpretation": 0.12,
                "note_element:Oxygen requirements": 0.10,
                "note_element:Steroid plan": 0.12,
                "encounter_signed": 0.27
            }
        }
    },
    # ── 9. Acute pancreatitis (medium: 5 notes) ──
    {
        "file": "acute-pancreatitis.json",
        "id": "acute-pancreatitis",
        "title": "Acute pancreatitis β€” aggressive hydration and imaging",
        "patient_id": "pat-1010",
        "encounter_id": "enc-1010",
        "role": "Attending Physician",
        "objective": "As the attending physician, review lipase and severity markers, place aggressive fluid resuscitation and CT imaging, document the etiology workup, severity scoring, and nutrition plan, then sign the encounter.",
        "required_orders": ["Lactated Ringer bolus", "CT abdomen with contrast"],
        "required_note_elements": [
            "Lipase elevation",
            "Gallstone evaluation",
            "Ranson criteria",
            "Fluid management",
            "NPO and nutrition plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Lactated Ringer bolus": 0.13,
                "order:CT abdomen with contrast": 0.10,
                "note_element:Lipase elevation": 0.12,
                "note_element:Gallstone evaluation": 0.10,
                "note_element:Ranson criteria": 0.10,
                "note_element:Fluid management": 0.10,
                "note_element:NPO and nutrition plan": 0.10,
                "encounter_signed": 0.25
            }
        }
    },
    # ── 10. Hyperkalemia (medium: 4 notes) ──
    {
        "file": "hyperkalemia.json",
        "id": "hyperkalemia",
        "title": "Hyperkalemia β€” emergent cardiac stabilization",
        "patient_id": "pat-1015",
        "encounter_id": "enc-1015",
        "role": "Attending Physician",
        "objective": "As the attending physician, review potassium and ECG, place emergent calcium gluconate and insulin-dextrose, document the potassium level, ECG changes, and management cascade, then sign the encounter.",
        "required_orders": ["Calcium gluconate IV", "Insulin and dextrose IV"],
        "required_note_elements": [
            "Potassium level",
            "ECG changes",
            "Emergent management",
            "Potassium shifting agents"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Calcium gluconate IV": 0.18,
                "order:Insulin and dextrose IV": 0.12,
                "note_element:Potassium level": 0.12,
                "note_element:ECG changes": 0.12,
                "note_element:Emergent management": 0.10,
                "note_element:Potassium shifting agents": 0.10,
                "encounter_signed": 0.26
            }
        }
    },
    # ── 11. Hepatic encephalopathy (medium: 5 notes) ──
    {
        "file": "hepatic-encephalopathy.json",
        "id": "hepatic-encephalopathy",
        "title": "Hepatic encephalopathy β€” lactulose titration and rifaximin",
        "patient_id": "pat-1016",
        "encounter_id": "enc-1016",
        "role": "Attending Physician",
        "objective": "As the attending physician, review ammonia and hepatic function, place lactulose and rifaximin, document the encephalopathy grading, precipitant, and titration goals, then sign the encounter.",
        "required_orders": ["Lactulose oral", "Rifaximin oral"],
        "required_note_elements": [
            "Ammonia level",
            "Mental status changes",
            "West Haven grade",
            "Precipitant identification",
            "Lactulose plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Lactulose oral": 0.14,
                "order:Rifaximin oral": 0.09,
                "note_element:Ammonia level": 0.12,
                "note_element:Mental status changes": 0.10,
                "note_element:West Haven grade": 0.10,
                "note_element:Precipitant identification": 0.12,
                "note_element:Lactulose plan": 0.10,
                "encounter_signed": 0.23
            }
        }
    },
    # ── 12. Alcohol withdrawal (medium: 5 notes) ──
    {
        "file": "alcohol-withdrawal.json",
        "id": "alcohol-withdrawal",
        "title": "Alcohol withdrawal β€” CIWA-guided benzodiazepine protocol",
        "patient_id": "pat-1020",
        "encounter_id": "enc-1020",
        "role": "Attending Physician",
        "objective": "As the attending physician, review CIWA score and seizure history, place lorazepam and IV thiamine, document the withdrawal severity, benzodiazepine plan, and DT risk, then sign the encounter.",
        "required_orders": ["Lorazepam IV", "Thiamine IV"],
        "required_note_elements": [
            "CIWA score",
            "Seizure history",
            "Last drink timing",
            "Benzodiazepine plan",
            "Delirium tremens risk"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Lorazepam IV": 0.14,
                "order:Thiamine IV": 0.09,
                "note_element:CIWA score": 0.12,
                "note_element:Seizure history": 0.10,
                "note_element:Last drink timing": 0.10,
                "note_element:Benzodiazepine plan": 0.12,
                "note_element:Delirium tremens risk": 0.10,
                "encounter_signed": 0.23
            }
        }
    },
    # ── 13. Sickle cell crisis (medium: 5 notes) ──
    {
        "file": "sickle-cell-crisis.json",
        "id": "sickle-cell-crisis",
        "title": "Sickle cell VOC β€” pain management and ACS screening",
        "patient_id": "pat-1023",
        "encounter_id": "enc-1023",
        "role": "Attending Physician",
        "objective": "As the attending physician, review hemolysis markers and hemoglobin, place hydromorphone PCA (noting morphine allergy) and CXR for ACS screening, document the pain assessment, ACS evaluation, and transfusion threshold, then sign the encounter.",
        "required_orders": ["Hydromorphone PCA", "Chest X-ray"],
        "required_note_elements": [
            "Hemoglobin baseline",
            "Pain assessment",
            "Acute chest syndrome screening",
            "Morphine allergy and opioid selection",
            "Transfusion threshold"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Hydromorphone PCA": 0.14,
                "order:Chest X-ray": 0.09,
                "note_element:Hemoglobin baseline": 0.10,
                "note_element:Pain assessment": 0.12,
                "note_element:Acute chest syndrome screening": 0.12,
                "note_element:Morphine allergy and opioid selection": 0.10,
                "note_element:Transfusion threshold": 0.10,
                "encounter_signed": 0.23
            }
        }
    },
    # ── 14. CHF exacerbation (medium: 5 notes) ──
    {
        "file": "chf-exacerbation.json",
        "id": "chf-exacerbation",
        "title": "CHF exacerbation β€” IV diuresis and volume management",
        "patient_id": "pat-1007",
        "encounter_id": "enc-1007",
        "role": "Attending Physician",
        "objective": "As the attending physician, review BNP, electrolytes, and daily weights, place IV furosemide and renal monitoring, document the volume overload assessment and diuresis strategy, then sign the encounter.",
        "required_orders": ["Furosemide IV", "Basic metabolic panel"],
        "required_note_elements": [
            "Volume status",
            "BNP level",
            "Daily weight trend",
            "Ejection fraction",
            "Diuretic plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Furosemide IV": 0.15,
                "order:Basic metabolic panel": 0.07,
                "note_element:Volume status": 0.13,
                "note_element:BNP level": 0.10,
                "note_element:Daily weight trend": 0.10,
                "note_element:Ejection fraction": 0.10,
                "note_element:Diuretic plan": 0.12,
                "encounter_signed": 0.23
            }
        }
    },
    # ── 15. PE workup (medium: 5 notes) ──
    {
        "file": "pe-workup.json",
        "id": "pe-workup",
        "title": "PE β€” diagnostic imaging and empiric anticoagulation",
        "patient_id": "pat-1008",
        "encounter_id": "enc-1008",
        "role": "Attending Physician",
        "objective": "As the attending physician, review D-dimer and Wells criteria, place CTA chest and heparin drip, document the PE probability, hemodynamics, and anticoagulation rationale, then sign the encounter.",
        "required_orders": ["CT angiography chest", "Heparin drip"],
        "required_note_elements": [
            "D-dimer elevation",
            "Wells score",
            "Hypoxia evaluation",
            "Right heart strain",
            "Anticoagulation plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:CT angiography chest": 0.13,
                "order:Heparin drip": 0.13,
                "note_element:D-dimer elevation": 0.10,
                "note_element:Wells score": 0.12,
                "note_element:Hypoxia evaluation": 0.10,
                "note_element:Right heart strain": 0.10,
                "note_element:Anticoagulation plan": 0.10,
                "encounter_signed": 0.22
            }
        }
    },

    # ──────────────────── HARD (6-7 note elements) ────────────────────

    # ── 16. DKA management (hard: 7 notes) ──
    {
        "file": "dka-management.json",
        "id": "dka-management",
        "title": "DKA β€” insulin protocol and anion-gap monitoring",
        "patient_id": "pat-1003",
        "encounter_id": "enc-1003",
        "role": "Attending Physician",
        "objective": "As the attending physician, review the metabolic panel (glucose, anion gap, pH, bicarbonate), start an insulin drip with serial BMP monitoring, document the DKA severity, precipitant workup, fluid and insulin management, potassium monitoring, and gap closure criteria, then sign the encounter.",
        "required_orders": ["Insulin drip", "Basic metabolic panel"],
        "required_note_elements": [
            "Anion gap",
            "Blood glucose level",
            "Serum bicarbonate",
            "Fluid resuscitation",
            "Insulin management",
            "DKA precipitant",
            "Potassium monitoring"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Insulin drip": 0.14,
                "order:Basic metabolic panel": 0.05,
                "note_element:Anion gap": 0.10,
                "note_element:Blood glucose level": 0.08,
                "note_element:Serum bicarbonate": 0.08,
                "note_element:Fluid resuscitation": 0.09,
                "note_element:Insulin management": 0.10,
                "note_element:DKA precipitant": 0.09,
                "note_element:Potassium monitoring": 0.08,
                "encounter_signed": 0.19
            }
        }
    },
    # ── 17. Acute coronary syndrome (hard: 7 notes) ──
    {
        "file": "acute-coronary-syndrome.json",
        "id": "acute-coronary-syndrome",
        "title": "STEMI β€” anticoagulation and cardiac workup",
        "patient_id": "pat-1004",
        "encounter_id": "enc-1004",
        "role": "Attending Physician",
        "objective": "As the attending physician, review serial troponins and ECG findings, place heparin drip and echocardiogram, document the full ACS assessment including risk stratification, ECG interpretation, antiplatelet and anticoagulation rationale, and cardiology consultation, then sign the encounter.",
        "required_orders": ["Heparin drip", "Echocardiogram"],
        "required_note_elements": [
            "Troponin trend",
            "ECG interpretation",
            "ST elevation",
            "Chest pain characterization",
            "TIMI risk score",
            "Antiplatelet therapy",
            "Cardiology consultation"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Heparin drip": 0.13,
                "order:Echocardiogram": 0.05,
                "note_element:Troponin trend": 0.10,
                "note_element:ECG interpretation": 0.10,
                "note_element:ST elevation": 0.08,
                "note_element:Chest pain characterization": 0.08,
                "note_element:TIMI risk score": 0.09,
                "note_element:Antiplatelet therapy": 0.09,
                "note_element:Cardiology consultation": 0.08,
                "encounter_signed": 0.20
            }
        }
    },
    # ── 18. Urosepsis (hard: 7 notes) ──
    {
        "file": "urosepsis.json",
        "id": "urosepsis",
        "title": "Urosepsis β€” SEP-1 bundle compliance",
        "patient_id": "pat-1009",
        "encounter_id": "enc-1009",
        "role": "Attending Physician",
        "objective": "As the attending physician, review lactate, urinalysis, and blood cultures, place empiric IV antibiotics and fluid resuscitation within the SEP-1 bundle, document the full sepsis workup including source, bundle timing, hemodynamic response, and reassessment, then sign the encounter.",
        "required_orders": ["Ceftriaxone IV", "Normal saline bolus"],
        "required_note_elements": [
            "Sepsis criteria",
            "Lactate level",
            "Source identification",
            "Blood culture timing",
            "Hemodynamic response to fluids",
            "Antibiotic selection rationale",
            "Reassessment plan"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Ceftriaxone IV": 0.12,
                "order:Normal saline bolus": 0.07,
                "note_element:Sepsis criteria": 0.10,
                "note_element:Lactate level": 0.09,
                "note_element:Source identification": 0.09,
                "note_element:Blood culture timing": 0.08,
                "note_element:Hemodynamic response to fluids": 0.09,
                "note_element:Antibiotic selection rationale": 0.09,
                "note_element:Reassessment plan": 0.08,
                "encounter_signed": 0.19
            }
        }
    },
    # ── 19. New-onset AFib (hard: 6 notes) ──
    {
        "file": "new-onset-afib.json",
        "id": "new-onset-afib",
        "title": "New-onset AFib with RVR β€” rate control and stroke risk",
        "patient_id": "pat-1011",
        "encounter_id": "enc-1011",
        "role": "Attending Physician",
        "objective": "As the attending physician, review electrolytes, thyroid function, and telemetry, place IV diltiazem and potassium repletion, document the rhythm analysis, CHA2DS2-VASc score, rate control strategy, and anticoagulation decision, then sign the encounter.",
        "required_orders": ["Diltiazem IV", "Potassium chloride IV"],
        "required_note_elements": [
            "Heart rate",
            "Rhythm interpretation",
            "CHA2DS2-VASc score",
            "Rate control strategy",
            "Anticoagulation decision",
            "Hemodynamic stability"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Diltiazem IV": 0.13,
                "order:Potassium chloride IV": 0.05,
                "note_element:Heart rate": 0.09,
                "note_element:Rhythm interpretation": 0.10,
                "note_element:CHA2DS2-VASc score": 0.12,
                "note_element:Rate control strategy": 0.12,
                "note_element:Anticoagulation decision": 0.12,
                "note_element:Hemodynamic stability": 0.08,
                "encounter_signed": 0.19
            }
        }
    },
    # ── 20. Hyponatremia workup (hard: 7 notes) ──
    {
        "file": "hyponatremia-workup.json",
        "id": "hyponatremia-workup",
        "title": "Severe hyponatremia β€” SIADH diagnosis and safe correction",
        "patient_id": "pat-1012",
        "encounter_id": "enc-1012",
        "role": "Attending Physician",
        "objective": "As the attending physician, review sodium, serum and urine osmolality, and urine sodium, place hypertonic saline with serial BMP monitoring, document the hyponatremia classification, SIADH diagnostic criteria, and safe correction rate plan with osmotic demyelination risk, then sign the encounter.",
        "required_orders": ["Sodium chloride 3% IV", "Basic metabolic panel"],
        "required_note_elements": [
            "Sodium level",
            "Serum osmolality",
            "Urine osmolality",
            "Urine sodium",
            "Volume status classification",
            "SIADH assessment",
            "Correction rate goal"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Sodium chloride 3% IV": 0.12,
                "order:Basic metabolic panel": 0.05,
                "note_element:Sodium level": 0.09,
                "note_element:Serum osmolality": 0.09,
                "note_element:Urine osmolality": 0.08,
                "note_element:Urine sodium": 0.08,
                "note_element:Volume status classification": 0.09,
                "note_element:SIADH assessment": 0.11,
                "note_element:Correction rate goal": 0.10,
                "encounter_signed": 0.19
            }
        }
    },
    # ── 21. Acute ischemic stroke (hard: 7 notes) ──
    {
        "file": "acute-ischemic-stroke.json",
        "id": "acute-ischemic-stroke",
        "title": "Acute ischemic stroke β€” thrombolysis decision",
        "patient_id": "pat-1013",
        "encounter_id": "enc-1013",
        "role": "Attending Physician",
        "objective": "As the attending physician, review CT head, INR, platelets, and glucose, assess tPA eligibility, place alteplase and CTA orders, document the NIHSS, time last known well, contraindication screen, eligibility determination, BP management, and neurology consultation, then sign the encounter.",
        "required_orders": ["Alteplase IV", "CT angiography head and neck"],
        "required_note_elements": [
            "NIHSS score",
            "Time last known well",
            "CT head interpretation",
            "tPA contraindication screen",
            "tPA eligibility",
            "Blood pressure management",
            "Neurology consultation"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Alteplase IV": 0.16,
                "order:CT angiography head and neck": 0.05,
                "note_element:NIHSS score": 0.09,
                "note_element:Time last known well": 0.10,
                "note_element:CT head interpretation": 0.08,
                "note_element:tPA contraindication screen": 0.10,
                "note_element:tPA eligibility": 0.09,
                "note_element:Blood pressure management": 0.08,
                "note_element:Neurology consultation": 0.06,
                "encounter_signed": 0.19
            }
        }
    },
    # ── 22. Anaphylaxis (hard: 6 notes) ──
    {
        "file": "anaphylaxis.json",
        "id": "anaphylaxis",
        "title": "Anaphylaxis β€” epinephrine infusion and allergen documentation",
        "patient_id": "pat-1017",
        "encounter_id": "enc-1017",
        "role": "Attending Physician",
        "objective": "As the attending physician, review tryptase and vital sign trajectory, place epinephrine infusion and IV steroids, document the anaphylaxis diagnostic criteria, causative agent, airway assessment, epinephrine dosing, hemodynamic response, and biphasic reaction monitoring plan, then sign the encounter.",
        "required_orders": ["Epinephrine IV drip", "Methylprednisolone IV"],
        "required_note_elements": [
            "Causative agent",
            "Anaphylaxis criteria",
            "Epinephrine administration",
            "Airway assessment",
            "Hemodynamic response",
            "Biphasic reaction monitoring"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Epinephrine IV drip": 0.17,
                "order:Methylprednisolone IV": 0.05,
                "note_element:Causative agent": 0.10,
                "note_element:Anaphylaxis criteria": 0.10,
                "note_element:Epinephrine administration": 0.12,
                "note_element:Airway assessment": 0.10,
                "note_element:Hemodynamic response": 0.08,
                "note_element:Biphasic reaction monitoring": 0.08,
                "encounter_signed": 0.20
            }
        }
    },
    # ── 23. Asthma exacerbation (hard: 6 notes) ──
    {
        "file": "asthma-exacerbation.json",
        "id": "asthma-exacerbation",
        "title": "Severe asthma β€” IV magnesium and systemic steroids",
        "patient_id": "pat-1019",
        "encounter_id": "enc-1019",
        "role": "Attending Physician",
        "objective": "As the attending physician, review ABG (noting ominous normal pCO2), peak flow, and accessory muscle use, place IV magnesium and systemic steroids, document the severity classification, bronchodilator response, intubation readiness, and ICU escalation criteria, then sign the encounter.",
        "required_orders": ["Magnesium sulfate IV", "Methylprednisolone IV"],
        "required_note_elements": [
            "Peak flow",
            "ABG with pCO2 interpretation",
            "Accessory muscle use",
            "Steroid therapy",
            "Bronchodilator response",
            "Intubation readiness"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Magnesium sulfate IV": 0.12,
                "order:Methylprednisolone IV": 0.12,
                "note_element:Peak flow": 0.09,
                "note_element:ABG with pCO2 interpretation": 0.10,
                "note_element:Accessory muscle use": 0.08,
                "note_element:Steroid therapy": 0.09,
                "note_element:Bronchodilator response": 0.09,
                "note_element:Intubation readiness": 0.10,
                "encounter_signed": 0.21
            }
        }
    },
    # ── 24. Thyroid storm (hard: 6 notes) ──
    {
        "file": "thyroid-storm.json",
        "id": "thyroid-storm",
        "title": "Thyroid storm β€” multi-drug thyroid blockade and rate control",
        "patient_id": "pat-1022",
        "encounter_id": "enc-1022",
        "role": "Attending Physician",
        "objective": "As the attending physician, review TSH, free T4/T3, and vital sign instability, place PTU and IV propranolol for dual blockade and rate control, document the Burch-Wartofsky score, anti-thyroid therapy, rate control rationale, temperature management, and precipitant, then sign the encounter.",
        "required_orders": ["Propylthiouracil oral", "Propranolol IV"],
        "required_note_elements": [
            "Thyroid hormone levels",
            "Burch-Wartofsky score",
            "Anti-thyroid therapy",
            "Beta-blocker rationale",
            "Temperature management",
            "Precipitating event"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Propylthiouracil oral": 0.12,
                "order:Propranolol IV": 0.12,
                "note_element:Thyroid hormone levels": 0.10,
                "note_element:Burch-Wartofsky score": 0.11,
                "note_element:Anti-thyroid therapy": 0.09,
                "note_element:Beta-blocker rationale": 0.08,
                "note_element:Temperature management": 0.08,
                "note_element:Precipitating event": 0.09,
                "encounter_signed": 0.21
            }
        }
    },
    # ── 25. Bacterial meningitis (hard: 7 notes) ──
    {
        "file": "bacterial-meningitis.json",
        "id": "bacterial-meningitis",
        "title": "Bacterial meningitis β€” empiric antibiotics and adjunctive steroids",
        "patient_id": "pat-1024",
        "encounter_id": "enc-1024",
        "role": "Attending Physician",
        "objective": "As the attending physician, review CSF analysis (cell count, glucose, protein, Gram stain), place IV ceftriaxone and adjunctive dexamethasone, document the meningeal exam, CSF interpretation, Gram stain findings, empiric regimen rationale, dexamethasone timing, and isolation precautions, then sign the encounter.",
        "required_orders": ["Ceftriaxone IV", "Dexamethasone IV"],
        "required_note_elements": [
            "CSF analysis",
            "Meningeal signs",
            "CSF glucose-to-serum ratio",
            "Gram stain results",
            "Empiric antibiotic rationale",
            "Dexamethasone timing rationale",
            "Droplet precautions"
        ],
        "scoring": {
            "base_reward": 1.0,
            "substeps": {
                "order:Ceftriaxone IV": 0.14,
                "order:Dexamethasone IV": 0.06,
                "note_element:CSF analysis": 0.10,
                "note_element:Meningeal signs": 0.09,
                "note_element:CSF glucose-to-serum ratio": 0.08,
                "note_element:Gram stain results": 0.08,
                "note_element:Empiric antibiotic rationale": 0.09,
                "note_element:Dexamethasone timing rationale": 0.08,
                "note_element:Droplet precautions": 0.08,
                "encounter_signed": 0.20
            }
        }
    }
]


def main():
    difficulty_map = {}
    for task in tasks:
        fn = task.pop("file")
        path = os.path.join(TASKS_DIR, fn)
        subs = task["scoring"]["substeps"]
        total = round(sum(subs.values()), 2)
        assert total == 1.0, f"{fn}: weights sum to {total}, not 1.0"
        for o in task["required_orders"]:
            assert f"order:{o}" in subs, f"{fn}: missing substep for order:{o}"
        for e in task["required_note_elements"]:
            assert f"note_element:{e}" in subs, f"{fn}: missing substep for note_element:{e}"
        assert "encounter_signed" in subs, f"{fn}: missing encounter_signed"
        with open(path, "w") as f:
            json.dump(task, f, indent=2)
            f.write("\n")
        n = len(task["required_note_elements"])
        diff = "BASIC" if n <= 3 else ("MEDIUM" if n <= 5 else "HARD")
        difficulty_map.setdefault(diff, []).append(fn)
        print(f"  [{diff:6s}] {fn:40s} notes={n} substeps={len(subs)} sum={total:.2f}")

    print(f"\nWrote {len(tasks)} task files.")
    for d in ["BASIC", "MEDIUM", "HARD"]:
        items = difficulty_map.get(d, [])
        print(f"  {d}: {len(items)} tasks")


if __name__ == "__main__":
    main()