@glion/lint-profile-required-components 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 +20 -11
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @glion/lint-profile-required-components
|
|
2
|
+
|
|
3
|
+
Lint rule to validate required components in composite datatype fields.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
Flags composite fields whose required components (as declared by the datatype profile for the message's version) are missing or empty in any repetition. The rule reads profile context attached by `@glion/annotate-profile-context`, resolves each field's datatype, and checks the required components on every repetition. Empty fields, primitive datatypes, and segments without a known profile are skipped.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @glion/lint-profile-required-components
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
|
|
19
|
+
import { hl7v2Parser } from "@glion/parser";
|
|
20
|
+
import hl7v2LintRequiredComponents from "@glion/lint-profile-required-components";
|
|
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(hl7v2LintRequiredComponents)
|
|
33
|
+
.process(message);
|
|
34
|
+
|
|
35
|
+
console.error(reporter([file]));
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## API
|
|
39
|
+
|
|
40
|
+
### `unified().use(hl7v2LintRequiredComponents)`
|
|
41
|
+
|
|
42
|
+
A `unified` lint rule plugin. Takes no options.
|
|
43
|
+
|
|
44
|
+
Reads `file.data.profile`. For each non-empty field, resolves the datatype definition from the field profile and iterates `dtDef.requiredSequences`. For every field repetition, checks that each required component is present with a non-empty first subcomponent value.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import type { Plugin } from "unified";
|
|
48
|
+
import type { Root } from "@glion/ast";
|
|
49
|
+
|
|
50
|
+
declare const hl7v2LintRequiredComponents: Plugin<[], Root>;
|
|
51
|
+
export default hl7v2LintRequiredComponents;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## What it checks
|
|
55
|
+
|
|
56
|
+
This rule flags missing required components on composite fields. The classic case is `MSH-9` (Message Type), where the `MSG` datatype requires the message code (`.1`) and trigger event (`.2`) components.
|
|
57
|
+
|
|
58
|
+
### Valid
|
|
59
|
+
|
|
60
|
+
`MSH-9` carries message code, trigger event, and message structure:
|
|
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-9.2` (Trigger Event) is empty, which violates the `MSG` datatype profile in v2.5:
|
|
70
|
+
|
|
71
|
+
```hl7
|
|
72
|
+
MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^|MSG00001|P|2.5
|
|
73
|
+
PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101|F
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Reported message:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
Required component MSH-9.2 (Trigger Event) is missing or empty
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
When the component name is available in the datatype profile it appears in parentheses. One message is reported per missing required component per repetition.
|
|
83
|
+
|
|
84
|
+
## Part of Glion
|
|
85
|
+
|
|
86
|
+
`@glion/lint-profile-required-components` 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-required-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "Lint rule to validate required components in composite datatype fields",
|
|
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-required-components"
|
|
23
|
+
},
|
|
20
24
|
"files": [
|
|
21
25
|
"dist"
|
|
22
26
|
],
|
|
@@ -30,33 +34,38 @@
|
|
|
30
34
|
},
|
|
31
35
|
"dependencies": {
|
|
32
36
|
"unified-lint-rule": "3.0.1",
|
|
33
|
-
"@glion/
|
|
34
|
-
"@glion/
|
|
35
|
-
"@glion/
|
|
37
|
+
"@glion/utils": "0.15.2",
|
|
38
|
+
"@glion/util-visit": "0.15.2",
|
|
39
|
+
"@glion/ast": "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/
|
|
49
|
-
"@glion/
|
|
50
|
+
"@glion/annotate-profile-context": "0.15.2",
|
|
51
|
+
"@glion/builder": "0.15.2",
|
|
52
|
+
"@glion/check-readme": "0.15.2",
|
|
53
|
+
"@glion/profiles": "0.15.2",
|
|
54
|
+
"@glion/testing": "0.15.2",
|
|
55
|
+
"@glion/tsconfig": "0.15.2"
|
|
50
56
|
},
|
|
51
57
|
"engines": {
|
|
52
58
|
"node": ">=18"
|
|
53
59
|
},
|
|
60
|
+
"packageManager": "pnpm@10.14.0",
|
|
54
61
|
"scripts": {
|
|
55
62
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
56
63
|
"check-types": "tsc --noEmit",
|
|
64
|
+
"check:readme": "glion-check-readme",
|
|
57
65
|
"bench": "vitest bench --run",
|
|
58
66
|
"test": "vitest run",
|
|
59
67
|
"test:coverage": "vitest run --coverage",
|
|
60
|
-
"test:watch": "vitest"
|
|
68
|
+
"test:watch": "vitest",
|
|
69
|
+
"publint": "publint --strict"
|
|
61
70
|
}
|
|
62
71
|
}
|