@glion/annotate-profile-fields-code-systems 0.25.0 → 0.26.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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Unified plugin to annotate HL7v2 field-level coded values with UTG code system metadata.
4
4
 
5
+ > **Experimental.** The annotations this plugin writes may change in any release. It is not part of `@glion/preset-annotate-profile-recommended`, which runs [`@glion/annotate-profile-tables`](../annotate-profile-tables) instead.
6
+
5
7
  ## What it does
6
8
 
7
9
  Fields bound to HL7v2 tables (such as PID-8 `Administrative Sex` bound to table `0001`, or MSH-11.1 `Processing ID` bound to table `0103`) carry coded values that expand into human-readable displays and lifecycle statuses. This plugin resolves each field's table reference against the UTG code system registry in `@glion/profiles`, then writes the code system identity onto the field and the resolved value entry onto each repetition. It requires `@glion/annotate-profile-fields` to run first so that `field.data.table` is populated.
package/dist/index.d.ts CHANGED
@@ -31,7 +31,9 @@ declare module "@glion/ast" {
31
31
  * - `field.data.codeSystem` — code system identity (same for all reps)
32
32
  * - `rep.data.code` — resolved value entry (different per rep)
33
33
  *
34
- * Requires the fields annotator to run first (preset guarantees ordering).
34
+ * Requires the fields annotator to run first.
35
+ *
36
+ * Experimental: its output may change in any release.
35
37
  */
36
38
  export declare const hl7v2AnnotateProfileFieldsCodeSystems: Plugin<[], Root, Root>;
37
39
  export default hl7v2AnnotateProfileFieldsCodeSystems;
@@ -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;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qCAAqC,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAuEtE,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;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qCAAqC,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAuEtE,CAAC;AAEJ,eAAe,qCAAqC,CAAC"}
package/dist/index.js CHANGED
@@ -25,7 +25,9 @@ function tableIdToCodeSystemId(tableRef) {
25
25
  * - `field.data.codeSystem` — code system identity (same for all reps)
26
26
  * - `rep.data.code` — resolved value entry (different per rep)
27
27
  *
28
- * Requires the fields annotator to run first (preset guarantees ordering).
28
+ * Requires the fields annotator to run first.
29
+ *
30
+ * Experimental: its output may change in any release.
29
31
  */
30
32
  const hl7v2AnnotateProfileFieldsCodeSystems = () => async (tree, file) => {
31
33
  const tableRefs = /* @__PURE__ */ new Set();
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 *\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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,"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.\n *\n * Experimental: its output may change in any release.\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;;;;;;;;;;;;;;;;;;;AAoB3C,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,7 +1,7 @@
1
1
  {
2
2
  "name": "@glion/annotate-profile-fields-code-systems",
3
- "version": "0.25.0",
4
- "description": "Unified plugin to annotate HL7v2 field-level coded values with UTG code system metadata",
3
+ "version": "0.26.0",
4
+ "description": "Experimental unified plugin to annotate HL7v2 field-level coded values with UTG code system metadata",
5
5
  "keywords": [
6
6
  "annotate",
7
7
  "code-system",
@@ -41,9 +41,9 @@
41
41
  "dependencies": {
42
42
  "unified": "11.0.5",
43
43
  "vfile": "6.0.3",
44
- "@glion/ast": "0.25.0",
45
- "@glion/profiles": "0.25.0",
46
- "@glion/util-visit": "0.25.0"
44
+ "@glion/ast": "0.26.0",
45
+ "@glion/profiles": "0.26.0",
46
+ "@glion/util-visit": "0.26.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.25.0",
56
- "@glion/builder": "0.25.0",
57
- "@glion/annotate-profile-fields": "0.25.0",
55
+ "@glion/annotate-profile-context": "0.26.0",
56
+ "@glion/annotate-profile-fields": "0.26.0",
57
+ "@glion/builder": "0.26.0",
58
58
  "@glion/check-readme": "0.18.0",
59
59
  "@glion/testing": "0.18.0",
60
60
  "@glion/tsconfig": "0.18.0"