fastify-hl7 4.0.0 → 4.0.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/CHANGELOG.md +279 -3
- package/README.md +156 -3
- package/dist/class/hL7Client.d.ts +1 -1
- package/dist/class/hL7Server.d.ts +1 -1
- package/dist/decorate.d.ts +1 -1
- package/dist/index.cjs +3 -7
- package/dist/index.mjs +2 -4
- package/package.json +8 -7
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,51 @@
|
|
|
1
1
|
# Fastify HL7
|
|
2
2
|
|
|
3
|
+
## v4.0.2 - 2026-09-26
|
|
4
|
+
|
|
5
|
+
### What Changed 👀
|
|
6
|
+
|
|
7
|
+
#### 🐛 Bug Fixes
|
|
8
|
+
|
|
9
|
+
- fix: use named node-hl7 imports so the CommonJS build works @Bugs5382 (#146)
|
|
10
|
+
- fix(build): keep source maps out of the npm package and guard its size @Bugs5382 (#144)
|
|
11
|
+
|
|
12
|
+
#### 📄 Documentation
|
|
13
|
+
|
|
14
|
+
- docs(readme): apply the lite emoji treatment @Bugs5382 (#141)
|
|
15
|
+
|
|
16
|
+
### Extra
|
|
17
|
+
|
|
18
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v4.0.1...v4.0.2
|
|
19
|
+
|
|
20
|
+
## v4.0.1 - 2026-08-11
|
|
21
|
+
|
|
22
|
+
### What Changed 👀
|
|
23
|
+
|
|
24
|
+
#### 🐛 Bug Fixes
|
|
25
|
+
|
|
26
|
+
- fix(deps): raise the node-hl7 floor to 4.1.1 @Bugs5382 (#136)
|
|
27
|
+
|
|
28
|
+
#### 📄 Documentation
|
|
29
|
+
|
|
30
|
+
- docs(changelog): put every release in the release-drafter format @Bugs5382 (#138)
|
|
31
|
+
- docs: add encapsulation recipe for a user plugin that streamlines sending HL7 @Bugs5382 (#128)
|
|
32
|
+
|
|
33
|
+
#### 🧩 Dependency Updates
|
|
34
|
+
|
|
35
|
+
- chore(deps): bump the github-actions group with 9 updates @[dependabot[bot]](https://github.com/apps/dependabot) (#125)
|
|
36
|
+
- chore(deps): bump the production-dependencies group with 2 updates @[dependabot[bot]](https://github.com/apps/dependabot) (#123)
|
|
37
|
+
- chore(deps-dev): bump the development-dependencies group with 2 updates @[dependabot[bot]](https://github.com/apps/dependabot) (#124)
|
|
38
|
+
|
|
39
|
+
### Extra
|
|
40
|
+
|
|
41
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v4.0.0...v4.0.1
|
|
42
|
+
|
|
3
43
|
## v4.0.0 - 2026-06-08
|
|
4
44
|
|
|
5
45
|
### What Changed 👀
|
|
6
46
|
|
|
47
|
+
- fix(ci): skip PR Body check for Dependabot @Bugs5382 (#105)
|
|
48
|
+
|
|
7
49
|
#### 💥 Breaking Changes
|
|
8
50
|
|
|
9
51
|
- feat!: upgrade to node-hl7 v4.0.0 @Bugs5382 (#88)
|
|
@@ -22,7 +64,7 @@
|
|
|
22
64
|
|
|
23
65
|
## v3.3.0 - 2025-03-25
|
|
24
66
|
|
|
25
|
-
|
|
67
|
+
### What Changed 👀
|
|
26
68
|
|
|
27
69
|
#### 🧩 Dependency Updates
|
|
28
70
|
|
|
@@ -34,7 +76,7 @@
|
|
|
34
76
|
|
|
35
77
|
## v3.2.0 - 2024-12-18
|
|
36
78
|
|
|
37
|
-
|
|
79
|
+
### What Changed 👀
|
|
38
80
|
|
|
39
81
|
#### 🚀 Features
|
|
40
82
|
|
|
@@ -46,7 +88,7 @@
|
|
|
46
88
|
|
|
47
89
|
## v3.1.0 - 2024-11-16
|
|
48
90
|
|
|
49
|
-
|
|
91
|
+
### What Changed 👀
|
|
50
92
|
|
|
51
93
|
#### 🚀 Features
|
|
52
94
|
|
|
@@ -55,3 +97,237 @@
|
|
|
55
97
|
### Extra
|
|
56
98
|
|
|
57
99
|
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v3.0.0...v3.1.0
|
|
100
|
+
|
|
101
|
+
## v3.0.0 - 2024-10-31
|
|
102
|
+
|
|
103
|
+
### What Changed 👀
|
|
104
|
+
|
|
105
|
+
#### 💥 Breaking Changes
|
|
106
|
+
|
|
107
|
+
- update node-hl7-server package to 3.0.0 which has a breaking change
|
|
108
|
+
|
|
109
|
+
#### 🚀 Features
|
|
110
|
+
|
|
111
|
+
- feat: 3.0.0 @Bugs5382 (#78)
|
|
112
|
+
- feat: update typedoc plugin @Bugs5382 (#79)
|
|
113
|
+
- updated packages @Bugs5382 ([743e34c](https://github.com/Bugs5382/fastify-hl7/commit/743e34c40ce44ef1a04a48fb22c52f197a2a0497))
|
|
114
|
+
|
|
115
|
+
### Extra
|
|
116
|
+
|
|
117
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v2.2.0...v3.0.0
|
|
118
|
+
|
|
119
|
+
## v2.2.0 - 2024-06-25
|
|
120
|
+
|
|
121
|
+
### What Changed 👀
|
|
122
|
+
|
|
123
|
+
#### 🚀 Features
|
|
124
|
+
|
|
125
|
+
- feat: updates packages @Bugs5382 (#43)
|
|
126
|
+
|
|
127
|
+
### Extra
|
|
128
|
+
|
|
129
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v2.1.0...v2.2.0
|
|
130
|
+
|
|
131
|
+
## v2.1.0 - 2024-02-22
|
|
132
|
+
|
|
133
|
+
### What Changed 👀
|
|
134
|
+
|
|
135
|
+
#### 🚀 Features
|
|
136
|
+
|
|
137
|
+
- feat: added buildDate @Bugs5382 (#29)
|
|
138
|
+
- feat: added new features in @Bugs5382 (#30)
|
|
139
|
+
|
|
140
|
+
### Extra
|
|
141
|
+
|
|
142
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v2.0.0...v2.1.0
|
|
143
|
+
|
|
144
|
+
## v2.0.0 - 2024-02-04
|
|
145
|
+
|
|
146
|
+
### What Changed 👀
|
|
147
|
+
|
|
148
|
+
#### 💥 Breaking Changes
|
|
149
|
+
|
|
150
|
+
- node 20
|
|
151
|
+
|
|
152
|
+
#### 🚀 Features
|
|
153
|
+
|
|
154
|
+
- feat: first batch of changes @Bugs5382 (#19)
|
|
155
|
+
- feat: v2.0.0 @Bugs5382 (#20)
|
|
156
|
+
|
|
157
|
+
#### 🐛 Bug Fixes
|
|
158
|
+
|
|
159
|
+
- fix: ci actions @Bugs5382 (#22)
|
|
160
|
+
|
|
161
|
+
### Extra
|
|
162
|
+
|
|
163
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.2.0...v2.0.0
|
|
164
|
+
|
|
165
|
+
## v1.2.0 - 2024-01-18
|
|
166
|
+
|
|
167
|
+
### What Changed 👀
|
|
168
|
+
|
|
169
|
+
#### 🚀 Features
|
|
170
|
+
|
|
171
|
+
- feat: update server package @Bugs5382 (#17)
|
|
172
|
+
- update server version @Bugs5382 ([f0548d6](https://github.com/Bugs5382/fastify-hl7/commit/f0548d63649546f3b67d4c3d9e9a993e2a4dbced))
|
|
173
|
+
|
|
174
|
+
### Extra
|
|
175
|
+
|
|
176
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.1.4...v1.2.0
|
|
177
|
+
|
|
178
|
+
## v1.1.4 - 2024-01-18
|
|
179
|
+
|
|
180
|
+
### What Changed 👀
|
|
181
|
+
|
|
182
|
+
#### 🐛 Bug Fixes
|
|
183
|
+
|
|
184
|
+
- fix: import for ESM @Bugs5382 (#14)
|
|
185
|
+
- update import with .js @Bugs5382 ([4527548](https://github.com/Bugs5382/fastify-hl7/commit/4527548796647c2af74116b8b18273d331bda92b))
|
|
186
|
+
- fix: update import with .js @Bugs5382 (#13)
|
|
187
|
+
|
|
188
|
+
### Extra
|
|
189
|
+
|
|
190
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.1.3...v1.1.4
|
|
191
|
+
|
|
192
|
+
## v1.1.3 - 2024-01-18
|
|
193
|
+
|
|
194
|
+
### What Changed 👀
|
|
195
|
+
|
|
196
|
+
#### 🐛 Bug Fixes
|
|
197
|
+
|
|
198
|
+
- fix: added export of FastifyHL7Options @Bugs5382 (#10)
|
|
199
|
+
- fix: export of FastifyHL7Options @Bugs5382 (#11)
|
|
200
|
+
|
|
201
|
+
### Extra
|
|
202
|
+
|
|
203
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.1.2...v1.1.3
|
|
204
|
+
|
|
205
|
+
## v1.1.2 - 2024-01-11
|
|
206
|
+
|
|
207
|
+
### What Changed 👀
|
|
208
|
+
|
|
209
|
+
#### 🐛 Bug Fixes
|
|
210
|
+
|
|
211
|
+
- fix: update packages @Bugs5382 (#7)
|
|
212
|
+
|
|
213
|
+
### Extra
|
|
214
|
+
|
|
215
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.1.1...v1.1.2
|
|
216
|
+
|
|
217
|
+
## v1.1.1 - 2024-01-10
|
|
218
|
+
|
|
219
|
+
### What Changed 👀
|
|
220
|
+
|
|
221
|
+
#### 🐛 Bug Fixes
|
|
222
|
+
|
|
223
|
+
- fix: update packages @Bugs5382 (#6)
|
|
224
|
+
|
|
225
|
+
### Extra
|
|
226
|
+
|
|
227
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.1.0...v1.1.1
|
|
228
|
+
|
|
229
|
+
## v1.1.1-beta.1 - 2024-01-10
|
|
230
|
+
|
|
231
|
+
### What Changed 👀
|
|
232
|
+
|
|
233
|
+
#### 🐛 Bug Fixes
|
|
234
|
+
|
|
235
|
+
- update packages @Bugs5382 ([62dc1ec](https://github.com/Bugs5382/fastify-hl7/commit/62dc1ec5e1735c59f7417df7b102b17404d90030))
|
|
236
|
+
|
|
237
|
+
### Extra
|
|
238
|
+
|
|
239
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.1.0...v1.1.1-beta.1
|
|
240
|
+
|
|
241
|
+
## v1.0.0-beta.3 - 2024-01-10
|
|
242
|
+
|
|
243
|
+
### What Changed 👀
|
|
244
|
+
|
|
245
|
+
#### 🐛 Bug Fixes
|
|
246
|
+
|
|
247
|
+
- update packages @Bugs5382 ([62dc1ec](https://github.com/Bugs5382/fastify-hl7/commit/62dc1ec5e1735c59f7417df7b102b17404d90030))
|
|
248
|
+
|
|
249
|
+
### Extra
|
|
250
|
+
|
|
251
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.0.0-beta.2...v1.0.0-beta.3
|
|
252
|
+
|
|
253
|
+
## v1.1.0 - 2023-12-31
|
|
254
|
+
|
|
255
|
+
### What Changed 👀
|
|
256
|
+
|
|
257
|
+
#### 🚀 Features
|
|
258
|
+
|
|
259
|
+
- feat: updated packages @Bugs5382 (#5)
|
|
260
|
+
|
|
261
|
+
### Extra
|
|
262
|
+
|
|
263
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.0.0...v1.1.0
|
|
264
|
+
|
|
265
|
+
## v1.0.0 - 2023-12-30
|
|
266
|
+
|
|
267
|
+
### What Changed 👀
|
|
268
|
+
|
|
269
|
+
#### 🚀 Features
|
|
270
|
+
|
|
271
|
+
- feat: added functions that get @Bugs5382 (#3)
|
|
272
|
+
- added in @Bugs5382 ([3c340d5](https://github.com/Bugs5382/fastify-hl7/commit/3c340d59ac2861bbf58c90acb28615914410b3ca))
|
|
273
|
+
- buildMessage, publishMessage @Bugs5382 ([fc1d7db](https://github.com/Bugs5382/fastify-hl7/commit/fc1d7db9968030247c518817ce5a6c8f231fa91d))
|
|
274
|
+
- client stuff done @Bugs5382 ([bd6cb46](https://github.com/Bugs5382/fastify-hl7/commit/bd6cb464ad45833b0c3df2623db22ff5737a36ba))
|
|
275
|
+
- develop branch for release @Bugs5382 ([28c5f30](https://github.com/Bugs5382/fastify-hl7/commit/28c5f30f01a88cbec9b04b37b1aadf7ed959a369))
|
|
276
|
+
- first working version @Bugs5382 ([f9d3ffd](https://github.com/Bugs5382/fastify-hl7/commit/f9d3ffd660c9802778adb9732d6e3587be109139))
|
|
277
|
+
- fixed client connections @Bugs5382 ([c421328](https://github.com/Bugs5382/fastify-hl7/commit/c4213281c43f8ee7655f4e6c88cf0d0ad15e8d3b))
|
|
278
|
+
- full example @Bugs5382 ([7c36b2d](https://github.com/Bugs5382/fastify-hl7/commit/7c36b2d02c65a05050ec44889f8745a2c61ede62))
|
|
279
|
+
- initial build @Bugs5382 ([36b35d9](https://github.com/Bugs5382/fastify-hl7/commit/36b35d904231507b6a6004bda4a5f07c2d224233))
|
|
280
|
+
- new design, again. @Bugs5382 ([2113ca3](https://github.com/Bugs5382/fastify-hl7/commit/2113ca3183d91a085791a067e2af6fc69d305aba))
|
|
281
|
+
- registration working @Bugs5382 ([6f54019](https://github.com/Bugs5382/fastify-hl7/commit/6f54019a66aa5c24ec1d7ce3130475ef6b602426))
|
|
282
|
+
- release branch for release @Bugs5382 ([c85e0be](https://github.com/Bugs5382/fastify-hl7/commit/c85e0bec4fbb6019d460e0b5743292e58097cb41))
|
|
283
|
+
- feat: standardized project @Bugs5382 (#1)
|
|
284
|
+
- update server signatures @Bugs5382 ([d1fc0da](https://github.com/Bugs5382/fastify-hl7/commit/d1fc0dad4c3ca5dbfa40b4850cd092f43a82e3d8))
|
|
285
|
+
- feat: v1.0.0 @Bugs5382 (#4)
|
|
286
|
+
|
|
287
|
+
#### 🐛 Bug Fixes
|
|
288
|
+
|
|
289
|
+
- removed .npmignore @Bugs5382 ([bd788da](https://github.com/Bugs5382/fastify-hl7/commit/bd788dad661f7f4e271458d5b633280a9d561fef))
|
|
290
|
+
|
|
291
|
+
### Extra
|
|
292
|
+
|
|
293
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/releases/tag/v1.0.0
|
|
294
|
+
|
|
295
|
+
## v1.0.0-beta.2 - 2023-12-30
|
|
296
|
+
|
|
297
|
+
### What Changed 👀
|
|
298
|
+
|
|
299
|
+
#### 🚀 Features
|
|
300
|
+
|
|
301
|
+
- feat: added functions that get @Bugs5382 (#3)
|
|
302
|
+
|
|
303
|
+
### Extra
|
|
304
|
+
|
|
305
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/compare/v1.0.0-beta.1...v1.0.0-beta.2
|
|
306
|
+
|
|
307
|
+
## v1.0.0-beta.1 - 2023-12-29
|
|
308
|
+
|
|
309
|
+
### What Changed 👀
|
|
310
|
+
|
|
311
|
+
#### 🚀 Features
|
|
312
|
+
|
|
313
|
+
- added in @Bugs5382 ([3c340d5](https://github.com/Bugs5382/fastify-hl7/commit/3c340d59ac2861bbf58c90acb28615914410b3ca))
|
|
314
|
+
- buildMessage, publishMessage @Bugs5382 ([fc1d7db](https://github.com/Bugs5382/fastify-hl7/commit/fc1d7db9968030247c518817ce5a6c8f231fa91d))
|
|
315
|
+
- client stuff done @Bugs5382 ([bd6cb46](https://github.com/Bugs5382/fastify-hl7/commit/bd6cb464ad45833b0c3df2623db22ff5737a36ba))
|
|
316
|
+
- develop branch for release @Bugs5382 ([28c5f30](https://github.com/Bugs5382/fastify-hl7/commit/28c5f30f01a88cbec9b04b37b1aadf7ed959a369))
|
|
317
|
+
- first working version @Bugs5382 ([f9d3ffd](https://github.com/Bugs5382/fastify-hl7/commit/f9d3ffd660c9802778adb9732d6e3587be109139))
|
|
318
|
+
- fixed client connections @Bugs5382 ([c421328](https://github.com/Bugs5382/fastify-hl7/commit/c4213281c43f8ee7655f4e6c88cf0d0ad15e8d3b))
|
|
319
|
+
- full example @Bugs5382 ([7c36b2d](https://github.com/Bugs5382/fastify-hl7/commit/7c36b2d02c65a05050ec44889f8745a2c61ede62))
|
|
320
|
+
- initial build @Bugs5382 ([36b35d9](https://github.com/Bugs5382/fastify-hl7/commit/36b35d904231507b6a6004bda4a5f07c2d224233))
|
|
321
|
+
- new design, again. @Bugs5382 ([2113ca3](https://github.com/Bugs5382/fastify-hl7/commit/2113ca3183d91a085791a067e2af6fc69d305aba))
|
|
322
|
+
- registration working @Bugs5382 ([6f54019](https://github.com/Bugs5382/fastify-hl7/commit/6f54019a66aa5c24ec1d7ce3130475ef6b602426))
|
|
323
|
+
- release branch for release @Bugs5382 ([c85e0be](https://github.com/Bugs5382/fastify-hl7/commit/c85e0bec4fbb6019d460e0b5743292e58097cb41))
|
|
324
|
+
- feat: standardized project @Bugs5382 (#1)
|
|
325
|
+
- update server signatures @Bugs5382 ([d1fc0da](https://github.com/Bugs5382/fastify-hl7/commit/d1fc0dad4c3ca5dbfa40b4850cd092f43a82e3d8))
|
|
326
|
+
|
|
327
|
+
#### 🐛 Bug Fixes
|
|
328
|
+
|
|
329
|
+
- removed .npmignore @Bugs5382 ([bd788da](https://github.com/Bugs5382/fastify-hl7/commit/bd788dad661f7f4e271458d5b633280a9d561fef))
|
|
330
|
+
|
|
331
|
+
### Extra
|
|
332
|
+
|
|
333
|
+
**Full Changelog**: https://github.com/Bugs5382/fastify-hl7/releases/tag/v1.0.0-beta.1
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fastify HL7 🏥
|
|
2
|
+
|
|
3
|
+
> 🩺 A Fastify HL7 plugin developed in pure TypeScript.
|
|
2
4
|
|
|
3
|
-
A Fastify HL7 plugin developed in pure TypeScript.
|
|
4
5
|
It wraps the `node-hl7-client` and `node-hl7-server` packages — both shipped from the
|
|
5
6
|
[`node-hl7`](https://github.com/Bugs5382/node-hl7) repo — so a Fastify app can send and
|
|
6
7
|
receive HL7 v2.x messages over MLLP.
|
|
@@ -21,7 +22,7 @@ contribution from the outside.
|
|
|
21
22
|
> "2.7.1" | "2.8"`. There is no default. A client's `version` must match the `MSH.12` of every
|
|
22
23
|
> message it sends; an inbound listener rejects (`AR`) any message whose `MSH.12` differs.
|
|
23
24
|
|
|
24
|
-
## Table of Contents
|
|
25
|
+
## 📑 Table of Contents
|
|
25
26
|
|
|
26
27
|
1. [Install](#-install)
|
|
27
28
|
2. [Basic Usage](#-basic-usage)
|
|
@@ -39,6 +40,7 @@ contribution from the outside.
|
|
|
39
40
|
8. [TLS and server options](#8-tls-and-server-options)
|
|
40
41
|
9. [Look up live clients and listeners](#9-look-up-live-clients-and-listeners)
|
|
41
42
|
10. [Error handling when the server is disabled](#10-error-handling-when-the-server-is-disabled)
|
|
43
|
+
11. [Encapsulate sending in your own plugin](#11-encapsulate-sending-in-your-own-plugin)
|
|
42
44
|
4. [API Reference](#-api-reference-fastifyhl7)
|
|
43
45
|
5. [Plugin Options](#-plugin-options)
|
|
44
46
|
6. [External Libraries](#-external-libraries)
|
|
@@ -53,6 +55,11 @@ npm install fastify-hl7
|
|
|
53
55
|
|
|
54
56
|
Requires Node.js ≥ 22.
|
|
55
57
|
|
|
58
|
+
The plugin depends on `node-hl7-client` and `node-hl7-server` `^4.1.1`, so a fresh install pulls
|
|
59
|
+
4.1.1 or newer of both. Versions 4.0.0 and 4.1.0 of `node-hl7-client` were published oversized
|
|
60
|
+
(about 44 MB unpacked), so 4.1.1 or newer is required. If an older lockfile or an `overrides`
|
|
61
|
+
entry pins either package below 4.1.1, update it.
|
|
62
|
+
|
|
56
63
|
## 🚀 Basic Usage
|
|
57
64
|
|
|
58
65
|
### Register the plugin
|
|
@@ -369,6 +376,152 @@ try {
|
|
|
369
376
|
|
|
370
377
|
Registering the plugin twice also throws (`FASTIFY_HL7_ERR_SETUP_ERRORS: "Already registered."`).
|
|
371
378
|
|
|
379
|
+
### 11. Encapsulate sending in your own plugin
|
|
380
|
+
|
|
381
|
+
This is the pattern the plugin is built for, and the reason it is a plugin at all. Fastify's
|
|
382
|
+
encapsulation lets you keep every HL7 concern — registering `fastify-hl7`, the version pin, the
|
|
383
|
+
client, the outbound connection, and the ACK handling — in **one plugin**, and expose just a small,
|
|
384
|
+
intent-named surface (a decorator like `app.adt`) to the rest of the app. Routes then send a message
|
|
385
|
+
in one call; they never touch clients, connections, or message headers.
|
|
386
|
+
|
|
387
|
+
Wrap your plugin with [`fastify-plugin`](https://github.com/fastify/fastify-plugin) so the decorator
|
|
388
|
+
is visible to sibling plugins and routes. Without `fp`, the decorator would be trapped inside this
|
|
389
|
+
plugin's own encapsulation context and the rest of the app could not see it.
|
|
390
|
+
|
|
391
|
+
The helper below builds a **validated** `ADT^A01` with `createBuilder("2.7")`, sends it over a
|
|
392
|
+
connection created once at startup, and resolves with the remote's acknowledgement code (`MSA.1`):
|
|
393
|
+
|
|
394
|
+
```ts
|
|
395
|
+
// plugins/adt.ts
|
|
396
|
+
import fp from "fastify-plugin";
|
|
397
|
+
import fastifyHL7 from "fastify-hl7";
|
|
398
|
+
|
|
399
|
+
// The HL7 version is pinned in one place. The client, the connection, and the
|
|
400
|
+
// builder all use it, so MSH.12 can never drift out of sync.
|
|
401
|
+
const HL7_VERSION = "2.7" as const;
|
|
402
|
+
|
|
403
|
+
// A small, route-facing input — the business shape, not an HL7 message.
|
|
404
|
+
interface Patient {
|
|
405
|
+
mrn: string;
|
|
406
|
+
name: string; // HL7 XPN, e.g. "DOE^JANE^A"
|
|
407
|
+
sex?: string; // HL7 administrative sex, e.g. "F"
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
declare module "fastify" {
|
|
411
|
+
interface FastifyInstance {
|
|
412
|
+
adt: {
|
|
413
|
+
/** Send an ADT^A01 (patient admit) and resolve with the ACK code from MSA.1. */
|
|
414
|
+
sendA01: (patient: Patient) => Promise<string>;
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export default fp(
|
|
420
|
+
async (app) => {
|
|
421
|
+
// 1. Register fastify-hl7. This app only sends, so the inbound server is off.
|
|
422
|
+
await app.register(fastifyHL7, { enableServer: false });
|
|
423
|
+
|
|
424
|
+
// 2. Wire the client and one outbound connection once, at startup. The ACK
|
|
425
|
+
// handler resolves a pending promise so the helper can await the reply.
|
|
426
|
+
const host = process.env.ADT_HOST ?? "127.0.0.1";
|
|
427
|
+
const port = Number(process.env.ADT_PORT ?? 3001);
|
|
428
|
+
|
|
429
|
+
app.hl7.createClient("adt_host", { host, version: HL7_VERSION });
|
|
430
|
+
|
|
431
|
+
let resolveAck: ((code: string) => void) | undefined;
|
|
432
|
+
const connection = app.hl7.createConnection(
|
|
433
|
+
"adt_host",
|
|
434
|
+
{ port, version: HL7_VERSION },
|
|
435
|
+
async (res) => {
|
|
436
|
+
// The remote replies with an ACK/NAK message; MSA.1 carries the code.
|
|
437
|
+
const code = res.getMessage().get("MSA.1").toString();
|
|
438
|
+
resolveAck?.(code);
|
|
439
|
+
},
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
// 3. Expose one intent-named helper. Routes call app.adt.sendA01(patient)
|
|
443
|
+
// and stay ignorant of HL7 framing, the connection, and the version.
|
|
444
|
+
app.decorate("adt", {
|
|
445
|
+
sendA01: async (patient: Patient): Promise<string> => {
|
|
446
|
+
const message = app.hl7
|
|
447
|
+
.createBuilder(HL7_VERSION)
|
|
448
|
+
.buildMSH({
|
|
449
|
+
msh_3: "MY_APP",
|
|
450
|
+
msh_4: "MY_FAC",
|
|
451
|
+
msh_5: "EPIC",
|
|
452
|
+
msh_6: "HOSP",
|
|
453
|
+
msh_9_1: "ADT",
|
|
454
|
+
msh_9_2: "A01",
|
|
455
|
+
msh_10: app.hl7.buildDate(new Date()),
|
|
456
|
+
msh_11_1: "P",
|
|
457
|
+
})
|
|
458
|
+
.buildEVN({ evn_1: "A01", evn_2: new Date() })
|
|
459
|
+
.buildPID({ pid_3: patient.mrn, pid_5: patient.name, pid_8: patient.sex })
|
|
460
|
+
.buildPV1({ pv1_2: "I" }) // patient class: I = inpatient
|
|
461
|
+
.toMessage();
|
|
462
|
+
|
|
463
|
+
const ack = new Promise<string>((resolve) => {
|
|
464
|
+
resolveAck = resolve;
|
|
465
|
+
});
|
|
466
|
+
await connection.sendMessage(message);
|
|
467
|
+
return ack;
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// 4. No teardown to write: fastify-hl7 registers preClose hooks that close
|
|
472
|
+
// the client and connection automatically when the app shuts down.
|
|
473
|
+
},
|
|
474
|
+
{ name: "adt" },
|
|
475
|
+
);
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
> The ACK handler above resolves a single pending promise, which keeps the example focused on the
|
|
479
|
+
> encapsulation pattern. The handler is per-connection and is not correlated to a specific outgoing
|
|
480
|
+
> message, so if you send several messages concurrently over the same connection you should match each
|
|
481
|
+
> reply to its request yourself — e.g. key pending promises by the `MSH.10` message-control id you set
|
|
482
|
+
> on the outgoing message and read back from the ACK's `MSA.2`.
|
|
483
|
+
|
|
484
|
+
Register it once, then admit a patient from anywhere with a single call:
|
|
485
|
+
|
|
486
|
+
```ts
|
|
487
|
+
import fastify from "fastify";
|
|
488
|
+
import adt from "./plugins/adt";
|
|
489
|
+
|
|
490
|
+
const app = fastify();
|
|
491
|
+
await app.register(adt);
|
|
492
|
+
|
|
493
|
+
app.post("/admit", async (request) => {
|
|
494
|
+
const ackCode = await app.adt.sendA01(request.body as never);
|
|
495
|
+
return { accepted: ackCode === "AA", ackCode };
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
await app.listen({ port: 3000 });
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
Why this shape works well:
|
|
502
|
+
|
|
503
|
+
- **One place owns HL7.** Registration, version pin, client, connection, and message building live
|
|
504
|
+
together; the rest of the app depends only on `app.adt`.
|
|
505
|
+
- **Startup wires, routes send.** The client and connection are created once at boot, so the first
|
|
506
|
+
request does not rebuild the connection or re-pin the version.
|
|
507
|
+
- **The version cannot drift.** `HL7_VERSION` feeds `createClient` and `createBuilder`, and the
|
|
508
|
+
builder stamps it into `MSH.12` — so the message a client sends always matches the version that
|
|
509
|
+
client was created with.
|
|
510
|
+
- **Lifecycle is handled for you.** `fastify-hl7`'s `preClose` hooks close the client and connection
|
|
511
|
+
with the app (see [Graceful shutdown](#7-graceful-shutdown)) — important for clean restarts and for
|
|
512
|
+
tests that start and stop Fastify repeatedly.
|
|
513
|
+
- **Swappable.** Because routes only know `app.adt`, you can repoint the host, add a second trigger
|
|
514
|
+
(`sendA08`, an `ORU` result via [recipe 4](#4-build-messages-batches-and-file-batches)), or stub the
|
|
515
|
+
decorator in a test without touching route code.
|
|
516
|
+
|
|
517
|
+
> **Registration order:** register your wrapper plugin (which registers `fastify-hl7` internally)
|
|
518
|
+
> before any plugin or route that uses `app.adt`. Because the wrapper is an `fp` plugin, Fastify
|
|
519
|
+
> guarantees its decorators are in place before sibling plugins and routes load.
|
|
520
|
+
>
|
|
521
|
+
> The types you need — `HL7`, `FastifyHL7Options`, and the client/server option types — are described
|
|
522
|
+
> in the [API Reference](#-api-reference-fastifyhl7); the underlying message, segment, and builder
|
|
523
|
+
> types come from `node-hl7-client` (see [External Libraries](#-external-libraries)).
|
|
524
|
+
|
|
372
525
|
## 📖 API Reference (`fastify.hl7`)
|
|
373
526
|
|
|
374
527
|
All methods hang off the `hl7` decorator on the Fastify instance.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Batch, Client, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, Connection, createHL7Date, FileBatch, HL7_2_1, HL7_2_2, HL7_2_3, HL7_2_3_1, HL7_2_4, HL7_2_5, HL7_2_5_1, HL7_2_6, HL7_2_7, HL7_2_7_1, HL7_2_8, HL7Version, Message, OutboundHandler } from "node-hl7-client";
|
|
2
2
|
/** Accepted HL7 date-length values, derived from node-hl7-client's
|
|
3
3
|
* `createHL7Date` so it stays in sync with the upstream type. */
|
|
4
4
|
export type DateLength = Parameters<typeof createHL7Date>[1];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Inbound, InboundHandler, ListenerOptions, Server } from "node-hl7-server";
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
3
|
export declare class HL7Server extends EventEmitter {
|
|
4
4
|
private readonly _server;
|
package/dist/decorate.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
@@ -23,9 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
let fastify_plugin = require("fastify-plugin");
|
|
24
24
|
fastify_plugin = __toESM(fastify_plugin, 1);
|
|
25
25
|
let node_hl7_server = require("node-hl7-server");
|
|
26
|
-
node_hl7_server = __toESM(node_hl7_server, 1);
|
|
27
26
|
let node_hl7_client = require("node-hl7-client");
|
|
28
|
-
node_hl7_client = __toESM(node_hl7_client, 1);
|
|
29
27
|
let _fastify_error = require("@fastify/error");
|
|
30
28
|
_fastify_error = __toESM(_fastify_error, 1);
|
|
31
29
|
let node_events = require("node:events");
|
|
@@ -136,7 +134,7 @@ var HL7Client = class {
|
|
|
136
134
|
createClient(name, properties) {
|
|
137
135
|
if (/[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/.test(name)) throw new errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
|
|
138
136
|
for (const connections of this._clientConnections) if (connections.name === name) throw new errors.FASTIFY_HL7_ERR_USAGE("name must be unique.");
|
|
139
|
-
const client = new node_hl7_client.
|
|
137
|
+
const client = new node_hl7_client.Client(properties);
|
|
140
138
|
this._clientConnections.push({
|
|
141
139
|
client,
|
|
142
140
|
name,
|
|
@@ -322,7 +320,7 @@ const fastifyHL7 = (0, fastify_plugin.default)(async (fastify, options) => {
|
|
|
322
320
|
...options,
|
|
323
321
|
...generatedOptions
|
|
324
322
|
};
|
|
325
|
-
const serverInstance = options.enableServer !== void 0 && options.enableServer ? new node_hl7_server.
|
|
323
|
+
const serverInstance = options.enableServer !== void 0 && options.enableServer ? new node_hl7_server.Server(options.serverOptions) : void 0;
|
|
326
324
|
let server;
|
|
327
325
|
if (serverInstance !== void 0) {
|
|
328
326
|
server = new HL7Server(serverInstance);
|
|
@@ -399,5 +397,3 @@ const fastifyHL7 = (0, fastify_plugin.default)(async (fastify, options) => {
|
|
|
399
397
|
});
|
|
400
398
|
//#endregion
|
|
401
399
|
module.exports = fastifyHL7;
|
|
402
|
-
|
|
403
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fp from "fastify-plugin";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { Inbound, Server } from "node-hl7-server";
|
|
3
|
+
import { Batch, Client, Connection, FileBatch, HL7_2_1, HL7_2_2, HL7_2_3, HL7_2_3_1, HL7_2_4, HL7_2_5, HL7_2_5_1, HL7_2_6, HL7_2_7, HL7_2_7_1, HL7_2_8, Message, createHL7Date, isBatch } from "node-hl7-client";
|
|
4
4
|
import createError from "@fastify/error";
|
|
5
5
|
import { EventEmitter } from "node:events";
|
|
6
6
|
//#region src/errors.ts
|
|
@@ -373,5 +373,3 @@ const fastifyHL7 = fp(async (fastify, options) => {
|
|
|
373
373
|
});
|
|
374
374
|
//#endregion
|
|
375
375
|
export { fastifyHL7 as default };
|
|
376
|
-
|
|
377
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify-hl7",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "A Fastify HL7 Plugin Developed in Pure TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"clean": "rm -rf coverage docs dist temp",
|
|
32
32
|
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
33
33
|
"build:watch": "tsdown --watch",
|
|
34
|
+
"check:pack": "node scripts/checkPack.mjs",
|
|
34
35
|
"typecheck": "tsc --noEmit",
|
|
35
36
|
"lint": "eslint .",
|
|
36
37
|
"lint:fix": "eslint . --fix",
|
|
@@ -62,15 +63,15 @@
|
|
|
62
63
|
},
|
|
63
64
|
"homepage": "https://github.com/Bugs5382/fastify-hl7#readme",
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"@fastify/error": "^4.
|
|
66
|
-
"fastify-plugin": "^
|
|
67
|
-
"node-hl7-client": "^4.
|
|
68
|
-
"node-hl7-server": "^4.
|
|
66
|
+
"@fastify/error": "^4.2.0",
|
|
67
|
+
"fastify-plugin": "^6.0.0",
|
|
68
|
+
"node-hl7-client": "^4.1.1",
|
|
69
|
+
"node-hl7-server": "^4.1.1"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"@shipgirl/typedoc-plugin-versions": "^0.3.2",
|
|
72
73
|
"@the-rabbit-hole/eslint-config": "^0.4.0",
|
|
73
|
-
"@types/node": "^25.9.
|
|
74
|
+
"@types/node": "^25.9.3",
|
|
74
75
|
"@types/tcp-port-used": "^1.0.4",
|
|
75
76
|
"@vitest/coverage-v8": "^4.1.8",
|
|
76
77
|
"@vitest/ui": "^4.1.8",
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
"npm-check-updates": "^22.2.3",
|
|
80
81
|
"portfinder": "^1.0.38",
|
|
81
82
|
"pre-commit": "^2.0.0",
|
|
82
|
-
"prettier": "^3.8.
|
|
83
|
+
"prettier": "^3.8.4",
|
|
83
84
|
"tcp-port-used": "^1.0.3",
|
|
84
85
|
"tsd": "^0.33.0",
|
|
85
86
|
"tsdown": "^0.22.2",
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["HL7_2_1","HL7_2_2","HL7_2_3","HL7_2_3_1","HL7_2_4","HL7_2_5","HL7_2_5_1","HL7_2_6","HL7_2_7","HL7_2_7_1","HL7_2_8","Batch","FileBatch","Message","Client","Connection","EventEmitter","Inbound","validateOptions","Server"],"sources":["../src/errors.ts","../src/class/hL7Client.ts","../src/class/hL7Server.ts","../src/validation.ts","../src/index.ts"],"sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport createError from \"@fastify/error\";\n\nexport const errors = {\n /** Error if there is an setup error of the plugin itself. */\n FASTIFY_HL7_ERR_SETUP_ERRORS: createError(\n \"FASTIFY_HL7_ERR_SETUP_ERRORS\",\n \"Setup error: %s\",\n ),\n /** If an invalid usage error was done, this error would pop up. */\n FASTIFY_HL7_ERR_USAGE: createError(\n \"FASTIFY_HL7_ERR_USAGE\",\n \"Usage error: %s\",\n ),\n};\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport Client, {\n Batch,\n ClientBuilderFileOptions,\n ClientBuilderMessageOptions,\n ClientBuilderOptions,\n ClientListenerOptions,\n ClientOptions,\n Connection,\n createHL7Date,\n FileBatch,\n HL7_2_1,\n HL7_2_2,\n HL7_2_3,\n HL7_2_3_1,\n HL7_2_4,\n HL7_2_5,\n HL7_2_5_1,\n HL7_2_6,\n HL7_2_7,\n HL7_2_7_1,\n HL7_2_8,\n HL7Version,\n isBatch,\n Message,\n OutboundHandler,\n} from \"node-hl7-client\";\n\nimport { AClients } from \"../decorate.js\";\nimport { errors } from \"../errors.js\";\n\n/** Accepted HL7 date-length values, derived from node-hl7-client's\n * `createHL7Date` so it stays in sync with the upstream type. */\nexport type DateLength = Parameters<typeof createHL7Date>[1];\n\n/** Maps an `HL7Version` string to the matching node-hl7-client builder class,\n * so `createBuilder(\"2.7\")` returns a fully typed `HL7_2_7`. */\nexport interface HL7VersionBuilders {\n \"2.1\": HL7_2_1;\n \"2.2\": HL7_2_2;\n \"2.3\": HL7_2_3;\n \"2.3.1\": HL7_2_3_1;\n \"2.4\": HL7_2_4;\n \"2.5\": HL7_2_5;\n \"2.5.1\": HL7_2_5_1;\n \"2.6\": HL7_2_6;\n \"2.7\": HL7_2_7;\n \"2.7.1\": HL7_2_7_1;\n \"2.8\": HL7_2_8;\n}\n\n/** Runtime version -> builder-class lookup backing `createBuilder`. */\nconst HL7_BUILDERS = {\n \"2.1\": HL7_2_1,\n \"2.2\": HL7_2_2,\n \"2.3\": HL7_2_3,\n \"2.3.1\": HL7_2_3_1,\n \"2.4\": HL7_2_4,\n \"2.5\": HL7_2_5,\n \"2.5.1\": HL7_2_5_1,\n \"2.6\": HL7_2_6,\n \"2.7\": HL7_2_7,\n \"2.7.1\": HL7_2_7_1,\n \"2.8\": HL7_2_8,\n} as const;\n\nexport class HL7Client {\n /** @internal */\n private readonly _clientConnections: AClients[];\n\n constructor() {\n this._clientConnections = [];\n }\n\n /**\n * Build a HL7 Batch\n * @remarks Create a properly formatted HL7 Batch.\n * @since 1.0.0\n * @param props\n */\n buildBatch(properties?: ClientBuilderOptions): Batch {\n return new Batch({ ...properties });\n }\n\n /**\n * Build Date\n * @remarks Build a date string based off HL7 Standards\n * @since 2.1.0\n * @param date\n * @param length Options are 8, 12, or 14 (default)\n */\n buildDate(date: Date, length?: DateLength): string {\n return createHL7Date(date, length);\n }\n\n /**\n * Build a HL7 File Batch\n * @remarks Create a properly formatted HL7 File Batch.\n * @since 1.0.0\n * @param props\n */\n buildFileBatch(properties?: ClientBuilderFileOptions): FileBatch {\n if (\n properties !== undefined &&\n (properties.fullFilePath !== undefined ||\n properties.fileBuffer !== undefined)\n ) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"Use readFile or readFileBuffer method. This is for building.\",\n );\n }\n return new FileBatch({ ...properties });\n }\n\n /**\n * Build a HL7 Message\n * @remarks Create a properly formatted HL7 message.\n * @since 1.0.0\n * @param props\n */\n buildMessage(properties?: ClientBuilderMessageOptions): Message {\n if (properties !== undefined && properties.text !== undefined) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"Use processMessage method. This is for building.\",\n );\n }\n return new Message({ ...properties });\n }\n\n /**\n * Close All Connections for this Client\n * @since 1.0.0\n */\n async closeAll(): Promise<boolean> {\n for (const outbound of this._clientConnections) {\n outbound.ports.map(async (port) => {\n await port.connection.close();\n });\n }\n return true;\n }\n\n /**\n * Create a version-pinned HL7 message builder\n * @remarks Returns the node-hl7-client builder for the given HL7 version, with\n * per-version field validation (withdrawn fields throw, backward-compatibility\n * fields warn, segments not in that version are rejected). Chain `build*`\n * methods and finish with `toMessage()`.\n * @since 4.0.0\n * @param version One of the supported HL7 versions (\"2.1\" - \"2.8\").\n * @param properties Optional builder options (date format, separators, hardError).\n * @example\n * ```ts\n * const message = fastify.hl7.createBuilder(\"2.7\")\n * .buildMSH({ msh_9_1: \"ADT\", msh_9_2: \"A01\", msh_11_1: \"P\" })\n * .buildPID({ pid_3: \"MRN12345\", pid_5: \"DOE^JANE^A\" })\n * .toMessage();\n * ```\n */\n createBuilder<V extends HL7Version>(\n version: V,\n properties?: ClientBuilderOptions,\n ): HL7VersionBuilders[V] {\n const Builder = HL7_BUILDERS[version] as new (\n properties?: ClientBuilderOptions,\n ) => HL7VersionBuilders[V];\n return new Builder(properties);\n }\n\n /**\n *\n * @param name\n * @param props\n */\n createClient(name: string, properties: ClientOptions): Client {\n const nameFormat = /[ `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~]/;\n if (nameFormat.test(name)) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"name must not contain certain characters: `!@#$%^&*()+\\\\-=\\\\[\\\\]{};':\\\"\\\\\\\\|,.<>\\\\/?~.\",\n );\n }\n\n // make sure that this does not exist already...\n for (const connections of this._clientConnections) {\n if (connections.name === name) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\"name must be unique.\");\n }\n // nto in the Client class yet\n // if (client.getHost() === props.host) {\n // throw new errors.FASTIFY_HL7_ERR_USAGE(`host is already a pointer. Name is: ${connections.name}`)\n // }\n }\n\n // new client\n const client = new Client(properties);\n\n // add it to the collection\n this._clientConnections.push({\n client,\n name,\n ports: [],\n });\n\n return client;\n }\n\n /**\n * Create an HL7 Outbound Connection\n * @remarks Connect to an HL7 Server/Broker\n * @since 1.0.0\n * @param name The name stored within created client connections.\n * @param props\n * @param handler\n */\n createConnection(\n name: string,\n properties: ClientListenerOptions,\n handler: OutboundHandler,\n ): Connection {\n const nameFormat = /[ `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~]/;\n if (nameFormat.test(name)) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"name must not contain certain characters: `!@#$%^&*()+\\\\-=\\\\[\\\\]{};':\\\"\\\\\\\\|,.<>\\\\/?~.\",\n );\n }\n\n const getConnection = this._clientConnections.find(\n (client) => client.name === name,\n );\n\n if (getConnection !== undefined) {\n // make sure port is not used all ready\n for (const outbound of getConnection.ports) {\n if (outbound.port === properties.port.toString()) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n `port ${properties.port} is already used with this client. Choose a new outgoing port.`,\n );\n }\n }\n\n // create outbound port to the server in getConnection.client\n const outbound = new Connection(\n getConnection.client,\n properties,\n handler,\n );\n\n // add it to the array of known ports. need to know this, so we can get it later if needed.\n getConnection.ports.push({\n connection: outbound,\n port: properties.port.toString(),\n });\n\n // return it right away. the user might do something with it.\n return outbound;\n }\n\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"No valid client. Improper setup of a outbound connection.\",\n );\n }\n\n /**\n * Get Client by the name\n * @since 1.0.0\n * @param name\n */\n getClientByName(name: string): Client | undefined {\n const connection = this._clientConnections.find(\n (connection) => connection.name === name,\n );\n if (connection !== undefined) {\n return connection.client;\n }\n return undefined;\n }\n\n /**\n * Get Connection by Port\n * @since 1.0.0\n * @param port\n */\n getClientConnectionByPort(port: string): Connection | undefined {\n let connection: Connection | undefined;\n for (const outbound of this._clientConnections) {\n for (const aPort of outbound.ports) {\n if (aPort.port === port) {\n connection = aPort.connection;\n }\n }\n }\n return connection;\n }\n\n /**\n * Process a HL7\n * @remarks A HL7 message that could either be a Message (MSH) or Batch (BHS)\n * @since 1.0.0\n * @param text Raw HL& String\n */\n processHL7(text: string): Batch | Message {\n return isBatch(text) ? new Batch({ text }) : new Message({ text });\n }\n\n /**\n * Read File\n * @remarks Pass the correct path of the file you want to read.\n * @since 1.0.0\n * @param fullFilePath\n * @returns FileBatch\n * @example\n * ```ts\n * fastify.hl7.readFile( path.join('temp/', 'hl7.readTestBHS.20231208.hl7') )\n * ```\n */\n readFile(fullFilePath: string): FileBatch {\n return new FileBatch({ fullFilePath });\n }\n\n /**\n * Read a File Buffer\n * @remarks Translate an already Buffered HL7 FHS segment to decode it.\n * @since 1.0.0\n * @param fileBuffer\n * @returns FileBatch\n * @example\n * ```ts\n * const fileBuffer = fs.readFileSync(path.join('temp/', 'hl7.readTestBHS.20231208.hl7'))\n * fastify.hl7.readFileBuffer(fileBuffer)\n * ```\n */\n readFileBuffer(fileBuffer: Buffer): FileBatch {\n return new FileBatch({ fileBuffer });\n }\n}\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport Server, {\n Inbound,\n InboundHandler,\n ListenerOptions,\n} from \"node-hl7-server\";\nimport { EventEmitter } from \"node:events\";\n\nimport { AServers } from \"../decorate.js\";\nimport { errors } from \"../errors.js\";\n\nexport class HL7Server extends EventEmitter {\n private readonly _server: Server;\n private readonly _serverInboundConnections: AServers[];\n\n constructor(server: Server) {\n super();\n this._server = server;\n this._serverInboundConnections = [];\n }\n\n /**\n * Close Inbound connection.\n * @since 1.0.0\n * @param port\n */\n async close(port: string): Promise<boolean> {\n const inbound = this._serverInboundConnections.find(\n (server) => server.port === port,\n );\n if (inbound !== undefined) {\n return await inbound.server.close(); // close the server for all inbound connections\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n `No inbound server listening on port: ${port}`,\n );\n }\n\n /**\n * Close all Inbound connections.\n * @since 1.0.0\n */\n async closeAll(): Promise<boolean> {\n this._serverInboundConnections.map(async (inbound) => {\n await inbound.server.close();\n });\n return true;\n }\n\n /**\n * Create Inbound connection.\n * @since 1.0.0\n * @param name\n * @param props\n * @param handler\n */\n createInbound(\n name: string,\n properties: ListenerOptions,\n handler: InboundHandler,\n ): Inbound {\n const nameFormat = /[ `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~]/;\n if (nameFormat.test(name)) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"name must not contain certain characters: `!@#$%^&*()+\\\\-=\\\\[\\\\]{};':\\\"\\\\\\\\|,.<>\\\\/?~.\",\n );\n }\n\n const inbound = new Inbound(this._server, properties, handler);\n\n this._serverInboundConnections.push({\n name,\n port: properties.port.toString(),\n server: inbound,\n });\n\n this.emit(\"inbound\", properties.port.toString());\n\n return inbound;\n }\n\n /**\n * Get Server Inbound Connection by Name\n * @since 1.0.0\n * @param name\n */\n getServerByName(name: string): Inbound | undefined {\n const inbound = this._serverInboundConnections.find(\n (inbound) => inbound.name === name,\n );\n if (inbound !== undefined) {\n return inbound.server;\n }\n return undefined;\n }\n\n /**\n * Get Server Inbound Connection by Port\n * @since 1.0.0\n * @param port\n */\n getServerByPort(port: string): Inbound | undefined {\n const inbound = this._serverInboundConnections.find(\n (inbound) => inbound.port === port,\n );\n if (inbound !== undefined) {\n return inbound.server;\n }\n return undefined;\n }\n}\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport { FastifyHL7Options } from \"./decorate.js\";\n\n/**\n * @since 1.0.0\n * @param opts\n */\nexport const validateOpts = async (\n options: FastifyHL7Options,\n): Promise<FastifyHL7Options> => {\n // Mandatory, Defaulted\n if (options.enableServer === undefined) {\n options.enableServer = true;\n }\n\n return options;\n};\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport { FastifyInstance, HL7 } from \"fastify\";\nimport fp from \"fastify-plugin\";\nimport Client, {\n Batch,\n ClientBuilderFileOptions,\n ClientBuilderMessageOptions,\n ClientBuilderOptions,\n Connection,\n FileBatch,\n HL7Version,\n Message,\n} from \"node-hl7-client\";\nimport Server, {\n Inbound,\n InboundHandler,\n ListenerOptions,\n} from \"node-hl7-server\";\n\nimport type { FastifyHL7Options } from \"./decorate.js\";\n\nimport {\n type DateLength,\n HL7Client,\n type HL7VersionBuilders,\n} from \"./class/hL7Client.js\";\nimport { HL7Server } from \"./class/hL7Server.js\";\nimport { errors } from \"./errors.js\";\nimport { validateOpts as validateOptions } from \"./validation.js\";\nexport { type FastifyHL7Options } from \"./decorate.js\";\n\n/**\n * @since 1.0.0\n * @param fastify\n * @param _opts\n * @param connection\n */\nconst decorateFastifyInstance = (\n fastify: FastifyInstance,\n _options: FastifyHL7Options,\n connection: HL7,\n): void => {\n if (fastify.hl7 !== undefined) {\n throw new errors.FASTIFY_HL7_ERR_SETUP_ERRORS(\"Already registered.\");\n }\n\n if (fastify.hl7 === undefined) {\n fastify.log.trace(\"[fastify-hl7] Decorate Fastify\");\n fastify.decorate(\"hl7\", connection);\n }\n};\n\nconst fastifyHL7 = fp<FastifyHL7Options>(async (fastify, options) => {\n const generatedOptions = await validateOptions(options);\n options = { ...options, ...generatedOptions };\n\n // Create server.\n // Since there can only be one server per IP address\n // (i.e., the host this is running on.) There can only be more than one.\n // A server can host many HL7 Inbound connections via different ports, this is fine.\n // Clients are different as an app could talk to different servers, on many ports.\n // So we need to do something different.\n const serverInstance =\n options.enableServer !== undefined && options.enableServer\n ? new Server(options.serverOptions)\n : undefined;\n\n // Server Functions\n let server: HL7Server | undefined;\n if (serverInstance !== undefined) {\n // Server Functions\n server = new HL7Server(serverInstance);\n\n server.on(\"inbound\", (port: string) => {\n fastify.log.info(\"HL7 Inbound Server Listening on Port %s\", port);\n });\n\n // before we close fastify, make sure all server instances are closed\n fastify.addHook(\"preClose\", async () => {\n if (server !== undefined) {\n await server.closeAll();\n }\n });\n }\n\n // Client Functions\n const client = new HL7Client();\n\n // run these before fastify closes\n fastify.addHook(\"preClose\", async () => {\n if (client !== undefined) {\n await client.closeAll();\n }\n });\n\n decorateFastifyInstance(fastify, options, {\n _serverInstance: serverInstance,\n buildBatch: function (properties: ClientBuilderOptions | undefined): Batch {\n return client.buildBatch(properties);\n },\n buildDate: function (date: Date, length?: DateLength): string {\n return client.buildDate(date, length);\n },\n buildFileBatch: function (\n properties: ClientBuilderFileOptions | undefined,\n ): FileBatch {\n return client.buildFileBatch(properties);\n },\n buildMessage: function (\n properties: ClientBuilderMessageOptions | undefined,\n ): Message {\n return client.buildMessage(properties);\n },\n closeServer: async function (port: string): Promise<boolean> {\n if (server !== undefined) {\n return await server.close(port);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n closeServerAll: async (): Promise<boolean> => {\n if (server !== undefined) {\n return await server.closeAll();\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n createBuilder: function <V extends HL7Version>(\n version: V,\n properties?: ClientBuilderOptions,\n ): HL7VersionBuilders[V] {\n return client.createBuilder(version, properties);\n },\n createClient: function (name, properties): Client {\n return client.createClient(name, properties);\n },\n createConnection: function (name, properties, handler) {\n return client.createConnection(name, properties, handler);\n },\n createInbound: function (\n name: string,\n properties: ListenerOptions,\n handler: InboundHandler,\n ): Inbound {\n if (server !== undefined) {\n return server.createInbound(name, properties, handler);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n getClientByName: function (name: string): Client | undefined {\n return client.getClientByName(name);\n },\n getClientConnectionByPort: function (port: string): Connection | undefined {\n return client.getClientConnectionByPort(port);\n },\n getServerByName: function (name: string): Inbound | undefined {\n if (server !== undefined) {\n return server.getServerByName(name);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n getServerByPort: function (port: string): Inbound | undefined {\n if (server !== undefined) {\n return server.getServerByPort(port);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n processHL7: function (text: string): Batch | Message {\n return client.processHL7(text);\n },\n readFile: function (fullFilePath: string): FileBatch {\n return client.readFile(fullFilePath);\n },\n readFileBuffer: function (fileBuffer: Buffer): FileBatch {\n return client.readFileBuffer(fileBuffer);\n },\n });\n});\n\nexport default fastifyHL7;\n\nexport * from \"./types.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,SAAS;;CAEpB,+BAAA,GAAA,eAAA,QAAA,CACE,gCACA,iBACF;;CAEA,wBAAA,GAAA,eAAA,QAAA,CACE,yBACA,iBACF;AACF;;;;ACsCA,MAAM,eAAe;CACnB,OAAOA,gBAAAA;CACP,OAAOC,gBAAAA;CACP,OAAOC,gBAA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1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["validateOptions"],"sources":["../src/errors.ts","../src/class/hL7Client.ts","../src/class/hL7Server.ts","../src/validation.ts","../src/index.ts"],"sourcesContent":["/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport createError from \"@fastify/error\";\n\nexport const errors = {\n /** Error if there is an setup error of the plugin itself. */\n FASTIFY_HL7_ERR_SETUP_ERRORS: createError(\n \"FASTIFY_HL7_ERR_SETUP_ERRORS\",\n \"Setup error: %s\",\n ),\n /** If an invalid usage error was done, this error would pop up. */\n FASTIFY_HL7_ERR_USAGE: createError(\n \"FASTIFY_HL7_ERR_USAGE\",\n \"Usage error: %s\",\n ),\n};\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport Client, {\n Batch,\n ClientBuilderFileOptions,\n ClientBuilderMessageOptions,\n ClientBuilderOptions,\n ClientListenerOptions,\n ClientOptions,\n Connection,\n createHL7Date,\n FileBatch,\n HL7_2_1,\n HL7_2_2,\n HL7_2_3,\n HL7_2_3_1,\n HL7_2_4,\n HL7_2_5,\n HL7_2_5_1,\n HL7_2_6,\n HL7_2_7,\n HL7_2_7_1,\n HL7_2_8,\n HL7Version,\n isBatch,\n Message,\n OutboundHandler,\n} from \"node-hl7-client\";\n\nimport { AClients } from \"../decorate.js\";\nimport { errors } from \"../errors.js\";\n\n/** Accepted HL7 date-length values, derived from node-hl7-client's\n * `createHL7Date` so it stays in sync with the upstream type. */\nexport type DateLength = Parameters<typeof createHL7Date>[1];\n\n/** Maps an `HL7Version` string to the matching node-hl7-client builder class,\n * so `createBuilder(\"2.7\")` returns a fully typed `HL7_2_7`. */\nexport interface HL7VersionBuilders {\n \"2.1\": HL7_2_1;\n \"2.2\": HL7_2_2;\n \"2.3\": HL7_2_3;\n \"2.3.1\": HL7_2_3_1;\n \"2.4\": HL7_2_4;\n \"2.5\": HL7_2_5;\n \"2.5.1\": HL7_2_5_1;\n \"2.6\": HL7_2_6;\n \"2.7\": HL7_2_7;\n \"2.7.1\": HL7_2_7_1;\n \"2.8\": HL7_2_8;\n}\n\n/** Runtime version -> builder-class lookup backing `createBuilder`. */\nconst HL7_BUILDERS = {\n \"2.1\": HL7_2_1,\n \"2.2\": HL7_2_2,\n \"2.3\": HL7_2_3,\n \"2.3.1\": HL7_2_3_1,\n \"2.4\": HL7_2_4,\n \"2.5\": HL7_2_5,\n \"2.5.1\": HL7_2_5_1,\n \"2.6\": HL7_2_6,\n \"2.7\": HL7_2_7,\n \"2.7.1\": HL7_2_7_1,\n \"2.8\": HL7_2_8,\n} as const;\n\nexport class HL7Client {\n /** @internal */\n private readonly _clientConnections: AClients[];\n\n constructor() {\n this._clientConnections = [];\n }\n\n /**\n * Build a HL7 Batch\n * @remarks Create a properly formatted HL7 Batch.\n * @since 1.0.0\n * @param props\n */\n buildBatch(properties?: ClientBuilderOptions): Batch {\n return new Batch({ ...properties });\n }\n\n /**\n * Build Date\n * @remarks Build a date string based off HL7 Standards\n * @since 2.1.0\n * @param date\n * @param length Options are 8, 12, or 14 (default)\n */\n buildDate(date: Date, length?: DateLength): string {\n return createHL7Date(date, length);\n }\n\n /**\n * Build a HL7 File Batch\n * @remarks Create a properly formatted HL7 File Batch.\n * @since 1.0.0\n * @param props\n */\n buildFileBatch(properties?: ClientBuilderFileOptions): FileBatch {\n if (\n properties !== undefined &&\n (properties.fullFilePath !== undefined ||\n properties.fileBuffer !== undefined)\n ) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"Use readFile or readFileBuffer method. This is for building.\",\n );\n }\n return new FileBatch({ ...properties });\n }\n\n /**\n * Build a HL7 Message\n * @remarks Create a properly formatted HL7 message.\n * @since 1.0.0\n * @param props\n */\n buildMessage(properties?: ClientBuilderMessageOptions): Message {\n if (properties !== undefined && properties.text !== undefined) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"Use processMessage method. This is for building.\",\n );\n }\n return new Message({ ...properties });\n }\n\n /**\n * Close All Connections for this Client\n * @since 1.0.0\n */\n async closeAll(): Promise<boolean> {\n for (const outbound of this._clientConnections) {\n outbound.ports.map(async (port) => {\n await port.connection.close();\n });\n }\n return true;\n }\n\n /**\n * Create a version-pinned HL7 message builder\n * @remarks Returns the node-hl7-client builder for the given HL7 version, with\n * per-version field validation (withdrawn fields throw, backward-compatibility\n * fields warn, segments not in that version are rejected). Chain `build*`\n * methods and finish with `toMessage()`.\n * @since 4.0.0\n * @param version One of the supported HL7 versions (\"2.1\" - \"2.8\").\n * @param properties Optional builder options (date format, separators, hardError).\n * @example\n * ```ts\n * const message = fastify.hl7.createBuilder(\"2.7\")\n * .buildMSH({ msh_9_1: \"ADT\", msh_9_2: \"A01\", msh_11_1: \"P\" })\n * .buildPID({ pid_3: \"MRN12345\", pid_5: \"DOE^JANE^A\" })\n * .toMessage();\n * ```\n */\n createBuilder<V extends HL7Version>(\n version: V,\n properties?: ClientBuilderOptions,\n ): HL7VersionBuilders[V] {\n const Builder = HL7_BUILDERS[version] as new (\n properties?: ClientBuilderOptions,\n ) => HL7VersionBuilders[V];\n return new Builder(properties);\n }\n\n /**\n *\n * @param name\n * @param props\n */\n createClient(name: string, properties: ClientOptions): Client {\n const nameFormat = /[ `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~]/;\n if (nameFormat.test(name)) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"name must not contain certain characters: `!@#$%^&*()+\\\\-=\\\\[\\\\]{};':\\\"\\\\\\\\|,.<>\\\\/?~.\",\n );\n }\n\n // make sure that this does not exist already...\n for (const connections of this._clientConnections) {\n if (connections.name === name) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\"name must be unique.\");\n }\n // nto in the Client class yet\n // if (client.getHost() === props.host) {\n // throw new errors.FASTIFY_HL7_ERR_USAGE(`host is already a pointer. Name is: ${connections.name}`)\n // }\n }\n\n // new client\n const client = new Client(properties);\n\n // add it to the collection\n this._clientConnections.push({\n client,\n name,\n ports: [],\n });\n\n return client;\n }\n\n /**\n * Create an HL7 Outbound Connection\n * @remarks Connect to an HL7 Server/Broker\n * @since 1.0.0\n * @param name The name stored within created client connections.\n * @param props\n * @param handler\n */\n createConnection(\n name: string,\n properties: ClientListenerOptions,\n handler: OutboundHandler,\n ): Connection {\n const nameFormat = /[ `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~]/;\n if (nameFormat.test(name)) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"name must not contain certain characters: `!@#$%^&*()+\\\\-=\\\\[\\\\]{};':\\\"\\\\\\\\|,.<>\\\\/?~.\",\n );\n }\n\n const getConnection = this._clientConnections.find(\n (client) => client.name === name,\n );\n\n if (getConnection !== undefined) {\n // make sure port is not used all ready\n for (const outbound of getConnection.ports) {\n if (outbound.port === properties.port.toString()) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n `port ${properties.port} is already used with this client. Choose a new outgoing port.`,\n );\n }\n }\n\n // create outbound port to the server in getConnection.client\n const outbound = new Connection(\n getConnection.client,\n properties,\n handler,\n );\n\n // add it to the array of known ports. need to know this, so we can get it later if needed.\n getConnection.ports.push({\n connection: outbound,\n port: properties.port.toString(),\n });\n\n // return it right away. the user might do something with it.\n return outbound;\n }\n\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"No valid client. Improper setup of a outbound connection.\",\n );\n }\n\n /**\n * Get Client by the name\n * @since 1.0.0\n * @param name\n */\n getClientByName(name: string): Client | undefined {\n const connection = this._clientConnections.find(\n (connection) => connection.name === name,\n );\n if (connection !== undefined) {\n return connection.client;\n }\n return undefined;\n }\n\n /**\n * Get Connection by Port\n * @since 1.0.0\n * @param port\n */\n getClientConnectionByPort(port: string): Connection | undefined {\n let connection: Connection | undefined;\n for (const outbound of this._clientConnections) {\n for (const aPort of outbound.ports) {\n if (aPort.port === port) {\n connection = aPort.connection;\n }\n }\n }\n return connection;\n }\n\n /**\n * Process a HL7\n * @remarks A HL7 message that could either be a Message (MSH) or Batch (BHS)\n * @since 1.0.0\n * @param text Raw HL& String\n */\n processHL7(text: string): Batch | Message {\n return isBatch(text) ? new Batch({ text }) : new Message({ text });\n }\n\n /**\n * Read File\n * @remarks Pass the correct path of the file you want to read.\n * @since 1.0.0\n * @param fullFilePath\n * @returns FileBatch\n * @example\n * ```ts\n * fastify.hl7.readFile( path.join('temp/', 'hl7.readTestBHS.20231208.hl7') )\n * ```\n */\n readFile(fullFilePath: string): FileBatch {\n return new FileBatch({ fullFilePath });\n }\n\n /**\n * Read a File Buffer\n * @remarks Translate an already Buffered HL7 FHS segment to decode it.\n * @since 1.0.0\n * @param fileBuffer\n * @returns FileBatch\n * @example\n * ```ts\n * const fileBuffer = fs.readFileSync(path.join('temp/', 'hl7.readTestBHS.20231208.hl7'))\n * fastify.hl7.readFileBuffer(fileBuffer)\n * ```\n */\n readFileBuffer(fileBuffer: Buffer): FileBatch {\n return new FileBatch({ fileBuffer });\n }\n}\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport Server, {\n Inbound,\n InboundHandler,\n ListenerOptions,\n} from \"node-hl7-server\";\nimport { EventEmitter } from \"node:events\";\n\nimport { AServers } from \"../decorate.js\";\nimport { errors } from \"../errors.js\";\n\nexport class HL7Server extends EventEmitter {\n private readonly _server: Server;\n private readonly _serverInboundConnections: AServers[];\n\n constructor(server: Server) {\n super();\n this._server = server;\n this._serverInboundConnections = [];\n }\n\n /**\n * Close Inbound connection.\n * @since 1.0.0\n * @param port\n */\n async close(port: string): Promise<boolean> {\n const inbound = this._serverInboundConnections.find(\n (server) => server.port === port,\n );\n if (inbound !== undefined) {\n return await inbound.server.close(); // close the server for all inbound connections\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n `No inbound server listening on port: ${port}`,\n );\n }\n\n /**\n * Close all Inbound connections.\n * @since 1.0.0\n */\n async closeAll(): Promise<boolean> {\n this._serverInboundConnections.map(async (inbound) => {\n await inbound.server.close();\n });\n return true;\n }\n\n /**\n * Create Inbound connection.\n * @since 1.0.0\n * @param name\n * @param props\n * @param handler\n */\n createInbound(\n name: string,\n properties: ListenerOptions,\n handler: InboundHandler,\n ): Inbound {\n const nameFormat = /[ `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~]/;\n if (nameFormat.test(name)) {\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"name must not contain certain characters: `!@#$%^&*()+\\\\-=\\\\[\\\\]{};':\\\"\\\\\\\\|,.<>\\\\/?~.\",\n );\n }\n\n const inbound = new Inbound(this._server, properties, handler);\n\n this._serverInboundConnections.push({\n name,\n port: properties.port.toString(),\n server: inbound,\n });\n\n this.emit(\"inbound\", properties.port.toString());\n\n return inbound;\n }\n\n /**\n * Get Server Inbound Connection by Name\n * @since 1.0.0\n * @param name\n */\n getServerByName(name: string): Inbound | undefined {\n const inbound = this._serverInboundConnections.find(\n (inbound) => inbound.name === name,\n );\n if (inbound !== undefined) {\n return inbound.server;\n }\n return undefined;\n }\n\n /**\n * Get Server Inbound Connection by Port\n * @since 1.0.0\n * @param port\n */\n getServerByPort(port: string): Inbound | undefined {\n const inbound = this._serverInboundConnections.find(\n (inbound) => inbound.port === port,\n );\n if (inbound !== undefined) {\n return inbound.server;\n }\n return undefined;\n }\n}\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport { FastifyHL7Options } from \"./decorate.js\";\n\n/**\n * @since 1.0.0\n * @param opts\n */\nexport const validateOpts = async (\n options: FastifyHL7Options,\n): Promise<FastifyHL7Options> => {\n // Mandatory, Defaulted\n if (options.enableServer === undefined) {\n options.enableServer = true;\n }\n\n return options;\n};\n","/*\nMIT License\n\nCopyright (c) 2026 Shane Froebel\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n*/\nimport { FastifyInstance, HL7 } from \"fastify\";\nimport fp from \"fastify-plugin\";\nimport Client, {\n Batch,\n ClientBuilderFileOptions,\n ClientBuilderMessageOptions,\n ClientBuilderOptions,\n Connection,\n FileBatch,\n HL7Version,\n Message,\n} from \"node-hl7-client\";\nimport Server, {\n Inbound,\n InboundHandler,\n ListenerOptions,\n} from \"node-hl7-server\";\n\nimport type { FastifyHL7Options } from \"./decorate.js\";\n\nimport {\n type DateLength,\n HL7Client,\n type HL7VersionBuilders,\n} from \"./class/hL7Client.js\";\nimport { HL7Server } from \"./class/hL7Server.js\";\nimport { errors } from \"./errors.js\";\nimport { validateOpts as validateOptions } from \"./validation.js\";\nexport { type FastifyHL7Options } from \"./decorate.js\";\n\n/**\n * @since 1.0.0\n * @param fastify\n * @param _opts\n * @param connection\n */\nconst decorateFastifyInstance = (\n fastify: FastifyInstance,\n _options: FastifyHL7Options,\n connection: HL7,\n): void => {\n if (fastify.hl7 !== undefined) {\n throw new errors.FASTIFY_HL7_ERR_SETUP_ERRORS(\"Already registered.\");\n }\n\n if (fastify.hl7 === undefined) {\n fastify.log.trace(\"[fastify-hl7] Decorate Fastify\");\n fastify.decorate(\"hl7\", connection);\n }\n};\n\nconst fastifyHL7 = fp<FastifyHL7Options>(async (fastify, options) => {\n const generatedOptions = await validateOptions(options);\n options = { ...options, ...generatedOptions };\n\n // Create server.\n // Since there can only be one server per IP address\n // (i.e., the host this is running on.) There can only be more than one.\n // A server can host many HL7 Inbound connections via different ports, this is fine.\n // Clients are different as an app could talk to different servers, on many ports.\n // So we need to do something different.\n const serverInstance =\n options.enableServer !== undefined && options.enableServer\n ? new Server(options.serverOptions)\n : undefined;\n\n // Server Functions\n let server: HL7Server | undefined;\n if (serverInstance !== undefined) {\n // Server Functions\n server = new HL7Server(serverInstance);\n\n server.on(\"inbound\", (port: string) => {\n fastify.log.info(\"HL7 Inbound Server Listening on Port %s\", port);\n });\n\n // before we close fastify, make sure all server instances are closed\n fastify.addHook(\"preClose\", async () => {\n if (server !== undefined) {\n await server.closeAll();\n }\n });\n }\n\n // Client Functions\n const client = new HL7Client();\n\n // run these before fastify closes\n fastify.addHook(\"preClose\", async () => {\n if (client !== undefined) {\n await client.closeAll();\n }\n });\n\n decorateFastifyInstance(fastify, options, {\n _serverInstance: serverInstance,\n buildBatch: function (properties: ClientBuilderOptions | undefined): Batch {\n return client.buildBatch(properties);\n },\n buildDate: function (date: Date, length?: DateLength): string {\n return client.buildDate(date, length);\n },\n buildFileBatch: function (\n properties: ClientBuilderFileOptions | undefined,\n ): FileBatch {\n return client.buildFileBatch(properties);\n },\n buildMessage: function (\n properties: ClientBuilderMessageOptions | undefined,\n ): Message {\n return client.buildMessage(properties);\n },\n closeServer: async function (port: string): Promise<boolean> {\n if (server !== undefined) {\n return await server.close(port);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n closeServerAll: async (): Promise<boolean> => {\n if (server !== undefined) {\n return await server.closeAll();\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n createBuilder: function <V extends HL7Version>(\n version: V,\n properties?: ClientBuilderOptions,\n ): HL7VersionBuilders[V] {\n return client.createBuilder(version, properties);\n },\n createClient: function (name, properties): Client {\n return client.createClient(name, properties);\n },\n createConnection: function (name, properties, handler) {\n return client.createConnection(name, properties, handler);\n },\n createInbound: function (\n name: string,\n properties: ListenerOptions,\n handler: InboundHandler,\n ): Inbound {\n if (server !== undefined) {\n return server.createInbound(name, properties, handler);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n getClientByName: function (name: string): Client | undefined {\n return client.getClientByName(name);\n },\n getClientConnectionByPort: function (port: string): Connection | undefined {\n return client.getClientConnectionByPort(port);\n },\n getServerByName: function (name: string): Inbound | undefined {\n if (server !== undefined) {\n return server.getServerByName(name);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n getServerByPort: function (port: string): Inbound | undefined {\n if (server !== undefined) {\n return server.getServerByPort(port);\n }\n throw new errors.FASTIFY_HL7_ERR_USAGE(\n \"server was not started. re-register plugin with enableServer set to true.\",\n );\n },\n processHL7: function (text: string): Batch | Message {\n return client.processHL7(text);\n },\n readFile: function (fullFilePath: string): FileBatch {\n return client.readFile(fullFilePath);\n },\n readFileBuffer: function (fileBuffer: Buffer): FileBatch {\n return client.readFileBuffer(fileBuffer);\n },\n });\n});\n\nexport default fastifyHL7;\n\nexport * from \"./types.js\";\n"],"mappings":";;;;;;AAwBA,MAAa,SAAS;;CAEpB,8BAA8B,YAC5B,gCACA,iBACF;;CAEA,uBAAuB,YACrB,yBACA,iBACF;AACF;;;;ACsCA,MAAM,eAAe;CACnB,OAAO;CACP,OAAO;CACP,OAAO;CACP,SAAS;CACT,OAAO;CACP,OAAO;CACP,SAAS;CACT,OAAO;CACP,OAAO;CACP,SAAS;CACT,OAAO;AACT;AAEA,IAAa,YAAb,MAAuB;;CAErB;CAEA,cAAc;EACZ,KAAK,qBAAqB,CAAC;CAC7B;;;;;;;CAQA,WAAW,YAA0C;EACnD,OAAO,IAAI,MAAM,EAAE,GAAG,WAAW,CAAC;CACpC;;;;;;;;CASA,UAAU,MAAY,QAA6B;EACjD,OAAO,cAAc,MAAM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