Recommended annotation preset
Preset bundling every profile-based annotation plugin so the AST carries full profile metadata after a single .use(...) call.
Preset bundling every profile-based annotation plugin so the AST carries full profile metadata after a single .use(...) call.
What it does
This preset wires the four profile annotation plugins plus the annotate-profile-context loader into a single unified plugin. One .use(...) call enriches every segment, field, field-repetition, component, sub-component, and primitive coded value in the AST with its HL7v2 profile metadata — names, datatypes, optionality, repetitions, max lengths, table references, and the table entry each primitive coded value matches. The annotated tree is self-describing and can be walked without loading any profiles yourself.
Install
npm install @glion/preset-annotate-profile-recommendedUse
import hl7v2PresetAnnotateProfileRecommended from "@glion/preset-annotate-profile-recommended";
import { hl7v2Parser } from "@glion/parser";
import { visit } from "@glion/util-visit";
import { unified } from "unified";
const processor = unified()
.use(hl7v2Parser)
.use(hl7v2PresetAnnotateProfileRecommended);
const file = await processor.process(
"MSH|^~\\&|SENDER||RECEIVER||20250601120000||ADT^A01|MSG00001|P|2.5\rPID|1||12345||Doe^John"
);
visit(file.result, "field", (node) => {
if (node.data?.optionality === "R" && node.data.name) {
console.log(`Required: ${node.data.id} (${node.data.name})`);
}
});API
unified().use(hl7v2PresetAnnotateProfileRecommended)
Default export is a Preset (unified's { plugins: [...] } shape). No options — to annotate selectively, compose individual plugins from their own packages instead.
What's bundled
The preset applies these plugins in order. annotate-profile-context runs first so each subsequent plugin reads the pre-resolved profile from file.data.profile.
| Plugin | Annotates |
|---|---|
@glion/annotate-profile-context (opens in a new tab) | Loads the HL7v2 profile for the message version onto file.data. |
@glion/annotate-profile-segments (opens in a new tab) | Annotates Segment nodes with their human-readable title (e.g. MSH → "Message Header"). |
@glion/annotate-profile-fields (opens in a new tab) | Annotates Field nodes with name, optionality, repetitions, datatype, maxLength, table. |
@glion/annotate-profile-datatypes (opens in a new tab) | Annotates FieldRepetition, Component, and Subcomponent nodes with datatype metadata. |
@glion/annotate-profile-tables (opens in a new tab) | Annotates primitive values bound to a table with their entry in the table of the message version. |
All plugins read the HL7v2 version from MSH-12 and load profiles via @glion/profiles. Unknown segments (Z-segments) are silently skipped so non-standard content passes through unchanged.
Composite coded values, such as a CWE field, are not annotated. @glion/annotate-profile-fields-code-systems (opens in a new tab), which is experimental and not part of this preset, annotates them against the UTG code systems.