mllp-node-sl7 2.1.3 → 2.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mllp-node-sl7",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "MLLP (HL7) implementation in Node.js",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.ts",
package/src/index.d.ts CHANGED
@@ -70,8 +70,8 @@ export declare class MLLPServer extends EventEmitter {
70
70
  currentRemote(): string | null;
71
71
  static createResponseHeader(data: Message | string | object): string;
72
72
  private handleAck;
73
- response(event: MessageResponseEvent): void;
74
- sendResponse(msgId: string, ack: string): void;
73
+ response(event: MessageResponseEvent): boolean;
74
+ sendResponse(msgId: string, ack: string): boolean;
75
75
  send(receivingHost: string, receivingPort: number, hl7Data: Buffer | Renderable | string, callback: (err: Error | null, response: string | null) => void): void;
76
76
  close(done?: (err?: Error) => void): void;
77
77
  private static closeSocket;
package/src/index.js CHANGED
@@ -197,6 +197,9 @@ class MLLPServer extends events_1.default {
197
197
  msgId = data2.getString("MSH-10");
198
198
  }
199
199
  this.logger(`Message:\r\n${messageString.replace(/\r/g, "\n")}\r\n\r\n`);
200
+ if (msgId === "") {
201
+ msgId = Math.random().toString(36).substring(2);
202
+ }
200
203
  const event = {
201
204
  id: msgId,
202
205
  ack: this.timeoutAck,
@@ -226,7 +229,6 @@ class MLLPServer extends events_1.default {
226
229
  sock.write(VT + ack + FS + CR);
227
230
  }
228
231
  }
229
- ;
230
232
  updateState() {
231
233
  this.connectionEventState.connected = this.openConnections.length > 0;
232
234
  let info = "";
@@ -292,6 +294,7 @@ class MLLPServer extends events_1.default {
292
294
  ack = ackMsg.render();
293
295
  }
294
296
  inMsg.sock.write(VT + ack + FS + CR);
297
+ return true;
295
298
  }
296
299
  catch (e) {
297
300
  this.logger(`Error sending response in mode ${mode}`, e);
@@ -300,18 +303,18 @@ class MLLPServer extends events_1.default {
300
303
  else {
301
304
  this.logger(`Response already send! Cannot process another response in mode ${mode}`, event);
302
305
  }
306
+ return false;
303
307
  }
304
308
  response(event) {
305
309
  if (this.openEvents[event.id] !== undefined) {
306
310
  const inMsg = this.openEvents[event.id];
307
- this.handleAck(Object.assign({ hl7: new sb_sl7_1.Message(inMsg.org), msg: inMsg.org.toString(), buffer: inMsg.org }, event), "direct");
308
- }
309
- else {
310
- this.logger(`Response already send! Cannot process another response directly.`, event);
311
+ return this.handleAck(Object.assign({ hl7: new sb_sl7_1.Message(inMsg.org), msg: inMsg.org.toString(), buffer: inMsg.org }, event), "direct");
311
312
  }
313
+ this.logger(`Response already send! Cannot process another response directly.`, event);
314
+ return false;
312
315
  }
313
316
  sendResponse(msgId, ack) {
314
- this.response({ id: msgId, ack });
317
+ return this.response({ id: msgId, ack });
315
318
  }
316
319
  send(receivingHost, receivingPort, hl7Data, callback) {
317
320
  mllpSendMessage(receivingHost, receivingPort, hl7Data, callback, this.logger);
package/src/index.ts CHANGED
@@ -280,6 +280,10 @@ export class MLLPServer extends EventEmitter {
280
280
  }
281
281
  this.logger(`Message:\r\n${messageString.replace(/\r/g, "\n")}\r\n\r\n`);
282
282
 
283
+ if (msgId === "") {
284
+ msgId = Math.random().toString(36).substring(2);
285
+ }
286
+
283
287
  const event: IncomingMessageEvent = {
284
288
  id: msgId,
285
289
  ack: this.timeoutAck,
@@ -360,7 +364,7 @@ export class MLLPServer extends EventEmitter {
360
364
  return message.render();
361
365
  }
362
366
 
363
- private handleAck(event: IncomingMessageEvent, mode: any): void {
367
+ private handleAck(event: IncomingMessageEvent, mode: any): boolean {
364
368
  if (this.openEvents[event.id] !== undefined) {
365
369
  const inMsg = this.openEvents[event.id];
366
370
  delete this.openEvents[event.id];
@@ -391,6 +395,7 @@ export class MLLPServer extends EventEmitter {
391
395
  ack = ackMsg.render();
392
396
  }
393
397
  inMsg.sock.write(VT + ack + FS + CR);
398
+ return true;
394
399
  } catch (e) {
395
400
  this.logger(`Error sending response in mode ${mode}`, e);
396
401
  }
@@ -400,12 +405,13 @@ export class MLLPServer extends EventEmitter {
400
405
  event
401
406
  );
402
407
  }
408
+ return false;
403
409
  }
404
410
 
405
- public response(event: MessageResponseEvent) {
411
+ public response(event: MessageResponseEvent): boolean {
406
412
  if (this.openEvents[event.id] !== undefined) {
407
413
  const inMsg = this.openEvents[event.id];
408
- this.handleAck(
414
+ return this.handleAck(
409
415
  {
410
416
  hl7: new Message(inMsg.org),
411
417
  msg: inMsg.org.toString(),
@@ -414,16 +420,16 @@ export class MLLPServer extends EventEmitter {
414
420
  },
415
421
  "direct"
416
422
  );
417
- } else {
418
- this.logger(
419
- `Response already send! Cannot process another response directly.`,
420
- event
421
- );
422
423
  }
424
+ this.logger(
425
+ `Response already send! Cannot process another response directly.`,
426
+ event
427
+ );
428
+ return false;
423
429
  }
424
430
 
425
- public sendResponse(msgId: string, ack: string) {
426
- this.response({ id: msgId, ack });
431
+ public sendResponse(msgId: string, ack: string): boolean {
432
+ return this.response({ id: msgId, ack });
427
433
  }
428
434
 
429
435
  public send(