fastify-hl7 3.0.0 → 3.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/README.md +26 -23
- package/lib/cjs/class/hL7Client.js +49 -34
- package/lib/cjs/class/hL7Server.js +12 -9
- package/lib/cjs/errors.js +2 -2
- package/lib/cjs/index.js +27 -22
- package/lib/cjs/validation.js +1 -1
- package/lib/esm/api.d.ts +5 -5
- package/lib/esm/api.js +3 -3
- package/lib/esm/class/hL7Client.d.ts +9 -9
- package/lib/esm/class/hL7Client.js +34 -29
- package/lib/esm/class/hL7Server.d.ts +3 -2
- package/lib/esm/class/hL7Server.js +14 -11
- package/lib/esm/decorate.d.ts +2 -2
- package/lib/esm/errors.js +3 -3
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +34 -29
- package/lib/esm/types.d.ts +6 -6
- package/lib/esm/validation.d.ts +1 -1
- package/lib/esm/validation.js +1 -1
- package/lib/types/api.d.ts +5 -5
- package/lib/types/class/hL7Client.d.ts +9 -9
- package/lib/types/class/hL7Server.d.ts +3 -2
- package/lib/types/decorate.d.ts +2 -2
- package/lib/types/index.d.ts +2 -2
- package/lib/types/types.d.ts +6 -6
- package/lib/types/validation.d.ts +1 -1
- package/package.json +30 -28
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Client, { Batch, FileBatch, Connection, isBatch, Message, createHL7Date } from
|
|
2
|
-
import { errors } from
|
|
1
|
+
import Client, { Batch, FileBatch, Connection, isBatch, Message, createHL7Date, } from "node-hl7-client";
|
|
2
|
+
import { errors } from "../errors.js";
|
|
3
3
|
export class HL7Client {
|
|
4
4
|
constructor() {
|
|
5
5
|
this._clientConnections = [];
|
|
@@ -9,7 +9,7 @@ export class HL7Client {
|
|
|
9
9
|
* @since 1.0.0
|
|
10
10
|
*/
|
|
11
11
|
async closeAll() {
|
|
12
|
-
this._clientConnections.forEach(outbound => {
|
|
12
|
+
this._clientConnections.forEach((outbound) => {
|
|
13
13
|
outbound.ports.map(async (port) => {
|
|
14
14
|
await port.connection.close();
|
|
15
15
|
});
|
|
@@ -18,19 +18,19 @@ export class HL7Client {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Build a HL7 Batch
|
|
21
|
-
|
|
21
|
+
* @remarks Create a properly formatted HL7 Batch.
|
|
22
22
|
* @since 1.0.0
|
|
23
23
|
* @param props
|
|
24
24
|
*/
|
|
25
25
|
buildBatch(props) {
|
|
26
|
-
if (typeof props !==
|
|
27
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
26
|
+
if (typeof props !== "undefined" && typeof props.text !== "undefined") {
|
|
27
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("Use processMessage method. This is for building.");
|
|
28
28
|
}
|
|
29
29
|
return new Batch({ ...props });
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Build Date
|
|
33
|
-
|
|
33
|
+
* @remarks Build a date string based off HL7 Standards
|
|
34
34
|
* @since 2.1.0
|
|
35
35
|
* @param date
|
|
36
36
|
* @param length Options are 8, 12, or 14 (default)
|
|
@@ -40,25 +40,27 @@ export class HL7Client {
|
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Build a HL7 File Batch
|
|
43
|
-
|
|
43
|
+
* @remarks Create a properly formatted HL7 File Batch.
|
|
44
44
|
* @since 1.0.0
|
|
45
45
|
* @param props
|
|
46
46
|
*/
|
|
47
47
|
buildFileBatch(props) {
|
|
48
|
-
if (typeof props !==
|
|
49
|
-
|
|
48
|
+
if (typeof props !== "undefined" &&
|
|
49
|
+
(typeof props.fullFilePath !== "undefined" ||
|
|
50
|
+
typeof props.fileBuffer !== "undefined")) {
|
|
51
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("Use readFile or readFileBuffer method. This is for building.");
|
|
50
52
|
}
|
|
51
53
|
return new FileBatch({ ...props });
|
|
52
54
|
}
|
|
53
55
|
/**
|
|
54
56
|
* Build a HL7 Message
|
|
55
|
-
|
|
57
|
+
* @remarks Create a properly formatted HL7 message.
|
|
56
58
|
* @since 1.0.0
|
|
57
59
|
* @param props
|
|
58
60
|
*/
|
|
59
61
|
buildMessage(props) {
|
|
60
|
-
if (typeof props !==
|
|
61
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
62
|
+
if (typeof props !== "undefined" && typeof props.text !== "undefined") {
|
|
63
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("Use processMessage method. This is for building.");
|
|
62
64
|
}
|
|
63
65
|
return new Message({ ...props });
|
|
64
66
|
}
|
|
@@ -70,12 +72,12 @@ export class HL7Client {
|
|
|
70
72
|
createClient(name, props) {
|
|
71
73
|
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
72
74
|
if (nameFormat.test(name)) {
|
|
73
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
75
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
|
|
74
76
|
}
|
|
75
77
|
// make sure that this does not exist already...
|
|
76
78
|
this._clientConnections.forEach((connections) => {
|
|
77
79
|
if (connections.name === name) {
|
|
78
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
80
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("name must be unique.");
|
|
79
81
|
}
|
|
80
82
|
// nto in the Client class yet
|
|
81
83
|
// if (client.getHost() === props.host) {
|
|
@@ -88,13 +90,13 @@ export class HL7Client {
|
|
|
88
90
|
this._clientConnections.push({
|
|
89
91
|
name,
|
|
90
92
|
client,
|
|
91
|
-
ports: []
|
|
93
|
+
ports: [],
|
|
92
94
|
});
|
|
93
95
|
return client;
|
|
94
96
|
}
|
|
95
97
|
/**
|
|
96
98
|
* Create an HL7 Outbound Connection
|
|
97
|
-
|
|
99
|
+
* @remarks Connect to an HL7 Server/Broker
|
|
98
100
|
* @since 1.0.0
|
|
99
101
|
* @param name The name stored within created client connections.
|
|
100
102
|
* @param props
|
|
@@ -103,10 +105,10 @@ export class HL7Client {
|
|
|
103
105
|
createConnection(name, props, handler) {
|
|
104
106
|
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
105
107
|
if (nameFormat.test(name)) {
|
|
106
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
108
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
|
|
107
109
|
}
|
|
108
|
-
const getConnection = this._clientConnections.find(client => client.name === name);
|
|
109
|
-
if (typeof getConnection !==
|
|
110
|
+
const getConnection = this._clientConnections.find((client) => client.name === name);
|
|
111
|
+
if (typeof getConnection !== "undefined") {
|
|
110
112
|
// make sure port is not used all ready
|
|
111
113
|
getConnection.ports.forEach((outbound) => {
|
|
112
114
|
if (outbound.port === props.port.toString()) {
|
|
@@ -116,11 +118,14 @@ export class HL7Client {
|
|
|
116
118
|
// create outbound port to the server in getConnection.client
|
|
117
119
|
const outbound = new Connection(getConnection.client, props, handler);
|
|
118
120
|
// add it to the array of known ports. need to know this, so we can get it later if needed.
|
|
119
|
-
getConnection.ports.push({
|
|
121
|
+
getConnection.ports.push({
|
|
122
|
+
port: props.port.toString(),
|
|
123
|
+
connection: outbound,
|
|
124
|
+
});
|
|
120
125
|
// return it right away. the user might do something with it.
|
|
121
126
|
return outbound;
|
|
122
127
|
}
|
|
123
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
128
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("No valid client. Improper setup of a outbound connection.");
|
|
124
129
|
}
|
|
125
130
|
/**
|
|
126
131
|
* Get Client by the name
|
|
@@ -128,8 +133,8 @@ export class HL7Client {
|
|
|
128
133
|
* @param name
|
|
129
134
|
*/
|
|
130
135
|
getClientByName(name) {
|
|
131
|
-
const connection = this._clientConnections.find(connection => connection.name === name);
|
|
132
|
-
if (typeof connection !==
|
|
136
|
+
const connection = this._clientConnections.find((connection) => connection.name === name);
|
|
137
|
+
if (typeof connection !== "undefined") {
|
|
133
138
|
return connection.client;
|
|
134
139
|
}
|
|
135
140
|
return undefined;
|
|
@@ -141,8 +146,8 @@ export class HL7Client {
|
|
|
141
146
|
*/
|
|
142
147
|
getClientConnectionByPort(port) {
|
|
143
148
|
let connection;
|
|
144
|
-
this._clientConnections.forEach(outbound => {
|
|
145
|
-
outbound.ports.forEach(aPort => {
|
|
149
|
+
this._clientConnections.forEach((outbound) => {
|
|
150
|
+
outbound.ports.forEach((aPort) => {
|
|
146
151
|
if (aPort.port === port) {
|
|
147
152
|
connection = aPort.connection;
|
|
148
153
|
}
|
|
@@ -152,7 +157,7 @@ export class HL7Client {
|
|
|
152
157
|
}
|
|
153
158
|
/**
|
|
154
159
|
* Process a HL7
|
|
155
|
-
|
|
160
|
+
* @remarks A HL7 message that could either be a Message (MSH) or Batch (BHS)
|
|
156
161
|
* @since 1.0.0
|
|
157
162
|
* @param text Raw HL& String
|
|
158
163
|
*/
|
|
@@ -166,7 +171,7 @@ export class HL7Client {
|
|
|
166
171
|
}
|
|
167
172
|
/**
|
|
168
173
|
* Read File
|
|
169
|
-
|
|
174
|
+
* @remarks Pass the correct path of the file you want to read.
|
|
170
175
|
* @since 1.0.0
|
|
171
176
|
* @param fullFilePath
|
|
172
177
|
* @returns FileBatch
|
|
@@ -180,7 +185,7 @@ export class HL7Client {
|
|
|
180
185
|
}
|
|
181
186
|
/**
|
|
182
187
|
* Read a File Buffer
|
|
183
|
-
|
|
188
|
+
* @remarks Translate an already Buffered HL7 FHS segment to decode it.
|
|
184
189
|
* @since 1.0.0
|
|
185
190
|
* @param fileBuffer
|
|
186
191
|
* @returns FileBatch
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import Server, { Inbound, InboundHandler, ListenerOptions } from "node-hl7-server";
|
|
3
|
+
export declare class HL7Server extends EventEmitter {
|
|
3
4
|
private readonly _server;
|
|
4
5
|
private readonly _serverInboundConnections;
|
|
5
6
|
constructor(server: Server);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { Inbound, } from "node-hl7-server";
|
|
3
|
+
import { errors } from "../errors.js";
|
|
4
|
+
export class HL7Server extends EventEmitter {
|
|
4
5
|
constructor(server) {
|
|
6
|
+
super();
|
|
5
7
|
this._server = server;
|
|
6
8
|
this._serverInboundConnections = [];
|
|
7
9
|
}
|
|
@@ -11,8 +13,8 @@ export class HL7Server {
|
|
|
11
13
|
* @param port
|
|
12
14
|
*/
|
|
13
15
|
async close(port) {
|
|
14
|
-
const inbound = this._serverInboundConnections.find(server => server.port === port);
|
|
15
|
-
if (typeof inbound !==
|
|
16
|
+
const inbound = this._serverInboundConnections.find((server) => server.port === port);
|
|
17
|
+
if (typeof inbound !== "undefined") {
|
|
16
18
|
return await inbound.server.close(); // close the server for all inbound connections
|
|
17
19
|
}
|
|
18
20
|
throw new errors.FASTIFY_HL7_ERR_USAGE(`No inbound server listening on port: ${port}`);
|
|
@@ -37,14 +39,15 @@ export class HL7Server {
|
|
|
37
39
|
createInbound(name, props, handler) {
|
|
38
40
|
const nameFormat = /[ `!@#$%^&*()+\-=\[\]{};':"\\|,.<>\/?~]/; //eslint-disable-line
|
|
39
41
|
if (nameFormat.test(name)) {
|
|
40
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
42
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("name must not contain certain characters: `!@#$%^&*()+\\-=\\[\\]{};':\"\\\\|,.<>\\/?~.");
|
|
41
43
|
}
|
|
42
44
|
const inbound = new Inbound(this._server, props, handler);
|
|
43
45
|
this._serverInboundConnections.push({
|
|
44
46
|
name,
|
|
45
47
|
port: props.port.toString(),
|
|
46
|
-
server: inbound
|
|
48
|
+
server: inbound,
|
|
47
49
|
});
|
|
50
|
+
this.emit("inbound", props.port.toString());
|
|
48
51
|
return inbound;
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
@@ -53,8 +56,8 @@ export class HL7Server {
|
|
|
53
56
|
* @param name
|
|
54
57
|
*/
|
|
55
58
|
getServerByName(name) {
|
|
56
|
-
const inbound = this._serverInboundConnections.find(inbound => inbound.name === name);
|
|
57
|
-
if (typeof inbound !==
|
|
59
|
+
const inbound = this._serverInboundConnections.find((inbound) => inbound.name === name);
|
|
60
|
+
if (typeof inbound !== "undefined") {
|
|
58
61
|
return inbound.server;
|
|
59
62
|
}
|
|
60
63
|
return undefined;
|
|
@@ -65,8 +68,8 @@ export class HL7Server {
|
|
|
65
68
|
* @param port
|
|
66
69
|
*/
|
|
67
70
|
getServerByPort(port) {
|
|
68
|
-
const inbound = this._serverInboundConnections.find(inbound => inbound.port === port);
|
|
69
|
-
if (typeof inbound !==
|
|
71
|
+
const inbound = this._serverInboundConnections.find((inbound) => inbound.port === port);
|
|
72
|
+
if (typeof inbound !== "undefined") {
|
|
70
73
|
return inbound.server;
|
|
71
74
|
}
|
|
72
75
|
return undefined;
|
package/lib/esm/decorate.d.ts
CHANGED
package/lib/esm/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import createError from
|
|
1
|
+
import createError from "@fastify/error";
|
|
2
2
|
export const errors = {
|
|
3
3
|
/** Error if there is an setup error of the plugin itself. */
|
|
4
|
-
FASTIFY_HL7_ERR_SETUP_ERRORS: createError(
|
|
4
|
+
FASTIFY_HL7_ERR_SETUP_ERRORS: createError("FASTIFY_HL7_ERR_SETUP_ERRORS", "Setup error: %s"),
|
|
5
5
|
/** If an invalid usage error was done, this error would pop up. */
|
|
6
|
-
FASTIFY_HL7_ERR_USAGE: createError(
|
|
6
|
+
FASTIFY_HL7_ERR_USAGE: createError("FASTIFY_HL7_ERR_USAGE", "Usage error: %s"),
|
|
7
7
|
};
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FastifyHL7Options } from
|
|
2
|
-
export * from
|
|
1
|
+
import { FastifyHL7Options } from "./decorate.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
3
|
declare const fastifyHL7: import("fastify").FastifyPluginCallback<FastifyHL7Options, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
4
4
|
export default fastifyHL7;
|
|
5
5
|
export { FastifyHL7Options };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fp from
|
|
2
|
-
import Server from
|
|
3
|
-
import { HL7Server } from
|
|
4
|
-
import { HL7Client } from
|
|
5
|
-
import { errors } from
|
|
6
|
-
import { validateOpts } from
|
|
7
|
-
export * from
|
|
1
|
+
import fp from "fastify-plugin";
|
|
2
|
+
import Server from "node-hl7-server";
|
|
3
|
+
import { HL7Server } from "./class/hL7Server.js";
|
|
4
|
+
import { HL7Client } from "./class/hL7Client.js";
|
|
5
|
+
import { errors } from "./errors.js";
|
|
6
|
+
import { validateOpts } from "./validation.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
8
|
/**
|
|
9
9
|
* @since 1.0.0
|
|
10
10
|
* @param fastify
|
|
@@ -12,12 +12,12 @@ export * from './types.js';
|
|
|
12
12
|
* @param connection
|
|
13
13
|
*/
|
|
14
14
|
const decorateFastifyInstance = (fastify, _opts, connection) => {
|
|
15
|
-
if (typeof fastify.hl7 !==
|
|
16
|
-
throw new errors.FASTIFY_HL7_ERR_SETUP_ERRORS(
|
|
15
|
+
if (typeof fastify.hl7 !== "undefined") {
|
|
16
|
+
throw new errors.FASTIFY_HL7_ERR_SETUP_ERRORS("Already registered.");
|
|
17
17
|
}
|
|
18
|
-
if (typeof fastify.hl7 ===
|
|
19
|
-
fastify.log.trace(
|
|
20
|
-
fastify.decorate(
|
|
18
|
+
if (typeof fastify.hl7 === "undefined") {
|
|
19
|
+
fastify.log.trace("[fastify-hl7] Decorate Fastify");
|
|
20
|
+
fastify.decorate("hl7", connection);
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
const fastifyHL7 = fp(async (fastify, opts) => {
|
|
@@ -29,15 +29,20 @@ const fastifyHL7 = fp(async (fastify, opts) => {
|
|
|
29
29
|
// A server can host many HL7 Inbound connections via different ports, this is fine.
|
|
30
30
|
// Clients are different as an app could talk to different servers, on many ports.
|
|
31
31
|
// So we need to do something different.
|
|
32
|
-
const serverInstance =
|
|
32
|
+
const serverInstance = typeof opts.enableServer !== "undefined" && opts.enableServer
|
|
33
|
+
? new Server(opts.serverOptions)
|
|
34
|
+
: undefined;
|
|
33
35
|
// Server Functions
|
|
34
36
|
let server;
|
|
35
|
-
if (typeof serverInstance !==
|
|
37
|
+
if (typeof serverInstance !== "undefined") {
|
|
36
38
|
// Server Functions
|
|
37
39
|
server = new HL7Server(serverInstance);
|
|
40
|
+
server.on("inbound", (port) => {
|
|
41
|
+
fastify.log.info("HL7 Inbound Server Listening on Port %s", port);
|
|
42
|
+
});
|
|
38
43
|
// before we close fastify, make sure all server instances are closed
|
|
39
|
-
fastify.addHook(
|
|
40
|
-
if (typeof server !==
|
|
44
|
+
fastify.addHook("preClose", async () => {
|
|
45
|
+
if (typeof server !== "undefined") {
|
|
41
46
|
await server.closeAll();
|
|
42
47
|
}
|
|
43
48
|
});
|
|
@@ -45,8 +50,8 @@ const fastifyHL7 = fp(async (fastify, opts) => {
|
|
|
45
50
|
// Client Functions
|
|
46
51
|
const client = new HL7Client();
|
|
47
52
|
// run these before fastify closes
|
|
48
|
-
fastify.addHook(
|
|
49
|
-
if (typeof client !==
|
|
53
|
+
fastify.addHook("preClose", async () => {
|
|
54
|
+
if (typeof client !== "undefined") {
|
|
50
55
|
await client.closeAll();
|
|
51
56
|
}
|
|
52
57
|
});
|
|
@@ -65,25 +70,25 @@ const fastifyHL7 = fp(async (fastify, opts) => {
|
|
|
65
70
|
return client.buildMessage(props);
|
|
66
71
|
},
|
|
67
72
|
closeServer: async function (port) {
|
|
68
|
-
if (typeof server !==
|
|
73
|
+
if (typeof server !== "undefined") {
|
|
69
74
|
return await server.close(port);
|
|
70
75
|
}
|
|
71
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
76
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
72
77
|
},
|
|
73
78
|
closeServerAll: async () => {
|
|
74
|
-
if (typeof server !==
|
|
79
|
+
if (typeof server !== "undefined") {
|
|
75
80
|
return await server.closeAll();
|
|
76
81
|
}
|
|
77
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
82
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
78
83
|
},
|
|
79
84
|
createClient: function (name, props) {
|
|
80
85
|
return client.createClient(name, props);
|
|
81
86
|
},
|
|
82
87
|
createInbound: function (name, props, handler) {
|
|
83
|
-
if (typeof server !==
|
|
88
|
+
if (typeof server !== "undefined") {
|
|
84
89
|
return server.createInbound(name, props, handler);
|
|
85
90
|
}
|
|
86
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
91
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
87
92
|
},
|
|
88
93
|
createConnection: function (name, props, handler) {
|
|
89
94
|
return client.createConnection(name, props, handler);
|
|
@@ -95,16 +100,16 @@ const fastifyHL7 = fp(async (fastify, opts) => {
|
|
|
95
100
|
return client.getClientConnectionByPort(port);
|
|
96
101
|
},
|
|
97
102
|
getServerByName: function (name) {
|
|
98
|
-
if (typeof server !==
|
|
103
|
+
if (typeof server !== "undefined") {
|
|
99
104
|
return server.getServerByName(name);
|
|
100
105
|
}
|
|
101
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
106
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
102
107
|
},
|
|
103
108
|
getServerByPort: function (port) {
|
|
104
|
-
if (typeof server !==
|
|
109
|
+
if (typeof server !== "undefined") {
|
|
105
110
|
return server.getServerByPort(port);
|
|
106
111
|
}
|
|
107
|
-
throw new errors.FASTIFY_HL7_ERR_USAGE(
|
|
112
|
+
throw new errors.FASTIFY_HL7_ERR_USAGE("server was not started. re-register plugin with enableServer set to true.");
|
|
108
113
|
},
|
|
109
114
|
processHL7: function (text) {
|
|
110
115
|
return client.processHL7(text);
|
|
@@ -114,7 +119,7 @@ const fastifyHL7 = fp(async (fastify, opts) => {
|
|
|
114
119
|
},
|
|
115
120
|
readFileBuffer: function (fileBuffer) {
|
|
116
121
|
return client.readFileBuffer(fileBuffer);
|
|
117
|
-
}
|
|
122
|
+
},
|
|
118
123
|
});
|
|
119
124
|
});
|
|
120
125
|
export default fastifyHL7;
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Server, { Inbound, InboundHandler, ListenerOptions } from
|
|
2
|
-
import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, Connection, FileBatch, Message, OutboundHandler } from
|
|
3
|
-
declare module
|
|
1
|
+
import Server, { Inbound, InboundHandler, ListenerOptions } from "node-hl7-server";
|
|
2
|
+
import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, Connection, FileBatch, Message, OutboundHandler } from "node-hl7-client";
|
|
3
|
+
declare module "fastify" {
|
|
4
4
|
interface HL7 {
|
|
5
5
|
/** Server Instance
|
|
6
6
|
* @since 1.0.0 **/
|
|
@@ -25,14 +25,14 @@ declare module 'fastify' {
|
|
|
25
25
|
* @since 1.0.0 */
|
|
26
26
|
closeServerAll: () => Promise<boolean>;
|
|
27
27
|
/** Create Client
|
|
28
|
-
|
|
28
|
+
* @remarks Connecting to a remote server/broker that accepts connections.
|
|
29
29
|
* @since 1.0.0 */
|
|
30
30
|
createClient: (name: string, props: ClientOptions) => Client;
|
|
31
31
|
/** Create an incoming port connection on the server.
|
|
32
32
|
* @since 1.0.0 */
|
|
33
33
|
createInbound: (name: string, props: ListenerOptions, handler: InboundHandler) => Inbound;
|
|
34
34
|
/** Create Outgoing Client Port
|
|
35
|
-
|
|
35
|
+
* @remarks This is on the established client that we are already a part off.
|
|
36
36
|
* @since 1.0.0 */
|
|
37
37
|
createConnection: (name: string, props: ClientListenerOptions, handler: OutboundHandler) => Connection;
|
|
38
38
|
/** Get Client (Outbound) connection by name.
|
|
@@ -59,7 +59,7 @@ declare module 'fastify' {
|
|
|
59
59
|
}
|
|
60
60
|
interface FastifyInstance {
|
|
61
61
|
/** Main Decorator for Fastify
|
|
62
|
-
|
|
62
|
+
* @remarks hl7 is the decorator that everything hangs off.
|
|
63
63
|
* @since 1.0.0 **/
|
|
64
64
|
hl7: HL7;
|
|
65
65
|
}
|
package/lib/esm/validation.d.ts
CHANGED
package/lib/esm/validation.js
CHANGED
package/lib/types/api.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HL7 } from
|
|
2
|
-
import fastifyHL7 from
|
|
3
|
-
import { AServers, FastifyHL7Options } from
|
|
4
|
-
import { HL7Client } from
|
|
5
|
-
import { HL7Server } from
|
|
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
6
|
export default fastifyHL7;
|
|
7
7
|
export { fastifyHL7, HL7, FastifyHL7Options, HL7Client, HL7Server, AServers };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, FileBatch, Connection, Message, OutboundHandler } from
|
|
1
|
+
import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, FileBatch, Connection, Message, OutboundHandler } from "node-hl7-client";
|
|
2
2
|
export declare class HL7Client {
|
|
3
3
|
/** @internal */
|
|
4
4
|
private readonly _clientConnections;
|
|
@@ -10,14 +10,14 @@ export declare class HL7Client {
|
|
|
10
10
|
closeAll(): Promise<boolean>;
|
|
11
11
|
/**
|
|
12
12
|
* Build a HL7 Batch
|
|
13
|
-
|
|
13
|
+
* @remarks Create a properly formatted HL7 Batch.
|
|
14
14
|
* @since 1.0.0
|
|
15
15
|
* @param props
|
|
16
16
|
*/
|
|
17
17
|
buildBatch(props?: ClientBuilderOptions): Batch;
|
|
18
18
|
/**
|
|
19
19
|
* Build Date
|
|
20
|
-
|
|
20
|
+
* @remarks Build a date string based off HL7 Standards
|
|
21
21
|
* @since 2.1.0
|
|
22
22
|
* @param date
|
|
23
23
|
* @param length Options are 8, 12, or 14 (default)
|
|
@@ -25,14 +25,14 @@ export declare class HL7Client {
|
|
|
25
25
|
buildDate(date: Date, length?: string): string;
|
|
26
26
|
/**
|
|
27
27
|
* Build a HL7 File Batch
|
|
28
|
-
|
|
28
|
+
* @remarks Create a properly formatted HL7 File Batch.
|
|
29
29
|
* @since 1.0.0
|
|
30
30
|
* @param props
|
|
31
31
|
*/
|
|
32
32
|
buildFileBatch(props?: ClientBuilderFileOptions): FileBatch;
|
|
33
33
|
/**
|
|
34
34
|
* Build a HL7 Message
|
|
35
|
-
|
|
35
|
+
* @remarks Create a properly formatted HL7 message.
|
|
36
36
|
* @since 1.0.0
|
|
37
37
|
* @param props
|
|
38
38
|
*/
|
|
@@ -45,7 +45,7 @@ export declare class HL7Client {
|
|
|
45
45
|
createClient(name: string, props: ClientOptions): Client;
|
|
46
46
|
/**
|
|
47
47
|
* Create an HL7 Outbound Connection
|
|
48
|
-
|
|
48
|
+
* @remarks Connect to an HL7 Server/Broker
|
|
49
49
|
* @since 1.0.0
|
|
50
50
|
* @param name The name stored within created client connections.
|
|
51
51
|
* @param props
|
|
@@ -66,14 +66,14 @@ export declare class HL7Client {
|
|
|
66
66
|
getClientConnectionByPort(port: string): Connection | undefined;
|
|
67
67
|
/**
|
|
68
68
|
* Process a HL7
|
|
69
|
-
|
|
69
|
+
* @remarks A HL7 message that could either be a Message (MSH) or Batch (BHS)
|
|
70
70
|
* @since 1.0.0
|
|
71
71
|
* @param text Raw HL& String
|
|
72
72
|
*/
|
|
73
73
|
processHL7(text: string): Message | Batch;
|
|
74
74
|
/**
|
|
75
75
|
* Read File
|
|
76
|
-
|
|
76
|
+
* @remarks Pass the correct path of the file you want to read.
|
|
77
77
|
* @since 1.0.0
|
|
78
78
|
* @param fullFilePath
|
|
79
79
|
* @returns FileBatch
|
|
@@ -85,7 +85,7 @@ export declare class HL7Client {
|
|
|
85
85
|
readFile(fullFilePath: string): FileBatch;
|
|
86
86
|
/**
|
|
87
87
|
* Read a File Buffer
|
|
88
|
-
|
|
88
|
+
* @remarks Translate an already Buffered HL7 FHS segment to decode it.
|
|
89
89
|
* @since 1.0.0
|
|
90
90
|
* @param fileBuffer
|
|
91
91
|
* @returns FileBatch
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import Server, { Inbound, InboundHandler, ListenerOptions } from "node-hl7-server";
|
|
3
|
+
export declare class HL7Server extends EventEmitter {
|
|
3
4
|
private readonly _server;
|
|
4
5
|
private readonly _serverInboundConnections;
|
|
5
6
|
constructor(server: Server);
|
package/lib/types/decorate.d.ts
CHANGED
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FastifyHL7Options } from
|
|
2
|
-
export * from
|
|
1
|
+
import { FastifyHL7Options } from "./decorate.js";
|
|
2
|
+
export * from "./types.js";
|
|
3
3
|
declare const fastifyHL7: import("fastify").FastifyPluginCallback<FastifyHL7Options, import("fastify").RawServerDefault, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
|
|
4
4
|
export default fastifyHL7;
|
|
5
5
|
export { FastifyHL7Options };
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Server, { Inbound, InboundHandler, ListenerOptions } from
|
|
2
|
-
import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, Connection, FileBatch, Message, OutboundHandler } from
|
|
3
|
-
declare module
|
|
1
|
+
import Server, { Inbound, InboundHandler, ListenerOptions } from "node-hl7-server";
|
|
2
|
+
import Client, { Batch, ClientBuilderFileOptions, ClientBuilderMessageOptions, ClientBuilderOptions, ClientListenerOptions, ClientOptions, Connection, FileBatch, Message, OutboundHandler } from "node-hl7-client";
|
|
3
|
+
declare module "fastify" {
|
|
4
4
|
interface HL7 {
|
|
5
5
|
/** Server Instance
|
|
6
6
|
* @since 1.0.0 **/
|
|
@@ -25,14 +25,14 @@ declare module 'fastify' {
|
|
|
25
25
|
* @since 1.0.0 */
|
|
26
26
|
closeServerAll: () => Promise<boolean>;
|
|
27
27
|
/** Create Client
|
|
28
|
-
|
|
28
|
+
* @remarks Connecting to a remote server/broker that accepts connections.
|
|
29
29
|
* @since 1.0.0 */
|
|
30
30
|
createClient: (name: string, props: ClientOptions) => Client;
|
|
31
31
|
/** Create an incoming port connection on the server.
|
|
32
32
|
* @since 1.0.0 */
|
|
33
33
|
createInbound: (name: string, props: ListenerOptions, handler: InboundHandler) => Inbound;
|
|
34
34
|
/** Create Outgoing Client Port
|
|
35
|
-
|
|
35
|
+
* @remarks This is on the established client that we are already a part off.
|
|
36
36
|
* @since 1.0.0 */
|
|
37
37
|
createConnection: (name: string, props: ClientListenerOptions, handler: OutboundHandler) => Connection;
|
|
38
38
|
/** Get Client (Outbound) connection by name.
|
|
@@ -59,7 +59,7 @@ declare module 'fastify' {
|
|
|
59
59
|
}
|
|
60
60
|
interface FastifyInstance {
|
|
61
61
|
/** Main Decorator for Fastify
|
|
62
|
-
|
|
62
|
+
* @remarks hl7 is the decorator that everything hangs off.
|
|
63
63
|
* @since 1.0.0 **/
|
|
64
64
|
hl7: HL7;
|
|
65
65
|
}
|