Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/inputs/score2_diabetes/test__input__patient_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"metadata": {
"patient_id": "P001-2024-001",
"sex": "male",
"timestamp": "2024-11-04T10:00:00Z",
"test_date": "2024-11-04",
"laboratory": "SCORE2-Diabetes Labs"
},
"raw_biomarkers": {
"age_years": {
"value": 45,
"unit": "years"
},
"smoking_yes_no": {
"value": false,
"unit": "yes/no"
},
"systolic_blood_pressure_mmhg": {
"value": 130,
"unit": "mmHg"
},
"total_cholesterol_mmol_l": {
"value": 5.5,
"unit": "mmol/L"
},
"hdl_cholesterol_mmol_l": {
"value": 1.2,
"unit": "mmol/L"
},
"is_male_yes_no": {
"value": true,
"unit": "yes/no"
},
"diabetes_yes_no": {
"value": true,
"unit": "yes/no"
},
"age_at_diabetes_diagnosis_years": {
"value": 40,
"unit": "years"
},
"hba1c_mmol_mol": {
"value": 48,
"unit": "mmol/mol"
},
"egfr_ml_min_1_73m2": {
"value": 90,
"unit": "mL/min/1.73m\u00b2"
}
}
}
51 changes: 51 additions & 0 deletions tests/inputs/score2_diabetes/test__input__patient_02.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"metadata": {
"patient_id": "P002-2024-002",
"sex": "female",
"timestamp": "2024-11-04T10:30:00Z",
"test_date": "2024-11-04",
"laboratory": "SCORE2-Diabetes Labs"
},
"raw_biomarkers": {
"age_years": {
"value": 55,
"unit": "years"
},
"smoking_yes_no": {
"value": true,
"unit": "yes/no"
},
"systolic_blood_pressure_mmhg": {
"value": 145,
"unit": "mmHg"
},
"total_cholesterol_mmol_l": {
"value": 6.8,
"unit": "mmol/L"
},
"hdl_cholesterol_mmol_l": {
"value": 1.1,
"unit": "mmol/L"
},
"is_male_yes_no": {
"value": false,
"unit": "yes/no"
},
"diabetes_yes_no": {
"value": true,
"unit": "yes/no"
},
"age_at_diabetes_diagnosis_years": {
"value": 50,
"unit": "years"
},
"hba1c_mmol_mol": {
"value": 58,
"unit": "mmol/mol"
},
"egfr_ml_min_1_73m2": {
"value": 75,
"unit": "mL/min/1.73m\u00b2"
}
}
}
51 changes: 51 additions & 0 deletions tests/inputs/score2_diabetes/test__input__patient_03.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"metadata": {
"patient_id": "P003-2024-003",
"sex": "male",
"timestamp": "2024-11-04T11:00:00Z",
"test_date": "2024-11-04",
"laboratory": "SCORE2-Diabetes Labs"
},
"raw_biomarkers": {
"age_years": {
"value": 65,
"unit": "years"
},
"smoking_yes_no": {
"value": false,
"unit": "yes/no"
},
"systolic_blood_pressure_mmhg": {
"value": 155,
"unit": "mmHg"
},
"total_cholesterol_mmol_l": {
"value": 7.2,
"unit": "mmol/L"
},
"hdl_cholesterol_mmol_l": {
"value": 0.9,
"unit": "mmol/L"
},
"is_male_yes_no": {
"value": true,
"unit": "yes/no"
},
"diabetes_yes_no": {
"value": true,
"unit": "yes/no"
},
"age_at_diabetes_diagnosis_years": {
"value": 55,
"unit": "years"
},
"hba1c_mmol_mol": {
"value": 68,
"unit": "mmol/mol"
},
"egfr_ml_min_1_73m2": {
"value": 60,
"unit": "mL/min/1.73m\u00b2"
}
}
}
51 changes: 51 additions & 0 deletions tests/inputs/score2_diabetes/test__input__patient_04.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"metadata": {
"patient_id": "P004-2024-004",
"sex": "female",
"timestamp": "2024-11-04T11:30:00Z",
"test_date": "2024-11-04",
"laboratory": "SCORE2-Diabetes Labs"
},
"raw_biomarkers": {
"age_years": {
"value": 48,
"unit": "years"
},
"smoking_yes_no": {
"value": false,
"unit": "yes/no"
},
"systolic_blood_pressure_mmhg": {
"value": 120,
"unit": "mmHg"
},
"total_cholesterol_mmol_l": {
"value": 4.8,
"unit": "mmol/L"
},
"hdl_cholesterol_mmol_l": {
"value": 1.5,
"unit": "mmol/L"
},
"is_male_yes_no": {
"value": false,
"unit": "yes/no"
},
"diabetes_yes_no": {
"value": true,
"unit": "yes/no"
},
"age_at_diabetes_diagnosis_years": {
"value": 45,
"unit": "years"
},
"hba1c_mmol_mol": {
"value": 42,
"unit": "mmol/mol"
},
"egfr_ml_min_1_73m2": {
"value": 100,
"unit": "mL/min/1.73m\u00b2"
}
}
}
51 changes: 51 additions & 0 deletions tests/inputs/score2_diabetes/test__input__patient_05.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"metadata": {
"patient_id": "P005-2024-005",
"sex": "male",
"timestamp": "2024-11-04T12:00:00Z",
"test_date": "2024-11-04",
"laboratory": "SCORE2-Diabetes Labs"
},
"raw_biomarkers": {
"age_years": {
"value": 60,
"unit": "years"
},
"smoking_yes_no": {
"value": true,
"unit": "yes/no"
},
"systolic_blood_pressure_mmhg": {
"value": 150,
"unit": "mmHg"
},
"total_cholesterol_mmol_l": {
"value": 6.5,
"unit": "mmol/L"
},
"hdl_cholesterol_mmol_l": {
"value": 1.0,
"unit": "mmol/L"
},
"is_male_yes_no": {
"value": true,
"unit": "yes/no"
},
"diabetes_yes_no": {
"value": true,
"unit": "yes/no"
},
"age_at_diabetes_diagnosis_years": {
"value": 48,
"unit": "years"
},
"hba1c_mmol_mol": {
"value": 75,
"unit": "mmol/mol"
},
"egfr_ml_min_1_73m2": {
"value": 60,
"unit": "mL/min/1.73m\u00b2"
}
}
}
51 changes: 51 additions & 0 deletions tests/inputs/score2_diabetes/test__input__patient_06.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"metadata": {
"patient_id": "P006-2024-006",
"sex": "female",
"timestamp": "2024-11-04T12:30:00Z",
"test_date": "2024-11-04",
"laboratory": "SCORE2-Diabetes Labs"
},
"raw_biomarkers": {
"age_years": {
"value": 42,
"unit": "years"
},
"smoking_yes_no": {
"value": true,
"unit": "yes/no"
},
"systolic_blood_pressure_mmhg": {
"value": 135,
"unit": "mmHg"
},
"total_cholesterol_mmol_l": {
"value": 6.0,
"unit": "mmol/L"
},
"hdl_cholesterol_mmol_l": {
"value": 1.3,
"unit": "mmol/L"
},
"is_male_yes_no": {
"value": false,
"unit": "yes/no"
},
"diabetes_yes_no": {
"value": true,
"unit": "yes/no"
},
"age_at_diabetes_diagnosis_years": {
"value": 38,
"unit": "years"
},
"hba1c_mmol_mol": {
"value": 53,
"unit": "mmol/mol"
},
"egfr_ml_min_1_73m2": {
"value": 85,
"unit": "mL/min/1.73m\u00b2"
}
}
}
40 changes: 40 additions & 0 deletions tests/test_score2_diabetes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pathlib import Path

