@glion/to-hl7v2 0.15.1 → 0.15.2
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 +26 -95
- package/package.json +12 -8
package/README.md
CHANGED
|
@@ -1,138 +1,69 @@
|
|
|
1
1
|
# @glion/to-hl7v2
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Compile HL7v2 ASTs back to HL7v2 text — as a `unified` plugin or a standalone helper for any node in the tree.
|
|
4
4
|
|
|
5
|
-
## What
|
|
5
|
+
## What it does
|
|
6
6
|
|
|
7
|
-
`@glion/to-hl7v2`
|
|
8
|
-
|
|
9
|
-
This plugin is useful for transforming, sanitizing, or reconstructing HL7v2 messages while preserving their structure and delimiters.
|
|
10
|
-
|
|
11
|
-
## When should I use this?
|
|
12
|
-
|
|
13
|
-
Use this plugin when you need to:
|
|
14
|
-
|
|
15
|
-
- Transform HL7v2 ASTs back to HL7v2 string format for transmission or storage.
|
|
16
|
-
- Sanitize HL7v2 messages by parsing and rebuilding them.
|
|
17
|
-
- Apply transformations to HL7v2 messages using AST manipulation.
|
|
18
|
-
- Round-trip HL7v2 messages through parsing and compilation.
|
|
19
|
-
|
|
20
|
-
If you need to parse raw HL7v2 messages first, use [`@glion/parser`](https://github.com/rethinkhealth/glion/tree/main/packages/hl7v2-parser) before applying this plugin.
|
|
7
|
+
`@glion/to-hl7v2` serializes an HL7v2 AST — typically produced by `@glion/parser` — into the original HL7v2 wire format. Delimiters are read from the Root node's data when present, so a parse-then-serialize round trip preserves the message byte-for-byte (modulo intentional edits to the tree in between). The standalone `toHl7v2()` helper works on any subtree, not just the Root, which makes it useful for extracting a single segment, field, or component as text.
|
|
21
8
|
|
|
22
9
|
## Install
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
In Node.js (version 16+), install with [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):
|
|
27
|
-
|
|
28
|
-
```sh
|
|
11
|
+
```bash
|
|
29
12
|
npm install @glion/to-hl7v2
|
|
30
13
|
```
|
|
31
14
|
|
|
32
15
|
## Use
|
|
33
16
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
import { unified } from "unified";
|
|
38
|
-
import { hl7v2Parse } from "@glion/parser";
|
|
17
|
+
```ts
|
|
18
|
+
import { hl7v2Parser } from "@glion/parser";
|
|
39
19
|
import { hl7v2ToHl7v2 } from "@glion/to-hl7v2";
|
|
20
|
+
import { unified } from "unified";
|
|
40
21
|
|
|
41
22
|
const msg = `MSH|^~\\&|HIS|RIH|EKG|EKG|200202150930||ADT^A01|MSG00001|P|2.4\rPID|||555-44-4444||DOE^JOHN`;
|
|
42
23
|
|
|
43
|
-
const file = await unified().use(
|
|
24
|
+
const file = await unified().use(hl7v2Parser).use(hl7v2ToHl7v2).process(msg);
|
|
44
25
|
|
|
45
26
|
console.log(String(file));
|
|
27
|
+
// MSH|^~\&|HIS|RIH|EKG|EKG|200202150930||ADT^A01|MSG00001|P|2.4
|
|
28
|
+
// PID|||555-44-4444||DOE^JOHN
|
|
46
29
|
```
|
|
47
30
|
|
|
48
|
-
Yields:
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
MSH|^~\&|HIS|RIH|EKG|EKG|200202150930||ADT^A01|MSG00001|P|2.4
|
|
52
|
-
PID|||555-44-4444||DOE^JOHN
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
The plugin preserves the original HL7v2 delimiters and structure, making it perfect for round-trip processing.
|
|
56
|
-
|
|
57
31
|
## API
|
|
58
32
|
|
|
59
33
|
### `unified().use(hl7v2ToHl7v2)`
|
|
60
34
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
###### Parameters
|
|
64
|
-
|
|
65
|
-
There are no options.
|
|
66
|
-
|
|
67
|
-
###### Returns
|
|
68
|
-
|
|
69
|
-
Nothing (`undefined`). The unified compiler returns a stringified HL7v2 message.
|
|
35
|
+
Register the plugin as the compiler of a `unified` processor. Serializes the AST back to HL7v2 text and sets it as the file contents. No options.
|
|
70
36
|
|
|
71
37
|
### `toHl7v2(node, delimiters?)`
|
|
72
38
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
###### Parameters
|
|
39
|
+
Standalone serializer. Converts any HL7v2 AST node — `Root`, `Segment`, `Field`, `FieldRepetition`, `Component`, or `Subcomponent` — to its HL7v2 text representation.
|
|
76
40
|
|
|
77
|
-
- `node` (`Nodes`) —
|
|
78
|
-
- `delimiters` (`Delimiters`, optional) —
|
|
41
|
+
- `node` (`Nodes`) — the node to serialize.
|
|
42
|
+
- `delimiters` (`Delimiters`, optional) — custom delimiter set. When omitted, reads from the Root node's `data` or falls back to the HL7v2 defaults (`|`, `^`, `~`, `\`, `&`, `\r`).
|
|
79
43
|
|
|
80
|
-
|
|
44
|
+
Returns the serialized `string`.
|
|
81
45
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
This function is highly flexible and can convert any level of the HL7v2 hierarchy:
|
|
85
|
-
|
|
86
|
-
```js
|
|
46
|
+
```ts
|
|
87
47
|
import { toHl7v2 } from "@glion/to-hl7v2";
|
|
88
48
|
|
|
89
|
-
// Convert entire message
|
|
90
49
|
toHl7v2(rootNode); // "MSH|^~\&|...\rPID|..."
|
|
91
|
-
|
|
92
|
-
// Convert individual segment
|
|
93
50
|
toHl7v2(segmentNode); // "PID|12345|DOE^JOHN"
|
|
94
|
-
|
|
95
|
-
// Convert individual field
|
|
96
51
|
toHl7v2(fieldNode); // "DOE^JOHN"
|
|
97
|
-
|
|
98
|
-
// Convert component
|
|
99
52
|
toHl7v2(componentNode); // "SUB1&SUB2"
|
|
100
53
|
```
|
|
101
54
|
|
|
102
|
-
##
|
|
103
|
-
|
|
104
|
-
- **Universal node support**: Can convert any HL7v2 AST node type (Root, Segment, Field, FieldRepetition, Component, Subcomponent)
|
|
105
|
-
- **Delimiter preservation**: Uses the original delimiters from Root AST metadata
|
|
106
|
-
- **Flexible delimiter handling**: Accepts custom delimiters or falls back to defaults
|
|
107
|
-
- **MSH segment handling**: Correctly handles the special MSH segment structure
|
|
108
|
-
- **Complete hierarchy support**: Supports all HL7v2 levels with proper delimiter usage
|
|
109
|
-
- **Empty value handling**: Properly handles empty fields and components
|
|
110
|
-
- **Error handling**: Provides clear error messages for unsupported node types
|
|
111
|
-
|
|
112
|
-
## Security
|
|
113
|
-
|
|
114
|
-
This plugin only transforms AST nodes and does not execute code. Ensure you trust the source of HL7v2 messages before processing.
|
|
115
|
-
|
|
116
|
-
## Contributing
|
|
117
|
-
|
|
118
|
-
We welcome contributions! Please see our [Contributing Guide][github-contributing] for more details.
|
|
119
|
-
|
|
120
|
-
1. Fork the repository
|
|
121
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
122
|
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
123
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
124
|
-
5. Open a Pull Request
|
|
125
|
-
|
|
126
|
-
## Code of Conduct
|
|
55
|
+
## Round-trip guarantees
|
|
127
56
|
|
|
128
|
-
|
|
57
|
+
- **Delimiter preservation** — custom delimiters set on `Root.data` (by the parser or by hand) carry through to the output. Messages that do not use the defaults round-trip correctly.
|
|
58
|
+
- **MSH handling** — the special case where `MSH-1` is the field separator and `MSH-2` carries the encoding characters is encoded correctly on serialization.
|
|
59
|
+
- **Empty fields and components** — preserved in position so field indexes remain stable.
|
|
60
|
+
- **Every node type supported** — serializing a partial subtree produces the exact fragment you would expect to find embedded inside the full message.
|
|
129
61
|
|
|
130
|
-
|
|
62
|
+
Pair with `@glion/parser` to read HL7v2 in and `@glion/to-hl7v2` to write it back out; layer `@glion/encode-escapes` and `@glion/decode-escapes` in between to handle delimiter characters that appear in content values.
|
|
131
63
|
|
|
132
|
-
|
|
64
|
+
## Part of Glion
|
|
133
65
|
|
|
134
|
-
|
|
66
|
+
`@glion/to-hl7v2` is part of **[Glion]**, the application framework for HL7v2. See the [Glion README] for the full package catalog and architecture.
|
|
135
67
|
|
|
136
|
-
[
|
|
137
|
-
[
|
|
138
|
-
[github-contributing]: https://github.com/rethinkhealth/glion/blob/main/CONTRIBUTING.md
|
|
68
|
+
[Glion]: https://github.com/rethinkhealth/glion#readme
|
|
69
|
+
[Glion README]: https://github.com/rethinkhealth/glion#readme
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glion/to-hl7v2",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
4
4
|
"description": "hl7v2 plugin to transform hl7v2 messages to a hl7v2. Useful for sanitizing messages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"health",
|
|
@@ -36,22 +36,24 @@
|
|
|
36
36
|
"unified": "11.0.5",
|
|
37
37
|
"unist-util-visit": "5.1.0",
|
|
38
38
|
"unist-util-visit-parents": "6.0.2",
|
|
39
|
-
"@glion/utils": "0.15.
|
|
39
|
+
"@glion/utils": "0.15.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "^25.5.0",
|
|
43
43
|
"@types/unist": "^3.0.3",
|
|
44
44
|
"@vitest/coverage-v8": "4.1.2",
|
|
45
|
+
"publint": "0.3.18",
|
|
45
46
|
"tsdown": "0.21.7",
|
|
46
47
|
"typescript": "^5.9.3",
|
|
47
48
|
"unist-builder": "^4.0.0",
|
|
48
49
|
"vfile": "^6.0.3",
|
|
49
50
|
"vitest": "4.1.2",
|
|
50
|
-
"@glion/
|
|
51
|
-
"@glion/
|
|
52
|
-
"@glion/
|
|
53
|
-
"@glion/tsconfig": "0.15.
|
|
54
|
-
"@glion/util-query": "0.15.
|
|
51
|
+
"@glion/ast": "0.15.2",
|
|
52
|
+
"@glion/builder": "0.15.2",
|
|
53
|
+
"@glion/check-readme": "0.15.2",
|
|
54
|
+
"@glion/tsconfig": "0.15.2",
|
|
55
|
+
"@glion/util-query": "0.15.2",
|
|
56
|
+
"@glion/testing": "0.15.2"
|
|
55
57
|
},
|
|
56
58
|
"engines": {
|
|
57
59
|
"node": ">=18"
|
|
@@ -60,8 +62,10 @@
|
|
|
60
62
|
"scripts": {
|
|
61
63
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
62
64
|
"check-types": "tsc --noEmit",
|
|
65
|
+
"check:readme": "glion-check-readme",
|
|
63
66
|
"test": "vitest run",
|
|
64
67
|
"test:coverage": "vitest run --coverage",
|
|
65
|
-
"test:watch": "vitest"
|
|
68
|
+
"test:watch": "vitest",
|
|
69
|
+
"publint": "publint --strict"
|
|
66
70
|
}
|
|
67
71
|
}
|