Surveillance cohort: a glandular-only index result counts as an index result

Mirror of the dbt rule no_index_result, which now reads the timeline's glandular rows (AGC, ADENOCARCINOMA) next to
the Bethesda and HPV ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
This commit is contained in:
2026-11-20 12:09:28 -06:00
parent 3e72063e3f
commit bde02109ab
3 changed files with 34 additions and 3 deletions
+3 -2
View File
@@ -11,7 +11,7 @@ pide el modelo de mezcla prevalencia–incidencia (Modelo-cacu):
Quién entra:
- la índice es la primera citología de toda la historia, si cae en la ventana;
- se excluye a quien tuvo una biopsia con el desenlace antes de la índice;
- y luego a quien no tiene resultado citológico ni de VPH en la índice.
- y luego a quien no tiene resultado citológico (escamoso o glandular) ni de VPH en la índice.
El desenlace solo se observa al verificar: una biopsia (positiva o negativa) o, con
`negativo_da_l`, un tamizaje completamente negativo posterior (`no_prevalente`).
@@ -55,6 +55,7 @@ def frame(filas, reglas: dict, inicio: date, fin: date, corte: date) -> tuple[li
eventos = [e for e in eventos if e["fecha"] <= corte]
resultado = {(e["fuente_tabla"], e["fuente_id"]): e["valor_codigo"] for e in eventos if e["tipo"] == "bethesda"}
vph = {(e["fuente_tabla"], e["fuente_id"]): e["valor_codigo"] for e in eventos if e["tipo"] == "vph"}
glandular = {(e["fuente_tabla"], e["fuente_id"]) for e in eventos if e["tipo"] == "glandular" and e["valor_codigo"]}
tomas = sorted((e for e in eventos if e["tipo"] == "citologia"), key=lambda e: (e["fecha"], e["fuente_id"]))
if not tomas or not (inicio <= tomas[0]["fecha"] < fin):
continue
@@ -66,7 +67,7 @@ def frame(filas, reglas: dict, inicio: date, fin: date, corte: date) -> tuple[li
if any(positiva and fecha < fecha_indice for fecha, positiva in biopsias):
evento_previo += 1
continue
if pap_0 is None and hpv_0 is None:
if pap_0 is None and hpv_0 is None and llave not in glandular:
sin_resultado += 1
continue
+1 -1
View File
@@ -25,7 +25,7 @@ description = "Biopsia con el desenlace antes de la fecha índice: no está en r
[[group.characteristic]]
code = "sin_resultado"
exclude = true
description = "La citología índice no tiene resultado citológico ni de VPH: no hay predictores"
description = "La citología índice no tiene resultado citológico (escamoso o glandular) ni de VPH: no hay predictores"
[group.reglas]
grados_evento = ["LIEAG", "CIS", "CARCINOMA"]
+30
View File
@@ -0,0 +1,30 @@
"""What this module covers: `models.cohorts.cacu.surveillance.frame`'s rule for an index cytology without results.
Fixtures: none; each test builds its timeline rows with `_event`.
"""
from datetime import date
from models.cohorts.cacu import surveillance
RULES = {"grados_evento": ["LIEAG"], "ventana_basal_dias": 180, "no_prevalente": {"pap": ["NORMAL"], "vph": ["NEGATIVO"]},
"negativo_da_l": False, "negativo_confirma_no_prevalente": False}
INDEX = date(2025, 1, 1)
def _event(pac_id, tipo, valor=None, fuente_id="a"):
return {"pac_id": pac_id, "fecha": INDEX, "tipo": tipo, "valor_codigo": valor, "fuente_tabla": "citologiacervical",
"fuente_id": f"{pac_id}{fuente_id}"}
def test_a_glandular_result_alone_is_an_index_result():
"""Pins down, as dbt's `cacu_surveillance_excl_no_index_result` does: a member whose index cytology has only a
glandular result (AGC) stays, and one with no result of any kind is left out. Fails if the rule goes back to
reading only the squamous Bethesda and HPV."""
rows = [_event(1, "citologia"), _event(1, "glandular", "AGC"),
_event(2, "citologia"), _event(2, "glandular", None)]
members, attrition = surveillance.frame(rows, RULES, date(2024, 1, 1), date(2026, 1, 1), date(2026, 12, 31))
assert [m.pac_id for m in members] == [1]
assert attrition[-1] == ("sin sin_resultado", 1)