mllp-node-sl7 2.1.4 → 2.1.6
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/.eslintrc.js +1 -0
- package/package.json +1 -1
- package/src/index.d.ts +3 -1
- package/src/index.js +16 -10
- package/src/index.ts +20 -10
- package/test/test.js +12 -0
package/.eslintrc.js
CHANGED
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ import { Message } from "@sourceblock-ug/sb-sl7";
|
|
|
7
7
|
export interface Renderable {
|
|
8
8
|
render(): string | Buffer;
|
|
9
9
|
}
|
|
10
|
-
export declare
|
|
10
|
+
export declare const cleanupString: (msg: string, removeParts: string[]) => string;
|
|
11
|
+
export declare const cleanup: (msg: string) => string;
|
|
12
|
+
export declare function mllpSendMessage(receivingHost: string, receivingPort: number, hl7Data: Buffer | Renderable | string, callback: (err: Error | null, response: string | null, responseMessage: string | null) => void, logger?: (msg: string) => void): void;
|
|
11
13
|
export interface MessageResponseEvent {
|
|
12
14
|
id: string;
|
|
13
15
|
ack: string | Renderable | unknown;
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MLLPServer = exports.mllpSendMessage = void 0;
|
|
6
|
+
exports.MLLPServer = exports.mllpSendMessage = exports.cleanup = exports.cleanupString = void 0;
|
|
7
7
|
const net_1 = __importDefault(require("net"));
|
|
8
8
|
const events_1 = __importDefault(require("events"));
|
|
9
9
|
const sb_sl7_1 = require("@sourceblock-ug/sb-sl7");
|
|
@@ -13,7 +13,7 @@ const decoder_1 = __importDefault(require("./decoder"));
|
|
|
13
13
|
const VT = String.fromCharCode(0x0b);
|
|
14
14
|
const VTi = 0x0b;
|
|
15
15
|
const FS = String.fromCharCode(0x1c); // const FSi = 0x1c;
|
|
16
|
-
const CR = String.fromCharCode(0x0d); // const CRi = 0x0d;
|
|
16
|
+
const CR = String.fromCharCode(0x0d); // const CRi = 0x0d; > \r
|
|
17
17
|
function isARenderable(obj) {
|
|
18
18
|
return (typeof obj === "object" &&
|
|
19
19
|
Object.prototype.hasOwnProperty.call(obj, "render") &&
|
|
@@ -25,6 +25,16 @@ function getPayload(hl7Data) {
|
|
|
25
25
|
}
|
|
26
26
|
return hl7Data;
|
|
27
27
|
}
|
|
28
|
+
const cleanupString = (msg, removeParts) => {
|
|
29
|
+
return removeParts.reduce((acc, part) => {
|
|
30
|
+
return acc.replace(part, "");
|
|
31
|
+
}, msg);
|
|
32
|
+
};
|
|
33
|
+
exports.cleanupString = cleanupString;
|
|
34
|
+
const cleanup = (msg) => {
|
|
35
|
+
return (0, exports.cleanupString)(msg, [VT, FS + CR, FS]);
|
|
36
|
+
};
|
|
37
|
+
exports.cleanup = cleanup;
|
|
28
38
|
function mllpSendMessage(receivingHost, receivingPort, hl7Data, callback, logger) {
|
|
29
39
|
// Render Message if it is an object:
|
|
30
40
|
const log = logger || console.log;
|
|
@@ -47,18 +57,14 @@ function mllpSendMessage(receivingHost, receivingPort, hl7Data, callback, logger
|
|
|
47
57
|
};
|
|
48
58
|
sendingClient.on("data", (rawAckData) => {
|
|
49
59
|
log(`${receivingHost}:${receivingPort} ACKED data`);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.split("\r")[1] // Ack data
|
|
54
|
-
.replace(FS, "")
|
|
55
|
-
.replace(CR, "");
|
|
56
|
-
callback(null, ackData);
|
|
60
|
+
const responseMessage = rawAckData.toString().replace(VT, "");
|
|
61
|
+
const ackData = responseMessage.split("\r")[1]; // Ack data
|
|
62
|
+
callback(null, (0, exports.cleanup)(ackData), (0, exports.cleanup)(responseMessage));
|
|
57
63
|
terminate();
|
|
58
64
|
});
|
|
59
65
|
sendingClient.on("error", (error) => {
|
|
60
66
|
log(`${receivingHost}:${receivingPort} couldn't process data`);
|
|
61
|
-
callback(error, null);
|
|
67
|
+
callback(error, null, null);
|
|
62
68
|
terminate();
|
|
63
69
|
});
|
|
64
70
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import decoder from "./decoder";
|
|
|
9
9
|
const VT = String.fromCharCode(0x0b);
|
|
10
10
|
const VTi = 0x0b;
|
|
11
11
|
const FS = String.fromCharCode(0x1c); // const FSi = 0x1c;
|
|
12
|
-
const CR = String.fromCharCode(0x0d); // const CRi = 0x0d;
|
|
12
|
+
const CR = String.fromCharCode(0x0d); // const CRi = 0x0d; > \r
|
|
13
13
|
|
|
14
14
|
export interface Renderable {
|
|
15
15
|
render(): string | Buffer;
|
|
@@ -30,11 +30,25 @@ function getPayload(hl7Data: Buffer | Renderable | string): string | Buffer {
|
|
|
30
30
|
return hl7Data;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export const cleanupString= (msg: string, removeParts: string[]): string => {
|
|
34
|
+
return removeParts.reduce((acc, part) => {
|
|
35
|
+
return acc.replace(part, "");
|
|
36
|
+
}, msg);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const cleanup = (msg: string): string => {
|
|
40
|
+
return cleanupString(msg, [VT, FS + CR, FS]);
|
|
41
|
+
};
|
|
42
|
+
|
|
33
43
|
export function mllpSendMessage(
|
|
34
44
|
receivingHost: string,
|
|
35
45
|
receivingPort: number,
|
|
36
46
|
hl7Data: Buffer | Renderable | string,
|
|
37
|
-
callback: (
|
|
47
|
+
callback: (
|
|
48
|
+
err: Error | null,
|
|
49
|
+
response: string | null,
|
|
50
|
+
responseMessage: string | null
|
|
51
|
+
) => void,
|
|
38
52
|
logger?: (msg: string) => void
|
|
39
53
|
) {
|
|
40
54
|
// Render Message if it is an object:
|
|
@@ -65,21 +79,17 @@ export function mllpSendMessage(
|
|
|
65
79
|
sendingClient.on("data", (rawAckData) => {
|
|
66
80
|
log(`${receivingHost}:${receivingPort} ACKED data`);
|
|
67
81
|
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
.replace(VT, "")
|
|
71
|
-
.split("\r")[1] // Ack data
|
|
72
|
-
.replace(FS, "")
|
|
73
|
-
.replace(CR, "");
|
|
82
|
+
const responseMessage = rawAckData.toString().replace(VT, "");
|
|
83
|
+
const ackData = responseMessage.split("\r")[1]; // Ack data
|
|
74
84
|
|
|
75
|
-
callback(null, ackData);
|
|
85
|
+
callback(null, cleanup(ackData), cleanup(responseMessage));
|
|
76
86
|
terminate();
|
|
77
87
|
});
|
|
78
88
|
|
|
79
89
|
sendingClient.on("error", (error) => {
|
|
80
90
|
log(`${receivingHost}:${receivingPort} couldn't process data`);
|
|
81
91
|
|
|
82
|
-
callback(error, null);
|
|
92
|
+
callback(error, null, null);
|
|
83
93
|
terminate();
|
|
84
94
|
});
|
|
85
95
|
}
|
package/test/test.js
CHANGED
|
@@ -109,4 +109,16 @@ describe("sends a large message for data exchange", function () {
|
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
|
+
|
|
113
|
+
describe("cleanup test", function () {
|
|
114
|
+
const sample = "MSH|^~\\&|RECEIVER|RECEIVING_FACILITY|SENDER|SENDING_FACILITY|20251009140009||ACK|202510091400090.335188|P|2.5||||||\r" +
|
|
115
|
+
"MSA|AA|MSG-OK-1|Test ACK\r" +
|
|
116
|
+
"\r";
|
|
117
|
+
|
|
118
|
+
it("should not remove necessary parts", function () {
|
|
119
|
+
const clean = mllp.cleanup(sample);
|
|
120
|
+
assert.equal(clean, "MSH|^~\\&|RECEIVER|RECEIVING_FACILITY|SENDER|SENDING_FACILITY|20251009140009||ACK|202510091400090.335188|P|2.5||||||\r" +
|
|
121
|
+
"MSA|AA|MSG-OK-1|Test ACK\r");
|
|
122
|
+
})
|
|
123
|
+
});
|
|
112
124
|
});
|