@glion/lint-profile-withdrawn 0.25.0 → 0.27.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Rethink Health
3
+ Copyright (c) 2023 Rethink Health, SUARL
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -79,7 +79,7 @@ AL1|1||PENICILLIN|||20240101
79
79
  Reported message:
80
80
 
81
81
  ```
82
- `AL1-6` (Identification Date) has a value; it is withdrawn in v2.7 and must be empty.
82
+ The data element has a value; it is withdrawn in v2.7 and must be empty.
83
83
  ```
84
84
 
85
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.
@@ -1 +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,kBAAkB,mDA8CvB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAA2B,IAAI,EAAgB,MAAM,YAAY,CAAC;AAe9E;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,kBAAkB,mDAwDvB,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { lintRule } from "unified-lint-rule";
6
6
  //#region src/index.ts
7
7
  /** HL7v2 explicit null: the receiver deletes the element's value. */
8
8
  const EXPLICIT_NULL = "\"\"";
9
- const messages = { withdrawn: (id, name, version) => `\`${id}\` (${name}) has a value; it is withdrawn in v${version} and must be empty.` };
9
+ const messages = { withdrawn: (version) => `The data element has a value; it is withdrawn in v${version} and must be empty.` };
10
10
  /**
11
11
  * Lint rule that reports a value in any element whose optionality is `W`
12
12
  * (withdrawn): a field, a component, or a subcomponent.
@@ -31,18 +31,36 @@ const hl7v2LintWithdrawn = lintRule({
31
31
  }, (tree, file) => {
32
32
  const version = file.data.profile?.version;
33
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.Withdrawn || isEmptyNode(node)) return;
34
+ /**
35
+ * Reports `node` when it is withdrawn and holds a value other than the
36
+ * explicit null. Returns whether `node` is withdrawn and not empty.
37
+ */
38
+ const report = (node, ancestors) => {
39
+ const { data } = node;
40
+ if (data?.optionality !== Optionality.Withdrawn || isEmptyNode(node)) return false;
38
41
  const value = toHl7v2(node, delimiters(tree));
39
- if (value === EXPLICIT_NULL) return SKIP;
40
- const message = file.message(messages.withdrawn(id, node.data?.name ?? "", version), {
41
- ancestors: [...ancestors, node],
42
- place: node.position
43
- });
44
- message.actual = value;
45
- message.expected = ["", EXPLICIT_NULL];
42
+ if (value !== EXPLICIT_NULL) {
43
+ const message = file.message(messages.withdrawn(version), {
44
+ ancestors,
45
+ place: node.position
46
+ });
47
+ message.actual = value;
48
+ message.expected = ["", EXPLICIT_NULL];
49
+ }
50
+ return true;
51
+ };
52
+ visit(tree, "field", (field, parents) => {
53
+ const fieldAncestors = [...parents, field];
54
+ if (report(field, fieldAncestors)) return SKIP;
55
+ for (const repetition of field.children) for (const component of repetition.children) {
56
+ const componentAncestors = [
57
+ ...fieldAncestors,
58
+ repetition,
59
+ component
60
+ ];
61
+ if (report(component, componentAncestors)) continue;
62
+ for (const subcomponent of component.children) report(subcomponent, [...componentAncestors, subcomponent]);
63
+ }
46
64
  return SKIP;
47
65
  });
48
66
  });
