@glion/annotate-profile-fields-code-systems 0.15.1 → 0.15.3

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 +90 -0
  2. package/package.json +14 -10
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @glion/annotate-profile-fields-code-systems
2
+
3
+ Unified plugin to annotate HL7v2 field-level coded values with UTG code system metadata.
4
+
5
+ ## What it does
6
+
7
+ Fields bound to HL7v2 tables (such as PID-8 `Administrative Sex` bound to table `0001`, or MSH-11.1 `Processing ID` bound to table `0103`) carry coded values that expand into human-readable displays and lifecycle statuses. This plugin resolves each field's table reference against the UTG code system registry in `@glion/profiles`, then writes the code system identity onto the field and the resolved value entry onto each repetition. It requires `@glion/annotate-profile-fields` to run first so that `field.data.table` is populated.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @glion/annotate-profile-fields-code-systems
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```ts
18
+ import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
19
+ import { hl7v2AnnotateProfileFields } from "@glion/annotate-profile-fields";
20
+ import { hl7v2AnnotateProfileFieldsCodeSystems } from "@glion/annotate-profile-fields-code-systems";
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(hl7v2AnnotateProfileFieldsCodeSystems);
29
+
30
+ const file = await processor.process(
31
+ "MSH|^~\\&|SENDER||RECEIVER||20241201||ADT^A01|MSG123|P|2.5\rPID|1||12345||Doe^John||19800101|M"
32
+ );
33
+
34
+ // PID-8 field.data.codeSystem === { id: "v2-0001", name: "AdministrativeSex", title: "Administrative Sex" }
35
+ // PID-8 repetition.data.code === { value: "M", display: "Male", status: "A" }
36
+ ```
37
+
38
+ ## API
39
+
40
+ This package exports the named constant `hl7v2AnnotateProfileFieldsCodeSystems`. The default export is the plugin itself.
41
+
42
+ ```ts
43
+ import type { Root } from "@glion/ast";
44
+ import type { Plugin } from "unified";
45
+
46
+ export const hl7v2AnnotateProfileFieldsCodeSystems: Plugin<[], Root, Root>;
47
+ ```
48
+
49
+ The plugin is async. Code system loads run in parallel; failures for unknown code systems are silent, while other errors attach a `VFile` message with source `hl7v2-annotate-profile-fields-code-systems`.
50
+
51
+ ## What it annotates
52
+
53
+ This plugin visits coded `field` nodes (fields with a table reference on `field.data.table`) and writes two pieces of metadata: a code system identity on the field itself (shared across all repetitions) and a resolved code entry on each repetition. Per the HL7v2 spec, when a coded field uses a composite datatype (CWE or CNE) the table binding constrains CWE.1 — the first subcomponent of the first component — which is the value this plugin reads.
54
+
55
+ ### `node.data` (Field, FieldRepetition)
56
+
57
+ After this plugin runs, the augmented interfaces are:
58
+
59
+ ```ts
60
+ declare module "@glion/ast" {
61
+ interface FieldData {
62
+ // Code system identity for the field's table reference.
63
+ // Present only when the table resolves in the UTG registry.
64
+ codeSystem?: {
65
+ id: string; // e.g. "v2-0001" (derived from "HL70001")
66
+ name: string; // e.g. "AdministrativeSex"
67
+ title: string; // e.g. "Administrative Sex"
68
+ };
69
+ }
70
+
71
+ interface FieldRepetitionData {
72
+ // Resolved code entry for this repetition's primary value.
73
+ // Present only when the repetition's CWE.1 value matches a code.
74
+ code?: {
75
+ value: string; // as written in the message, e.g. "M"
76
+ display: string; // e.g. "Male"
77
+ status: string; // UTG lifecycle status, e.g. "A" (active)
78
+ };
79
+ }
80
+ }
81
+ ```
82
+
83
+ Table references are converted from the HL7v2 form (`HL70001`) to the UTG form (`v2-0001`) before lookup. Fields whose table does not resolve in the UTG registry are left untouched, and repetitions whose primary value does not match any code in the registry are left without a `code` entry.
84
+
85
+ ## Part of Glion
86
+
87
+ `@glion/annotate-profile-fields-code-systems` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
88
+
89
+ [Glion]: https://github.com/rethinkhealth/glion#readme
90
+ [Glion README]: https://github.com/rethinkhealth/glion#readme
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/annotate-profile-fields-code-systems",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "description": "Unified plugin to annotate HL7v2 field-level coded values with UTG code system metadata",
5
5
  "keywords": [
6
6
  "annotate",
@@ -41,21 +41,23 @@
41
41
  "dependencies": {
42
42
  "unified": "11.0.5",
43
43
  "vfile": "6.0.3",
44
- "@glion/ast": "0.15.1",
45
- "@glion/profiles": "0.15.1",
46
- "@glion/util-visit": "0.15.1"
44
+ "@glion/ast": "0.15.3",
45
+ "@glion/profiles": "0.15.3",
46
+ "@glion/util-visit": "0.15.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^25.5.0",
50
50
  "@vitest/coverage-v8": "4.1.2",
51
+ "publint": "0.3.18",
51
52
  "tsdown": "0.21.7",
52
53
  "typescript": "^5.9.3",
53
54
  "vitest": "4.1.2",
54
- "@glion/annotate-profile-context": "0.15.1",
55
- "@glion/annotate-profile-fields": "0.15.1",
56
- "@glion/builder": "0.15.1",
57
- "@glion/testing": "0.15.1",
58
- "@glion/tsconfig": "0.15.1"
55
+ "@glion/annotate-profile-fields": "0.15.3",
56
+ "@glion/builder": "0.15.3",
57
+ "@glion/check-readme": "0.15.3",
58
+ "@glion/tsconfig": "0.15.3",
59
+ "@glion/testing": "0.15.3",
60
+ "@glion/annotate-profile-context": "0.15.3"
59
61
  },
60
62
  "engines": {
61
63
  "node": ">=18"
@@ -64,9 +66,11 @@
64
66
  "scripts": {
65
67
  "build": "tsdown && tsc --emitDeclarationOnly",
66
68
  "check-types": "tsc --noEmit",
69
+ "check:readme": "glion-check-readme",
67
70
  "bench": "vitest bench --run",
68
71
  "test": "vitest run",
69
72
  "test:coverage": "vitest run --coverage",
70
- "test:watch": "vitest"
73
+ "test:watch": "vitest",
74
+ "publint": "publint --strict"
71
75
  }
72
76
  }