@glion/lint-required-message-header 0.22.0 → 0.23.0
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 +23 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Lint rule that requires the message header segment (`MSH`) to be the first segme
|
|
|
4
4
|
|
|
5
5
|
## What it does
|
|
6
6
|
|
|
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
|
|
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 message naming that segment; if the message has no segments, it reports the message as empty. HL7v2 messages must begin with `MSH` because it carries the metadata required for routing and interpretation.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -37,7 +37,7 @@ console.error(reporter([file]));
|
|
|
37
37
|
|
|
38
38
|
A `unified` lint rule plugin. Takes no options.
|
|
39
39
|
|
|
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
|
|
40
|
+
The plugin visits the tree and finds the first `segment` node (descending through any nested groups). If it is not named `MSH`, or the tree has no segments, the plugin reports a message. The message's severity is the one the rule is configured with; it does not throw.
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
43
|
import type { Plugin } from "unified";
|
|
@@ -49,7 +49,7 @@ export default hl7v2LintRequiredMessageHeader;
|
|
|
49
49
|
|
|
50
50
|
## What it checks
|
|
51
51
|
|
|
52
|
-
The
|
|
52
|
+
The message must have at least one segment, and the first must be `MSH`.
|
|
53
53
|
|
|
54
54
|
### Valid
|
|
55
55
|
|
|
@@ -72,10 +72,28 @@ PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
|
|
|
72
72
|
Reported message:
|
|
73
73
|
|
|
74
74
|
```
|
|
75
|
-
|
|
75
|
+
The first segment is `PID`; a message must start with the message header segment (`MSH`).
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
A segment with an empty Segment ID first, such as an input that starts with the field separator:
|
|
79
|
+
|
|
80
|
+
```hl7
|
|
81
|
+
|A|B
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Reported message:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
The first segment has an empty Segment ID; a message must start with the message header segment (`MSH`).
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
An empty input (`""`), which parses to a tree with no segments, is reported as:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
The message has no segments; it must start with the message header segment (`MSH`).
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The rule reports at most one message per tree. Each message sets `expected` to `['MSH']` and, when the message has a first segment, `actual` to its Segment ID.
|
|
79
97
|
|
|
80
98
|
## Part of Glion
|
|
81
99
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Root } from "@glion/ast";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Lint rule that reports a message whose first segment is not the message
|
|
4
|
+
* header (`MSH`), or that has no segments.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* The first segment is found through any nested groups. Reports at most one
|
|
7
|
+
* message per tree, with `expected` set to `MSH` and `actual` to the first
|
|
8
|
+
* segment's Segment ID when there is one.
|
|
7
9
|
*/
|
|
8
|
-
declare const hl7v2LintSegmentRequiredMessageHeader: import("unified-lint-rule").Plugin<
|
|
10
|
+
declare const hl7v2LintSegmentRequiredMessageHeader: import("unified-lint-rule").Plugin<Root, unknown>;
|
|
9
11
|
export default hl7v2LintSegmentRequiredMessageHeader;
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,YAAY,CAAC;AAahD;;;;;;;GAOG;AACH,QAAA,MAAM,qCAAqC,mDA0C1C,CAAC;AAEF,eAAe,qCAAqC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,52 @@
|
|
|
1
1
|
import { lintRule } from "unified-lint-rule";
|
|
2
2
|
import { EXIT, visitParents } from "unist-util-visit-parents";
|
|
3
3
|
//#region src/index.ts
|
|
4
|
+
const messages = {
|
|
5
|
+
emptyMessage: "The message has no segments; it must start with the message header segment (`MSH`).",
|
|
6
|
+
emptySegmentId: "The first segment has an empty Segment ID; a message must start with the message header segment (`MSH`).",
|
|
7
|
+
notMessageHeader: (segmentId) => `The first segment is \`${segmentId}\`; a message must start with the message header segment (\`MSH\`).`
|
|
8
|
+
};
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
10
|
+
* Lint rule that reports a message whose first segment is not the message
|
|
11
|
+
* header (`MSH`), or that has no segments.
|
|
6
12
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
13
|
+
* The first segment is found through any nested groups. Reports at most one
|
|
14
|
+
* message per tree, with `expected` set to `MSH` and `actual` to the first
|
|
15
|
+
* segment's Segment ID when there is one.
|
|
9
16
|
*/
|
|
10
17
|
const hl7v2LintSegmentRequiredMessageHeader = lintRule({
|
|
11
18
|
origin: "hl7v2-lint:segment-required-message-header",
|
|
12
|
-
url: "https://github.com/rethinkhealth/
|
|
19
|
+
url: "https://github.com/rethinkhealth/glion/tree/main/packages/lint-required-message-header#readme"
|
|
13
20
|
}, (tree, file) => {
|
|
14
|
-
|
|
15
|
-
visitParents(tree, (node) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
file.fail(`Message header (MSH) segment is required as the first segment — received '${node.name}' instead`, {
|
|
19
|
-
ancestors: [node],
|
|
20
|
-
place: node.position
|
|
21
|
-
});
|
|
22
|
-
}
|
|
21
|
+
let first;
|
|
22
|
+
visitParents(tree, "segment", (node) => {
|
|
23
|
+
first = node;
|
|
24
|
+
return EXIT;
|
|
23
25
|
});
|
|
26
|
+
if (!first) {
|
|
27
|
+
const message = file.message(messages.emptyMessage, {
|
|
28
|
+
ancestors: [tree],
|
|
29
|
+
place: tree.position
|
|
30
|
+
});
|
|
31
|
+
message.expected = ["MSH"];
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (first.name === "MSH") return;
|
|
35
|
+
if (first.name === "") {
|
|
36
|
+
const message = file.message(messages.emptySegmentId, {
|
|
37
|
+
ancestors: [first],
|
|
38
|
+
place: first.position
|
|
39
|
+
});
|
|
40
|
+
message.actual = "";
|
|
41
|
+
message.expected = ["MSH"];
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const message = file.message(messages.notMessageHeader(first.name), {
|
|
45
|
+
ancestors: [first],
|
|
46
|
+
place: first.position
|
|
47
|
+
});
|
|
48
|
+
message.actual = first.name;
|
|
49
|
+
message.expected = ["MSH"];
|
|
24
50
|
});
|
|
25
51
|
//#endregion
|
|
26
52
|
export { hl7v2LintSegmentRequiredMessageHeader as default };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Root, Segment } from \"@glion/ast\";\nimport { lintRule } from \"unified-lint-rule\";\nimport { EXIT, visitParents } from \"unist-util-visit-parents\";\n\nconst messages = {\n emptyMessage:\n \"The message has no segments; it must start with the message header segment (`MSH`).\",\n emptySegmentId:\n \"The first segment has an empty Segment ID; a message must start with the message header segment (`MSH`).\",\n notMessageHeader: (segmentId: string) =>\n `The first segment is \\`${segmentId}\\`; a message must start with the message header segment (\\`MSH\\`).`,\n} as const;\n\n/**\n * Lint rule that reports a message whose first segment is not the message\n * header (`MSH`), or that has no segments.\n *\n * The first segment is found through any nested groups. Reports at most one\n * message per tree, with `expected` set to `MSH` and `actual` to the first\n * segment's Segment ID when there is one.\n */\nconst hl7v2LintSegmentRequiredMessageHeader = lintRule<Root>(\n {\n origin: \"hl7v2-lint:segment-required-message-header\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-required-message-header#readme\",\n },\n (tree, file) => {\n let first: Segment | undefined;\n visitParents(tree, \"segment\", (node) => {\n first = node;\n return EXIT;\n });\n\n if (!first) {\n const message = file.message(messages.emptyMessage, {\n ancestors: [tree],\n place: tree.position,\n });\n message.expected = [\"MSH\"];\n return;\n }\n\n if (first.name === \"MSH\") {\n return;\n }\n\n if (first.name === \"\") {\n const message = file.message(messages.emptySegmentId, {\n ancestors: [first],\n place: first.position,\n });\n message.actual = \"\";\n message.expected = [\"MSH\"];\n return;\n }\n\n const message = file.message(messages.notMessageHeader(first.name), {\n ancestors: [first],\n place: first.position,\n });\n message.actual = first.name;\n message.expected = [\"MSH\"];\n }\n);\n\nexport default hl7v2LintSegmentRequiredMessageHeader;\n"],"mappings":";;;AAIA,MAAM,WAAW;CACf,cACE;CACF,gBACE;CACF,mBAAmB,cACjB,0BAA0B,UAAU;CACvC;;;;;;;;;AAUD,MAAM,wCAAwC,SAC5C;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,SAAS;CACd,IAAI;AACJ,cAAa,MAAM,YAAY,SAAS;AACtC,UAAQ;AACR,SAAO;GACP;AAEF,KAAI,CAAC,OAAO;EACV,MAAM,UAAU,KAAK,QAAQ,SAAS,cAAc;GAClD,WAAW,CAAC,KAAK;GACjB,OAAO,KAAK;GACb,CAAC;AACF,UAAQ,WAAW,CAAC,MAAM;AAC1B;;AAGF,KAAI,MAAM,SAAS,MACjB;AAGF,KAAI,MAAM,SAAS,IAAI;EACrB,MAAM,UAAU,KAAK,QAAQ,SAAS,gBAAgB;GACpD,WAAW,CAAC,MAAM;GAClB,OAAO,MAAM;GACd,CAAC;AACF,UAAQ,SAAS;AACjB,UAAQ,WAAW,CAAC,MAAM;AAC1B;;CAGF,MAAM,UAAU,KAAK,QAAQ,SAAS,iBAAiB,MAAM,KAAK,EAAE;EAClE,WAAW,CAAC,MAAM;EAClB,OAAO,MAAM;EACd,CAAC;AACF,SAAQ,SAAS,MAAM;AACvB,SAAQ,WAAW,CAAC,MAAM;EAE7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/lint-required-message-header",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "hl7v2-lint rule to warn when message header segment is missing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"definition",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"vfile": "^6.0.3",
|
|
51
51
|
"vfile-reporter": "^8.1.1",
|
|
52
52
|
"vitest": "4.1.11",
|
|
53
|
-
"@glion/ast": "0.
|
|
54
|
-
"@glion/builder": "0.
|
|
53
|
+
"@glion/ast": "0.23.0",
|
|
54
|
+
"@glion/builder": "0.23.0",
|
|
55
55
|
"@glion/check-readme": "0.18.0",
|
|
56
56
|
"@glion/testing": "0.18.0",
|
|
57
57
|
"@glion/tsconfig": "0.18.0"
|