@glion/lint-profile-required-fields 0.15.1 → 0.15.3

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 +89 -0
  2. package/package.json +13 -9
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @glion/lint-profile-required-fields
2
+
3
+ Lint rule to validate required fields per HL7v2 profile.
4
+
5
+ ## What it does
6
+
7
+ Flags segments whose required fields (as declared by the HL7v2 profile for the message's version) are missing or empty. The rule reads profile context attached to the file by `@glion/annotate-profile-context` and reports one message per missing required field. Segments without a known profile (for example Z-segments like `ZPD`) are silently skipped.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @glion/lint-profile-required-fields
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```ts
18
+ import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
19
+ import { hl7v2Parser } from "@glion/parser";
20
+ import hl7v2LintRequiredFields from "@glion/lint-profile-required-fields";
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(hl7v2LintRequiredFields)
33
+ .process(message);
34
+
35
+ console.error(reporter([file]));
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### `unified().use(hl7v2LintRequiredFields)`
41
+
42
+ A `unified` lint rule plugin. Takes no options.
43
+
44
+ The plugin reads `file.data.profile` (populated by `@glion/annotate-profile-context`). If no profile context is present the rule exits silently. For each segment, it iterates `fieldDef.requiredSequences` and checks that the corresponding field at that 1-based position is present and non-empty.
45
+
46
+ ```ts
47
+ import type { Plugin } from "unified";
48
+ import type { Root } from "@glion/ast";
49
+
50
+ declare const hl7v2LintRequiredFields: Plugin<[], Root>;
51
+ export default hl7v2LintRequiredFields;
52
+ ```
53
+
54
+ ## What it checks
55
+
56
+ This rule flags fields declared `required: true` in the HL7v2 profile for the message's version when those fields are missing or empty on the corresponding segment.
57
+
58
+ ### Valid
59
+
60
+ `PID-3` (Patient Identifier List) and `PID-5` (Patient Name) are required in v2.5 and both are populated:
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
+ `PID-3` is empty, which violates the v2.5 profile for the `PID` segment:
70
+
71
+ ```hl7
72
+ MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5
73
+ PID|1||||DOE^JANE||19800101|F
74
+ ```
75
+
76
+ Reported message:
77
+
78
+ ```
79
+ Required field PID-3 (Patient Identifier List) is missing or empty
80
+ ```
81
+
82
+ When the profile attaches a field name, it appears in parentheses after the position. Segments shorter than the highest required sequence produce one message per missing required field.
83
+
84
+ ## Part of Glion
85
+
86
+ `@glion/lint-profile-required-fields` 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-fields",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
4
4
  "description": "Lint rule to validate required fields per HL7v2 profile",
5
5
  "keywords": [
6
6
  "health",
@@ -34,22 +34,24 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "unified-lint-rule": "3.0.1",
37
- "@glion/ast": "0.15.1",
38
- "@glion/util-visit": "0.15.1",
39
- "@glion/utils": "0.15.1"
37
+ "@glion/ast": "0.15.3",
38
+ "@glion/util-visit": "0.15.3",
39
+ "@glion/utils": "0.15.3"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "^25.5.0",
43
43
  "@vitest/coverage-v8": "4.1.2",
44
+ "publint": "0.3.18",
44
45
  "tsdown": "0.21.7",
45
46
  "typescript": "^5.9.3",
46
47
  "unified": "^11.0.5",
47
48
  "vfile": "^6.0.3",
48
49
  "vitest": "4.1.2",
49
- "@glion/builder": "0.15.1",
50
- "@glion/annotate-profile-context": "0.15.1",
51
- "@glion/testing": "0.15.1",
52
- "@glion/tsconfig": "0.15.1"
50
+ "@glion/annotate-profile-context": "0.15.3",
51
+ "@glion/builder": "0.15.3",
52
+ "@glion/check-readme": "0.15.3",
53
+ "@glion/testing": "0.15.3",
54
+ "@glion/tsconfig": "0.15.3"
53
55
  },
54
56
  "engines": {
55
57
  "node": ">=18"
@@ -58,9 +60,11 @@
58
60
  "scripts": {
59
61
  "build": "tsdown && tsc --emitDeclarationOnly",
60
62
  "check-types": "tsc --noEmit",
63
+ "check:readme": "glion-check-readme",
61
64
  "bench": "vitest bench --run",
62
65
  "test": "vitest run",
63
66
  "test:coverage": "vitest run --coverage",
64
- "test:watch": "vitest"
67
+ "test:watch": "vitest",
68
+ "publint": "publint --strict"
65
69
  }
66
70
  }