@glion/annotate-profile-fields-code-systems 0.20.0 → 0.22.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 CHANGED
@@ -27,6 +27,7 @@ declare module "@glion/ast" {
27
27
  * datatype (CWE/CNE), the table constrains CWE.1 — the first component's
28
28
  * first subcomponent. This plugin reads that value from each repetition,
29
29
  * resolves it against the UTG code system, and attaches:
30
+ *
30
31
  * - `field.data.codeSystem` — code system identity (same for all reps)
31
32
  * - `rep.data.code` — resolved value entry (different per rep)
32
33
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,IAAI,EAAE,MAAM,YAAY,CAAC;AAIrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAYtC,OAAO,QAAQ,YAAY,CAAC;IAC1B,UAAU,SAAS;QACjB,0EAA0E;QAC1E,UAAU,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,GAAG,SAAS,CAAC;KACtE;IACD,UAAU,mBAAmB;QAC3B,+DAA+D;QAC/D,IAAI,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,GAAG,SAAS,CAAC;KACvE;CACF;AAUD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qCAAqC,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CA2EtE,CAAC;AAEJ,eAAe,qCAAqC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,IAAI,EAAE,MAAM,YAAY,CAAC;AAIrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAYtC,OAAO,QAAQ,YAAY,CAAC;IAC1B,UAAU,SAAS;QACjB,0EAA0E;QAC1E,UAAU,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,GAAG,SAAS,CAAC;KACtE;IACD,UAAU,mBAAmB;QAC3B,+DAA+D;QAC/D,IAAI,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,GAAG,SAAS,CAAC;KACvE;CACF;AAUD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qCAAqC,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAuEtE,CAAC;AAEJ,eAAe,qCAAqC,CAAC"}
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ function tableIdToCodeSystemId(tableRef) {
21
21
  * datatype (CWE/CNE), the table constrains CWE.1 — the first component's
22
22
  * first subcomponent. This plugin reads that value from each repetition,
23
23
  * resolves it against the UTG code system, and attaches:
24
+ *
24
25
  * - `field.data.codeSystem` — code system identity (same for all reps)
25
26
  * - `rep.data.code` — resolved value entry (different per rep)
26
27
  *
@@ -34,15 +35,13 @@ const hl7v2AnnotateProfileFieldsCodeSystems = () => async (tree, file) => {
34
35
  const codeSystems = /* @__PURE__ */ new Map();
35
36
  const entries = [...tableRefs].map((ref) => [ref, tableIdToCodeSystemId(ref)]);
36
37
  const results = await Promise.allSettled(entries.map(([, csId]) => profiles.codeSystems.load(csId)));
37
- for (let i = 0; i < results.length; i++) {
38
- const result = results[i];
38
+ for (const [i, result] of results.entries()) {
39
39
  const [tableRef] = entries[i];
40
- if (result.status === "fulfilled") codeSystems.set(tableRef, result.value);
41
- else if (!(result.reason instanceof Error) || !result.reason.message.startsWith("Unknown ")) {
40
+ if (result.status === "rejected") {
42
41
  const msg = file.message(`Failed to load code system for table '${tableRef}'`);
43
42
  msg.source = "hl7v2-annotate-profile-fields-code-systems";
44
43
  msg.cause = result.reason;
45
- }
44
+ } else if (result.value) codeSystems.set(tableRef, result.value);
46
45
  }
47
46
  visit(tree, isCodedField, (node) => {
48
47
  const table = node.data.table;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Field, Nodes, Root } from \"@glion/ast\";\nimport type { CodeSystemDefinition } from \"@glion/profiles\";\nimport { profiles } from \"@glion/profiles\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { VFile } from \"vfile\";\n\n/** Visit predicate: only visit field nodes that have a table reference. */\nfunction isCodedField(node: Nodes): node is Field {\n return (\n node.type === \"field\" &&\n typeof (node.data as Record<string, unknown> | undefined)?.table ===\n \"string\"\n );\n}\n\ndeclare module \"@glion/ast\" {\n interface FieldData {\n /** Resolved UTG code system identity for this field's table reference. */\n codeSystem?: { id: string; name: string; title: string } | undefined;\n }\n interface FieldRepetitionData {\n /** Resolved code entry for this repetition's primary value. */\n code?: { value: string; display: string; status: string } | undefined;\n }\n}\n\n/**\n * Convert a field profile table reference to a UTG code system ID.\n * Field profiles use \"HL70001\"; UTG code systems use \"v2-0001\".\n */\nfunction tableIdToCodeSystemId(tableRef: string): string {\n return `v2-${tableRef.replace(/^HL7/, \"\")}`;\n}\n\n/**\n * Unified plugin that annotates coded fields with their resolved UTG\n * code system identity (on the field) and the display/status of each\n * repetition's primary value (on the field-repetition).\n *\n * Per the HL7v2 spec, when a field has a table binding and a composite\n * datatype (CWE/CNE), the table constrains CWE.1 — the first component's\n * first subcomponent. This plugin reads that value from each repetition,\n * resolves it against the UTG code system, and attaches:\n * - `field.data.codeSystem` — code system identity (same for all reps)\n * - `rep.data.code` — resolved value entry (different per rep)\n *\n * Requires the fields annotator to run first (preset guarantees ordering).\n */\nexport const hl7v2AnnotateProfileFieldsCodeSystems: Plugin<[], Root, Root> =\n () => async (tree: Root, file: VFile) => {\n // Collect table references from field.data.table (set by fields annotator)\n const tableRefs = new Set<string>();\n visit(tree, isCodedField, (node) => {\n tableRefs.add((node.data as Record<string, unknown>).table as string);\n });\n\n // Resolve UTG code systems in parallel\n const codeSystems = new Map<string, CodeSystemDefinition>();\n const entries = [...tableRefs].map(\n (ref) => [ref, tableIdToCodeSystemId(ref)] as const\n );\n const results = await Promise.allSettled(\n entries.map(([, csId]) => profiles.codeSystems.load(csId))\n );\n\n for (let i = 0; i < results.length; i++) {\n const result = results[i]!;\n const [tableRef] = entries[i]!;\n if (result.status === \"fulfilled\") {\n codeSystems.set(tableRef, result.value);\n } else if (\n !(result.reason instanceof Error) ||\n !result.reason.message.startsWith(\"Unknown \")\n ) {\n const msg = file.message(\n `Failed to load code system for table '${tableRef}'`\n );\n msg.source = \"hl7v2-annotate-profile-fields-code-systems\";\n msg.cause = result.reason;\n }\n }\n\n // Annotate: codeSystem on field, resolved code on each repetition\n visit(tree, isCodedField, (node) => {\n const table = (node.data as Record<string, unknown>).table as string;\n const csDef = codeSystems.get(table);\n if (!csDef) {\n return SKIP;\n }\n\n // Code system identity on the field (same for all repetitions)\n (node.data as Record<string, unknown>).codeSystem = {\n id: csDef.id,\n name: csDef.name,\n title: csDef.title,\n };\n\n // Resolved value on each repetition\n for (const rep of node.children) {\n const primaryValue = rep.children[0]?.children[0]?.value;\n if (!primaryValue) {\n continue;\n }\n\n const entry = csDef.codes.get(primaryValue);\n if (!entry) {\n continue;\n }\n\n if (!rep.data) {\n rep.data = {};\n }\n rep.data.code = {\n display: entry.display,\n status: entry.status,\n value: primaryValue,\n };\n }\n\n return SKIP;\n });\n\n return tree;\n };\n\nexport default hl7v2AnnotateProfileFieldsCodeSystems;\n"],"mappings":";;;;AAQA,SAAS,aAAa,MAA4B;AAChD,QACE,KAAK,SAAS,WACd,OAAQ,KAAK,MAA8C,UACz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KACP,KAAI,OAAO,EAAE;AAEf,OAAI,KAAK,OAAO;IACd,SAAS,MAAM;IACf,QAAQ,MAAM;IACd,OAAO;IACR;;AAGH,SAAO;GACP;AAEF,QAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Field, Nodes, Root } from \"@glion/ast\";\nimport type { CodeSystemDefinition } from \"@glion/profiles\";\nimport { profiles } from \"@glion/profiles\";\nimport { SKIP, visit } from \"@glion/util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { VFile } from \"vfile\";\n\n/** Visit predicate: only visit field nodes that have a table reference. */\nfunction isCodedField(node: Nodes): node is Field {\n return (\n node.type === \"field\" &&\n typeof (node.data as Record<string, unknown> | undefined)?.table ===\n \"string\"\n );\n}\n\ndeclare module \"@glion/ast\" {\n interface FieldData {\n /** Resolved UTG code system identity for this field's table reference. */\n codeSystem?: { id: string; name: string; title: string } | undefined;\n }\n interface FieldRepetitionData {\n /** Resolved code entry for this repetition's primary value. */\n code?: { value: string; display: string; status: string } | undefined;\n }\n}\n\n/**\n * Convert a field profile table reference to a UTG code system ID.\n * Field profiles use \"HL70001\"; UTG code systems use \"v2-0001\".\n */\nfunction tableIdToCodeSystemId(tableRef: string): string {\n return `v2-${tableRef.replace(/^HL7/, \"\")}`;\n}\n\n/**\n * Unified plugin that annotates coded fields with their resolved UTG\n * code system identity (on the field) and the display/status of each\n * repetition's primary value (on the field-repetition).\n *\n * Per the HL7v2 spec, when a field has a table binding and a composite\n * datatype (CWE/CNE), the table constrains CWE.1 — the first component's\n * first subcomponent. This plugin reads that value from each repetition,\n * resolves it against the UTG code system, and attaches:\n *\n * - `field.data.codeSystem` — code system identity (same for all reps)\n * - `rep.data.code` — resolved value entry (different per rep)\n *\n * Requires the fields annotator to run first (preset guarantees ordering).\n */\nexport const hl7v2AnnotateProfileFieldsCodeSystems: Plugin<[], Root, Root> =\n () => async (tree: Root, file: VFile) => {\n // Collect table references from field.data.table (set by fields annotator)\n const tableRefs = new Set<string>();\n visit(tree, isCodedField, (node) => {\n tableRefs.add((node.data as Record<string, unknown>).table as string);\n });\n\n // Resolve UTG code systems in parallel\n const codeSystems = new Map<string, CodeSystemDefinition>();\n const entries = [...tableRefs].map(\n (ref) => [ref, tableIdToCodeSystemId(ref)] as const\n );\n const results = await Promise.allSettled(\n entries.map(([, csId]) => profiles.codeSystems.load(csId))\n );\n\n for (const [i, result] of results.entries()) {\n const [tableRef] = entries[i] as (typeof entries)[number];\n if (result.status === \"rejected\") {\n const msg = file.message(\n `Failed to load code system for table '${tableRef}'`\n );\n msg.source = \"hl7v2-annotate-profile-fields-code-systems\";\n msg.cause = result.reason;\n } else if (result.value) {\n codeSystems.set(tableRef, result.value);\n }\n }\n\n // Annotate: codeSystem on field, resolved code on each repetition\n visit(tree, isCodedField, (node) => {\n const table = (node.data as Record<string, unknown>).table as string;\n const csDef = codeSystems.get(table);\n if (!csDef) {\n return SKIP;\n }\n\n // Code system identity on the field (same for all repetitions)\n (node.data as Record<string, unknown>).codeSystem = {\n id: csDef.id,\n name: csDef.name,\n title: csDef.title,\n };\n\n // Resolved value on each repetition\n for (const rep of node.children) {\n const primaryValue = rep.children[0]?.children[0]?.value;\n if (!primaryValue) {\n continue;\n }\n\n const entry = csDef.codes.get(primaryValue);\n if (!entry) {\n continue;\n }\n\n if (!rep.data) {\n rep.data = {};\n }\n rep.data.code = {\n display: entry.display,\n status: entry.status,\n value: primaryValue,\n };\n }\n\n return SKIP;\n });\n\n return tree;\n };\n\nexport default hl7v2AnnotateProfileFieldsCodeSystems;\n"],"mappings":";;;;AAQA,SAAS,aAAa,MAA4B;AAChD,QACE,KAAK,SAAS,WACd,OAAQ,KAAK,MAA8C,UACzD;;;;;;AAmBN,SAAS,sBAAsB,UAA0B;AACvD,QAAO,MAAM,SAAS,QAAQ,QAAQ,GAAG;;;;;;;;;;;;;;;;;AAkB3C,MAAa,8CACL,OAAO,MAAY,SAAgB;CAEvC,MAAM,4BAAY,IAAI,KAAa;AACnC,OAAM,MAAM,eAAe,SAAS;AAClC,YAAU,IAAK,KAAK,KAAiC,MAAgB;GACrE;CAGF,MAAM,8BAAc,IAAI,KAAmC;CAC3D,MAAM,UAAU,CAAC,GAAG,UAAU,CAAC,KAC5B,QAAQ,CAAC,KAAK,sBAAsB,IAAI,CAAC,CAC3C;CACD,MAAM,UAAU,MAAM,QAAQ,WAC5B,QAAQ,KAAK,GAAG,UAAU,SAAS,YAAY,KAAK,KAAK,CAAC,CAC3D;AAED,MAAK,MAAM,CAAC,GAAG,WAAW,QAAQ,SAAS,EAAE;EAC3C,MAAM,CAAC,YAAY,QAAQ;AAC3B,MAAI,OAAO,WAAW,YAAY;GAChC,MAAM,MAAM,KAAK,QACf,yCAAyC,SAAS,GACnD;AACD,OAAI,SAAS;AACb,OAAI,QAAQ,OAAO;aACV,OAAO,MAChB,aAAY,IAAI,UAAU,OAAO,MAAM;;AAK3C,OAAM,MAAM,eAAe,SAAS;EAClC,MAAM,QAAS,KAAK,KAAiC;EACrD,MAAM,QAAQ,YAAY,IAAI,MAAM;AACpC,MAAI,CAAC,MACH,QAAO;AAIR,OAAK,KAAiC,aAAa;GAClD,IAAI,MAAM;GACV,MAAM,MAAM;GACZ,OAAO,MAAM;GACd;AAGD,OAAK,MAAM,OAAO,KAAK,UAAU;GAC/B,MAAM,eAAe,IAAI,SAAS,IAAI,SAAS,IAAI;AACnD,OAAI,CAAC,aACH;GAGF,MAAM,QAAQ,MAAM,MAAM,IAAI,aAAa;AAC3C,OAAI,CAAC,MACH;AAGF,OAAI,CAAC,IAAI,KACP,KAAI,OAAO,EAAE;AAEf,OAAI,KAAK,OAAO;IACd,SAAS,MAAM;IACf,QAAQ,MAAM;IACd,OAAO;IACR;;AAGH,SAAO;GACP;AAEF,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glion/annotate-profile-fields-code-systems",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "Unified plugin to annotate HL7v2 field-level coded values with UTG code system metadata",
5
5
  "keywords": [
6
6
  "annotate",
@@ -41,9 +41,9 @@
41
41
  "dependencies": {
42
42
  "unified": "11.0.5",
43
43
  "vfile": "6.0.3",
44
- "@glion/ast": "0.20.0",
45
- "@glion/profiles": "0.20.0",
46
- "@glion/util-visit": "0.20.0"
44
+ "@glion/ast": "0.22.0",
45
+ "@glion/profiles": "0.22.0",
46
+ "@glion/util-visit": "0.22.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "25.6.0",
@@ -52,9 +52,9 @@
52
52
  "tsdown": "0.21.10",
53
53
  "typescript": "6.0.3",
54
54
  "vitest": "4.1.11",
55
- "@glion/annotate-profile-context": "0.20.0",
56
- "@glion/annotate-profile-fields": "0.20.0",
57
- "@glion/builder": "0.20.0",
55
+ "@glion/annotate-profile-context": "0.22.0",
56
+ "@glion/annotate-profile-fields": "0.22.0",
57
+ "@glion/builder": "0.22.0",
58
58
  "@glion/check-readme": "0.18.0",
59
59
  "@glion/testing": "0.18.0",
60
60
  "@glion/tsconfig": "0.18.0"