hl7v2-net 1.8.0 → 1.8.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.
Files changed (3) hide show
  1. package/README.md +282 -17
  2. package/hl7-router.js +1 -1
  3. package/package.json +7 -7
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # HL7v2
1
+ # hl7v2-net
2
2
 
3
3
  [![NPM Version][npm-image]][npm-url]
4
4
  [![NPM Downloads][downloads-image]][downloads-url]
@@ -7,35 +7,300 @@
7
7
 
8
8
  ## About
9
9
 
10
- HL7 v2.x TCP Client/Server for NodeJS
10
+ HL7 v2.x MLLP server and client for Node.js. This package provides a high-level API for building HL7 servers and clients using TCP or TLS.
11
11
 
12
12
  ## Installation
13
13
 
14
14
  ```bash
15
- $ npm install hl7v2 --save
15
+ $ npm install hl7v2-net --save
16
16
  ```
17
17
 
18
+ ## Usage Example
19
+
20
+ ### Server Example
21
+
22
+ ```typescript
23
+ import { HL7Server } from 'hl7v2-net';
24
+
25
+ const server = HL7Server.createServer();
26
+
27
+ // Middleware to handle incoming messages
28
+ server.use(async (req, res) => {
29
+ console.log('Received message:', req.message.toHL7String());
30
+ // res.message is already initialized with an ACK
31
+ // You can modify it or just let the server send it automatically
32
+ });
33
+
34
+ server.listen(12345, () => {
35
+ console.log('HL7 Server listening on port 12345');
36
+ });
37
+ ```
38
+
39
+ ### Client Example
40
+
41
+ ```typescript
42
+ import { Hl7Client } from 'hl7v2-net';
43
+ import { HL7Message } from 'hl7v2';
44
+
45
+ const client = Hl7Client.createClient({ host: 'localhost', port: 12345 });
46
+
47
+ async function send() {
48
+ await client.connect();
49
+
50
+ const msg = new HL7Message();
51
+ msg.header.field(9).setValue('ORU^R01');
52
+ msg.addSegment('PID').field(5).setValue('DOE^JOHN');
53
+
54
+ const response = await client.sendMessageWaitAck(msg);
55
+ console.log('Received ACK:', response.toHL7String());
56
+
57
+ await client.close();
58
+ }
59
+
60
+ send().catch(console.error);
61
+ ```
62
+
63
+ ## API Reference
64
+
65
+ ### HL7Server
66
+
67
+ The `HL7Server` class is used to create an HL7 MLLP server.
68
+
69
+ #### Methods
70
+
71
+ ##### .createServer()
72
+
73
+ Creates a new `HL7Server` instance for TCP connections.
74
+ `static createServer(listenerOptions?: net.ListenOptions, options?: HL7Server.Options): HL7Server`
75
+ example
76
+
77
+ ```typescript
78
+ const server = HL7Server.createServer();
79
+ ```
80
+
81
+ ##### .createTlsServer()
82
+
83
+ Creates a new `HL7Server` instance for TLS connections.
84
+ `static createTlsServer(listenerOptions?: tls.TlsOptions, options?: HL7Server.Options): HL7Server`
85
+ example
86
+
87
+ ```typescript
88
+ const server = HL7Server.createTlsServer({
89
+ key: fs.readFileSync('server-key.pem'),
90
+ cert: fs.readFileSync('server-cert.pem')
91
+ });
92
+ ```
93
+
94
+ ##### .listen()
95
+
96
+ Starts the server listening for connections.
97
+ `listen(port?: number, hostname?: string, backlog?: number): Promise<void>`
98
+ example
99
+
100
+ ```typescript
101
+ await server.listen(12345);
102
+ ```
103
+
104
+ ##### .close()
105
+
106
+ Stops the server from accepting new connections and closes existing ones.
107
+ `close(waitRunningHandlers?: number): Promise<void>`
108
+ example
109
+
110
+ ```typescript
111
+ await server.close(5000); // Wait up to 5s for running handlers
112
+ ```
113
+
114
+ ##### .use()
115
+
116
+ Adds a middleware handler to the server.
117
+ `use(handler: HL7Middleware | HL7Router, priority?: number): void`
118
+ example
119
+
120
+ ```typescript
121
+ server.use((req, res, next) => {
122
+ // Do something
123
+ next();
124
+ });
125
+ ```
126
+
127
+ ---
128
+
129
+ ### Hl7Client
130
+
131
+ The `Hl7Client` class is used to create an HL7 MLLP client.
132
+
133
+ #### Properties
134
+
135
+ - `connected: boolean`: Whether the client is currently connected.
136
+ - `readyState: string`: The state of the underlying socket.
137
+
138
+ #### Methods
139
+
140
+ ##### .createClient()
141
+
142
+ Creates a new `Hl7Client` instance for TCP connections.
143
+ `static createClient(options: Hl7Client.NetConnectOptions): Hl7Client`
144
+ example
145
+
146
+ ```typescript
147
+ const client = Hl7Client.createClient({ host: 'localhost', port: 12345 });
148
+ ```
149
+
150
+ ##### .createTlsClient()
151
+
152
+ Creates a new `Hl7Client` instance for TLS connections.
153
+ `static createTlsClient(options: Hl7Client.TlsConnectOptions): Hl7Client`
154
+ example
155
+
156
+ ```typescript
157
+ const client = Hl7Client.createTlsClient({ host: 'localhost', port: 12345, rejectUnauthorized: false });
158
+ ```
159
+
160
+ ##### .connect()
161
+
162
+ Connects to the server.
163
+ `connect(): Promise<void>`
164
+ example
165
+
166
+ ```typescript
167
+ await client.connect();
168
+ ```
169
+
170
+ ##### .close()
171
+
172
+ Closes the connection.
173
+ `close(): Promise<void>`
174
+ example
175
+
176
+ ```typescript
177
+ await client.close();
178
+ ```
179
+
180
+ ##### .sendMessage()
181
+
182
+ Sends an HL7 message without waiting for an acknowledgment.
183
+ `sendMessage(message: HL7Message | string): Promise<void>`
184
+ example
185
+
186
+ ```typescript
187
+ await client.sendMessage(msg);
188
+ ```
189
+
190
+ ##### .sendMessageWaitAck()
191
+
192
+ Sends an HL7 message and waits for an acknowledgment.
193
+ `sendMessageWaitAck(message: HL7Message | string): Promise<HL7Message>`
194
+ example
195
+
196
+ ```typescript
197
+ const ack = await client.sendMessageWaitAck(msg);
198
+ ```
199
+
200
+ ---
201
+
202
+ ### HL7Socket
203
+
204
+ Represents an HL7 MLLP socket connection.
205
+
206
+ #### Properties
207
+
208
+ - `connected: boolean`: Whether the socket is connected.
209
+ - `remoteAddress: string`: The remote IP address.
210
+ - `remotePort: number`: The remote port.
211
+
212
+ #### Methods
213
+
214
+ ##### .sendMessage()
215
+
216
+ Sends an HL7 message.
217
+ `sendMessage(message: HL7Message | string): Promise<void>`
218
+ example
219
+
220
+ ```typescript
221
+ await socket.sendMessage(msg);
222
+ ```
223
+
224
+ ##### .sendMessageWaitAck()
225
+
226
+ Sends an HL7 message and waits for an acknowledgment.
227
+ `sendMessageWaitAck(message: HL7Message | string): Promise<HL7Message>`
228
+ example
229
+
230
+ ```typescript
231
+ const ack = await socket.sendMessageWaitAck(msg);
232
+ ```
233
+
234
+ ---
235
+
236
+ ### HL7Router
237
+
238
+ Provides routing capabilities for HL7 messages based on middleware.
239
+
240
+ #### Methods
241
+
242
+ ##### .use()
243
+
244
+ Adds a middleware or another router to this router.
245
+ `use(handler: HL7Middleware | HL7Router, priority?: number): void`
246
+ example
247
+
248
+ ```typescript
249
+ const router = new HL7Router();
250
+ router.use((req, res) => { ... });
251
+ server.use(router);
252
+ ```
253
+
254
+ ---
255
+
256
+ ### HL7Request
257
+
258
+ Represents an incoming HL7 request.
259
+
260
+ #### Properties
261
+
262
+ - `socket: HL7Socket`: The socket the request was received on.
263
+ - `message: HL7Message`: The received HL7 message.
264
+
265
+ ---
266
+
267
+ ### HL7Response
268
+
269
+ Represents the response to an HL7 request.
270
+
271
+ #### Properties
272
+
273
+ - `request: HL7Request`: The corresponding request.
274
+ - `message: HL7Message`: The HL7 message to be sent as a response (defaults to an ACK).
275
+ - `finished: boolean`: Whether the response has been sent.
276
+
277
+ #### Methods
278
+
279
+ ##### .failed()
280
+
281
+ Marks the request as failed and sets the response to a NAK message.
282
+ `failed(error: Error): void`
283
+ example
284
+
285
+ ```typescript
286
+ res.failed(new Error('Processing failed'));
287
+ ```
288
+
289
+ ---
290
+
18
291
  ## Node Compatibility
