@glion/lint-segment-header-length 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.
- package/README.md +41 -118
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -1,174 +1,97 @@
|
|
|
1
1
|
# @glion/lint-segment-header-length
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lint rule that flags HL7v2 segment headers whose name is not exactly three characters.
|
|
4
4
|
|
|
5
|
-
## What
|
|
5
|
+
## What it does
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
It reports a message when the header before the first field delimiter is not a 3-letter uppercase code.
|
|
10
|
-
|
|
11
|
-
## When should I use this?
|
|
12
|
-
|
|
13
|
-
Use this rule to enforce canonical HL7v2 segment identifiers across messages, catch typos (e.g., `PID1`, `Obx`, `MS`), and improve downstream processing reliability.
|
|
14
|
-
|
|
15
|
-
## Presets
|
|
16
|
-
|
|
17
|
-
This plugin is included in the following presets:
|
|
18
|
-
|
|
19
|
-
| Preset | Options |
|
|
20
|
-
| ------------------------- | ------- |
|
|
21
|
-
| `@glion/lint-recommended` | |
|
|
7
|
+
Visits every `segment` node and checks that `node.name.length === 3`. HL7v2 segments are identified by a three-character code (`MSH`, `PID`, `OBX`, `ZAD`). Lengths other than three usually indicate a typo (`PID1`, `MS`, `Obx`), malformed input, or a miscoded private extension.
|
|
22
8
|
|
|
23
9
|
## Install
|
|
24
10
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
```sh
|
|
11
|
+
```bash
|
|
28
12
|
npm install @glion/lint-segment-header-length
|
|
29
13
|
```
|
|
30
14
|
|
|
31
15
|
## Use
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import { unified } from "unified";
|
|
37
|
-
import { hl7v2Parse } from "@glion/parser";
|
|
17
|
+
```ts
|
|
18
|
+
import { hl7v2Parser } from "@glion/parser";
|
|
38
19
|
import hl7v2LintSegmentHeaderLength from "@glion/lint-segment-header-length";
|
|
20
|
+
import { unified } from "unified";
|
|
39
21
|
import { reporter } from "vfile-reporter";
|
|
40
22
|
|
|
41
|
-
const
|
|
23
|
+
const message =
|
|
24
|
+
"MSH|^~\\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5";
|
|
25
|
+
|
|
42
26
|
const file = await unified()
|
|
43
|
-
.use(
|
|
27
|
+
.use(hl7v2Parser)
|
|
44
28
|
.use(hl7v2LintSegmentHeaderLength)
|
|
45
|
-
.process(
|
|
29
|
+
.process(message);
|
|
46
30
|
|
|
47
31
|
console.error(reporter([file]));
|
|
48
32
|
```
|
|
49
33
|
|
|
50
34
|
## API
|
|
51
35
|
|
|
52
|
-
### `unified().use(hl7v2LintSegmentHeaderLength
|
|
36
|
+
### `unified().use(hl7v2LintSegmentHeaderLength)`
|
|
53
37
|
|
|
54
|
-
|
|
38
|
+
A `unified` lint rule plugin. Takes no options.
|
|
55
39
|
|
|
56
|
-
|
|
40
|
+
Visits every `segment` node and reports one message per segment whose `name.length !== 3`. The reported text names how many characters to add or remove to reach the three-character target.
|
|
57
41
|
|
|
58
|
-
|
|
42
|
+
```ts
|
|
43
|
+
import type { Plugin } from "unified";
|
|
44
|
+
import type { Root } from "@glion/ast";
|
|
59
45
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
## Recommendation
|
|
65
|
-
|
|
66
|
-
HL7v2 segments are identified by **exactly three uppercase letters**. Deviations often indicate malformed input, private extensions used incorrectly, or typos that can break routing and transformations.
|
|
46
|
+
declare const hl7v2LintSegmentHeaderLength: Plugin<[], Root>;
|
|
47
|
+
export default hl7v2LintSegmentHeaderLength;
|
|
48
|
+
```
|
|
67
49
|
|
|
68
|
-
|
|
50
|
+
## What it checks
|
|
69
51
|
|
|
70
|
-
|
|
52
|
+
Each segment name must be exactly three characters long.
|
|
71
53
|
|
|
72
|
-
|
|
54
|
+
### Valid
|
|
73
55
|
|
|
74
|
-
|
|
56
|
+
All segments have three-character names:
|
|
75
57
|
|
|
76
58
|
```hl7
|
|
77
|
-
MSH
|
|
78
|
-
PID|1||
|
|
59
|
+
MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5
|
|
60
|
+
PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
|
|
79
61
|
OBX|1|TX|...
|
|
80
62
|
```
|
|
81
63
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
No messages.
|
|
85
|
-
|
|
86
|
-
##### `not-ok-too-long.hl7`
|
|
64
|
+
### Invalid
|
|
87
65
|
|
|
88
|
-
|
|
66
|
+
A four-character segment name:
|
|
89
67
|
|
|
90
68
|
```hl7
|
|
91
|
-
PID1|1||
|
|
69
|
+
PID1|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
|
|
92
70
|
```
|
|
93
71
|
|
|
94
|
-
|
|
72
|
+
Reported message:
|
|
95
73
|
|
|
96
|
-
```text
|
|
97
|
-
1:1-1:4: Invalid segment header `PID1`: expected exactly 3 uppercase letters (e.g., `PID`)
|
|
98
74
|
```
|
|
99
|
-
|
|
100
|
-
##### `not-ok-too-short.hl7`
|
|
101
|
-
|
|
102
|
-
###### In
|
|
103
|
-
|
|
104
|
-
```hl7
|
|
105
|
-
MS|^~\&|...
|
|
75
|
+
Unexpected 4 header length, expected 3 characters, remove 1 character
|
|
106
76
|
```
|
|
107
77
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
```text
|
|
111
|
-
1:1-1:3: Invalid segment header `MS`: expected 3 uppercase letters
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
##### `not-ok-lowercase.hl7`
|
|
115
|
-
|
|
116
|
-
###### In
|
|
78
|
+
A two-character segment name:
|
|
117
79
|
|
|
118
80
|
```hl7
|
|
119
|
-
|
|
81
|
+
MS|^~\&|...
|
|
120
82
|
```
|
|
121
83
|
|
|
122
|
-
|
|
84
|
+
Reported message:
|
|
123
85
|
|
|
124
|
-
```text
|
|
125
|
-
1:1-1:4: Invalid segment header `obx`: expected uppercase `OBX`
|
|
126
86
|
```
|
|
127
|
-
|
|
128
|
-
##### `ok-with-allowlist.hl7`
|
|
129
|
-
|
|
130
|
-
###### In
|
|
131
|
-
|
|
132
|
-
```hl7
|
|
133
|
-
ZAD|1|...
|
|
87
|
+
Unexpected 2 header length, expected 3 characters, add 1 character
|
|
134
88
|
```
|
|
135
89
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
```js
|
|
139
|
-
.unified().use(hl7v2LintSegmentHeaderLength, { allow: ['ZAD'] })
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
###### Out
|
|
143
|
-
|
|
144
|
-
No messages.
|
|
145
|
-
|
|
146
|
-
## Security
|
|
147
|
-
|
|
148
|
-
This plugin only transforms AST nodes and does not execute code. Ensure you trust the source of HL7v2 messages before processing.
|
|
149
|
-
|
|
150
|
-
## Contributing
|
|
151
|
-
|
|
152
|
-
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
153
|
-
|
|
154
|
-
1. Fork the repository
|
|
155
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
156
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
157
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
158
|
-
5. Open a Pull Request
|
|
159
|
-
|
|
160
|
-
## Code of Conduct
|
|
161
|
-
|
|
162
|
-
To ensure a welcoming and positive environment, we have a [Code of Conduct][github-code-of-conduct] that all contributors and participants are expected to adhere to.
|
|
163
|
-
|
|
164
|
-
## License
|
|
90
|
+
The delta between the actual length and three is interpolated with pluralization (`remove 1 character`, `add 2 characters`). One message is reported per offending segment.
|
|
165
91
|
|
|
166
|
-
|
|
92
|
+
## Part of Glion
|
|
167
93
|
|
|
168
|
-
|
|
94
|
+
`@glion/lint-segment-header-length` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
|
|
169
95
|
|
|
170
|
-
[
|
|
171
|
-
[
|
|
172
|
-
[github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
|
|
173
|
-
[github-unified]: https://github.com/unifiedjs/unified
|
|
174
|
-
[github-hl7v2-parser]: https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-parser
|
|
96
|
+
[Glion]: https://github.com/rethinkhealth/glion#readme
|
|
97
|
+
[Glion README]: https://github.com/rethinkhealth/glion#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/lint-segment-header-length",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "hl7v2-lint rule to warn when segment header length is invalid",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"definition",
|
|
@@ -46,14 +46,16 @@
|
|
|
46
46
|
"@types/pluralize": "^0.0.33",
|
|
47
47
|
"@types/unist": "^3.0.3",
|
|
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
|
"vfile": "^6.0.3",
|
|
52
53
|
"vitest": "4.1.2",
|
|
53
|
-
"@glion/
|
|
54
|
-
"@glion/
|
|
55
|
-
"@glion/
|
|
56
|
-
"@glion/
|
|
54
|
+
"@glion/ast": "0.15.2",
|
|
55
|
+
"@glion/builder": "0.15.2",
|
|
56
|
+
"@glion/testing": "0.15.2",
|
|
57
|
+
"@glion/tsconfig": "0.15.2",
|
|
58
|
+
"@glion/check-readme": "0.15.2"
|
|
57
59
|
},
|
|
58
60
|
"engines": {
|
|
59
61
|
"node": ">=18"
|
|
@@ -62,8 +64,10 @@
|
|
|
62
64
|
"scripts": {
|
|
63
65
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
64
66
|
"check-types": "tsc --noEmit",
|
|
67
|
+
"check:readme": "glion-check-readme",
|
|
65
68
|
"test": "vitest run",
|
|
66
69
|
"test:coverage": "vitest run --coverage",
|
|
67
|
-
"test:watch": "vitest"
|
|
70
|
+
"test:watch": "vitest",
|
|
71
|
+
"publint": "publint --strict"
|
|
68
72
|
}
|
|
69
73
|
}
|