All projects 01 of 08

MedScribe Local

// Offline reader for handwritten prescriptions

Kind
Software
Year
2026
Status
In progress. Phases 1 to 4 done; drug-list matching, review UI and export still to do.

Reads a pediatrician's prescription slips with a local vision model, so patient data stays on the machine.

Stack
Python, OpenCV, Ollama, Qwen3-VL (qwen3-vl:4b)
Built with
A pediatrician in my hometown in India
Runs
Fully on the clinic's own machine
Pages screen of the MedScribe Local terminal UI in demo mode, listing six synthetic pages with their stage status and counts of agreeing, differing and withheld readings.
01

What it does

MedScribe Local reads a pediatrician's handwritten prescription slips and turns them into structured fields: patient ID, date, vitals, complaints, diagnosis, investigations and prescription lines. A person then checks them.

Everything runs on the clinic's own machine with a local vision model, so patient data never leaves the device. The output is a draft. The tool only transcribes; it does not advise, diagnose, correct or interpret.

02

The pipeline

  1. Preprocess

    Lift the blue and purple ink off the pink letterhead, deskew, apply CLAHE and binarize.

  2. Segment

    Match the printed letterhead to fix page coordinates, then cut 7 regions from config and split the prescription block into one crop per line.

  3. Read

    Send each region to qwen3-vl:4b in Ollama with one narrow prompt.

  4. Parse strictly

    Withhold a value, with a reason, when the reply is malformed, unparseable or implausible.

  5. Read twice

    Read every region with two differently worded prompts and record whether they agree.

  6. Evaluate

    Score exact match, character error rate, agreement and timing against ground truth the doctor verified.

03

Withhold, don't guess

The parser re-derives every value from the raw reply. If a value is not valid JSON, cannot be reduced to a number, or falls outside the field's plausible range, it is stored as null with a reason. It is never repaired.

Example: the model once read a printed % sign as a digit and returned an SpO2 of 100.1. Rounding that to 100 would look right and still be made up, so it is withheld. Lists are all or nothing, because three of four complaints looks like a complete list.

04

How well does it work?

Measured on 7 real slips, which is every slip so far. At this size one page moves most numbers by about 14 points, so treat these as a baseline, not a verdict on the approach. qwen3-vl:4b on Ollama 0.40.14, pass A, exact match against ground truth.
RegionExact match
vitals (weight, temperature, SpO2, heart rate, ...)38/42
header (patient ID, name)4/14
date1/7
diagnosis3/14
complaints0/7
investigations0/7
prescription lines5/44
05

What the numbers leave open

Two-pass agreement is 87 of 247 fields. Both passes can agree on the same wrong value, so agreement is a signal for review, not a confidence score.

The vitals work. The free-text regions, the header, and speed on the clinic's CPU-only machine are open problems. On hard handwriting the 4B model swaps in real drug names that are not on the slip. Checking drug names against the clinic's own drug list is the next phase.

06

Checking the labels, not just the model

Several fields first scored near zero because the ground truth was wrong, not the model. Patient IDs had been written inside the template's example slot, circled durations were recorded as missing, and one slip gave a duration in hours. The schema now stores a duration and a unit, and a missing unit is stored as unknown, not assumed to be days.

An Ollama auto-update (0.32.6 to 0.40.14) also broke the JSON output with no code change. Replies are cached by crop hash, region, model and prompt version, so every number can be replayed and runtime changes show up as diffs.

07

Terminal UI

One synthetic page open in the terminal UI, comparing extraction pass A and pass B for each vitals field, with one differing value and one value withheld with its reason.
Pass A against pass B; a withheld value shows why
Run screen of the terminal UI showing preprocess and extract stages replayed from cache, with a note that inference is off in demo mode.
Run screen; inference is disabled in the demo
Eval screen of the terminal UI with per-field exact-match accuracy and overall tables computed from synthetic fixtures.
Eval screen on synthetic fixtures

A keyboard-driven terminal UI sits over the same pipeline. It computes nothing itself; every number on screen comes from the stages and the eval harness. It is not the review UI, and you cannot correct anything in it.

The repository ships no scans, fixtures or cache, because the real ones contain patient data. The demo mode builds six made-up pages in a temporary folder and needs neither scans nor Ollama.

08

Run the demo

powershell
git clone https://github.com/KickPi314/medscribe-local-public.git
cd medscribe-local-public
py -3 -m venv .venv
.venv\Scripts\python.exe -m pip install -r requirements.txt
.venv\Scripts\python.exe -m src.tui --demo
09

Phases

PhaseScopeStatus
1Preprocessing pipeline, intermediate image dump, eval harness skeletonDone
2Region segmentation from a config-driven templateDone
3Single-region extraction (vitals), measured against ground truthDone
4Remaining regions and two-pass agreementDone
ExtraTerminal UI over phases 1 to 4Done
5Formulary, validation and flaggingTo do; waiting on the clinic's drug list
6Review UITo do
7Export and audit logTo do
8Packaging and setup documentationTo do
//

Notes

  • The public repository is a scrubbed copy of a private one. Patient scans, ground truth and model outputs are not in it, and identifying details were replaced with placeholders.
  • Screenshots use the synthetic demo data.
  • Most of the code was written with Claude Code. The design decisions, work on the ground truth and failure analysis are mine.