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
+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)