hl7v2 0.9.0 → 0.11.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/HL7Message.js CHANGED
@@ -94,7 +94,7 @@ class HL7Message {
94
94
 
95
95
  /**
96
96
  *
97
- * @param {Buffer|Uint8Array|string} buf
97
+ * @param {Buffer|string} buf
98
98
  * @param {Object} [options]
99
99
  * @param {string} [options.encoding='utf8']
100
100
  * @private
@@ -102,7 +102,7 @@ class HL7Message {
102
102
  parse(buf, options) {
103
103
  this._segments = [];
104
104
  let str;
105
- if (buf instanceof Uint8Array) {
105
+ if (buf instanceof Buffer) {
106
106
  let encoding = (options && options.encoding) || 'utf8';
107
107
  /* Character set detection */
108
108
  const sep = FIELD_SEPARATOR.charCodeAt(0);
@@ -121,8 +121,11 @@ class HL7Message {
121
121
  }
122
122
  } while (l > 0 && l < crIdx);
123
123
  str = iconv.decode(buf, encoding.replace(/^UNICODE/, ''));
124
- } else
125
- str = String(buf);
124
+ } else if (typeof buf === 'string') {
125
+ str = buf;
126
+ } else {
127
+ throw new ArgumentError('You must provide string or Buffer argument');
128
+ }
126
129
 
127
130
  if (str.startsWith(VT))
128
131
  str = str.substring(1);
@@ -137,7 +140,7 @@ class HL7Message {
137
140
  if (!str.startsWith('MSH'))
138
141
  throw new ParseError('Message must start with (MSH) segment');
139
142
 
140
- const lines = str.split(/\r|\r\n|\n/);
143
+ const lines = str.split(CR);
141
144
  for (const [i, line] of lines.entries()) {
142
145
  if (!line)
143
146
  continue;
@@ -147,7 +147,7 @@ class HL7Client extends EventEmitter {
147
147
  this._buffer.on('block', data => this._onHL7Data(data));
148
148
 
149
149
  this._socket = socket = socket ||
150
- (opts.cert ? tls.connect(opts) : net.connect(opts));
150
+ (opts.protocol === 'mllps' || opts.cert ? tls.connect(opts) : net.connect(opts));
151
151
 
152
152
  socket.removeListener('connect', this._connectionListener);
153
153
  socket.removeListener('secureConnect', this._connectionListener);
@@ -228,7 +228,7 @@ class HL7Client extends EventEmitter {
228
228
  msg.MSH.MessageControlId.value = ++this._controlIdSeq;
229
229
 
230
230
  const str = msg.toHL7();
231
- let charset = 'utf8';
231
+ let charset = this.encoding || 'utf8';
232
232
  if (msg.MSH[18]) {
233
233
  if (this.encoding && !msg.MSH[18].value)
234
234
  msg.MSH[18].value = this.encoding;
@@ -44,6 +44,8 @@ class HL7MessageRouter extends Callable {
44
44
  * @private
45
45
  */
46
46
  __call__(req, ...args) {
47
+ if (!req)
48
+ throw new Error('Request was undefined');
47
49
  return waterfall.some([...this._handlers,
48
50
  this._defaultHandler], (next, o) => {
49
51
  if (!o.handler)
@@ -22,7 +22,7 @@ class HL7Server extends EventEmitter {
22
22
  * @param {Object} [param2]
23
23
  * @param {string} [param2.applicationName]
24
24
  * @param {string} [param2.facilityName]
25
- * @param {string} [param2.defaultEncoding]
25
+ * @param {string} [param2.encoding]
26
26
  * @param {string} [param2.defaultVersion]
27
27
  * @param {number} [param2.maxBufferPerSocket]
28
28
  * @param {string} [param2.cert]
@@ -220,14 +220,14 @@ class HL7Server extends EventEmitter {
220
220
  /**
221
221
  *
222
222
  * @param {net.Socket} socket
223
- * @param {string} block
223
+ * @param {Buffer} block
224
224
  * @private
225
225
  */
226
226
  _onHl7Block(socket, block) {
227
227
  let msg;
228
228
  // Parse message
229
229
  try {
230
- msg = HL7Message.parse(block, {encoding: this.defaultEncoding});
230
+ msg = HL7Message.parse(block, {encoding: this.encoding});
231
231
  socket._errorCount = 0;
232
232
  } catch (e) {
233
233
  const ack = this._createACK(msg, 'AR',
@@ -254,6 +254,7 @@ class HL7Server extends EventEmitter {
254
254
  socket.remoteAddress + '. ' + e.message;
255
255
  e.socket = socket;
256
256
  this.emitSafe('error', e);
257
+ return;
257
258
  }
258
259
  socket._messageQueue.add(msg);
259
260
  this._router(msg, socket)
@@ -294,7 +295,7 @@ class HL7Server extends EventEmitter {
294
295
  throw new ArgumentError('You must provide HL7Message or string argument');
295
296
 
296
297
  const str = msg.toHL7();
297
- let charset = 'utf8';
298
+ let charset = this.encoding || 'utf8';
298
299
  /* istanbul ignore next: same in client */
299
300
  if (msg.MSH[18]) {
300
301
  if (this.encoding && !msg.MSH[18].value)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hl7v2",
3
3
  "description": "HL7 v2 parser, serializer, validator and tcp client/server for NodeJS",
4
- "version": "0.9.0",
4
+ "version": "0.11.0",
5
5
  "author": "Panates Ltd.",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -28,9 +28,9 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "babel-eslint": "^10.1.0",
31
- "eslint": "^7.14.0",
31
+ "eslint": "^8.1.0",
32
32
  "eslint-config-google": "^0.14.0",
33
- "mocha": "^8.2.1",
33
+ "mocha": "^9.1.3",
34
34
  "nyc": "^15.1.0",
35
35
  "rejected-or-not": "^2.0.0"
36
36
  },