Skip to content

Add input validation for biomarker ranges in SCORE2 #10

@fbraza

Description

@fbraza

Issue Description

The SCORE2 and SCORE2-Diabetes implementations don't validate that biomarker values are within reasonable physiological ranges, which could lead to incorrect risk calculations.

Suggested Validation Ranges

SCORE2 Biomarkers

SCORE2_RANGES = {
    'systolic_blood_pressure': (70, 250),    # mmHg
    'total_cholesterol': (2.0, 15.0),        # mmol/L
    'hdl_cholesterol': (0.5, 5.0),           # mmol/L
}

SCORE2-Diabetes Additional Biomarkers

SCORE2_DIABETES_RANGES = {
    # All SCORE2 ranges plus:
    'age_at_diabetes_diagnosis': (0, 120),   # years (cannot exceed current age)
    'hba1c': (20, 200),                      # mmol/mol (normal: 42-47, diabetes: >47)
    'egfr': (5, 150),                        # mL/min/1.73m² (very low to normal+)
}

Implementation Suggestion

For SCORE2 (vitals/score2/compute.py):

def validate_score2_biomarkers(biomarkers: schemas.Score2Markers) -> None:
    """Validate that SCORE2 biomarker values are within reasonable ranges."""
    
    # Validate SBP
    if not (70 <= biomarkers.systolic_blood_pressure <= 250):
        raise ValueError(
            f"Systolic blood pressure {biomarkers.systolic_blood_pressure} mmHg "
            f"is outside reasonable range (70-250 mmHg)"
        )
    
    # Validate total cholesterol
    if not (2.0 <= biomarkers.total_cholesterol <= 15.0):
        raise ValueError(
            f"Total cholesterol {biomarkers.total_cholesterol} mmol/L "
            f"is outside reasonable range (2.0-15.0 mmol/L)"
        )
    
    # Validate HDL cholesterol
    if not (0.5 <= biomarkers.hdl_cholesterol <= 5.0):
        raise ValueError(
            f"HDL cholesterol {biomarkers.hdl_cholesterol} mmol/L "
            f"is outside reasonable range (0.5-5.0 mmol/L)"
        )
    
    # HDL should not exceed total cholesterol
    if biomarkers.hdl_cholesterol > biomarkers.total_cholesterol:
        raise ValueError(
            f"HDL cholesterol ({biomarkers.hdl_cholesterol}) cannot exceed "
            f"total cholesterol ({biomarkers.total_cholesterol})"
        )

For SCORE2-Diabetes (vitals/score2_diabetes/compute.py):

def validate_score2_diabetes_biomarkers(biomarkers: schemas.Score2DiabetesMarkers) -> None:
    """Validate that SCORE2-Diabetes biomarker values are within reasonable ranges."""
    
    # Validate all SCORE2 ranges (reuse logic)
    # ... same SBP, cholesterol validations ...
    
    # Validate diabetes-specific biomarkers
    if not (0 <= biomarkers.age_at_diabetes_diagnosis <= biomarkers.age):
        raise ValueError(
            f"Age at diabetes diagnosis ({biomarkers.age_at_diabetes_diagnosis}) "
            f"cannot exceed current age ({biomarkers.age})"
        )
    
    if not (20 <= biomarkers.hba1c <= 200):
        raise ValueError(
            f"HbA1c {biomarkers.hba1c} mmol/mol is outside reasonable range (20-200 mmol/mol)"
        )
    
    if not (5 <= biomarkers.egfr <= 150):
        raise ValueError(
            f"eGFR {biomarkers.egfr} mL/min/1.73m² is outside reasonable range (5-150)"
        )

Benefits

Considerations

  • Ranges should be reviewed by medical experts
  • Consider whether to error or warn for edge cases
  • May need different ranges for different populations
  • eGFR lower bound (5) prevents logarithm calculation errors in SCORE2-Diabetes

Related

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions