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