File size: 1,086 Bytes
877add7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Dose policy features."""

from __future__ import annotations

from app.common.types import PatientProfile


def build_dose_features(patient: PatientProfile, drug: str) -> dict[str, float]:
    med_count = float(len(patient.medications))
    interaction_load = min(1.0, med_count / 12.0)
    organ_stress = min(
        1.0,
        max(0.0, (35.0 - float(patient.labs.egfr or 60.0)) / 35.0)
        + max(0.0, (float(patient.labs.ast or 30.0) - 80.0) / 80.0)
        + max(0.0, (float(patient.labs.alt or 30.0) - 80.0) / 80.0),
    )
    return {
        "egfr": float(patient.labs.egfr or 60.0),
        "ast": float(patient.labs.ast or 30.0),
        "alt": float(patient.labs.alt or 30.0),
        "adherence": float(patient.adherence_estimate),
        "frailty": float(patient.frailty_score),
        "interaction_load": interaction_load,
        "organ_stress": organ_stress,
        "inr": float(patient.labs.inr or 1.2),
        "glucose": float(patient.labs.glucose or 110.0),
        "is_target_drug_present": float(any(m.drug == drug for m in patient.medications)),
    }