Files
WebApi/webapi/eeg.py
T
2026-11-26 07:06:52 -06:00

48 lines
1.0 KiB
Python

"""TEA's EEGs for model governance: every study with its analysis verdict, and one study's
metrics with their age curves' scores."""
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from persistance import eeg
router = APIRouter(prefix="/tea/eegs", tags=["eeg"])
class Study(BaseModel):
id: str # person and study date
person_id: str
study_date: str
lab_record_id: str | None
analysed: bool
valid: bool | None
level: str | None
class Metric(BaseModel):
code: str
value: float
z: float | None
outside: float | None
model: str | None
class Analysis(BaseModel):
id: str
valid: bool | None
level: str | None
age_months: float | None
metrics: list[Metric]
@router.get("")
def studies() -> list[Study]:
return [Study(**s) for s in eeg.studies()]
@router.get("/{eeg_id}")
def study(eeg_id: str) -> Analysis:
if (found := eeg.study(eeg_id)) is None:
raise HTTPException(404, detail=f"no analysed EEG {eeg_id}")
return Analysis(**found)