38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
"""Import schema for `core.cama.models.Mastografia`."""
|
|
from datetime import date
|
|
from typing import Optional
|
|
|
|
from pydantic import field_validator
|
|
|
|
from core.cama.enums import BIRADS, BIRADS_ALIAS
|
|
from webapi.imports.schemas.base import ImportSchema
|
|
from webapi.imports.schemas.coercion import Catalog, CatalogValue, HospitalId, coerce_date, required_str
|
|
|
|
_BIRADS_CATALOG = Catalog(BIRADS, BIRADS_ALIAS)
|
|
|
|
|
|
class MastografiaImportSchema(ImportSchema):
|
|
# The source's own id, kept so rows that reference it by id (not by a
|
|
# natural key) still point at this record.
|
|
mast_id: Optional[int] = None
|
|
pac_id: Optional[int] = None
|
|
pac_id_hospital: HospitalId
|
|
ord_id: Optional[int] = None
|
|
ord_numero_hospital: Optional[int] = None
|
|
mast_fecha_toma: Optional[date] = None
|
|
mast_fecha_reporte: Optional[date] = None
|
|
mast_calidad_imagen: Optional[str] = None
|
|
mast_birads: CatalogValue(_BIRADS_CATALOG) = None
|
|
mast_dicom_blob: Optional[bytes] = None
|
|
mast_interpretacion: Optional[str] = None
|
|
|
|
@field_validator("pac_id_hospital", mode="before")
|
|
@classmethod
|
|
def _required_pac_id_hospital(cls, v):
|
|
return required_str(v, field_name="pac_id_hospital")
|
|
|
|
@field_validator("mast_fecha_toma", "mast_fecha_reporte", mode="before")
|
|
@classmethod
|
|
def _coerce_dates(cls, v):
|
|
return coerce_date(v)
|