hl7v2-net 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.
package/cjs/hl7-socket.js CHANGED
@@ -87,10 +87,17 @@ class HL7Socket extends node_events_async_1.AsyncEventEmitter {
87
87
  throw new Error('Socket is not connected');
88
88
  if (!this.socket.writable)
89
89
  throw new Error('Socket is not writable');
90
- let encoding = message.header.field(hl7v2_1.MSHSegment.CharacterSet).getValue();
91
- if (!encoding) {
92
- encoding = 'UTF-8';
93
- message.header.field(hl7v2_1.MSHSegment.CharacterSet).setValue(encoding);
90
+ let charset = message.header.field(hl7v2_1.MSHSegment.CharacterSet).getValue();
91
+ if (!charset) {
92
+ charset = 'UNICODE UTF-8';
93
+ message.header.field(hl7v2_1.MSHSegment.CharacterSet).setValue(charset);
94
+ }
95
+ let encoding = hl7v2_1.HL7Message.encodingMapping[charset] || charset || 'utf-8';
96
+ try {
97
+ iconv_lite_1.default.getEncoder(charset);
98
+ }
99
+ catch {
100
+ encoding = 'utf-8';
94
101
  }
95
102
  const str = message.toHL7String();
96
103
  const buf = iconv_lite_1.default.encode(str, encoding);
package/esm/hl7-socket.js CHANGED
@@ -83,10 +83,17 @@ export class HL7Socket extends AsyncEventEmitter {
83
83
  throw new Error('Socket is not connected');
84
84
  if (!this.socket.writable)
85
85
  throw new Error('Socket is not writable');
86
- let encoding = message.header.field(MSHSegment.CharacterSet).getValue();
87
- if (!encoding) {
88
- encoding = 'UTF-8';
89
- message.header.field(MSHSegment.CharacterSet).setValue(encoding);
86
+ let charset = message.header.field(MSHSegment.CharacterSet).getValue();
87
+ if (!charset) {
88
+ charset = 'UNICODE UTF-8';
89
+ message.header.field(MSHSegment.CharacterSet).setValue(charset);
90
+ }
91
+ let encoding = HL7Message.encodingMapping[charset] || charset || 'utf-8';
92
+ try {
93
+ iconv.getEncoder(charset);
94
+ }
95
+ catch {
96
+ encoding = 'utf-8';
90
97
  }
91
98
  const str = message.toHL7String();
92
99
  const buf = iconv.encode(str, encoding);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hl7v2-net",
3
3
  "description": "HL7 v2 server/client for NodeJS",
4
- "version": "1.2.2",
4
+ "version": "1.2.3",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
@@ -15,8 +15,8 @@
15
15
  "uid": "^2.0.2"
16
16
  },
17
17
  "peerDependencies": {
18
- "hl7v2": "^1.2.2",
19
- "hl7v2-dictionary": "^1.2.2"
18
+ "hl7v2": "^1.2.3",
19
+ "hl7v2-dictionary": "^1.2.3"
20
20
  },
21
21
  "type": "module",
22
22
  "exports": {