Automático drafts whole pipelines (layouts, joins, codes) and suggests review answers

This commit is contained in:
Roberto Treviño
2026-12-03 10:42:18 -06:00
parent 1a1ea5c7a9
commit a2a9eb7af3
11 changed files with 814 additions and 42 deletions
+42
View File
@@ -0,0 +1,42 @@
"""Automático's judgements that need no model: a layout whose title the text layer
garbles is still marked by a line it prints, and a report that leaves its sample's date to
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
HPV = (
"No.Proceso {n}\nPaciente {name}\nDDDDEEEETTTTEEEECCCCCCCCIIIIOOOONNNN\n"
"ESPECIMEN: CEPILLADO CERVICOVAGINAL\nVVVVPPPPHHHH . . . . . NNNNEEEEGGGG"
)
FORM = "SOLICITUD DE CITOLOGÍA CERVICAL\nNombre: {name}\nFecha de recepción: 0{n}/03/2025"
def row(record: str, text: str, order) -> dict:
return {"_record": record, "_file": f"{record:0>64}", "text": text, "format": "pdf",
"orden_servicio_id": order, "tipo": "resultado"} # fmt: skip
def test_a_layout_is_marked_by_a_line_only_it_prints():
hpv = [row(f"h{n}", HPV.format(n=n, name=f"PACIENTE {n}"), n) for n in range(5)]
forms = [row(f"c{n}", FORM.format(n=n, name=f"PACIENTE {n}"), n) for n in range(5)]
assert printed_line(hpv, forms) == "ESPECIMEN: CEPILLADO CERVICOVAGINAL"
assert printed_line(forms, forms[:1] + hpv) is None # what it prints, another prints too
def test_a_report_is_read_with_the_order_the_same_column_pairs_it_with():
reports = Kind("cervical_cytology", "VPH", "cervicovaginal", [],
[row(f"h{n}", HPV.format(n=n, name="X"), n) for n in range(4)]) # fmt: skip
orders = Kind("cervical_cytology", "Citología", "citología", [],
[row(f"c{n}", FORM.format(n=n, name="X"), n) for n in range(1, 6)]) # fmt: skip
# `tipo` and `format` pair every document with every other: they pair nothing.
assert partner(reports, [reports, orders]) == (orders, "orden_servicio_id")
orders.route = Route(id="citologia", label="Citología", inputs=["texto"])
node = Join(id="vph_con_citologia", inputs=["vph", "citologia"],
on=[("orden_servicio_id", "orden_servicio_id")], how="left") # fmt: skip
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
lone = Kind("cervical_cytology", "VPH", "x", [], reports.everyone[:1])
assert partner(lone, [lone, orders]) is None