SHC vNext QR proof of concept
SHA-256 Extension · 0x00 0 WASM imports · 0 floats Embedded CPIC knowledge base + deterministic CDS expansion

Pharmacogenomics (CPIC Panel)

14-gene pharmacogenomics diplotype panel in ~90 bytes that expands via embedded CPIC clinical tables into FHIR R4 Genomics Observations and actionable DetectedIssue drug-gene alerts.

WASM module44,707 Bpgx-cpic.wasm
Card sizes88–92 Bacross 4 sample records
Max FHIR ÷ card358×deterministic FHIR R4 output
Best QR versionVersion 6-Lup to Version 7-L

Try live in Viewer (high-risk-multi) Download WASM (by hash) View model.d.ts

Quick launch any sample record in the universal viewer:

high-risk-multi cardio-warfarin oncology-immuno all-normal-14

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
8a0e73db854b448f7b4975d42c1917b1fa563c1055f232333b705349bdf36f3f (download by hash)
WASM exports
memory, shc_alloc, shc_decode, shc_encode (0 host imports)
Machine-readable files
model.d.ts · codecs/pgx-cpic/pgx-cpic.wasm · Source on GitHub

Sample records & benchmarks (4)

Each sample record below was encoded at build time by pgx-cpic.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
high-risk-multiHigh-risk multi-gene profile (16 actionable CPIC alerts) 92 BVersion 7-L / Version 8-M 32,965 B29 entries 3,692 Bfits none 358× model.json · card.txt · fhir.json
cardio-warfarinCardiology & anticoagulation panel (CYP2C19, VKORC1, SLCO1B1) 91 BVersion 7-L / Version 8-M 23,712 B22 entries 2,839 BVersion 40-L 261× model.json · card.txt · fhir.json
oncology-immunoOncology & transplant safety panel (DPYD, TPMT, UGT1A1, CYP3A5) 88 BVersion 6-L / Version 8-M 24,358 B23 entries 2,649 BVersion 39-L 277× model.json · card.txt · fhir.json
all-normal-14All 14 CPIC genes tested — normal metabolizer baseline 90 BVersion 6-L / Version 8-M 31,148 B31 entries 1,744 BVersion 31-L 346× model.json · card.txt · fhir.json

Technical specification & format

Rendered from codecs/pgx-cpic/README.md in the repository.

A content-addressed (0x00 || sha256(wasm)) WebAssembly extension codec implementing the embedded clinical knowledge-table expansion paradigm for CODEC-ABI v0.1.

Instead of serializing tens of kilobytes of repetitive FHIR Genomics Reporting observations and CPIC drug-gene clinical decision support alerts into a dense QR code, pgx-cpic encodes only the patient's tested pharmacogenes and exact diplotypes (~53–57 bytes; ~88–92 bytes with full SHA-256 content-addressing and 2-byte integrity check, fitting inside a tiny QR Version 5-L symbol) and deterministically expands them inside a sandboxed, zero-import, zero-float, zero-panic #![no_std] Rust WASM module into a complete FHIR R4 Genomics Reporting Bundle with actionable CPIC DetectedIssue clinical drug-safety alerts (~23–33 KB — a 423×–578× expansion over the wire payload, and 19×–40× smaller than raw DEFLATE-9).

Module Properties (pgx-cpic.wasm)

  • Size: 44,707 bytes (includes the entire 14-gene CPIC diplotype/phenotype/drug-alert knowledge table, strict JSON encoder, bit-packed binary decoder, and FHIR R4 JSON renderer)
  • SHA-256: 8a0e73db854b448f7b4975d42c1917b1fa563c1055f232333b705349bdf36f3f
  • ABI Audit (auditWasm): 0 violations, 0 imports (link-time zero-panic guarantee), 0 floats, 0 SIMD/threads, declared memory max 16384 pages (1 GiB)
  • Exports: memory, shc_alloc, shc_decode, shc_encode
  • Safety: #![no_std] and #![forbid(unsafe_code)] across pgx_cpic_core; only the 100-line ABI shim touches linear memory

Embedded 14-Gene CPIC Pharmacogenomics Table