19
292
 
20
- - node >= 18.x
293
+ - node >= 20.x
21
294
 
22
295
  ### License
23
296
 
24
- HL7v2 is available under [MIT](LICENSE) license.
297
+ hl7v2-net is available under [MIT](LICENSE) license.
25
298
 
26
- [npm-image]: https://img.shields.io/npm/v/hl7v2.svg
27
- [npm-url]: https://npmjs.org/package/hl7v2
299
+ [npm-image]: https://img.shields.io/npm/v/hl7v2-net.svg
300
+ [npm-url]: https://npmjs.org/package/hl7v2-net
28
301
  [ci-test-image]: https://github.com/panates/hl7v2/actions/workflows/test.yml/badge.svg
29
302
  [ci-test-url]: https://github.com/panates/hl7v2/actions/workflows/test.yml
30
303
  [coveralls-image]: https://img.shields.io/coveralls/panates/hl7v2/master.svg
31
304
  [coveralls-url]: https://coveralls.io/r/panates/hl7v2
32
- [downloads-image]: https://img.shields.io/npm/dm/hl7v2.svg
33
- [downloads-url]: https://npmjs.org/package/hl7v2
34
- [gitter-image]: https://badges.gitter.im/panates/hl7v2.svg
35
- [gitter-url]: https://gitter.im/panates/hl7v2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
36
- [dependencies-image]: https://david-dm.org/panates/hl7v2/status.svg
37
- [dependencies-url]: https://david-dm.org/panates/hl7v2
38
- [devdependencies-image]: https://david-dm.org/panates/hl7v2/dev-status.svg
39
- [devdependencies-url]: https://david-dm.org/panates/hl7v2?type=dev
40
- [quality-image]: http://npm.packagequality.com/shield/hl7v2.png
41
- [quality-url]: http://packagequality.com/#?package=hl7v2
305
+ [downloads-image]: https://img.shields.io/npm/dm/hl7v2-net.svg
306
+ [downloads-url]: https://npmjs.org/package/hl7v2-net
package/hl7-router.js CHANGED
@@ -3,7 +3,7 @@ export class HL7Router {
3
3
  _needPrepare = true;
4
4
  _handlers = [];
5
5
  use(handler, priority = 0) {
6
- let list = this._handlerStack[priority];
6
+ let list = this._handlerStack.get(priority);
7
7
  if (!list) {
8
8
  list = [];
9
9
  this._handlerStack.set(priority, list);
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "hl7v2-net",
3
3
  "description": "HL7 v2 server/client for NodeJS",
4
- "version": "1.8.0",
4
+ "version": "1.8.2",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
- "@jsopen/objects": "^2.1.1",
8
+ "@jsopen/objects": "^2.2.1",
9
9
  "backoff": "^2.5.0",
10
10
  "iconv-lite": "^0.7.2",
11
11
  "is-typedarray": "^1.0.0",
12
- "node-events-async": "^1.5.0",
12
+ "node-events-async": "^1.5.2",
13
13
  "reconnect-core": "^1.3.0",
14
- "ts-gems": "^3.11.3",
14
+ "ts-gems": "^3.11.6",
15
15
  "tslib": "^2.8.1",
16
- "valgen": "^5.19.5",
16
+ "valgen": "^6.0.3",
17
17
  "uid": "^2.0.2"
18
18
  },
19
19
  "peerDependencies": {
20
- "hl7v2": "^1.8.0",
21
- "hl7v2-dictionary": "^1.8.0"
20
+ "hl7v2": "^1.8.2",
21
+ "hl7v2-dictionary": "^1.8.2"
22
22
  },
23
23
  "type": "module",
24
24
  "module": "./index.js",