@glion/lint-required-message-header 0.15.0 → 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.
Files changed (2) hide show
  1. package/README.md +38 -88
  2. package/package.json +15 -7
package/README.md CHANGED
@@ -1,135 +1,85 @@
1
1
  # @glion/lint-required-message-header
2
2
 
3
- A [`unified`][github-unified] lint rule for HL7v2 that warns when the message header segment (`MSH`) is missing or not the first segment in a message. This helps ensure all HL7v2 messages begin with the required header, improving interoperability and data quality.
3
+ Lint rule that requires the message header segment (`MSH`) to be the first segment of an HL7v2 message.
4
4
 
5
- HL7v2 messages must always begin with a message header segment, known as `MSH`. This rule checks that the first segment in a message is `MSH` and warns if it is missing or replaced by another segment.
5
+ ## What it does
6
6
 
7
- ## What is this?
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
- This package is **ESM only**. In Node.js (v16+), install with npm:
28
-
29
- ```sh
11
+ ```bash
30
12
  npm install @glion/lint-required-message-header
31
13
  ```
32
14
 
33
15
  ## Use
34
16
 
35
- On the API:
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 msg = `MSH|^~\\&|...`;
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(hl7v2Parse)
27
+ .use(hl7v2Parser)
46
28
  .use(hl7v2LintRequiredMessageHeader)
47
- .process(msg);
29
+ .process(message);
48
30
 
49
31
  console.error(reporter([file]));
50
32
  ```
51
33
 
52
34
  ## API
53
35
 
54
- ### `unified().use(hl7v2LintSegmentHeaderLength[, options])`
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` Transformer that adds messages to the file.
38
+ A `unified` lint rule plugin. Takes no options.
61
39
 
62
- ## Recommendation
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
- This helps ensure that HL7v2 messages are well-formed and can be reliably parsed and processed by downstream systems. If the message does not start with `MSH`, a warning is reported indicating which segment was found instead.
42
+ ```ts
43
+ import type { Plugin } from "unified";
44
+ import type { Root } from "@glion/ast";
65
45
 
66
- **Why is this important?**
67
-
68
- - The `MSH` segment contains metadata required for routing and interpreting the message.
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
- It’s recommended to enable this rule in most pipelines.
50
+ ## What it checks
76
51
 
77
- ## Examples
52
+ The first segment of the message must be `MSH`.
78
53
 
79
- ##### `ok.hl7`
54
+ ### Valid
80
55
 
81
- ###### In
56
+ `MSH` comes first, followed by any other segments:
82
57
 
83
58
  ```hl7
84
- MSH|^~\&|...
85
- PID|1||12345^^^HOSP^MR||DOE^JANE||...
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
- ###### Out
64
+ ### Invalid
90
65
 
91
- No messages.
92
-
93
- ##### `not-ok.hl7`
94
-
95
- ###### In
66
+ A non-`MSH` segment appears first:
96
67
 
97
68
  ```hl7
98
- PID|1||12345||DOE^JANE||...
69
+ PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
99
70
  ```
100
71
 
101
- ###### Out
72
+ Reported message:
102
73
 
103
- ```text
104
- Message header (MSH) segment is required. Received PID instead.
74
+ ```
75
+ Message header (MSH) segment is required as the first segment — received 'PID' instead
105
76
  ```
106
77
 
107
- ## Security
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
- Copyright 2025 Rethink Health, SUARL. All rights reserved.
80
+ ## Part of Glion
128
81
 
129
- This program is licensed to you under the terms of the [MIT License](https://opensource.org/licenses/MIT). This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [LICENSE][github-license] file for details.
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
- [github-code-of-conduct]: https://github.com/rethinkhealth/glion/blob/main/CODE_OF_CONDUCT.md
132
- [github-license]: https://github.com/rethinkhealth/glion/blob/main/LICENSE
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.0",
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",
@@ -19,7 +19,11 @@
19
19
  "name": "Melek Somai",
20
20
  "email": "melek@rethinkhealth.io"
21
21
  },
22
- "repository": "rethinkhealth/glion.git",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/rethinkhealth/glion.git",
25
+ "directory": "packages/lint-required-message-header"
26
+ },
23
27
  "files": [
24
28
  "dist"
25
29
  ],
@@ -40,15 +44,17 @@
40
44
  "@types/node": "^25.5.0",
41
45
  "@types/unist": "^3.0.3",
42
46
  "@vitest/coverage-v8": "4.1.2",
47
+ "publint": "0.3.18",
43
48
  "tsdown": "0.21.7",
44
49
  "typescript": "^5.9.3",
45
50
  "vfile": "^6.0.3",
46
51
  "vfile-reporter": "^8.1.1",
47
52
  "vitest": "4.1.2",
48
- "@glion/ast": "0.15.0",
49
- "@glion/builder": "0.15.0",
50
- "@glion/testing": "0.15.0",
51
- "@glion/tsconfig": "0.15.0"
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"
52
58
  },
53
59
  "engines": {
54
60
  "node": ">=18"
@@ -57,8 +63,10 @@
57
63
  "scripts": {
58
64
  "build": "tsdown && tsc --emitDeclarationOnly",
59
65
  "check-types": "tsc --noEmit",
66
+ "check:readme": "glion-check-readme",
60
67
  "test": "vitest run",
61
68
  "test:coverage": "vitest run --coverage",
62
- "test:watch": "vitest"
69
+ "test:watch": "vitest",
70
+ "publint": "publint --strict"
63
71
  }
64
72
  }