Spaces:
Sleeping
Sleeping
File size: 2,821 Bytes
6dc9d46 696f787 6dc9d46 696f787 6dc9d46 696f787 6dc9d46 9659593 6dc9d46 9659593 6dc9d46 696f787 6dc9d46 696f787 7caf4dc 6dc9d46 696f787 6dc9d46 696f787 6dc9d46 696f787 6dc9d46 696f787 6dc9d46 9659593 6dc9d46 9659593 6dc9d46 696f787 6dc9d46 9659593 6dc9d46 696f787 6dc9d46 696f787 6dc9d46 9659593 6dc9d46 696f787 7caf4dc 696f787 6dc9d46 9659593 | 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 | """
Biomarkers List Endpoint
"""
import json
from datetime import datetime
from pathlib import Path
from fastapi import APIRouter, HTTPException
from app.models.schemas import BiomarkerInfo, BiomarkerReferenceRange, BiomarkersListResponse
router = APIRouter(prefix="/api/v1", tags=["biomarkers"])
@router.get("/biomarkers", response_model=BiomarkersListResponse)
async def list_biomarkers():
"""
Get list of all supported biomarkers with reference ranges.
Returns comprehensive information about all 24 biomarkers:
- Name and unit
- Normal reference ranges (gender-specific if applicable)
- Critical thresholds
- Clinical significance
Useful for:
- Frontend validation
- Understanding what biomarkers can be analyzed
- Getting reference ranges for display
"""
try:
# Load biomarker references
config_path = Path(__file__).parent.parent.parent.parent / "config" / "biomarker_references.json"
with open(config_path, encoding="utf-8") as f:
config_data = json.load(f)
biomarkers_data = config_data.get("biomarkers", {})
biomarkers_list = []
for name, info in biomarkers_data.items():
# Parse reference range
normal_range_data = info.get("normal_range", {})
if "male" in normal_range_data or "female" in normal_range_data:
# Gender-specific ranges
reference_range = BiomarkerReferenceRange(
min=None, max=None, male=normal_range_data.get("male"), female=normal_range_data.get("female")
)
else:
# Universal range
reference_range = BiomarkerReferenceRange(
min=normal_range_data.get("min"), max=normal_range_data.get("max"), male=None, female=None
)
biomarker_info = BiomarkerInfo(
name=name,
unit=info.get("unit", ""),
normal_range=reference_range,
critical_low=info.get("critical_low"),
critical_high=info.get("critical_high"),
gender_specific=info.get("gender_specific", False),
description=info.get("description", ""),
clinical_significance=info.get("clinical_significance", {}),
)
biomarkers_list.append(biomarker_info)
return BiomarkersListResponse(
biomarkers=biomarkers_list, total_count=len(biomarkers_list), timestamp=datetime.now().isoformat()
)
except FileNotFoundError as exc:
raise HTTPException(status_code=500, detail="Biomarker configuration file not found") from exc
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to load biomarkers: {e!s}") from e
|