polyguard-openenv / app /models /dosing /dose_policy_features.py
TheJackBright's picture
Deploy PolyGuard OpenEnv Space
877add7 verified
"""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)),
}