@glion/lint-profile-backward-compatible 0.0.0-stage → 0.0.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 CHANGED
@@ -1,3 +1,92 @@
1
- # Temporary Holding Version
1
+ # @glion/lint-profile-backward-compatible
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lint rule that reports a value in an element HL7v2 keeps only for backward compatibility.
4
+
5
+ ## What it does
6
+
7
+ Flags a field, component, or subcomponent that has a value although the HL7v2 standard for the message's version marks it `B` (backward compatible). HL7v2 keeps such an element so older systems can still send it, and another element now carries its data. A value is still allowed, so `@glion/preset-lint-profile-recommended` reports it as a warning. It needs the plugins `@glion/annotate-profile-context`, `@glion/annotate-profile-fields` and `@glion/annotate-profile-datatypes` to run before it; `@glion/preset-lint-profile-recommended` includes them.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @glion/lint-profile-backward-compatible
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```ts
18
+ import { hl7v2AnnotateProfileContext } from "@glion/annotate-profile-context";
19
+ import { hl7v2AnnotateProfileDatatypes } from "@glion/annotate-profile-datatypes";
20
+ import { hl7v2AnnotateProfileFields } from "@glion/annotate-profile-fields";
21
+ import hl7v2LintBackwardCompatible from "@glion/lint-profile-backward-compatible";
22
+ import { parseHL7v2 } from "@glion/parser";
23
+ import { unified } from "unified";
24
+ import { VFile } from "vfile";
25
+ import { reporter } from "vfile-reporter";
26
+
27
+ const message = [
28
+ "MSH|^~\\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5.1",
29
+ "DG1|1|I9|250.00|DIABETES",
30
+ ].join("\r");
31
+
32
+ const file = new VFile();
33
+ await unified()
34
+ .use(hl7v2AnnotateProfileContext)
35
+ .use(hl7v2AnnotateProfileFields)
36
+ .use(hl7v2AnnotateProfileDatatypes)
37
+ .use(hl7v2LintBackwardCompatible)
38
+ .run(parseHL7v2(message), file);
39
+
40
+ console.error(reporter([file]));
41
+ ```
42
+
43
+ ## API
44
+
45
+ ### `unified().use(hl7v2LintBackwardCompatible)`
46
+
47
+ A `unified` lint rule plugin. Takes no options. Reports one message for each backward-compatible element that has a value.
48
+
49
+ ```ts
50
+ import type { Plugin } from "unified";
51
+ import type { Root } from "@glion/ast";
52
+
53
+ declare const hl7v2LintBackwardCompatible: Plugin<[], Root>;
54
+ export default hl7v2LintBackwardCompatible;
55
+ ```
56
+
57
+ ## What it checks
58
+
59
+ An element whose optionality is `B` in the message's version should be empty. The explicit null `""` is accepted. For example, in v2.5.1 the field `DG1-4` (Diagnosis Description) is backward compatible, and `DG1-3` (Diagnosis Code) carries the diagnosis.
60
+
61
+ ### Valid
62
+
63
+ `DG1-4` is empty in a v2.5.1 message:
64
+
65
+ ```hl7
66
+ MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5.1
67
+ DG1|1|I9|250.00
68
+ ```
69
+
70
+ ### Invalid
71
+
72
+ `DG1-4` has a value in a v2.5.1 message:
73
+
74
+ ```hl7
75
+ MSH|^~\&|SENDER|FAC|RECV|RFAC|20250601120000||ADT^A01^ADT_A01|MSG00001|P|2.5.1
76
+ DG1|1|I9|250.00|DIABETES
77
+ ```
78
+
79
+ Reported message:
80
+
81
+ ```
82
+ `DG1-4` (Diagnosis Description) has a value; v2.5.1 keeps it only for backward compatibility.
83
+ ```
84
+
85
+ A field is reported once, whichever of its repetitions has a value. A component is reported in each repetition that gives it a value.
86
+
87
+ ## Part of Glion
88
+
89
+ `@glion/lint-profile-backward-compatible` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
90
+
91
+ [Glion]: https://github.com/rethinkhealth/glion#readme
92
+ [Glion README]: https://github.com/rethinkhealth/glion#readme
@@ -0,0 +1,22 @@
1
+ import type { Root } from "@glion/ast";
2
+ /**
3
+ * Lint rule that reports a value in any element whose optionality is `B`
4
+ * (backward compatible): a field, a component, or a subcomponent.
5
+ *
6
+ * Reads `optionality` from `node.data`, which the profile annotators write, so
7
+ * `@glion/annotate-profile-fields` and `@glion/annotate-profile-datatypes`
8
+ * MUST run before it. An empty element and the explicit null `""` are
9
+ * accepted.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * unified()
14
+ * .use(hl7v2AnnotateProfileContext)
15
+ * .use(hl7v2AnnotateProfileFields)
16
+ * .use(hl7v2AnnotateProfileDatatypes)
17
+ * .use(hl7v2LintBackwardCompatible);
18
+ * ```;
19
+ */
20
+ declare const hl7v2LintBackwardCompatible: import("unified-lint-rule").Plugin<Root, unknown>;
21
+ export default hl7v2LintBackwardCompatible;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAevC;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,2BAA2B,mDA8ChC,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ import { toHl7v2 } from "@glion/to-hl7v2";
2
+ import { delimiters } from "@glion/util-query";
3
+ import { SKIP, visit } from "@glion/util-visit";
4
+ import { Optionality, isEmptyNode } from "@glion/utils";
5
+ import { lintRule } from "unified-lint-rule";
6
+ //#region src/index.ts
7
+ /** HL7v2 explicit null: the receiver deletes the element's value. */
8
+ const EXPLICIT_NULL = "\"\"";
9
+ const messages = { backwardCompatible: (id, name, version) => `\`${id}\` (${name}) has a value; v${version} keeps it only for backward compatibility.` };
10
+ /**
11
+ * Lint rule that reports a value in any element whose optionality is `B`
12
+ * (backward compatible): a field, a component, or a subcomponent.
13
+ *
14
+ * Reads `optionality` from `node.data`, which the profile annotators write, so
15
+ * `@glion/annotate-profile-fields` and `@glion/annotate-profile-datatypes`
16
+ * MUST run before it. An empty element and the explicit null `""` are
17
+ * accepted.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * unified()
22
+ * .use(hl7v2AnnotateProfileContext)
23
+ * .use(hl7v2AnnotateProfileFields)
24
+ * .use(hl7v2AnnotateProfileDatatypes)
25
+ * .use(hl7v2LintBackwardCompatible);
26
+ * ```;
27
+ */
28
+ const hl7v2LintBackwardCompatible = lintRule({
29
+ origin: "hl7v2-lint:backward-compatible",
30
+ url: "https://github.com/rethinkhealth/glion/tree/main/packages/lint-profile-backward-compatible#readme"
31
+ }, (tree, file) => {
32
+ const version = file.data.profile?.version;
33
+ if (version === void 0) return;
34
+ visit(tree, (node, ancestors) => {
35
+ if (node.type !== "field" && node.type !== "component" && node.type !== "subcomponent") return;
36
+ const id = node.data?.id;
37
+ if (id === void 0 || node.data?.optionality !== Optionality.BackwardCompatible || isEmptyNode(node)) return;
38
+ const value = toHl7v2(node, delimiters(tree));
39
+ if (value === EXPLICIT_NULL) return SKIP;
40
+ const message = file.message(messages.backwardCompatible(id, node.data?.name ?? "", version), {
41
+ ancestors: [...ancestors, node],
42
+ place: node.position
43
+ });
44
+ message.actual = value;
45
+ message.expected = ["", EXPLICIT_NULL];
46
+ return SKIP;
47
+ });
48
+ });
49
+ //#endregion
50
+ export { hl7v2LintBackwardCompatible as default };
51
+
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["// oxlint-disable-next-line no-unused-vars -- triggers VFile DataMap augmentation\nimport type { ProfileContext } from \"@glion/annotate-profile-context\";\n// oxlint-disable-next-line no-unused-vars -- triggers ComponentData and SubcomponentData augmentation\nimport type { hl7v2AnnotateProfileDatatypes } from \"@glion/annotate-profile-datatypes\";\n// oxlint-disable-next-line no-unused-vars -- triggers FieldData augmentation\nimport type { hl7v2AnnotateProfileFields } from \"@glion/annotate-profile-fields\";\nimport type { Root } from \"@glion/ast\";\nimport { toHl7v2 } from \"@glion/to-hl7v2\";\nimport { delimiters } from \"@glion/util-query\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport { isEmptyNode, Optionality } from \"@glion/utils\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/** HL7v2 explicit null: the receiver deletes the element's value. */\nconst EXPLICIT_NULL = '\"\"';\n\nconst messages = {\n backwardCompatible: (id: string, name: string, version: string) =>\n `\\`${id}\\` (${name}) has a value; v${version} keeps it only for backward compatibility.`,\n} as const;\n\n/**\n * Lint rule that reports a value in any element whose optionality is `B`\n * (backward compatible): a field, a component, or a subcomponent.\n *\n * Reads `optionality` from `node.data`, which the profile annotators write, so\n * `@glion/annotate-profile-fields` and `@glion/annotate-profile-datatypes`\n * MUST run before it. An empty element and the explicit null `\"\"` are\n * accepted.\n *\n * @example\n * ```typescript\n * unified()\n * .use(hl7v2AnnotateProfileContext)\n * .use(hl7v2AnnotateProfileFields)\n * .use(hl7v2AnnotateProfileDatatypes)\n * .use(hl7v2LintBackwardCompatible);\n * ```;\n */\nconst hl7v2LintBackwardCompatible = lintRule<Root>(\n {\n origin: \"hl7v2-lint:backward-compatible\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-profile-backward-compatible#readme\",\n },\n (tree, file) => {\n const version = file.data.profile?.version;\n if (version === undefined) {\n return;\n }\n\n visit(tree, (node, ancestors) => {\n // Fields, components and subcomponents carry an optionality.\n if (\n node.type !== \"field\" &&\n node.type !== \"component\" &&\n node.type !== \"subcomponent\"\n ) {\n return;\n }\n\n // An element that is not reported may still have components that are.\n const id = node.data?.id;\n if (\n id === undefined ||\n node.data?.optionality !== Optionality.BackwardCompatible ||\n isEmptyNode(node)\n ) {\n return;\n }\n\n const value = toHl7v2(node, delimiters(tree));\n if (value === EXPLICIT_NULL) {\n return SKIP;\n }\n\n const message = file.message(\n messages.backwardCompatible(id, node.data?.name ?? \"\", version),\n { ancestors: [...ancestors, node], place: node.position }\n );\n message.actual = value;\n message.expected = [\"\", EXPLICIT_NULL];\n // The element is reported; its components need no report of their own.\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintBackwardCompatible;\n"],"mappings":";;;;;;;AAcA,MAAM,gBAAgB;AAEtB,MAAM,WAAW,EACf,qBAAqB,IAAY,MAAc,YAC7C,KAAK,GAAG,MAAM,KAAK,kBAAkB,QAAQ,6CAChD;;;;;;;;;;;;;;;;;;;AAoBD,MAAM,8BAA8B,SAClC;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,SAAS;CACd,MAAM,UAAU,KAAK,KAAK,SAAS;AACnC,KAAI,YAAY,KAAA,EACd;AAGF,OAAM,OAAO,MAAM,cAAc;AAE/B,MACE,KAAK,SAAS,WACd,KAAK,SAAS,eACd,KAAK,SAAS,eAEd;EAIF,MAAM,KAAK,KAAK,MAAM;AACtB,MACE,OAAO,KAAA,KACP,KAAK,MAAM,gBAAgB,YAAY,sBACvC,YAAY,KAAK,CAEjB;EAGF,MAAM,QAAQ,QAAQ,MAAM,WAAW,KAAK,CAAC;AAC7C,MAAI,UAAU,cACZ,QAAO;EAGT,MAAM,UAAU,KAAK,QACnB,SAAS,mBAAmB,IAAI,KAAK,MAAM,QAAQ,IAAI,QAAQ,EAC/D;GAAE,WAAW,CAAC,GAAG,WAAW,KAAK;GAAE,OAAO,KAAK;GAAU,CAC1D;AACD,UAAQ,SAAS;AACjB,UAAQ,WAAW,CAAC,IAAI,cAAc;AAEtC,SAAO;GACP;EAEL"}
package/package.json CHANGED
@@ -1,6 +1,74 @@
1
1
  {
2
2
  "name": "@glion/lint-profile-backward-compatible",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.0",
4
+ "description": "Lint rule that reports a value in an element HL7v2 keeps only for backward compatibility",
5
+ "keywords": [
6
+ "health",
7
+ "healthcare",
8
+ "hl7",
9
+ "hl7v2",
10
+ "nodejs",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://glion.dev",
14
+ "license": "MIT",
15
+ "author": {
16
+ "name": "Melek Somai",
17
+ "email": "melek@rethinkhealth.io"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/rethinkhealth/glion.git",
22
+ "directory": "packages/lint-profile-backward-compatible"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "type": "module",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": "./dist/index.js"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsdown && tsc --emitDeclarationOnly",
37
+ "check-types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
38
+ "check:readme": "glion-check-readme",
39
+ "test": "vitest run",
40
+ "test:coverage": "vitest run --coverage",
41
+ "test:watch": "vitest",
42
+ "publint": "publint --strict"
43
+ },
44
+ "dependencies": {
45
+ "@glion/annotate-profile-datatypes": "workspace:*",
46
+ "@glion/annotate-profile-fields": "workspace:*",
47
+ "@glion/ast": "workspace:*",
48
+ "@glion/to-hl7v2": "workspace:*",
49
+ "@glion/util-query": "workspace:*",
50
+ "@glion/util-visit": "workspace:*",
51
+ "@glion/utils": "workspace:*",
52
+ "unified-lint-rule": "3.0.1"
53
+ },
54
+ "devDependencies": {
55
+ "@glion/annotate-profile-context": "workspace:*",
56
+ "@glion/builder": "workspace:*",
57
+ "@glion/check-readme": "workspace:*",
58
+ "@glion/parser": "workspace:*",
59
+ "@glion/testing": "workspace:*",
60
+ "@glion/tsconfig": "workspace:*",
61
+ "@types/node": "25.6.0",
62
+ "@vitest/coverage-v8": "4.1.11",
63
+ "publint": "0.3.18",
64
+ "tsdown": "0.21.10",
65
+ "typescript": "6.0.3",
66
+ "unified": "^11.0.5",
67
+ "vfile": "^6.0.3",
68
+ "vitest": "4.1.11"
69
+ },
70
+ "engines": {
71
+ "node": ">=22"
72
+ },
73
+ "packageManager": "pnpm@10.14.0"
74
+ }