Files
edgar ae440e074d
pruebas / pytest (push) Failing after 4s
CaCu: the valuation visit, the colposcopy and the treatment as medical notes (S-D20)
After an anomalous cytology, poblar and documentos add, in clinical order, the valuation visit, the colposcopy (the day
its biopsy is requested, with the kit's reason as its note) and, for some biopsies, the treatment. The notes follow the
kit's lists and do not resolve any sample, so what was already generated stays the same.
2026-11-22 02:31:40 -06:00

129 lines
4.9 KiB
Python

"""CaCu: la cita de valoración, la colposcopia y el tratamiento que se agregan a las historias (S-D20).
Los CIE-10, la especialidad y el motivo se comparan con los del kit (`cacu.seguimiento.*`), no con una copia.
"""
from datetime import date
import pytest
from dev_data.azar import Azar
from dev_data.cacu.cancer import con_cancer
from dev_data.cacu.filas import a_filas
from dev_data.cacu.historias import CIE_DE_LA_CITOLOGIA, COLPOSCOPIA, ONCOLOGIA
from dev_data.cacu.ruta import CIE_DE_LA_COLPOSCOPIA, PROPORCION_TRATADA, TRATAMIENTO_DESDE
from dev_data.parametros import valores_del_archivo
REFERENCIA = date(2026, 1, 1)
N = 500
SEMILLA = 7
def _cie(codigo: str) -> str:
"""El CIE-10 como lo lista el kit: sin punto."""
return codigo.replace(".", "")
@pytest.fixture(scope="module")
def mujeres():
return con_cancer(N, Azar(SEMILLA, REFERENCIA))
def _colposcopias(h):
return [n for n in h.notas if n.motivo]
def _tratamientos(h):
return [n for n in h.notas if n.toma is None and n.especialidad == ONCOLOGIA and _cie(n.cie).startswith("D06")]
def _valoraciones(h):
return [n for n in h.notas if n.toma is None and n.especialidad == COLPOSCOPIA and not n.motivo]
def test_hay_valoraciones_colposcopias_y_tratamientos(mujeres):
assert any(_valoraciones(h) for h in mujeres)
assert any(_colposcopias(h) for h in mujeres)
assert any(_tratamientos(h) for h in mujeres)
def test_la_cita_de_valoracion_es_anterior_a_la_colposcopia(mujeres):
for h in mujeres:
for colposcopia in _colposcopias(h):
assert any(v.fecha < colposcopia.fecha for v in _valoraciones(h))
def test_la_valoracion_es_una_nota_de_diagnostico_de_colposcopia_segun_el_kit(mujeres):
kit = valores_del_archivo()
diagnostican = set(kit["cacu.diagnostico.cie"])
notas = [v for h in mujeres for v in _valoraciones(h)]
assert notas and {_cie(v.cie) for v in notas} <= diagnostican
assert {v.especialidad for v in notas} == {COLPOSCOPIA}
def test_la_nota_de_colposcopia_lleva_el_motivo_y_los_cie_del_kit(mujeres):
kit = valores_del_archivo()
notas = [c for h in mujeres for c in _colposcopias(h)]
assert notas
assert {c.motivo for c in notas} <= set(kit["cacu.seguimiento.colposcopia.motivos"])
assert {_cie(c.cie) for c in notas} <= set(kit["cacu.seguimiento.colposcopia.cie"])
assert {c.especialidad for c in notas} == {COLPOSCOPIA}
def test_los_cie_de_la_ruta_son_los_que_se_declaran_aqui():
assert set(CIE_DE_LA_COLPOSCOPIA) <= set(CIE_DE_LA_CITOLOGIA)
def test_la_solicitud_de_una_biopsia_cae_el_dia_de_una_colposcopia(mujeres):
biopsias = [(h, b) for h in mujeres for b in h.biopsias]
coinciden = [1 for h, b in biopsias if any(c.fecha == b.fecha_solicitud for c in _colposcopias(h))]
assert biopsias and len(coinciden) / len(biopsias) > 0.7
def test_la_valoracion_de_una_biopsia_es_anterior_a_su_solicitud(mujeres):
for h in mujeres:
for b in h.biopsias:
if any(c.fecha == b.fecha_solicitud for c in _colposcopias(h)):
assert any(v.fecha < b.fecha_solicitud for v in _valoraciones(h))
def test_el_tratamiento_es_posterior_a_la_colposcopia_y_al_reporte_de_la_biopsia(mujeres):
kit = valores_del_archivo()
tratadas = [h for h in mujeres if _tratamientos(h)]
assert tratadas
for h in tratadas:
for t in _tratamientos(h):
assert _cie(t.cie) in set(kit["cacu.seguimiento.tratamiento.cie"])
assert any(c.fecha < t.fecha for c in _colposcopias(h))
assert any(b.fecha_reporte and b.fecha_reporte.toordinal() + TRATAMIENTO_DESDE <= t.fecha.toordinal() for b in h.biopsias)
def test_solo_se_trata_a_quien_tiene_una_biopsia_de_un_grado_con_tratamiento(mujeres):
for h in mujeres:
if _tratamientos(h):
assert any(b.grado in PROPORCION_TRATADA for b in h.biopsias if b.fecha_reporte)
def test_hay_menos_tratamientos_que_colposcopias(mujeres):
assert 0 < sum(len(_tratamientos(h)) for h in mujeres) < sum(len(_colposcopias(h)) for h in mujeres)
def test_las_notas_de_la_ruta_no_resuelven_ninguna_toma(mujeres):
assert all(n.toma is None for h in mujeres for n in [*_valoraciones(h), *_colposcopias(h), *_tratamientos(h)])
def test_ninguna_nota_pasa_de_la_referencia_ni_de_la_defuncion(mujeres):
assert all(n.fecha <= REFERENCIA for h in mujeres for n in h.notas)
assert all(n.fecha <= h.defuncion for h in mujeres if h.defuncion for n in h.notas)
def test_las_notas_de_cada_mujer_van_en_orden_de_fecha(mujeres):
assert all([n.fecha for n in h.notas] == sorted(n.fecha for n in h.notas) for h in mujeres)
def test_las_filas_llevan_el_motivo_de_la_colposcopia(mujeres):
filas = a_filas(mujeres)
con_motivo = [n for n in filas["notas"] if n.nm_motivo_consulta]
assert len(con_motivo) == sum(len(_colposcopias(h)) for h in mujeres)
assert {n.nm_especialidad for n in con_motivo} == {COLPOSCOPIA}