All projects 01 of 08
Med Scribe Local
// Offline reader for handwritten prescriptions
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

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.
The pipeline
- Preprocess
Lift the blue and purple ink off the pink letterhead, deskew, apply CLAHE and binarize.
- 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.
- Read
Send each region to qwen3-vl:4b in Ollama with one narrow prompt.
- Parse strictly
Withhold a value, with a reason, when the reply is malformed, unparseable or implausible.
- Read twice
Read every region with two differently worded prompts and record whether they agree.
- Evaluate
Score exact match, character error rate, agreement and timing against ground truth the doctor verified.
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.
How well does it work?
| Region | Exact match |
|---|---|
| vitals (weight, temperature, SpO2, heart rate, ...) | 38/42 |
| header (patient ID, name) | 4/14 |
| date | 1/7 |
| diagnosis | 3/14 |
| complaints | 0/7 |
| investigations | 0/7 |
| prescription lines | 5/44 |
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.
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.
Terminal UI



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.
Run the demo
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 --demoPhases
| Phase | Scope | Status |
|---|---|---|
| 1 | Preprocessing pipeline, intermediate image dump, eval harness skeleton | Done |
| 2 | Region segmentation from a config-driven template | Done |
| 3 | Single-region extraction (vitals), measured against ground truth | Done |
| 4 | Remaining regions and two-pass agreement | Done |
| Extra | Terminal UI over phases 1 to 4 | Done |
| 5 | Formulary, validation and flagging | To do; waiting on the clinic's drug list |
| 6 | Review UI | To do |
| 7 | Export and audit log | To do |
| 8 | Packaging and setup documentation | To 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.