DocsValidators

loinc_code validator

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

Resolver-backed

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

Implementation

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

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.

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.

fields:
  - column: loinc_code
    type: string
    required: true
    validators:
      - type: loinc_code

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.

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

Schema-only mode (headers + ≤3 sample rows) is free and unlimited; full-data commits are metered. See plans →