fastify-hl7 3.3.0 → 4.0.0
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/CHANGELOG.md +57 -0
- package/README.md +388 -60
- package/dist/api.d.ts +5 -0
- package/{lib/types → dist}/class/hL7Client.d.ts +49 -13
- package/{lib/esm → dist}/class/hL7Server.d.ts +2 -2
- package/dist/index.cjs +403 -0
- package/dist/index.cjs.map +1 -0
- package/{lib/types → dist}/index.d.ts +3 -3
- package/dist/index.mjs +377 -0
- package/dist/index.mjs.map +1 -0
- package/{lib/esm → dist}/types.d.ts +26 -20
- package/dist/validation.d.ts +6 -0
- package/package.json +42 -48
- package/lib/cjs/api.js +0 -13
- package/lib/cjs/class/hL7Client.js +0 -238
- package/lib/cjs/class/hL7Server.js +0 -81
- package/lib/cjs/decorate.js +0 -2
- package/lib/cjs/errors.js +0 -13
- package/lib/cjs/index.js +0 -144
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/types.js +0 -2
- package/lib/cjs/validation.js +0 -15
- package/lib/esm/api.d.ts +0 -7
- package/lib/esm/api.js +0 -5
- package/lib/esm/class/hL7Client.d.ts +0 -99
- package/lib/esm/class/hL7Client.js +0 -201
- package/lib/esm/class/hL7Server.js +0 -77
- package/lib/esm/decorate.js +0 -1
- package/lib/esm/errors.js +0 -7
- package/lib/esm/index.d.ts +0 -5
- package/lib/esm/index.js +0 -125
- package/lib/esm/package.json +0 -3
- package/lib/esm/types.js +0 -1
- package/lib/esm/validation.d.ts +0 -6
- package/lib/esm/validation.js +0 -11
- package/lib/types/api.d.ts +0 -7
- package/lib/types/class/hL7Server.d.ts +0 -38
- package/lib/types/decorate.d.ts +0 -38
- package/lib/types/errors.d.ts +0 -10
- package/lib/types/types.d.ts +0 -69
- package/lib/types/validation.d.ts +0 -6
- package/{lib/esm → dist}/decorate.d.ts +16 -16
- /package/{lib/esm → dist}/errors.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify-hl7",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A Fastify HL7 Plugin Developed in Pure TypeScript.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
14
19
|
}
|
|
15
20
|
},
|
|
16
21
|
"files": [
|
|
17
|
-
"
|
|
22
|
+
"dist",
|
|
18
23
|
"README.md",
|
|
19
|
-
"LICENSE"
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"CHANGELOG.md"
|
|
20
26
|
],
|
|
21
27
|
"engines": {
|
|
22
28
|
"node": ">=20.15.0"
|
|
23
29
|
},
|
|
24
30
|
"scripts": {
|
|
25
|
-
"clean": "rm -rf coverage docs
|
|
26
|
-
"build": "
|
|
27
|
-
"build:watch": "
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"lint:fix": "npm run npm:lint && eslint --fix | snazzy",
|
|
33
|
-
"pack": "npm pack",
|
|
34
|
-
"prepublishOnly": "npm run clean && npm run build && npm run pack",
|
|
31
|
+
"clean": "rm -rf coverage docs dist temp",
|
|
32
|
+
"build": "tsdown && tsc --emitDeclarationOnly",
|
|
33
|
+
"build:watch": "tsdown --watch",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"lint": "eslint .",
|
|
36
|
+
"lint:fix": "eslint . --fix",
|
|
37
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
35
38
|
"test": "vitest run",
|
|
36
39
|
"test:verbose": "vitest run --reporter verbose",
|
|
37
40
|
"test:watch": "vitest watch",
|
|
@@ -61,39 +64,30 @@
|
|
|
61
64
|
"dependencies": {
|
|
62
65
|
"@fastify/error": "^4.1.0",
|
|
63
66
|
"fastify-plugin": "^5.0.1",
|
|
64
|
-
"node-hl7-client": "^
|
|
65
|
-
"node-hl7-server": "^
|
|
67
|
+
"node-hl7-client": "^4.0.0",
|
|
68
|
+
"node-hl7-server": "^4.0.0"
|
|
66
69
|
},
|
|
67
70
|
"devDependencies": {
|
|
68
|
-
"@
|
|
69
|
-
"@
|
|
70
|
-
"@
|
|
71
|
-
"@types/node": "^22.13.11",
|
|
71
|
+
"@shipgirl/typedoc-plugin-versions": "^0.3.2",
|
|
72
|
+
"@the-rabbit-hole/eslint-config": "^0.4.0",
|
|
73
|
+
"@types/node": "^25.9.2",
|
|
72
74
|
"@types/tcp-port-used": "^1.0.4",
|
|
73
|
-
"@
|
|
74
|
-
"@
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"tcp-port-used": "^1.0.2",
|
|
88
|
-
"ts-node": "^10.9.2",
|
|
89
|
-
"tsd": "^0.31.2",
|
|
90
|
-
"typedoc": "^0.28.1",
|
|
91
|
-
"typescript": "^5.8.2",
|
|
92
|
-
"typescript-eslint": "^8.27.0",
|
|
93
|
-
"vitest": "^3.0.9"
|
|
75
|
+
"@vitest/coverage-v8": "^4.1.8",
|
|
76
|
+
"@vitest/ui": "^4.1.8",
|
|
77
|
+
"eslint": "^10.4.1",
|
|
78
|
+
"fastify": "^5.8.5",
|
|
79
|
+
"npm-check-updates": "^22.2.3",
|
|
80
|
+
"portfinder": "^1.0.38",
|
|
81
|
+
"pre-commit": "^2.0.0",
|
|
82
|
+
"prettier": "^3.8.3",
|
|
83
|
+
"tcp-port-used": "^1.0.3",
|
|
84
|
+
"tsd": "^0.33.0",
|
|
85
|
+
"tsdown": "^0.22.2",
|
|
86
|
+
"typedoc": "^0.28.19",
|
|
87
|
+
"typescript": "^6.0.3",
|
|
88
|
+
"vitest": "^4.1.8"
|
|
94
89
|
},
|
|
95
90
|
"precommit": [
|
|
96
|
-
"format",
|
|
97
91
|
"lint:fix",
|
|
98
92
|
"build"
|
|
99
93
|
]
|
package/lib/cjs/api.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HL7Server = exports.HL7Client = exports.fastifyHL7 = void 0;
|
|
7
|
-
const _1 = __importDefault(require("."));
|
|
8
|
-
exports.fastifyHL7 = _1.default;
|
|
9
|
-
const hL7Client_js_1 = require("./class/hL7Client.js");
|
|
10
|
-
Object.defineProperty(exports, "HL7Client", { enumerable: true, get: function () { return hL7Client_js_1.HL7Client; } });
|
|
11
|
-
const hL7Server_js_1 = require("./class/hL7Server.js");
|
|
12
|
-
Object.defineProperty(exports, "HL7Server", { enumerable: true, get: function () { return hL7Server_js_1.HL7Server; } });
|
|
13
|
-
exports.default = _1.default;
|
|
@@ -1,238 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.HL7Client = void 0;
|
|
37
|
-
const node_hl7_client_1 = __importStar(require("node-hl7-client"));
|
|
38
|
-
const errors_js_1 = require("../errors.js");
|
|
39
|
-
class HL7Client {
|
|
40
|
-
constructor() {
|
|
41
|
-
this._clientConnections = [];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Close All Connections for this Client
|
|
45
|
-
* @since 1.0.0
|
|
46
|
-
*/
|
|
47
|
-
async closeAll() {
|
|
48
|
-
this._clientConnections.forEach((outbound) => {
|
|
49
|
-
outbound.ports.map(async (port) => {
|
|
50
|
-
await port.connection.close();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Build a HL7 Batch
|
|
57
|
-
* @remarks Create a properly formatted HL7 Batch.
|
|
58
|
-
* @since 1.0.0
|
|
59
|
-
* @param props
|
|
60
|
-
*/
|
|
61
|
-
buildBatch(props) {
|
|
62
|
-
if (typeof props !== "undefined" && typeof props.text !== "undefined") {
|
|
63
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("Use processMessage method. This is for building.");
|
|
64
|
-
}
|
|
65
|
-
return new node_hl7_client_1.Batch({ ...props });
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Build Date
|
|
69
|
-
* @remarks Build a date string based off HL7 Standards
|
|
70
|
-
* @since 2.1.0
|
|
71
|
-
* @param date
|
|
72
|
-
* @param length Options are 8, 12, or 14 (default)
|
|
73
|
-
*/
|
|
74
|
-
buildDate(date, length) {
|
|
75
|
-
return (0, node_hl7_client_1.createHL7Date)(date, length);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Build a HL7 File Batch
|
|
79
|
-
* @remarks Create a properly formatted HL7 File Batch.
|
|
80
|
-
* @since 1.0.0
|
|
81
|
-
* @param props
|
|
82
|
-
*/
|
|
83
|
-
buildFileBatch(props) {
|
|
84
|
-
if (typeof props !== "undefined" &&
|
|
85
|
-
(typeof props.fullFilePath !== "undefined" ||
|
|
86
|
-
typeof props.fileBuffer !== "undefined")) {
|
|
87
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("Use readFile or readFileBuffer method. This is for building.");
|
|
88
|
-
}
|
|
89
|
-
return new node_hl7_client_1.FileBatch({ ...props });
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Build a HL7 Message
|
|
93
|
-
* @remarks Create a properly formatted HL7 message.
|
|
94
|
-
* @since 1.0.0
|
|
95
|
-
* @param props
|
|
96
|
-
*/
|
|
97
|
-
buildMessage(props) {
|
|
98
|
-
if (typeof props !== "undefined" && typeof props.text !== "undefined") {
|
|
99
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("Use processMessage method. This is for building.");
|
|
100
|
-
}
|
|
101
|
-
return new node_hl7_client_1.Message({ ...props });
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
* @param name
|
|
106
|
-
* @param props
|
|
107
|
-
*/
|
|
108
|
-
createClient(name, props) {
|
|
109
|
-
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
110
|
-
if (nameFormat.test(name)) {
|
|
111
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
|
|
112
|
-
}
|
|
113
|
-
// make sure that this does not exist already...
|
|
114
|
-
this._clientConnections.forEach((connections) => {
|
|
115
|
-
if (connections.name === name) {
|
|
116
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("name must be unique.");
|
|
117
|
-
}
|
|
118
|
-
// nto in the Client class yet
|
|
119
|
-
// if (client.getHost() === props.host) {
|
|
120
|
-
// throw new errors.FASTIFY_HL7_ERR_USAGE(`host is already a pointer. Name is: ${connections.name}`)
|
|
121
|
-
// }
|
|
122
|
-
});
|
|
123
|
-
// new client
|
|
124
|
-
const client = new node_hl7_client_1.default(props);
|
|
125
|
-
// add it to the collection
|
|
126
|
-
this._clientConnections.push({
|
|
127
|
-
name,
|
|
128
|
-
client,
|
|
129
|
-
ports: [],
|
|
130
|
-
});
|
|
131
|
-
return client;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Create an HL7 Outbound Connection
|
|
135
|
-
* @remarks Connect to an HL7 Server/Broker
|
|
136
|
-
* @since 1.0.0
|
|
137
|
-
* @param name The name stored within created client connections.
|
|
138
|
-
* @param props
|
|
139
|
-
* @param handler
|
|
140
|
-
*/
|
|
141
|
-
createConnection(name, props, handler) {
|
|
142
|
-
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
143
|
-
if (nameFormat.test(name)) {
|
|
144
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
|
|
145
|
-
}
|
|
146
|
-
const getConnection = this._clientConnections.find((client) => client.name === name);
|
|
147
|
-
if (typeof getConnection !== "undefined") {
|
|
148
|
-
// make sure port is not used all ready
|
|
149
|
-
getConnection.ports.forEach((outbound) => {
|
|
150
|
-
if (outbound.port === props.port.toString()) {
|
|
151
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE(`port ${props.port} is already used with this client. Choose a new outgoing port.`);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
// create outbound port to the server in getConnection.client
|
|
155
|
-
const outbound = new node_hl7_client_1.Connection(getConnection.client, props, handler);
|
|
156
|
-
// add it to the array of known ports. need to know this, so we can get it later if needed.
|
|
157
|
-
getConnection.ports.push({
|
|
158
|
-
port: props.port.toString(),
|
|
159
|
-
connection: outbound,
|
|
160
|
-
});
|
|
161
|
-
// return it right away. the user might do something with it.
|
|
162
|
-
return outbound;
|
|
163
|
-
}
|
|
164
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("No valid client. Improper setup of a outbound connection.");
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Get Client by the name
|
|
168
|
-
* @since 1.0.0
|
|
169
|
-
* @param name
|
|
170
|
-
*/
|
|
171
|
-
getClientByName(name) {
|
|
172
|
-
const connection = this._clientConnections.find((connection) => connection.name === name);
|
|
173
|
-
if (typeof connection !== "undefined") {
|
|
174
|
-
return connection.client;
|
|
175
|
-
}
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Get Connection by Port
|
|
180
|
-
* @since 1.0.0
|
|
181
|
-
* @param port
|
|
182
|
-
*/
|
|
183
|
-
getClientConnectionByPort(port) {
|
|
184
|
-
let connection;
|
|
185
|
-
this._clientConnections.forEach((outbound) => {
|
|
186
|
-
outbound.ports.forEach((aPort) => {
|
|
187
|
-
if (aPort.port === port) {
|
|
188
|
-
connection = aPort.connection;
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
return connection;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Process a HL7
|
|
196
|
-
* @remarks A HL7 message that could either be a Message (MSH) or Batch (BHS)
|
|
197
|
-
* @since 1.0.0
|
|
198
|
-
* @param text Raw HL& String
|
|
199
|
-
*/
|
|
200
|
-
processHL7(text) {
|
|
201
|
-
if ((0, node_hl7_client_1.isBatch)(text)) {
|
|
202
|
-
return new node_hl7_client_1.Batch({ text });
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
return new node_hl7_client_1.Message({ text });
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Read File
|
|
210
|
-
* @remarks Pass the correct path of the file you want to read.
|
|
211
|
-
* @since 1.0.0
|
|
212
|
-
* @param fullFilePath
|
|
213
|
-
* @returns FileBatch
|
|
214
|
-
* @example
|
|
215
|
-
* ```ts
|
|
216
|
-
* fastify.hl7.readFile( path.join('temp/', 'hl7.readTestBHS.20231208.hl7') )
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
readFile(fullFilePath) {
|
|
220
|
-
return new node_hl7_client_1.FileBatch({ fullFilePath });
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Read a File Buffer
|
|
224
|
-
* @remarks Translate an already Buffered HL7 FHS segment to decode it.
|
|
225
|
-
* @since 1.0.0
|
|
226
|
-
* @param fileBuffer
|
|
227
|
-
* @returns FileBatch
|
|
228
|
-
* @example
|
|
229
|
-
* ```ts
|
|
230
|
-
* const fileBuffer = fs.readFileSync(path.join('temp/', 'hl7.readTestBHS.20231208.hl7'))
|
|
231
|
-
* fastify.hl7.readFileBuffer(fileBuffer)
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
readFileBuffer(fileBuffer) {
|
|
235
|
-
return new node_hl7_client_1.FileBatch({ fileBuffer });
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
exports.HL7Client = HL7Client;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HL7Server = void 0;
|
|
4
|
-
const node_events_1 = require("node:events");
|
|
5
|
-
const node_hl7_server_1 = require("node-hl7-server");
|
|
6
|
-
const errors_js_1 = require("../errors.js");
|
|
7
|
-
class HL7Server extends node_events_1.EventEmitter {
|
|
8
|
-
constructor(server) {
|
|
9
|
-
super();
|
|
10
|
-
this._server = server;
|
|
11
|
-
this._serverInboundConnections = [];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Close Inbound connection.
|
|
15
|
-
* @since 1.0.0
|
|
16
|
-
* @param port
|
|
17
|
-
*/
|
|
18
|
-
async close(port) {
|
|
19
|
-
const inbound = this._serverInboundConnections.find((server) => server.port === port);
|
|
20
|
-
if (typeof inbound !== "undefined") {
|
|
21
|
-
return await inbound.server.close(); // close the server for all inbound connections
|
|
22
|
-
}
|
|
23
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE(`No inbound server listening on port: ${port}`);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Close all Inbound connections.
|
|
27
|
-
* @since 1.0.0
|
|
28
|
-
*/
|
|
29
|
-
async closeAll() {
|
|
30
|
-
this._serverInboundConnections.map(async (inbound) => {
|
|
31
|
-
await inbound.server.close();
|
|
32
|
-
});
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Create Inbound connection.
|
|
37
|
-
* @since 1.0.0
|
|
38
|
-
* @param name
|
|
39
|
-
* @param props
|
|
40
|
-
* @param handler
|
|
41
|
-
*/
|
|
42
|
-
createInbound(name, props, handler) {
|
|
43
|
-
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
44
|
-
if (nameFormat.test(name)) {
|
|
45
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
|
|
46
|
-
}
|
|
47
|
-
const inbound = new node_hl7_server_1.Inbound(this._server, props, handler);
|
|
48
|
-
this._serverInboundConnections.push({
|
|
49
|
-
name,
|
|
50
|
-
port: props.port.toString(),
|
|
51
|
-
server: inbound,
|
|
52
|
-
});
|
|
53
|
-
this.emit("inbound", props.port.toString());
|
|
54
|
-
return inbound;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Get Server Inbound Connection by Name
|
|
58
|
-
* @since 1.0.0
|
|
59
|
-
* @param name
|
|
60
|
-
*/
|
|
61
|
-
getServerByName(name) {
|
|
62
|
-
const inbound = this._serverInboundConnections.find((inbound) => inbound.name === name);
|
|
63
|
-
if (typeof inbound !== "undefined") {
|
|
64
|
-
return inbound.server;
|
|
65
|
-
}
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Get Server Inbound Connection by Port
|
|
70
|
-
* @since 1.0.0
|
|
71
|
-
* @param port
|
|
72
|
-
*/
|
|
73
|
-
getServerByPort(port) {
|
|
74
|
-
const inbound = this._serverInboundConnections.find((inbound) => inbound.port === port);
|
|
75
|
-
if (typeof inbound !== "undefined") {
|
|
76
|
-
return inbound.server;
|
|
77
|
-
}
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.HL7Server = HL7Server;
|
package/lib/cjs/decorate.js
DELETED
package/lib/cjs/errors.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.errors = void 0;
|
|
7
|
-
const error_1 = __importDefault(require("@fastify/error"));
|
|
8
|
-
exports.errors = {
|
|
9
|
-
/** Error if there is an setup error of the plugin itself. */
|
|
10
|
-
FASTIFY_HL7_ERR_SETUP_ERRORS: (0, error_1.default)("FASTIFY_HL7_ERR_SETUP_ERRORS", "Setup error: %s"),
|
|
11
|
-
/** If an invalid usage error was done, this error would pop up. */
|
|
12
|
-
FASTIFY_HL7_ERR_USAGE: (0, error_1.default)("FASTIFY_HL7_ERR_USAGE", "Usage error: %s"),
|
|
13
|
-
};
|
package/lib/cjs/index.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
|
|
21
|
-
const node_hl7_server_1 = __importDefault(require("node-hl7-server"));
|
|
22
|
-
const hL7Server_js_1 = require("./class/hL7Server.js");
|
|
23
|
-
const hL7Client_js_1 = require("./class/hL7Client.js");
|
|
24
|
-
const errors_js_1 = require("./errors.js");
|
|
25
|
-
const validation_js_1 = require("./validation.js");
|
|
26
|
-
__exportStar(require("./types.js"), exports);
|
|
27
|
-
/**
|
|
28
|
-
* @since 1.0.0
|
|
29
|
-
* @param fastify
|
|
30
|
-
* @param _opts
|
|
31
|
-
* @param connection
|
|
32
|
-
*/
|
|
33
|
-
const decorateFastifyInstance = (fastify, _opts, connection) => {
|
|
34
|
-
if (typeof fastify.hl7 !== "undefined") {
|
|
35
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_SETUP_ERRORS("Already registered.");
|
|
36
|
-
}
|
|
37
|
-
if (typeof fastify.hl7 === "undefined") {
|
|
38
|
-
fastify.log.trace("[fastify-hl7] Decorate Fastify");
|
|
39
|
-
fastify.decorate("hl7", connection);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const fastifyHL7 = (0, fastify_plugin_1.default)(async (fastify, opts) => {
|
|
43
|
-
const generatedOpts = await (0, validation_js_1.validateOpts)(opts);
|
|
44
|
-
opts = { ...opts, ...generatedOpts };
|
|
45
|
-
// Create server.
|
|
46
|
-
// Since there can only be one server per IP address
|
|
47
|
-
// (i.e., the host this is running on.) There can only be more than one.
|
|
48
|
-
// A server can host many HL7 Inbound connections via different ports, this is fine.
|
|
49
|
-
// Clients are different as an app could talk to different servers, on many ports.
|
|
50
|
-
// So we need to do something different.
|
|
51
|
-
const serverInstance = typeof opts.enableServer !== "undefined" && opts.enableServer
|
|
52
|
-
? new node_hl7_server_1.default(opts.serverOptions)
|
|
53
|
-
: undefined;
|
|
54
|
-
// Server Functions
|
|
55
|
-
let server;
|
|
56
|
-
if (typeof serverInstance !== "undefined") {
|
|
57
|
-
// Server Functions
|
|
58
|
-
server = new hL7Server_js_1.HL7Server(serverInstance);
|
|
59
|
-
server.on("inbound", (port) => {
|
|
60
|
-
fastify.log.info("HL7 Inbound Server Listening on Port %s", port);
|
|
61
|
-
});
|
|
62
|
-
// before we close fastify, make sure all server instances are closed
|
|
63
|
-
fastify.addHook("preClose", async () => {
|
|
64
|
-
if (typeof server !== "undefined") {
|
|
65
|
-
await server.closeAll();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
// Client Functions
|
|
70
|
-
const client = new hL7Client_js_1.HL7Client();
|
|
71
|
-
// run these before fastify closes
|
|
72
|
-
fastify.addHook("preClose", async () => {
|
|
73
|
-
if (typeof client !== "undefined") {
|
|
74
|
-
await client.closeAll();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
decorateFastifyInstance(fastify, opts, {
|
|
78
|
-
_serverInstance: serverInstance,
|
|
79
|
-
buildBatch: function (props) {
|
|
80
|
-
return client.buildBatch(props);
|
|
81
|
-
},
|
|
82
|
-
buildDate: function (date, length) {
|
|
83
|
-
return client.buildDate(date, length);
|
|
84
|
-
},
|
|
85
|
-
buildFileBatch: function (props) {
|
|
86
|
-
return client.buildFileBatch(props);
|
|
87
|
-
},
|
|
88
|
-
buildMessage: function (props) {
|
|
89
|
-
return client.buildMessage(props);
|
|
90
|
-
},
|
|
91
|
-
closeServer: async function (port) {
|
|
92
|
-
if (typeof server !== "undefined") {
|
|
93
|
-
return await server.close(port);
|
|
94
|
-
}
|
|
95
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
96
|
-
},
|
|
97
|
-
closeServerAll: async () => {
|
|
98
|
-
if (typeof server !== "undefined") {
|
|
99
|
-
return await server.closeAll();
|
|
100
|
-
}
|
|
101
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
102
|
-
},
|
|
103
|
-
createClient: function (name, props) {
|
|
104
|
-
return client.createClient(name, props);
|
|
105
|
-
},
|
|
106
|
-
createInbound: function (name, props, handler) {
|
|
107
|
-
if (typeof server !== "undefined") {
|
|
108
|
-
return server.createInbound(name, props, handler);
|
|
109
|
-
}
|
|
110
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
111
|
-
},
|
|
112
|
-
createConnection: function (name, props, handler) {
|
|
113
|
-
return client.createConnection(name, props, handler);
|
|
114
|
-
},
|
|
115
|
-
getClientByName: function (name) {
|
|
116
|
-
return client.getClientByName(name);
|
|
117
|
-
},
|
|
118
|
-
getClientConnectionByPort: function (port) {
|
|
119
|
-
return client.getClientConnectionByPort(port);
|
|
120
|
-
},
|
|
121
|
-
getServerByName: function (name) {
|
|
122
|
-
if (typeof server !== "undefined") {
|
|
123
|
-
return server.getServerByName(name);
|
|
124
|
-
}
|
|
125
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
126
|
-
},
|
|
127
|
-
getServerByPort: function (port) {
|
|
128
|
-
if (typeof server !== "undefined") {
|
|
129
|
-
return server.getServerByPort(port);
|
|
130
|
-
}
|
|
131
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
132
|
-
},
|
|
133
|
-
processHL7: function (text) {
|
|
134
|
-
return client.processHL7(text);
|
|
135
|
-
},
|
|
136
|
-
readFile: function (fullFilePath) {
|
|
137
|
-
return client.readFile(fullFilePath);
|
|
138
|
-
},
|
|
139
|
-
readFileBuffer: function (fileBuffer) {
|
|
140
|
-
return client.readFileBuffer(fileBuffer);
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
exports.default = fastifyHL7;
|
package/lib/cjs/package.json
DELETED
package/lib/cjs/types.js
DELETED
package/lib/cjs/validation.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validateOpts = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @since 1.0.0
|
|
6
|
-
* @param opts
|
|
7
|
-
*/
|
|
8
|
-
const validateOpts = async (opts) => {
|
|
9
|
-
// Mandatory, Defaulted
|
|
10
|
-
if (typeof opts.enableServer === "undefined") {
|
|
11
|
-
opts.enableServer = true;
|
|
12
|
-
}
|
|
13
|
-
return opts;
|
|
14
|
-
};
|
|
15
|
-
exports.validateOpts = validateOpts;
|
package/lib/esm/api.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { HL7 } from "fastify";
|
|
2
|
-
import fastifyHL7 from ".";
|
|
3
|
-
import { AServers, FastifyHL7Options } from "./decorate.js";
|
|
4
|
-
import { HL7Client } from "./class/hL7Client.js";
|
|
5
|
-
import { HL7Server } from "./class/hL7Server.js";
|
|
6
|
-
export default fastifyHL7;
|
|
7
|
-
export { fastifyHL7, HL7, FastifyHL7Options, HL7Client, HL7Server, AServers };
|