From 4a61bd8d33287044e0c7f489299a8d1671d78405 Mon Sep 17 00:00:00 2001 From: edgar Date: Sun, 22 Nov 2026 15:03:22 -0600 Subject: [PATCH] CaCu import: a patient's date of death `pac_fecha_defuncion` was dropped on import, so `persona.fecha_defuncion` and the timeline's `defuncion` fact were always empty in CaCu and the survival scenario trained with no deaths. CaMa's schema already carried it. --- tests/test_schemas.py | 12 ++++++++++++ webapi/imports/schemas/cacu/paciente.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/tests/test_schemas.py b/tests/test_schemas.py index 1881fe9..4d07a5f 100644 --- a/tests/test_schemas.py +++ b/tests/test_schemas.py @@ -43,6 +43,18 @@ def test_paciente_schema_coerces_date_from_datetime_object(): assert schema.pac_fecha_nacimiento.isoformat() == "2020-01-15" +def test_cacu_paciente_keeps_her_date_of_death(): + """Pins down: a CaCu patient's `pac_fecha_defuncion` is imported (the survival scenario's outcome), and an alive + patient has none. Fails if the schema drops the column again: every CaCu death would be lost on import and the + survival model would train with no deaths.""" + from datetime import date + + dead = PacienteImportSchema(pac_id_hospital="H-1", pac_fecha_nacimiento="1960-03-01", pac_fecha_defuncion="2025-07-09") + alive = PacienteImportSchema(pac_id_hospital="H-2", pac_fecha_nacimiento="1960-03-01") + + assert dead.pac_fecha_defuncion == date(2025, 7, 9) and alive.pac_fecha_defuncion is None + + def test_tea_pacientes_schema_is_fully_optional(): schema = PacientesImportSchema() assert schema.pac_id_hospital is None diff --git a/webapi/imports/schemas/cacu/paciente.py b/webapi/imports/schemas/cacu/paciente.py index 49393dc..1f38733 100644 --- a/webapi/imports/schemas/cacu/paciente.py +++ b/webapi/imports/schemas/cacu/paciente.py @@ -6,6 +6,7 @@ from webapi.imports.schemas.base import ImportSchema from webapi.imports.schemas.coercion import ( Catalog, CatalogValue, + FlexDate, PostalCode, RequiredDate, RequiredHospitalId, @@ -25,6 +26,8 @@ class PacienteImportSchema(ImportSchema): pac_sexo: CatalogValue(_SEXO_BIOLOGICO_CATALOG) = None # IND-01: required, since age at each event of interest is derived from it. pac_fecha_nacimiento: RequiredDate + # Survival's outcome; empty while she is alive or the date is unknown. + pac_fecha_defuncion: FlexDate = None pac_codigo_postal: PostalCode = None pac_dependencia: CatalogValue(_DEPENDENCIA_CATALOG) = None pac_parentesco: CatalogValue(_PARENTESCO_CATALOG) = None