File size: 1,211 Bytes
dab7db2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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 = ""