A medical document OCR pipeline moves clinical documents from capture to structured data in stages. Intake agents collect documents, image clean-up repairs scans and faxes, classification decides what each document is, OCR extracts text with a confidence score, and routing sends the structured result downstream. Recognition is one stage out of five, and most production failures happen in the other four.

We have built each of these stages for clinical operators, and in none of the failures we were called in for was the OCR engine the cause. Documents were lost before they reached it, arrived unreadable, carried the wrong label or passed through with unscored mistakes. Buying a better engine fixes the one stage that was already working.

The shape of the pipeline

Each stage exists to stop one kind of failure. Capture stops lost documents and documents with no provenance. Clean-up stops unreadable input from producing nonsense. Classification stops the right fields being read from the wrong form. OCR with a confidence score stops wrong reads from entering the record unmarked. Routing stops duplicates, silent drops and errors that spread downstream.

The order of the stages counts too. Clean-up runs before classification, since a classifier trained on clean images misfires on raw faxes. Classification runs before OCR, since the document type decides which fields are worth reading: a lab result, a signed consent and a claim form each have their own.

Capture with watcher agents

Manual uploads lose clinical documents. The reliable alternative is unattended capture: watcher agents at every endpoint detect new files, hash them for chain of custody and push them to a central store with no staff involved. Our clinical document watcher works this way and replaced FTP polls and manual uploads that had been losing and duplicating documents.

Two properties make capture fit for production. During a network or storage outage the agents keep files locally with checkpoint markers and later continue from the last marker without sending duplicates, so an outage loses nothing. And hashing at capture starts the chain of custody at the source, so a compliance question becomes a lookup in the audit log.

OCR pipeline stages: capture agents, image clean-up, classification, scored OCR, fallback path, routing to the record
Each stage stops one failure: lost files, unreadable scans, wrong document types or uncertain reads.

Image clean-up before OCR

Medical paperwork arrives skewed, noisy and faint, often as a photocopy of a photocopy. A person can read it; a model often cannot, and OCR on raw input produces confident nonsense that is far harder to remove from a record than to stop.

Our scan and fax clean-up pipeline deskews, denoises and normalizes contrast, and a small classifier chooses the profile for each input type: scan, fax or photo of paper. Each page then gets a readability score before OCR. Pages that stay unreadable go through stronger filters, and pages that still fail go to human review. Every transformation is logged, so the record shows what was done to an image before anything read it.

Classification and extraction

Classification gives each document a type, and the type decides what follows: which fields to extract, which checks apply, where the result goes. A wrong type is worse than a failure, because a lab value read from the wrong form looks plausible. Classification confidence therefore gets the same routing as OCR confidence.

Extraction runs on scores as well. Confident reads go to the clinical data store; uncertain ones take a fallback route with stronger preprocessing, a second engine or a barcode read where the document carries one; repeated failures go to an escalation queue with their processing history. No read enters the record without a confidence decision recorded next to it.

Throughput under burst load

Document traffic comes in bursts: batch drops, the morning fax rush, quarter-end. Sizing for average load guarantees a backlog at the busiest hour. The pipeline in our image classification and OCR case replaced synchronous workers that fell behind in bursts and lost frames when the GPUs saturated.

Three changes fixed it. Worker batch sizes adjust to available GPU memory. Deduplication by content hash means a resent document costs nothing downstream. Queue depth and per-stage latency are tracked as primary metrics, so a backlog shows on a dashboard while it forms. With batch size capping the cost of each image, a spike raises latency and loses no frames.

Put together, the five stages are judged by how they handle the worst page of the worst fax on the busiest day. Accuracy on clean pages is something every engine already has.