@syncbridge/hl7 0.4.18 → 0.4.20

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