mllp-node-sl7 2.1.2 → 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/RELEASENOTES.md +3 -0
- package/package.json +1 -1
- package/src/index.d.ts +3 -3
- package/src/index.js +64 -60
- package/src/index.ts +81 -87
package/RELEASENOTES.md
CHANGED
|
@@ -22,3 +22,6 @@ This is the initial release of this library.
|
|
|
22
22
|
# v2.1.2 - Juli 24 , 2023
|
|
23
23
|
- switched to @sourceblock-ug/sb-sl7, Version 2.0.17; added cleanup on handleAck();
|
|
24
24
|
- added default Response as Param to Constructor
|
|
25
|
+
|
|
26
|
+
# v2.1.3 - Mar 28 , 2024
|
|
27
|
+
- fixed a Bug with the Buffer handling on parallel Socket-Connections
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -52,7 +52,6 @@ export declare class MLLPServer extends EventEmitter {
|
|
|
52
52
|
protected readonly HOST: string;
|
|
53
53
|
protected readonly PORT: number;
|
|
54
54
|
protected readonly TIMEOUT: number;
|
|
55
|
-
protected message: Buffer;
|
|
56
55
|
protected logger: (msg: string, ...data: unknown[]) => void;
|
|
57
56
|
protected charset: string;
|
|
58
57
|
private readonly TIMEOUTS;
|
|
@@ -62,6 +61,7 @@ export declare class MLLPServer extends EventEmitter {
|
|
|
62
61
|
private readonly openConnections;
|
|
63
62
|
private readonly timeoutAck;
|
|
64
63
|
constructor(host: string, port: number, defaultLogger?: (msg: string) => void, timeout?: number, defaultCharset?: string, timeoutAck?: string);
|
|
64
|
+
private handleIncomingMessage;
|
|
65
65
|
private updateState;
|
|
66
66
|
private addSocket;
|
|
67
67
|
private removeSocket;
|
|
@@ -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):
|
|
74
|
-
sendResponse(msgId: string, ack: string):
|
|
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
|
@@ -95,7 +95,6 @@ class MLLPServer extends events_1.default {
|
|
|
95
95
|
this.openConnections = [];
|
|
96
96
|
this.HOST = host || "127.0.0.1";
|
|
97
97
|
this.PORT = port || 6969;
|
|
98
|
-
this.message = Buffer.from("", "binary");
|
|
99
98
|
this.TIMEOUT = timeout || 600;
|
|
100
99
|
this.logger = defaultLogger || console.log;
|
|
101
100
|
this.TIMEOUTS = {};
|
|
@@ -114,6 +113,7 @@ class MLLPServer extends events_1.default {
|
|
|
114
113
|
};
|
|
115
114
|
try {
|
|
116
115
|
this.Server = net_1.default.createServer((sock) => {
|
|
116
|
+
let message = Buffer.from("", "binary");
|
|
117
117
|
this.logger(`CONNECTED: ${sock.remoteAddress}:${sock.remotePort}`);
|
|
118
118
|
this.addSocket(sock);
|
|
119
119
|
sock.on("end", () => {
|
|
@@ -122,69 +122,24 @@ class MLLPServer extends events_1.default {
|
|
|
122
122
|
this.logger("server disconnected", this.HOST, this.PORT);
|
|
123
123
|
this.removeSocket(sock);
|
|
124
124
|
});
|
|
125
|
-
const handleIncomingMessage = (messageBuffer) => {
|
|
126
|
-
let messageString = messageBuffer.toString();
|
|
127
|
-
let data2 = new sb_sl7_1.Message(messageString);
|
|
128
|
-
let msgId = data2.getString("MSH-10");
|
|
129
|
-
let encoding = data2.getString("MSH-18");
|
|
130
|
-
if (encoding === undefined || encoding === null || encoding === "") {
|
|
131
|
-
// use Default:
|
|
132
|
-
encoding = this.charset;
|
|
133
|
-
}
|
|
134
|
-
if (encoding !== "UNICODE UTF-8") {
|
|
135
|
-
// Decoding needed:
|
|
136
|
-
messageString = (0, decoder_1.default)(messageBuffer, encoding);
|
|
137
|
-
data2 = new sb_sl7_1.Message(messageString);
|
|
138
|
-
msgId = data2.getString("MSH-10");
|
|
139
|
-
}
|
|
140
|
-
this.logger(`Message:\r\n${messageString.replace(/\r/g, "\n")}\r\n\r\n`);
|
|
141
|
-
const event = {
|
|
142
|
-
id: msgId,
|
|
143
|
-
ack: this.timeoutAck,
|
|
144
|
-
msg: messageString,
|
|
145
|
-
hl7: data2,
|
|
146
|
-
buffer: messageBuffer,
|
|
147
|
-
};
|
|
148
|
-
if (this.openEvents[msgId] === undefined) {
|
|
149
|
-
// Using a Timeout if no response has been sended within the timeout.
|
|
150
|
-
this.TIMEOUTS[msgId] = setTimeout(() => {
|
|
151
|
-
this.handleAck(event, "timeout");
|
|
152
|
-
}, this.TIMEOUT);
|
|
153
|
-
this.openEvents[msgId] = { sock, org: this.message }; // save socket and Message for Response
|
|
154
|
-
/**
|
|
155
|
-
* MLLP HL7 Event. Fired when a HL7 Message is received.
|
|
156
|
-
* @event MLLPServer#hl7
|
|
157
|
-
* @type {string}
|
|
158
|
-
* @property {object} Event with the message string (msg), the Msg-ID, the default ACK and the parsed HL7 Object
|
|
159
|
-
*/
|
|
160
|
-
this.emit("hl7", event);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
// The Message ID is currently already in Progress... send a direkt REJECT-Message
|
|
164
|
-
const ackMsg = sb_sl7_1.Message.createResponse(event.hl7, "AR", "Message already in progress");
|
|
165
|
-
ackMsg.cleanup();
|
|
166
|
-
const ack = ackMsg.render();
|
|
167
|
-
sock.write(VT + ack + FS + CR);
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
125
|
/*
|
|
171
126
|
* handling incoming Data. Currently only one message per Connection is supported.
|
|
172
127
|
*/
|
|
173
128
|
sock.on("data", (data) => {
|
|
174
|
-
|
|
175
|
-
while (
|
|
176
|
-
let subBuffer =
|
|
177
|
-
|
|
129
|
+
message = Buffer.concat([message, data]);
|
|
130
|
+
while (message.indexOf(FS + CR) > -1) {
|
|
131
|
+
let subBuffer = message.subarray(0, message.indexOf(FS + CR));
|
|
132
|
+
message = message.subarray(message.indexOf(FS + CR) + 2);
|
|
178
133
|
if (subBuffer.indexOf(VTi) > -1) {
|
|
179
134
|
subBuffer = subBuffer.subarray(subBuffer.indexOf(VTi) + 1);
|
|
180
135
|
}
|
|
181
|
-
handleIncomingMessage(subBuffer);
|
|
136
|
+
this.handleIncomingMessage(subBuffer, sock);
|
|
182
137
|
}
|
|
183
|
-
if (
|
|
138
|
+
if (message.indexOf(VTi) > 0) {
|
|
184
139
|
// got a new Message indicator - but there is something before that message - handle as (not proper closed) message:
|
|
185
|
-
const unwrappedBuffer =
|
|
186
|
-
|
|
187
|
-
handleIncomingMessage(unwrappedBuffer);
|
|
140
|
+
const unwrappedBuffer = message.subarray(0, message.indexOf(VTi));
|
|
141
|
+
message = message.subarray(message.indexOf(VTi) + 1);
|
|
142
|
+
this.handleIncomingMessage(unwrappedBuffer, sock);
|
|
188
143
|
}
|
|
189
144
|
});
|
|
190
145
|
// emit incoming errors on the Sock to the outside world
|
|
@@ -226,6 +181,54 @@ class MLLPServer extends events_1.default {
|
|
|
226
181
|
throw new Error(`Error Listen to ${this.HOST}:${this.PORT}`);
|
|
227
182
|
}
|
|
228
183
|
}
|
|
184
|
+
handleIncomingMessage(messageBuffer, sock) {
|
|
185
|
+
let messageString = messageBuffer.toString();
|
|
186
|
+
let data2 = new sb_sl7_1.Message(messageString);
|
|
187
|
+
let msgId = data2.getString("MSH-10");
|
|
188
|
+
let encoding = data2.getString("MSH-18");
|
|
189
|
+
if (encoding === undefined || encoding === null || encoding === "") {
|
|
190
|
+
// use Default:
|
|
191
|
+
encoding = this.charset;
|
|
192
|
+
}
|
|
193
|
+
if (encoding !== "UNICODE UTF-8") {
|
|
194
|
+
// Decoding needed:
|
|
195
|
+
messageString = (0, decoder_1.default)(messageBuffer, encoding);
|
|
196
|
+
data2 = new sb_sl7_1.Message(messageString);
|
|
197
|
+
msgId = data2.getString("MSH-10");
|
|
198
|
+
}
|
|
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
|
+
}
|
|
203
|
+
const event = {
|
|
204
|
+
id: msgId,
|
|
205
|
+
ack: this.timeoutAck,
|
|
206
|
+
msg: messageString,
|
|
207
|
+
hl7: data2,
|
|
208
|
+
buffer: messageBuffer,
|
|
209
|
+
};
|
|
210
|
+
if (this.openEvents[msgId] === undefined) {
|
|
211
|
+
// Using a Timeout if no response has been sended within the timeout.
|
|
212
|
+
this.TIMEOUTS[msgId] = setTimeout(() => {
|
|
213
|
+
this.handleAck(event, "timeout");
|
|
214
|
+
}, this.TIMEOUT);
|
|
215
|
+
this.openEvents[msgId] = { sock, org: messageBuffer }; // save socket and Message for Response
|
|
216
|
+
/**
|
|
217
|
+
* MLLP HL7 Event. Fired when a HL7 Message is received.
|
|
218
|
+
* @event MLLPServer#hl7
|
|
219
|
+
* @type {string}
|
|
220
|
+
* @property {object} Event with the message string (msg), the Msg-ID, the default ACK and the parsed HL7 Object
|
|
221
|
+
*/
|
|
222
|
+
this.emit("hl7", event);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
// The Message ID is currently already in Progress... send a direkt REJECT-Message
|
|
226
|
+
const ackMsg = sb_sl7_1.Message.createResponse(event.hl7, "AR", "Message already in progress");
|
|
227
|
+
ackMsg.cleanup();
|
|
228
|
+
const ack = ackMsg.render();
|
|
229
|
+
sock.write(VT + ack + FS + CR);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
229
232
|
updateState() {
|
|
230
233
|
this.connectionEventState.connected = this.openConnections.length > 0;
|
|
231
234
|
let info = "";
|
|
@@ -291,6 +294,7 @@ class MLLPServer extends events_1.default {
|
|
|
291
294
|
ack = ackMsg.render();
|
|
292
295
|
}
|
|
293
296
|
inMsg.sock.write(VT + ack + FS + CR);
|
|
297
|
+
return true;
|
|
294
298
|
}
|
|
295
299
|
catch (e) {
|
|
296
300
|
this.logger(`Error sending response in mode ${mode}`, e);
|
|
@@ -299,18 +303,18 @@ class MLLPServer extends events_1.default {
|
|
|
299
303
|
else {
|
|
300
304
|
this.logger(`Response already send! Cannot process another response in mode ${mode}`, event);
|
|
301
305
|
}
|
|
306
|
+
return false;
|
|
302
307
|
}
|
|
303
308
|
response(event) {
|
|
304
309
|
if (this.openEvents[event.id] !== undefined) {
|
|
305
310
|
const inMsg = this.openEvents[event.id];
|
|
306
|
-
this.handleAck(Object.assign({ hl7: new sb_sl7_1.Message(inMsg.org), msg: inMsg.org.toString(), buffer: inMsg.org }, event), "direct");
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
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");
|
|
310
312
|
}
|
|
313
|
+
this.logger(`Response already send! Cannot process another response directly.`, event);
|
|
314
|
+
return false;
|
|
311
315
|
}
|
|
312
316
|
sendResponse(msgId, ack) {
|
|
313
|
-
this.response({ id: msgId, ack });
|
|
317
|
+
return this.response({ id: msgId, ack });
|
|
314
318
|
}
|
|
315
319
|
send(receivingHost, receivingPort, hl7Data, callback) {
|
|
316
320
|
mllpSendMessage(receivingHost, receivingPort, hl7Data, callback, this.logger);
|
package/src/index.ts
CHANGED
|
@@ -140,8 +140,6 @@ export class MLLPServer extends EventEmitter {
|
|
|
140
140
|
|
|
141
141
|
protected readonly TIMEOUT: number;
|
|
142
142
|
|
|
143
|
-
protected message: Buffer;
|
|
144
|
-
|
|
145
143
|
protected logger: (msg: string, ...data: unknown[]) => void;
|
|
146
144
|
|
|
147
145
|
protected charset: string;
|
|
@@ -169,7 +167,6 @@ export class MLLPServer extends EventEmitter {
|
|
|
169
167
|
super();
|
|
170
168
|
this.HOST = host || "127.0.0.1";
|
|
171
169
|
this.PORT = port || 6969;
|
|
172
|
-
this.message = Buffer.from("", "binary");
|
|
173
170
|
this.TIMEOUT = timeout || 600;
|
|
174
171
|
this.logger = defaultLogger || console.log;
|
|
175
172
|
this.TIMEOUTS = {};
|
|
@@ -189,6 +186,7 @@ export class MLLPServer extends EventEmitter {
|
|
|
189
186
|
|
|
190
187
|
try {
|
|
191
188
|
this.Server = net.createServer((sock) => {
|
|
189
|
+
let message: Buffer = Buffer.from("", "binary");
|
|
192
190
|
this.logger(`CONNECTED: ${sock.remoteAddress}:${sock.remotePort}`);
|
|
193
191
|
this.addSocket(sock);
|
|
194
192
|
|
|
@@ -199,90 +197,26 @@ export class MLLPServer extends EventEmitter {
|
|
|
199
197
|
this.removeSocket(sock);
|
|
200
198
|
});
|
|
201
199
|
|
|
202
|
-
const handleIncomingMessage = (messageBuffer: Buffer) => {
|
|
203
|
-
let messageString = messageBuffer.toString();
|
|
204
|
-
let data2 = new Message(messageString);
|
|
205
|
-
let msgId: string = data2.getString("MSH-10");
|
|
206
|
-
let encoding = data2.getString("MSH-18");
|
|
207
|
-
if (encoding === undefined || encoding === null || encoding === "") {
|
|
208
|
-
// use Default:
|
|
209
|
-
encoding = this.charset;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (encoding !== "UNICODE UTF-8") {
|
|
213
|
-
// Decoding needed:
|
|
214
|
-
messageString = decoder(messageBuffer, encoding);
|
|
215
|
-
data2 = new Message(messageString);
|
|
216
|
-
msgId = data2.getString("MSH-10");
|
|
217
|
-
}
|
|
218
|
-
this.logger(
|
|
219
|
-
`Message:\r\n${messageString.replace(/\r/g, "\n")}\r\n\r\n`
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
const event: IncomingMessageEvent = {
|
|
223
|
-
id: msgId,
|
|
224
|
-
ack: this.timeoutAck,
|
|
225
|
-
msg: messageString,
|
|
226
|
-
hl7: data2,
|
|
227
|
-
buffer: messageBuffer,
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
if (this.openEvents[msgId] === undefined) {
|
|
231
|
-
// Using a Timeout if no response has been sended within the timeout.
|
|
232
|
-
this.TIMEOUTS[msgId] = setTimeout(() => {
|
|
233
|
-
this.handleAck(event, "timeout");
|
|
234
|
-
}, this.TIMEOUT);
|
|
235
|
-
|
|
236
|
-
this.openEvents[msgId] = { sock, org: this.message }; // save socket and Message for Response
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* MLLP HL7 Event. Fired when a HL7 Message is received.
|
|
240
|
-
* @event MLLPServer#hl7
|
|
241
|
-
* @type {string}
|
|
242
|
-
* @property {object} Event with the message string (msg), the Msg-ID, the default ACK and the parsed HL7 Object
|
|
243
|
-
*/
|
|
244
|
-
this.emit("hl7", event);
|
|
245
|
-
} else {
|
|
246
|
-
// The Message ID is currently already in Progress... send a direkt REJECT-Message
|
|
247
|
-
const ackMsg = Message.createResponse(
|
|
248
|
-
event.hl7,
|
|
249
|
-
"AR",
|
|
250
|
-
"Message already in progress"
|
|
251
|
-
);
|
|
252
|
-
ackMsg.cleanup();
|
|
253
|
-
const ack = ackMsg.render();
|
|
254
|
-
sock.write(VT + ack + FS + CR);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
|
|
258
200
|
/*
|
|
259
201
|
* handling incoming Data. Currently only one message per Connection is supported.
|
|
260
202
|
*/
|
|
261
203
|
sock.on("data", (data) => {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
while (
|
|
265
|
-
let subBuffer =
|
|
266
|
-
|
|
267
|
-
this.message.indexOf(FS + CR)
|
|
268
|
-
);
|
|
269
|
-
this.message = this.message.subarray(
|
|
270
|
-
this.message.indexOf(FS + CR) + 2
|
|
271
|
-
);
|
|
204
|
+
message = Buffer.concat([message, data]);
|
|
205
|
+
|
|
206
|
+
while (message.indexOf(FS + CR) > -1) {
|
|
207
|
+
let subBuffer = message.subarray(0, message.indexOf(FS + CR));
|
|
208
|
+
message = message.subarray(message.indexOf(FS + CR) + 2);
|
|
272
209
|
if (subBuffer.indexOf(VTi) > -1) {
|
|
273
210
|
subBuffer = subBuffer.subarray(subBuffer.indexOf(VTi) + 1);
|
|
274
211
|
}
|
|
275
|
-
handleIncomingMessage(subBuffer);
|
|
212
|
+
this.handleIncomingMessage(subBuffer, sock);
|
|
276
213
|
}
|
|
277
214
|
|
|
278
|
-
if (
|
|
215
|
+
if (message.indexOf(VTi) > 0) {
|
|
279
216
|
// got a new Message indicator - but there is something before that message - handle as (not proper closed) message:
|
|
280
|
-
const unwrappedBuffer =
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
);
|
|
284
|
-
this.message = this.message.subarray(this.message.indexOf(VTi) + 1);
|
|
285
|
-
handleIncomingMessage(unwrappedBuffer);
|
|
217
|
+
const unwrappedBuffer = message.subarray(0, message.indexOf(VTi));
|
|
218
|
+
message = message.subarray(message.indexOf(VTi) + 1);
|
|
219
|
+
this.handleIncomingMessage(unwrappedBuffer, sock);
|
|
286
220
|
}
|
|
287
221
|
});
|
|
288
222
|
|
|
@@ -328,6 +262,64 @@ export class MLLPServer extends EventEmitter {
|
|
|
328
262
|
}
|
|
329
263
|
}
|
|
330
264
|
|
|
265
|
+
private handleIncomingMessage(messageBuffer: Buffer, sock: net.Socket) {
|
|
266
|
+
let messageString = messageBuffer.toString();
|
|
267
|
+
let data2 = new Message(messageString);
|
|
268
|
+
let msgId: string = data2.getString("MSH-10");
|
|
269
|
+
let encoding = data2.getString("MSH-18");
|
|
270
|
+
if (encoding === undefined || encoding === null || encoding === "") {
|
|
271
|
+
// use Default:
|
|
272
|
+
encoding = this.charset;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (encoding !== "UNICODE UTF-8") {
|
|
276
|
+
// Decoding needed:
|
|
277
|
+
messageString = decoder(messageBuffer, encoding);
|
|
278
|
+
data2 = new Message(messageString);
|
|
279
|
+
msgId = data2.getString("MSH-10");
|
|
280
|
+
}
|
|
281
|
+
this.logger(`Message:\r\n${messageString.replace(/\r/g, "\n")}\r\n\r\n`);
|
|
282
|
+
|
|
283
|
+
if (msgId === "") {
|
|
284
|
+
msgId = Math.random().toString(36).substring(2);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const event: IncomingMessageEvent = {
|
|
288
|
+
id: msgId,
|
|
289
|
+
ack: this.timeoutAck,
|
|
290
|
+
msg: messageString,
|
|
291
|
+
hl7: data2,
|
|
292
|
+
buffer: messageBuffer,
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
if (this.openEvents[msgId] === undefined) {
|
|
296
|
+
// Using a Timeout if no response has been sended within the timeout.
|
|
297
|
+
this.TIMEOUTS[msgId] = setTimeout(() => {
|
|
298
|
+
this.handleAck(event, "timeout");
|
|
299
|
+
}, this.TIMEOUT);
|
|
300
|
+
|
|
301
|
+
this.openEvents[msgId] = { sock, org: messageBuffer }; // save socket and Message for Response
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* MLLP HL7 Event. Fired when a HL7 Message is received.
|
|
305
|
+
* @event MLLPServer#hl7
|
|
306
|
+
* @type {string}
|
|
307
|
+
* @property {object} Event with the message string (msg), the Msg-ID, the default ACK and the parsed HL7 Object
|
|
308
|
+
*/
|
|
309
|
+
this.emit("hl7", event);
|
|
310
|
+
} else {
|
|
311
|
+
// The Message ID is currently already in Progress... send a direkt REJECT-Message
|
|
312
|
+
const ackMsg = Message.createResponse(
|
|
313
|
+
event.hl7,
|
|
314
|
+
"AR",
|
|
315
|
+
"Message already in progress"
|
|
316
|
+
);
|
|
317
|
+
ackMsg.cleanup();
|
|
318
|
+
const ack = ackMsg.render();
|
|
319
|
+
sock.write(VT + ack + FS + CR);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
331
323
|
private updateState(): MLLPConnectionState {
|
|
332
324
|
this.connectionEventState.connected = this.openConnections.length > 0;
|
|
333
325
|
let info = "";
|
|
@@ -372,7 +364,7 @@ export class MLLPServer extends EventEmitter {
|
|
|
372
364
|
return message.render();
|
|
373
365
|
}
|
|
374
366
|
|
|
375
|
-
private handleAck(event: IncomingMessageEvent, mode: any):
|
|
367
|
+
private handleAck(event: IncomingMessageEvent, mode: any): boolean {
|
|
376
368
|
if (this.openEvents[event.id] !== undefined) {
|
|
377
369
|
const inMsg = this.openEvents[event.id];
|
|
378
370
|
delete this.openEvents[event.id];
|
|
@@ -403,6 +395,7 @@ export class MLLPServer extends EventEmitter {
|
|
|
403
395
|
ack = ackMsg.render();
|
|
404
396
|
}
|
|
405
397
|
inMsg.sock.write(VT + ack + FS + CR);
|
|
398
|
+
return true;
|
|
406
399
|
} catch (e) {
|
|
407
400
|
this.logger(`Error sending response in mode ${mode}`, e);
|
|
408
401
|
}
|
|
@@ -412,12 +405,13 @@ export class MLLPServer extends EventEmitter {
|
|
|
412
405
|
event
|
|
413
406
|
);
|
|
414
407
|
}
|
|
408
|
+
return false;
|
|
415
409
|
}
|
|
416
410
|
|
|
417
|
-
public response(event: MessageResponseEvent) {
|
|
411
|
+
public response(event: MessageResponseEvent): boolean {
|
|
418
412
|
if (this.openEvents[event.id] !== undefined) {
|
|
419
413
|
const inMsg = this.openEvents[event.id];
|
|
420
|
-
this.handleAck(
|
|
414
|
+
return this.handleAck(
|
|
421
415
|
{
|
|
422
416
|
hl7: new Message(inMsg.org),
|
|
423
417
|
msg: inMsg.org.toString(),
|
|
@@ -426,16 +420,16 @@ export class MLLPServer extends EventEmitter {
|
|
|
426
420
|
},
|
|
427
421
|
"direct"
|
|
428
422
|
);
|
|
429
|
-
} else {
|
|
430
|
-
this.logger(
|
|
431
|
-
`Response already send! Cannot process another response directly.`,
|
|
432
|
-
event
|
|
433
|
-
);
|
|
434
423
|
}
|
|
424
|
+
this.logger(
|
|
425
|
+
`Response already send! Cannot process another response directly.`,
|
|
426
|
+
event
|
|
427
|
+
);
|
|
428
|
+
return false;
|
|
435
429
|
}
|
|
436
430
|
|
|
437
|
-
public sendResponse(msgId: string, ack: string) {
|
|
438
|
-
this.response({ id: msgId, ack });
|
|
431
|
+
public sendResponse(msgId: string, ack: string): boolean {
|
|
432
|
+
return this.response({ id: msgId, ack });
|
|
439
433
|
}
|
|
440
434
|
|
|
441
435
|
public send(
|