Read keeps the file and says its format; extract takes fields from columns; EEG batches carry their recording, on Dask where it is installed

This commit is contained in:
Roberto Treviño
2026-11-27 16:25:01 -06:00
parent 3546269eaf
commit 385cc5b80b
7 changed files with 103 additions and 28 deletions
+9 -4
View File
@@ -6,7 +6,8 @@ one SQL Server table, the institute's forms beside what outsourced labs send bac
is a document of its own on its cytology's order; pathology comes scanned, the name surname
first and no birth date; some forms say "MA." for María or misspell the name and leave the
employee number out; some HPV reports were re-issued the other way; two women share a name.
Medical notes (the colposcopy clinic's, oncology's) and death notes are the institute's forms.
Medical notes (the colposcopy clinic's, oncology's, neurology's), death notes and TEA's
M-CHAT, ADOS-2 and EEG reports are the institute's forms.
"""
import json
@@ -15,6 +16,7 @@ from datetime import date
from core import catalog
ADOS2_SCORES = tuple(f for f, d in catalog.studies()["ados2"].fields.items() if d.type == "number")
FIELDS = {
"cervical_cytology": ("sample_date", "report_date", "adequacy", "result", "hpv", "hpv_16",
"hpv_18"),
@@ -25,9 +27,12 @@ FIELDS = {
"breast_treatment": ("start_date", "kind"),
"clinical_note": ("note_date", "specialty", "icd10"),
"death": ("death_date",),
"mchat": ("screening_date", "score"),
"ados2": ("evaluation_date", "module", *ADOS2_SCORES),
"eeg": ("study_date", "lab_record_id", "edf"),
} # fmt: skip
BOOLS = {"hpv", "hpv_16", "hpv_18"}
NUMBERS = {"ki67_pct", "size_mm"}
NUMBERS = {"ki67_pct", "size_mm", "score", *ADOS2_SCORES}
def value(field, v):
@@ -104,7 +109,7 @@ def test_a_site_becomes_silver_and_review_gets_the_rest(platform, site, tmp_path
# the documents say is read (a scan's columns can come back out of order, and a value its
# pattern doesn't find is left out, never guessed). A scan can misread one valid code as
# another ("IIA" as "IA"), which nothing in the text betrays: at most 1% of a scan's
# values, each listed.
# values (one, on a site too small for a rate), each listed.
at = {r["where"]: r for r in truth}
place = {r: f"ResultadoSubrogado:{i}"
for i, r in q("select id, _record from bronze.n__site__resultados")} # fmt: skip
@@ -134,7 +139,7 @@ def test_a_site_becomes_silver_and_review_gets_the_rest(platform, site, tmp_path
stated, read = stated + len(truly), read + len(got)
missed.update(set(truly) - set(got))
assert read >= 0.95 * stated, (entity, read, stated, missed)
assert len(wrong) <= 0.01 * scanned, (entity, wrong)
assert len(wrong) <= max(1, 0.01 * scanned), (entity, wrong)
# A row a rule held because of a value (a scan misread) is held because it is wrong:
# never loaded, and a reviewer sees it.