SHC vNext QR proof of concept
SHA-256 Extension · 0x00 0 WASM imports · 0 floats Bit-packed clinical quantizer (quarter-diopter optical fields)

Vision Prescription

Bit-packed eyeglasses and contact lens prescriptions (sphere, cylinder, axis, add, prism, base curve, diameter, PD) expanding to FHIR R4 VisionPrescription + LOINC 79886-8 Observation.

WASM module29,823 Bvision-rx.wasm
Card sizes70–200 Bacross 4 sample records
Max FHIR ÷ card20×deterministic FHIR R4 output
Best QR versionVersion 6-Lup to Version 10-L

Try live in Viewer (progressive-prism) Download WASM (by hash) View model.d.ts

Quick launch any sample record in the universal viewer:

progressive-prism toric-contacts glasses-plus-contacts simple-myopia

Card header
0x00 followed by the 32-byte SHA-256 digest of the WebAssembly module (35 bytes total card framing including the 2-byte SHA-256 check)
SHA-256
7e6ae21f82b4f2bc5c9046d0416d2870bdbbf869401b90a645577e5aac3f9cd0 (download by hash)
WASM exports
memory, shc_alloc, shc_decode, shc_encode (0 host imports)
Machine-readable files
model.d.ts · codecs/vision-rx/vision-rx.wasm · Source on GitHub

Sample records & benchmarks (4)

Each sample record below was encoded at build time by vision-rx.wasm, wrapped in a SHA-256 content-addressed card (0x00 || sha256), and decoded back into a FHIR R4 Bundle. Click any record name to open its live QR card in the universal viewer.

RecordCard & QR (L / M)FHIR JSONDEFLATE (L9)FHIR ÷ cardDownloads
progressive-prismProgressive eyeglasses with astigmatism & vertical prism 151 BVersion 9-L / Version 10-M 2,158 B4 entries 788 BVersion 20-L 14× model.json · card.txt · fhir.json
toric-contactsDaily toric contact lenses (OD/OS) 144 BVersion 8-L / Version 10-M 1,595 B3 entries 629 BVersion 18-L 11× model.json · card.txt · fhir.json
glasses-plus-contactsDual prescription (eyeglasses + multifocal contacts) 200 BVersion 10-L / Version 11-M 2,546 B4 entries 819 BVersion 21-L 13× model.json · card.txt · fhir.json
simple-myopiaSingle-vision myopia eyeglasses (70 B, Version 5-L) 70 BVersion 6-L / Version 7-M 1,420 B4 entries 537 BVersion 17-L 20× model.json · card.txt · fhir.json

Technical specification & format

Rendered from codecs/vision-rx/README.md in the repository.

