fastify-hl7 3.3.0 → 4.0.1

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +316 -0
  2. package/README.md +535 -60
  3. package/dist/api.d.ts +5 -0
  4. package/{lib/types → dist}/class/hL7Client.d.ts +49 -13
  5. package/{lib/esm → dist}/class/hL7Server.d.ts +2 -2
  6. package/dist/index.cjs +403 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/{lib/types → dist}/index.d.ts +3 -3
  9. package/dist/index.mjs +377 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/{lib/esm → dist}/types.d.ts +26 -20
  12. package/dist/validation.d.ts +6 -0
  13. package/package.json +44 -50
  14. package/lib/cjs/api.js +0 -13
  15. package/lib/cjs/class/hL7Client.js +0 -238
  16. package/lib/cjs/class/hL7Server.js +0 -81
  17. package/lib/cjs/decorate.js +0 -2
  18. package/lib/cjs/errors.js +0 -13
  19. package/lib/cjs/index.js +0 -144
  20. package/lib/cjs/package.json +0 -3
  21. package/lib/cjs/types.js +0 -2
  22. package/lib/cjs/validation.js +0 -15
  23. package/lib/esm/api.d.ts +0 -7
  24. package/lib/esm/api.js +0 -5
  25. package/lib/esm/class/hL7Client.d.ts +0 -99
  26. package/lib/esm/class/hL7Client.js +0 -201
  27. package/lib/esm/class/hL7Server.js +0 -77
  28. package/lib/esm/decorate.js +0 -1
  29. package/lib/esm/errors.js +0 -7
  30. package/lib/esm/index.d.ts +0 -5
  31. package/lib/esm/index.js +0 -125
  32. package/lib/esm/package.json +0 -3
  33. package/lib/esm/types.js +0 -1
  34. package/lib/esm/validation.d.ts +0 -6
  35. package/lib/esm/validation.js +0 -11
  36. package/lib/types/api.d.ts +0 -7
  37. package/lib/types/class/hL7Server.d.ts +0 -38
  38. package/lib/types/decorate.d.ts +0 -38
  39. package/lib/types/errors.d.ts +0 -10
  40. package/lib/types/types.d.ts +0 -69
  41. package/lib/types/validation.d.ts +0 -6
  42. package/{lib/esm → dist}/decorate.d.ts +16 -16
  43. /package/{lib/esm → dist}/errors.d.ts +0 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,377 @@
