test(cacu): cover the two times to treatment

The CaCu catalog holds nine measures. A fixture adds H-004's colposcopy and treatment on top of the shared data, and a
test pins the days of both intervals with a 60-day horizon.
This commit is contained in:
2026-11-21 19:35:44 -06:00
parent 0c102d89f7
commit 14e11e20b6
6 changed files with 53 additions and 9 deletions
+43 -1
View File
@@ -19,7 +19,7 @@ from sqlalchemy import text
from sqlmodel import Session, select
from conftest import base_de
from core.cacu.models import BiopsiaCervical, CitologiaCervical
from core.cacu.models import BiopsiaCervical, CitologiaCervical, NotaMedica, Paciente
from webapi.compositions import answer_composition, composition_definitions, composition_report
from webapi.metrics import INTERVAL_HIGH, INTERVAL_LOW, Counts, Question, answer, measure_definitions, measure_report
from webapi.orchestration import run
@@ -47,6 +47,28 @@ def base(tmp_path, sin_supresion, manifest):
base.motor.dispose()
def _con_tratamiento(sesion: Session) -> None:
"""The fixture data and, for H-004, her colposcopy (August 20) and her treatment (August 28), after the
valuation visit of August 10: the timeline then holds a treatment to end an interval at."""
from staging.cacu import COLPOSCOPIA, FAMILIAR, insertar
insertar(sesion)
paciente = sesion.exec(select(Paciente).where(Paciente.pac_id_hospital == "H-004")).one()
sesion.add_all(NotaMedica(pac_id=paciente.pac_id, pac_id_hospital="H-004", nm_id_hospital=f"NM-9{n}", nm_fecha=fecha,
nm_cie_codigo=cie, nm_especialidad=especialidad)
for n, (fecha, cie, especialidad) in enumerate(
[(date(2025, 8, 20), "R87.6", COLPOSCOPIA), (date(2025, 8, 28), "D06.9", FAMILIAR)], start=1))
sesion.commit()
@pytest.fixture
def base_con_tratamiento(tmp_path, sin_supresion, manifest):
base = base_de("cacu", tmp_path, datos=_con_tratamiento)
base.run(*HASTA_MODELOS, parameters=sin_supresion, allow_undecided=True)
yield replace(base, ctx=replace(base.ctx, parameters=sin_supresion, allow_undecided=True))
base.motor.dispose()
@pytest.fixture
def kit():
return json.loads(SNAPSHOT.read_text(encoding="utf-8"))
@@ -467,6 +489,26 @@ def test_a_sample_waiting_for_its_diagnosis_within_the_horizon_is_not_measured_y
assert (result.initial, result.n, result.median, result.excluded) == (1, 1, 40.0, 0)
DIAS_TOMA_TRATAMIENTO = "cacu/CACU_DIAS_TOMA_TRATAMIENTO"
DIAS_DIAGNOSTICO_TRATAMIENTO = "cacu/CACU_DIAS_DIAGNOSTICO_TRATAMIENTO"
@pytest.mark.parametrize("url, expected", [(DIAS_TOMA_TRATAMIENTO, (4, 1, 58.0, 3)), (DIAS_DIAGNOSTICO_TRATAMIENTO, (1, 1, 18.0, 0))])
def test_the_times_to_treatment_are_counted_from_their_start_to_the_first_treatment(base_con_tratamiento, manifest, url, expected):
"""Pins down the two times to treatment on the fixture with H-004's colposcopy and treatment, 2025-S2 cut at the
end of the year, with a 60-day horizon. From the sample: H-004's July sample reaches her treatment of August 28 in
58 days; the other three samples of the semester have no treatment and their horizon has passed, so they are in
the initial population and not measured. From the diagnosis: only that sample has one in the period, and its
diagnosis of August 10 reaches the treatment in 18 days. Fails if the end event, the start (sample or diagnosis),
the horizon rule or the split between not measured yet and without event changes."""
from webapi.durations import answer_duration, duration_definitions
definition = duration_definitions(manifest)[url]
result = answer_duration("cacu", definition, Question(url, "2025-S2", date(2025, 12, 31)),
**repositories(base_con_tratamiento))
assert (result.initial, result.n, result.median, result.excluded) == expected
CONFIRMACION = "cacu/CACU_CONFIRMACION_CITOLOGIA"