npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@glion/annotate-profile-context

v0.16.0

Published

Unified plugin to centralize HL7v2 profile loading onto file.data

Readme

@glion/annotate-profile-context

Unified plugin to centralize HL7v2 profile loading onto file.data.

What it does

Downstream profile-aware plugins (segment annotators, field annotators, datatype annotators, code-system annotators, profile lints) all need the same slice of HL7v2 profile data for the version declared in MSH-12.1. This plugin loads that data once — field definitions, segment titles, datatype definitions (with component and subcomponent cascade), and table definitions — and stores it as a single ProfileContext on file.data.profile. The load is idempotent and silently skips unknown profiles.

Install

npm install @glion/annotate-profile-context

Use

import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
import { hl7v2Parser } from "@glion/parser";
import { unified } from "unified";

const processor = unified().use(hl7v2Parser).use(hl7v2AnnotateProfileContext);

const file = await processor.process(
  "MSH|^~\\&|SENDER||RECEIVER||20241201||ADT^A01|MSG123|P|2.5\rPID|1||12345"
);

// file.data.profile.version       === "2.5"
// file.data.profile.fields        === Map<"MSH" | "PID", FieldDefinition>
// file.data.profile.datatypes     === Map<"ST" | "CX" | "XPN" | ..., DatatypeDefinition>
// file.data.profile.tables        === Map<"0001" | "0003" | ..., TableDefinition>
// file.data.profile.segments.byId === Map<"MSH" | "PID" | ..., { title: string }>

API

This package exports the named constant hl7v2AnnotateProfileContext and the ProfileContext type. The default export is the plugin itself.

import type { Root } from "@glion/ast";
import type {
  DatatypeDefinition,
  FieldDefinition,
  SegmentDefinition,
  TableDefinition,
} from "@glion/profiles";
import type { Plugin } from "unified";

export const hl7v2AnnotateProfileContext: Plugin<[], Root, Root>;

export interface ProfileContext {
  version: string;
  fields: ReadonlyMap<string, FieldDefinition>;
  datatypes: ReadonlyMap<string, DatatypeDefinition>;
  tables: ReadonlyMap<string, TableDefinition>;
  segments: SegmentDefinition;
}

The plugin is async: it awaits all profile loads in parallel.

What it annotates

This plugin writes to file.data, not to AST nodes. It populates one entry, file.data.profile, with the resolved ProfileContext for the HL7v2 version declared in MSH-12.1.

file.data.profile

After this plugin runs, the vfile carries:

// Augmented on VFile's DataMap:
declare module "vfile" {
  interface DataMap {
    profile?: ProfileContext | undefined;
  }
}

interface ProfileContext {
  // HL7v2 version from MSH-12.1 (e.g. "2.5", "2.5.1", "2.8")
  version: string;

  // Field definitions indexed by segment name
  fields: ReadonlyMap<string, FieldDefinition>;

  // Datatype definitions indexed by datatype id (e.g. "ST", "CWE", "XPN")
  datatypes: ReadonlyMap<string, DatatypeDefinition>;

  // Table definitions indexed by normalized table id (e.g. "0001")
  // Note: field profiles reference "HL70001"; this map uses "0001"
  tables: ReadonlyMap<string, TableDefinition>;

  // Segment titles indexed by segment id (e.g. "MSH", "PID", "OBX")
  segments: SegmentDefinition;
}

Loading is idempotent: if file.data.profile is already populated, the plugin returns immediately. If MSH-12.1 is missing, it returns without setting the key. Datatype loading cascades through composite datatypes up to three levels deep so every component and subcomponent datatype referenced anywhere in the field definitions is resolved in advance.

Part of Glion

@glion/annotate-profile-context is part of Glion, the application framework for HL7v2. See the Glion README for the full package catalog and architecture.