@rethinkhealth/hl7v2-jsonify 0.2.15 → 0.2.17
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 +4 -4
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { Nodes, Root } from
|
|
2
|
-
import type { Plugin } from
|
|
1
|
+
import type { Nodes, Root } from "@rethinkhealth/hl7v2-ast";
|
|
2
|
+
import type { Plugin } from "unified";
|
|
3
3
|
type FieldValue = string | string[];
|
|
4
|
-
type
|
|
4
|
+
type SegmentJson = {
|
|
5
5
|
segment: string;
|
|
6
6
|
fields: (FieldValue | FieldValue[])[];
|
|
7
7
|
};
|
|
8
8
|
export declare const hl7v2Jsonify: Plugin<[], Root, string>;
|
|
9
|
-
export declare function toJson(root: Nodes):
|
|
9
|
+
export declare function toJson(root: Nodes): SegmentJson[];
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -53,9 +53,7 @@ function materializeField(field) {
|
|
|
53
53
|
}
|
|
54
54
|
return c.children.map((sc) => sc.value);
|
|
55
55
|
};
|
|
56
|
-
const toRepetitionArray = (r) =>
|
|
57
|
-
return r.children.map((c) => toComponent(c));
|
|
58
|
-
};
|
|
56
|
+
const toRepetitionArray = (r) => r.children.map((c) => toComponent(c));
|
|
59
57
|
const repetitions = field.children;
|
|
60
58
|
if (repetitions.length === 1) {
|
|
61
59
|
const rep = repetitions[0];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Component,\n Field,\n FieldRepetition,\n Nodes,\n Root,\n Segment,\n Subcomponent,\n} from
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Component,\n Field,\n FieldRepetition,\n Nodes,\n Root,\n Segment,\n Subcomponent,\n} from \"@rethinkhealth/hl7v2-ast\";\nimport type { Plugin } from \"unified\";\nimport type { Node } from \"unist\";\n\ntype FieldValue = string | string[];\n\ntype SegmentJson = {\n segment: string;\n fields: (FieldValue | FieldValue[])[]; // Nested arrays for fields/repetitions/components\n};\n\nexport const hl7v2Jsonify: Plugin<[], Root, 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 Nodes), null, 2);\n }\n\n self.compiler = compiler;\n};\n\nexport function toJson(root: Nodes): SegmentJson[] {\n const r = root as Root;\n const out: SegmentJson[] = [];\n\n for (const s of r.children as Segment[]) {\n const segmentName = getSegmentName(s);\n const fields: (FieldValue | FieldValue[])[] = [];\n\n // Skip the header field (index 0) when projecting to fields\n for (let i = 1; i < s.children.length; i++) {\n const f = s.children[i] as Field;\n fields.push(materializeField(f));\n }\n\n out.push({ segment: segmentName, fields });\n }\n\n return out;\n}\n\n// Extract segment name from the first field's first component's first subcomponent\nfunction getSegmentName(segment: Segment): string {\n try {\n // Navigate: segment -> field[0] -> fieldRepetition[0] -> component[0] -> subcomponent[0]\n const firstField = segment.children[0] as Field | undefined;\n if (!firstField) {\n return \"UNKNOWN\";\n }\n\n const firstRepetition = firstField.children[0] as\n | FieldRepetition\n | undefined;\n if (!firstRepetition) {\n return \"UNKNOWN\";\n }\n\n const firstComponent = firstRepetition.children[0] as Component | undefined;\n if (!firstComponent) {\n return \"UNKNOWN\";\n }\n\n const firstSubcomponent = firstComponent.children[0] as\n | Subcomponent\n | undefined;\n if (!firstSubcomponent) {\n return \"UNKNOWN\";\n }\n\n return firstSubcomponent.value || \"UNKNOWN\";\n } catch {\n return \"UNKNOWN\";\n }\n}\n\n// Convert a Field into JSON-friendly value: string or nested arrays representing reps/components/subcomponents\nfunction materializeField(field: Field): FieldValue | FieldValue[] {\n const toComponent = (c: Component): FieldValue => {\n if (c.children.length === 0) {\n return \"\";\n }\n if (c.children.length === 1) {\n return (c.children[0] as Subcomponent).value;\n }\n return c.children.map((sc) => (sc as Subcomponent).value);\n };\n\n const toRepetitionArray = (r: FieldRepetition): FieldValue[] =>\n r.children.map((c) => toComponent(c as Component));\n\n const repetitions = field.children as FieldRepetition[];\n\n if (repetitions.length === 1) {\n const rep = repetitions[0];\n\n if (!rep) {\n throw new Error(\"Expected a field repetition\");\n }\n\n if (rep.children.length === 1) {\n const comp = rep.children[0] as Component;\n const compVal = toComponent(comp);\n\n return Array.isArray(compVal) ? [compVal] : compVal;\n }\n return toRepetitionArray(rep);\n }\n\n // Multiple repetitions: project each repetition to a value (string or array)\n return repetitions.map((r) => {\n const rep = r as FieldRepetition;\n if (rep.children.length === 1) {\n return toComponent(rep.children[0] as Component);\n }\n return toRepetitionArray(rep);\n }) as string[];\n}\n"],"mappings":";AAmBO,IAAM,eAAyC,WAAkB;AAEtE,QAAM,OAAO;AAEb,WAAS,SAAS,MAAoB;AACpC,WAAO,KAAK,UAAU,OAAO,IAAa,GAAG,MAAM,CAAC;AAAA,EACtD;AAEA,OAAK,WAAW;AAClB;AAEO,SAAS,OAAO,MAA4B;AACjD,QAAM,IAAI;AACV,QAAM,MAAqB,CAAC;AAE5B,aAAW,KAAK,EAAE,UAAuB;AACvC,UAAM,cAAc,eAAe,CAAC;AACpC,UAAM,SAAwC,CAAC;AAG/C,aAAS,IAAI,GAAG,IAAI,EAAE,SAAS,QAAQ,KAAK;AAC1C,YAAM,IAAI,EAAE,SAAS,CAAC;AACtB,aAAO,KAAK,iBAAiB,CAAC,CAAC;AAAA,IACjC;AAEA,QAAI,KAAK,EAAE,SAAS,aAAa,OAAO,CAAC;AAAA,EAC3C;AAEA,SAAO;AACT;AAGA,SAAS,eAAe,SAA0B;AAChD,MAAI;AAEF,UAAM,aAAa,QAAQ,SAAS,CAAC;AACrC,QAAI,CAAC,YAAY;AACf,aAAO;AAAA,IACT;AAEA,UAAM,kBAAk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,CAAC;AACH;","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.17",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Melek Somai",
|
|
@@ -21,14 +21,13 @@
|
|
|
21
21
|
"unist-util-visit-parents": "6.0.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/node": "24.
|
|
24
|
+
"@types/node": "24.5.2",
|
|
25
25
|
"@types/unist": "^3.0.3",
|
|
26
|
-
"@vitest/coverage-c8": "^0.33.0",
|
|
27
26
|
"@vitest/coverage-v8": "^3.2.4",
|
|
28
27
|
"tsup": "8.5.0",
|
|
29
28
|
"typescript": "^5.8.3",
|
|
30
29
|
"vitest": "^3.2.4",
|
|
31
|
-
"@rethinkhealth/hl7v2-ast": "0.2.
|
|
30
|
+
"@rethinkhealth/hl7v2-ast": "0.2.17",
|
|
32
31
|
"@rethinkhealth/testing": "0.0.1",
|
|
33
32
|
"@rethinkhealth/tsconfig": "0.0.1"
|
|
34
33
|
},
|