Files
ISSSTELEON/Core/core/schema.py
T
alberto 781e1ea75a C1a: code only, no comments, no Markdown
The four Markdown files (README.md, tests/fixtures/ados2_items_by_module.md, tools/delivery/README.md, tools/delivery/README.repo.md) live in the outer repo under docs/ISSSTELEON; the delivery scripts no longer produce a README and the ADOS-2 expected values stay in the Python test.
2026-12-01 16:56:14 -06:00

60 lines
1.6 KiB
Python

import re
from datetime import date
from enum import StrEnum
from typing import ClassVar
from pydantic import BaseModel, ConfigDict, Field, field_validator
from core import catalog
class Sex(StrEnum):
FEMALE = "female"
MALE = "male"
IDENTIFIER_SYSTEMS = {
"curp": "https://isssteleon.org/fhir/sid/curp",
"nss": "https://isssteleon.org/fhir/sid/nss",
}
RECORD_NUMBER_SYSTEM = "urn:isssteleon:"
_DATE = re.compile(r"\d{1,4}[/.-]\d{1,2}[/.-]\d{1,4}")
class Entity(BaseModel):
model_config = ConfigDict(extra="forbid", str_strip_whitespace=True)
key: ClassVar[tuple[str, ...]] = ()
class Identity(Entity):
model_config = ConfigDict(
json_schema_extra={
"description": (
"What a record says about whom it belongs to. "
"Input to linkage, never trusted alone."
)
}
)
record_number: str | None = Field(None, title="Número de expediente")
full_name: str | None = Field(None, title="Nombre completo")
curp: str | None = Field(None, title="CURP")
nss: str | None = Field(None, title="NSS")
birth_date: date | None = Field(None, title="Fecha de nacimiento")
sex: Sex | None = Field(None, title="Sexo")
@field_validator("record_number")
@classmethod
def _not_a_date(cls, v: str | None) -> str | None:
if v is not None and _DATE.fullmatch(v.strip()):
raise ValueError("a date is not a record number")
return v
ENTITIES: dict[str, type[BaseModel]] = {
"identity": Identity,
**{name: catalog.model(name) for name in catalog.studies()},
}