@glion/lint-profile-field-repetition 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.
Files changed (2) hide show
  1. package/README.md +89 -0
  2. package/package.json +18 -9
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @glion/lint-profile-field-repetition
2
+
3
+ Lint rule that flags non-repeatable fields with multiple repetitions.
4
+
5
+ ## What it does
6
+
7
+ Flags fields that contain more than one repetition (delimited by `~`) when the HL7v2 profile for the message's version declares `repeatable: false` for that field. The rule reads profile context attached by `@glion/annotate-profile-context`. A single repetition is always valid regardless of the `repeatable` flag; only 2+ repetitions on a non-repeatable field are reported. Segments without a known profile are silently skipped.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @glion/lint-profile-field-repetition
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```ts
18
+ import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
19
+ import { hl7v2Parser } from "@glion/parser";
20
+ import hl7v2LintFieldRepetition from "@glion/lint-profile-field-repetition";
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(hl7v2LintFieldRepetition)
33
+ .process(message);
34
+
35
+ console.error(reporter([file]));
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### `unified().use(hl7v2LintFieldRepetition)`
41
+
42
+ A `unified` lint rule plugin. Takes no options.
43
+
44
+ Reads `file.data.profile`. For each field under a segment with a known profile it looks up the field entry by sequence. If the field's profile sets `repeatable: false` and the AST has more than one repetition, the rule emits one message for that field.
45
+
46
+ ```ts
47
+ import type { Plugin } from "unified";
48
+ import type { Root } from "@glion/ast";
49
+
50
+ declare const hl7v2LintFieldRepetition: Plugin<[], Root>;
51
+ export default hl7v2LintFieldRepetition;
52
+ ```
53
+
54
+ ## What it checks
55
+
56
+ This rule flags fields with multiple `~`-delimited repetitions when the profile marks the field as non-repeatable. For example, `PID-7` (Date of Birth) is not repeatable in v2.5.
57
+
58
+ ### Valid
59
+
60
+ `PID-7` carries a single Date of Birth:
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-7` carries two `~`-separated values, which violates the v2.5 profile for the `PID-7` field:
70
+
71
+ ```hl7
72
+ MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5
73
+ PID|1||PATID1234^^^HOSP^MR||DOE^JANE||19800101~19800102|F
74
+ ```
75
+
76
+ Reported message:
77
+
78
+ ```
79
+ Field PID-7 (Date/Time of Birth) is not repeatable but has 2 repetitions
80
+ ```
81
+
82
+ When the field name is available in the profile it appears in parentheses after the position. The reported count equals the number of repetitions present in the field.
83
+
84
+ ## Part of Glion
85
+
86
+ `@glion/lint-profile-field-repetition` 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-field-repetition",
3
- "version": "0.14.1",
3
+ "version": "0.15.2",
4
4
  "description": "Lint rule that flags non-repeatable fields with multiple repetitions",
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": "rethinkhealth/glion.git",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/rethinkhealth/glion.git",
22
+ "directory": "packages/lint-profile-field-repetition"
23
+ },
20
24
  "files": [
21
25
  "dist"
22
26
  ],
@@ -30,31 +34,36 @@
30
34
  },
31
35
  "dependencies": {
32
36
  "unified-lint-rule": "3.0.1",
33
- "@glion/util-visit": "0.14.1",
34
- "@glion/ast": "0.14.1"
37
+ "@glion/ast": "0.15.2",
38
+ "@glion/util-visit": "0.15.2"
35
39
  },
36
40
  "devDependencies": {
37
41
  "@types/node": "^25.5.0",
38
42
  "@vitest/coverage-v8": "4.1.2",
43
+ "publint": "0.3.18",
39
44
  "tsdown": "0.21.7",
40
45
  "typescript": "^5.9.3",
41
46
  "unified": "^11.0.5",
42
47
  "vfile": "^6.0.3",
43
48
  "vitest": "4.1.2",
44
- "@glion/tsconfig": "0.0.1",
45
- "@glion/testing": "0.0.2",
46
- "@glion/builder": "0.14.1",
47
- "@glion/annotate-profile-context": "0.14.1"
49
+ "@glion/annotate-profile-context": "0.15.2",
50
+ "@glion/check-readme": "0.15.2",
51
+ "@glion/builder": "0.15.2",
52
+ "@glion/testing": "0.15.2",
53
+ "@glion/tsconfig": "0.15.2"
48
54
  },
49
55
  "engines": {
50
56
  "node": ">=18"
51
57
  },
58
+ "packageManager": "pnpm@10.14.0",
52
59
  "scripts": {
53
60
  "build": "tsdown && tsc --emitDeclarationOnly",
54
61
  "check-types": "tsc --noEmit",
62
+ "check:readme": "glion-check-readme",
55
63
  "bench": "vitest bench --run",
56
64
  "test": "vitest run",
57
65
  "test:coverage": "vitest run --coverage",
58
- "test:watch": "vitest"
66
+ "test:watch": "vitest",
67
+ "publint": "publint --strict"
59
68
  }
60
69
  }