@glion/lint-profile-field-max-length 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 +89 -0
  2. package/package.json +13 -9
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @glion/lint-profile-field-max-length
2
+
3
+ Lint rule to validate field value lengths against HL7v2 profile maxLength.
4
+
5
+ ## What it does
6
+
7
+ Flags field values that exceed the `maxLength` declared in the HL7v2 profile for the message's version. Length is computed by recursively summing the string lengths of all subcomponent values in a repetition, so delimiters (`^`, `&`, `~`) are not counted. The rule reads profile context attached by `@glion/annotate-profile-context` and reports once per offending repetition. Fields without a declared `maxLength`, empty fields, and Z-segments are skipped.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @glion/lint-profile-field-max-length
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```ts
18
+ import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
19
+ import { hl7v2Parser } from "@glion/parser";
20
+ import hl7v2LintFieldMaxLength from "@glion/lint-profile-field-max-length";
21
+ import { unified } from "unified";
22
+ import { reporter } from "vfile-reporter";
23
+
24
+ const message = [
25
+ "MSH|^~\\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5",
26
+ "PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F",
27
+ ].join("\r");
28
+
29
+ const file = await unified()
30
+ .use(hl7v2Parser)
31
+ .use(hl7v2AnnotateProfileContext)
32
+ .use(hl7v2LintFieldMaxLength)
33
+ .process(message);
34
+
35
+ console.error(reporter([file]));
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### `unified().use(hl7v2LintFieldMaxLength)`
41
+
42
+ A `unified` lint rule plugin. Takes no options.
43
+
44
+ Reads `file.data.profile`. For each segment in the tree it walks its fields, looks up the profile entry by sequence, and — if a `maxLength` is declared — compares it against `getLength()` from `@glion/utils` for every repetition. Each repetition over the limit produces one message.
45
+
46
+ ```ts
47
+ import type { Plugin } from "unified";
48
+ import type { Root } from "@glion/ast";
49
+
50
+ declare const hl7v2LintFieldMaxLength: Plugin<[], Root>;
51
+ export default hl7v2LintFieldMaxLength;
52
+ ```
53
+
54
+ ## What it checks
55
+
56
+ This rule flags fields whose measured content length is greater than the `maxLength` declared for that field in the HL7v2 profile. In v2.5, `MSH-10` (Message Control ID) has `maxLength: 20`.
57
+
58
+ ### Valid
59
+
60
+ `MSH-10` carries a 9-character Message Control ID, well within the v2.5 limit of 20:
61
+
62
+ ```hl7
63
+ MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5
64
+ PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
65
+ ```
66
+
67
+ ### Invalid
68
+
69
+ `MSH-10` is 28 characters long, exceeding the v2.5 limit of 20:
70
+
71
+ ```hl7
72
+ MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG0000000000000000000000001|P|2.5
73
+ PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
74
+ ```
75
+
76
+ Reported message:
77
+
78
+ ```
79
+ Field MSH-10 exceeds max length of 20 (actual: 28)
80
+ ```
81
+
82
+ One message is produced per offending repetition. Delimiters are not included in the measured length — a composite value like `DOE^JANE` counts as 7 characters, not 8.
83
+
84
+ ## Part of Glion
85
+
86
+ `@glion/lint-profile-field-max-length` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
87
+
88
+ [Glion]: https://github.com/rethinkhealth/glion#readme
89
+ [Glion README]: https://github.com/rethinkhealth/glion#readme
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/lint-profile-field-max-length",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "description": "Lint rule to validate field value lengths against HL7v2 profile maxLength",
5
5
  "keywords": [
6
6
  "health",
@@ -34,22 +34,24 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "unified-lint-rule": "3.0.1",
37
- "@glion/ast": "0.15.1",
38
- "@glion/util-visit": "0.15.1",
39
- "@glion/utils": "0.15.1"
37
+ "@glion/ast": "0.15.3",
38
+ "@glion/util-visit": "0.15.3",
39
+ "@glion/utils": "0.15.3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "^25.5.0",
43
43
  "@vitest/coverage-v8": "4.1.2",
44
+ "publint": "0.3.18",
44
45
  "tsdown": "0.21.7",
45
46
  "typescript": "^5.9.3",
46
47
  "unified": "^11.0.5",
47
48
  "vfile": "^6.0.3",
48
49
  "vitest": "4.1.2",
49
- "@glion/annotate-profile-context": "0.15.1",
50
- "@glion/builder": "0.15.1",
51
- "@glion/testing": "0.15.1",
52
- "@glion/tsconfig": "0.15.1"
50
+ "@glion/annotate-profile-context": "0.15.3",
51
+ "@glion/builder": "0.15.3",
52
+ "@glion/check-readme": "0.15.3",
53
+ "@glion/testing": "0.15.3",
54
+ "@glion/tsconfig": "0.15.3"
53
55
  },
54
56
  "engines": {
55
57
  "node": ">=18"
@@ -58,9 +60,11 @@
58
60
  "scripts": {
59
61
  "build": "tsdown && tsc --emitDeclarationOnly",
60
62
  "check-types": "tsc --noEmit",
63
+ "check:readme": "glion-check-readme",
61
64
  "bench": "vitest bench --run",
62
65
  "test": "vitest run",
63
66
  "test:coverage": "vitest run --coverage",
64
- "test:watch": "vitest"
67
+ "test:watch": "vitest",
68
+ "publint": "publint --strict"
65
69
  }
66
70
  }