@glion/lint-profile-table-values 0.24.0 → 0.25.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,YAAY,CAAC;AAgDhD,QAAA,MAAM,oBAAoB,mDAgDzB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,YAAY,CAAC;AAuChD,QAAA,MAAM,oBAAoB,mDAgDzB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -3,13 +3,6 @@ import { isEmptyNode } from "@glion/utils";
3
3
  import { lintRule } from "unified-lint-rule";
4
4
  //#region src/index.ts
5
5
  /**
6
- * Strip the "HL7" prefix from table IDs in field profiles.
7
- * Field profiles reference tables as "HL70001"; the tables store uses "0001".
8
- */
9
- function normalizeTableId(tableRef) {
10
- return tableRef.replace(/^HL7/, "");
11
- }
12
- /**
13
6
  * Lint rule that validates coded field values against HL7-type tables.
14
7
  *
15
8
  * For each field that references a table in its profile, loads the table
@@ -29,13 +22,11 @@ function normalizeTableId(tableRef) {
29
22
  function resolveHl7Table(ctx, segmentName, sequence) {
30
23
  const fieldProfile = ctx.fields.get(segmentName)?.bySequence.get(sequence);
31
24
  if (!fieldProfile?.table) return;
32
- const tableId = normalizeTableId(fieldProfile.table);
33
- const tableDef = ctx.tables.get(tableId);
25
+ const tableDef = ctx.tables.get(fieldProfile.table);
34
26
  if (tableDef?.type !== "hl7") return;
35
27
  return {
36
28
  fieldProfile,
37
- tableDef,
38
- tableId
29
+ tableDef
39
30
  };
40
31
  }
41
32
  const hl7v2LintTableValues = lintRule({ origin: "hl7v2-lint:table-values" }, (tree, file) => {
@@ -47,14 +38,14 @@ const hl7v2LintTableValues = lintRule({ origin: "hl7v2-lint:table-values" }, (tr
47
38
  if (!segment || segment.type !== "segment") return SKIP;
48
39
  const resolved = resolveHl7Table(ctx, segment.name, info.sequence);
49
40
  if (!resolved) return SKIP;
50
- const { fieldProfile, tableId, tableDef } = resolved;
41
+ const { fieldProfile, tableDef } = resolved;
51
42
  for (const repetition of fieldNode.children) {
52
43
  const sub = repetition?.children[0]?.children[0];
53
44
  if (!sub?.value) continue;
54
45
  const val = sub.value;
55
46
  if (!tableDef.codes.has(val)) {
56
47
  const name = fieldProfile.name ? ` (${fieldProfile.name})` : "";
57
- file.message(`Field ${segment.name}-${info.sequence}${name} value '${val}' is not in table ${tableId} (${tableDef.description})`, {
48
+ file.message(`Field ${segment.name}-${info.sequence}${name} value '${val}' is not in table ${tableDef.id} (${tableDef.description})`, {
58
49
  ancestors: [
59
50
  ...ancestors,
60
51
  fieldNode,
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\";\nimport type { Root, Segment } from \"@glion/ast\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport { isEmptyNode } from \"@glion/utils\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/**\n * Strip the \"HL7\" prefix from table IDs in field profiles.\n * Field profiles reference tables as \"HL70001\"; the tables store uses \"0001\".\n */\nfunction normalizeTableId(tableRef: string): string {\n return tableRef.replace(/^HL7/, \"\");\n}\n\n/**\n * Lint rule that validates coded field values against HL7-type tables.\n *\n * For each field that references a table in its profile, loads the table\n * definition and checks that the field's first component value is a valid\n * code in that table.\n *\n * Only `hl7`-type tables are validated. `user`-type tables are skipped\n * (they contain site-specific codes).\n *\n * Empty fields are skipped. Segments without a known profile are skipped.\n *\n * @example\n * ```typescript\n * unified().use(hl7v2LintTableValues);\n * ```;\n */\nfunction resolveHl7Table(\n ctx: ProfileContext,\n segmentName: string,\n sequence: number\n) {\n const fieldProfile = ctx.fields.get(segmentName)?.bySequence.get(sequence);\n if (!fieldProfile?.table) {\n return;\n }\n const tableId = normalizeTableId(fieldProfile.table);\n const tableDef = ctx.tables.get(tableId);\n // Only HL7-defined tables are validated; user tables hold site-specific codes.\n if (tableDef?.type !== \"hl7\") {\n return;\n }\n return { fieldProfile, tableDef, tableId };\n}\n\nconst hl7v2LintTableValues = lintRule<Root>(\n { origin: \"hl7v2-lint:table-values\" },\n (tree, file) => {\n const ctx = file.data.profile;\n if (!ctx) {\n return;\n }\n\n visit(tree, \"field\", (fieldNode, ancestors, info) => {\n // Check emptiness first — avoids lookups for the majority of fields\n if (isEmptyNode(fieldNode)) {\n return SKIP;\n }\n\n const segment = ancestors.at(-1) as Segment | undefined;\n if (!segment || segment.type !== \"segment\") {\n return SKIP;\n }\n\n const resolved = resolveHl7Table(ctx, segment.name, info.sequence);\n if (!resolved) {\n return SKIP;\n }\n const { fieldProfile, tableId, tableDef } = resolved;\n\n // Check each repetition's coded value against the table\n for (const repetition of fieldNode.children) {\n const sub = repetition?.children[0]?.children[0];\n if (!sub?.value) {\n continue;\n }\n const val = sub.value;\n\n if (!tableDef.codes.has(val)) {\n const name = fieldProfile.name ? ` (${fieldProfile.name})` : \"\";\n file.message(\n `Field ${segment.name}-${info.sequence}${name} value '${val}' is not in table ${tableId} (${tableDef.description})`,\n {\n ancestors: [...ancestors, fieldNode, repetition],\n place: repetition.position ?? fieldNode.position,\n }\n );\n }\n }\n\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintTableValues;\n"],"mappings":";;;;;;;;AAWA,SAAS,iBAAiB,UAA0B;AAClD,QAAO,SAAS,QAAQ,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;AAoBrC,SAAS,gBACP,KACA,aACA,UACA;CACA,MAAM,eAAe,IAAI,OAAO,IAAI,YAAY,EAAE,WAAW,IAAI,SAAS;AAC1E,KAAI,CAAC,cAAc,MACjB;CAEF,MAAM,UAAU,iBAAiB,aAAa,MAAM;CACpD,MAAM,WAAW,IAAI,OAAO,IAAI,QAAQ;AAExC,KAAI,UAAU,SAAS,MACrB;AAEF,QAAO;EAAE;EAAc;EAAU;EAAS;;AAG5C,MAAM,uBAAuB,SAC3B,EAAE,QAAQ,2BAA2B,GACpC,MAAM,SAAS;CACd,MAAM,MAAM,KAAK,KAAK;AACtB,KAAI,CAAC,IACH;AAGF,OAAM,MAAM,UAAU,WAAW,WAAW,SAAS;AAEnD,MAAI,YAAY,UAAU,CACxB,QAAO;EAGT,MAAM,UAAU,UAAU,GAAG,GAAG;AAChC,MAAI,CAAC,WAAW,QAAQ,SAAS,UAC/B,QAAO;EAGT,MAAM,WAAW,gBAAgB,KAAK,QAAQ,MAAM,KAAK,SAAS;AAClE,MAAI,CAAC,SACH,QAAO;EAET,MAAM,EAAE,cAAc,SAAS,aAAa;AAG5C,OAAK,MAAM,cAAc,UAAU,UAAU;GAC3C,MAAM,MAAM,YAAY,SAAS,IAAI,SAAS;AAC9C,OAAI,CAAC,KAAK,MACR;GAEF,MAAM,MAAM,IAAI;AAEhB,OAAI,CAAC,SAAS,MAAM,IAAI,IAAI,EAAE;IAC5B,MAAM,OAAO,aAAa,OAAO,KAAK,aAAa,KAAK,KAAK;AAC7D,SAAK,QACH,SAAS,QAAQ,KAAK,GAAG,KAAK,WAAW,KAAK,UAAU,IAAI,oBAAoB,QAAQ,IAAI,SAAS,YAAY,IACjH;KACE,WAAW;MAAC,GAAG;MAAW;MAAW;MAAW;KAChD,OAAO,WAAW,YAAY,UAAU;KACzC,CACF;;;AAIL,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\";\nimport type { Root, Segment } from \"@glion/ast\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport { isEmptyNode } from \"@glion/utils\";\nimport { lintRule } from \"unified-lint-rule\";\n\n/**\n * Lint rule that validates coded field values against HL7-type tables.\n *\n * For each field that references a table in its profile, loads the table\n * definition and checks that the field's first component value is a valid\n * code in that table.\n *\n * Only `hl7`-type tables are validated. `user`-type tables are skipped\n * (they contain site-specific codes).\n *\n * Empty fields are skipped. Segments without a known profile are skipped.\n *\n * @example\n * ```typescript\n * unified().use(hl7v2LintTableValues);\n * ```;\n */\nfunction resolveHl7Table(\n ctx: ProfileContext,\n segmentName: string,\n sequence: number\n) {\n const fieldProfile = ctx.fields.get(segmentName)?.bySequence.get(sequence);\n if (!fieldProfile?.table) {\n return;\n }\n const tableDef = ctx.tables.get(fieldProfile.table);\n // Only HL7-defined tables are validated; user tables hold site-specific codes.\n if (tableDef?.type !== \"hl7\") {\n return;\n }\n return { fieldProfile, tableDef };\n}\n\nconst hl7v2LintTableValues = lintRule<Root>(\n { origin: \"hl7v2-lint:table-values\" },\n (tree, file) => {\n const ctx = file.data.profile;\n if (!ctx) {\n return;\n }\n\n visit(tree, \"field\", (fieldNode, ancestors, info) => {\n // Check emptiness first — avoids lookups for the majority of fields\n if (isEmptyNode(fieldNode)) {\n return SKIP;\n }\n\n const segment = ancestors.at(-1) as Segment | undefined;\n if (!segment || segment.type !== \"segment\") {\n return SKIP;\n }\n\n const resolved = resolveHl7Table(ctx, segment.name, info.sequence);\n if (!resolved) {\n return SKIP;\n }\n const { fieldProfile, tableDef } = resolved;\n\n // Check each repetition's coded value against the table\n for (const repetition of fieldNode.children) {\n const sub = repetition?.children[0]?.children[0];\n if (!sub?.value) {\n continue;\n }\n const val = sub.value;\n\n if (!tableDef.codes.has(val)) {\n const name = fieldProfile.name ? ` (${fieldProfile.name})` : \"\";\n file.message(\n `Field ${segment.name}-${info.sequence}${name} value '${val}' is not in table ${tableDef.id} (${tableDef.description})`,\n {\n ancestors: [...ancestors, fieldNode, repetition],\n place: repetition.position ?? fieldNode.position,\n }\n );\n }\n }\n\n return SKIP;\n });\n }\n);\n\nexport default hl7v2LintTableValues;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,SAAS,gBACP,KACA,aACA,UACA;CACA,MAAM,eAAe,IAAI,OAAO,IAAI,YAAY,EAAE,WAAW,IAAI,SAAS;AAC1E,KAAI,CAAC,cAAc,MACjB;CAEF,MAAM,WAAW,IAAI,OAAO,IAAI,aAAa,MAAM;AAEnD,KAAI,UAAU,SAAS,MACrB;AAEF,QAAO;EAAE;EAAc;EAAU;;AAGnC,MAAM,uBAAuB,SAC3B,EAAE,QAAQ,2BAA2B,GACpC,MAAM,SAAS;CACd,MAAM,MAAM,KAAK,KAAK;AACtB,KAAI,CAAC,IACH;AAGF,OAAM,MAAM,UAAU,WAAW,WAAW,SAAS;AAEnD,MAAI,YAAY,UAAU,CACxB,QAAO;EAGT,MAAM,UAAU,UAAU,GAAG,GAAG;AAChC,MAAI,CAAC,WAAW,QAAQ,SAAS,UAC/B,QAAO;EAGT,MAAM,WAAW,gBAAgB,KAAK,QAAQ,MAAM,KAAK,SAAS;AAClE,MAAI,CAAC,SACH,QAAO;EAET,MAAM,EAAE,cAAc,aAAa;AAGnC,OAAK,MAAM,cAAc,UAAU,UAAU;GAC3C,MAAM,MAAM,YAAY,SAAS,IAAI,SAAS;AAC9C,OAAI,CAAC,KAAK,MACR;GAEF,MAAM,MAAM,IAAI;AAEhB,OAAI,CAAC,SAAS,MAAM,IAAI,IAAI,EAAE;IAC5B,MAAM,OAAO,aAAa,OAAO,KAAK,aAAa,KAAK,KAAK;AAC7D,SAAK,QACH,SAAS,QAAQ,KAAK,GAAG,KAAK,WAAW,KAAK,UAAU,IAAI,oBAAoB,SAAS,GAAG,IAAI,SAAS,YAAY,IACrH;KACE,WAAW;MAAC,GAAG;MAAW;MAAW;MAAW;KAChD,OAAO,WAAW,YAAY,UAAU;KACzC,CACF;;;AAIL,SAAO;GACP;EAEL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/lint-profile-table-values",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Lint rule to validate coded field values against HL7v2 tables",
5
5
  "keywords": [
6
6
  "health",
@@ -34,9 +34,9 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "unified-lint-rule": "3.0.1",
37
- "@glion/ast": "0.24.0",
38
- "@glion/util-visit": "0.24.0",
39
- "@glion/utils": "0.24.0"
37
+ "@glion/ast": "0.25.0",
38
+ "@glion/util-visit": "0.25.0",
39
+ "@glion/utils": "0.25.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/node": "25.6.0",
@@ -47,8 +47,8 @@
47
47
  "unified": "^11.0.5",
48
48
  "vfile": "^6.0.3",
49
49
  "vitest": "4.1.11",
50
- "@glion/annotate-profile-context": "0.24.0",
51
- "@glion/builder": "0.24.0",
50
+ "@glion/annotate-profile-context": "0.25.0",
51
+ "@glion/builder": "0.25.0",
52
52
  "@glion/check-readme": "0.18.0",
53
53
  "@glion/testing": "0.18.0",
54
54
  "@glion/tsconfig": "0.18.0"