Skip to content

Recommended profile preset

Preset bundling every profile-based HL7v2 lint rule for validating messages against their version-specific profiles.

Preset bundling every profile-based HL7v2 lint rule for validating messages against their version-specific profiles.

What it does

One .use(...) call checks a message against the HL7v2 standard of its version (MSH-12): required fields and components, field lengths and repetitions, table values, extra fields and components, segment order, and values in withdrawn or backward-compatible elements. The preset includes the profile annotators these rules need, so nothing else has to run first.

Install

npm install @glion/preset-lint-profile-recommended

Use

import { parseHL7v2 } from "@glion/parser";
import hl7v2PresetLintProfileRecommended from "@glion/preset-lint-profile-recommended";
import { unified } from "unified";
import { VFile } from "vfile";
import { reporter } from "vfile-reporter";

const message = [
  "MSH|^~\\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01|MSG00001|P|2.5",
  "PID|1||PATID1234^^^HOSP^MR",
].join("\r");

const file = new VFile();
await unified()
  .use(hl7v2PresetLintProfileRecommended)
  .run(parseHL7v2(message), file);

console.error(reporter([file]));

API

unified().use(hl7v2PresetLintProfileRecommended)

The default export is a unified preset. Takes no options. A rule's severity can be changed, or the rule turned off, by adding it again after the preset: .use(hl7v2LintBackwardCompatible, "error") or .use(hl7v2LintBackwardCompatible, false).

What's bundled

The preset runs these plugins in order: the annotators first, then the rules.

PluginSeverityPurpose
@glion/annotate-profile-context (opens in a new tab)—Loads the HL7v2 profile of the message's version.
@glion/annotate-profile-fields (opens in a new tab)—Annotates each field with its row in the segment attribute table.
@glion/annotate-profile-datatypes (opens in a new tab)—Annotates each component and subcomponent with its row in its datatype.
@glion/lint-profile-required-fields (opens in a new tab)errorFlags missing or empty required fields.
@glion/lint-profile-field-max-length (opens in a new tab)warningEnforces field-value maxLength from the profile.
@glion/lint-profile-field-repetition (opens in a new tab)errorFlags fields with more repetitions than HL7v2 allows.
@glion/lint-profile-required-components (opens in a new tab)errorValidates required components inside composite datatypes.
@glion/lint-profile-table-values (opens in a new tab)warningValidates coded values against HL7 tables.
@glion/lint-profile-timestamps (opens in a new tab)warningFlags a DT, TM, or DTM value that is not a valid date or time.
@glion/lint-profile-extra-fields (opens in a new tab)warningWarns when a segment contains more fields than the profile defines.
@glion/lint-profile-extra-components (opens in a new tab)warningWarns when a composite field contains more components than its datatype.
@glion/lint-profile-segment-order (opens in a new tab)errorValidates segment order against the event schema.
@glion/lint-profile-withdrawn (opens in a new tab)errorFlags a value in a withdrawn field, component, or subcomponent.
@glion/lint-profile-backward-compatible (opens in a new tab)warningFlags a value in an element kept only for backward compatibility.

An error sets fatal: true on the message; a warning sets fatal: false. Neither throws.

@glion/preset-lint-recommended holds the lint rules that do not depend on the version.