DocsValidators

pharmacode validator

Swiss pharmacode — 4 to 7-digit local drug identifier.

Format

Matches `/^\d{4,7}$/`. Digits only, length 4 through 7 inclusive.

Examples

  • 1234
  • 7680411180014 (NO — this is GTIN, not pharmacode)
  • 5396512

Implementation

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

function validPharmacode(value) {
  return /^\d{4,7}$/.test(value)
    ? OK
    : fail('pharmacode_format', 'expected 4–7 digits')
}

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: pharmacode
    type: string
    validators:
      - type: pharmacode

Common gotchas

  • Pharmacode has no published checksum, so we cannot detect transposition errors. Pair with a downstream lookup if accuracy matters.
  • Do not confuse with GTIN — the Swiss drug GTIN starts `7680` and is 13 digits. Pharmacode is 4–7 digits, standalone.
  • Leading zeros are valid pharmacode digits. Send as a string.

Related templates

  • Drug formularydrug_formulary_v1

    ATC/GTIN-coded drug catalog. Emits FHIR Medication.

    Fields: pharmacode

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 →