Automático: several studies per layout, loose markers, joins only across documents, unreadable answers held
This commit is contained in:
@@ -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