@glion/lint-profile-table-values 0.15.3 → 0.19.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/dist/index.d.ts +0 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/package.json +16 -18
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
import type { Root } from "@glion/ast";
|
|
2
|
-
/**
|
|
3
|
-
* Lint rule that validates coded field values against HL7-type tables.
|
|
4
|
-
*
|
|
5
|
-
* For each field that references a table in its profile, loads the table
|
|
6
|
-
* definition and checks that the field's first component value is a valid
|
|
7
|
-
* code in that table.
|
|
8
|
-
*
|
|
9
|
-
* Only `hl7`-type tables are validated. `user`-type tables are skipped
|
|
10
|
-
* (they contain site-specific codes).
|
|
11
|
-
*
|
|
12
|
-
* Empty fields are skipped. Segments without a known profile are skipped.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* unified().use(hl7v2LintTableValues);
|
|
17
|
-
* ```;
|
|
18
|
-
*/
|
|
19
2
|
declare const hl7v2LintTableValues: import("unified-lint-rule").Plugin<Root, unknown>;
|
|
20
3
|
export default hl7v2LintTableValues;
|
|
21
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,18 @@ function normalizeTableId(tableRef) {
|
|
|
26
26
|
* unified().use(hl7v2LintTableValues);
|
|
27
27
|
* ```;
|
|
28
28
|
*/
|
|
29
|
+
function resolveHl7Table(ctx, segmentName, sequence) {
|
|
30
|
+
const fieldProfile = ctx.fields.get(segmentName)?.bySequence.get(sequence);
|
|
31
|
+
if (!fieldProfile?.table) return;
|
|
32
|
+
const tableId = normalizeTableId(fieldProfile.table);
|
|
33
|
+
const tableDef = ctx.tables.get(tableId);
|
|
34
|
+
if (tableDef?.type !== "hl7") return;
|
|
35
|
+
return {
|
|
36
|
+
fieldProfile,
|
|
37
|
+
tableDef,
|
|
38
|
+
tableId
|
|
39
|
+
};
|
|
40
|
+
}
|
|
29
41
|
const hl7v2LintTableValues = lintRule({ origin: "hl7v2-lint:table-values" }, (tree, file) => {
|
|
30
42
|
const ctx = file.data.profile;
|
|
31
43
|
if (!ctx) return;
|
|
@@ -33,14 +45,9 @@ const hl7v2LintTableValues = lintRule({ origin: "hl7v2-lint:table-values" }, (tr
|
|
|
33
45
|
if (isEmptyNode(fieldNode)) return SKIP;
|
|
34
46
|
const segment = ancestors.at(-1);
|
|
35
47
|
if (!segment || segment.type !== "segment") return SKIP;
|
|
36
|
-
const
|
|
37
|
-
if (!
|
|
38
|
-
const fieldProfile =
|
|
39
|
-
if (!fieldProfile?.table) return SKIP;
|
|
40
|
-
const tableId = normalizeTableId(fieldProfile.table);
|
|
41
|
-
const tableDef = ctx.tables.get(tableId);
|
|
42
|
-
if (!tableDef) return SKIP;
|
|
43
|
-
if (tableDef.type !== "hl7") return SKIP;
|
|
48
|
+
const resolved = resolveHl7Table(ctx, segment.name, info.sequence);
|
|
49
|
+
if (!resolved) return SKIP;
|
|
50
|
+
const { fieldProfile, tableId, tableDef } = resolved;
|
|
44
51
|
for (const repetition of fieldNode.children) {
|
|
45
52
|
const sub = repetition?.children[0]?.children[0];
|
|
46
53
|
if (!sub?.value) continue;
|
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 */\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
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/lint-profile-table-values",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Lint rule to validate coded field values against HL7v2 tables",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -34,34 +34,32 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"unified-lint-rule": "3.0.1",
|
|
37
|
-
"@glion/util-visit": "0.
|
|
38
|
-
"@glion/
|
|
39
|
-
"@glion/
|
|
37
|
+
"@glion/util-visit": "0.19.0",
|
|
38
|
+
"@glion/utils": "0.19.0",
|
|
39
|
+
"@glion/ast": "0.19.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "
|
|
43
|
-
"@vitest/coverage-v8": "4.1.
|
|
42
|
+
"@types/node": "25.6.0",
|
|
43
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
44
44
|
"publint": "0.3.18",
|
|
45
|
-
"tsdown": "0.21.
|
|
46
|
-
"typescript": "
|
|
45
|
+
"tsdown": "0.21.10",
|
|
46
|
+
"typescript": "6.0.3",
|
|
47
47
|
"unified": "^11.0.5",
|
|
48
48
|
"vfile": "^6.0.3",
|
|
49
|
-
"vitest": "4.1.
|
|
50
|
-
"@glion/annotate-profile-context": "0.
|
|
51
|
-
"@glion/
|
|
52
|
-
"@glion/
|
|
53
|
-
"@glion/testing": "0.
|
|
54
|
-
"@glion/tsconfig": "0.
|
|
49
|
+
"vitest": "4.1.11",
|
|
50
|
+
"@glion/annotate-profile-context": "0.19.0",
|
|
51
|
+
"@glion/builder": "0.19.0",
|
|
52
|
+
"@glion/check-readme": "0.18.0",
|
|
53
|
+
"@glion/testing": "0.18.0",
|
|
54
|
+
"@glion/tsconfig": "0.18.0"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
57
|
+
"node": ">=22"
|
|
58
58
|
},
|
|
59
|
-
"packageManager": "pnpm@10.14.0",
|
|
60
59
|
"scripts": {
|
|
61
60
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
62
|
-
"check-types": "tsc --noEmit",
|
|
61
|
+
"check-types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
|
|
63
62
|
"check:readme": "glion-check-readme",
|
|
64
|
-
"bench": "vitest bench --run",
|
|
65
63
|
"test": "vitest run",
|
|
66
64
|
"test:coverage": "vitest run --coverage",
|
|
67
65
|
"test:watch": "vitest",
|