#GeneHGNC IDBit WidthClinical Drugs Covered (RxNorm)
0CYP2C19HGNC:26214 bits (15 + esc)clopidogrel (32968), voriconazole (121243), citalopram (2556), escitalopram (321988), sertraline (36437), omeprazole (7646)
1CYP2D6HGNC:26255 bits (31 + esc)codeine (2670), tramadol (10689), tamoxifen (10324), ondansetron (26225), amitriptyline (704)
2CYP2C9HGNC:26234 bits (15 + esc)warfarin (11289), phenytoin (8183), celecoxib (140587), siponimod (2123111)
3VKORC1HGNC:236632 bits (3 + esc)warfarin (11289) — -1639G>A (G/G, G/A, A/A)
4SLCO1B1HGNC:109594 bits (15 + esc)simvastatin (36567), atorvastatin (83367), rosuvastatin (301542)
5DPYDHGNC:30124 bits (15 + esc)fluorouracil (4492), capecitabine (194000)
6TPMTHGNC:120144 bits (15 + esc)azathioprine (1256), mercaptopurine (103), thioguanine (10485)
7NUDT15HGNC:230633 bits (7 + esc)azathioprine (1256), mercaptopurine (103)
8UGT1A1HGNC:125303 bits (7 + esc)irinotecan (51499), atazanavir (343047)
9CYP3A5HGNC:26383 bits (7 + esc)tacrolimus (42316) (*3/*3 non-expresser baseline; *1/*1, *1/*3 expressers → 1.5–2× starting dose)
10HLA-B*57:01HGNC:49322 bits (2 + esc)abacavir (190521) — hypersensitivity reaction
11HLA-B*58:01HGNC:49322 bits (2 + esc)allopurinol (519) — SJS/TEN
12HLA-B*15:02HGNC:49322 bits (2 + esc)carbamazepine (2002), oxcarbazepine (32624) — SJS/TEN
13G6PDHGNC:40572 bits (3 + esc)rasburicase (283810), primaquine (8686) — acute hemolytic anemia

Any diplotype not in a gene's built-in table is encoded losslessly using that gene's escape code plus a length-prefixed UTF-8 string (decoded with phenotype Indeterminate and zero speculative drug alerts).

Canonical Wire Format (v0)

Every valid PgxPanel has a single canonical binary encoding:

  1. Header (1 byte): bits 7..5 = format version (0; non-zero returns UNSUPPORTED), bit 4 = reserved (0), bit 3 = has_lab, bit 2 = has_birth_date, bit 1 = has_given, bit 0 = has_family.
  2. testDate (2 bytes, u16 LE): days since 1900-01-01 (1900-01-01 through 2079-06-06).
  3. geneMask (2 bytes, u16 LE): 14-bit presence mask for genes 0..13 (non-zero; bits 14..15 must be 0).
  4. Bit-packed diplotype indices (LSB-first, zero-padded to byte boundary): for each set bit i in 0..13, GENES[i].bits bits encoding either a built-in diplotype index or GENES[i].escape_code. Non-zero padding bits are rejected as MALFORMED.
  5. Escape diplotype strings: in ascending gene index order, len: u8 (1..=64) + UTF-8 bytes (must not duplicate a built-in table entry for that gene).
  6. Optional fields in flag order: family (u8 len + UTF-8), given (u8 count (1..=8) × u8 len + UTF-8), birthDate (u16 LE days since 1900-01-01), lab.name (u8 len + UTF-8). Trailing bytes are rejected as MALFORMED.

FHIR R4 Output Structure

shc_decode emits a canonical minified FHIR R4 Bundle (type: "collection") with fullUrl values resource:0, resource:1, ...:

  • Patient (id: "0", fullUrl: "resource:0")
  • Optional performing laboratory Organization (id: "1", fullUrl: "resource:1")
  • DiagnosticReport (id: "pgx-report", LOINC 51969-4 Genetic analysis report, effectiveDateTime: testDate, result[] referencing every genotype & phenotype Observation)
  • Per tested gene (in canonical gene order):
    • Genotype / Diplotype Observation (LOINC 84413-4, HGNC gene studied component LOINC 48018-6, lossless diplotype in valueCodeableConcept.text)
    • Predicted Phenotype Observation (LOINC 53040-2, CPIC metabolizer/function phenotype with LOINC Answer code + HL7 interpretation, derivedFrom genotype Observation)
  • Deterministically expanded CPIC DetectedIssue drug-safety alerts (code DRG, severity high/moderate/low, affected RxNorm medication code, gene + phenotype evidence references, CPIC guideline link, and concise clinical recommendation) — emitted only for actionable non-normal findings at 0 extra QR bytes.

Showcase Benchmarks

Measured with bun test codecs/pgx-cpic/pgx-cpic.test.ts:

SampleGenesAlertsFHIR JSONRaw DEFLATE-9Wire BytesSHA-256 Card (0x00||sha256)QR (EC-L)Reg. Card (ID 1)Reg. QRExpansion vs Card / Wire
high-risk-multi51632,965 B3,692 B57 B92 BV5-L60 BV4-L358× / 578×
cardio-warfarin41123,712 B2,839 B56 B91 BV5-L59 BV4-L261× / 423×
oncology-immuno51024,358 B2,649 B53 B88 BV5-L56 BV4-L277× / 460×
all-normal-1414031,148 B1,744 B55 B90 BV5-L58 BV4-L346× / 566×

Building & Testing

# Build pgx-cpic.wasm (Rust stable with wasm32-unknown-unknown target)
bash codecs/pgx-cpic/rust/build.sh

# Run full audit, round-trip, clinical expansion, fuzz, and benchmark suite
bun test codecs/pgx-cpic/pgx-cpic.test.ts