64 lines
3.7 KiB
Python
64 lines
3.7 KiB
Python
"""What this module covers: how silver reads the wording of a breast pathology report's text layer, as the hospital's
|
|
reports (and dev-data's synthetic ones) print it: the grade after a histological type that says "no especial", the
|
|
HER2 caption with its method in parentheses, and Ki-67 under its long caption. Each case is one report fragment.
|
|
|
|
Fixtures: none; the extractor is `silver.cama.DEL_REPORTE_DE_PATOLOGIA`, fed text through `lineas_de_texto`.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from webapi.orchestration.silver.cama import DEL_REPORTE_DE_PATOLOGIA
|
|
from webapi.orchestration.silver.extracted import lineas_de_texto
|
|
|
|
DIAGNOSTICO = (
|
|
"BIOPSIA: CARCINOMA DUCTAL INFILTRANTE (CARCINOMA INVASOR DE TIPO NO ESPECIAL) (8500/3), GRADO HISTOLÓGICO {g} "
|
|
"DE NOTTINGHAM (PUNTAJE 6/9). INVASIÓN LINFOVASCULAR: NO IDENTIFICADA."
|
|
)
|
|
|
|
|
|
def _leer(texto: str) -> dict:
|
|
extractor = DEL_REPORTE_DE_PATOLOGIA._extraer # the cached reader of text, as `leer` calls it
|
|
return extractor(texto)
|
|
|
|
|
|
@pytest.mark.parametrize("grado, codigo", [(1, "G1"), (2, "G2"), (3, "G3")])
|
|
def test_the_grade_after_a_type_that_says_no_especial_is_read(grado, codigo):
|
|
"""Pins down: "TIPO NO ESPECIAL" names a histological type, it does not deny what follows, so the Nottingham grade
|
|
later in the same line is still read. Fails if "no especial" stops being a pseudo-trigger of the negation context."""
|
|
assert _leer(DIAGNOSTICO.format(g=grado))["biopsia.grado_nottingham"][0] == codigo
|
|
|
|
|
|
@pytest.mark.parametrize("texto, codigo", [
|
|
("HER2/neu (IHQ): NEGATIVO (0)", "H0"), ("HER2/neu (IHQ): NEGATIVO (1+)", "H1"),
|
|
("HER2/neu (IHQ): EQUÍVOCO (2+)", "H2"), ("HER2/neu (IHQ): POSITIVO (3+)", "H3"),
|
|
])
|
|
def test_her2_is_read_with_its_method_in_the_caption(texto, codigo):
|
|
"""Pins down: a caption "HER2/neu (IHQ):" gives the score that follows it, not the "(IHQ):" of its own method.
|
|
Fails if the longer captions leave the catalog's `etiquetas_fuente` for HER2."""
|
|
assert _leer(texto)["biopsia.her2"][0] == codigo
|
|
|
|
|
|
def test_ki67_is_read_under_its_long_caption_and_not_from_the_name():
|
|
"""Pins down: "Índice de proliferación Ki-67: 25 %" gives 25, not the 67 of the marker's name. Fails if the long
|
|
caption leaves the catalog's `etiquetas_fuente` for Ki-67."""
|
|
assert float(_leer("Índice de proliferación Ki-67: 25 %")["biopsia.ki67_pct"][0]) == 25.0
|
|
|
|
|
|
@pytest.mark.parametrize("tipo, codigo", [("CARCINOMA MUCINOSO", "8480/3"), ("CARCINOMA TUBULAR", "8211/3"),
|
|
("CARCINOMA DUCTAL Y LOBULILLAR INFILTRANTE (MIXTO)", "8522/3")])
|
|
def test_the_rarer_invasive_types_are_read_as_their_code(tipo, codigo):
|
|
"""Pins down: a mucinous, tubular or mixed ductal and lobular carcinoma is read as its ICD-O-3 code rather than left
|
|
unresolved or taken as ductal or lobular. Fails if their names leave the catalog's aliases."""
|
|
assert _leer(f"Diagnóstico: BIOPSIA: {tipo} (8480/3).")["biopsia.tipo_histologico"][0] == codigo
|
|
|
|
|
|
@pytest.mark.parametrize("texto", [
|
|
"GRADO HISTOLÓGICO 2 DE NOTTINGHAM (PUNTAJE 6/9). TAMAÑO DE LA LESIÓN: 25 MM. INVASIÓN LINFOVASCULAR: NO.",
|
|
"GRADO HISTOLÓGICO 2 DE NOTTINGHAM (PUNTAJE 6/9). TAMAÑO DE LA\nLESIÓN: 25 MM. INVASIÓN LINFOVASCULAR: NO.",
|
|
"GRADO HISTOLÓGICO 2 DE NOTTINGHAM (PUNTAJE 6/9). TAMAÑO\nDE LA LESIÓN: 25 MM. INVASIÓN LINFOVASCULAR: NO.",
|
|
])
|
|
def test_the_lesion_size_is_read_even_when_the_page_wraps_its_caption(texto):
|
|
"""Pins down: "TAMAÑO DE LA LESIÓN: 25 MM" gives 25 whether it is on one line or the page wraps it between words,
|
|
because the extractor also sees each pair of adjacent lines joined. Fails if the joined lines stop being offered."""
|
|
assert float(_leer(texto)["biopsia.tamano_tumor_mm"][0]) == 25.0
|