From 0e2a5d92cf9ea3e7e395adc0f32cf99ab9684f24 Mon Sep 17 00:00:00 2001 From: ulises Date: Sun, 22 Nov 2026 08:47:00 -0600 Subject: [PATCH 01/15] CaMa recurrence: bronze variables, follow-up table, catalog, timeline and submodule pointers The patient carries the menopausal state, molecular and clinical subtype, integrative cluster, cellularity, mutation load, Ki-67 category and source of the record; `seguimientomama` holds the recurrence and the last contact; hormone and anti-HER2 therapy are treatments, with an explicit "no treatment" value. One alembic revision on survival's chain, the catalog studies and the timeline entries. Includes the survival bronze and total-cohort work this builds on. Co-Authored-By: Claude Sonnet 5.5 --- Core/core/cama/biopsia_mama/model.py | 72 ++++++++ Core/core/cama/mastografia/model.py | 12 ++ Core/core/cama/models.py | 4 + Core/core/cama/nota_medica/model.py | 8 + Core/core/cama/paciente/model.py | 48 ++++++ Core/core/cama/seguimiento_mama/__init__.py | 0 Core/core/cama/seguimiento_mama/model.py | 39 +++++ Core/core/cama/tratamiento_mama/__init__.py | 0 Core/core/cama/tratamiento_mama/model.py | 43 +++++ Core/core/catalogos/cama.toml | 160 +++++++++++++++++- Persistance/persistance/cama/__init__.py | 4 + ...a82c57_structured_results_and_treatment.py | 98 +++++++++++ .../c7e2a5f9b413_recurrence_variables.py | 56 ++++++ Persistance/persistance/edges/dbt.py | 13 +- .../persistance/edges/silver/procedures.py | 8 +- Transformation/dbt_project.yml | 3 + .../models/cama/cohorts/total/cama_total.yml | 17 ++ .../cohorts/total/cama_total_all_patients.sql | 3 + .../cohorts/total/cama_total_index_date.sql | 13 ++ .../cama/silver/cama_linea_de_tiempo.yml | 14 ++ WebApi | 2 +- WebApp | 2 +- models | 2 +- 23 files changed, 606 insertions(+), 15 deletions(-) create mode 100644 Core/core/cama/seguimiento_mama/__init__.py create mode 100644 Core/core/cama/seguimiento_mama/model.py create mode 100644 Core/core/cama/tratamiento_mama/__init__.py create mode 100644 Core/core/cama/tratamiento_mama/model.py create mode 100644 Persistance/persistance/cama/alembic/versions/b6d1f4a82c57_structured_results_and_treatment.py create mode 100644 Persistance/persistance/cama/alembic/versions/c7e2a5f9b413_recurrence_variables.py create mode 100644 Transformation/models/cama/cohorts/total/cama_total.yml create mode 100644 Transformation/models/cama/cohorts/total/cama_total_all_patients.sql create mode 100644 Transformation/models/cama/cohorts/total/cama_total_index_date.sql diff --git a/Core/core/cama/biopsia_mama/model.py b/Core/core/cama/biopsia_mama/model.py index 9398353..b2c3530 100644 --- a/Core/core/cama/biopsia_mama/model.py +++ b/Core/core/cama/biopsia_mama/model.py @@ -49,6 +49,78 @@ class BiopsiaMama(CaMaModel, table=True): default=None, sa_column=sa.Column(sa.Text), ) + bx_tipo_histologico: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_grado_nottingham: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_receptor_estrogeno: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_receptor_estrogeno_pct: Optional[float] = Field( + default=None, + sa_column=sa.Column(sa.Float), + ) + bx_receptor_progesterona: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_receptor_progesterona_pct: Optional[float] = Field( + default=None, + sa_column=sa.Column(sa.Float), + ) + bx_her2: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_her2_fish: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_ki67_pct: Optional[float] = Field( + default=None, + sa_column=sa.Column(sa.Float), + ) + bx_tamano_tumor_mm: Optional[float] = Field( + default=None, + sa_column=sa.Column(sa.Float), + ) + bx_ganglios_positivos: Optional[float] = Field( + default=None, + sa_column=sa.Column(sa.Float), + ) + bx_invasion_linfovascular: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_multifocalidad: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_margenes: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_pt: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_pn: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_lateralidad: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + bx_localizacion: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) bx_pdf_blob: Optional[bytes] = Field( default=None, sa_column=sa.Column(FileBlob), diff --git a/Core/core/cama/mastografia/model.py b/Core/core/cama/mastografia/model.py index 07d4dfe..031b88f 100644 --- a/Core/core/cama/mastografia/model.py +++ b/Core/core/cama/mastografia/model.py @@ -58,5 +58,17 @@ class Mastografia(CaMaModel, table=True): sa_column=sa.Column(sa.Text), description="enlace o referencia a la interpretación del radiólogo; formato pendiente", ) + mast_densidad: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + mast_margen_masa: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + mast_tipo_hallazgo: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) diff --git a/Core/core/cama/models.py b/Core/core/cama/models.py index 5957b77..bdb9827 100644 --- a/Core/core/cama/models.py +++ b/Core/core/cama/models.py @@ -5,6 +5,8 @@ from core.cama.biopsia_mama.model import BiopsiaMama from core.cama.nota_medica.model import NotaMedica from core.cama.biometria_hematica.model import BiometriaHematica from core.cama.episodio_clinico.model import EpisodioClinico +from core.cama.tratamiento_mama.model import TratamientoMama +from core.cama.seguimiento_mama.model import SeguimientoMama __all__ = [ "Paciente", @@ -14,4 +16,6 @@ __all__ = [ "NotaMedica", "BiometriaHematica", "EpisodioClinico", + "TratamientoMama", + "SeguimientoMama", ] diff --git a/Core/core/cama/nota_medica/model.py b/Core/core/cama/nota_medica/model.py index b880229..6326c64 100644 --- a/Core/core/cama/nota_medica/model.py +++ b/Core/core/cama/nota_medica/model.py @@ -69,6 +69,14 @@ class NotaMedica(CaMaModel, table=True): default=None, sa_column=sa.Column(sa.Text), ) + nm_estadio_clinico: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + nm_metastasis: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) nm_tratamiento_texto: Optional[str] = Field( default=None, sa_column=sa.Column(sa.Text), diff --git a/Core/core/cama/paciente/model.py b/Core/core/cama/paciente/model.py index b971172..9ffaff3 100644 --- a/Core/core/cama/paciente/model.py +++ b/Core/core/cama/paciente/model.py @@ -33,6 +33,54 @@ class Paciente(CaMaModel, table=True): default=None, sa_column=sa.Column(sa.Date), ) + pac_estado_civil: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_raza: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_brca1: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_brca2: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_estado_menopausico: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_pam50: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_subtipo_clinico: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_cluster_integrativo: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_celularidad: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_carga_mutacional: Optional[float] = Field( + default=None, + sa_column=sa.Column(sa.Float), + ) + pac_ki67_categoria: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + pac_fuente: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) pac_codigo_postal: Optional[str] = Field( default=None, sa_column=sa.Column( diff --git a/Core/core/cama/seguimiento_mama/__init__.py b/Core/core/cama/seguimiento_mama/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Core/core/cama/seguimiento_mama/model.py b/Core/core/cama/seguimiento_mama/model.py new file mode 100644 index 0000000..0992eda --- /dev/null +++ b/Core/core/cama/seguimiento_mama/model.py @@ -0,0 +1,39 @@ +from datetime import date +from typing import Optional + +import sqlalchemy as sa +from sqlmodel import Field +from core.cama.base import CaMaModel +from core.columns import HOSPITAL_ID_LENGTH + + +class SeguimientoMama(CaMaModel, table=True): + """ + Un hecho del seguimiento de la paciente: una recaída o el último contacto, con su fecha. + `seg_tipo` es el estudio del catálogo (`recurrencia`, `ultimo_contacto`); `seg_detalle`, su resultado: + el sitio de la recaída. + """ + + seg_id: Optional[int] = Field( + default=None, + sa_column=sa.Column(sa.Integer, primary_key=True, autoincrement=True), + ) + pac_id: Optional[int] = Field( + default=None, + sa_column=sa.Column(sa.Integer, index=True), + description="rellenado por el loader via lookup en paciente.pac_id_hospital", + ) + pac_id_hospital: str = Field( + sa_column=sa.Column(sa.String(HOSPITAL_ID_LENGTH), index=True, nullable=False), + ) + seg_tipo: str = Field( + sa_column=sa.Column(sa.Text, nullable=False), + ) + seg_fecha: Optional[date] = Field( + default=None, + sa_column=sa.Column(sa.Date), + ) + seg_detalle: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) diff --git a/Core/core/cama/tratamiento_mama/__init__.py b/Core/core/cama/tratamiento_mama/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Core/core/cama/tratamiento_mama/model.py b/Core/core/cama/tratamiento_mama/model.py new file mode 100644 index 0000000..90a3a73 --- /dev/null +++ b/Core/core/cama/tratamiento_mama/model.py @@ -0,0 +1,43 @@ +from datetime import date +from typing import Optional + +import sqlalchemy as sa +from sqlmodel import Field +from core.cama.base import CaMaModel +from core.columns import HOSPITAL_ID_LENGTH + + +class TratamientoMama(CaMaModel, table=True): + """ + Un tratamiento del cáncer de mama: una cirugía, un curso de radioterapia o uno de quimioterapia, con su fecha. + `trat_tipo` es el estudio del catálogo (`cirugia`, `radioterapia`, `quimioterapia`); `trat_detalle`, su resultado: + el tipo de cirugía o la intención del curso. + """ + + trat_id: Optional[int] = Field( + default=None, + sa_column=sa.Column(sa.Integer, primary_key=True, autoincrement=True), + ) + pac_id: Optional[int] = Field( + default=None, + sa_column=sa.Column(sa.Integer, index=True), + description="rellenado por el loader via lookup en paciente.pac_id_hospital", + ) + pac_id_hospital: str = Field( + sa_column=sa.Column(sa.String(HOSPITAL_ID_LENGTH), index=True, nullable=False), + ) + trat_tipo: str = Field( + sa_column=sa.Column(sa.Text, nullable=False), + ) + trat_fecha: Optional[date] = Field( + default=None, + sa_column=sa.Column(sa.Date), + ) + trat_detalle: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) + trat_lateralidad: Optional[str] = Field( + default=None, + sa_column=sa.Column(sa.Text), + ) diff --git a/Core/core/catalogos/cama.toml b/Core/core/catalogos/cama.toml index 16b6a9c..10db0e8 100644 --- a/Core/core/catalogos/cama.toml +++ b/Core/core/catalogos/cama.toml @@ -118,7 +118,6 @@ etiquetas_fuente = ["Tamaño de la lesión", "Tamaño del nódulo", "Diámetro m [mastografia.resultados.localizacion] etiqueta = "Localización en la mama" tipo_valor = "codigo" -sistema = "CIE-10" provisional = true etiquetas_fuente = ["Localización", "Cuadrante", "Sitio"] valores = [ @@ -170,7 +169,6 @@ valores = [ [biopsia.resultados.localizacion] etiqueta = "Localización en la mama" tipo_valor = "codigo" -sistema = "CIE-10" provisional = true etiquetas_fuente = ["Localización", "Cuadrante", "Sitio", "Topografía"] valores = [ @@ -208,7 +206,6 @@ valores = [ [biopsia.resultados.tipo_histologico] etiqueta = "Tipo histológico (OMS)" tipo_valor = "codigo" -sistema = "CIE-O-3" provisional = true etiquetas_fuente = ["Tipo histológico", "Diagnóstico histopatológico", "Diagnóstico", "Variedad histológica"] buscar_en_texto = true @@ -414,7 +411,6 @@ etiquetas_fuente = ["Ganglios positivos", "Ganglios con metástasis", "Ganglios [biopsia.resultados.pt] etiqueta = "T patológica (pT)" tipo_valor = "codigo" -sistema = "TNM-AJCC" provisional = true etiquetas_fuente = ["pT", "T patológica", "Tumor primario (pT)"] valores = [ @@ -438,7 +434,6 @@ valores = [ [biopsia.resultados.pn] etiqueta = "N patológica (pN)" tipo_valor = "codigo" -sistema = "TNM-AJCC" provisional = true etiquetas_fuente = ["pN", "N patológica", "Ganglios linfáticos regionales (pN)"] valores = [ @@ -459,6 +454,7 @@ valores = [ { valor = "LIBRES", etiqueta = "Libres", alias = ["Libres", "Negativos", "Libres de neoplasia", "Sin neoplasia"] }, { valor = "CERCANOS", etiqueta = "Cercanos", alias = ["Cercanos", "Próximos"] }, { valor = "AFECTADOS", etiqueta = "Afectados", alias = ["Afectados", "Positivos", "Comprometidos", "Con neoplasia"] }, + { valor = "SIN_CIRUGIA", etiqueta = "Sin cirugía" }, ] [biopsia.resultados.multicentricidad] @@ -535,7 +531,6 @@ valores = [ [nota_medica.resultados.ct] etiqueta = "T clínica (cT)" tipo_valor = "codigo" -sistema = "TNM-AJCC" provisional = true etiquetas_fuente = ["cT", "T clínica", "Tumor primario"] valores = [ @@ -559,7 +554,6 @@ valores = [ [nota_medica.resultados.cn] etiqueta = "N clínica (cN)" tipo_valor = "codigo" -sistema = "TNM-AJCC" provisional = true etiquetas_fuente = ["cN", "N clínica", "Ganglios linfáticos regionales"] valores = [ @@ -573,7 +567,6 @@ valores = [ [nota_medica.resultados.m] etiqueta = "Metástasis a distancia (M)" tipo_valor = "codigo" -sistema = "TNM-AJCC" provisional = true etiquetas_fuente = ["Metástasis a distancia", "Metástasis distante", "cM"] valores = [ @@ -708,6 +701,34 @@ valores = [ { valor = "VIUDA", etiqueta = "Viuda", alias = ["Viuda", "Viudo", "V"] }, ] +[sociodemografico.resultados.raza] +etiqueta = "Raza" +tipo_valor = "codigo" +etiquetas_fuente = ["Raza"] +valores = [ + { valor = "BLANCA", etiqueta = "Blanca", alias = ["Blanca", "Blanco"] }, + { valor = "NEGRA", etiqueta = "Negra", alias = ["Negra", "Negro"] }, + { valor = "OTRA", etiqueta = "Otra (indígena americana, asiática o de las islas del Pacífico)", alias = ["Otra", "Indígena", "Asiática"] }, +] + +[sociodemografico.resultados.estado_menopausico] +etiqueta = "Estado menopáusico" +tipo_valor = "codigo" +valores = [ + { valor = "PREMENOPAUSIA", etiqueta = "Premenopausia" }, + { valor = "POSMENOPAUSIA", etiqueta = "Posmenopausia" }, +] + +[sociodemografico.resultados.fuente] +etiqueta = "Fuente del registro" +tipo_valor = "codigo" +valores = [ + { valor = "METABRIC", etiqueta = "METABRIC" }, + { valor = "SCANB", etiqueta = "SCAN-B" }, + { valor = "SEER", etiqueta = "SEER" }, + { valor = "ISSSTELEON", etiqueta = "ISSSTELEON" }, +] + # The BRCA1 and BRCA2 test (7.1.1.1.7, 7.5.3): `orden`, `toma` and its `reporte`. Each gene gets the class of the # variant found, in the ACMG/AMP five tiers, or NEGATIVO when the report finds none. [prueba_genetica] @@ -764,6 +785,9 @@ valores = [ { valor = "SEGMENTECTOMIA", etiqueta = "Segmentectomía o cuadrantectomía" }, { valor = "MASTECTOMIA_TOTAL", etiqueta = "Mastectomía total" }, { valor = "MASTECTOMIA_RADICAL_MODIFICADA", etiqueta = "Mastectomía radical modificada" }, + { valor = "SIN_CIRUGIA", etiqueta = "Sin cirugía" }, + { valor = "DESTRUCCION_LOCAL", etiqueta = "Destrucción local" }, + { valor = "CIRUGIA_NO_ESPECIFICADA", etiqueta = "Cirugía sin especificar" }, ] [cirugia.resultados.cirugia_axilar] @@ -785,6 +809,7 @@ valores = [ { valor = "NEOADYUVANTE", etiqueta = "Neoadyuvante" }, { valor = "ADYUVANTE", etiqueta = "Adyuvante" }, { valor = "PALIATIVA", etiqueta = "Paliativa" }, + { valor = "NINGUNA", etiqueta = "Sin tratamiento" }, ] [radioterapia.resultados.lateralidad] @@ -811,6 +836,7 @@ valores = [ { valor = "NEOADYUVANTE", etiqueta = "Neoadyuvante" }, { valor = "ADYUVANTE", etiqueta = "Adyuvante" }, { valor = "PALIATIVA", etiqueta = "Paliativa" }, + { valor = "NINGUNA", etiqueta = "Sin tratamiento" }, ] [quimioterapia.resultados.fecha_fin] @@ -863,3 +889,121 @@ valores = [ # factores_riesgo breastfeeding (7.1.1.6), implants (Apéndice Informativo D) # treatment reconstruction (10.2.3); radiotherapy's dose, fractions and site; chemotherapy's cycles and # regimen; hormone and biological therapy (10.2.5.4, 10.2.5.5) + +# Molecular and clinical profile of the tumour as the registry gives it. +[perfil_molecular] +etiqueta = "Perfil molecular y clínico del tumor" + +[perfil_molecular.resultados.pam50] +etiqueta = "Subtipo PAM50" +tipo_valor = "codigo" +valores = [ + { valor = "LUMA", etiqueta = "Luminal A" }, + { valor = "LUMB", etiqueta = "Luminal B" }, + { valor = "HER2", etiqueta = "HER2-enriquecido" }, + { valor = "BASAL", etiqueta = "Basal" }, + { valor = "CLAUDIN_LOW", etiqueta = "Claudin-low" }, + { valor = "NORMAL", etiqueta = "Normal-like" }, + { valor = "NC", etiqueta = "No clasificado" }, +] + +[perfil_molecular.resultados.subtipo_clinico] +etiqueta = "Subtipo clínico" +tipo_valor = "codigo" +valores = [ + { valor = "LUMINAL_A", etiqueta = "Luminal A" }, + { valor = "LUMINAL_B_HER2_NEG", etiqueta = "Luminal B HER2 negativo" }, + { valor = "LUMINAL_B_HER2_POS", etiqueta = "Luminal B HER2 positivo" }, + { valor = "BASAL_LIKE", etiqueta = "Basal-like" }, + { valor = "NO_LUMINAL_HER2_POS", etiqueta = "No luminal HER2 positivo" }, + { valor = "LUMINAL_NO_DETERMINADO", etiqueta = "Luminal sin determinar" }, + { valor = "RE_NEG_NO_DETERMINADO", etiqueta = "RE negativo sin determinar" }, +] + +[perfil_molecular.resultados.cluster_integrativo] +etiqueta = "Clúster integrativo" +tipo_valor = "codigo" +valores = [ + { valor = "IC1", etiqueta = "Clúster 1" }, + { valor = "IC2", etiqueta = "Clúster 2" }, + { valor = "IC3", etiqueta = "Clúster 3" }, + { valor = "IC4ERP", etiqueta = "Clúster 4 RE+" }, + { valor = "IC4ERN", etiqueta = "Clúster 4 RE-" }, + { valor = "IC5", etiqueta = "Clúster 5" }, + { valor = "IC6", etiqueta = "Clúster 6" }, + { valor = "IC7", etiqueta = "Clúster 7" }, + { valor = "IC8", etiqueta = "Clúster 8" }, + { valor = "IC9", etiqueta = "Clúster 9" }, + { valor = "IC10", etiqueta = "Clúster 10" }, +] + +[perfil_molecular.resultados.celularidad] +etiqueta = "Celularidad" +tipo_valor = "codigo" +valores = [ + { valor = "ALTA", etiqueta = "Alta" }, + { valor = "MODERADA", etiqueta = "Moderada" }, + { valor = "BAJA", etiqueta = "Baja" }, +] + +[perfil_molecular.resultados.carga_mutacional] +etiqueta = "Carga mutacional (número de mutaciones)" +tipo_valor = "numero" + +[perfil_molecular.resultados.ki67_categoria] +etiqueta = "Ki-67 por categoría" +tipo_valor = "codigo" +valores = [ + { valor = "BAJO", etiqueta = "Bajo" }, + { valor = "INTERMEDIO", etiqueta = "Intermedio" }, + { valor = "ALTO", etiqueta = "Alto" }, +] + +[hormonoterapia] +etiqueta = "Hormonoterapia" + +[hormonoterapia.resultados.intencion] +etiqueta = "Intención" +tipo_valor = "codigo" +valores = [ + { valor = "NEOADYUVANTE", etiqueta = "Neoadyuvante" }, + { valor = "ADYUVANTE", etiqueta = "Adyuvante" }, + { valor = "PALIATIVA", etiqueta = "Paliativa" }, + { valor = "NINGUNA", etiqueta = "Sin tratamiento" }, +] + +[anti_her2] +etiqueta = "Tratamiento anti-HER2" + +[anti_her2.resultados.intencion] +etiqueta = "Intención" +tipo_valor = "codigo" +valores = [ + { valor = "NEOADYUVANTE", etiqueta = "Neoadyuvante" }, + { valor = "ADYUVANTE", etiqueta = "Adyuvante" }, + { valor = "PALIATIVA", etiqueta = "Paliativa" }, + { valor = "NINGUNA", etiqueta = "Sin tratamiento" }, +] + +[recurrencia] +etiqueta = "Recaída" + +[recurrencia.resultados.sitio] +etiqueta = "Sitio de la recaída" +tipo_valor = "codigo" +valores = [ + { valor = "LOCAL", etiqueta = "Local" }, + { valor = "REGIONAL", etiqueta = "Regional" }, + { valor = "A_DISTANCIA", etiqueta = "A distancia" }, + { valor = "NO_ESPECIFICADO", etiqueta = "Sin especificar" }, +] + +[ultimo_contacto] +etiqueta = "Último contacto" + +[ultimo_contacto.resultados.estado] +etiqueta = "Estado en el último contacto" +tipo_valor = "codigo" +valores = [ + { valor = "VIVA", etiqueta = "Viva" }, +] diff --git a/Persistance/persistance/cama/__init__.py b/Persistance/persistance/cama/__init__.py index a87764e..209ee99 100644 --- a/Persistance/persistance/cama/__init__.py +++ b/Persistance/persistance/cama/__init__.py @@ -38,6 +38,8 @@ from core.cama.models import ( NotaMedica, OrdenesEstudio, Paciente, + TratamientoMama, + SeguimientoMama, ) from core.indicadores.cohortes import TablasCohorte @@ -72,6 +74,8 @@ biopsia_mama_repository = Repository(get_cama_session, BiopsiaMama) nota_medica_repository = Repository(get_cama_session, NotaMedica) biometria_hematica_repository = Repository(get_cama_session, BiometriaHematica) episodio_clinico_repository = Repository(get_cama_session, EpisodioClinico) +tratamiento_mama_repository = Repository(get_cama_session, TratamientoMama) +seguimiento_mama_repository = Repository(get_cama_session, SeguimientoMama) # indicadores_kit (Core/docs/ADR-004). Se leen con get/list/count; lo que # se escribe va por métodos de subclases (persistance/edges, por capa). diff --git a/Persistance/persistance/cama/alembic/versions/b6d1f4a82c57_structured_results_and_treatment.py b/Persistance/persistance/cama/alembic/versions/b6d1f4a82c57_structured_results_and_treatment.py new file mode 100644 index 0000000..16fa4b4 --- /dev/null +++ b/Persistance/persistance/cama/alembic/versions/b6d1f4a82c57_structured_results_and_treatment.py @@ -0,0 +1,98 @@ +"""structured pathology, staging, treatment and patient attributes + +The results the survival model reads, as they arrive: the biopsy report's structured fields (`biopsia_mama`), the mammogram's density and findings (`mastografia`), the +clinical stage and metastasis of a note (`nota_medica`), marital status, race and BRCA results of the patient +(`paciente`) and one row per treatment course (`tratamiento_mama`). + +Revision ID: b6d1f4a82c57 +Revises: a9c4e2f17d38 +Create Date: 2026-11-22 12:00:00.000000 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = 'b6d1f4a82c57' +down_revision = 'a9c4e2f17d38' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.add_column('biopsiamama', sa.Column('bx_tipo_histologico', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_grado_nottingham', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_receptor_estrogeno', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_receptor_estrogeno_pct', sa.Float(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_receptor_progesterona', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_receptor_progesterona_pct', sa.Float(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_her2', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_her2_fish', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_ki67_pct', sa.Float(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_tamano_tumor_mm', sa.Float(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_ganglios_positivos', sa.Float(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_invasion_linfovascular', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_multifocalidad', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_margenes', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_pt', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_pn', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_lateralidad', sa.Text(), nullable=True)) + op.add_column('biopsiamama', sa.Column('bx_localizacion', sa.Text(), nullable=True)) + op.add_column('mastografia', sa.Column('mast_densidad', sa.Text(), nullable=True)) + op.add_column('mastografia', sa.Column('mast_margen_masa', sa.Text(), nullable=True)) + op.add_column('mastografia', sa.Column('mast_tipo_hallazgo', sa.Text(), nullable=True)) + op.add_column('notamedica', sa.Column('nm_estadio_clinico', sa.Text(), nullable=True)) + op.add_column('notamedica', sa.Column('nm_metastasis', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_estado_civil', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_raza', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_brca1', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_brca2', sa.Text(), nullable=True)) + op.create_table( + 'tratamientomama', + sa.Column('trat_id', sa.Integer(), primary_key=True, autoincrement=True), + sa.Column('pac_id', sa.Integer(), nullable=True), + sa.Column('pac_id_hospital', sa.String(length=64), nullable=False), + sa.Column('trat_tipo', sa.Text(), nullable=False), + sa.Column('trat_fecha', sa.Date(), nullable=True), + sa.Column('trat_detalle', sa.Text(), nullable=True), + sa.Column('trat_lateralidad', sa.Text(), nullable=True), + ) + op.create_index('ix_tratamientomama_pac_id', 'tratamientomama', ['pac_id']) + op.create_index('ix_tratamientomama_pac_id_hospital', 'tratamientomama', ['pac_id_hospital']) + + +def downgrade() -> None: + op.drop_index('ix_tratamientomama_pac_id_hospital', table_name='tratamientomama') + op.drop_index('ix_tratamientomama_pac_id', table_name='tratamientomama') + op.drop_table('tratamientomama') + with op.batch_alter_table('mastografia') as batch: + batch.drop_column('mast_tipo_hallazgo') + batch.drop_column('mast_margen_masa') + batch.drop_column('mast_densidad') + with op.batch_alter_table('paciente') as batch: + batch.drop_column('pac_brca2') + batch.drop_column('pac_brca1') + batch.drop_column('pac_raza') + batch.drop_column('pac_estado_civil') + with op.batch_alter_table('notamedica') as batch: + batch.drop_column('nm_metastasis') + batch.drop_column('nm_estadio_clinico') + with op.batch_alter_table('biopsiamama') as batch: + batch.drop_column('bx_localizacion') + batch.drop_column('bx_lateralidad') + batch.drop_column('bx_pn') + batch.drop_column('bx_pt') + batch.drop_column('bx_margenes') + batch.drop_column('bx_multifocalidad') + batch.drop_column('bx_invasion_linfovascular') + batch.drop_column('bx_ganglios_positivos') + batch.drop_column('bx_tamano_tumor_mm') + batch.drop_column('bx_ki67_pct') + batch.drop_column('bx_her2_fish') + batch.drop_column('bx_her2') + batch.drop_column('bx_receptor_progesterona_pct') + batch.drop_column('bx_receptor_progesterona') + batch.drop_column('bx_receptor_estrogeno_pct') + batch.drop_column('bx_receptor_estrogeno') + batch.drop_column('bx_grado_nottingham') + batch.drop_column('bx_tipo_histologico') diff --git a/Persistance/persistance/cama/alembic/versions/c7e2a5f9b413_recurrence_variables.py b/Persistance/persistance/cama/alembic/versions/c7e2a5f9b413_recurrence_variables.py new file mode 100644 index 0000000..35d9bca --- /dev/null +++ b/Persistance/persistance/cama/alembic/versions/c7e2a5f9b413_recurrence_variables.py @@ -0,0 +1,56 @@ +"""recurrence variables and follow-up + +The facts the recurrence model reads, as they arrive: the patient's menopausal state, molecular and clinical subtypes, +integrative cluster, cellularity, mutation load, Ki-67 category and the source of her record (`paciente`), and one row per +follow-up fact, a recurrence or the last contact (`seguimientomama`). + +Revision ID: c7e2a5f9b413 +Revises: b6d1f4a82c57 +Create Date: 2026-11-22 18:00:00.000000 + +""" +from alembic import op +import sqlalchemy as sa + +# revision identifiers, used by Alembic. +revision = 'c7e2a5f9b413' +down_revision = 'b6d1f4a82c57' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + op.add_column('paciente', sa.Column('pac_estado_menopausico', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_pam50', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_subtipo_clinico', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_cluster_integrativo', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_celularidad', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_carga_mutacional', sa.Float(), nullable=True)) + op.add_column('paciente', sa.Column('pac_ki67_categoria', sa.Text(), nullable=True)) + op.add_column('paciente', sa.Column('pac_fuente', sa.Text(), nullable=True)) + op.create_table( + 'seguimientomama', + sa.Column('seg_id', sa.Integer(), primary_key=True, autoincrement=True), + sa.Column('pac_id', sa.Integer(), nullable=True), + sa.Column('pac_id_hospital', sa.String(length=64), nullable=False), + sa.Column('seg_tipo', sa.Text(), nullable=False), + sa.Column('seg_fecha', sa.Date(), nullable=True), + sa.Column('seg_detalle', sa.Text(), nullable=True), + ) + op.create_index('ix_seguimientomama_pac_id', 'seguimientomama', ['pac_id']) + op.create_index('ix_seguimientomama_pac_id_hospital', 'seguimientomama', ['pac_id_hospital']) + + +def downgrade() -> None: + op.drop_index('ix_seguimientomama_pac_id_hospital', table_name='seguimientomama') + op.drop_index('ix_seguimientomama_pac_id', table_name='seguimientomama') + op.drop_table('seguimientomama') + with op.batch_alter_table('paciente') as batch: + batch.drop_column('pac_fuente') + batch.drop_column('pac_ki67_categoria') + batch.drop_column('pac_carga_mutacional') + batch.drop_column('pac_celularidad') + batch.drop_column('pac_cluster_integrativo') + batch.drop_column('pac_subtipo_clinico') + batch.drop_column('pac_pam50') + batch.drop_column('pac_estado_menopausico') diff --git a/Persistance/persistance/edges/dbt.py b/Persistance/persistance/edges/dbt.py index 29bae53..c1f1d98 100644 --- a/Persistance/persistance/edges/dbt.py +++ b/Persistance/persistance/edges/dbt.py @@ -22,6 +22,10 @@ class DbtRelationError(RuntimeError): """A relation dbt should have created can't be read.""" +# How many patients go in one `IN (...)`: under the bound-variable limit of the engines (SQL Server's is 2,100). +PATIENTS_PER_QUERY = 2_000 + + def timeline_view(domain: str) -> str: return f"{domain}_linea_de_tiempo" @@ -30,7 +34,7 @@ class DbtTimelineRepository(TimelineRepository): """The domain's timeline, read from dbt's view `_linea_de_tiempo`. `fecha` comes back as a date and `conocida_en` as an aware UTC datetime on every engine. The filters run in the database; `patients` becomes one bound - parameter per patient, so a long list can exceed an engine's limit (SQL Server's is 2,100): read without it and join. + parameter per patient, so it is read in lists of `PATIENTS_PER_QUERY`, in patient order. """ def __init__(self, session_factory: Callable, domain: str): @@ -52,7 +56,12 @@ class DbtTimelineRepository(TimelineRepository): def read(self, *, patients: Iterable[int] | None = None, until: date | None = None, known_until: datetime | None = None) -> list[dict]: try: - return super().read(patients=patients, until=until, known_until=known_until) + if patients is None: + return super().read(patients=None, until=until, known_until=known_until) + ids = sorted(set(patients)) + return [row for desde in range(0, len(ids), PATIENTS_PER_QUERY) + for row in super().read(patients=ids[desde:desde + PATIENTS_PER_QUERY], until=until, + known_until=known_until)] except DBAPIError as error: raise DbtRelationError(f"can't read {self.view} ({error.orig}): is it created? " f"Run `dbt run --select {self.view}` in Transformation") from error diff --git a/Persistance/persistance/edges/silver/procedures.py b/Persistance/persistance/edges/silver/procedures.py index 334b59b..1a92b44 100644 --- a/Persistance/persistance/edges/silver/procedures.py +++ b/Persistance/persistance/edges/silver/procedures.py @@ -30,6 +30,9 @@ log = logging.getLogger(__name__) KEY = ("fuente_tabla", "fuente_id", "estudio_id", "clase") +# How many ids go in one `IN (...)`: under the limit of bound variables of the engines. +_LOTE = 10_000 + def save_silver_in( sesion: Session, plata, *, procedimiento: type[SQLModel], observacion: type[SQLModel], carga_id: int ) -> dict[str, int]: @@ -84,8 +87,9 @@ def save_silver_in( ids = [fila.procedimiento_id for fila in existentes.values()] actuales = { (o.procedimiento_id, o.resultado_id): o - for o in sesion.exec(select(observacion).where(observacion.procedimiento_id.in_(ids))) - } if ids else {} + for desde in range(0, len(ids), _LOTE) + for o in sesion.exec(select(observacion).where(observacion.procedimiento_id.in_(ids[desde:desde + _LOTE]))) + } for o in plata.observaciones: dueno = existentes.get(o["procedimiento"]) if dueno is None: diff --git a/Transformation/dbt_project.yml b/Transformation/dbt_project.yml index 30a59aa..38d7452 100644 --- a/Transformation/dbt_project.yml +++ b/Transformation/dbt_project.yml @@ -137,6 +137,9 @@ vars: recruitment_end: "2027-01-01" cutoff: "2026-12-31" surgeries: ["ESCISIONAL", "SEGMENTECTOMIA", "MASTECTOMIA_TOTAL", "MASTECTOMIA_RADICAL_MODIFICADA"] + # CaMa's total cohort (models/cama/cohorts/total): the cut-off of its index. + total_cohort: + cutoff: "2026-12-31" # The surveillance cohort's rules (models/cacu/cohorts/surveillance). surveillance_cohort: recruitment_start: "2024-01-01" diff --git a/Transformation/models/cama/cohorts/total/cama_total.yml b/Transformation/models/cama/cohorts/total/cama_total.yml new file mode 100644 index 0000000..891df4e --- /dev/null +++ b/Transformation/models/cama/cohorts/total/cama_total.yml @@ -0,0 +1,17 @@ +version: 2 + +# The total cohort: every patient with an invasive carcinoma, from the date of its first biopsy report, with no further +# rule. It is the source of the survival model, which reads each patient's variables from her whole timeline. +models: + - name: cama_total_all_patients + description: Every patient of the domain. + config: + materialized: ephemeral + meta: + cohort: cama/cohorte_total + kind: population + cutoff: "{{ var('total_cohort')['cutoff'] }}" + parameters: "{{ var('total_cohort') | tojson }}" + - name: cama_total_index_date + description: First biopsy reported as invasive carcinoma up to the cut-off. Sets the index date. + config: {materialized: ephemeral, meta: {cohort: cama/cohorte_total, kind: index}} diff --git a/Transformation/models/cama/cohorts/total/cama_total_all_patients.sql b/Transformation/models/cama/cohorts/total/cama_total_all_patients.sql new file mode 100644 index 0000000..8303f0c --- /dev/null +++ b/Transformation/models/cama/cohorts/total/cama_total_all_patients.sql @@ -0,0 +1,3 @@ +{# Every patient of the domain: the total cohort has no rule but the index. #} +select pac_id +from {{ source('silver', 'persona') }} diff --git a/Transformation/models/cama/cohorts/total/cama_total_index_date.sql b/Transformation/models/cama/cohorts/total/cama_total_index_date.sql new file mode 100644 index 0000000..c01f259 --- /dev/null +++ b/Transformation/models/cama/cohorts/total/cama_total_index_date.sql @@ -0,0 +1,13 @@ +{# The date of the patient's first biopsy reported as invasive carcinoma, up to the cut-off: the diagnosis. The report's + `fuente_id` names it. #} +{% set p = var('total_cohort') %} +with biopsies as ( + select + pac_id, fecha, fuente_tabla, fuente_id, + row_number() over (partition by pac_id order by fecha, fuente_id) as position + from {{ ref('cama_linea_de_tiempo') }} + where tipo = 'biopsia' and valor_codigo = 'CARCINOMA_INVASOR' and fecha <= '{{ p.cutoff }}' +) +select pac_id, fecha as fecha_indice, fuente_tabla as indice_fuente_tabla, fuente_id as indice_fuente_id +from biopsies +where position = 1 diff --git a/Transformation/models/cama/silver/cama_linea_de_tiempo.yml b/Transformation/models/cama/silver/cama_linea_de_tiempo.yml index c9819dd..d0d603f 100644 --- a/Transformation/models/cama/silver/cama_linea_de_tiempo.yml +++ b/Transformation/models/cama/silver/cama_linea_de_tiempo.yml @@ -47,10 +47,24 @@ models: - {estudio_id: "prueba_genetica", clase: "reporte", resultado_id: "prueba_genetica.brca1", clase_de_linea: "medicion", tipo: "brca1"} - {estudio_id: "prueba_genetica", clase: "reporte", resultado_id: "prueba_genetica.brca2", clase_de_linea: "medicion", tipo: "brca2"} - {estudio_id: "sociodemografico", clase: "parte", resultado_id: "sociodemografico.estado_civil", clase_de_linea: "medicion", tipo: "estado_civil"} + - {estudio_id: "sociodemografico", clase: "parte", resultado_id: "sociodemografico.raza", clase_de_linea: "medicion", tipo: "raza"} # Treatment, when it was done: one row per course (a surgery per breast), its value the kind or the intent. - {estudio_id: "cirugia", clase: "encuentro", resultado_id: "cirugia.tipo_cirugia", clase_de_linea: "procedimiento", tipo: "cirugia"} - {estudio_id: "cirugia", clase: "encuentro", resultado_id: "cirugia.lateralidad", clase_de_linea: "medicion", tipo: "cirugia_lateralidad"} - {estudio_id: "radioterapia", clase: "encuentro", resultado_id: "radioterapia.intencion", clase_de_linea: "procedimiento", tipo: "radioterapia"} - {estudio_id: "quimioterapia", clase: "encuentro", resultado_id: "quimioterapia.intencion", clase_de_linea: "procedimiento", tipo: "quimioterapia"} + - {estudio_id: "hormonoterapia", clase: "encuentro", resultado_id: "hormonoterapia.intencion", clase_de_linea: "procedimiento", tipo: "hormonoterapia"} + - {estudio_id: "anti_her2", clase: "encuentro", resultado_id: "anti_her2.intencion", clase_de_linea: "procedimiento", tipo: "anti_her2"} + - {estudio_id: "recurrencia", clase: "encuentro", resultado_id: "recurrencia.sitio", clase_de_linea: "medicion", tipo: "recurrencia"} + - {estudio_id: "ultimo_contacto", clase: "encuentro", resultado_id: "ultimo_contacto.estado", clase_de_linea: "medicion", tipo: "ultimo_contacto"} + - {estudio_id: "sociodemografico", clase: "parte", resultado_id: "sociodemografico.estado_menopausico", clase_de_linea: "medicion", tipo: "estado_menopausico"} + - {estudio_id: "sociodemografico", clase: "parte", resultado_id: "sociodemografico.fuente", clase_de_linea: "medicion", tipo: "fuente"} + - {estudio_id: "perfil_molecular", clase: "parte", resultado_id: "perfil_molecular.pam50", clase_de_linea: "medicion", tipo: "pam50"} + - {estudio_id: "perfil_molecular", clase: "parte", resultado_id: "perfil_molecular.subtipo_clinico", clase_de_linea: "medicion", tipo: "subtipo_clinico"} + - {estudio_id: "perfil_molecular", clase: "parte", resultado_id: "perfil_molecular.cluster_integrativo", clase_de_linea: "medicion", tipo: "cluster_integrativo"} + - {estudio_id: "perfil_molecular", clase: "parte", resultado_id: "perfil_molecular.celularidad", clase_de_linea: "medicion", tipo: "celularidad"} + - {estudio_id: "perfil_molecular", clase: "parte", resultado_id: "perfil_molecular.carga_mutacional", clase_de_linea: "medicion", tipo: "carga_mutacional"} + - {estudio_id: "perfil_molecular", clase: "parte", resultado_id: "perfil_molecular.ki67_categoria", clase_de_linea: "medicion", tipo: "ki67_categoria"} - {estudio_id: null, clase: "orden", resultado_id: null, clase_de_linea: "orden", tipo: "orden", columna: "codigo_fuente"} - {estudio_id: "nota_medica", clase: "encuentro", resultado_id: "nota_medica.diagnostico", clase_de_linea: "diagnostico", tipo: "nota_medica"} + - {estudio_id: "nota_medica", clase: "encuentro", resultado_id: null, clase_de_linea: "procedimiento", tipo: "consulta"} diff --git a/WebApi b/WebApi index d1e0679..9a62ddc 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit d1e06798c9548d8ccec2fbf81a0572bfd678aaf0 +Subproject commit 9a62ddcdaf5465e17a6995187038608e1986c7af diff --git a/WebApp b/WebApp index 7aa3d2c..4c181af 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit 7aa3d2c6e63f76c7358be5f1c0c8abee442d7fdd +Subproject commit 4c181af291b5ffa1931c6e20f0d663d529a57184 diff --git a/models b/models index 7b2eae2..73c5176 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit 7b2eae27820638c3692bf95252f4250c17c8e687 +Subproject commit 73c5176482a65c1578ea2bd4342ab36419f6d654 From 7c74978f38a08cfd44d2009b913d5c73ae2d3ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 09:22:15 -0600 Subject: [PATCH 02/15] Update WebApp pin for the CaMa SEER survival panel --- WebApp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebApp b/WebApp index 0127162..dd356ef 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit 01271621b710630a4aa5450057ca97239eea754d +Subproject commit dd356efb6b04cfe630b7e1b79ca3aee96570d910 From 6a652466f2cb5ba0fb419bb6861e0d4afb57cee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 10:16:34 -0600 Subject: [PATCH 03/15] CaMa clinical scenario: a treatment encounter after the malignant diagnosis is post-treatment evidence --- Transformation/dbt_project.yml | 7 +++++-- .../models/cama/silver/cama_procedimientos_inferidos.sql | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Transformation/dbt_project.yml b/Transformation/dbt_project.yml index 105b4e7..d658b8c 100644 --- a/Transformation/dbt_project.yml +++ b/Transformation/dbt_project.yml @@ -71,14 +71,17 @@ vars: # kind in `valor_codigo`; being under observation has no fact. # egreso a note of one of `tipos_nota_egreso` with one of `cie_tumor_maligno`, or on or after her diagnosis # nota a note with one of `cie_tumor_maligno` by one of `tratamiento_especialidades`, after her diagnosis + # tratamiento a treatment encounter of one of `tratamiento_estudios` (surgery, chemotherapy, radiotherapy) on or + # after her diagnosis # Her diagnosis is her first evidence of a kind `diagnostico_evidencias` names. cie: a note with one of # `cie_tumor_maligno` (an in situ carcinoma isn't one), whoever wrote it; biopsia: a report of one of # `grados_malignos`. escenarios: - postratamiento_evidencias: ["egreso"] + postratamiento_evidencias: ["egreso", "tratamiento"] tipos_nota_egreso: ["EGRESO"] tratamiento_especialidades: ["CIRUGIA_ONCOLOGICA", "ONCOLOGIA_MEDICA"] - diagnostico_evidencias: ["cie"] + tratamiento_estudios: ["cirugia", "quimioterapia", "radioterapia"] + diagnostico_evidencias: ["cie", "biopsia"] cie_tumor_maligno: ["C50", "C500", "C501", "C502", "C503", "C504", "C505", "C506", "C508", "C509"] grados_malignos: ["CARCINOMA_INVASOR"] especialidades_diagnostico: ["CIRUGIA_ONCOLOGICA"] diff --git a/Transformation/models/cama/silver/cama_procedimientos_inferidos.sql b/Transformation/models/cama/silver/cama_procedimientos_inferidos.sql index bbd7040..b203b62 100644 --- a/Transformation/models/cama/silver/cama_procedimientos_inferidos.sql +++ b/Transformation/models/cama/silver/cama_procedimientos_inferidos.sql @@ -60,6 +60,14 @@ evidencia_postratamiento as ( where n.tipo_nota in {{ sql_list(e['tipos_nota_egreso']) }} and (n.cie_codigo in {{ sql_list(e['cie_tumor_maligno']) }} or n.fecha >= d.primera) {% endif %} + {% if 'tratamiento' in e['postratamiento_evidencias'] %} + union all + select t.pac_id, t.fecha, c.inicio, t.fuente_tabla, t.fuente_id, 'tratamiento' + from {{ source('silver', 'procedimiento') }} t + join {{ source('silver', 'carga') }} c on c.carga_id = t.carga_id + join diagnostico_maligno d on d.pac_id = t.pac_id and t.fecha >= d.primera + where t.estudio_id in {{ sql_list(e['tratamiento_estudios']) }} and t.clase = 'encuentro' + {% endif %} {% if 'nota' in e['postratamiento_evidencias'] %} union all select n.pac_id, n.fecha, n.conocida_en, n.fuente_tabla, n.fuente_id, 'nota' From 18b8b0a395278ab9fdf4120d102cae22c45bb013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 16:22:06 -0600 Subject: [PATCH 04/15] Update models and WebApp pins: CaMa survival reads stage and treatments, one survival panel --- WebApp | 2 +- models | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WebApp b/WebApp index dd356ef..5bf6af8 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit dd356efb6b04cfe630b7e1b79ca3aee96570d910 +Subproject commit 5bf6af8ecfa108375a1cca8b44ee8daf498485ec diff --git a/models b/models index 94c7cf9..d91ac7c 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit 94c7cf93dc48b21cf2290e15f35f67682d688c8a +Subproject commit d91ac7c14b2744127b6c1706f57a6e8382cca539 From 1f1d32aa573445ab54a314b5da6d73d3fdd6a5b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 18:04:58 -0600 Subject: [PATCH 05/15] CaMa window to the end of the year; pins for the recurrence and survival changes --- Transformation/dbt_project.yml | 4 ++-- WebApi | 2 +- WebApp | 2 +- models | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Transformation/dbt_project.yml b/Transformation/dbt_project.yml index d658b8c..b1d7d4d 100644 --- a/Transformation/dbt_project.yml +++ b/Transformation/dbt_project.yml @@ -175,11 +175,11 @@ vars: # CaMa's recruitment window and cut-off, once (YAML merge key), and its total cohort (models/cama/cohorts/total): # every patient with a clinical event up to the cut-off, with no rules, for the scenarios that index and filter in # their own pipeline. The window is the one the scenarios take for their index; the cut-off is where follow-up ends - # (provisional: the synthetic hospital's reference date). + # (the end of the year; no member is followed past the day her build is read). cama_window: &cama_window recruitment_start: "2018-01-01" recruitment_end: "2027-01-01" - cutoff: "2026-01-01" + cutoff: "2026-12-31" cama_total_cohort: <<: *cama_window # The post-treatment cohort (models/cacu/cohorts/post_treatment; KPNC's post-treatment tables): the first cytology diff --git a/WebApi b/WebApi index cc54c1d..1fbeabb 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit cc54c1dc8610985b241746788553c3e21c53de9c +Subproject commit 1fbeabb872ea1aa4029a1f68c8c53b0c9d8b6ff9 diff --git a/WebApp b/WebApp index 5bf6af8..29c9e68 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit 5bf6af8ecfa108375a1cca8b44ee8daf498485ec +Subproject commit 29c9e6853b3d6bb524818be17e02b7760b5b9afc diff --git a/models b/models index d91ac7c..5a10be4 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit d91ac7c14b2744127b6c1706f57a6e8382cca539 +Subproject commit 5a10be44d094756f96ca524a2b43e99d6c3e7d36 From 839bfcc7810153a1d1017c3214a39b5ec0fd93e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 18:10:48 -0600 Subject: [PATCH 06/15] Update WebApp pin for the Seguimiento tab --- WebApp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebApp b/WebApp index 29c9e68..ec8542d 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit 29c9e6853b3d6bb524818be17e02b7760b5b9afc +Subproject commit ec8542de9f50989d1a27755007212a21e921b810 From ce467e87e394639f8f0cb69ddf01ab782f61bc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 19:51:21 -0600 Subject: [PATCH 07/15] Update models and WebApi pins: CaMa recurrence reads the database --- WebApi | 2 +- models | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WebApi b/WebApi index 1fbeabb..88c9694 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit 1fbeabb872ea1aa4029a1f68c8c53b0c9d8b6ff9 +Subproject commit 88c9694a4699eb664bc20eb8fcb0fde5ba1b35c9 diff --git a/models b/models index 5a10be4..b3e02f0 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit 5a10be44d094756f96ca524a2b43e99d6c3e7d36 +Subproject commit b3e02f0980fbaefdf43ba0e64508fea0c3b7490d From 28534c5290c493389612ee82503add883a4b2337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 21:38:43 -0600 Subject: [PATCH 08/15] Update WebApi and WebApp pins: CaMa patient header and survival scenario from her data --- WebApi | 2 +- WebApp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WebApi b/WebApi index 88c9694..f7f8af8 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit 88c9694a4699eb664bc20eb8fcb0fde5ba1b35c9 +Subproject commit f7f8af8b4c13c3ae307e5594381b711288da93f1 diff --git a/WebApp b/WebApp index ec8542d..7ab2567 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit ec8542de9f50989d1a27755007212a21e921b810 +Subproject commit 7ab2567dc9a1ef622b1069ce4e744e01e71d5f03 From 4debce6892deb6c5c1b00e06a6cb89ff975dbd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 22:02:04 -0600 Subject: [PATCH 09/15] Update WebApi pin: live models load from the cycle's file --- WebApi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebApi b/WebApi index f7f8af8..f97d120 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit f7f8af8b4c13c3ae307e5594381b711288da93f1 +Subproject commit f97d1202a9c60f6f1b96b61f44b8d33401938f63 From 17fb0f8bb20a6a736ae2f811740f042567161d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 22:20:13 -0600 Subject: [PATCH 10/15] Update WebApi pin: CaMa follow-up cohort cached by revision --- WebApi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebApi b/WebApi index f97d120..201ef4f 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit f97d1202a9c60f6f1b96b61f44b8d33401938f63 +Subproject commit 201ef4fb0356dbf384371edd140e9497fb002559 From 162ad66716495c75cb7004c215d899f23868a922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 22:59:48 -0600 Subject: [PATCH 11/15] Update models and WebApi pins: CaMa survival figure from the pipeline's subgroup results --- WebApi | 2 +- models | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WebApi b/WebApi index 201ef4f..93649a0 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit 201ef4fb0356dbf384371edd140e9497fb002559 +Subproject commit 93649a0e2786290560427cc462013fc815ee786c diff --git a/models b/models index b3e02f0..07c91ad 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit b3e02f0980fbaefdf43ba0e64508fea0c3b7490d +Subproject commit 07c91adbe6315ffb5033cd60e986b3e64c69a44a From 60f550c6b2ff7f710fe8bb22985e5f9a922e68b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Sun, 22 Nov 2026 23:22:31 -0600 Subject: [PATCH 12/15] Update models and WebApi pins: CaMa survival points recomputed by the indicators cycle --- WebApi | 2 +- models | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WebApi b/WebApi index 93649a0..3248324 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit 93649a0e2786290560427cc462013fc815ee786c +Subproject commit 32483249c713bf11301ef6dbb1b7090fa7fdf41f diff --git a/models b/models index 07c91ad..706f751 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit 07c91adbe6315ffb5033cd60e986b3e64c69a44a +Subproject commit 706f7510c57eba5d09ac6cfd46a3f92da5fc3560 From 7422d48c84ff6d86e294e31de0b0eb3f40e27301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Mon, 23 Nov 2026 00:09:49 -0600 Subject: [PATCH 13/15] Update models, WebApi and WebApp pins: CaMa survival points all from the pipeline's survival stage; measures answered after each cycle --- WebApi | 2 +- WebApp | 2 +- models | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WebApi b/WebApi index 5738a9c..bd8c7aa 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit 5738a9c302f191de9e23a8fdaf650689c7540f39 +Subproject commit bd8c7aa55a938d6582ee57d555e1a874e0f06d85 diff --git a/WebApp b/WebApp index be46429..069cc45 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit be46429627e173899e00aea10a327b8ad78dd583 +Subproject commit 069cc459a4333fa6607c6b10ef6dfb249d036a0f diff --git a/models b/models index 678c02b..674bdc4 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit 678c02b79dd701adc5697d5a88b9e66532fa3fdb +Subproject commit 674bdc4bb29094c443903f2471ce3c703f48a81e From 320b7f972b12ec73da7fe84d1fce3f8c0f6aad24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Mon, 23 Nov 2026 00:10:04 -0600 Subject: [PATCH 14/15] Update WebApp pin: CaMa labels from dev with the optional adjusted Kaplan-Meier --- WebApp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebApp b/WebApp index 069cc45..6ade415 160000 --- a/WebApp +++ b/WebApp @@ -1 +1 @@ -Subproject commit 069cc459a4333fa6607c6b10ef6dfb249d036a0f +Subproject commit 6ade415f6351ca48b2c19e3e2dfe72847a05d6f9 From 3743ea694eea501bc2c11a12b93c8f7948e1a2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o=20Cervantes?= Date: Mon, 23 Nov 2026 00:14:16 -0600 Subject: [PATCH 15/15] Update models and WebApi pins: the cycle no longer batch-scores CaMa recurrence --- WebApi | 2 +- models | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WebApi b/WebApi index bd8c7aa..5831fcd 160000 --- a/WebApi +++ b/WebApi @@ -1 +1 @@ -Subproject commit bd8c7aa55a938d6582ee57d555e1a874e0f06d85 +Subproject commit 5831fcd9d92cd392cf01431fe83bf81f7d061d5e diff --git a/models b/models index 674bdc4..f9d97f4 160000 --- a/models +++ b/models @@ -1 +1 @@ -Subproject commit 674bdc4bb29094c443903f2471ce3c703f48a81e +Subproject commit f9d97f4d12fd3c9b5957f55aabddf98710103fea