Docs · Validators

loinc_code validator

LOINC code (`NNNNN-N`) with free-text resolver fallback.

Resolver-backed

Reference

Format

Matches `/^\d{1,5}-\d$/` — 1 to 5 digits, hyphen, single check digit. On format failure, the resolver tries to map free-text labels (e.g. "heart rate", "hba1c") to a canonical code; if confidence ≥ 0.85 and the resolved code re-validates, the row passes with `resolved` set.

Examples

  • 8867-4 (Heart rate)
  • 4548-4 (HbA1c)
  • "glucose" → resolved to 2345-7

How it runs

Implementation

Faithful summary of lib/validators.ts. Validators are pure functions and run identically in the worker, the Workbench, and the MCP server.

lib/validators.ts
function validLoinc(value) {
  return /^\d{1,5}-\d$/.test(value)
    ? OK
    : fail('loinc_format', 'expected NNNNN-N')
}
// Plus the resolver wrapper: on direct failure, try mapping the
// raw value via LOINC_TABLE; if confidence >= 0.85 AND the resolved
// code re-passes the direct check, return ok with "resolved" set.

Config

Use in a template

Validators attach to a field on a custom template. The cascade runs them after mapping but before commit; failures surface in the per-row validation report.

template.yaml
fields:
  - column: loinc_code
    type: string
    required: true
    validators:
      - type: loinc_code

Watch out

Common gotchas

  • Mod-10 check digit is NOT verified. `99999-9` passes the format check even if the LOINC registry disagrees.
  • The resolver table is ~50 high-volume concepts — vitals, lipid panel, CBC, A1c. Niche or specialty assays will not resolve and must be sent as codes.
  • When the resolver fires, the response carries `resolved` and `resolved_label` — commit the resolved code, not the original.

Catalogue

Related templates

  • Lab result cataloglab_result_catalog_v1

    LOINC-coded test definitions and reference ranges.

    Fields: loinc_code

  • Lab resultslab_results_v1

    Patient-linked lab results. Emits FHIR Observation.

    Fields: loinc_code

Pricing

Validators run on every committed row

Validators add no AI cost — they are pure functions. Every map bills a small flat per-map fee from your prepaid token wallet ($10 minimum, shared across our suite); only columns that reach the metered LLM layer, plus any-to-any convert and reshape, bill real AI tokens. See pricing →

Ready when you are

Validate every row — before it lands.

Attach checksum-strict validators to any field, and gate risky commits with the requires_hitl flag. One key runs the whole cascade.

Prepaid token wallet · schema-only data-minimization mode
loinc_code validator — AdaptivMapr