package/dist/index.js.map CHANGED
@@ -1 +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 withdrawn: (id: string, name: string, version: string) =>\n `\\`${id}\\` (${name}) has a value; it is withdrawn in v${version} and must be empty.`,\n} as const;\n\n/**\n * Lint rule that reports a value in any element whose optionality is `W`\n * (withdrawn): 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(hl7v2LintWithdrawn);\n * ```;\n */\nconst hl7v2LintWithdrawn = lintRule<Root>(\n {\n origin: \"hl7v2-lint:withdrawn\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-profile-withdrawn#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.Withdrawn ||\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.withdrawn(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 hl7v2LintWithdrawn;\n"],"mappings":";;;;;;;AAcA,MAAM,gBAAgB;AAEtB,MAAM,WAAW,EACf,YAAY,IAAY,MAAc,YACpC,KAAK,GAAG,MAAM,KAAK,qCAAqC,QAAQ,sBACnE;;;;;;;;;;;;;;;;;;;AAoBD,MAAM,qBAAqB,SACzB;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,aACvC,YAAY,KAAK,CAEjB;EAGF,MAAM,QAAQ,QAAQ,MAAM,WAAW,KAAK,CAAC;AAC7C,MAAI,UAAU,cACZ,QAAO;EAGT,MAAM,UAAU,KAAK,QACnB,SAAS,UAAU,IAAI,KAAK,MAAM,QAAQ,IAAI,QAAQ,EACtD;GAAE,WAAW,CAAC,GAAG,WAAW,KAAK;GAAE,OAAO,KAAK;GAAU,CAC1D;AACD,UAAQ,SAAS;AACjB,UAAQ,WAAW,CAAC,IAAI,cAAc;AAEtC,SAAO;GACP;EAEL"}
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 { Component, Field, Nodes, Root, Subcomponent } 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 withdrawn: (version: string) =>\n `The data element has a value; it is withdrawn in v${version} and must be empty.`,\n} as const;\n\n/**\n * Lint rule that reports a value in any element whose optionality is `W`\n * (withdrawn): 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(hl7v2LintWithdrawn);\n * ```;\n */\nconst hl7v2LintWithdrawn = lintRule<Root>(\n {\n origin: \"hl7v2-lint:withdrawn\",\n url: \"https://github.com/rethinkhealth/glion/tree/main/packages/lint-profile-withdrawn#readme\",\n },\n (tree, file) => {\n const version = file.data.profile?.version;\n if (version === undefined) {\n return;\n }\n\n /**\n * Reports `node` when it is withdrawn and holds a value other than the\n * explicit null. Returns whether `node` is withdrawn and not empty.\n */\n const report = (\n node: Field | Component | Subcomponent,\n ancestors: Nodes[]\n ): boolean => {\n const { data } = node;\n if (data?.optionality !== Optionality.Withdrawn || isEmptyNode(node)) {\n return false;\n }\n\n const value = toHl7v2(node, delimiters(tree));\n if (value !== EXPLICIT_NULL) {\n const message = file.message(messages.withdrawn(version), {\n ancestors,\n place: node.position,\n });\n message.actual = value;\n message.expected = [\"\", EXPLICIT_NULL];\n }\n return true;\n };\n\n // A reported element's components need no report of their own.\n visit(tree, \"field\", (field, parents) => {\n const fieldAncestors = [...parents, field];\n if (report(field, fieldAncestors)) {\n return SKIP;\n }\n for (const repetition of field.children) {\n for (const component of repetition.children) {\n const componentAncestors = [...fieldAncestors, repetition, component];\n if (report(component, componentAncestors)) {\n continue;\n }\n for (const subcomponent of component.children) {\n report(subcomponent, [...componentAncestors, subcomponent]);\n }\n }\n }\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintWithdrawn;\n"],"mappings":";;;;;;;AAcA,MAAM,gBAAgB;AAEtB,MAAM,WAAW,EACf,YAAY,YACV,qDAAqD,QAAQ,sBAChE;;;;;;;;;;;;;;;;;;;AAoBD,MAAM,qBAAqB,SACzB;CACE,QAAQ;CACR,KAAK;CACN,GACA,MAAM,SAAS;CACd,MAAM,UAAU,KAAK,KAAK,SAAS;AACnC,KAAI,YAAY,KAAA,EACd;;;;;CAOF,MAAM,UACJ,MACA,cACY;EACZ,MAAM,EAAE,SAAS;AACjB,MAAI,MAAM,gBAAgB,YAAY,aAAa,YAAY,KAAK,CAClE,QAAO;EAGT,MAAM,QAAQ,QAAQ,MAAM,WAAW,KAAK,CAAC;AAC7C,MAAI,UAAU,eAAe;GAC3B,MAAM,UAAU,KAAK,QAAQ,SAAS,UAAU,QAAQ,EAAE;IACxD;IACA,OAAO,KAAK;IACb,CAAC;AACF,WAAQ,SAAS;AACjB,WAAQ,WAAW,CAAC,IAAI,cAAc;;AAExC,SAAO;;AAIT,OAAM,MAAM,UAAU,OAAO,YAAY;EACvC,MAAM,iBAAiB,CAAC,GAAG,SAAS,MAAM;AAC1C,MAAI,OAAO,OAAO,eAAe,CAC/B,QAAO;AAET,OAAK,MAAM,cAAc,MAAM,SAC7B,MAAK,MAAM,aAAa,WAAW,UAAU;GAC3C,MAAM,qBAAqB;IAAC,GAAG;IAAgB;IAAY;IAAU;AACrE,OAAI,OAAO,WAAW,mBAAmB,CACvC;AAEF,QAAK,MAAM,gBAAgB,UAAU,SACnC,QAAO,cAAc,CAAC,GAAG,oBAAoB,aAAa,CAAC;;AAIjE,SAAO;GACP;EAEL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/lint-profile-withdrawn",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "Lint rule that reports a value in an element HL7v2 has withdrawn",
5
5
  "keywords": [
6
6
  "health",
@@ -34,15 +34,17 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "unified-lint-rule": "3.0.1",
37
- "@glion/annotate-profile-datatypes": "0.25.0",
38
- "@glion/annotate-profile-fields": "0.25.0",
39
- "@glion/ast": "0.25.0",
40
- "@glion/to-hl7v2": "0.25.0",
41
- "@glion/util-query": "0.25.0",
42
- "@glion/util-visit": "0.25.0",
43
- "@glion/utils": "0.25.0"
37
+ "@glion/annotate-profile-datatypes": "0.27.0",
38
+ "@glion/annotate-profile-fields": "0.27.0",
39
+ "@glion/ast": "0.27.0",
40
+ "@glion/to-hl7v2": "0.27.0",
41
+ "@glion/util-visit": "0.27.0",
42
+ "@glion/util-query": "0.27.0",
43
+ "@glion/utils": "0.27.0"
44
44
  },
45
45
  "devDependencies": {
46
+ "@stryker-mutator/core": "10.0.0",
47
+ "@stryker-mutator/vitest-runner": "10.0.0",
46
48
  "@types/node": "25.6.0",
47
49
  "@vitest/coverage-v8": "4.1.11",
48
50
  "publint": "0.3.18",
@@ -51,12 +53,12 @@
51
53
  "unified": "^11.0.5",
52
54
  "vfile": "^6.0.3",
53
55
  "vitest": "4.1.11",
54
- "@glion/annotate-profile-context": "0.25.0",
55
- "@glion/builder": "0.25.0",
56
+ "@glion/annotate-profile-context": "0.27.0",
57
+ "@glion/builder": "0.27.0",
56
58
  "@glion/check-readme": "0.18.0",
57
- "@glion/parser": "0.25.0",
59
+ "@glion/tsconfig": "0.18.0",
58
60
  "@glion/testing": "0.18.0",
59
- "@glion/tsconfig": "0.18.0"
61
+ "@glion/parser": "0.27.0"
60
62
  },
61
63
  "engines": {
62
64
  "node": ">=22"
@@ -65,9 +67,10 @@
65
67
  "build": "tsdown && tsc --emitDeclarationOnly",
66
68
  "check-types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
67
69
  "check:readme": "glion-check-readme",
70
+ "mutate": "stryker run",
71
+ "publint": "publint --strict",
68
72
  "test": "vitest run",
69
73
  "test:coverage": "vitest run --coverage",
70
- "test:watch": "vitest",
71
- "publint": "publint --strict"
74
+ "test:watch": "vitest"
72
75
  }
73
76
  }