TEA: an order carries its study's report as a PDF through the import
This commit is contained in:
@@ -348,3 +348,41 @@ def test_embedded_image_in_the_report_maps_onto_the_target_dicom_column(client):
|
|||||||
[row] = mastografia_repository.list(pac_id_hospital="IMG-0001")
|
[row] = mastografia_repository.list(pac_id_hospital="IMG-0001")
|
||||||
assert "nódulo circunscrito" in row.mast_interpretacion
|
assert "nódulo circunscrito" in row.mast_interpretacion
|
||||||
assert row.mast_dicom_blob.startswith(b"\x89PNG")
|
assert row.mast_dicom_blob.startswith(b"\x89PNG")
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_tea_order_keeps_the_pdf_its_sql_source_carries(client, tmp_path):
|
||||||
|
"""Pins down: `ord_pdf_blob` travels with the order from a SQL source into `ordenes_estudio`, byte for
|
||||||
|
byte, and an order without a file stays without one. The source is a SQLite file in `tmp_path` holding a
|
||||||
|
two-row `ordenes_estudio`. Fails if the import schema drops the field or the commit rewrites the bytes."""
|
||||||
|
report = text_pdf([["EVALUACION PSICOLOGICA", "ADOS-2 Modulo 2"]])
|
||||||
|
url = f"sqlite:///{tmp_path / 'hospital.db'}"
|
||||||
|
table = sa.Table(
|
||||||
|
"ordenes_estudio", sa.MetaData(),
|
||||||
|
sa.Column("ord_id", sa.String(36), primary_key=True),
|
||||||
|
sa.Column("ord_id_hospital", sa.String(64)),
|
||||||
|
sa.Column("ord_tipo_estudio", sa.Text),
|
||||||
|
sa.Column("ord_pdf_blob", sa.LargeBinary),
|
||||||
|
)
|
||||||
|
engine = sa.create_engine(url)
|
||||||
|
table.create(engine)
|
||||||
|
with engine.begin() as connection:
|
||||||
|
connection.execute(sa.insert(table), [
|
||||||
|
{"ord_id": "ord-pdf-1", "ord_id_hospital": "ORD-PDF-1", "ord_tipo_estudio": "ADOS2", "ord_pdf_blob": report},
|
||||||
|
{"ord_id": "ord-pdf-2", "ord_id_hospital": "ORD-PDF-2", "ord_tipo_estudio": "EEG", "ord_pdf_blob": None},
|
||||||
|
])
|
||||||
|
engine.dispose()
|
||||||
|
source = {
|
||||||
|
"source_type": "sql",
|
||||||
|
"target": "tea.OrdenesEstudio",
|
||||||
|
"column_mapping": {column.name: column.name for column in table.columns},
|
||||||
|
"payload": {"connection_string": url, "table": "ordenes_estudio"},
|
||||||
|
}
|
||||||
|
|
||||||
|
result = client.post("/imports/commit", json={"sources": [source], "on_conflict": "upsert"}).get_json()["results"][0]
|
||||||
|
|
||||||
|
assert (result["created"], result["rejected"]) == (2, 0), result
|
||||||
|
|
||||||
|
from persistance.tea import ordenes_estudio_repository
|
||||||
|
|
||||||
|
assert ordenes_estudio_repository.get("ord-pdf-1").ord_pdf_blob == report
|
||||||
|
assert ordenes_estudio_repository.get("ord-pdf-2").ord_pdf_blob is None
|
||||||
|
|||||||
@@ -15,3 +15,4 @@ class OrdenesEstudioImportSchema(ImportSchema):
|
|||||||
ord_id_hospital: OptionalStr = None
|
ord_id_hospital: OptionalStr = None
|
||||||
ord_tipo_estudio: CatalogValue(_TIPO_ESTUDIO_CATALOG) = None
|
ord_tipo_estudio: CatalogValue(_TIPO_ESTUDIO_CATALOG) = None
|
||||||
ord_fecha: FlexDate = None
|
ord_fecha: FlexDate = None
|
||||||
|
ord_pdf_blob: Optional[bytes] = None
|
||||||
|
|||||||
Reference in New Issue
Block a user