Back to the work

04VigiRegistro · Pharmacy safety

An offline safety registry for a hospital pharmacy

Personal product for a hospital pharmacy · Lima, PeruAI

Problem
The head of pharmacy at a public hospital in Lima copied every paper safety notification by hand into a yearly Excel file, on a locked-down PC with no paid AI.
My call
Keep the reader on the hospital PC and let it only propose. The user confirms every field, and there is no button to confirm them all.
What I produced
A local registry with two modules, a scan reader with a weighted evaluation rubric, a dashboard of 18 cards and an Excel export that matches the pharmacy's workbook cell by cell.
Result
The drug-safety export matches the pharmacy's workbook with 0 differences. The reader scores 74.4% against a 70% target, and the user still confirms every field.

Problem

The head of pharmacy at a public hospital in Lima, the decision maker on the hospital side, receives drug-safety and medical-device-safety notifications on paper and used to copy every field by hand into a yearly Excel file. That copying was the workload, and the same records feed statistics for management, the pharmacotherapy committee and, once a year, DIGEMID, the national medicines authority.

The setting ruled out the easy answers. The hospital PC allows no installs without IT, no USB sticks and no paid AI. Under Peru’s Ley 29733 patients appear as initials only, and a scan with a crossed-out name is still personal data. The pharmacy’s existing workbook is the format other offices expect.

I was the product owner of this personal build: I set the product, brought the pharmacy head’s requests from our calls into the plan and decided what to ship. Claude Code and Codex designed the mechanisms and wrote the code on my brief.

The system

Paper goes in at one end and the pharmacy’s own workbook comes out at the other. In between, a model may propose and only a person decides. The limits in the last row shaped every part above them.

Everything happens on one PC. Paper goes in at one end and the pharmacy's own workbook comes out at the other. Pick a part to read what it does, or follow one thing through.

One notification

  1. Paper form. A clinician fills the paper form. The pharmacy head crosses out the name and scans it.
  2. Scan. The app straightens the scan and shows it beside a form that follows the paper.
  3. Reader. The reader proposes the fields from the scan, with no network.
  4. Confirm. The user confirms or corrects each field. Names arrive as initials.
  5. Registry. Only confirmed values become data.
  6. Table. The notification joins the table and the dashboard's counts.
  7. Workbook. The year's workbook is generated in the pharmacy's own layout.
  8. Yearly send. The sheet for the national authority leaves with no patient data.

One field the reader gets wrong

  1. Reader. The model misreads a handwritten name, or fills a box that is empty on paper.
  2. Confirm. The field shows in amber beside the scan. The user corrects it against the paper and confirms.
  3. Registry. Only the confirmed value is saved, so the mistake costs a correction and never becomes a record.
Paper form
A clinician fills the official notification by hand. The pharmacy head crosses out the patient's name and scans it.
Scan
The app straightens the page and shows it beside the form. Straightening raised the reader's score and whitening the page lowered it, so the page is passed on as it is.
Reader
A small model on a bundled llama.cpp engine reads the scan and proposes each field. It runs with no network.
Confirmrules I set
Each proposal shows in amber with a confirm button. Correcting a field does not confirm it, and anything left unconfirmed returns to its old value on save.
Registry
One database on the PC is the source of truth, with both modules driven by one field list. An upgrade never drops or renames a column.
Table
Every notification, with the filters and chosen columns an Excel user expects.
Dashboardrules I set
Eighteen cards for drug safety, device safety or both. Counts describe reporting load, not harm, and a change on a small base is written in words.
Workbookrules I set
One Excel file per module. The drug-safety one reproduces the pharmacy's own workbook, and a test compares the two cell by cell.
Yearly send
A sheet for the national medicines authority, with no patient data on it.
Privacy law
Patients appear as initials. A crossed-out scan is not anonymous and sending it abroad is a cross-border transfer, so whatever reads scans stays on the PC.
The PC
No installs without IT, no USB sticks, no paid AI. The app is a portable folder with its own Python, offline and at zero cost.
Old workbook
The pharmacy's existing workbook is the reference: the design may change, the values may not.
The user
An Excel expert who is not technical. A misread percentage on a small base led to changes written in words and last year drawn as a ghost bar.

Key decision

The call
Keep the reader on the hospital PC and let it only propose: the user confirms every field, and there is no button to confirm them all.
Alternatives
  1. A newer cloud model. A 2026 study put the best of them at about 85% on fixed fields.
  2. A confirm-all button to make registering faster.
Why
Privacy law rules out sending a scan abroad and the PC has no paid AI, so the model had to be small and local. A small model does not only miss handwriting, it invents plausible medicine names and lot numbers, and in drug safety an invention is worse than a blank. The reader cleared its 70% target at 74.4%, saves typing and still cannot be trusted with a record, so every proposal waits for a person.

What I built

The product is a local web app with two modules, drug safety and device safety, on one page. A notification opens with the scan, straightened automatically, beside a form that follows the official paper. A table with Excel-like filters, a dashboard of 18 cards and each module’s workbook cover reporting.

