@glion/lint-required-message-header 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 +38 -88
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -1,135 +1,85 @@
|
|
|
1
1
|
# @glion/lint-required-message-header
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lint rule that requires the message header segment (`MSH`) to be the first segment of an HL7v2 message.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## What it does
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
This package validates the **segment header** in HL7v2 syntax trees produced by parsers like [`@glion/parser`][github-hl7v2-parser].
|
|
10
|
-
|
|
11
|
-
It reports a message when the first segment of an HL7v2 message is not a segment header (MSH).
|
|
12
|
-
|
|
13
|
-
## When should I use this?
|
|
14
|
-
|
|
15
|
-
Use this rule to enforce canonical HL7v2 segment identifiers across messages, catch typos (e.g., `PID1`, `Obx`, `MS`), and improve downstream processing reliability.
|
|
16
|
-
|
|
17
|
-
## Presets
|
|
18
|
-
|
|
19
|
-
This plugin is included in the following presets:
|
|
20
|
-
|
|
21
|
-
| Preset | Options |
|
|
22
|
-
| ------------------------- | ------- |
|
|
23
|
-
| `@glion/lint-recommended` | |
|
|
7
|
+
Walks the parsed tree and checks that the first `segment` node is named `MSH`. If a different segment appears first, the rule reports one fail message naming the offending segment and stops. HL7v2 messages must begin with `MSH` because it carries the metadata required for routing and interpretation.
|
|
24
8
|
|
|
25
9
|
## Install
|
|
26
10
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```sh
|
|
11
|
+
```bash
|
|
30
12
|
npm install @glion/lint-required-message-header
|
|
31
13
|
```
|
|
32
14
|
|
|
33
15
|
## Use
|
|
34
16
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```js
|
|
38
|
-
import { unified } from "unified";
|
|
39
|
-
import { hl7v2Parse } from "@glion/parser";
|
|
17
|
+
```ts
|
|
18
|
+
import { hl7v2Parser } from "@glion/parser";
|
|
40
19
|
import hl7v2LintRequiredMessageHeader from "@glion/lint-required-message-header";
|
|
20
|
+
import { unified } from "unified";
|
|
41
21
|
import { reporter } from "vfile-reporter";
|
|
42
22
|
|
|
43
|
-
const
|
|
23
|
+
const message =
|
|
24
|
+
"MSH|^~\\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5";
|
|
25
|
+
|
|
44
26
|
const file = await unified()
|
|
45
|
-
.use(
|
|
27
|
+
.use(hl7v2Parser)
|
|
46
28
|
.use(hl7v2LintRequiredMessageHeader)
|
|
47
|
-
.process(
|
|
29
|
+
.process(message);
|
|
48
30
|
|
|
49
31
|
console.error(reporter([file]));
|
|
50
32
|
```
|
|
51
33
|
|
|
52
34
|
## API
|
|
53
35
|
|
|
54
|
-
### `unified().use(
|
|
55
|
-
|
|
56
|
-
Warn when a segment header is not a three-letter uppercase code.
|
|
57
|
-
|
|
58
|
-
###### Returns
|
|
36
|
+
### `unified().use(hl7v2LintRequiredMessageHeader)`
|
|
59
37
|
|
|
60
|
-
A `unified`
|
|
38
|
+
A `unified` lint rule plugin. Takes no options.
|
|
61
39
|
|
|
62
|
-
|
|
40
|
+
The plugin visits the tree and finds the first `segment` node (descending through any nested groups). If it is not named `MSH`, the plugin calls `file.fail(...)` — this is a hard failure, not a warning.
|
|
63
41
|
|
|
64
|
-
|
|
42
|
+
```ts
|
|
43
|
+
import type { Plugin } from "unified";
|
|
44
|
+
import type { Root } from "@glion/ast";
|
|
65
45
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
- Missing or misplaced `MSH` segments can cause interoperability issues and data loss.
|
|
70
|
-
|
|
71
|
-
**When to disable:**
|
|
72
|
-
|
|
73
|
-
You should only disable this rule if you are intentionally working with non-standard HL7v2 messages that do not require a message header segment, which is rare in practice.
|
|
46
|
+
declare const hl7v2LintRequiredMessageHeader: Plugin<[], Root>;
|
|
47
|
+
export default hl7v2LintRequiredMessageHeader;
|
|
48
|
+
```
|
|
74
49
|
|
|
75
|
-
|
|
50
|
+
## What it checks
|
|
76
51
|
|
|
77
|
-
|
|
52
|
+
The first segment of the message must be `MSH`.
|
|
78
53
|
|
|
79
|
-
|
|
54
|
+
### Valid
|
|
80
55
|
|
|
81
|
-
|
|
56
|
+
`MSH` comes first, followed by any other segments:
|
|
82
57
|
|
|
83
58
|
```hl7
|
|
84
|
-
MSH
|
|
85
|
-
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
|
|
86
61
|
OBX|1|TX|...
|
|
87
62
|
```
|
|
88
63
|
|
|
89
|
-
|
|
64
|
+
### Invalid
|
|
90
65
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
##### `not-ok.hl7`
|
|
94
|
-
|
|
95
|
-
###### In
|
|
66
|
+
A non-`MSH` segment appears first:
|
|
96
67
|
|
|
97
68
|
```hl7
|
|
98
|
-
PID|1||
|
|
69
|
+
PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
|
|
99
70
|
```
|
|
100
71
|
|
|
101
|
-
|
|
72
|
+
Reported message:
|
|
102
73
|
|
|
103
|
-
```
|
|
104
|
-
Message header (MSH) segment is required
|
|
74
|
+
```
|
|
75
|
+
Message header (MSH) segment is required as the first segment — received 'PID' instead
|
|
105
76
|
```
|
|
106
77
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
This plugin only transforms AST nodes and does not execute code. Ensure you trust the source of HL7v2 messages before processing.
|
|
110
|
-
|
|
111
|
-
## Contributing
|
|
112
|
-
|
|
113
|
-
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
114
|
-
|
|
115
|
-
1. Fork the repository
|
|
116
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
117
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
118
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
119
|
-
5. Open a Pull Request
|
|
120
|
-
|
|
121
|
-
## Code of Conduct
|
|
122
|
-
|
|
123
|
-
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.
|
|
124
|
-
|
|
125
|
-
## License
|
|
78
|
+
The name of the first segment found is interpolated into the message. The rule reports at most one failure per tree.
|
|
126
79
|
|
|
127
|
-
|
|
80
|
+
## Part of Glion
|
|
128
81
|
|
|
129
|
-
|
|
82
|
+
`@glion/lint-required-message-header` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
|
|
130
83
|
|
|
131
|
-
[
|
|
132
|
-
[
|
|
133
|
-
[github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
|
|
134
|
-
[github-unified]: https://github.com/unifiedjs/unified
|
|
135
|
-
[github-hl7v2-parser]: https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-parser
|
|
84
|
+
[Glion]: https://github.com/rethinkhealth/glion#readme
|
|
85
|
+
[Glion README]: https://github.com/rethinkhealth/glion#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/lint-required-message-header",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "hl7v2-lint rule to warn when message header segment is missing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"definition",
|
|
@@ -44,15 +44,17 @@
|
|
|
44
44
|
"@types/node": "^25.5.0",
|
|
45
45
|
"@types/unist": "^3.0.3",
|
|
46
46
|
"@vitest/coverage-v8": "4.1.2",
|
|
47
|
+
"publint": "0.3.18",
|
|
47
48
|
"tsdown": "0.21.7",
|
|
48
49
|
"typescript": "^5.9.3",
|
|
49
50
|
"vfile": "^6.0.3",
|
|
50
51
|
"vfile-reporter": "^8.1.1",
|
|
51
52
|
"vitest": "4.1.2",
|
|
52
|
-
"@glion/ast": "0.15.
|
|
53
|
-
"@glion/builder": "0.15.
|
|
54
|
-
"@glion/testing": "0.15.
|
|
55
|
-
"@glion/
|
|
53
|
+
"@glion/ast": "0.15.2",
|
|
54
|
+
"@glion/builder": "0.15.2",
|
|
55
|
+
"@glion/testing": "0.15.2",
|
|
56
|
+
"@glion/check-readme": "0.15.2",
|
|
57
|
+
"@glion/tsconfig": "0.15.2"
|
|
56
58
|
},
|
|
57
59
|
"engines": {
|
|
58
60
|
"node": ">=18"
|
|
@@ -61,8 +63,10 @@
|
|
|
61
63
|
"scripts": {
|
|
62
64
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
63
65
|
"check-types": "tsc --noEmit",
|
|
66
|
+
"check:readme": "glion-check-readme",
|
|
64
67
|
"test": "vitest run",
|
|
65
68
|
"test:coverage": "vitest run --coverage",
|
|
66
|
-
"test:watch": "vitest"
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"publint": "publint --strict"
|
|
67
71
|
}
|
|
68
72
|
}
|