@glion/annotate-profile-datatypes 0.15.1 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +98 -0
  2. package/package.json +13 -9
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # @glion/annotate-profile-datatypes
2
+
3
+ Unified plugin to annotate HL7v2 field repetition, component, and subcomponent nodes with datatype profile metadata.
4
+
5
+ ## What it does
6
+
7
+ HL7v2 fields hold either a primitive value (like `ST` or `DT`) or a composite structure built from a datatype like `XPN` or `CWE` whose components and subcomponents each have their own datatype. This plugin walks each field repetition, component, and subcomponent, resolves the corresponding datatype from the profile context, and writes that metadata onto `node.data` using a stop-at-primitive cascade — annotation stops at the node where the primitive value actually lives. It requires `@glion/annotate-profile-context` and `@glion/annotate-profile-fields` to run first.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @glion/annotate-profile-datatypes
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```ts
18
+ import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
19
+ import { hl7v2AnnotateProfileDatatypes } from "@glion/annotate-profile-datatypes";
20
+ import { hl7v2AnnotateProfileFields } from "@glion/annotate-profile-fields";
21
+ import { hl7v2Parser } from "@glion/parser";
22
+ import { unified } from "unified";
23
+
24
+ const processor = unified()
25
+ .use(hl7v2Parser)
26
+ .use(hl7v2AnnotateProfileContext)
27
+ .use(hl7v2AnnotateProfileFields)
28
+ .use(hl7v2AnnotateProfileDatatypes);
29
+
30
+ const file = await processor.process(
31
+ "MSH|^~\\&|SENDER||RECEIVER||20241201||ADT^A01|MSG123|P|2.5\rPID|1||12345||Doe^John"
32
+ );
33
+
34
+ // PID-5 field-repetition.data === { datatypeId: "XPN", kind: "composite", title: "Extended Person Name" }
35
+ // PID-5.1 component.data === { id: "XPN.1", name: "Family Name", required: false, datatypeId: "FN", kind: "composite", title: "Family Name" }
36
+ // PID-5.1.1 subcomponent.data === { id: "FN.1", name: "Surname", required: true, datatypeId: "ST", kind: "primitive", title: "String Data" }
37
+ ```
38
+
39
+ ## API
40
+
41
+ This package exports the named constant `hl7v2AnnotateProfileDatatypes`. The default export is the plugin itself.
42
+
43
+ ```ts
44
+ import type { Root } from "@glion/ast";
45
+ import type { Plugin } from "unified";
46
+
47
+ export const hl7v2AnnotateProfileDatatypes: Plugin<[], Root, Root>;
48
+ ```
49
+
50
+ The plugin reads `file.data.profile` and `field.data.datatype` from upstream annotators. It writes to `FieldRepetitionData`, `ComponentData`, and `SubcomponentData` (all declared on the `@glion/ast` module augmentation).
51
+
52
+ ## What it annotates
53
+
54
+ This plugin visits three node types in order — `field-repetition`, `component`, and `subcomponent` — and writes datatype metadata to `node.data`. The cascade follows the composite structure: primitive fields stop at the repetition; composite fields with primitive components stop at the component; fully nested composites continue to the subcomponent.
55
+
56
+ `kind: "primitive"` means the value lives on that node. `kind: "composite"` means inspect the children. Nodes on ancestor paths of the primitive carry no annotation from this plugin.
57
+
58
+ ### `node.data` (FieldRepetition, Component, Subcomponent)
59
+
60
+ After this plugin runs, the augmented interfaces are:
61
+
62
+ ```ts
63
+ declare module "@glion/ast" {
64
+ interface FieldRepetitionData {
65
+ datatypeId?: string; // e.g. "ST", "CWE", "XPN"
66
+ kind?: "primitive" | "composite";
67
+ title?: string; // e.g. "String Data", "Coded with Exceptions"
68
+ }
69
+
70
+ interface ComponentData {
71
+ id?: string; // "<datatypeId>.<sequence>", e.g. "CWE.1", "XPN.2"
72
+ name?: string; // e.g. "Family Name"
73
+ required?: boolean;
74
+ datatypeId?: string; // e.g. "ST", "ID", "FN"
75
+ maxLength?: number;
76
+ kind?: "primitive" | "composite";
77
+ title?: string;
78
+ }
79
+
80
+ interface SubcomponentData {
81
+ id?: string; // "<datatypeId>.<sequence>", e.g. "FN.1", "HD.2"
82
+ name?: string;
83
+ required?: boolean;
84
+ datatypeId?: string;
85
+ kind?: "primitive" | "composite";
86
+ title?: string;
87
+ }
88
+ }
89
+ ```
90
+
91
+ Annotation is skipped for nodes whose datatype is not known to the profile (for example Z-segments or custom fields). The field-level `datatype` property is read from `field.data.datatype`, which is populated by `@glion/annotate-profile-fields`.
92
+
93
+ ## Part of Glion
94
+
95
+ `@glion/annotate-profile-datatypes` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
96
+
97
+ [Glion]: https://github.com/rethinkhealth/glion#readme
98
+ [Glion README]: https://github.com/rethinkhealth/glion#readme
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/annotate-profile-datatypes",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Unified plugin to annotate HL7v2 field repetition, component, and subcomponent nodes with datatype profile metadata",
5
5
  "keywords": [
6
6
  "annotate",
@@ -40,20 +40,22 @@
40
40
  "dependencies": {
41
41
  "unified": "11.0.5",
42
42
  "vfile": "6.0.3",
43
- "@glion/ast": "0.15.1",
44
- "@glion/util-visit": "0.15.1"
43
+ "@glion/util-visit": "0.15.2",
44
+ "@glion/ast": "0.15.2"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "^25.5.0",
48
48
  "@vitest/coverage-v8": "4.1.2",
49
+ "publint": "0.3.18",
49
50
  "tsdown": "0.21.7",
50
51
  "typescript": "^5.9.3",
51
52
  "vitest": "4.1.2",
52
- "@glion/annotate-profile-context": "0.15.1",
53
- "@glion/annotate-profile-fields": "0.15.1",
54
- "@glion/builder": "0.15.1",
55
- "@glion/tsconfig": "0.15.1",
56
- "@glion/testing": "0.15.1"
53
+ "@glion/annotate-profile-context": "0.15.2",
54
+ "@glion/annotate-profile-fields": "0.15.2",
55
+ "@glion/builder": "0.15.2",
56
+ "@glion/check-readme": "0.15.2",
57
+ "@glion/testing": "0.15.2",
58
+ "@glion/tsconfig": "0.15.2"
57
59
  },
58
60
  "engines": {
59
61
  "node": ">=18"
@@ -62,9 +64,11 @@
62
64
  "scripts": {
63
65
  "build": "tsdown && tsc --emitDeclarationOnly",
64
66
  "check-types": "tsc --noEmit",
67
+ "check:readme": "glion-check-readme",
65
68
  "bench": "vitest bench --run",
66
69
  "test": "vitest run",
67
70
  "test:coverage": "vitest run --coverage",
68
- "test:watch": "vitest"
71
+ "test:watch": "vitest",
72
+ "publint": "publint --strict"
69
73
  }
70
74
  }