fastify-hl7 2.0.0 → 2.2.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/lib/cjs/api.js +3 -3
- package/lib/cjs/class/hL7Client.js +66 -116
- package/lib/cjs/class/hL7Server.js +28 -85
- package/lib/cjs/errors.js +1 -1
- package/lib/cjs/index.js +102 -173
- package/lib/cjs/validation.js +7 -45
- package/lib/esm/api.d.ts +7 -0
- package/lib/esm/class/hL7Client.d.ts +99 -0
- package/lib/esm/class/hL7Client.js +15 -7
- package/lib/esm/class/hL7Server.d.ts +37 -0
- package/lib/esm/class/hL7Server.js +0 -2
- package/lib/esm/decorate.d.ts +38 -0
- package/lib/esm/errors.d.ts +10 -0
- package/lib/esm/index.d.ts +5 -0
- package/lib/esm/index.js +4 -1
- package/lib/esm/types.d.ts +66 -0
- package/lib/esm/validation.d.ts +6 -0
- package/lib/types/class/hL7Client.d.ts +14 -5
- package/lib/types/types.d.ts +4 -1
- package/package.json +20 -21
package/lib/cjs/api.js
CHANGED
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HL7Server = exports.HL7Client = exports.fastifyHL7 = void 0;
|
|
7
|
-
|
|
7
|
+
const _1 = __importDefault(require("."));
|
|
8
8
|
exports.fastifyHL7 = _1.default;
|
|
9
|
-
|
|
9
|
+
const hL7Client_js_1 = require("./class/hL7Client.js");
|
|
10
10
|
Object.defineProperty(exports, "HL7Client", { enumerable: true, get: function () { return hL7Client_js_1.HL7Client; } });
|
|
11
|
-
|
|
11
|
+
const hL7Server_js_1 = require("./class/hL7Server.js");
|
|
12
12
|
Object.defineProperty(exports, "HL7Server", { enumerable: true, get: function () { return hL7Server_js_1.HL7Server; } });
|
|
13
13
|
exports.default = _1.default;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -33,122 +22,84 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
22
|
__setModuleDefault(result, mod);
|
|
34
23
|
return result;
|
|
35
24
|
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
-
function step(op) {
|
|
50
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
-
switch (op[0]) {
|
|
55
|
-
case 0: case 1: t = op; break;
|
|
56
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
-
default:
|
|
60
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
-
if (t[2]) _.ops.pop();
|
|
65
|
-
_.trys.pop(); continue;
|
|
66
|
-
}
|
|
67
|
-
op = body.call(thisArg, _);
|
|
68
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
26
|
exports.HL7Client = void 0;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
27
|
+
const node_hl7_client_1 = __importStar(require("node-hl7-client"));
|
|
28
|
+
const errors_js_1 = require("../errors.js");
|
|
29
|
+
class HL7Client {
|
|
30
|
+
constructor() {
|
|
78
31
|
this._clientConnections = [];
|
|
79
32
|
}
|
|
80
33
|
/**
|
|
81
34
|
* Close All Connections for this Client
|
|
82
35
|
* @since 1.0.0
|
|
83
36
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this._clientConnections.forEach(function (outbound) {
|
|
89
|
-
outbound.ports.map(function (port) { return __awaiter(_this, void 0, void 0, function () {
|
|
90
|
-
return __generator(this, function (_a) {
|
|
91
|
-
switch (_a.label) {
|
|
92
|
-
case 0: return [4 /*yield*/, port.connection.close()];
|
|
93
|
-
case 1:
|
|
94
|
-
_a.sent();
|
|
95
|
-
return [2 /*return*/];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}); });
|
|
99
|
-
});
|
|
100
|
-
return [2 /*return*/, true];
|
|
37
|
+
async closeAll() {
|
|
38
|
+
this._clientConnections.forEach(outbound => {
|
|
39
|
+
outbound.ports.map(async (port) => {
|
|
40
|
+
await port.connection.close();
|
|
101
41
|
});
|
|
102
42
|
});
|
|
103
|
-
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
104
45
|
/**
|
|
105
46
|
* Build a HL7 Batch
|
|
106
47
|
* @description Create a properly formatted HL7 Batch.
|
|
107
48
|
* @since 1.0.0
|
|
108
49
|
* @param props
|
|
109
50
|
*/
|
|
110
|
-
|
|
51
|
+
buildBatch(props) {
|
|
111
52
|
if (typeof props !== 'undefined' && typeof props.text !== 'undefined') {
|
|
112
53
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('Use processMessage method. This is for building.');
|
|
113
54
|
}
|
|
114
|
-
return new node_hl7_client_1.Batch(
|
|
115
|
-
}
|
|
55
|
+
return new node_hl7_client_1.Batch({ ...props });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Build Date
|
|
59
|
+
* @description Build a date string based off HL7 Standards
|
|
60
|
+
* @since 2.1.0
|
|
61
|
+
* @param date
|
|
62
|
+
* @param length Options are 8, 12, or 14 (default)
|
|
63
|
+
*/
|
|
64
|
+
buildDate(date, length) {
|
|
65
|
+
return (0, node_hl7_client_1.createHL7Date)(date, length);
|
|
66
|
+
}
|
|
116
67
|
/**
|
|
117
68
|
* Build a HL7 File Batch
|
|
118
69
|
* @description Create a properly formatted HL7 File Batch.
|
|
119
70
|
* @since 1.0.0
|
|
120
71
|
* @param props
|
|
121
72
|
*/
|
|
122
|
-
|
|
73
|
+
buildFileBatch(props) {
|
|
123
74
|
if (typeof props !== 'undefined' && (typeof props.fullFilePath !== 'undefined' || typeof props.fileBuffer !== 'undefined')) {
|
|
124
75
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('Use readFile or readFileBuffer method. This is for building.');
|
|
125
76
|
}
|
|
126
|
-
return new node_hl7_client_1.FileBatch(
|
|
127
|
-
}
|
|
77
|
+
return new node_hl7_client_1.FileBatch({ ...props });
|
|
78
|
+
}
|
|
128
79
|
/**
|
|
129
80
|
* Build a HL7 Message
|
|
130
81
|
* @description Create a properly formatted HL7 message.
|
|
131
82
|
* @since 1.0.0
|
|
132
83
|
* @param props
|
|
133
84
|
*/
|
|
134
|
-
|
|
85
|
+
buildMessage(props) {
|
|
135
86
|
if (typeof props !== 'undefined' && typeof props.text !== 'undefined') {
|
|
136
87
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('Use processMessage method. This is for building.');
|
|
137
88
|
}
|
|
138
|
-
return new node_hl7_client_1.Message(
|
|
139
|
-
}
|
|
89
|
+
return new node_hl7_client_1.Message({ ...props });
|
|
90
|
+
}
|
|
140
91
|
/**
|
|
141
92
|
*
|
|
142
93
|
* @param name
|
|
143
94
|
* @param props
|
|
144
95
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
96
|
+
createClient(name, props) {
|
|
97
|
+
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
147
98
|
if (nameFormat.test(name)) {
|
|
148
99
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};\':"\\\\|,.<>\\/?~.');
|
|
149
100
|
}
|
|
150
101
|
// make sure that this does not exist already...
|
|
151
|
-
this._clientConnections.forEach(
|
|
102
|
+
this._clientConnections.forEach((connections) => {
|
|
152
103
|
if (connections.name === name) {
|
|
153
104
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('name must be unique.');
|
|
154
105
|
}
|
|
@@ -158,15 +109,15 @@ var HL7Client = /** @class */ (function () {
|
|
|
158
109
|
// }
|
|
159
110
|
});
|
|
160
111
|
// new client
|
|
161
|
-
|
|
112
|
+
const client = new node_hl7_client_1.default(props);
|
|
162
113
|
// add it to the collection
|
|
163
114
|
this._clientConnections.push({
|
|
164
|
-
name
|
|
165
|
-
client
|
|
115
|
+
name,
|
|
116
|
+
client,
|
|
166
117
|
ports: []
|
|
167
118
|
});
|
|
168
119
|
return client;
|
|
169
|
-
}
|
|
120
|
+
}
|
|
170
121
|
/**
|
|
171
122
|
* Create an HL7 Outbound Connection
|
|
172
123
|
* @description Connect to an HL7 Server/Broker
|
|
@@ -175,70 +126,70 @@ var HL7Client = /** @class */ (function () {
|
|
|
175
126
|
* @param props
|
|
176
127
|
* @param handler
|
|
177
128
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
129
|
+
createConnection(name, props, handler) {
|
|
130
|
+
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
180
131
|
if (nameFormat.test(name)) {
|
|
181
132
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};\':"\\\\|,.<>\\/?~.');
|
|
182
133
|
}
|
|
183
|
-
|
|
134
|
+
const getConnection = this._clientConnections.find(client => client.name === name);
|
|
184
135
|
if (typeof getConnection !== 'undefined') {
|
|
185
136
|
// make sure port is not used all ready
|
|
186
|
-
getConnection.ports.forEach(
|
|
137
|
+
getConnection.ports.forEach((outbound) => {
|
|
187
138
|
if (outbound.port === props.port.toString()) {
|
|
188
|
-
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE(
|
|
139
|
+
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE(`port ${props.port} is already used with this client. Choose a new outgoing port.`);
|
|
189
140
|
}
|
|
190
141
|
});
|
|
191
142
|
// create outbound port to the server in getConnection.client
|
|
192
|
-
|
|
143
|
+
const outbound = new node_hl7_client_1.Connection(getConnection.client, props, handler);
|
|
193
144
|
// add it to the array of known ports. need to know this, so we can get it later if needed.
|
|
194
145
|
getConnection.ports.push({ port: props.port.toString(), connection: outbound });
|
|
195
146
|
// return it right away. the user might do something with it.
|
|
196
147
|
return outbound;
|
|
197
148
|
}
|
|
198
149
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('No valid client. Improper setup of a outbound connection.');
|
|
199
|
-
}
|
|
150
|
+
}
|
|
200
151
|
/**
|
|
201
152
|
* Get Client by the name
|
|
202
153
|
* @since 1.0.0
|
|
203
154
|
* @param name
|
|
204
155
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
156
|
+
getClientByName(name) {
|
|
157
|
+
const connection = this._clientConnections.find(connection => connection.name === name);
|
|
207
158
|
if (typeof connection !== 'undefined') {
|
|
208
159
|
return connection.client;
|
|
209
160
|
}
|
|
210
161
|
return undefined;
|
|
211
|
-
}
|
|
162
|
+
}
|
|
212
163
|
/**
|
|
213
164
|
* Get Connection by Port
|
|
214
165
|
* @since 1.0.0
|
|
215
166
|
* @param port
|
|
216
167
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this._clientConnections.forEach(
|
|
220
|
-
outbound.ports.forEach(
|
|
168
|
+
getClientConnectionByPort(port) {
|
|
169
|
+
let connection;
|
|
170
|
+
this._clientConnections.forEach(outbound => {
|
|
171
|
+
outbound.ports.forEach(aPort => {
|
|
221
172
|
if (aPort.port === port) {
|
|
222
173
|
connection = aPort.connection;
|
|
223
174
|
}
|
|
224
175
|
});
|
|
225
176
|
});
|
|
226
177
|
return connection;
|
|
227
|
-
}
|
|
178
|
+
}
|
|
228
179
|
/**
|
|
229
180
|
* Process a HL7
|
|
230
181
|
* @description A HL7 message that could either be a Message (MSH) or Batch (BHS)
|
|
231
182
|
* @since 1.0.0
|
|
232
183
|
* @param text Raw HL& String
|
|
233
184
|
*/
|
|
234
|
-
|
|
185
|
+
processHL7(text) {
|
|
235
186
|
if ((0, node_hl7_client_1.isBatch)(text)) {
|
|
236
|
-
return new node_hl7_client_1.Batch({ text
|
|
187
|
+
return new node_hl7_client_1.Batch({ text });
|
|
237
188
|
}
|
|
238
189
|
else {
|
|
239
|
-
return new node_hl7_client_1.Message({ text
|
|
190
|
+
return new node_hl7_client_1.Message({ text });
|
|
240
191
|
}
|
|
241
|
-
}
|
|
192
|
+
}
|
|
242
193
|
/**
|
|
243
194
|
* Read File
|
|
244
195
|
* @description Pass the correct path of the file you want to read.
|
|
@@ -246,13 +197,13 @@ var HL7Client = /** @class */ (function () {
|
|
|
246
197
|
* @param fullFilePath
|
|
247
198
|
* @returns FileBatch
|
|
248
199
|
* @example
|
|
249
|
-
*
|
|
200
|
+
* ```ts
|
|
250
201
|
* fastify.hl7.readFile( path.join('temp/', 'hl7.readTestBHS.20231208.hl7') )
|
|
251
|
-
*
|
|
202
|
+
* ```
|
|
252
203
|
*/
|
|
253
|
-
|
|
254
|
-
return new node_hl7_client_1.FileBatch({ fullFilePath
|
|
255
|
-
}
|
|
204
|
+
readFile(fullFilePath) {
|
|
205
|
+
return new node_hl7_client_1.FileBatch({ fullFilePath });
|
|
206
|
+
}
|
|
256
207
|
/**
|
|
257
208
|
* Read a File Buffer
|
|
258
209
|
* @description Translate an already Buffered HL7 FHS segment to decode it.
|
|
@@ -260,14 +211,13 @@ var HL7Client = /** @class */ (function () {
|
|
|
260
211
|
* @param fileBuffer
|
|
261
212
|
* @returns FileBatch
|
|
262
213
|
* @example
|
|
263
|
-
*
|
|
214
|
+
* ```ts
|
|
264
215
|
* const fileBuffer = fs.readFileSync(path.join('temp/', 'hl7.readTestBHS.20231208.hl7'))
|
|
265
216
|
* fastify.hl7.readFileBuffer(fileBuffer)
|
|
266
|
-
*
|
|
217
|
+
* ```
|
|
267
218
|
*/
|
|
268
|
-
|
|
269
|
-
return new node_hl7_client_1.FileBatch({ fileBuffer
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
}());
|
|
219
|
+
readFileBuffer(fileBuffer) {
|
|
220
|
+
return new node_hl7_client_1.FileBatch({ fileBuffer });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
273
223
|
exports.HL7Client = HL7Client;
|
|
@@ -1,46 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.HL7Server = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
4
|
+
const node_hl7_server_1 = require("node-hl7-server");
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
6
|
+
class HL7Server {
|
|
7
|
+
constructor(server) {
|
|
44
8
|
this._server = server;
|
|
45
9
|
this._serverInboundConnections = [];
|
|
46
10
|
}
|
|
@@ -49,43 +13,23 @@ var HL7Server = /** @class */ (function () {
|
|
|
49
13
|
* @since 1.0.0
|
|
50
14
|
* @param port
|
|
51
15
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!(typeof inbound !== 'undefined')) return [3 /*break*/, 2];
|
|
60
|
-
return [4 /*yield*/, inbound.server.close()]; // close the server for all inbound connections
|
|
61
|
-
case 1: return [2 /*return*/, _a.sent()]; // close the server for all inbound connections
|
|
62
|
-
case 2: throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE("No inbound server listening on port: ".concat(port));
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
};
|
|
16
|
+
async close(port) {
|
|
17
|
+
const inbound = this._serverInboundConnections.find(server => server.port === port);
|
|
18
|
+
if (typeof inbound !== 'undefined') {
|
|
19
|
+
return await inbound.server.close(); // close the server for all inbound connections
|
|
20
|
+
}
|
|
21
|
+
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE(`No inbound server listening on port: ${port}`);
|
|
22
|
+
}
|
|
67
23
|
/**
|
|
68
24
|
* Close all Inbound connections.
|
|
69
25
|
* @since 1.0.0
|
|
70
26
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return __generator(this, function (_a) {
|
|
75
|
-
this._serverInboundConnections.map(function (inbound) { return __awaiter(_this, void 0, void 0, function () {
|
|
76
|
-
return __generator(this, function (_a) {
|
|
77
|
-
switch (_a.label) {
|
|
78
|
-
case 0: return [4 /*yield*/, inbound.server.close()];
|
|
79
|
-
case 1:
|
|
80
|
-
_a.sent();
|
|
81
|
-
return [2 /*return*/];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}); });
|
|
85
|
-
return [2 /*return*/, true];
|
|
86
|
-
});
|
|
27
|
+
async closeAll() {
|
|
28
|
+
this._serverInboundConnections.map(async (inbound) => {
|
|
29
|
+
await inbound.server.close();
|
|
87
30
|
});
|
|
88
|
-
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
89
33
|
/**
|
|
90
34
|
* Create Inbound connection.
|
|
91
35
|
* @since 1.0.0
|
|
@@ -93,43 +37,42 @@ var HL7Server = /** @class */ (function () {
|
|
|
93
37
|
* @param props
|
|
94
38
|
* @param handler
|
|
95
39
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
40
|
+
createInbound(name, props, handler) {
|
|
41
|
+
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
98
42
|
if (nameFormat.test(name)) {
|
|
99
43
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};\':"\\\\|,.<>\\/?~.');
|
|
100
44
|
}
|
|
101
|
-
|
|
45
|
+
const inbound = new node_hl7_server_1.Inbound(this._server, props, handler);
|
|
102
46
|
this._serverInboundConnections.push({
|
|
103
|
-
name
|
|
47
|
+
name,
|
|
104
48
|
port: props.port.toString(),
|
|
105
49
|
server: inbound
|
|
106
50
|
});
|
|
107
51
|
return inbound;
|
|
108
|
-
}
|
|
52
|
+
}
|
|
109
53
|
/**
|
|
110
54
|
* Get Server Inbound Connection by Name
|
|
111
55
|
* @since 1.0.0
|
|
112
56
|
* @param name
|
|
113
57
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
58
|
+
getServerByName(name) {
|
|
59
|
+
const inbound = this._serverInboundConnections.find(inbound => inbound.name === name);
|
|
116
60
|
if (typeof inbound !== 'undefined') {
|
|
117
61
|
return inbound.server;
|
|
118
62
|
}
|
|
119
63
|
return undefined;
|
|
120
|
-
}
|
|
64
|
+
}
|
|
121
65
|
/**
|
|
122
66
|
* Get Server Inbound Connection by Port
|
|
123
67
|
* @since 1.0.0
|
|
124
68
|
* @param port
|
|
125
69
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
70
|
+
getServerByPort(port) {
|
|
71
|
+
const inbound = this._serverInboundConnections.find(inbound => inbound.port === port);
|
|
128
72
|
if (typeof inbound !== 'undefined') {
|
|
129
73
|
return inbound.server;
|
|
130
74
|
}
|
|
131
75
|
return undefined;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
}());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
135
78
|
exports.HL7Server = HL7Server;
|
package/lib/cjs/errors.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.errors = void 0;
|
|
7
|
-
|
|
7
|
+
const error_1 = __importDefault(require("@fastify/error"));
|
|
8
8
|
exports.errors = {
|
|
9
9
|
/** Error if there is an setup error of the plugin itself. */
|
|
10
10
|
FASTIFY_HL7_ERR_SETUP_ERRORS: (0, error_1.default)('FASTIFY_HL7_ERR_SETUP_ERRORS', 'Setup error: %s'),
|