mllp-node-sl7 2.1.5 → 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 CHANGED
@@ -12,6 +12,7 @@ module.exports = {
12
12
  ],
13
13
  plugins: ["jsx-a11y", "import", "prettier", "@typescript-eslint"],
14
14
  globals: {},
15
+ ignorePatterns: ["coverage", "dist", "node_modules", "test"],
15
16
  rules: {
16
17
  // prettier
17
18
  "prettier/prettier": ["error"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mllp-node-sl7",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
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
@@ -7,6 +7,8 @@ import { Message } from "@sourceblock-ug/sb-sl7";
7
7
  export interface Renderable {
8
8
  render(): string | Buffer;
9
9
  }
10
+ export declare const cleanupString: (msg: string, removeParts: string[]) => string;
11
+ export declare const cleanup: (msg: string) => string;
10
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;
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;
@@ -45,17 +55,14 @@ function mllpSendMessage(receivingHost, receivingPort, hl7Data, callback, logger
45
55
  log(`closing connection with ${receivingHost}:${receivingPort}`);
46
56
  sendingClient.end();
47
57
  };
48
- const cleanup = (msg) => {
49
- return msg.replace(VT, '').replace(FS, '').replace(CR, '');
50
- };
51
- sendingClient.on('data', (rawAckData) => {
58
+ sendingClient.on("data", (rawAckData) => {
52
59
  log(`${receivingHost}:${receivingPort} ACKED data`);
53
- const responseMessage = rawAckData.toString().replace(VT, '');
54
- const ackData = responseMessage.split('\r')[1]; // Ack data
55
- callback(null, cleanup(ackData), cleanup(responseMessage));
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));
56
63
  terminate();
57
64
  });
58
- sendingClient.on('error', (error) => {
65
+ sendingClient.on("error", (error) => {
59
66
  log(`${receivingHost}:${receivingPort} couldn't process data`);
60
67
  callback(error, null, null);
61
68
  terminate();
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,6 +30,16 @@ 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,
@@ -66,10 +76,6 @@ export function mllpSendMessage(
66
76
  sendingClient.end();
67
77
  };
68
78
 
69
- const cleanup = (msg: string): string => {
70
- return msg.replace(VT, "").replace(FS, "").replace(CR, "");
71
- };
72
-
73
79
  sendingClient.on("data", (rawAckData) => {
74
80
  log(`${receivingHost}:${receivingPort} ACKED data`);
75
81
 
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
  });