hl7v2 1.2.2 → 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.
@@ -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
+ };
@@ -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
+ };
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.2",
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.2"
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
  }