hl7v2 1.2.1 → 1.2.3

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.
@@ -99,7 +99,7 @@ class Hl7Component {
99
99
  let segmentIndex = this.segment.index;
100
100
  if (segmentIndex < 0)
101
101
  segmentIndex = this.message.segments.length;
102
- throw new hl7_error_js_1.HL7Error(`The field (${location}) contained data of the wrong data type. ${e.message}.`, {
102
+ const err = new hl7_error_js_1.HL7Error(`The field (${location}) contained data of the wrong data type. ${e.message}.`, {
103
103
  segmentType: this.segment.segmentType,
104
104
  segmentSequence: segmentIndex,
105
105
  fieldPosition: this.field.position,
@@ -107,6 +107,8 @@ class Hl7Component {
107
107
  repetitionIndex: this.repetition.index,
108
108
  hl7ErrorCode: 102,
109
109
  });
110
+ err.stack = e.stack;
111
+ throw err;
110
112
  }
111
113
  return;
112
114
  }
@@ -289,7 +289,14 @@ class HL7Message {
289
289
  /* Detect version and charset */
290
290
  const headerItems = headerStr.split(fieldSeparator);
291
291
  const version = headerItems[11];
292
- const encoding = headerItems[17]?.split('^')[0] || 'UTF-8';
292
+ const charset = headerItems[17]?.split('^')[0];
293
+ let encoding = HL7Message.encodingMapping[charset] || charset || 'utf-8';
294
+ try {
295
+ iconv_lite_1.default.getDecoder(charset);
296
+ }
297
+ catch {
298
+ encoding = 'utf-8';
299
+ }
293
300
  let str = Buffer.isBuffer(input) ? iconv_lite_1.default.decode(input, encoding) : input;
294
301
  if (str.startsWith(constants_js_1.VT))
295
302
  str = str.substring(1);
@@ -311,3 +318,28 @@ class HL7Message {
311
318
  }
312
319
  }
313
320
  exports.HL7Message = HL7Message;
321
+ HL7Message.encodingMapping = {
322
+ ASCII: 'ascii',
323
+ '8859/1': 'latin1',
324
+ '8859/2': 'latin2',
325
+ '8859/3': 'ISO-8859-3',
326
+ '8859/4': 'ISO-8859-4',
327
+ '8859/5': 'ISO-8859-5',
328
+ '8859/6': 'ISO-8859-6',
329
+ '8859/7': 'ISO-8859-7',
330
+ '8859/8': 'ISO-8859-8',
331
+ '8859/9': 'latin5',
332
+ '8859/15': 'latin9',
333
+ 'ISO IR6': 'ascii',
334
+ 'ISO IR14': 'ISO-2022-JP',
335
+ 'ISO IR87': 'ISO-2022-JP',
336
+ 'ISO IR159': 'ISO-2022-JP-2',
337
+ 'GB 18030-2000': 'gb18030',
338
+ 'KS X 1001': 'EUC-KR',
339
+ 'CNS 11643-1992': 'EUC-TW',
340
+ 'BIG-5': 'Big5',
341
+ UNICODE: 'utf16-le',
342
+ 'UNICODE UTF-8': 'utf8',
343
+ 'UNICODE UTF-16': 'utf16-le',
344
+ // ⚠️ UTF-32 iconv-lite tarafından desteklenmez
345
+ };
@@ -5,7 +5,6 @@ const hl7v2_dictionary_1 = require("hl7v2-dictionary");
5
5
  const hl7_error_js_1 = require("./hl7-error.js");
6
6
  const hl7_escape_js_1 = require("./utils/hl7-escape.js");
7
7
  class Hl7SubComponent {
8
- // protected _raw?: any;
9
8
  constructor(component, position, def) {
10
9
  this.component = component;
11
10
  this.position = position;
@@ -96,7 +96,7 @@ export class Hl7Component {
96
96
  let segmentIndex = this.segment.index;
97
97
  if (segmentIndex < 0)
98
98
  segmentIndex = this.message.segments.length;
99
- throw new HL7Error(`The field (${location}) contained data of the wrong data type. ${e.message}.`, {
99
+ const err = new HL7Error(`The field (${location}) contained data of the wrong data type. ${e.message}.`, {
100
100
  segmentType: this.segment.segmentType,
101
101
  segmentSequence: segmentIndex,
102
102
  fieldPosition: this.field.position,
@@ -104,6 +104,8 @@ export class Hl7Component {
104
104
  repetitionIndex: this.repetition.index,
105
105
  hl7ErrorCode: 102,
106
106
  });
107
+ err.stack = e.stack;
108
+ throw err;
107
109
  }
108
110
  return;
109
111
  }
@@ -285,7 +285,14 @@ export class HL7Message {
285
285
  /* Detect version and charset */
286
286
  const headerItems = headerStr.split(fieldSeparator);
287
287
  const version = headerItems[11];
288
- const encoding = headerItems[17]?.split('^')[0] || 'UTF-8';
288
+ const charset = headerItems[17]?.split('^')[0];
289
+ let encoding = HL7Message.encodingMapping[charset] || charset || 'utf-8';
290
+ try {
291
+ iconv.getDecoder(charset);
292
+ }
293
+ catch {
294
+ encoding = 'utf-8';
295
+ }
289
296
  let str = Buffer.isBuffer(input) ? iconv.decode(input, encoding) : input;
290
297
  if (str.startsWith(VT))
291
298
  str = str.substring(1);
@@ -306,3 +313,28 @@ export class HL7Message {
306
313
  };
307
314
  }
308
315
  }
316
+ HL7Message.encodingMapping = {
317
+ ASCII: 'ascii',
318
+ '8859/1': 'latin1',
319
+ '8859/2': 'latin2',
320
+ '8859/3': 'ISO-8859-3',
321
+ '8859/4': 'ISO-8859-4',
322
+ '8859/5': 'ISO-8859-5',
323
+ '8859/6': 'ISO-8859-6',
324
+ '8859/7': 'ISO-8859-7',
325
+ '8859/8': 'ISO-8859-8',
326
+ '8859/9': 'latin5',
327
+ '8859/15': 'latin9',
328
+ 'ISO IR6': 'ascii',
329
+ 'ISO IR14': 'ISO-2022-JP',
330
+ 'ISO IR87': 'ISO-2022-JP',
331
+ 'ISO IR159': 'ISO-2022-JP-2',
332
+ 'GB 18030-2000': 'gb18030',
333
+ 'KS X 1001': 'EUC-KR',
334
+ 'CNS 11643-1992': 'EUC-TW',
335
+ 'BIG-5': 'Big5',
336
+ UNICODE: 'utf16-le',
337
+ 'UNICODE UTF-8': 'utf8',
338
+ 'UNICODE UTF-16': 'utf16-le',
339
+ // ⚠️ UTF-32 iconv-lite tarafından desteklenmez
340
+ };
@@ -2,7 +2,6 @@ import { toHL7DateTime, } from 'hl7v2-dictionary';
2
2
  import { HL7Error } from './hl7-error.js';
3
3
  import { hl7Escape, hl7UnEscape } from './utils/hl7-escape.js';
4
4
  export class Hl7SubComponent {
5
- // protected _raw?: any;
6
5
  constructor(component, position, def) {
7
6
  this.component = component;
8
7
  this.position = position;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hl7v2",
3
3
  "description": "HL7 v2 parser, serializer, validator for NodeJS",
4
- "version": "1.2.1",
4
+ "version": "1.2.3",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -15,7 +15,7 @@
15
15
  "uid": "^2.0.2"
16
16
  },
17
17
  "peerDependencies": {
18
- "hl7v2-dictionary": "^1.2.1"
18
+ "hl7v2-dictionary": "^1.2.3"
19
19
  },
20
20
  "type": "module",
21
21
  "exports": {
@@ -54,6 +54,30 @@ export declare class HL7Message {
54
54
  messageType: string;
55
55
  data: string;
56
56
  };
57
+ static readonly encodingMapping: {
58
+ ASCII: string;
59
+ '8859/1': string;
60
+ '8859/2': string;
61
+ '8859/3': string;
62
+ '8859/4': string;
63
+ '8859/5': string;
64
+ '8859/6': string;
65
+ '8859/7': string;
66
+ '8859/8': string;
67
+ '8859/9': string;
68
+ '8859/15': string;
69
+ 'ISO IR6': string;
70
+ 'ISO IR14': string;
71
+ 'ISO IR87': string;
72
+ 'ISO IR159': string;
73
+ 'GB 18030-2000': string;
74
+ 'KS X 1001': string;
75
+ 'CNS 11643-1992': string;
76
+ 'BIG-5': string;
77
+ UNICODE: string;
78
+ 'UNICODE UTF-8': string;
79
+ 'UNICODE UTF-16': string;
80
+ };
57
81
  }
58
82
  export interface HL7MessageSerializeOptions extends Hl7SegmentSerializeOptions {
59
83
  }