from __future__ import annotations from enum import Enum from pydantic import BaseModel, Field class Flag(str, Enum): NORMAL = "normal" LOW = "low" HIGH = "high" CRITICAL_LOW = "critical_low" CRITICAL_HIGH = "critical_high" UNKNOWN = "unknown" # could not be judged (no range, unknown unit) CHECK = "check" # value is physically implausible: probably misread, ask the user class Result(BaseModel): """One test line read from a report.""" test_key: str | None = None raw_name: str value: float unit: str | None = None ref_low: float | None = None ref_high: float | None = None ref_source: str = "report" # "report" | "catalog" | "none" match_score: float = 0.0 source_line: str = "" report_marker: str | None = None # "H" / "L" / "*" printed next to the value by the lab class FlaggedResult(Result): flag: Flag = Flag.UNKNOWN canonical_value: float | None = None reason: str = "" class Analysis(BaseModel): language: str = "en" results: list[FlaggedResult] = Field(default_factory=list) unmatched_lines: list[str] = Field(default_factory=list) urgent: bool = False extraction_method: str = ""