A content-addressed (0x00 || sha256(wasm)) WebAssembly codec (Codec ABI v0.1) for eyeglasses and contact lens prescriptions. Encodes a constrained optical prescription JSON model (VisionRx) into a canonical, bit-packed binary payload and decodes it deterministically into a minified FHIR R4 Bundle.

  • Module: vision-rx.wasm (29,823 bytes)
  • SHA-256: 7e6ae21f82b4f2bc5c9046d0416d2870bdbbf869401b90a645577e5aac3f9cd0
  • Audit: auditWasm(wasm) = 0 violations (0 imports, no start section, no floats, no SIMD/threads, declared max memory 16,384 pages, link-time zero-panic proof, #![no_std] + #![forbid(unsafe_code)] in core)
  • Exports: memory, shc_alloc, shc_decode, shc_encode

Benchmark Summary (4 Showcase Samples)

Card size includes the 33-byte content-addressed codec header (0x00 || sha256(wasm)) and 2-byte SHA-256 card check (35 bytes of framing around the wire payload).

SampleFHIR R4 JSONRaw DEFLATE-9Wire PayloadSHA-256 CardQR DigitsQR Symbol (EC-L)vs FHIR JSONvs DEFLATE
progressive-prism2,158 B788 B116 B151 B367V8-L (49x49)14.3x5.2x
toric-contacts1,595 B629 B109 B144 B350V7-L (45x45)11.1x4.4x
simple-myopia1,420 B537 B35 B70 B170V5-L (37x37)20.3x7.7x
glasses-plus-contacts2,546 B819 B165 B200 B486V9-L (53x53)12.7x4.1x

Input Model (model.d.ts)

  • patient (family, given[1..4], birthDate YYYY-MM-DD; {} allowed for anonymous prescriptions)
  • prescriber (optional: family, given[1..4], qualification, 10-digit US npi)
  • dateWritten (YYYY-MM-DD, 1900-01-01..2155-12-31)
  • expires (optional YYYY-MM-DD, 1..4095 days after dateWritten)
  • pdMm (45.0..80.0 mm, exact 0.5 mm step), pdRightMm / pdLeftMm (20.0..45.0 mm, exact 0.5 mm step)
  • lensSpecifications (1..4 specs):
    • product: "lens" | "contact"
    • eye: "right" | "left"
    • sphere: -25.00..+25.00 D (0.25 D step)
    • cylinder: -12.00..+12.00 D (0.25 D step)
    • axis: integer 1..180 degrees
    • add: +0.25..+5.00 D (0.25 D step)
    • prism: 1..2 entries of { amount: 0.25..20.00 (0.25 step), base: "up" | "down" | "in" | "out" }
    • power: -25.00..+25.00 D (0.25 D step)
    • backCurve: 6.00..11.00 mm (0.01 mm step)
    • diameter: 8.0..18.0 mm (0.1 mm step)
    • duration: { value: 1..365, unit: "d" | "wk" | "mo" }
    • color (<= 32 UTF-8 B), brand (<= 64 UTF-8 B), note (<= 128 UTF-8 B)

shc_encode uses pure integer fixed-point decimal parsing (zero floats) and rejects any out-of-range value, inexact step, unknown field, duplicate key, or control character with status 1 (MALFORMED).

Canonical Bit-Packed Wire Format (v1)

MSB-first bitstream, zero-padded to the final byte boundary (non-zero padding bits and trailing bytes are rejected as MALFORMED):

  1. Header (8 bits): 4-bit version (1; 0 => MALFORMED, 2..15 => UNSUPPORTED) + 4 presence bits (has_patient, has_prescriber, has_expires, has_pd).
  2. Dates: dateWritten as 17-bit days since 1900-01-01; optional expires as 12-bit offset (1..4095 days).
  3. Patient (if present): presence bits + length-prefixed UTF-8 strings (6-bit length 1..64) + optional 17-bit birthDate.
  4. Prescriber (if present): presence bits + 2-bit qualification tag (0=none, 1="OD", 2="MD", 3=custom UTF-8 string excluding "OD"/"MD") + optional 34-bit US NPI integer.
  5. Pupillary Distance (if present): 3 presence bits + 7-bit binocular PD + 6-bit right/left monocular PD (exact half-millimeter integers).
  6. Lens Specifications (2-bit count 1..4): per spec: product (1b), eye (1b), 13-bit presence/prism-count mask, compact fixed-point integer fields, and canonical 1-bit deduplication of color/brand/note against the immediately preceding lens specification when identical (non-canonical literal duplicates are rejected).

FHIR R4 Output (shc_decode)

Emits a deterministic, minified FHIR R4 Bundle (type: "collection"):

  • resource:0 — Patient (id: "0", name, birthDate)
  • resource:1 (optional) — Practitioner (id: "1", identifier with http://hl7.org/fhir/sid/us-npi, name, qualification)
  • resource:2 (or resource:1 if no prescriber) — VisionPrescription (status: "active", created, dateWritten, patient: { reference: "Patient/0" }, optional prescriber: { reference: "Practitioner/1" }, optional expires extension, and lensSpecification[] using http://terminology.hl7.org/CodeSystem/ex-visionprescriptionproduct and UCUM durations)
  • resource:3 (optional, when any PD is present) — Observation (LOINC 79886-8 Pupillary distance, valueQuantity in mm for binocular PD, and right/left monocular PD component[])

Worst-Case Bounds

  • Max wire size: < 1,700 bytes (well under the 4,096-byte QR ceiling)
  • Max FHIR JSON output: < 12 KiB
  • WASM memory: <= 2 pages (128 KiB) on all valid inputs; zero recursion (O(1) stack)

Build & Test

# Build vision-rx.wasm (requires rustup stable + wasm32-unknown-unknown target)
bash codecs/vision-rx/rust/build.sh

# Run full audit, round-trip, fuzz, and benchmark test suite
bun test codecs/vision-rx/vision-rx.test.ts