@glion/jsonify 0.15.1 → 0.15.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/README.md +23 -68
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -1,44 +1,27 @@
|
|
|
1
1
|
# @glion/jsonify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Serialize an HL7v2 AST into a compact, structured JSON document.
|
|
4
4
|
|
|
5
|
-
## What
|
|
5
|
+
## What it does
|
|
6
6
|
|
|
7
|
-
`@glion/jsonify`
|
|
8
|
-
|
|
9
|
-
It strips away [unist](https://github.com/syntax-tree/unist) metadata and preserves only meaningful HL7v2 properties such as segment type, field indexes, and values.
|
|
10
|
-
|
|
11
|
-
## When should I use this?
|
|
12
|
-
|
|
13
|
-
Use this plugin when you need:
|
|
14
|
-
|
|
15
|
-
- A minimal JSON representation of HL7v2 messages for downstream processing.
|
|
16
|
-
- To serialize HL7v2 ASTs into a format suitable for APIs or storage.
|
|
17
|
-
|
|
18
|
-
If you need to parse raw HL7v2 messages first, use [`@glion/ast`](https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-parser) before applying this plugin.
|
|
7
|
+
`@glion/jsonify` takes an HL7v2 AST — typically produced by `@glion/parser` — and emits a JSON representation that strips `unist` metadata (position, raw, type discriminators) and keeps only the meaningful HL7v2 shape: segment names, field indexes, values, and children. The result is a clean payload for downstream APIs, message queues, and analytics stores that want structured HL7v2 without the parser's internal tree representation.
|
|
19
8
|
|
|
20
9
|
## Install
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
In Node.js (version 16+), install with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):
|
|
25
|
-
|
|
26
|
-
```sh
|
|
11
|
+
```bash
|
|
27
12
|
npm install @glion/jsonify
|
|
28
13
|
```
|
|
29
14
|
|
|
30
15
|
## Use
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```js
|
|
35
|
-
import { unified } from "unified";
|
|
36
|
-
import { hl7v2Parse } from "@glion/ast";
|
|
17
|
+
```ts
|
|
18
|
+
import { hl7v2Parser } from "@glion/parser";
|
|
37
19
|
import { hl7v2Jsonify } from "@glion/jsonify";
|
|
20
|
+
import { unified } from "unified";
|
|
38
21
|
|
|
39
22
|
const msg = `MSH|^~\\&|HIS|RIH|EKG|EKG|200202150930||ADT^A01|MSG00001|P|2.4\rPID|||555-44-4444||DOE^JOHN`;
|
|
40
23
|
|
|
41
|
-
const file = await unified().use(
|
|
24
|
+
const file = await unified().use(hl7v2Parser).use(hl7v2Jsonify).process(msg);
|
|
42
25
|
|
|
43
26
|
console.log(String(file));
|
|
44
27
|
```
|
|
@@ -54,8 +37,7 @@ Yields:
|
|
|
54
37
|
"name": "MSH",
|
|
55
38
|
"children": [
|
|
56
39
|
{ "type": "Field", "name": "MSH-1", "value": "|" },
|
|
57
|
-
{ "type": "Field", "name": "MSH-2", "value": "^~\\&" }
|
|
58
|
-
...
|
|
40
|
+
{ "type": "Field", "name": "MSH-2", "value": "^~\\&" }
|
|
59
41
|
]
|
|
60
42
|
},
|
|
61
43
|
{
|
|
@@ -74,55 +56,28 @@ Yields:
|
|
|
74
56
|
|
|
75
57
|
### `unified().use(hl7v2Jsonify)`
|
|
76
58
|
|
|
77
|
-
|
|
59
|
+
Register the plugin as the compiler of a `unified` processor. The processor's `process()` call returns a file whose stringified contents is the JSON document. No options.
|
|
78
60
|
|
|
79
|
-
|
|
61
|
+
## JSON shape
|
|
80
62
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
###### Returns
|
|
84
|
-
|
|
85
|
-
Nothing (`undefined`). The unified compiler returns a stringified JSON document.
|
|
86
|
-
|
|
87
|
-
## JSON Schema
|
|
88
|
-
|
|
89
|
-
The output JSON has the following shape:
|
|
63
|
+
Every node in the output has the following shape:
|
|
90
64
|
|
|
91
65
|
```ts
|
|
92
66
|
interface HL7v2JsonNode {
|
|
93
|
-
type: string;
|
|
94
|
-
name?: string;
|
|
95
|
-
index?: number;
|
|
96
|
-
value?: string;
|
|
97
|
-
delimiter?: string;
|
|
98
|
-
children?: HL7v2JsonNode[];
|
|
67
|
+
type: string; // "Message", "Segment", "Field", "Component", ...
|
|
68
|
+
name?: string; // segment name (e.g. "MSH") or field id (e.g. "PID-3")
|
|
69
|
+
index?: number; // positional index where relevant
|
|
70
|
+
value?: string; // leaf value for Field / Component / Subcomponent
|
|
71
|
+
delimiter?: string; // delimiter character when it is meaningful to preserve
|
|
72
|
+
children?: HL7v2JsonNode[]; // recursive shape for composite nodes
|
|
99
73
|
}
|
|
100
74
|
```
|
|
101
75
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
This plugin only transforms AST nodes and does not execute code. Ensure you trust the source of HL7v2 messages before processing.
|
|
105
|
-
|
|
106
|
-
## Contributing
|
|
107
|
-
|
|
108
|
-
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
109
|
-
|
|
110
|
-
1. Fork the repository
|
|
111
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
112
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
113
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
114
|
-
5. Open a Pull Request
|
|
115
|
-
|
|
116
|
-
## Code of Conduct
|
|
117
|
-
|
|
118
|
-
To ensure a welcoming and positive environment, we have a [Code of Conduct][github-code-of-conduct] that all contributors and participants are expected to adhere to.
|
|
119
|
-
|
|
120
|
-
## License
|
|
76
|
+
Only the fields relevant to a given node appear in the output — `Field` nodes carry `name` and `value`, composite nodes carry `name` and `children`, and so on.
|
|
121
77
|
|
|
122
|
-
|
|
78
|
+
## Part of Glion
|
|
123
79
|
|
|
124
|
-
|
|
80
|
+
`@glion/jsonify` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
|
|
125
81
|
|
|
126
|
-
[
|
|
127
|
-
[
|
|
128
|
-
[github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
|
|
82
|
+
[Glion]: https://github.com/rethinkhealth/glion#readme
|
|
83
|
+
[Glion README]: https://github.com/rethinkhealth/glion#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/jsonify",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "hl7v2 plugin to transform hl7v2 messages to a simplified JSON representation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -34,18 +34,20 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"unified": "11.0.5",
|
|
37
|
-
"@glion/ast": "0.15.
|
|
37
|
+
"@glion/ast": "0.15.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^25.5.0",
|
|
41
41
|
"@types/unist": "^3.0.3",
|
|
42
42
|
"@vitest/coverage-v8": "4.1.2",
|
|
43
|
+
"publint": "0.3.18",
|
|
43
44
|
"tsdown": "0.21.7",
|
|
44
45
|
"typescript": "^5.9.3",
|
|
45
46
|
"vitest": "4.1.2",
|
|
46
|
-
"@glion/builder": "0.15.
|
|
47
|
-
"@glion/
|
|
48
|
-
"@glion/
|
|
47
|
+
"@glion/builder": "0.15.3",
|
|
48
|
+
"@glion/check-readme": "0.15.3",
|
|
49
|
+
"@glion/tsconfig": "0.15.3",
|
|
50
|
+
"@glion/testing": "0.15.3"
|
|
49
51
|
},
|
|
50
52
|
"engines": {
|
|
51
53
|
"node": ">=18"
|
|
@@ -54,8 +56,10 @@
|
|
|
54
56
|
"scripts": {
|
|
55
57
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
56
58
|
"check-types": "tsc --noEmit",
|
|
59
|
+
"check:readme": "glion-check-readme",
|
|
57
60
|
"test": "vitest run",
|
|
58
61
|
"test:coverage": "vitest run --coverage",
|
|
59
|
-
"test:watch": "vitest"
|
|
62
|
+
"test:watch": "vitest",
|
|
63
|
+
"publint": "publint --strict"
|
|
60
64
|
}
|
|
61
65
|
}
|