Skip to content

medextract → observations bridge — scope

Status: Draft scope (not yet approved for build) Date: 2026-07-27

Blocked by design, not by effort. medextract's extraction, annotation and precision mechanism is still being worked on. Nothing here is built until that is finalised. Wiring a consumer to a pipeline whose output shape is still moving would freeze decisions on the wrong side of the boundary — and this app is the side that must not churn, because its rows are somebody's medical history.

Problem

The vision names three jobs: organise clinical records, understand them over time, prepare focused exports. The first and third are built. The second is severed mid-spine.

document → extraction (kind, value, source_page, source_region, status)
                ↓
           ✗ nothing writes across this gap
                ↓
        observations (loinc_code, value_num, unit, ref_low, ref_high,
                      taken_at, document_id ← never populated)

Both tables exist. Extractions are created and confirmed on the document page, then go nowhere. The only way an observation exists today is hand-typing it on /labs.

Measured on this deployment: 0 extractions ever created, 7 observations, every one with document_id: none and a hand-typed source. One real trend in the whole database — Ferritin, three readings, January to June.

That is the cost. A lab report holds twenty to forty values; entering them by hand means they are not entered, so there is nothing to understand over time.

Why medextract rather than a parser in this app

medextract (/mnt/bulk/srv/apps/medical-records-pipeline) already solves the hard half: PDFs, scans and photos of Slovak, Czech, English and Latin-abbreviated records into typed structured data, with layout/OCR, region-anchored output and a human review step that produces a golden.

Rebuilding that here would duplicate a pipeline that is already further along, in a codebase whose strength is the record rather than the extraction. The supplement label parser in this repo is the counter-example that proves the point: worth owning because the vocabulary is closed and tiny (Annex I/II). Clinical documents are neither.

The shapes already line up

Nothing needs inventing at the boundary — both sides are FHIR-shaped, which ADR-0001 chose for this app independently.

medextract ClinicalEntity app observations
coding (FHIR CodeableConcept — LOINC + SNOMED) loinc_code
normalized_value (str \| float) value_num / value_text
unit unit
observed/collected date taken_at
BoundingBox (page or normalized units) extractions.source_region
page index extractions.source_page
review status from the golden extractions.status

The app's extractions table was built for exactly this and has been waiting: source_page, source_region and status are the columns a region-anchored, human-reviewed pipeline produces.

Intended shape when it is built

  1. medextract stays the producer. It ingests, extracts, and a person reviews in its own reviewer. The golden is the reviewed truth — see that project's standing rule that a golden is never auto-rebaselined.
  2. The app imports a reviewed result, never a raw run. Only output a human has passed through review crosses the boundary. An unreviewed extraction becoming a clinical observation is the failure mode worth engineering against; the vision already forbids it in general terms.
  3. Import lands in extractions, not observations. It arrives as a proposal carrying page and region, and is promoted to an observation by the existing confirm step. The app's own review gate stays in the path even though medextract has one — they answer different questions: is this what the page says versus is this my medical history.
  4. Promotion writes provenance. The resulting observation carries document_id, and the page and region survive alongside it, so a number can be clicked back to the line it came from. That is the thing hand-entry can never give.
  5. Transport is a file, not a service. A run directory or exported JSON, read by the app. No socket between two local-first tools, no daemon, nothing that has to be running for the record to open.

Open questions — for when the mechanism settles

  • What is the stable interchange artifact? A golden file, a run manifest, or a purpose-made export. This is the decision that must not be taken early.
  • Units and reference ranges. ref_low / ref_high are per-lab and often printed beside the value. Does medextract carry them, and do they belong on the observation or on the source?
  • LOINC coverage. What fraction of Slovak lab panels resolve to a code, and what happens to those that do not — a named observation with no code, or a refusal?
  • Idempotency. Re-importing a corrected run must update rather than duplicate. Content hash of the entity plus document identity is the obvious key, mirroring the catalogue's corroboration approach.
  • Which direction owns the document. Both projects can hold the PDF; only one should be authoritative.

Not in scope

Connecting anything now. Changing medextract to suit this consumer while its own precision work is in flight. Any automatic promotion that skips review.

Sequencing

Trends, charts and analysis over observations come after this, not before. Charting seven hand-typed points proves nothing; the work only becomes answerable once real panels are landing with provenance.