"""Import schema for `core.tea.models.Pacientes`. All fields optional, like TEA's Core; system-managed `pac_created_at`/`pac_updated_at`/`pac_fuente_sistema` are excluded. `pac_id` is importable: every other TEA table references the patient by the source system's integer id, so it has to be kept, not renumbered.""" from datetime import date from typing import Optional from pydantic import field_validator from core.tea.enums import Parentesco, SexoBiologico from webapi.imports.schemas.base import ImportSchema from webapi.imports.schemas.coercion import Catalog, CatalogValue, coerce_date, optional_str _SEXO_CATALOG = Catalog(SexoBiologico) _PARENTESCO_CATALOG = Catalog(Parentesco) class PacientesImportSchema(ImportSchema): pac_id: Optional[int] = None pac_id_hospital: Optional[str] = None pac_id_titular: Optional[str] = None pac_parentesco: CatalogValue(_PARENTESCO_CATALOG) = None pac_fecha_nacimiento: Optional[date] = None pac_sexo: CatalogValue(_SEXO_CATALOG) = None pac_codigo_postal_vigente: Optional[str] = None pac_dependencia: Optional[str] = None @field_validator("pac_id_hospital", "pac_id_titular", "pac_codigo_postal_vigente", "pac_dependencia", mode="before") @classmethod def _optional_str_fields(cls, v): return optional_str(v) @field_validator("pac_fecha_nacimiento", mode="before") @classmethod def _coerce_fecha_nacimiento(cls, v): return coerce_date(v)