1. Goals, and how far the current build meets them
The project has two goals. (1) An ongoing, auditable ledger of how EU rules are implemented in each Member State, how to map between the implementations, and how large the gap between them is, whether linguistic or procedural. (2) An MCP server and API that give cancer patients the best EU care options, with costs and conditions referenced to official documents.
| Requirement | Status | What exists now | What is missing |
|---|---|---|---|
| Log every site, API and file accessed, with timestamps, before processing | done | Write-ahead, hash-chained audit ledger in D1 (§4); originals stored by SHA-256. | External anchoring outside Cloudflare. |
| Track changing rules over time | done | Each re-fetch is compared by hash. Changed bytes create a new document version and change events; unchanged bytes create none. | History deepens as the hourly schedule keeps running. |
| Store original, translation and compact reference | done | Original bytes, extracted text, English translations (two methods) and an LLM reference card per legal text, all hash-linked. | Full-document translation is opt-in per source (budget). |
| EU directive → national implementation mapping | partial | Directive 2011/24/EU in 4 official languages and Regulation 883/2004 are ingested and split into articles. | National transposition acts (NL, DE, RO) are not yet sources, so the transposition table is empty. |
| Size of the gap (linguistic / procedural) | partial | Coverage, granularity, linguistic distance and translation disagreement, per concept and country (§9). | Procedural gap (prices, authorisation rules) needs DE/RO tariffs. |
| MCP server / API for patients | done | 7 read-only MCP tools and a REST API, every answer with provenance. | Patient-friendly wording; per-country contact-point info. |
| Costs referenced to official documents | partial | NL: national average sale price per care product (NZa) — pipeline ready. | DE (InEK DRG × state base rate) and RO (CNAS) prices. |
| Conditions (cross-border routes) | partial | S2 vs Directive route with citations to the ingested EU texts. | National lists of care requiring prior authorisation. |
| "Best EU care" for a patient | not yet | — | Needs quality data (e.g. ECIBC-certified breast units, outcomes). Out of the current scope; listed honestly. |
2. Sources checked, and why they were selected live
Selection rules: (a) the publisher is the body legally responsible for the code system, tariff or law, or its official portal; (b) the content is public and its licence allows at least storing and citing it; (c) it covers the worked example (breast-cancer surgery) or the EU rule being implemented; (d) it can be fetched automatically within the free plan, or through the heavy lane for large files. When the best available copy is not from the official publisher (Romania), that is stated and the source is kept private.
| Where | Publisher and source | Why it was selected | Licence |
|---|
2a. Romania: why the procedure list is hard to pull, and the official sources used instead
Not an Australian dependency. RO DRG v1 is a Romanian classification (Ordin MS 1199/2011, MO 542/2011), but its content is derived from Australia's ICD-10-AM / ACHI / AR-DRG under a government licence. The only consequences are the licence caveat and the code format (letter + 5 digits, e.g. Q00701).
Why it fails at the edge. No ministry or SNSPMS download or API was found; the list exists only as a 7.8 MB, ~310-page PDF hosted by hospitals. The free plan's 10 ms CPU limit and the edge PDF converter returned about 6,000 of ~869,000 characters, so the full text comes from the heavy lane (pdftotext on GitHub Actions).
Official sources added.
- CNAS Ordin 1018/528/2025 (cnas.ro): Anexa 23 A gives the per-hospital base rate (TCP, ICM, DMS); Anexa 23 B II gives the DRG relative value (VR). Romanian price per case = TCP × VR. Breast DRGs are J1021 (major procedures, malignant, VR 1.2097) and J1031 (minor, malignant, VR 0.5482). A DRG is a payment group, so its price is shown at group level, with
skos:narrowMatchto "Breast cancer surgery". - CNAS consolidated norms 1857/441/2023 (cnas.ro, PDF): the rule text, stored and compacted.
- legislatie.just.ro (Ministry of Justice portal): the authoritative consolidated act. If its robots.txt disallows crawlers, the Worker does not fetch it; the ledger shows
fetch_skipped · robots_disallowand the citation stays in the reference catalogue. - cnas.ro/spitale: hospital indicators app; no API, snapshotted for the audit trail only.
2b. Reference catalogue (portable, for processing outside Cloudflare)
Table document_reference lists every official act, annex and classification PDF behind a Romanian figure: legal reference (e.g. Ordin MS/CNAS 1018/528/2025), publication reference, URL, host (official, official portal, mirror, third party, none), what it holds and where (annex, DRG codes). The view v_document_reference adds the live fetch outcome, last fetch time, SHA-256 and size from the ledger.
Exports: CSV, SQLite script (sqlite3 refs.db < document_reference.sql), JSON, and the MCP tool document_references. The repo holds the same catalogue as data/references/references.sqlite (built from the migrations by scripts/build-reference-db.mjs). scripts/fetch-references.mjs downloads and extracts the PDFs on any machine: it checks robots.txt, writes the attempt before each request, hashes the file, runs pdftotext, and appends results to local_fetch.
Open request: a Law 544/2001 information request to SNSPMS / the Ministry of Health for an official, machine-readable RO DRG v1 copy and its reuse terms (docs/requests/RO-544-2001-RO-DRG-request.md).
3. Pipeline: what runs, when, and why
An hourly schedule (minute 17, UTC) queues every enabled source whose refresh window has passed. Work then runs as small, idempotent jobs, one at a time, so crawling stays polite and each step fits the free plan's 10 ms CPU limit. Every job has a deterministic key, so repeating work is a no-op. The diagram and live counts are on Data model & pipeline.
| Step | Triggered by | What it does | Ledger events |
|---|---|---|---|
| fetch | hourly schedule; parser discovering child pages; admin run | robots.txt check (RFC 9309) → write-ahead log → conditional GET (ETag / Last-Modified) → SHA-256 → content store. Files over 4 MB are routed to the heavy lane. | robots_fetched, fetch_started, fetch_completed / fetch_not_modified / fetch_skipped / fetch_failed |
| extract | a new document version | HTML, PDF text layer, DOCX → Markdown with Workers AI Markdown Conversion; CSV and text kept as-is. Scanned PDFs with no text layer are flagged for OCR instead of guessed. | extracted / ocr_required |
| parse | extracted text | A deterministic parser per source type (OPS pages, EUR-Lex articles, NZa CSV, RO DRG list) produces codes, provisions or tariffs. Large files are read in 96 KB chunks. A hash of the parsed records is logged, so the parse can be re-checked. | parsed, parse_schema_mismatch |
| map | new codes | Proposes code → concept mappings with the keyword rules and parent chaining (§7). | mapped |
| translate | new non-English codes; backfill | Two English renderings per label: literal MT baseline and glossary-guided LLM (§5). | translated, translation_rejected |
| compact | new legal / guideline version; backfill | LLM reference card (title, scope, key points, rights and obligations), built from the parsed articles. | compacted |
| gap | new mappings or translations | Recomputes the gap score; skipped when its inputs hash is unchanged. | gap_computed |
| anchor | daily 03:17 UTC | Re-verifies new ledger rows and stores the head hash as a separate object. | anchor |
| backfill | every hourly run | Brings older data up to the current method (new model, new glossary) through normal jobs, never deleting. | (the events of the steps it queues) |
4. The audit ledger
- Write-ahead:
fetch_startedis written before a single byte is requested. Every later step records the hash of what it consumed (input_sha256) and what it produced (sha256), so any database fact can be traced back to the exact download. - Timestamps: UTC with milliseconds, inside the hashed row.
- Tamper evidence: each row stores
row_hash = SHA-256(canonical row, including the previous row's hash). Database triggers reject updates, deletes and any insert that doesn't continue the chain./api/ledger/verifyrecomputes the hashes, and a daily anchor stores the verified head separately. - Limit: a Cloudflare account administrator could drop the triggers and rewrite history. The chain makes that detectable, not impossible. Publishing the daily anchor somewhere independent is the next step.
5. English as the comparison baseline: how translation is done
English is used only as a pivot for comparison. The original-language label is always kept and shown. There are three kinds of English text, each recorded with its method:
| Text | Method | Why |
|---|---|---|
| EU legal texts | Official language versions fetched from EUR-Lex (EN, NL, DE, RO). No machine translation. | All language versions of EU law are equally authentic, so the EU's own translations are the reference for linguistic comparison. |
| National code labels — baseline | @cf/meta/m2m100-1.2b, literal machine translation, one label at a time. | A neutral, reproducible baseline. It is visibly weak on medical Latin: German Mamma (breast) became "mother" in the first live run. |
| National code labels — preferred | LLM (MODEL_COMPACT) with a curated medical glossary live in the prompt, temperature 0, JSON output checked for one translation per label. | Correct terminology. The glossary's hash is logged with every batch, so the output can be reproduced. Output that fails the check is rejected and logged, not stored. |
Where the two renderings differ, that difference is itself measured as translation disagreement (§9): it shows how much of an apparent gap may come from language rather than substance.
Glossary used (live)
| Lang | Term | English | Note |
|---|
6. The ontology on top of the ledger
National systems are not mapped to each other directly (that would need n×(n−1) crosswalks). Each one is mapped to a small reference concept tree that this project defines and versions in git (migration 0002), with EU/ECIBC guidance as the scope reference and WHO ICHI planned as the external anchor. Layers:
| Layer | Tables | Meaning |
|---|---|---|
| Jurisdiction → authority → source | jurisdiction, authority, source | Who publishes what, for which country or the EU. |
| Evidence | audit_ledger, artifact, document, document_version, rendition | What was read, when, and every derived text. |
| National vocabularies | procedure_system, system_version, code, code_label | Each country's code systems (procedure, billing product, DRG), versioned. |
| Reference concepts | concept (tree), concept_reference | The shared meaning that national codes are compared through. |
| Mappings | mapping (SSSOM shape, SKOS predicates) | "National code X relates to concept Y in way Z", with justification, confidence, author and review status. |
| Law, money, rights | legal_act, provision, transposition, tariff, entitlement_rule | The EU rule, its national implementation, prices, and patient routes. |
Current concept tree live
7. Matching algorithm (national code → concept)
- Lexical rules. Each concept has regular-expression keywords per language live, written for the original-language label (not the translation), so translation errors can't create false matches. Each rule carries the SKOS relation it proposes.
- Negation guard. A keyword preceded by zonder / ohne / fără / without does not count ("Mastectomie zonder okselklierdissectie" is not an axillary dissection).
- Most-specific wins. If a label matches both a concept and its child, only the child is proposed.
- Parent chaining. A code with no match of its own inherits its parent code's concepts as
skos:broadMatch(the code is narrower), confidence 0.4, justificationsemapv:MappingChaining. - Never auto-confirmed. Every mapping starts as proposed. A person confirms or rejects it through the admin API, and that review is itself logged.
Direction is always code → concept: closeMatch means about equivalent, broadMatch means the concept is broader than the code, narrowMatch means the concept is narrower.
Keyword rules (live)
| Concept | Lang | Pattern | Proposes |
|---|
8. Is there a semantic layer?
Yes, but deliberately a thin one. Matching (§7) is rule-based and explainable. Semantics comes in only for measuring: English labels and concept labels are embedded with @cf/baai/bge-m3, a multilingual embedding model, and compared by cosine similarity. Embeddings are computed when a gap is recalculated and are not stored; there is no vector database yet. Embedding-based candidate suggestions (always as proposals) are the planned next step, once a review interface exists.
9. Gap score
| Component | Question | How it is computed |
|---|---|---|
| Coverage | Does the country have any code for this concept or its sub-types? | 1 if none, else 0. |
| Granularity | How well does the closest code fit? | exact 0 · close 0.25 · code more specific 0.4 · code broader 0.6 · related 0.75 (best mapping wins). |
| Linguistic | How far is the national wording, in English, from the reference concept? | 1 − highest cosine(bge-m3) between the concept label and the preferred English labels. |
| Translation disagreement | How unstable is the English rendering? | Mean (1 − cosine) between the MT baseline and the glossary LLM translation of the same labels. |
| Procedural | Do price or authorisation rules differ? | Column exists; filled once DE and RO tariffs are ingested. |
| Composite | 1 if no coverage; otherwise the mean of granularity and linguistic. |
These scores are a screening signal for where to look, not a clinical equivalence judgement. They become meaningful once the proposed mappings have been reviewed.
10. EU and international standards referenced live
The EU has no common procedure-code system, so the "European standard" in this project is threefold: EU law (the common rule, in its authentic language versions), EU clinical guidance (ECIBC, which defines the scope of the reference concepts), and international interoperability standards (SKOS/SSSOM for mappings now; ICHI, SNOMED CT and the EHDS exchange format planned).
| Status | Standard | Issuer | How Rosetta uses it |
|---|
11. Known limitations
- Only one clinical area (breast-cancer surgery) and four jurisdictions (EU, NL, DE, RO).
- The Romanian list comes from a hospital-hosted copy of an ACHI-derived classification. It is kept private and its labels are withheld publicly until the official SNSPMS/CNAS copy is found.
- Keyword rules have high precision on these labels but limited recall. Unreviewed mappings must not be read as equivalences.
- Free-plan limits (10 ms CPU, 10,000 AI neurons per day) make processing slow; work is deferred rather than dropped.
- No national transposition acts yet, so goal 1's EU → national link is only measured at the procedure level.