import pytest

from vitals.score2_diabetes import compute

OUT_FILEPATH = Path(__file__).parent / "inputs" / "score2_diabetes"


@pytest.mark.parametrize(
"filename,expected",
[
("test__input__patient_01.json", (45.00, 4.40, "High")),
("test__input__patient_02.json", (55.00, 11.80, "Very high")),
("test__input__patient_03.json", (65.00, 18.60, "Very high")),
("test__input__patient_04.json", (48.00, 2.30, "Low to moderate")),
("test__input__patient_05.json", (60.00, 22.30, "Very high")),
("test__input__patient_06.json", (42.00, 5.80, "High")),
],
)
def test_score2_diabetes(filename, expected):
"""
Test SCORE2-Diabetes cardiovascular risk calculation.

NOTE: The expected risk values and categories are placeholders.
They need to be calculated using MDCalc and updated before running tests.
"""
# Get the actual fixture value
age, pred_risk, pred_risk_category = compute.cardiovascular_risk(
OUT_FILEPATH / filename
)
expected_age, expected_risk, expected_category = expected

assert age == expected_age
assert pred_risk_category == expected_category
assert pytest.approx(pred_risk, abs=0.1) == expected_risk


if __name__ == "__main__":
pytest.main([__file__])
2 changes: 1 addition & 1 deletion vitals/biomarkers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from vitals.biomarkers import schemas

Biomarkers = TypeVar("Biomarkers", bound=BaseModel)
Units = schemas.PhenoageUnits | schemas.Score2Units
Units = schemas.PhenoageUnits | schemas.Score2Units | schemas.Score2DiabetesUnits


class ConversionInfo(TypedDict):
Expand Down
33 changes: 33 additions & 0 deletions vitals/biomarkers/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,36 @@ class Score2Markers(BaseModel):
hdl_cholesterol: float
smoking: bool
is_male: bool


# ------ SCORE2-Diabetes Schemas
class Score2DiabetesUnits(BaseModel):
"""
The expected unit to be used for Score2-Diabetes computation
"""

age: str = "years"
systolic_blood_pressure: str = "mmHg"
total_cholesterol: str = "mmol/L"
hdl_cholesterol: str = "mmol/L"
smoking: str = "yes/no"
is_male: str = "yes/no"
diabetes: str = "yes/no"
age_at_diabetes_diagnosis: str = "years"
hba1c: str = "mmol/mol"
egfr: str = "mL/min/1.73m²"


class Score2DiabetesMarkers(BaseModel):
"""Processed Score2-Diabetes biomarkers with standardized units."""

age: float
systolic_blood_pressure: float
total_cholesterol: float
hdl_cholesterol: float
smoking: bool
is_male: bool
diabetes: bool
age_at_diabetes_diagnosis: float
hba1c: float
egfr: float
Loading