The rules I set are tagged in the project record with my words and the date, such as «no quiero esconder nada» (“I don’t want to hide anything”) on 27 September, and change only on request. The user’s calls become decisions the same way: after my call with the pharmacy head on 30 October I added a device-safety workbook and hid three device-safety fields the user no longer needed, keeping their columns so that no real value is erased.

The product's rules

  • One field list

    Then
    A field is defined once and drives the form, the table and the Excel export
  • An upgrade never loses a value

    When
    A newer version opens an older database
    Then
    Columns are added, never dropped or renamed, and a differing value is never overwritten
  • The workbook is the acceptance bar

    When
    The code changes
    If
    The generated workbook still matches the pharmacy's original, cell by cell
    Then
    The change may ship
  • Small bases in words

    When
    A change is computed on a small base
    Then
    It is written in words, and last year shows as a ghost bar

    The pharmacy head had misread a percentage.

The reader's rules

rules I set
  • A proposal is not data

    When
    The reader fills a field
    Then
    It shows in amber and waits for the user

    Correcting a field does not confirm it.

  • Unconfirmed never saves

    When
    The user saves with fields unconfirmed
    Then
    Each one returns to its previous value
  • No confirm-all

    Then
    Every proposal is accepted one at a time

    A button that accepts everything at once was left out on purpose. Small models invent plausible values, so review is field by field.

  • Names become initials

    When
    The reader returns a person's name
    Then
    It arrives as initials, and an unreadable value leaves the field empty
VigiRegistro pharmacovigilance table in Spanish: module tabs, year selector and a New notification button across the top; a side panel of alerts that flag the same defect reported by several companies within 30 days; five indicator tiles with sparklines; and rows of notifications with number, pharmacy code, event and reception dates, medicine, sanitary registration and lot.
Pharmacovigilance table, the registry that replaces hand-copying paper notifications into Excel. Synthetic data
VigiRegistro dashboard for pharmacovigilance: an index of statistics cards on the left, five indicator tiles, a Main findings card that compares the year with the last one, and an Alerts card that names a contamination suspicion and repeated complaints across lots of one product.
Dashboard, the five indicators and the findings and alerts cards for one module. Synthetic data; the hospital’s name is left out
VigiRegistro table with the New notification menu open under its button, asking whether the notification is pharmacovigilance or technovigilance.
New notification, which first asks for the module. Synthetic data

AI design choices

  • Where the model runs. On the hospital PC: Qwen3.5-4B, a 4-billion-parameter model, on a llama.cpp engine bundled with the app, about 3.4 GB, with no network. Four local models were compared by size and license.
  • What it may decide. Nothing on its own. It proposes field values from the scan, and a proposal is not data until the user confirms it. The screens do not say AI: the button reads «leer el escaneo», “read the scan”.
  • How quality is measured. A rubric scores the reader field by field against three filled forms I copied by hand, and weighs each field by what it costs to read well. The chart shows where it earns its points.
  • The human in the loop. Checkboxes, dates and codes are read well enough to save typing. Doctors’ handwriting is harder: names and free text score under the target, and a small model can fill a gap with a plausible invention. So the user checks every field against the paper. Judging harm stays with people too: counts describe reporting load, not harm, and the product has no risk score.
Measured Where the reader can be trusted, by kind of field
  • Checkboxweight 1
  • Short datumweight 2
  • Codeweight 3
  • Blank boxweight 1
  • Long textweight 6
  • Short textweight 3

Share of rubric points earned on three filled forms, 10 October 2026: 73.5% overall. Read the way the app reads, from the straightened page, the reader reaches 74.4%. Handwritten text is what stays under the line.

How the reader is measured

  • A weighted rubric

    blank 1 · checkbox 1 · short datum 2code 3 · short text 3 · long text 6score = points earned ÷ 276 possiblepass mark 70%

    Each field weighs what it costs to read well. The reference is three filled forms I copied by hand.

  • An invention scores zero

    When
    The model fills a box that is empty on paper
    Then
    It earns nothing

    It filled 11 of 63 empty boxes.

  • A blank form must come out blank

    When
    A new version of the instructions is tried
    If
    A form with nothing filled in is read
    Then
    Every field must come back empty

    Shorter instructions scored the same and wrote two fields into a blank form, so the longer ones stayed.

  • The ceiling is the model, not the prompt

    14 set-ups: 66.5% to 74.6%best of the 14, field by field: 84.0%

    The model errs on the same fields each time, so a vote over several readings does not help.

Outcome

The drug-safety export matches the pharmacy’s workbook with 0 differences in every cell, style, width and chart, checked on synthetic records. The reader scores 74.4% against its 70% target, and still nothing it reads becomes data without the user. The update is packaged for the pharmacy’s Windows PC as a portable folder; handover is the next step.

Learnings

Keep the agents’ context lean from the first week. By October their working context had grown into a verbatim history so heavy that Codex truncated the instruction file, and the agents kept rebuilding screen rounds I had already replaced. I approved a rewrite into lean topic files: current rules with an owner and date beat a transcript.

This is the kind of work I do in a 10-day product discovery

Back to the work