1
+ import fp from "fastify-plugin";
2
+ import Server, { Inbound } from "node-hl7-server";
3
+ import Client, { Batch, 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
+ import createError from "@fastify/error";
5
+ import { EventEmitter } from "node:events";
6
+ //#region src/errors.ts
7
+ const errors = {
8
+ /** Error if there is an setup error of the plugin itself. */
9
+ FASTIFY_HL7_ERR_SETUP_ERRORS: createError("FASTIFY_HL7_ERR_SETUP_ERRORS", "Setup error: %s"),
10
+ /** If an invalid usage error was done, this error would pop up. */
11
+ FASTIFY_HL7_ERR_USAGE: createError("FASTIFY_HL7_ERR_USAGE", "Usage error: %s")
12
+ };
13
+ //#endregion
14
+ //#region src/class/hL7Client.ts
15
+ /** Runtime version -> builder-class lookup backing `createBuilder`. */
16
+ const HL7_BUILDERS = {
17
+ "2.1": HL7_2_1,
18
+ "2.2": HL7_2_2,
19
+ "2.3": HL7_2_3,
20
+ "2.3.1": HL7_2_3_1,
21
+ "2.4": HL7_2_4,
22
+ "2.5": HL7_2_5,
23
+ "2.5.1": HL7_2_5_1,
24
+ "2.6": HL7_2_6,
25
+ "2.7": HL7_2_7,
26
+ "2.7.1": HL7_2_7_1,
27
+ "2.8": HL7_2_8
28
+ };
29
+ var HL7Client = class {
30
+ /** @internal */
31
+ _clientConnections;
32
+ constructor() {
33
+ this._clientConnections = [];
34
+ }
35
+ /**
36
+ * Build a HL7 Batch
37
+ * @remarks Create a properly formatted HL7 Batch.
38
+ * @since 1.0.0
39
+ * @param props
40
+ */
41
+ buildBatch(properties) {
42
+ return new Batch({ ...properties });
43
+ }
44
+ /**
45
+ * Build Date
46
+ * @remarks Build a date string based off HL7 Standards
47
+ * @since 2.1.0
48
+ * @param date
49
+ * @param length Options are 8, 12, or 14 (default)
50
+ */
51
+ buildDate(date, length) {
52
+ return createHL7Date(date, length);
53
+ }
54
+ /**
55
+ * Build a HL7 File Batch
56
+ * @remarks Create a properly formatted HL7 File Batch.
57
+ * @since 1.0.0
58
+ * @param props
59
+ */
60
+ buildFileBatch(properties) {
61
+ if (properties !== void 0 && (properties.fullFilePath !== void 0 || properties.fileBuffer !== void 0)) throw new errors.FASTIFY_HL7_ERR_USAGE("Use readFile or readFileBuffer method. This is for building.");
62
+ return new FileBatch({ ...properties });
63
+ }
64
+ /**
65
+ * Build a HL7 Message
66
+ * @remarks Create a properly formatted HL7 message.
67
+ * @since 1.0.0
68
+ * @param props
69
+ */
70
+ buildMessage(properties) {
71
+ if (properties !== void 0 && properties.text !== void 0) throw new errors.FASTIFY_HL7_ERR_USAGE("Use processMessage method. This is for building.");
72
+ return new Message({ ...properties });
73
+ }
74
+ /**
75
+ * Close All Connections for this Client
76
+ * @since 1.0.0
77
+ */
78
+ async closeAll() {
79
+ for (const outbound of this._clientConnections) outbound.ports.map(async (port) => {
80
+ await port.connection.close();
81
+ });
82
+ return true;
83
+ }
84
+ /**
85
+ * Create a version-pinned HL7 message builder
86
+ * @remarks Returns the node-hl7-client builder for the given HL7 version, with
87
+ * per-version field validation (withdrawn fields throw, backward-compatibility
88
+ * fields warn, segments not in that version are rejected). Chain `build*`
89
+ * methods and finish with `toMessage()`.
90
+ * @since 4.0.0
91
+ * @param version One of the supported HL7 versions ("2.1" - "2.8").
92
+ * @param properties Optional builder options (date format, separators, hardError).
93
+ * @example
94
+ * ```ts
95
+ * const message = fastify.hl7.createBuilder("2.7")
96
+ * .buildMSH({ msh_9_1: "ADT", msh_9_2: "A01", msh_11_1: "P" })
97
+ * .buildPID({ pid_3: "MRN12345", pid_5: "DOE^JANE^A" })
98
+ * .toMessage();
99
+ * ```
100
+ */
101
+ createBuilder(version, properties) {
102
+ const Builder = HL7_BUILDERS[version];
103
+ return new Builder(properties);
104
+ }
105
+ /**
106
+ *
107
+ * @param name
108
+ * @param props
109
+ */
110
+ createClient(name, properties) {
111
+ if (/[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/.test(name)) throw new errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
112
+ for (const connections of this._clientConnections) if (connections.name === name) throw new errors.FASTIFY_HL7_ERR_USAGE("name must be unique.");
113
+ const client = new Client(properties);
114
+ this._clientConnections.push({
115
+ client,
116
+ name,
117
+ ports: []
118
+ });
119
+ return client;
120
+ }
121
+ /**
122
+ * Create an HL7 Outbound Connection
123
+ * @remarks Connect to an HL7 Server/Broker
124
+ * @since 1.0.0
125
+ * @param name The name stored within created client connections.
126
+ * @param props
127
+ * @param handler
128
+ */
129
+ createConnection(name, properties, handler) {
130
+ if (/[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/.test(name)) throw new errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
131
+ const getConnection = this._clientConnections.find((client) => client.name === name);
132
+ if (getConnection !== void 0) {
133
+ for (const outbound of getConnection.ports) if (outbound.port === properties.port.toString()) throw new errors.FASTIFY_HL7_ERR_USAGE(`port ${properties.port} is already used with this client. Choose a new outgoing port.`);
134
+ const outbound = new Connection(getConnection.client, properties, handler);
135
+ getConnection.ports.push({
136
+ connection: outbound,
137
+ port: properties.port.toString()
138
+ });
139
+ return outbound;
140
+ }
141
+ throw new errors.FASTIFY_HL7_ERR_USAGE("No valid client. Improper setup of a outbound connection.");
142
+ }
143
+ /**
144
+ * Get Client by the name
145
+ * @since 1.0.0
146
+ * @param name
147
+ */
148
+ getClientByName(name) {
149
+ const connection = this._clientConnections.find((connection) => connection.name === name);
150
+ if (connection !== void 0) return connection.client;
151
+ }
152
+ /**
153
+ * Get Connection by Port
154
+ * @since 1.0.0
155
+ * @param port
156
+ */
157
+ getClientConnectionByPort(port) {
158
+ let connection;
159
+ for (const outbound of this._clientConnections) for (const aPort of outbound.ports) if (aPort.port === port) connection = aPort.connection;
160
+ return connection;
161
+ }
162
+ /**
163
+ * Process a HL7
164
+ * @remarks A HL7 message that could either be a Message (MSH) or Batch (BHS)
165
+ * @since 1.0.0
166
+ * @param text Raw HL& String
167
+ */
168
+ processHL7(text) {
169
+ return isBatch(text) ? new Batch({ text }) : new Message({ text });
170
+ }
171
+ /**
172
+ * Read File
173
+ * @remarks Pass the correct path of the file you want to read.
174
+ * @since 1.0.0
175
+ * @param fullFilePath
176
+ * @returns FileBatch
177
+ * @example
178
+ * ```ts
179
+ * fastify.hl7.readFile( path.join('temp/', 'hl7.readTestBHS.20231208.hl7') )
180
+ * ```
181
+ */
182
+ readFile(fullFilePath) {
183
+ return new FileBatch({ fullFilePath });
184
+ }
185
+ /**
186
+ * Read a File Buffer
187
+ * @remarks Translate an already Buffered HL7 FHS segment to decode it.
188
+ * @since 1.0.0
189
+ * @param fileBuffer
190
+ * @returns FileBatch
191
+ * @example
192
+ * ```ts
193
+ * const fileBuffer = fs.readFileSync(path.join('temp/', 'hl7.readTestBHS.20231208.hl7'))
194
+ * fastify.hl7.readFileBuffer(fileBuffer)
195
+ * ```
196
+ */
197
+ readFileBuffer(fileBuffer) {
198
+ return new FileBatch({ fileBuffer });
199
+ }
200
+ };
201
+ //#endregion
202
+ //#region src/class/hL7Server.ts
203
+ var HL7Server = class extends EventEmitter {
204
+ _server;
205
+ _serverInboundConnections;
206
+ constructor(server) {
207
+ super();
208
+ this._server = server;
209
+ this._serverInboundConnections = [];
210
+ }
211
+ /**
212
+ * Close Inbound connection.
213
+ * @since 1.0.0
214
+ * @param port
215
+ */
216
+ async close(port) {
217
+ const inbound = this._serverInboundConnections.find((server) => server.port === port);
218
+ if (inbound !== void 0) return await inbound.server.close();
219
+ throw new errors.FASTIFY_HL7_ERR_USAGE(`No inbound server listening on port: ${port}`);
220
+ }
221
+ /**
222
+ * Close all Inbound connections.
223
+ * @since 1.0.0
224
+ */
225
+ async closeAll() {
226
+ this._serverInboundConnections.map(async (inbound) => {
227
+ await inbound.server.close();
228
+ });
229
+ return true;
230
+ }
231
+ /**
232
+ * Create Inbound connection.
233
+ * @since 1.0.0
234
+ * @param name
235
+ * @param props
236
+ * @param handler
237
+ */
238
+ createInbound(name, properties, handler) {
239
+ if (/[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/.test(name)) throw new errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
240
+ const inbound = new Inbound(this._server, properties, handler);
241
+ this._serverInboundConnections.push({
242
+ name,
243
+ port: properties.port.toString(),
244
+ server: inbound
245
+ });
246
+ this.emit("inbound", properties.port.toString());
247
+ return inbound;
248
+ }
249
+ /**
250
+ * Get Server Inbound Connection by Name
251
+ * @since 1.0.0
252
+ * @param name
253
+ */
254
+ getServerByName(name) {
255
+ const inbound = this._serverInboundConnections.find((inbound) => inbound.name === name);
256
+ if (inbound !== void 0) return inbound.server;
257
+ }
258
+ /**
259
+ * Get Server Inbound Connection by Port
260
+ * @since 1.0.0
261
+ * @param port
262
+ */
263
+ getServerByPort(port) {
264
+ const inbound = this._serverInboundConnections.find((inbound) => inbound.port === port);
265
+ if (inbound !== void 0) return inbound.server;
266
+ }
267
+ };
268
+ //#endregion
269
+ //#region src/validation.ts
270
+ /**
271
+ * @since 1.0.0
272
+ * @param opts
273
+ */
274
+ const validateOpts = async (options) => {
275
+ if (options.enableServer === void 0) options.enableServer = true;
276
+ return options;
277
+ };
278
+ //#endregion
279
+ //#region src/index.ts
280
+ /**
281
+ * @since 1.0.0
282
+ * @param fastify
283
+ * @param _opts
284
+ * @param connection
285
+ */
286
+ const decorateFastifyInstance = (fastify, _options, connection) => {
287
+ if (fastify.hl7 !== void 0) throw new errors.FASTIFY_HL7_ERR_SETUP_ERRORS("Already registered.");
288
+ if (fastify.hl7 === void 0) {
289
+ fastify.log.trace("[fastify-hl7] Decorate Fastify");
290
+ fastify.decorate("hl7", connection);
291
+ }
292
+ };
293
+ const fastifyHL7 = fp(async (fastify, options) => {
294
+ const generatedOptions = await validateOpts(options);
295
+ options = {
296
+ ...options,
297
+ ...generatedOptions
298
+ };
299
+ const serverInstance = options.enableServer !== void 0 && options.enableServer ? new Server(options.serverOptions) : void 0;
300
+ let server;
301
+ if (serverInstance !== void 0) {
302
+ server = new HL7Server(serverInstance);
303
+ server.on("inbound", (port) => {
304
+ fastify.log.info("HL7 Inbound Server Listening on Port %s", port);
305
+ });
306
+ fastify.addHook("preClose", async () => {
307
+ if (server !== void 0) await server.closeAll();
308
+ });
309
+ }
310
+ const client = new HL7Client();
311
+ fastify.addHook("preClose", async () => {
312
+ if (client !== void 0) await client.closeAll();
313
+ });
314
+ decorateFastifyInstance(fastify, options, {
315
+ _serverInstance: serverInstance,
316
+ buildBatch: function(properties) {
317
+ return client.buildBatch(properties);
318
+ },
319
+ buildDate: function(date, length) {
320
+ return client.buildDate(date, length);
321
+ },
322
+ buildFileBatch: function(properties) {
323
+ return client.buildFileBatch(properties);
324
+ },
325
+ buildMessage: function(properties) {
326
+ return client.buildMessage(properties);
327
+ },
328
+ closeServer: async function(port) {
329
+ if (server !== void 0) return await server.close(port);
330
+ throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
331
+ },
332
+ closeServerAll: async () => {
333
+ if (server !== void 0) return await server.closeAll();
334
+ throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
335
+ },
336
+ createBuilder: function(version, properties) {
337
+ return client.createBuilder(version, properties);
338
+ },
339
+ createClient: function(name, properties) {
340
+ return client.createClient(name, properties);
341
+ },
342
+ createConnection: function(name, properties, handler) {
343
+ return client.createConnection(name, properties, handler);
344
+ },
345
+ createInbound: function(name, properties, handler) {
346
+ if (server !== void 0) return server.createInbound(name, properties, handler);
347
+ throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
348
+ },
349
+ getClientByName: function(name) {
350
+ return client.getClientByName(name);
351
+ },
352
+ getClientConnectionByPort: function(port) {
353
+ return client.getClientConnectionByPort(port);
354
+ },
355
+ getServerByName: function(name) {
356
+ if (server !== void 0) return server.getServerByName(name);
357
+ throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
358
+ },
359
+ getServerByPort: function(port) {
360
+ if (server !== void 0) return server.getServerByPort(port);
361
+ throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
362
+ },
363
+ processHL7: function(text) {
364
+ return client.processHL7(text);
365
+ },
366
+ readFile: function(fullFilePath) {
367
+ return client.readFile(fullFilePath);
368
+ },
369
+ readFileBuffer: function(fileBuffer) {
370
+ return client.readFileBuffer(fileBuffer);
371
+ }
372
+ });
373
+ });
374
+ //#endregion
375
+ export { fastifyHL7 as default };
376
+
377
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
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,MAAM;CACnC;;;;;;;CAQA,eAAe,YAAkD;EAC/D,IACE,eAAe,KAAA,MACd,WAAW,iBAAiB,KAAA,KAC3B,WAAW,eAAe,KAAA,IAE5B,MAAM,IAAI,OAAO,sBACf,8DACF;EAEF,OAAO,IAAI,UAAU,EAAE,GAAG,WAAW,CAAC;CACxC;;;;;;;CAQA,aAAa,YAAmD;EAC9D,IAAI,eAAe,KAAA,KAAa,WAAW,SAAS,KAAA,GAClD,MAAM,IAAI,OAAO,sBACf,kDACF;EAEF,OAAO,IAAI,QAAQ,EAAE,GAAG,WAAW,CAAC;CACtC;;;;;CAMA,MAAM,WAA6B;EACjC,KAAK,MAAM,YAAY,KAAK,oBAC1B,SAAS,MAAM,IAAI,OAAO,SAAS;GACjC,MAAM,KAAK,WAAW,MAAM;EAC9B,CAAC;EAEH,OAAO;CAC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;GACnD,OAAO,OAAO,SAAS,YAAY;EACrC;EACA,gBAAgB,SAAU,YAA+B;GACvD,OAAO,OAAO,eAAe,UAAU;EACzC;CACF,CAAC;AACH,CAAC"}
@@ -1,58 +1,70 @@
1
+ import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, Connection, FileBatch, HL7Version, Message, OutboundHandler } from "node-hl7-client";
1
2
  import Server, { Inbound, InboundHandler, ListenerOptions } from "node-hl7-server";
2
- import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, Connection, FileBatch, Message, OutboundHandler } from "node-hl7-client";
3
+ import { DateLength, HL7VersionBuilders } from "./class/hL7Client.js";
3
4
  declare module "fastify" {
5
+ interface FastifyInstance {
6
+ /** Main Decorator for Fastify
7
+ * @remarks hl7 is the decorator that everything hangs off.
8
+ * @since 1.0.0 **/
9
+ hl7: HL7;
10
+ }
4
11
  interface HL7 {
5
12
  /** Server Instance
6
13
  * @since 1.0.0 **/
7
14
  _serverInstance?: Server;
8
15
  /** Build HL7 Batch
9
16
  * @since 1.0.0 */
10
- buildBatch: (props?: ClientBuilderOptions) => Batch;
17
+ buildBatch: (properties?: ClientBuilderOptions) => Batch;
11
18
  /** Build Date
12
19
  * @remarks Build a date string based off HL7 Standards
13
20
  * @param date
14
21
  * @param length Options are 8, 12, or 14 (default)
15
22
  * @since 2.1.0
16
23
  */
17
- buildDate: (date: Date, length?: string) => string;
24
+ buildDate: (date: Date, length?: DateLength) => string;
18
25
  /** Build HL7 File Batch
19
26
  * @since 1.0.0 */
20
- buildFileBatch: (props?: ClientBuilderFileOptions) => FileBatch;
27
+ buildFileBatch: (properties?: ClientBuilderFileOptions) => FileBatch;
21
28
  /** Build HL7 Message
22
29
  * @since 1.0.0 */
23
- buildMessage: (props?: ClientBuilderMessageOptions) => Message;
30
+ buildMessage: (properties?: ClientBuilderMessageOptions) => Message;
24
31
  /** Close a incoming HL7 port.
25
32
  * @since 1.0.0 */
26
33
  closeServer: (port: string) => Promise<boolean>;
27
34
  /** Close all incoming HL7 ports.
28
35
  * @since 1.0.0 */
29
36
  closeServerAll: () => Promise<boolean>;
37
+ /** Create a version-pinned HL7 message builder.
38
+ * @remarks Returns the node-hl7-client builder for the given version with
39
+ * per-version field validation. Chain `build*` and finish with `toMessage()`.
40
+ * @since 4.0.0 */
41
+ createBuilder: <V extends HL7Version>(version: V, properties?: ClientBuilderOptions) => HL7VersionBuilders[V];
30
42
  /** Create Client
31
43
  * @remarks Connecting to a remote server/broker that accepts connections.
32
44
  * @since 1.0.0 */
33
- createClient: (name: string, props: ClientOptions) => Client;
34
- /** Create an incoming port connection on the server.
35
- * @since 1.0.0 */
36
- createInbound: (name: string, props: ListenerOptions, handler: InboundHandler) => Inbound;
45
+ createClient: (name: string, properties: ClientOptions) => Client;
37
46
  /** Create Outgoing Client Port
38
47
  * @remarks This is on the established client that we are already a part off.
39
48
  * @since 1.0.0 */
40
- createConnection: (name: string, props: ClientListenerOptions, handler: OutboundHandler) => Connection;
49
+ createConnection: (name: string, properties: ClientListenerOptions, handler: OutboundHandler) => Connection;
50
+ /** Create an incoming port connection on the server.
51
+ * @since 1.0.0 */
52
+ createInbound: (name: string, properties: ListenerOptions, handler: InboundHandler) => Inbound;
41
53
  /** Get Client (Outbound) connection by name.
42
54
  * @since 1.0.0 */
43
55
  getClientByName: (name: string) => Client | undefined;
44
56
  /** Get Client Connection (Outbound) connection by port.
45
57
  * @since 1.0.0 */
46
58
  getClientConnectionByPort: (port: string) => Connection | undefined;
47
- /** Get Server (Inbound) connection by port.
48
- * @since 1.0.0 */
49
- getServerByPort: (port: string) => Inbound | undefined;
50
59
  /** Get Server (Inbound) connection by name.
51
60
  * @since 1.0.0 */
52
61
  getServerByName: (name: string) => Inbound | undefined;
62
+ /** Get Server (Inbound) connection by port.
63
+ * @since 1.0.0 */
64
+ getServerByPort: (port: string) => Inbound | undefined;
53
65
  /** Process an HL7 string.
54
66
  * @since 1.0.0 */
55
- processHL7: (text: string) => Message | Batch;
67
+ processHL7: (text: string) => Batch | Message;
56
68
  /** Read a file from a path.
57
69
  * @since 1.0.0 */
58
70
  readFile: (fullFilePath: string) => FileBatch;
@@ -60,10 +72,4 @@ declare module "fastify" {
60
72
  * @since 1.0.0 */
61
73
  readFileBuffer: (fileBuffer: Buffer) => FileBatch;
62
74
  }
63
- interface FastifyInstance {
64
- /** Main Decorator for Fastify
65
- * @remarks hl7 is the decorator that everything hangs off.
66
- * @since 1.0.0 **/
67
- hl7: HL7;
68
- }
69
75
  }
@@ -0,0 +1,6 @@
1
+ import { FastifyHL7Options } from "./decorate.js";
2
+ /**
3
+ * @since 1.0.0
4
+ * @param opts
5
+ */
6
+ export declare const validateOpts: (options: FastifyHL7Options) => Promise<FastifyHL7Options>;