fastify-hl7 2.1.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 +58 -118
- package/lib/cjs/class/hL7Server.js +28 -85
- package/lib/cjs/errors.js +1 -1
- package/lib/cjs/index.js +102 -176
- 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 +4 -6
- 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 +1 -1
- package/lib/esm/types.d.ts +66 -0
- package/lib/esm/validation.d.ts +6 -0
- package/lib/types/class/hL7Client.d.ts +6 -5
- package/lib/types/types.d.ts +0 -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,86 +22,38 @@ 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
|
+
}
|
|
116
57
|
/**
|
|
117
58
|
* Build Date
|
|
118
59
|
* @description Build a date string based off HL7 Standards
|
|
@@ -120,45 +61,45 @@ var HL7Client = /** @class */ (function () {
|
|
|
120
61
|
* @param date
|
|
121
62
|
* @param length Options are 8, 12, or 14 (default)
|
|
122
63
|
*/
|
|
123
|
-
|
|
64
|
+
buildDate(date, length) {
|
|
124
65
|
return (0, node_hl7_client_1.createHL7Date)(date, length);
|
|
125
|
-
}
|
|
66
|
+
}
|
|
126
67
|
/**
|
|
127
68
|
* Build a HL7 File Batch
|
|
128
69
|
* @description Create a properly formatted HL7 File Batch.
|
|
129
70
|
* @since 1.0.0
|
|
130
71
|
* @param props
|
|
131
72
|
*/
|
|
132
|
-
|
|
73
|
+
buildFileBatch(props) {
|
|
133
74
|
if (typeof props !== 'undefined' && (typeof props.fullFilePath !== 'undefined' || typeof props.fileBuffer !== 'undefined')) {
|
|
134
75
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('Use readFile or readFileBuffer method. This is for building.');
|
|
135
76
|
}
|
|
136
|
-
return new node_hl7_client_1.FileBatch(
|
|
137
|
-
}
|
|
77
|
+
return new node_hl7_client_1.FileBatch({ ...props });
|
|
78
|
+
}
|
|
138
79
|
/**
|
|
139
80
|
* Build a HL7 Message
|
|
140
81
|
* @description Create a properly formatted HL7 message.
|
|
141
82
|
* @since 1.0.0
|
|
142
83
|
* @param props
|
|
143
84
|
*/
|
|
144
|
-
|
|
85
|
+
buildMessage(props) {
|
|
145
86
|
if (typeof props !== 'undefined' && typeof props.text !== 'undefined') {
|
|
146
87
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('Use processMessage method. This is for building.');
|
|
147
88
|
}
|
|
148
|
-
return new node_hl7_client_1.Message(
|
|
149
|
-
}
|
|
89
|
+
return new node_hl7_client_1.Message({ ...props });
|
|
90
|
+
}
|
|
150
91
|
/**
|
|
151
92
|
*
|
|
152
93
|
* @param name
|
|
153
94
|
* @param props
|
|
154
95
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
96
|
+
createClient(name, props) {
|
|
97
|
+
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
157
98
|
if (nameFormat.test(name)) {
|
|
158
99
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};\':"\\\\|,.<>\\/?~.');
|
|
159
100
|
}
|
|
160
101
|
// make sure that this does not exist already...
|
|
161
|
-
this._clientConnections.forEach(
|
|
102
|
+
this._clientConnections.forEach((connections) => {
|
|
162
103
|
if (connections.name === name) {
|
|
163
104
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('name must be unique.');
|
|
164
105
|
}
|
|
@@ -168,15 +109,15 @@ var HL7Client = /** @class */ (function () {
|
|
|
168
109
|
// }
|
|
169
110
|
});
|
|
170
111
|
// new client
|
|
171
|
-
|
|
112
|
+
const client = new node_hl7_client_1.default(props);
|
|
172
113
|
// add it to the collection
|
|
173
114
|
this._clientConnections.push({
|
|
174
|
-
name
|
|
175
|
-
client
|
|
115
|
+
name,
|
|
116
|
+
client,
|
|
176
117
|
ports: []
|
|
177
118
|
});
|
|
178
119
|
return client;
|
|
179
|
-
}
|
|
120
|
+
}
|
|
180
121
|
/**
|
|
181
122
|
* Create an HL7 Outbound Connection
|
|
182
123
|
* @description Connect to an HL7 Server/Broker
|
|
@@ -185,70 +126,70 @@ var HL7Client = /** @class */ (function () {
|
|
|
185
126
|
* @param props
|
|
186
127
|
* @param handler
|
|
187
128
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
129
|
+
createConnection(name, props, handler) {
|
|
130
|
+
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
190
131
|
if (nameFormat.test(name)) {
|
|
191
132
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};\':"\\\\|,.<>\\/?~.');
|
|
192
133
|
}
|
|
193
|
-
|
|
134
|
+
const getConnection = this._clientConnections.find(client => client.name === name);
|
|
194
135
|
if (typeof getConnection !== 'undefined') {
|
|
195
136
|
// make sure port is not used all ready
|
|
196
|
-
getConnection.ports.forEach(
|
|
137
|
+
getConnection.ports.forEach((outbound) => {
|
|
197
138
|
if (outbound.port === props.port.toString()) {
|
|
198
|
-
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.`);
|
|
199
140
|
}
|
|
200
141
|
});
|
|
201
142
|
// create outbound port to the server in getConnection.client
|
|
202
|
-
|
|
143
|
+
const outbound = new node_hl7_client_1.Connection(getConnection.client, props, handler);
|
|
203
144
|
// add it to the array of known ports. need to know this, so we can get it later if needed.
|
|
204
145
|
getConnection.ports.push({ port: props.port.toString(), connection: outbound });
|
|
205
146
|
// return it right away. the user might do something with it.
|
|
206
147
|
return outbound;
|
|
207
148
|
}
|
|
208
149
|
throw new errors_js_1.errors.FASTIFY_HL7_ERR_USAGE('No valid client. Improper setup of a outbound connection.');
|
|
209
|
-
}
|
|
150
|
+
}
|
|
210
151
|
/**
|
|
211
152
|
* Get Client by the name
|
|
212
153
|
* @since 1.0.0
|
|
213
154
|
* @param name
|
|
214
155
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
156
|
+
getClientByName(name) {
|
|
157
|
+
const connection = this._clientConnections.find(connection => connection.name === name);
|
|
217
158
|
if (typeof connection !== 'undefined') {
|
|
218
159
|
return connection.client;
|
|
219
160
|
}
|
|
220
161
|
return undefined;
|
|
221
|
-
}
|
|
162
|
+
}
|
|
222
163
|
/**
|
|
223
164
|
* Get Connection by Port
|
|
224
165
|
* @since 1.0.0
|
|
225
166
|
* @param port
|
|
226
167
|
*/
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this._clientConnections.forEach(
|
|
230
|
-
outbound.ports.forEach(
|
|
168
|
+
getClientConnectionByPort(port) {
|
|
169
|
+
let connection;
|
|
170
|
+
this._clientConnections.forEach(outbound => {
|
|
171
|
+
outbound.ports.forEach(aPort => {
|
|
231
172
|
if (aPort.port === port) {
|
|
232
173
|
connection = aPort.connection;
|
|
233
174
|
}
|
|
234
175
|
});
|
|
235
176
|
});
|
|
236
177
|
return connection;
|
|
237
|
-
}
|
|
178
|
+
}
|
|
238
179
|
/**
|
|
239
180
|
* Process a HL7
|
|
240
181
|
* @description A HL7 message that could either be a Message (MSH) or Batch (BHS)
|
|
241
182
|
* @since 1.0.0
|
|
242
183
|
* @param text Raw HL& String
|
|
243
184
|
*/
|
|
244
|
-
|
|
185
|
+
processHL7(text) {
|
|
245
186
|
if ((0, node_hl7_client_1.isBatch)(text)) {
|
|
246
|
-
return new node_hl7_client_1.Batch({ text
|
|
187
|
+
return new node_hl7_client_1.Batch({ text });
|
|
247
188
|
}
|
|
248
189
|
else {
|
|
249
|
-
return new node_hl7_client_1.Message({ text
|
|
190
|
+
return new node_hl7_client_1.Message({ text });
|
|
250
191
|
}
|
|
251
|
-
}
|
|
192
|
+
}
|
|
252
193
|
/**
|
|
253
194
|
* Read File
|
|
254
195
|
* @description Pass the correct path of the file you want to read.
|
|
@@ -256,13 +197,13 @@ var HL7Client = /** @class */ (function () {
|
|
|
256
197
|
* @param fullFilePath
|
|
257
198
|
* @returns FileBatch
|
|
258
199
|
* @example
|
|
259
|
-
*
|
|
200
|
+
* ```ts
|
|
260
201
|
* fastify.hl7.readFile( path.join('temp/', 'hl7.readTestBHS.20231208.hl7') )
|
|
261
|
-
*
|
|
202
|
+
* ```
|
|
262
203
|
*/
|
|
263
|
-
|
|
264
|
-
return new node_hl7_client_1.FileBatch({ fullFilePath
|
|
265
|
-
}
|
|
204
|
+
readFile(fullFilePath) {
|
|
205
|
+
return new node_hl7_client_1.FileBatch({ fullFilePath });
|
|
206
|
+
}
|
|
266
207
|
/**
|
|
267
208
|
* Read a File Buffer
|
|
268
209
|
* @description Translate an already Buffered HL7 FHS segment to decode it.
|
|
@@ -270,14 +211,13 @@ var HL7Client = /** @class */ (function () {
|
|
|
270
211
|
* @param fileBuffer
|
|
271
212
|
* @returns FileBatch
|
|
272
213
|
* @example
|
|
273
|
-
*
|
|
214
|
+
* ```ts
|
|
274
215
|
* const fileBuffer = fs.readFileSync(path.join('temp/', 'hl7.readTestBHS.20231208.hl7'))
|
|
275
216
|
* fastify.hl7.readFileBuffer(fileBuffer)
|
|
276
|
-
*
|
|
217
|
+
* ```
|
|
277
218
|
*/
|
|
278
|
-
|
|
279
|
-
return new node_hl7_client_1.FileBatch({ fileBuffer
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
}());
|
|
219
|
+
readFileBuffer(fileBuffer) {
|
|
220
|
+
return new node_hl7_client_1.FileBatch({ fileBuffer });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
283
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'),
|