@glion/lint-profile-table-values 0.14.1
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 +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Rethink Health
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
declare const hl7v2LintTableValues: import("unified-lint-rule").Plugin<Root, unknown>;
|
|
20
|
+
export default hl7v2LintTableValues;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,YAAY,CAAC;AAahD;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,oBAAoB,mDA+DzB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SKIP, visit } from "@glion/util-visit";
|
|
2
|
+
import { isEmptyNode } from "@glion/utils";
|
|
3
|
+
import { lintRule } from "unified-lint-rule";
|
|
4
|
+
//#region src/index.ts
|
|
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
|
+
* Lint rule that validates coded field values against HL7-type tables.
|
|
14
|
+
*
|
|
15
|
+
* For each field that references a table in its profile, loads the table
|
|
16
|
+
* definition and checks that the field's first component value is a valid
|
|
17
|
+
* code in that table.
|
|
18
|
+
*
|
|
19
|
+
* Only `hl7`-type tables are validated. `user`-type tables are skipped
|
|
20
|
+
* (they contain site-specific codes).
|
|
21
|
+
*
|
|
22
|
+
* Empty fields are skipped. Segments without a known profile are skipped.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* unified().use(hl7v2LintTableValues);
|
|
27
|
+
* ```;
|
|
28
|
+
*/
|
|
29
|
+
const hl7v2LintTableValues = lintRule({ origin: "hl7v2-lint:table-values" }, (tree, file) => {
|
|
30
|
+
const ctx = file.data.profile;
|
|
31
|
+
if (!ctx) return;
|
|
32
|
+
visit(tree, "field", (fieldNode, ancestors, info) => {
|
|
33
|
+
if (isEmptyNode(fieldNode)) return SKIP;
|
|
34
|
+
const segment = ancestors.at(-1);
|
|
35
|
+
if (!segment || segment.type !== "segment") return SKIP;
|
|
36
|
+
const fieldDef = ctx.fields.get(segment.name);
|
|
37
|
+
if (!fieldDef) return SKIP;
|
|
38
|
+
const fieldProfile = fieldDef.bySequence.get(info.sequence);
|
|
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;
|
|
44
|
+
for (const repetition of fieldNode.children) {
|
|
45
|
+
const sub = repetition?.children[0]?.children[0];
|
|
46
|
+
if (!sub?.value) continue;
|
|
47
|
+
const val = sub.value;
|
|
48
|
+
if (!tableDef.codes.has(val)) {
|
|
49
|
+
const name = fieldProfile.name ? ` (${fieldProfile.name})` : "";
|
|
50
|
+
file.message(`Field ${segment.name}-${info.sequence}${name} value '${val}' is not in table ${tableId} (${tableDef.description})`, {
|
|
51
|
+
ancestors: [
|
|
52
|
+
...ancestors,
|
|
53
|
+
fieldNode,
|
|
54
|
+
repetition
|
|
55
|
+
],
|
|
56
|
+
place: repetition.position ?? fieldNode.position
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return SKIP;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
//#endregion
|
|
64
|
+
export { hl7v2LintTableValues as default };
|
|
65
|
+
|
|
66
|
+
//# 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\";\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 fieldDef = ctx.fields.get(segment.name);\n if (!fieldDef) {\n return SKIP;\n }\n\n const fieldProfile = fieldDef.bySequence.get(info.sequence);\n if (!fieldProfile?.table) {\n return SKIP;\n }\n\n const tableId = normalizeTableId(fieldProfile.table);\n const tableDef = ctx.tables.get(tableId);\n if (!tableDef) {\n return SKIP;\n }\n\n // Only validate HL7-defined tables\n if (tableDef.type !== \"hl7\") {\n return SKIP;\n }\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,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,IAAI,OAAO,IAAI,QAAQ,KAAK;AAC7C,MAAI,CAAC,SACH,QAAO;EAGT,MAAM,eAAe,SAAS,WAAW,IAAI,KAAK,SAAS;AAC3D,MAAI,CAAC,cAAc,MACjB,QAAO;EAGT,MAAM,UAAU,iBAAiB,aAAa,MAAM;EACpD,MAAM,WAAW,IAAI,OAAO,IAAI,QAAQ;AACxC,MAAI,CAAC,SACH,QAAO;AAIT,MAAI,SAAS,SAAS,MACpB,QAAO;AAIT,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
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@glion/lint-profile-table-values",
|
|
3
|
+
"version": "0.14.1",
|
|
4
|
+
"description": "Lint rule to validate coded field values against HL7v2 tables",
|
|
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": "rethinkhealth/glion.git",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"unified-lint-rule": "3.0.1",
|
|
33
|
+
"@glion/ast": "0.14.1",
|
|
34
|
+
"@glion/utils": "0.14.1",
|
|
35
|
+
"@glion/util-visit": "0.14.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^25.5.0",
|
|
39
|
+
"@vitest/coverage-v8": "4.1.2",
|
|
40
|
+
"tsdown": "0.21.7",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
|
+
"unified": "^11.0.5",
|
|
43
|
+
"vfile": "^6.0.3",
|
|
44
|
+
"vitest": "4.1.2",
|
|
45
|
+
"@glion/annotate-profile-context": "0.14.1",
|
|
46
|
+
"@glion/tsconfig": "0.0.1",
|
|
47
|
+
"@glion/testing": "0.0.2",
|
|
48
|
+
"@glion/builder": "0.14.1"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
55
|
+
"check-types": "tsc --noEmit",
|
|
56
|
+
"bench": "vitest bench --run",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:coverage": "vitest run --coverage",
|
|
59
|
+
"test:watch": "vitest"
|
|
60
|
+
}
|
|
61
|
+
}
|