Files
ISSSTELEON/Extraction

Extraction

Reads clinical documents (PDF with or without a text layer, images, plain text) and EEG files, and turns the documents into records of the fields an import target has (VAR-01..03, VARM-01..04a). It has no dependency on the rest of the platform: WebApi gives it the fields to look for and stores what it finds.

From pages to values

Step Module What it does
Reading readers/ Text layer with word positions (pdfplumber), Tesseract OCR on pages without one, embedded images located.
Records segmentation.py, records.py Pages split into records (by patient key, by page count, whole document) and records of the same key merged; the most confident value wins and confident disagreements are kept as conflicts.
Letterhead template.py Margin lines that repeat across different patients' documents are the issuer's, and fill nothing.
Candidates nlp/extractors.py Every reading of every field, each with how it was found (ExtractedValue.features): LabeledValueExtractor (caption and value, in columns too), PatternExtractor (values with a known shape), FreeTextMentionExtractor (catalog terms in prose), MeasurementExtractor (a number with its unit after its concept).
Context nlp/context.py Whether the report affirms, denies, supposes, quotes from history or from the clinical request each mention (ConText and NegEx), and which section it sits in.
Choice nlp/ranking.py One value per field: the most confident (HeuristicRanker) or a ranker learned from corrections (LearnedRanker).
Measurement nlp/evaluation.py Precision, recall and F1 per field against an answer key.

Everything a field is looked for with lives in nlp/vocabulary.py: captions (LABELS), catalog terms as reports write them (CLINICAL_TERMS), the concepts a generic answer must follow (ANCHORS), severity orders (SEVERITY), what a denied mention means for a presence field (NEGATED_VALUES), units (UNITS), what each kind of report is about (SUBJECTS), section headings and trigger phrases. A report format with a caption or a term the extractor doesn't know is fixed there, without code changes.

What the rules do

  • Assertions. A mention preceded, within its clause, by a negation ("sin", "negativo para"), a hypothetical ("en caso de", "un resultado"), a historical ("antecedente de") or an uncertainty trigger ("probable") is qualified accordingly. A form answer after it (Carcinoma invasor: NO) denies it, and a caption whose answer is elsewhere asserts nothing. Negated mentions fill nothing, except a presence field's negated_value ("sin actividad epileptiforme" is 0). Hypothetical ones fill nothing without a trained ranker.
  • Sections. A heading alone on its line opens a section until the next one: clinical data (what was suspected, presumed), history, description, result, and reference text (interpretation guides, reference intervals, methods), whose mentions describe no patient. A caption with its content on the same line qualifies only that line.
  • Generic answers. "POSITIVO", "NO", "NORMAL" in prose only count after their concept (ANCHORS or the field's captions), so a form's other positives don't fill the HPV result.
  • Severity. When a report affirms several values of an ordered field (one per specimen, one per breast), the most severe is the finding.
  • Subject. A record whose pages name another kind of study (SUBJECTS of the other targets) and not the target's fills nothing, and is flagged in the review. A record that names no study at all is not judged.
  • OCR look-alikes. On OCR pages, captions and terms also match with commonly confused characters collapsed (ocr_fold: l/I/!, 0/O inside words...), at a slightly lower confidence.

The learned ranker

LearnedRanker is a logistic regression over the candidates' features: method, assertion, section, label score, how many candidates agree, whether the document is on topic, crossed with the field and the method. It never sees the document's words, so its weights can be read and shared. It learns online with AdaGrad and L2, one batch at a time.

  • It starts from the rules. Its score is blended with the heuristic's, and trusted fully after TRUST_EXAMPLES examples. Until then, what the rules rule out (hypothetical mentions, off-topic documents) stays out.
  • Each domain's ranker is versioned in the model registry as <domain>-extraccion (models.io.extraction_ranker), with its five routine records like any model. Extraction uses the version in production, otherwise the latest.
  • It learns in line: when an import whose documents a person corrected is written, the corrected records become examples (WebApi, review_learning.py) and a new DEV version is registered in the background.
  • It can also learn from an answer key: python -m webapi.nlp train --documents <folder> --key <key.json>, which first estimates, leaving each document out in turn, how it does on documents it hasn't seen.

Measuring it (VAR-04, VARM-05)

python -m webapi.nlp evaluate --documents <folder> --key <key.json> prints precision, recall and F1 per field and overall, and which document and field each error is in (--with-values adds the values). The key gives, per document and target, the right value of each field checked, with null for a field that must stay empty. Measure on documents the vocabulary was not adjusted on: the score on the documents used to adjust it says how well it fits them, not how it generalizes.

References

  • Chapman WW et al. A simple algorithm for identifying negated findings and diseases in discharge summaries. J Biomed Inform 2001;34(5):301-310 (NegEx).
  • Harkema H et al. ConText: an algorithm for determining negation, experiencer, and temporal status from clinical reports. J Biomed Inform 2009;42(5):839-851.
  • Duchi J, Hazan E, Singer Y. Adaptive subgradient methods for online learning and stochastic optimization. J Mach Learn Res 2011;12:2121-2159 (AdaGrad).
  • Nayar R, Wilbur DC (eds.). The Bethesda System for Reporting Cervical Cytology, 3rd ed. Springer, 2015.
  • Darragh TM et al. The Lower Anogenital Squamous Terminology Standardization Project for HPV-associated lesions (LAST). Arch Pathol Lab Med 2012;136(10):1266-1297.
  • American College of Radiology. ACR BI-RADS Atlas, 5th ed., 2013.
  • Hirsch LJ et al. American Clinical Neurophysiology Society's Standardized Critical Care EEG Terminology: 2021 version. J Clin Neurophysiol 2021;38(1):1-29.
  • Smith R. An overview of the Tesseract OCR engine. ICDAR 2007.