@rethinkhealth/hl7v2-jsonify 0.2.2 → 0.2.3
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.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAStD,CAAC;AAEF,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAStD,CAAC;AAEF,wBAAgB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,EAAE,CA+BrD"}
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ function toJson(root) {
|
|
|
22
22
|
if (typeof n.index !== "number") {
|
|
23
23
|
throw new Error("HL7 AST node is missing a numeric index");
|
|
24
24
|
}
|
|
25
|
-
return n.index - 1;
|
|
25
|
+
return n.type === "field" ? n.index - 1 : n.index;
|
|
26
26
|
});
|
|
27
27
|
setNestedArrayValue(currentSegment.fields, path, node.value);
|
|
28
28
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { HL7v2Node } from '@rethinkhealth/hl7v2-ast';\nimport type { Plugin } from 'unified';\nimport type { Node } from 'unist';\nimport { visitParents } from 'unist-util-visit-parents';\n\ntype SegmentJSON = {\n segment: string;\n fields: (string | string[])[]; // Nested arrays for fields/repetitions/components\n};\n\nexport const hl7v2Jsonify: Plugin<[], HL7v2Node, string> = function (): void {\n // biome-ignore lint/complexity/noUselessThisAlias: this is a plugin\n const self = this;\n\n function compiler(tree: Node): string {\n return JSON.stringify(toJson(tree as HL7v2Node), null, 2);\n }\n\n self.compiler = compiler;\n};\n\nexport function toJson(root: HL7v2Node): SegmentJSON[] {\n const segments: SegmentJSON[] = [];\n let currentSegment: SegmentJSON | null = null;\n\n visitParents<HL7v2Node, HL7v2Node>(root, (node, ancestors) => {\n if (node.type === 'segment') {\n currentSegment = { segment: node.name || 'UNKNOWN', fields: [] };\n segments.push(currentSegment);\n }\n\n if (node.value !== undefined && currentSegment) {\n // Build numeric path for all indices except segment/root\n const path = [...ancestors, node]\n .filter(\n (n) =>\n n.index !== undefined && n.type !== 'segment' && n.type !== 'root'\n )\n .map((n) => {\n if (typeof n.index !== 'number') {\n throw new Error('HL7 AST node is missing a numeric index');\n }\n return n.index - 1;\n });\n\n setNestedArrayValue(currentSegment.fields, path, node.value);\n }\n });\n\n return segments;\n}\n\n/**\n * Recursively create nested arrays along the path and set the value.\n */\nfunction setNestedArrayValue(\n arr: (string | string[])[],\n path: number[],\n value: string\n) {\n let current: (string | string[])[] = arr;\n for (let i = 0; i < path.length - 1; i++) {\n const idx = path[i];\n\n if (idx === undefined) {\n return;\n }\n\n if (!current[idx]) {\n current[idx] = [];\n }\n current = current[idx] as (string | string[])[];\n }\n\n const lastKey = path.at(-1);\n if (lastKey === undefined) {\n return;\n }\n\n current[lastKey] = value;\n}\n"],"mappings":";AAGA,SAAS,oBAAoB;AAOtB,IAAM,eAA8C,WAAkB;AAE3E,QAAM,OAAO;AAEb,WAAS,SAAS,MAAoB;AACpC,WAAO,KAAK,UAAU,OAAO,IAAiB,GAAG,MAAM,CAAC;AAAA,EAC1D;AAEA,OAAK,WAAW;AAClB;AAEO,SAAS,OAAO,MAAgC;AACrD,QAAM,WAA0B,CAAC;AACjC,MAAI,iBAAqC;AAEzC,eAAmC,MAAM,CAAC,MAAM,cAAc;AAC5D,QAAI,KAAK,SAAS,WAAW;AAC3B,uBAAiB,EAAE,SAAS,KAAK,QAAQ,WAAW,QAAQ,CAAC,EAAE;AAC/D,eAAS,KAAK,cAAc;AAAA,IAC9B;AAEA,QAAI,KAAK,UAAU,UAAa,gBAAgB;AAE9C,YAAM,OAAO,CAAC,GAAG,WAAW,IAAI,EAC7B;AAAA,QACC,CAAC,MACC,EAAE,UAAU,UAAa,EAAE,SAAS,aAAa,EAAE,SAAS;AAAA,MAChE,EACC,IAAI,CAAC,MAAM;AACV,YAAI,OAAO,EAAE,UAAU,UAAU;AAC/B,gBAAM,IAAI,MAAM,yCAAyC;AAAA,QAC3D;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { HL7v2Node } from '@rethinkhealth/hl7v2-ast';\nimport type { Plugin } from 'unified';\nimport type { Node } from 'unist';\nimport { visitParents } from 'unist-util-visit-parents';\n\ntype SegmentJSON = {\n segment: string;\n fields: (string | string[])[]; // Nested arrays for fields/repetitions/components\n};\n\nexport const hl7v2Jsonify: Plugin<[], HL7v2Node, string> = function (): void {\n // biome-ignore lint/complexity/noUselessThisAlias: this is a plugin\n const self = this;\n\n function compiler(tree: Node): string {\n return JSON.stringify(toJson(tree as HL7v2Node), null, 2);\n }\n\n self.compiler = compiler;\n};\n\nexport function toJson(root: HL7v2Node): SegmentJSON[] {\n const segments: SegmentJSON[] = [];\n let currentSegment: SegmentJSON | null = null;\n\n visitParents<HL7v2Node, HL7v2Node>(root, (node, ancestors) => {\n if (node.type === 'segment') {\n currentSegment = { segment: node.name || 'UNKNOWN', fields: [] };\n segments.push(currentSegment);\n }\n\n if (node.value !== undefined && currentSegment) {\n // Build numeric path for all indices except segment/root\n const path = [...ancestors, node]\n .filter(\n (n) =>\n n.index !== undefined && n.type !== 'segment' && n.type !== 'root'\n )\n .map((n) => {\n if (typeof n.index !== 'number') {\n throw new Error('HL7 AST node is missing a numeric index');\n }\n // Fields: subtract 1 to skip header (index 0) and convert to 0-based array indices\n // Components/subcomponents: use index as-is (no header to skip)\n return n.type === 'field' ? n.index - 1 : n.index;\n });\n\n setNestedArrayValue(currentSegment.fields, path, node.value);\n }\n });\n\n return segments;\n}\n\n/**\n * Recursively create nested arrays along the path and set the value.\n */\nfunction setNestedArrayValue(\n arr: (string | string[])[],\n path: number[],\n value: string\n) {\n let current: (string | string[])[] = arr;\n for (let i = 0; i < path.length - 1; i++) {\n const idx = path[i];\n\n if (idx === undefined) {\n return;\n }\n\n if (!current[idx]) {\n current[idx] = [];\n }\n current = current[idx] as (string | string[])[];\n }\n\n const lastKey = path.at(-1);\n if (lastKey === undefined) {\n return;\n }\n\n current[lastKey] = value;\n}\n"],"mappings":";AAGA,SAAS,oBAAoB;AAOtB,IAAM,eAA8C,WAAkB;AAE3E,QAAM,OAAO;AAEb,WAAS,SAAS,MAAoB;AACpC,WAAO,KAAK,UAAU,OAAO,IAAiB,GAAG,MAAM,CAAC;AAAA,EAC1D;AAEA,OAAK,WAAW;AAClB;AAEO,SAAS,OAAO,MAAgC;AACrD,QAAM,WAA0B,CAAC;AACjC,MAAI,iBAAqC;AAEzC,eAAmC,MAAM,CAAC,MAAM,cAAc;AAC5D,QAAI,KAAK,SAAS,WAAW;AAC3B,uBAAiB,EAAE,SAAS,KAAK,QAAQ,WAAW,QAAQ,CAAC,EAAE;AAC/D,eAAS,KAAK,cAAc;AAAA,IAC9B;AAEA,QAAI,KAAK,UAAU,UAAa,gBAAgB;AAE9C,YAAM,OAAO,CAAC,GAAG,WAAW,IAAI,EAC7B;AAAA,QACC,CAAC,MACC,EAAE,UAAU,UAAa,EAAE,SAAS,aAAa,EAAE,SAAS;AAAA,MAChE,EACC,IAAI,CAAC,MAAM;AACV,YAAI,OAAO,EAAE,UAAU,UAAU;AAC/B,gBAAM,IAAI,MAAM,yCAAyC;AAAA,QAC3D;AAGA,eAAO,EAAE,SAAS,UAAU,EAAE,QAAQ,IAAI,EAAE;AAAA,MAC9C,CAAC;AAEH,0BAAoB,eAAe,QAAQ,MAAM,KAAK,KAAK;AAAA,IAC7D;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAKA,SAAS,oBACP,KACA,MACA,OACA;AACA,MAAI,UAAiC;AACrC,WAAS,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;AACxC,UAAM,MAAM,KAAK,CAAC;AAElB,QAAI,QAAQ,QAAW;AACrB;AAAA,IACF;AAEA,QAAI,CAAC,QAAQ,GAAG,GAAG;AACjB,cAAQ,GAAG,IAAI,CAAC;AAAA,IAClB;AACA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,QAAM,UAAU,KAAK,GAAG,EAAE;AAC1B,MAAI,YAAY,QAAW;AACzB;AAAA,EACF;AAEA,UAAQ,OAAO,IAAI;AACrB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rethinkhealth/hl7v2-jsonify",
|
|
3
3
|
"description": "hl7v2 plugin to transform hl7v2 messages to a simplified JSON representation",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Melek Somai",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"tsup": "8.5.0",
|
|
29
29
|
"typescript": "^5.8.3",
|
|
30
30
|
"vitest": "^3.2.4",
|
|
31
|
-
"@rethinkhealth/
|
|
32
|
-
"@rethinkhealth/
|
|
33
|
-
"@rethinkhealth/
|
|
31
|
+
"@rethinkhealth/hl7v2-ast": "0.2.3",
|
|
32
|
+
"@rethinkhealth/tsconfig": "0.0.0",
|
|
33
|
+
"@rethinkhealth/testing": "0.0.0"
|
|
34
34
|
},
|
|
35
35
|
"repository": "rethinkhealth/hl7v2.git",
|
|
36
36
|
"homepage": "https://www.rethinkhealth.io/hl7v2/docs",
|