Automático: several studies per layout, loose markers, joins only across documents, unreadable answers held
This commit is contained in:
@@ -5,7 +5,7 @@ column's date format, and the site's codes as a ConceptMap the platform accepts.
|
||||
from core import concept_map
|
||||
from core.drafting import codes_schema, layout_schema, table_schema
|
||||
from models.draft import fields
|
||||
from models.draft.documents import layouts
|
||||
from models.draft.layouts import layouts
|
||||
|
||||
FORM = (
|
||||
"SOLICITUD DE CITOLOGÍA CERVICAL\nNombre: {name}\nFecha de recepción: {date}\n"
|
||||
@@ -63,8 +63,12 @@ def test_a_columns_dates_get_the_format_every_value_parses_with():
|
||||
|
||||
|
||||
def test_answers_are_held_to_the_platforms_terms():
|
||||
layout = layout_schema()["properties"]["entity"]["enum"]
|
||||
assert "cervical_cytology" in layout and "none" in layout and "identity" not in layout
|
||||
layout = layout_schema(3)["$defs"]["Study"]["properties"]
|
||||
assert (
|
||||
"cervical_cytology" in layout["entity"]["enum"]
|
||||
and "identity" not in layout["entity"]["enum"]
|
||||
)
|
||||
assert layout["documents"]["items"]["enum"] == [1, 2, 3]
|
||||
codes = codes_schema(["NEGATIVO", "BAJO GRADO"], ["NILM", "LSIL"])
|
||||
one = codes["$defs"]["Code"]["properties"]
|
||||
assert one["raw"]["enum"] == ["NEGATIVO", "BAJO GRADO"]
|
||||
|
||||
@@ -3,8 +3,8 @@ garbles is still marked by a line it prints, and a report that leaves its sample
|
||||
the order it answers is paired with that order by the column both carry."""
|
||||
|
||||
from core.pipeline import Join, Route
|
||||
from models.draft.documents import printed_line
|
||||
from models.draft.joins import Kind, joined, partner
|
||||
from models.draft.joins import Kind, apart_from, joined, partner
|
||||
from models.draft.layouts import printed_line
|
||||
|
||||
HPV = (
|
||||
"No.Proceso {n}\nPaciente {name}\nDDDDEEEETTTTEEEECCCCCCCCIIIIOOOONNNN\n"
|
||||
@@ -38,5 +38,11 @@ def test_a_report_is_read_with_the_order_the_same_column_pairs_it_with():
|
||||
found = dict((r["_record"], t) for t, r in joined(node, reports.everyone, orders))
|
||||
assert found["h1"].startswith("SOLICITUD DE CITOLOGÍA") and "Proceso 1" in found["h1"]
|
||||
assert found["h0"].startswith("No.Proceso 0") # no order: its own text alone
|
||||
assert apart_from(next(r for _, r in joined(node, reports.everyone, orders)
|
||||
if r["_record"] == "h1"), orders) # fmt: skip
|
||||
both = row("c1", FORM.format(n=1, name="X") + "\n" + HPV.format(n=1, name="X"), 1)
|
||||
(_, itself), = joined(node, [both], Kind("cervical_cytology", "", "", [], [both],
|
||||
orders.route)) # fmt: skip
|
||||
assert not apart_from(itself, orders) # one file, order and report: paired with itself
|
||||
lone = Kind("cervical_cytology", "VPH", "x", [], reports.everyone[:1])
|
||||
assert partner(lone, [lone, orders]) is None
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"""One layout, several studies: the model is shown a layout's documents as unlike each
|
||||
other as they come (so the one note that records a death is among them), and a study only
|
||||
some of them report is kept only with a phrase that marks those and none of the others."""
|
||||
|
||||
from models.draft.documents import apart
|
||||
from models.draft.layouts import diverse, marks
|
||||
|
||||
NOTE = "INFORME MÉDICO\nNOMBRE: {name}\nMOTIVO DE LA CONSULTA: {why}\nPLAN: {plan}"
|
||||
ROUTINE = [
|
||||
NOTE.format(name=f"PACIENTE {n}", why="control anual", plan="cita en un año") for n in range(20)
|
||||
]
|
||||
DEATH = NOTE.format(name="PACIENTE 99", why="NOTA DE DEFUNCIÓN: falleció en urgencias",
|
||||
plan="certificado de defunción, causa: choque séptico") # fmt: skip
|
||||
PATHOLOGY = "ESTUDIO PATOLÓGICO\nNOMBRE: {name}\nÓRGANO: {organ}\nDIAGNÓSTICO: {dx}"
|
||||
|
||||
|
||||
def docs(texts: list[str]) -> list[dict]:
|
||||
return [{"_record": str(i), "text": t} for i, t in enumerate(texts)]
|
||||
|
||||
|
||||
def test_the_one_unlike_note_is_among_those_shown():
|
||||
notes = docs(ROUTINE[:10] + [DEATH] + ROUTINE[10:])
|
||||
assert any("DEFUNCIÓN" in r["text"] for r in diverse(notes, 3))
|
||||
assert len(diverse(notes, 30)) == len(notes)
|
||||
|
||||
|
||||
def test_a_study_some_documents_report_is_kept_with_what_marks_them():
|
||||
shown = docs([PATHOLOGY.format(name="A", organ="CÉRVIX", dx="NIC 2"),
|
||||
PATHOLOGY.format(name="B", organ="MAMA", dx="CARCINOMA DUCTAL"),
|
||||
PATHOLOGY.format(name="C", organ="CÉRVIX", dx="NIC 1")]) # fmt: skip
|
||||
log = []
|
||||
cervix = {"label": "Biopsia cervical", "documents": [1, 3], "marker": "ÓRGANO: CÉRVIX"}
|
||||
assert apart(cervix, shown, {2}, log.append) == "ÓRGANO: CÉRVIX"
|
||||
# The model's phrase marks the wrong documents: a printed line that does is taken.
|
||||
breast = {"label": "Biopsia de mama", "documents": [2], "marker": "DIAGNÓSTICO"}
|
||||
assert apart(breast, shown, {1, 3}, log.append) == "ÓRGANO: MAMA"
|
||||
# A study the model gives all but one, the one no other study claims: all of them.
|
||||
assert apart({**cervix, "documents": [1, 3]}, shown, set(), log.append) is None
|
||||
every = {"label": "Patología", "documents": [1, 2, 3], "marker": "ESTUDIO"}
|
||||
assert apart(every, shown, set(), log.append) is None # all of them: the layout's own route
|
||||
assert apart({**every, "documents": []}, shown, set(), log.append) is False
|
||||
alike = {"label": "x", "documents": [1], "marker": None} # nothing sets A apart from C
|
||||
assert apart(alike, shown, {3}, log.append) is False and log
|
||||
|
||||
|
||||
def test_a_phrase_the_model_tidied_still_finds_what_the_document_writes():
|
||||
organs = ["CÉRVIX", "MAMA DERECHA", "CERVIX", "MAMA IZQUIERDA"]
|
||||
shown = docs([PATHOLOGY.format(name=n, organ=f"{o}, BIOPSIA:", dx="X")
|
||||
for n, o in zip("ABCD", organs, strict=True)]) # fmt: skip
|
||||
breast = {"label": "Biopsia de mama", "documents": [2, 4], "marker": "MAMA, BIOPSIA"}
|
||||
found = apart(breast, shown, {1, 3}, print)
|
||||
assert [marks(found, r["text"]) for r in shown] == [False, True, False, True]
|
||||
cervix = {"label": "Biopsia cervical", "documents": [1, 3], "marker": "CÉRVIX, BIOPSIA"}
|
||||
found = apart(cervix, shown, {2, 4}, print) # written without its accent in C
|
||||
assert [marks(found, r["text"]) for r in shown] == [True, False, True, False]
|
||||
Reference in New Issue
Block a user