mllp-node-sl7 2.1.1

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 ADDED
@@ -0,0 +1,52 @@
1
+ module.exports = {
2
+ parser: "@typescript-eslint/parser",
3
+ env: {
4
+ es6: true,
5
+ },
6
+ extends: [
7
+ "airbnb",
8
+ "airbnb/hooks",
9
+ "plugin:@typescript-eslint/recommended",
10
+ "prettier",
11
+ "prettier/@typescript-eslint",
12
+ ],
13
+ plugins: ["jsx-a11y", "import", "prettier", "@typescript-eslint"],
14
+ globals: {},
15
+ rules: {
16
+ // prettier
17
+ "prettier/prettier": ["error"],
18
+ "no-unexpected-multiline": "error",
19
+ // TypeScript
20
+ "@typescript-eslint/no-unused-vars": "error",
21
+ "@typescript-eslint/no-explicit-any": "warn",
22
+ "@typescript-eslint/explicit-member-accessibility": "off",
23
+ "@typescript-eslint/no-object-literal-type-assertion": "off",
24
+ "import/prefer-default-export": "off",
25
+ "class-methods-use-this": "warn",
26
+ // v4 changes
27
+ "no-use-before-define": "off",
28
+ "@typescript-eslint/no-use-before-define": ["error"],
29
+ "no-shadow": "off",
30
+ "@typescript-eslint/no-shadow": ["error"],
31
+ // import
32
+ "import/extensions": [
33
+ "error",
34
+ "ignorePackages",
35
+ {
36
+ js: "never",
37
+ mjs: "never",
38
+ jsx: "never",
39
+ ts: "never",
40
+ tsx: "never",
41
+ },
42
+ ],
43
+ },
44
+ settings: {
45
+ "import/resolver": {
46
+ node: {
47
+ extensions: [".js", ".ts", ".jsx", ".tsx", ".json"],
48
+ },
49
+ },
50
+ "import/extensions": [".js", ".ts", ".mjs", ".jsx", ".tsx"],
51
+ },
52
+ };
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Amida Technology Solutions (http://amida-tech.com)
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ mllp
2
+ ====
3
+ Fork, for original Readme see below!
4
+
5
+ # Install:
6
+ [![NPM](https://nodei.co/npm/mllp-node-sl7.png)](https://nodei.co/npm/mllp-node-sl7/)
7
+
8
+ Changes:
9
+ - Multi Message Support on a single Socket Connection
10
+ - Basic Character Encoding Support
11
+ - Timeout with Auto-Response
12
+ - Supports bind to all Interfaces (0.0.0.0)
13
+ - Using Package [sb-sl7](https://github.com/sourceblock-ug/sb-sl7) for Message parsing
14
+
15
+ Sample (see example.js):
16
+ ```javascript
17
+ var mllp = require('mllp-node');
18
+ var timeout = 600; // ms
19
+ var server = new mllp.MLLPServer('0.0.0.0', 1234, timeout);
20
+
21
+ // Subscribe to inbound messages
22
+ server.on('hl7', function (data){
23
+ console.log('received payload:', data);
24
+ });
25
+
26
+ // Send outbound messages
27
+ server.send('127.0.0.1', 4321, 'outbound-hl7-message', function (err, ackData) {
28
+ // async callback code here
29
+ });
30
+ ```
31
+
32
+ Original Readme:
33
+
34
+
35
+ [![NPM](https://nodei.co/npm/mllp-node.png)](https://nodei.co/npm/mllp-node/)
36
+
37
+ [![Build Status](https://travis-ci.org/amida-tech/mllp.svg)](https://travis-ci.org/amida-tech/mllp)
38
+ [![Coverage Status](https://coveralls.io/repos/amida-tech/mllp/badge.png)](https://coveralls.io/r/amida-tech/mllp)
39
+
40
+ HL7's MLLP (Minimum Lower Layer Protocol) server implementation in Node.js.
41
+
42
+
43
+ Listen on predefined port for HL7 messages in format:
44
+
45
+ ```
46
+ <VT>[HL7 Message]<FS><CR>
47
+ ```
48
+
49
+ * [HL7 MLP minimul layer protocol defined](http://www.hl7standards.com/blog/2007/05/02/hl7-mlp-minimum-layer-protocol-defined/)
50
+ * [ACK message](http://www.hl7standards.com/blog/2007/02/01/ack-message-original-mode-acknowledgement/)
51
+
52
+
53
+ ## Quick up and running guide
54
+
55
+ ### Prerequisites
56
+
57
+ - Node.js (v0.10+) and NPM
58
+ - Grunt.js
59
+
60
+ ```
61
+ # you need Node.js and Grunt.js installed
62
+
63
+ # install dependencies and build
64
+ npm install
65
+ grunt
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ See `example.js`:
71
+
72
+ ```javascript
73
+ var mllp = require('mllp-node');
74
+
75
+ var server = new mllp.MLLPServer('127.0.0.1', 1234);
76
+
77
+ // Subscribe to inbound messages
78
+ server.on('hl7', function (data){
79
+ console.log('received payload:', data);
80
+ });
81
+
82
+ // Send outbound messages
83
+ server.send('127.0.0.1', 4321, 'outbound-hl7-message', function (err, ackData) {
84
+ // async callback code here
85
+ });
86
+ ```
87
+
88
+ ## Contributing
89
+
90
+ Contributors are welcome. See issues on [GitHub issues](https://github.com/amida-tech/mllp/issues)
91
+
92
+ ## Release Notes
93
+
94
+ See release notes [here] (./RELEASENOTES.md)
95
+
96
+ ## License
97
+
98
+ Licensed under [Apache 2.0](./LICENSE)
@@ -0,0 +1,20 @@
1
+ # MLLP Release Notes
2
+
3
+ # v1.0.0 - December 12, 2014
4
+
5
+ This is the initial release of this library.
6
+
7
+ - Basic listener server compliant with HL7's MLLP standard
8
+ - Sends AA acknowledgement
9
+ - Access to HL7 messages/data via EventEmitter
10
+
11
+ # v2.0.0 - September 25 , 2018
12
+
13
+ - Set minimum node version to be 8
14
+ - Large message support
15
+
16
+ # v2.1.1 - Juli 24 , 2023
17
+
18
+ - added Socket-Termination on server.close()
19
+ - Switched to eslint & prettier and Updated code accordingly
20
+ - updated dependencies
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "mllp-node-sl7",
3
+ "version": "2.1.1",
4
+ "description": "MLLP (HL7) implementation in Node.js",
5
+ "main": "src/index.js",
6
+ "types": "src/index.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "test": "tsc && mocha",
10
+ "lint": "npx eslint src --ext ts --ignore-pattern \"src/**/*.d.ts\"",
11
+ "lint:fix": "npm run lint -- --fix"
12
+ },
13
+ "contributors": [
14
+ {
15
+ "name": "Dmitry Kachaev",
16
+ "email": "dmitry.kachaev@gmail.com",
17
+ "url": "http://github.com/kachok"
18
+ },
19
+ {
20
+ "name": "Alexander Drexler",
21
+ "email": "dx2308@googlemail.com",
22
+ "url": "http://github.com/tkalex"
23
+ }
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git@github.com:tka-lex/mllp.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/amida-tech/mllp/issues"
31
+ },
32
+ "license": "Apache-2.0",
33
+ "devDependencies": {
34
+ "@types/node": "^18.6.1",
35
+ "@typescript-eslint/eslint-plugin": "^6.1.0",
36
+ "@typescript-eslint/parser": "^6.1.0",
37
+ "chai": "4.1.x",
38
+ "chai-datetime": "1.5.x",
39
+ "coveralls": "3.1.1",
40
+ "mocha": "^10.2.0",
41
+ "mocha-lcov-reporter": "1.3.x",
42
+ "typescript": "^4.7.4",
43
+ "eslint": "^8.43.0",
44
+ "prettier": "^2.8.8",
45
+ "eslint-config-airbnb": "^19.0.2",
46
+ "eslint-config-prettier": "^6.15.0",
47
+ "eslint-plugin-import": "^2.25.3",
48
+ "eslint-plugin-jsx-a11y": "^6.5.1",
49
+ "eslint-plugin-prettier": "^3.1.4"
50
+ },
51
+ "engines": {
52
+ "node": ">=8.x.x"
53
+ },
54
+ "dependencies": {
55
+ "iconv-lite": "^0.6.0",
56
+ "sb-sl7": "^2.0.11"
57
+ }
58
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ declare function decode(msgBuffer: Buffer, hl7Encoding: string): string;
3
+ export default decode;
package/src/decoder.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const iconv = __importStar(require("iconv-lite"));
27
+ function decode(msgBuffer, hl7Encoding) {
28
+ try {
29
+ if (hl7Encoding.startsWith("8859/")) {
30
+ return iconv.decode(msgBuffer, `ISO-${hl7Encoding.replace("/", "-")}`);
31
+ }
32
+ if (hl7Encoding.toUpperCase() === "UNICODE UTF-16") {
33
+ return iconv.decode(msgBuffer, "UTF-16BE");
34
+ }
35
+ if (hl7Encoding.toUpperCase() === "ASCII") {
36
+ return iconv.decode(msgBuffer, "ascii");
37
+ }
38
+ }
39
+ catch (e) {
40
+ // eslint-disable-next-line no-console
41
+ console.error("Error during decode: ", e);
42
+ }
43
+ return msgBuffer.toString(); // Fallback if encoding is not supported.
44
+ }
45
+ exports.default = decode;
package/src/decoder.ts ADDED
@@ -0,0 +1,20 @@
1
+ import * as iconv from "iconv-lite";
2
+
3
+ function decode(msgBuffer: Buffer, hl7Encoding: string): string {
4
+ try {
5
+ if (hl7Encoding.startsWith("8859/")) {
6
+ return iconv.decode(msgBuffer, `ISO-${hl7Encoding.replace("/", "-")}`);
7
+ }
8
+ if (hl7Encoding.toUpperCase() === "UNICODE UTF-16") {
9
+ return iconv.decode(msgBuffer, "UTF-16BE");
10
+ }
11
+ if (hl7Encoding.toUpperCase() === "ASCII") {
12
+ return iconv.decode(msgBuffer, "ascii");
13
+ }
14
+ } catch (e) {
15
+ // eslint-disable-next-line no-console
16
+ console.error("Error during decode: ", e);
17
+ }
18
+ return msgBuffer.toString(); // Fallback if encoding is not supported.
19
+ }
20
+ export default decode;
package/src/example.js ADDED
@@ -0,0 +1,54 @@
1
+ /* eslint-disable no-param-reassign,no-console */
2
+ import { MLLPServer } from "./index";
3
+
4
+ const timeout = 600; // ms
5
+ const server = new MLLPServer("127.0.0.1", 1234, console.log, timeout);
6
+
7
+ // Subscribe to inbound messages
8
+ server.on("hl7", (eventData) => {
9
+ console.debug("received payload: ", eventData.msg);
10
+
11
+ /*
12
+ * You can send a Response back to the Server by using server.response(eventData).
13
+ * Your Response can (must?) be packed into the "eventData.ack" Property.
14
+ * Default is "AA" - other possible values see below.
15
+ *
16
+ * Alternatively you can use server.sendResponse(msg_id, <your-response>).
17
+ *
18
+ * Please be aware, that the Server will automatically send a default ACK after the given Timeout!
19
+ * If you send a response after the Timeout, your response will be ignored but logged.
20
+ * Attention:
21
+ * The Timeout and the EventHandler currently share the Event-Object. Changes to eventData.ack
22
+ * before the timeout will be used for the timeout-triggered response!
23
+ *
24
+ * Possible Values for a Answer are:
25
+ * - 2 Letter HL7 State like "AA", "AE" or "AR" (see http://wiki.hl7.de/index.php?title=Segment_MSA)
26
+ * - Object with a "render" method (Which will be called to get the String for the Message)
27
+ * - Object stringify with the hl7 "serializeJSON" method (nodejs hl7 Package)
28
+ * - String containing the full response
29
+ */
30
+
31
+ /* if (false) {
32
+ // Direct Answer:
33
+ eventData.ack = "AR"; // Reject the Message in this example
34
+
35
+ server.response(eventData);
36
+ // server.sendResponse(eventData.id, "AA"); // alternatively
37
+ // or skip both to let the timeout handle this for you.
38
+ } else { */
39
+ // you can also send the incoming message to another Server and use the Response
40
+ eventData.ack = "AE"; // set defaul to an Error
41
+ server.send("127.0.0.1", 22222, eventData.hl7, function (err, ackData) {
42
+ // async callback code here
43
+ console.log(eventData);
44
+ eventData.ack = `${server.createResponseHeader(eventData.hl7)}\r${ackData}`;
45
+ server.response(eventData);
46
+ });
47
+ // }
48
+ });
49
+
50
+ // Send outbound messages
51
+ server.send("127.0.0.1", 22222, "outbound-hl7-message", (err, ackData) => {
52
+ // async callback code here
53
+ console.log(err, ackData);
54
+ });
package/src/index.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import net from "net";
5
+ import EventEmitter from "events";
6
+ import { Message } from "sb-sl7/dist/message";
7
+ export interface Renderable {
8
+ render(): string | Buffer;
9
+ }
10
+ export declare function mllpSendMessage(receivingHost: string, receivingPort: number, hl7Data: Buffer | Renderable | string, callback: (err: Error | null, response: string | null) => void, logger?: (msg: string) => void): void;
11
+ export interface MessageResponseEvent {
12
+ id: string;
13
+ ack: string | Renderable | unknown;
14
+ }
15
+ export interface IncomingMessageEvent extends MessageResponseEvent {
16
+ msg: string;
17
+ hl7: Message;
18
+ buffer: Buffer;
19
+ }
20
+ export interface MLLPConnectionState {
21
+ host: string;
22
+ port: number;
23
+ connected: boolean;
24
+ remote: null | string;
25
+ }
26
+ /**
27
+ * @constructor MLLPServer
28
+ * @param {string} host a resolvable hostname or IP Address
29
+ * @param {number} port a valid free port for the server to listen on.
30
+ * @param defaultLogger
31
+ * @param {number} timeout after which the answer is sended.
32
+ * @param {string} defaultCharset for Message decoding
33
+ *
34
+ * @fires MLLPServer#hl7
35
+ *
36
+ * @example
37
+ * const server = new MLLPServer('hl7server.mydomain', 3333, console.log);
38
+ *
39
+ * server.on('hl7', function(message) {
40
+ * console.log("Message: " + message);
41
+ * // INSERT Unmarshalling or Processing here
42
+ * });
43
+ *
44
+ * @example
45
+ * <caption>An ACK is sent back to the server</caption>
46
+ * MSH|^~\&|SOMELAB|SOMELAB|SOMELAB|SOMELAB|20080511103530||ORU^R01|Q335939501T337311002|P|2.3|||
47
+ * MSA|AA|Q335939501T337311002
48
+ *
49
+ */
50
+ export declare class MLLPServer extends EventEmitter {
51
+ protected readonly HOST: string;
52
+ protected readonly PORT: number;
53
+ protected readonly TIMEOUT: number;
54
+ protected message: Buffer;
55
+ protected logger: (msg: string, ...data: unknown[]) => void;
56
+ protected charset: string;
57
+ private readonly TIMEOUTS;
58
+ private readonly openEvents;
59
+ protected Server: net.Server;
60
+ protected connectionEventState: MLLPConnectionState;
61
+ private readonly openConnections;
62
+ constructor(host: string, port: number, defaultLogger?: (msg: string) => void, timeout?: number, defaultCharset?: string);
63
+ private updateState;
64
+ private addSocket;
65
+ private removeSocket;
66
+ port(): number;
67
+ isConnected(): boolean;
68
+ currentRemote(): string | null;
69
+ static createResponseHeader(data: Message | string | object): string;
70
+ private handleAck;
71
+ response(event: MessageResponseEvent): void;
72
+ sendResponse(msgId: string, ack: string): void;
73
+ send(receivingHost: string, receivingPort: number, hl7Data: Buffer | Renderable | string, callback: (err: Error | null, response: string | null) => void): void;
74
+ close(done?: (err?: Error) => void): void;
75
+ private static closeSocket;
76
+ }