75 lines
1.5 KiB
Python
75 lines
1.5 KiB
Python
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_id: str
|
|
study_date: str
|
|
lab_record_id: str | None
|
|
analysed: bool
|
|
valid: bool | None
|
|
level: str | None
|
|
|
|
|
|
class Site(BaseModel):
|
|
site: str
|
|
value: float
|
|
z: float | None
|
|
|
|
|
|
class Metric(BaseModel):
|
|
code: str
|
|
value: float
|
|
z: float | None
|
|
outside: float | None
|
|
p5: float | None = None
|
|
median: float | None = None
|
|
p95: float | None = None
|
|
model: str | None
|
|
zones: list[Site] = []
|
|
electrodes: list[Site] = []
|
|
|
|
|
|
class Relation(BaseModel):
|
|
biomarker: str
|
|
metric: str
|
|
zone: str
|
|
outcome_code: str
|
|
kind: str
|
|
event: str
|
|
z: float
|
|
probability: float
|
|
reference_probability: float
|
|
observed: float | None = None
|
|
odds_ratio: float
|
|
ci_low: float | None
|
|
ci_high: float | None
|
|
q: float | None
|
|
n: float
|
|
model: str
|
|
|
|
|
|
class Analysis(BaseModel):
|
|
id: str
|
|
valid: bool | None
|
|
level: str | None
|
|
age_months: float | None
|
|
metrics: list[Metric]
|
|
relation: list[Relation] = []
|
|
|
|
|
|
@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)
|