test(cacu): cover the times along the screening route
The CaCu catalog holds fourteen measures. A fixture adds H-007, who goes the whole route in order, and a test pins the population, the cases and the median of each of the five new times.
This commit is contained in:
@@ -70,13 +70,16 @@ def groups(measure: dict) -> dict[str, str]:
|
||||
|
||||
|
||||
def test_each_contract_publishes_the_figures_the_page_can_draw(measures):
|
||||
"""Pins down: the two distributions offer the donut and the bars and the four durations their box plot; the C1
|
||||
"""Pins down: the two distributions offer the donut and the bars and the nine durations their box plot; the C1
|
||||
proportions and the risk bands none, because no figure is approved for them yet. Fails if a figure is declared
|
||||
that the page has no builder for, or one is dropped."""
|
||||
assert {i: figures(m) for i, m in measures.items()} == {
|
||||
"CACU-EU7": ["fig_c2_donas", "fig_c2_barras"], "CACU-CONFIRMACION-CITOLOGIA": ["fig_c2_donas", "fig_c2_barras"],
|
||||
"CACU-EU-TIEMPO-REPORTE": ["fig_c3r_caja"], "CACU-DIAS-TOMA-DIAGNOSTICO": ["fig_c3r_caja"],
|
||||
"CACU-DIAS-TOMA-TRATAMIENTO": ["fig_c3r_caja"], "CACU-DIAS-DIAGNOSTICO-TRATAMIENTO": ["fig_c3r_caja"],
|
||||
"CACU-DIAS-TOMA-COLPOSCOPIA": ["fig_c3r_caja"], "CACU-DIAS-TOMA-BIOPSIA": ["fig_c3r_caja"],
|
||||
"CACU-DIAS-RESULTADO-COLPOSCOPIA": ["fig_c3r_caja"], "CACU-DIAS-COLPOSCOPIA-BIOPSIA": ["fig_c3r_caja"],
|
||||
"CACU-DIAS-BIOPSIA-DIAGNOSTICO": ["fig_c3r_caja"],
|
||||
"CACU-EU13": [], "IND1": [], "CACU-RIESGO-BANDA": []}
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ def test_every_measure_and_one_report_of_each_are_valid_fhir(domain_client):
|
||||
with strata included. Fails if the serialization of a scoring, a stratifier or a population breaks FHIR's shape."""
|
||||
domain, client = domain_client
|
||||
measures = valid(client.get(f"/{domain}/fhir/Measure").get_json())
|
||||
assert measures["total"] == {"cacu": 9, "cama": 11}[domain]
|
||||
assert measures["total"] == {"cacu": 14, "cama": 11}[domain]
|
||||
for item in measures["entry"]:
|
||||
response = client.get(f"/{domain}/fhir/Measure/{item['resource']['id']}/$evaluate-measure?periodo=2025-S1")
|
||||
assert response.status_code in (200, 409), response.get_json()
|
||||
|
||||
@@ -81,6 +81,8 @@ def test_the_list_names_what_is_answered_on_request(client):
|
||||
|
||||
assert listed == {IND1.split("/")[1], EU13.split("/")[1], EU7.split("/")[1], "CACU_EU_TIEMPO_REPORTE",
|
||||
"CACU_DIAS_TOMA_DIAGNOSTICO", "CACU_DIAS_TOMA_TRATAMIENTO", "CACU_DIAS_DIAGNOSTICO_TRATAMIENTO",
|
||||
"CACU_DIAS_TOMA_COLPOSCOPIA", "CACU_DIAS_TOMA_BIOPSIA", "CACU_DIAS_RESULTADO_COLPOSCOPIA",
|
||||
"CACU_DIAS_COLPOSCOPIA_BIOPSIA", "CACU_DIAS_BIOPSIA_DIAGNOSTICO",
|
||||
"CACU_CONFIRMACION_CITOLOGIA", "CACU_RIESGO_BANDA"}
|
||||
|
||||
|
||||
|
||||
@@ -61,6 +61,39 @@ def _con_tratamiento(sesion: Session) -> None:
|
||||
sesion.commit()
|
||||
|
||||
|
||||
def _con_ruta(sesion: Session) -> None:
|
||||
"""The fixture data and H-007, who goes the whole route in order: a cytology on July 5 with its result on July 15,
|
||||
a valuation note on July 20, her colposcopy and the request of her biopsy on August 5, the biopsy report on
|
||||
August 25 and a diagnosis after it on September 10."""
|
||||
from staging.cacu import COLPOSCOPIA, ONCOLOGIA, SATISFACTORIO, insertar
|
||||
|
||||
insertar(sesion)
|
||||
paciente = Paciente(pac_id_hospital="H-007", pac_sexo="Femenino", pac_fecha_nacimiento=date(1980, 1, 1))
|
||||
sesion.add(paciente)
|
||||
sesion.flush()
|
||||
citologia = CitologiaCervical(pac_id=paciente.pac_id, pac_id_hospital="H-007", cit_fecha_toma=date(2025, 7, 5),
|
||||
cit_calidad_especimen=SATISFACTORIO, cit_fecha_reporte=date(2025, 7, 15),
|
||||
cit_celulas_escamosas="ASC-US", cit_vph_resultado="POSITIVO")
|
||||
sesion.add(citologia)
|
||||
sesion.flush()
|
||||
sesion.add(BiopsiaCervical(pac_id=paciente.pac_id, pac_id_hospital="H-007", cit_id=citologia.cit_id,
|
||||
bx_fecha_solicitud=date(2025, 8, 5), bx_fecha_reporte=date(2025, 8, 25), bx_cin_grado="CIN2"))
|
||||
sesion.add_all(NotaMedica(pac_id=paciente.pac_id, pac_id_hospital="H-007", nm_id_hospital=f"NM-8{n}", nm_fecha=fecha,
|
||||
nm_cie_codigo=cie, nm_especialidad=especialidad)
|
||||
for n, (fecha, cie, especialidad) in enumerate(
|
||||
[(date(2025, 7, 20), "R87.6", COLPOSCOPIA), (date(2025, 8, 5), "R87.6", COLPOSCOPIA),
|
||||
(date(2025, 9, 10), "D06.9", ONCOLOGIA)], start=1))
|
||||
sesion.commit()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def base_con_ruta(tmp_path, sin_supresion, manifest):
|
||||
base = base_de("cacu", tmp_path, datos=_con_ruta)
|
||||
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 base_con_tratamiento(tmp_path, sin_supresion, manifest):
|
||||
base = base_de("cacu", tmp_path, datos=_con_tratamiento)
|
||||
@@ -509,6 +542,30 @@ def test_the_times_to_treatment_are_counted_from_their_start_to_the_first_treatm
|
||||
assert (result.initial, result.n, result.median, result.excluded) == expected
|
||||
|
||||
|
||||
RUTA = { # url -> (población inicial, n, mediana, excluidas) en 2025-S2, con corte a fin de año
|
||||
"cacu/CACU_DIAS_TOMA_COLPOSCOPIA": (5, 1, 31.0, 4),
|
||||
"cacu/CACU_DIAS_TOMA_BIOPSIA": (5, 2, 41.0, 3),
|
||||
"cacu/CACU_DIAS_RESULTADO_COLPOSCOPIA": (3, 1, 21.0, 2),
|
||||
"cacu/CACU_DIAS_COLPOSCOPIA_BIOPSIA": (1, 1, 20.0, 0),
|
||||
"cacu/CACU_DIAS_BIOPSIA_DIAGNOSTICO": (2, 2, 12.5, 0),
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("url", sorted(RUTA))
|
||||
def test_the_times_along_the_screening_route_count_between_consecutive_events(base_con_ruta, manifest, url):
|
||||
"""Pins down the five times of the screening route on the fixture with H-007, 2025-S2 cut at the end of the year.
|
||||
From the sample: H-007's colposcopy (31 days) and the biopsy reports of H-004 (31) and H-007 (51); the other
|
||||
samples have none and their 60-day horizon has passed, so they are in the initial population and not measured.
|
||||
Between events: the colposcopy from the cytology result (21 days), the biopsy report from the colposcopy (20) and
|
||||
the diagnosis from the biopsy report (9 and 16 days). Fails if an event, its start, its horizon or the population
|
||||
each measure counts over 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_ruta))
|
||||
assert (result.initial, result.n, result.median, result.excluded) == RUTA[url]
|
||||
|
||||
|
||||
CONFIRMACION = "cacu/CACU_CONFIRMACION_CITOLOGIA"
|
||||
|
||||
|
||||
|
||||
@@ -84,11 +84,11 @@ def test_las_definiciones_son_las_del_manifiesto_de_dbt(base):
|
||||
measure the manifest declares stops reaching `cat_estrato` and `cat_measure`, or a second run deletes rows."""
|
||||
resumen = base.run("definitions")["definitions"]
|
||||
|
||||
# CaCu: three strata and its nine measures; CaMa: the five strata of its invasive cancers, the BI-RADS stratum of the histopathological result and its eleven measures;
|
||||
# CaCu: three strata and its fourteen measures; CaMa: the five strata of its invasive cancers, the BI-RADS stratum of the histopathological result and its eleven measures;
|
||||
# TEA: the age group and its ten measures.
|
||||
assert resumen["definitions"] == {"cacu": 12, "cama": 17, "tea": 11}[base.proyecto]
|
||||
assert resumen["definitions"] == {"cacu": 17, "cama": 17, "tea": 11}[base.proyecto]
|
||||
# Y el catálogo de publicación de §6f (T-19b): un `cat_measure` por measure, sincronizado.
|
||||
assert base.dominio.cat_measure_repository.count() == {"cacu": 9, "cama": 11, "tea": 10}[base.proyecto]
|
||||
assert base.dominio.cat_measure_repository.count() == {"cacu": 14, "cama": 11, "tea": 10}[base.proyecto]
|
||||
assert base.run("definitions")["definitions"]["borradas"] == 0
|
||||
|
||||
|
||||
|
||||
@@ -109,7 +109,8 @@ def test_indicators_recompute_from_imported_rows(client):
|
||||
assert {m["id"] for m in client.get("/cacu/indicadores").get_json()} == {
|
||||
"IND1", "CACU_EU13", "CACU_EU7", "CACU_CONFIRMACION_CITOLOGIA", "CACU_EU_TIEMPO_REPORTE",
|
||||
"CACU_DIAS_TOMA_DIAGNOSTICO", "CACU_DIAS_TOMA_TRATAMIENTO", "CACU_DIAS_DIAGNOSTICO_TRATAMIENTO",
|
||||
"CACU_RIESGO_BANDA"}
|
||||
"CACU_DIAS_TOMA_COLPOSCOPIA", "CACU_DIAS_TOMA_BIOPSIA", "CACU_DIAS_RESULTADO_COLPOSCOPIA",
|
||||
"CACU_DIAS_COLPOSCOPIA_BIOPSIA", "CACU_DIAS_BIOPSIA_DIAGNOSTICO", "CACU_RIESGO_BANDA"}
|
||||
|
||||
assert client.post("/reportes/indicadores/cacu/recalcular").status_code == 202
|
||||
assert client.post("/reportes/indicadores/xx/recalcular").status_code == 404
|
||||
|
||||
Reference in New Issue
Block a user