ADR-0006: Mirror the ŠÚKL registry locally and extract appearance from leaflets
- Status: Accepted
- Date: 2026-07-25
- Supersedes: None
- Superseded by: None
Context
Medications were captured entirely by hand, and their pill appearance was guessed from the name and form (ADR-0005). Slovakia's medicines authority (ŠÚKL) publishes the national registry, but not as an API:
https://www.sukl.sk/verejne/is an open directory of monthly ZIP archives.zoznam_liekov_aktualny.zip(~6 MB) holdszoznam_liekov.xlsx— 54,800 packages with ŠÚKL code, registration number, name, pack description, strength, ATC, dispensing status and marketing-authorisation holder.spc_pil_aktualny.zip(~3.8 GB) holds every patient leaflet (PIL) and SmPC, plus an index page mapping ŠÚKL code → document file name.- No appearance columns exist anywhere. Colour, shape, score, imprint and dimensions appear only as prose in PIL section 6 ("Ako vyzerá … a obsah balenia"), e.g. "biele okrúhle (priemer 6 mm) mierne vypuklé filmom obalené tablety so skosenými hranami".
The US path (RxNav ndcproperties) does return structured colour, shape,
imprint, size and score, but only for NDC-labelled products; it does not cover
the Slovak market.
Decision
- Mirror, don't proxy. The registry is ingested into local tables
(
sukl_products,sukl_documents) with a snapshot row per ingest (sukl_snapshots) recording the source URL, upstreamLast-Modified, item count and fetch time. Lookups then work offline and staleness is answerable per dataset, per record. - Range-read the document archive. ŠÚKL's server honours HTTP range
requests, so
zip.tsreads only the 3.8 GB archive's central directory and index, and pulls individual leaflets (~270 KB) on demand. Extracted text is cached per file name insukl_document_text. Nothing mirrors the corpus. - Rules-first extraction.
appearance-sk.tsmaps a closed Slovak lexicon over diacritic-folded text — deterministic, auditable and free. Every parse keeps the sentence it read and a confidence score. No model is involved. - Both documents, per strength. The leaflet and the SmPC fail in different places, so both are parsed: the PIL says "biela tableta" and stops, while the SmPC's form section adds the outline and the printed marking. A leaflet also usually covers every strength of a medicine at once ("Concerta 18 mg… 36 mg… 54 mg"), so the package's own strength selects the line that describes it.
- Facts, then a resolved profile. Extraction writes one row per attribute
per source (
pill_appearance_facts, replacing only that source's rows); a resolver collapses them intopill_profilesby a fixed priority (manual>sukl-pil>sukl-spc, then confidence). Editing a pill by hand writes amanualoverride the resolver will not overwrite; the automatic first bake does not, since nobody edited it. That override carries the whole appearance — construction, colours, marking and dimensions in millimetres — and is written for every package of the same product (same registration number, strength and form), because the registry is package-level and one medicine is a dozen rows differing only in box size. - Two shape vocabularies.
PillShapestays the five shapes the Three.js foundry can draw and the editor offers;ShapeToken(src/lib/pill/shapes.ts) carries what the document actually said — heart, hexagon, teardrop — and maps to the nearest renderable shape at draw time. The UI says when the render is an approximation. - Verified geometry is a separate fact. The generic outline words in a
leaflet cannot establish a tablet's edge construction, so a manual correction
may store an optional
tablet_geometryon the local package profile (domed-oblongfor a biconvex belly,barrel-oblongfor a rolled osmotic cylinder). It applies to later drafts for that exact ŠÚKL code; without it an oblong renders as the flat-faced caplet. Shape tokens are never overloaded to carry this — anovalread from oválne has to keep meaning an oval. - Drafts are proposals. A lookup fills the add form; only the person's
submit writes a medication.
medications.sukl_coderecords which package a record came from.
Consequences
- A medication can be added in two clicks with name, strength, pharmaceutical form, ATC substance, dispensing status and a leaflet-accurate pill render.
- Corrections compound: what a person fixes once on any pack of a medicine is what every later record of that medicine starts from, and the editor states which of the two it is showing.
- Measured on a 100-package sample: 95 produced an appearance (mean confidence
0.77). The five failures are Word 97 leaflets — ~9 % of the archive is
.doc, which needsantiword/LibreOffice that the app does not depend on; those records fall back to the ADR-0005 heuristic appearance and say so. - Extraction quality is a lexicon, so it fails in specific, fixable ways rather than diffusely. Each trap found in the corpus (a "prolonged release" phrase read as an elongated shape, a caplet read as a capsule, a compound colour word read as two colours, "s čiernym nápisom" read as a black pill, one leaflet's first strength answering for all of them) is now a regression test.
- Coverage is Slovak-market only. Foreign or unregistered products find nothing and fall back to manual entry.
- The renders remain illustrative (ADR-0005). Name, strength, holder and pack always outrank the picture, and the leaflet sentence is shown beside it.
- Syncing writes ~55,000 rows while other processes hold the database open, so
the sync sets
PRAGMA busy_timeout. Deployments that run the app server continuously should put SQLite in WAL mode. - ŠÚKL publishes no explicit reuse licence. The mirror is local and single-user; redistributing it would need that question answered first.