Skip to content
All projects
Core engineering libraryData Manager

study_id_patterns.py — Study-ID Pattern Registry

BCHPR · 9 projects, 4 countries · 2023 – present

The most-imported module in the codebase — 35 files depend on it. 27 registered patterns (16 participant and specimen ID forms, 11 site codes) covering identifiers that arrive from QR scanners, free-text notes and typed entry, where a transposed digit produces something structurally valid and completely wrong.

Highlights

  • A vectorised ISO 7064 Mod 37,36 check-character kernel that reads a UCS-4 string array as a raw uint32 buffer and iterates character positions rather than payloads — roughly 30× the scalar path at 100k IDs, and caching cannot help because participant IDs are near-unique.
  • One combined alternation regex replaces per-pattern looping: 100,000 rows went from 1.2 million regex operations to 100,000.
  • A rule narrowed after a real incident — the DARE-TB site digit accepted [1-9] until July 2026, which admitted IDs no site could mint; QA found two of them sitting in a live REDCap project.
  • Validation returns typed errors (invalid format, wrong project, wrong country, failed check character, duplicate) with a suggested correction, not a boolean.
  • Cleaning handles the specific corruptions that occur: OCR O-to-zero confusion, missing hyphens, trailing scanner noise, and IDs concatenated with no separator.
  • Garbage collection gated behind a 100,000-row threshold after 67 frames of a few rows each paid 3.2 seconds of pure GC on a memory-constrained WSL run.