@syncbridge/hl7 0.4.16 → 0.4.18
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.
|
@@ -15,6 +15,8 @@ export declare class HL7ClientComponent<TEvents extends HL7ClientComponent.Event
|
|
|
15
15
|
transmitLogger?: TransmitLogger;
|
|
16
16
|
values: HL7ClientVariables;
|
|
17
17
|
protected _init(): Promise<void>;
|
|
18
|
+
protected _configureClient(): Promise<void>;
|
|
19
|
+
protected _configureTransmitLogger(): void;
|
|
18
20
|
protected _start(abortSignal: AbortSignal): Promise<void>;
|
|
19
21
|
protected _stop(): Promise<void>;
|
|
20
22
|
use(handler: HL7Middleware, priority?: number): void;
|
|
@@ -16,99 +16,121 @@ let HL7ClientComponent = class HL7ClientComponent extends ComponentBase {
|
|
|
16
16
|
await super._init();
|
|
17
17
|
this.values.reconnect = this.values.reconnect || {};
|
|
18
18
|
try {
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
host: this.values.host,
|
|
22
|
-
port: this.values.port,
|
|
23
|
-
connectTimeout: this.values.connectTimeout,
|
|
24
|
-
responseTimeout: this.values.responseTimeout,
|
|
25
|
-
keepAlive: this.values.keepAlive,
|
|
26
|
-
reconnect: this.values.reconnect,
|
|
27
|
-
...this.values.tls,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
this.client = Hl7Client.createClient({
|
|
32
|
-
host: this.values.host,
|
|
33
|
-
port: this.values.port,
|
|
34
|
-
connectTimeout: this.values.connectTimeout,
|
|
35
|
-
responseTimeout: this.values.responseTimeout,
|
|
36
|
-
keepAlive: this.values.keepAlive,
|
|
37
|
-
reconnect: {
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
strategy: 'exponential',
|
|
40
|
-
...this.values.reconnect,
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
this.client.on('connect', () => {
|
|
45
|
-
this._address = { ...this.client.address() };
|
|
46
|
-
this._address.toString = function () {
|
|
47
|
-
return `${this.address}:${this.port}`;
|
|
48
|
-
}.bind(this._address);
|
|
49
|
-
if (this.transmitLogger)
|
|
50
|
-
this.transmitLogger.info('Connected', `${this._address}`);
|
|
51
|
-
this.logger?.trace(`Connected to ${this._address}`);
|
|
52
|
-
this.emit('connect', this._address);
|
|
19
|
+
this.on('data', (data, info) => {
|
|
20
|
+
this.transmitLogger?.received(data, info);
|
|
53
21
|
});
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
if (this.transmitLogger)
|
|
57
|
-
this.transmitLogger.info('Disconnected', this._address);
|
|
58
|
-
this.logger?.trace(`Disconnected from ${this._address}`);
|
|
59
|
-
this.emit('close', this._address);
|
|
22
|
+
this.on('transmit', (data, info) => {
|
|
23
|
+
this.transmitLogger?.transmitted(data, info);
|
|
60
24
|
});
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.logger?.error(error);
|
|
66
|
-
this.emit('error', error, this._address);
|
|
25
|
+
this.on('values-updated', async (keys) => {
|
|
26
|
+
console.log('values-updated', keys);
|
|
27
|
+
await this._configureClient();
|
|
28
|
+
this._configureTransmitLogger();
|
|
67
29
|
});
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
this.emit('message', message, this._address);
|
|
71
|
-
});
|
|
72
|
-
this.client.on('send', message => {
|
|
73
|
-
this.logger?.trace(`HL7 message (${message.messageType}) sent to ${this.client.uri}`);
|
|
74
|
-
this.emit('send', message, this._address);
|
|
75
|
-
});
|
|
76
|
-
this.client.on('data', data => {
|
|
77
|
-
this.emit('data', data, this._address);
|
|
78
|
-
});
|
|
79
|
-
const { communicationLogs } = this.values;
|
|
80
|
-
const { dataDirectory } = this.processor;
|
|
81
|
-
if (communicationLogs) {
|
|
82
|
-
const transmitLogger = (this.transmitLogger = new TransmitLogger({
|
|
83
|
-
...communicationLogs,
|
|
84
|
-
logDirectory: dataDirectory
|
|
85
|
-
? path.join(dataDirectory, 'comm-logs')
|
|
86
|
-
: undefined,
|
|
87
|
-
name: this.path.replace(/\//g, '-'),
|
|
88
|
-
maxFiles: communicationLogs?.maxFiles,
|
|
89
|
-
maxFileSize: communicationLogs?.maxFileSize,
|
|
90
|
-
}));
|
|
91
|
-
this.on('data', (data, info) => {
|
|
92
|
-
transmitLogger.received(data, info);
|
|
93
|
-
});
|
|
94
|
-
this.on('transmit', (data, info) => {
|
|
95
|
-
transmitLogger.transmitted(data, info);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
30
|
+
await this._configureClient();
|
|
31
|
+
this._configureTransmitLogger();
|
|
98
32
|
}
|
|
99
33
|
catch (err) {
|
|
100
34
|
this.logger?.error(err);
|
|
101
35
|
this.setStatus(ServiceStatus.unhealthy, err.message);
|
|
102
36
|
}
|
|
103
37
|
}
|
|
38
|
+
async _configureClient() {
|
|
39
|
+
const isStopped = this.stopped;
|
|
40
|
+
if (!isStopped)
|
|
41
|
+
await this._stop();
|
|
42
|
+
if (this.client)
|
|
43
|
+
await this.client.close();
|
|
44
|
+
if (this.values.tls) {
|
|
45
|
+
this.client = Hl7Client.createTlsClient({
|
|
46
|
+
host: this.values.host,
|
|
47
|
+
port: this.values.port,
|
|
48
|
+
connectTimeout: this.values.connectTimeout,
|
|
49
|
+
responseTimeout: this.values.responseTimeout,
|
|
50
|
+
keepAlive: this.values.keepAlive,
|
|
51
|
+
reconnect: this.values.reconnect,
|
|
52
|
+
...this.values.tls,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.client = Hl7Client.createClient({
|
|
57
|
+
host: this.values.host,
|
|
58
|
+
port: this.values.port,
|
|
59
|
+
connectTimeout: this.values.connectTimeout,
|
|
60
|
+
responseTimeout: this.values.responseTimeout,
|
|
61
|
+
keepAlive: this.values.keepAlive,
|
|
62
|
+
reconnect: {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
strategy: 'exponential',
|
|
65
|
+
...this.values.reconnect,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
this.client.on('connect', () => {
|
|
70
|
+
this._address = { ...this.client.address() };
|
|
71
|
+
this._address.toString = function () {
|
|
72
|
+
return `${this.address}:${this.port}`;
|
|
73
|
+
}.bind(this._address);
|
|
74
|
+
if (this.transmitLogger)
|
|
75
|
+
this.transmitLogger.info('Connected', `${this._address}`);
|
|
76
|
+
this.logger?.trace(`Connected to ${this._address}`);
|
|
77
|
+
this.emit('connect', this._address);
|
|
78
|
+
});
|
|
79
|
+
this.client.on('ready', () => this.emit('ready', this._address));
|
|
80
|
+
this.client.on('close', () => {
|
|
81
|
+
if (this.transmitLogger)
|
|
82
|
+
this.transmitLogger.info('Disconnected', this._address);
|
|
83
|
+
this.logger?.trace(`Disconnected from ${this._address}`);
|
|
84
|
+
this.emit('close', this._address);
|
|
85
|
+
});
|
|
86
|
+
this.client.on('error', error => {
|
|
87
|
+
error = error instanceof AggregateError ? error.errors[0] : error;
|
|
88
|
+
if (error.code === 'ECONNREFUSED')
|
|
89
|
+
error.message = `Connection refused to ${error.address}:${error.port}`;
|
|
90
|
+
this.logger?.error(error);
|
|
91
|
+
this.emit('error', error, this._address);
|
|
92
|
+
});
|
|
93
|
+
this.client.on('message', message => {
|
|
94
|
+
this.logger?.trace(`HL7 message (${message.messageType}) received from ${this.client.uri}`);
|
|
95
|
+
this.emit('message', message, this._address);
|
|
96
|
+
});
|
|
97
|
+
this.client.on('send', message => {
|
|
98
|
+
this.logger?.trace(`HL7 message (${message.messageType}) sent to ${this.client.uri}`);
|
|
99
|
+
this.emit('send', message, this._address);
|
|
100
|
+
});
|
|
101
|
+
this.client.on('data', data => {
|
|
102
|
+
this.emit('data', data, this._address);
|
|
103
|
+
});
|
|
104
|
+
if (!isStopped)
|
|
105
|
+
await this._start(new AbortSignal());
|
|
106
|
+
}
|
|
107
|
+
_configureTransmitLogger() {
|
|
108
|
+
const { communicationLogs } = this.values;
|
|
109
|
+
const { dataDirectory } = this.processor;
|
|
110
|
+
if (this.transmitLogger)
|
|
111
|
+
this.transmitLogger.close();
|
|
112
|
+
if (communicationLogs) {
|
|
113
|
+
this.transmitLogger = new TransmitLogger({
|
|
114
|
+
...communicationLogs,
|
|
115
|
+
logDirectory: dataDirectory
|
|
116
|
+
? path.join(dataDirectory, 'comm-logs')
|
|
117
|
+
: undefined,
|
|
118
|
+
name: this.path.replace(/\//g, '-'),
|
|
119
|
+
maxFiles: communicationLogs?.maxFiles,
|
|
120
|
+
maxFileSize: communicationLogs?.maxFileSize,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
104
124
|
async _start(abortSignal) {
|
|
125
|
+
await super._start(abortSignal);
|
|
105
126
|
this._stopping = false;
|
|
106
127
|
this.client.connect().catch(noOp);
|
|
107
|
-
|
|
128
|
+
if (!this.client.connected)
|
|
129
|
+
this.setStatus(ServiceStatus.unhealthy);
|
|
108
130
|
}
|
|
109
131
|
async _stop() {
|
|
110
132
|
this._stopping = true;
|
|
111
|
-
await this.client
|
|
133
|
+
await this.client?.close(30000);
|
|
112
134
|
return super._stop();
|
|
113
135
|
}
|
|
114
136
|
use(handler, priority) {
|
|
@@ -114,7 +114,7 @@ let HL7ServerComponent = class HL7ServerComponent extends ComponentBase {
|
|
|
114
114
|
async _start(abortSignal) {
|
|
115
115
|
this._stopping = false;
|
|
116
116
|
await this.server.listen(this.values.port);
|
|
117
|
-
super._start(abortSignal);
|
|
117
|
+
await super._start(abortSignal);
|
|
118
118
|
}
|
|
119
119
|
async _stop() {
|
|
120
120
|
this._stopping = true;
|
package/constants.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncbridge/hl7",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"description": "SyncBridge HL7 connection components",
|
|
5
5
|
"author": "Panates Inc",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"node-events-async": "^1.5.0"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@syncbridge/common": "^0.5.
|
|
16
|
-
"@syncbridge/builtins": "^0.4.
|
|
17
|
-
"@syncbridge/net": "^0.4.
|
|
15
|
+
"@syncbridge/common": "^0.5.12",
|
|
16
|
+
"@syncbridge/builtins": "^0.4.18",
|
|
17
|
+
"@syncbridge/net": "^0.4.18"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|