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