@glion/lint-profile-field-max-length 0.14.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.
- package/README.md +89 -0
- package/package.json +19 -10
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.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Lint rule to validate field value lengths against HL7v2 profile maxLength",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
"name": "Melek Somai",
|
|
17
17
|
"email": "melek@rethinkhealth.io"
|
|
18
18
|
},
|
|
19
|
-
"repository":
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/rethinkhealth/glion.git",
|
|
22
|
+
"directory": "packages/lint-profile-field-max-length"
|
|
23
|
+
},
|
|
20
24
|
"files": [
|
|
21
25
|
"dist"
|
|
22
26
|
],
|
|
@@ -30,32 +34,37 @@
|
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|
|
32
36
|
"unified-lint-rule": "3.0.1",
|
|
33
|
-
"@glion/ast": "0.
|
|
34
|
-
"@glion/util-visit": "0.
|
|
35
|
-
"@glion/utils": "0.
|
|
37
|
+
"@glion/ast": "0.15.2",
|
|
38
|
+
"@glion/util-visit": "0.15.2",
|
|
39
|
+
"@glion/utils": "0.15.2"
|
|
36
40
|
},
|
|
37
41
|
"devDependencies": {
|
|
38
42
|
"@types/node": "^25.5.0",
|
|
39
43
|
"@vitest/coverage-v8": "4.1.2",
|
|
44
|
+
"publint": "0.3.18",
|
|
40
45
|
"tsdown": "0.21.7",
|
|
41
46
|
"typescript": "^5.9.3",
|
|
42
47
|
"unified": "^11.0.5",
|
|
43
48
|
"vfile": "^6.0.3",
|
|
44
49
|
"vitest": "4.1.2",
|
|
45
|
-
"@glion/annotate-profile-context": "0.
|
|
46
|
-
"@glion/builder": "0.
|
|
47
|
-
"@glion/
|
|
48
|
-
"@glion/
|
|
50
|
+
"@glion/annotate-profile-context": "0.15.2",
|
|
51
|
+
"@glion/builder": "0.15.2",
|
|
52
|
+
"@glion/check-readme": "0.15.2",
|
|
53
|
+
"@glion/testing": "0.15.2",
|
|
54
|
+
"@glion/tsconfig": "0.15.2"
|
|
49
55
|
},
|
|
50
56
|
"engines": {
|
|
51
57
|
"node": ">=18"
|
|
52
58
|
},
|
|
59
|
+
"packageManager": "pnpm@10.14.0",
|
|
53
60
|
"scripts": {
|
|
54
61
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
55
62
|
"check-types": "tsc --noEmit",
|
|
63
|
+
"check:readme": "glion-check-readme",
|
|
56
64
|
"bench": "vitest bench --run",
|
|
57
65
|
"test": "vitest run",
|
|
58
66
|
"test:coverage": "vitest run --coverage",
|
|
59
|
-
"test:watch": "vitest"
|
|
67
|
+
"test:watch": "vitest",
|
|
68
|
+
"publint": "publint --strict"
|
|
60
69
|
}
|
|
61
70
|
}
|