@rethinkhealth/hl7v2-jsonify 0.2.22 → 0.2.24
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 +3 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -16
- package/dist/index.js.map +1 -1
- package/dist/processor.d.ts +3 -0
- package/dist/processor.d.ts.map +1 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +8 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
type SegmentJson = {
|
|
5
|
-
segment: string;
|
|
6
|
-
fields: (FieldValue | FieldValue[])[];
|
|
7
|
-
};
|
|
8
|
-
export declare const hl7v2Jsonify: Plugin<[], Root, string>;
|
|
9
|
-
export declare function toJson(root: Nodes): SegmentJson[];
|
|
10
|
-
export {};
|
|
1
|
+
export { hl7v2Jsonify } from "./processor";
|
|
2
|
+
export { toJsonRuntime } from "./runtime";
|
|
3
|
+
export type { FieldJson, GroupJson, Hl7v2JsonResult, SegmentJson, } from "./types";
|
|
11
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,YAAY,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
const self = this;
|
|
4
|
-
function compiler(tree) {
|
|
5
|
-
return JSON.stringify(toJson(tree), null, 2);
|
|
6
|
-
}
|
|
7
|
-
self.compiler = compiler;
|
|
8
|
-
};
|
|
9
|
-
function toJson(root) {
|
|
1
|
+
// src/runtime.ts
|
|
2
|
+
function toJsonRuntime(root) {
|
|
10
3
|
const r = root;
|
|
11
4
|
const out = [];
|
|
12
|
-
for (const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
for (const child of r.children) {
|
|
6
|
+
if (child.type === "segment") {
|
|
7
|
+
out.push(processSegment(child));
|
|
8
|
+
} else if (child.type === "group") {
|
|
9
|
+
out.push(processGroup(child));
|
|
17
10
|
}
|
|
18
|
-
out.push({ segment: segmentName, fields });
|
|
19
11
|
}
|
|
20
12
|
return out;
|
|
21
13
|
}
|
|
14
|
+
function processSegment(segment) {
|
|
15
|
+
const segmentName = segment.children[0].value;
|
|
16
|
+
const fields = [];
|
|
17
|
+
for (const f of segment.children.slice(1)) {
|
|
18
|
+
fields.push(materializeField(f));
|
|
19
|
+
}
|
|
20
|
+
return { segment: segmentName, fields };
|
|
21
|
+
}
|
|
22
|
+
function processGroup(group) {
|
|
23
|
+
const children = [];
|
|
24
|
+
for (const child of group.children) {
|
|
25
|
+
if (child.type === "segment") {
|
|
26
|
+
children.push(processSegment(child));
|
|
27
|
+
} else if (child.type === "group") {
|
|
28
|
+
children.push(processGroup(child));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { group: group.name ?? "", children };
|
|
32
|
+
}
|
|
22
33
|
function materializeField(field) {
|
|
23
34
|
const toComponent = (c) => {
|
|
24
35
|
if (c.children?.length === 0) {
|
|
@@ -51,8 +62,17 @@ function materializeField(field) {
|
|
|
51
62
|
return toRepetitionArray(rep);
|
|
52
63
|
});
|
|
53
64
|
}
|
|
65
|
+
|
|
66
|
+
// src/processor.ts
|
|
67
|
+
function hl7v2Jsonify() {
|
|
68
|
+
const self = this;
|
|
69
|
+
function compiler(tree) {
|
|
70
|
+
return toJsonRuntime(tree);
|
|
71
|
+
}
|
|
72
|
+
self.compiler = compiler;
|
|
73
|
+
}
|
|
54
74
|
export {
|
|
55
75
|
hl7v2Jsonify,
|
|
56
|
-
|
|
76
|
+
toJsonRuntime
|
|
57
77
|
};
|
|
58
78
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/runtime.ts","../src/processor.ts"],"sourcesContent":["import type {\n Component,\n Field,\n FieldRepetition,\n Group,\n Nodes,\n Root,\n Segment,\n Subcomponent,\n} from \"@rethinkhealth/hl7v2-ast\";\nimport type {\n FieldJson,\n GroupJson,\n Hl7v2JsonResult,\n SegmentJson,\n} from \"./types\";\n\nexport function toJsonRuntime(root: Nodes): Hl7v2JsonResult {\n const r = root as Root;\n const out: Hl7v2JsonResult = [];\n\n for (const child of r.children) {\n if (child.type === \"segment\") {\n out.push(processSegment(child as Segment));\n } else if (child.type === \"group\") {\n out.push(processGroup(child as Group));\n }\n }\n\n return out;\n}\n\nfunction processSegment(segment: Segment): SegmentJson {\n const segmentName = segment.children[0].value;\n const fields: (FieldJson | FieldJson[])[] = [];\n\n // Skip the header field (index 0) when projecting to fields\n for (const f of segment.children.slice(1) as Field[]) {\n fields.push(materializeField(f));\n }\n\n return { segment: segmentName, fields };\n}\n\nfunction processGroup(group: Group): GroupJson {\n const children: Array<SegmentJson | GroupJson> = [];\n\n for (const child of group.children) {\n if (child.type === \"segment\") {\n children.push(processSegment(child as Segment));\n } else if (child.type === \"group\") {\n children.push(processGroup(child as Group));\n }\n }\n\n return { group: group.name ?? \"\", children };\n}\n\n// Convert a Field into JSON-friendly value: string or nested arrays representing reps/components/subcomponents\nfunction materializeField(field: Field): FieldJson | FieldJson[] {\n const toComponent = (c: Component): FieldJson => {\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 ? c.children.map((sc) => (sc as Subcomponent).value) : [];\n };\n\n const toRepetitionArray = (r: FieldRepetition): FieldJson[] =>\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","import type { Node, Nodes, Root } from \"@rethinkhealth/hl7v2-ast\";\nimport type { Processor } from \"unified\";\nimport { toJsonRuntime } from \"./runtime\";\nimport type { Hl7v2JsonResult } from \"./types\";\n\nexport function hl7v2Jsonify(this: Processor) {\n const self = this as unknown as Processor<\n Node,\n undefined,\n undefined,\n Root,\n undefined\n >;\n\n function compiler(tree: Nodes): Hl7v2JsonResult {\n return toJsonRuntime(tree);\n }\n\n self.compiler = compiler as unknown as typeof self.compiler;\n}\n"],"mappings":";AAiBO,SAAS,cAAc,MAA8B;AAC1D,QAAM,IAAI;AACV,QAAM,MAAuB,CAAC;AAE9B,aAAW,SAAS,EAAE,UAAU;AAC9B,QAAI,MAAM,SAAS,WAAW;AAC5B,UAAI,KAAK,eAAe,KAAgB,CAAC;AAAA,IAC3C,WAAW,MAAM,SAAS,SAAS;AACjC,UAAI,KAAK,aAAa,KAAc,CAAC;AAAA,IACvC;AAAA,EACF;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,SAA+B;AACrD,QAAM,cAAc,QAAQ,SAAS,CAAC,EAAE;AACxC,QA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,IAAI,CAAC,MAAM;AAC5B,UAAM,MAAM;AACZ,QAAI,IAAI,SAAS,WAAW,GAAG;AAC7B,aAAO,YAAY,IAAI,SAAS,CAAC,CAAc;AAAA,IACjD;AACA,WAAO,kBAAkB,GAAG;AAAA,EAC9B,CAAC;AACH;;;AC9FO,SAAS,eAA8B;AAC5C,QAAM,OAAO;AAQb,WAAS,SAAS,MAA8B;AAC9C,WAAO,cAAc,IAAI;AAAA,EAC3B;AAEA,OAAK,WAAW;AAClB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,QAc3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,KAAK,EAIN,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAGV,eAAe,EAEhB,MAAM,SAAS,CAAC;AAEjB,wBAAgB,aAAa,CAAC,IAAI,EAAE,KAAK,GAAG,eAAe,CAa1D"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type FieldJson = string | string[];
|
|
2
|
+
export type SegmentJson = {
|
|
3
|
+
segment: string;
|
|
4
|
+
fields: (FieldJson | FieldJson[])[];
|
|
5
|
+
};
|
|
6
|
+
export type GroupJson = {
|
|
7
|
+
group: string;
|
|
8
|
+
children: Array<SegmentJson | GroupJson>;
|
|
9
|
+
};
|
|
10
|
+
export type Hl7v2JsonResult = Array<SegmentJson | GroupJson>;
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC"}
|
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.24",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Melek Somai",
|
|
@@ -17,20 +17,18 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"unified": "11.0.5",
|
|
20
|
-
"
|
|
21
|
-
"unist-util-visit-parents": "6.0.2"
|
|
20
|
+
"@rethinkhealth/hl7v2-ast": "0.2.24"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
|
-
"@types/node": "24.
|
|
23
|
+
"@types/node": "24.9.2",
|
|
25
24
|
"@types/unist": "^3.0.3",
|
|
26
|
-
"@vitest/coverage-v8": "^
|
|
25
|
+
"@vitest/coverage-v8": "^4.0.5",
|
|
27
26
|
"tsup": "8.5.0",
|
|
28
27
|
"typescript": "^5.9.3",
|
|
29
|
-
"vitest": "^
|
|
30
|
-
"@rethinkhealth/
|
|
31
|
-
"@rethinkhealth/hl7v2-builder": "0.2.
|
|
32
|
-
"@rethinkhealth/tsconfig": "0.0.1"
|
|
33
|
-
"@rethinkhealth/testing": "0.0.1"
|
|
28
|
+
"vitest": "^4.0.6",
|
|
29
|
+
"@rethinkhealth/testing": "0.0.2",
|
|
30
|
+
"@rethinkhealth/hl7v2-builder": "0.2.24",
|
|
31
|
+
"@rethinkhealth/tsconfig": "0.0.1"
|
|
34
32
|
},
|
|
35
33
|
"repository": "rethinkhealth/hl7v2.git",
|
|
36
34
|
"homepage": "https://www.rethinkhealth.io/hl7v2/docs",
|