File size: 3,029 Bytes
ef41468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

from dataclasses import dataclass

import pandas as pd


@dataclass(frozen=True)
class TaskConfig:
    task_id: str
    title: str
    description: str
    min_steps: int
    max_steps: int
    preferred_stay_ids: tuple[int, ...]
    score_weights: dict[str, float]


def _ordered_stays(summary: pd.DataFrame, selector) -> tuple[int, ...]:
    subset = summary[selector(summary)].sort_values(["mean_severity", "length", "mortality", "icustay_id"])
    return tuple(int(stay_id) for stay_id in subset["icustay_id"].tolist())


def build_task_catalog(summary: pd.DataFrame) -> dict[str, TaskConfig]:
    easy_ids = _ordered_stays(
        summary,
        lambda df: (df["mean_severity"] <= 1.0) & (df["length"] >= 8),
    )
    medium_ids = _ordered_stays(
        summary,
        lambda df: (df["mean_severity"] >= 0.8) & (df["max_severity"] >= 2.0) & (df["length"] >= 8),
    )
    hard_ids = _ordered_stays(
        summary,
        lambda df: (df["max_severity"] >= 3.0) & (df["length"] >= 8),
    )

    if not hard_ids:
        hard_ids = medium_ids[-4:]
    if not medium_ids:
        medium_ids = easy_ids[-6:]
    if not easy_ids:
        easy_ids = tuple(int(stay_id) for stay_id in summary.sort_values("icustay_id")["icustay_id"].head(6).tolist())

    return {
        "easy": TaskConfig(
            task_id="easy",
            title="Early Sepsis Workup",
            description=(
                "Identify likely sepsis early and request the most informative initial labs from partial bedside data."
            ),
            min_steps=6,
            max_steps=8,
            preferred_stay_ids=easy_ids,
            score_weights={"detection": 0.35, "lab_workup": 0.35, "timeliness": 0.20, "safety": 0.10},
        ),
        "medium": TaskConfig(
            task_id="medium",
            title="Diagnosis And Early Treatment",
            description=(
                "Use iterative lab requests to confirm deterioration and start an appropriate treatment plan early."
            ),
            min_steps=8,
            max_steps=12,
            preferred_stay_ids=medium_ids,
            score_weights={
                "detection": 0.20,
                "lab_workup": 0.20,
                "treatment": 0.30,
                "timeliness": 0.20,
                "safety": 0.10,
            },
        ),
        "hard": TaskConfig(
            task_id="hard",
            title="Full Sepsis Management",
            description=(
                "Balance workup, treatment escalation, and stabilization across longer unstable sepsis trajectories "
                "while avoiding unsafe actions."
            ),
            min_steps=8,
            max_steps=16,
            preferred_stay_ids=hard_ids,
            score_weights={
                "detection": 0.15,
                "lab_workup": 0.15,
                "treatment": 0.20,
                "stability": 0.20,
                "safety": 0.10,
                "outcome": 0.20,
            },
        ),
    }