Docs · Validators

loinc_code validator

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

Resolver-backed — free text that fails the format check is looked up before it is rejected · One of 19 validator types · pure compute, no AI cost

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

A faithful summary of lib/validators.ts. Validators are pure functions and run identically in the Worker, the Workbench and the MCP server — one implementation, so the three cannot disagree about whether a value is valid.

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.

Where it runs

Three routes, no AI cost.

  • POST/v1/validate-rowValidate one row against a template. Stateless, no key, pure compute — the fastest way to try loinc_code against a real value.no key
  • POST/v1/uploads/:id/validateRun every field validator over the parsed upload, without committing. Returns errors and warnings per row.read
  • POST/v1/uploads/:id/commitValidates on the way out. skip_invalid_rows drops the failures instead of failing the commit.commit

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

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

Explore

All 19 validator types

The complete list a template field can declare. There is no SNOMED validator — it required an affiliate licence, no template used it, and it was removed in 2026.

Ready when you are

Validate every row — before it lands.

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

Prepaid token wallet · schema-only data-minimization mode · no free tier