hl7v2 1.6.0 → 1.7.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.
Files changed (37) hide show
  1. package/{esm/hl7-message.js → hl7-message.js} +1 -1
  2. package/package.json +10 -26
  3. package/cjs/constants.js +0 -12
  4. package/cjs/hl7-component.js +0 -178
  5. package/cjs/hl7-error.js +0 -37
  6. package/cjs/hl7-field.js +0 -107
  7. package/cjs/hl7-message-node.js +0 -96
  8. package/cjs/hl7-message.js +0 -442
  9. package/cjs/hl7-repetition.js +0 -97
  10. package/cjs/hl7-segment.js +0 -81
  11. package/cjs/hl7-sub-component.js +0 -106
  12. package/cjs/index.js +0 -14
  13. package/cjs/package.json +0 -3
  14. package/cjs/utils/hl7-escape.js +0 -88
  15. package/esm/package.json +0 -3
  16. package/types/index.d.cts +0 -11
  17. /package/{types/constants.d.ts → constants.d.ts} +0 -0
  18. /package/{esm/constants.js → constants.js} +0 -0
  19. /package/{types/hl7-component.d.ts → hl7-component.d.ts} +0 -0
  20. /package/{esm/hl7-component.js → hl7-component.js} +0 -0
  21. /package/{types/hl7-error.d.ts → hl7-error.d.ts} +0 -0
  22. /package/{esm/hl7-error.js → hl7-error.js} +0 -0
  23. /package/{types/hl7-field.d.ts → hl7-field.d.ts} +0 -0
  24. /package/{esm/hl7-field.js → hl7-field.js} +0 -0
  25. /package/{types/hl7-message-node.d.ts → hl7-message-node.d.ts} +0 -0
  26. /package/{esm/hl7-message-node.js → hl7-message-node.js} +0 -0
  27. /package/{types/hl7-message.d.ts → hl7-message.d.ts} +0 -0
  28. /package/{types/hl7-repetition.d.ts → hl7-repetition.d.ts} +0 -0
  29. /package/{esm/hl7-repetition.js → hl7-repetition.js} +0 -0
  30. /package/{types/hl7-segment.d.ts → hl7-segment.d.ts} +0 -0
  31. /package/{esm/hl7-segment.js → hl7-segment.js} +0 -0
  32. /package/{types/hl7-sub-component.d.ts → hl7-sub-component.d.ts} +0 -0
  33. /package/{esm/hl7-sub-component.js → hl7-sub-component.js} +0 -0
  34. /package/{types/index.d.ts → index.d.ts} +0 -0
  35. /package/{esm/index.js → index.js} +0 -0
  36. /package/{types/utils → utils}/hl7-escape.d.ts +0 -0
  37. /package/{esm/utils → utils}/hl7-escape.js +0 -0
@@ -35,7 +35,7 @@ export class HL7Message {
35
35
  const f = this.header.field(MSHSegment.MessageType);
36
36
  if (!f)
37
37
  return '';
38
- return f.getValue(1) + '^' + f.getValue(2);
38
+ return f.getValue(1) + '^' + (f.getValue(2) || '');
39
39
  }
40
40
  get controlId() {
41
41
  return this.header.field(MSHSegment.MessageControlID).toHL7String();
package/package.json CHANGED
@@ -1,40 +1,35 @@
1
1
  {
2
2
  "name": "hl7v2",
3
3
  "description": "HL7 v2 parser, serializer, validator for NodeJS",
4
- "version": "1.6.0",
4
+ "version": "1.7.0",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@jsopen/objects": "^2.0.2",
9
9
  "iconv-lite": "^0.7.1",
10
10
  "is-typedarray": "^1.0.0",
11
- "node-events-async": "^1.2.0",
11
+ "node-events-async": "^1.5.0",
12
12
  "ts-gems": "^3.11.3",
13
13
  "tslib": "^2.8.1",
14
14
  "valgen": "^5.18.2",
15
15
  "uid": "^2.0.2"
16
16
  },
17
17
  "peerDependencies": {
18
- "hl7v2-dictionary": "^1.6.0"
18
+ "hl7v2-dictionary": "^1.7.0"
19
19
  },
20
20
  "type": "module",
21
+ "module": "./index.js",
22
+ "types": "./index.d.ts",
21
23
  "exports": {
22
24
  ".": {
23
- "import": {
24
- "types": "./types/index.d.ts",
25
- "default": "./esm/index.js"
26
- },
27
- "require": {
28
- "types": "./types/index.d.cts",
29
- "default": "./cjs/index.js"
30
- },
31
- "default": "./esm/index.js"
25
+ "types": "./index.d.ts",
26
+ "default": "./index.js"
32
27
  },
33
28
  "./package.json": "./package.json"
34
29
  },
35
- "main": "./cjs/index.js",
36
- "module": "./esm/index.js",
37
- "types": "./types/index.d.ts",
30
+ "engines": {
31
+ "node": ">=20.0"
32
+ },
38
33
  "contributors": [
39
34
  "Eray Hanoglu <e.hanoglu@panates.com>"
40
35
  ],
@@ -43,17 +38,6 @@
43
38
  "url": "https://github.com/panates/hl7v2.git",
44
39
  "directory": "packages/common"
45
40
  },
46
- "engines": {
47
- "node": ">=18.0"
48
- },
49
- "files": [
50
- "cjs/",
51
- "esm/",
52
- "types/",
53
- "LICENSE",
54
- "README.md",
55
- "CHANGELOG.md"
56
- ],
57
41
  "keywords": [
58
42
  "hl7",
59
43
  "perser",
package/cjs/constants.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FS = exports.VT = exports.LF = exports.CR = exports.SUBCOMPONENT_SEPARATOR = exports.ESCAPE_CHARACTER = exports.REPETITION_SEPARATOR = exports.COMPONENT_SEPARATOR = exports.FIELD_SEPARATOR = void 0;
4
- exports.FIELD_SEPARATOR = '|';
5
- exports.COMPONENT_SEPARATOR = '^';
6
- exports.REPETITION_SEPARATOR = '~';
7
- exports.ESCAPE_CHARACTER = '\\';
8
- exports.SUBCOMPONENT_SEPARATOR = '&';
9
- exports.CR = '\x0D';
10
- exports.LF = '\x0A';
11
- exports.VT = '\x0B';
12
- exports.FS = '\x1C';
@@ -1,178 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Hl7Component = void 0;
4
- const hl7v2_dictionary_1 = require("hl7v2-dictionary");
5
- const hl7_error_js_1 = require("./hl7-error.js");
6
- const hl7_sub_component_js_1 = require("./hl7-sub-component.js");
7
- const hl7_escape_js_1 = require("./utils/hl7-escape.js");
8
- class Hl7Component {
9
- repetition;
10
- position;
11
- constructor(repetition, position, def) {
12
- this.repetition = repetition;
13
- this.position = position;
14
- this._definition = def;
15
- this._typeDef = this.message.dictionary.types[this._definition.type];
16
- if (!this._typeDef)
17
- throw new Error(`Unknown data type: ${this._definition.type}`);
18
- if (this.isPrimitive) {
19
- this._data = new hl7_sub_component_js_1.Hl7SubComponent(this, 1, this.definition);
20
- }
21
- this.clear();
22
- }
23
- get message() {
24
- return this.field.message;
25
- }
26
- get segment() {
27
- return this.field.segment;
28
- }
29
- get field() {
30
- return this.repetition.field;
31
- }
32
- get definition() {
33
- return this._definition;
34
- }
35
- get typeDef() {
36
- return this._typeDef;
37
- }
38
- get isPrimitive() {
39
- return !this.typeDef.fields;
40
- }
41
- get subComponents() {
42
- return this._subComponents;
43
- }
44
- clear() {
45
- if (this.field.isPrimitive) {
46
- this._data.value = undefined;
47
- }
48
- else
49
- this._subComponents = [];
50
- }
51
- isEmpty() {
52
- if (this._data)
53
- return this._data.value == null;
54
- if (this._subComponents) {
55
- for (const sub of this._subComponents) {
56
- if (!sub.isEmpty())
57
- return false;
58
- }
59
- }
60
- return true;
61
- }
62
- subcomp(position) {
63
- if (this.field.isPrimitive)
64
- throw new Error('Primitive fields have no sub-component');
65
- if (position < 1)
66
- throw new Error('Invalid sub-component position');
67
- let subComponent = this._subComponents[position - 1];
68
- if (!subComponent) {
69
- let fDef = this.typeDef.fields?.[String(position)];
70
- if (!fDef) {
71
- if (position === 1)
72
- fDef = this.definition;
73
- else
74
- fDef = {
75
- type: 'ST',
76
- };
77
- }
78
- subComponent = new hl7_sub_component_js_1.Hl7SubComponent(this, position, fDef);
79
- this._subComponents[position - 1] = subComponent;
80
- }
81
- return subComponent;
82
- }
83
- getValue(subComponent) {
84
- if (this._data)
85
- return subComponent && subComponent > 1 ? undefined : this._data.value;
86
- return this._subComponents[(subComponent ?? 1) - 1]?.value;
87
- }
88
- setValue(value, subComponent) {
89
- if (subComponent || !this._data) {
90
- this.subcomp(subComponent || 1).value = value;
91
- return this;
92
- }
93
- this._data.value = value;
94
- return this;
95
- }
96
- fromHL7String(value, options) {
97
- if (value === '') {
98
- this.setValue(undefined);
99
- return;
100
- }
101
- if (this._data) {
102
- const decode = this.definition.decode || this.typeDef.decode;
103
- const unescaped = (0, hl7_escape_js_1.hl7UnEscape)(value, this.field.message);
104
- try {
105
- if (Buffer.isBuffer(unescaped) || unescaped == null)
106
- this._data._value = unescaped;
107
- else
108
- this._data._value = decode ? decode(unescaped) : unescaped;
109
- }
110
- catch (e) {
111
- if (!options?.strict) {
112
- this._data._value = unescaped;
113
- return;
114
- }
115
- const location = `${this.segment.segmentType}.${this.field.position}.${this.position}[${this.repetition.index}]`;
116
- let segmentIndex = this.segment.index;
117
- if (segmentIndex < 0)
118
- segmentIndex = this.message.segments.length;
119
- const err = new hl7_error_js_1.HL7Error(`The field (${location}) contained data of the wrong data type. ${e.message}.`, {
120
- segmentType: this.segment.segmentType,
121
- segmentSequence: segmentIndex,
122
- fieldPosition: this.field.position,
123
- componentPosition: this.position,
124
- repetitionIndex: this.repetition.index,
125
- hl7ErrorCode: 102,
126
- });
127
- err.stack = e.stack;
128
- throw err;
129
- }
130
- return;
131
- }
132
- else {
133
- this._subComponents = [];
134
- const subComponents = value.split(this.field.message.subComponentSeparator);
135
- let pos = 1;
136
- for (const subComponent of subComponents) {
137
- this.subcomp(pos++).fromHL7String(subComponent, options);
138
- }
139
- }
140
- }
141
- toHL7String(options) {
142
- let str;
143
- if (this._data) {
144
- let v = this._data.value;
145
- if (v === null)
146
- return '""';
147
- if (v === undefined)
148
- return '';
149
- const encode = this.definition.encode || this.typeDef.encode;
150
- if (encode) {
151
- try {
152
- v = encode(v);
153
- }
154
- catch {
155
- v = v == null ? v : String(v);
156
- }
157
- }
158
- else {
159
- if (typeof v === 'object' && v instanceof Date)
160
- v = (0, hl7v2_dictionary_1.toHL7DateTime)(v);
161
- }
162
- str = (0, hl7_escape_js_1.hl7Escape)(v, this.field.message);
163
- }
164
- else {
165
- const { subComponentSeparator } = this.segment.message;
166
- str = this._subComponents.map(subComponent => subComponent.toHL7String(options)).join(subComponentSeparator);
167
- while (str.endsWith(subComponentSeparator))
168
- str = str.substring(0, str.length - 1);
169
- }
170
- if (options?.serializeComponent)
171
- return String(options?.serializeComponent(this, str, options) || '');
172
- return str;
173
- }
174
- [Symbol.toStringTag]() {
175
- return this.toHL7String();
176
- }
177
- }
178
- exports.Hl7Component = Hl7Component;
package/cjs/hl7-error.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HL7Error = void 0;
4
- class HL7Error extends Error {
5
- hl7ErrorCode;
6
- severity = 'E';
7
- appErrorCode;
8
- line;
9
- segmentType;
10
- segmentSequence;
11
- fieldPosition;
12
- componentPosition;
13
- subComponentPosition;
14
- repetitionIndex;
15
- constructor(message, args) {
16
- super(message);
17
- if (args?.hl7ErrorCode)
18
- this.hl7ErrorCode = args?.hl7ErrorCode;
19
- if (args?.severity)
20
- this.severity = args?.severity;
21
- if (args?.appErrorCode)
22
- this.appErrorCode = args?.appErrorCode;
23
- if (args?.segmentType)
24
- this.segmentType = args?.segmentType;
25
- if (args?.segmentSequence != null)
26
- this.segmentSequence = args?.segmentSequence;
27
- if (args?.fieldPosition != null)
28
- this.fieldPosition = args?.fieldPosition;
29
- if (args?.componentPosition != null)
30
- this.componentPosition = args?.componentPosition;
31
- if (args?.subComponentPosition != null)
32
- this.subComponentPosition = args?.subComponentPosition;
33
- if (args?.repetitionIndex != null)
34
- this.repetitionIndex = args?.repetitionIndex;
35
- }
36
- }
37
- exports.HL7Error = HL7Error;
package/cjs/hl7-field.js DELETED
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HL7Field = void 0;
4
- const hl7_repetition_js_1 = require("./hl7-repetition.js");
5
- class HL7Field {
6
- segment;
7
- position;
8
- constructor(segment, position, def) {
9
- this.segment = segment;
10
- this.position = position;
11
- this._definition = def;
12
- this._typeDef = this.message.dictionary.types[this._definition.type];
13
- if (!this._typeDef)
14
- throw new Error(`Unknown data type: ${this._definition.type}`);
15
- this.clear();
16
- }
17
- get message() {
18
- return this.segment.message;
19
- }
20
- get definition() {
21
- return this._definition;
22
- }
23
- get typeDef() {
24
- return this._typeDef;
25
- }
26
- get isPrimitive() {
27
- return !this.typeDef.fields;
28
- }
29
- get repetitions() {
30
- return this._repetitions;
31
- }
32
- add() {
33
- const rep = new hl7_repetition_js_1.HL7Repetition(this);
34
- this._repetitions.push(rep);
35
- return rep;
36
- }
37
- clear() {
38
- this._repetitions = [];
39
- }
40
- isEmpty() {
41
- for (const rep of this._repetitions) {
42
- if (!rep.isEmpty())
43
- return false;
44
- }
45
- return true;
46
- }
47
- repetition(repetitionIndex = 0) {
48
- while (repetitionIndex >= this._repetitions.length)
49
- this.add();
50
- return this._repetitions[repetitionIndex];
51
- }
52
- component(position) {
53
- return this.repetition(0).comp(position);
54
- }
55
- subComponent(componentPos, subComponentPos) {
56
- return this.repetition(0).comp(componentPos).subcomp(subComponentPos);
57
- }
58
- /**
59
- * Alias of .repetition()
60
- */
61
- rep(repetitionIndex = 0) {
62
- return this.repetition(repetitionIndex);
63
- }
64
- /**
65
- * Alias of .component()
66
- */
67
- comp(position) {
68
- return this.component(position);
69
- }
70
- /**
71
- * Alias of .subComponent()
72
- */
73
- subcomp(componentPos, subComponentPos) {
74
- return this.subComponent(componentPos, subComponentPos);
75
- }
76
- getValue(component, subComponent) {
77
- return this._repetitions[0]?.getValue(component, subComponent);
78
- }
79
- setValue(value, component, subComponent) {
80
- return this.repetition(0).setValue(value, component, subComponent);
81
- }
82
- fromHL7String(value, options) {
83
- const components = value.split(this.message.repetitionSeparator);
84
- this._repetitions = [];
85
- for (const cmp of components) {
86
- this.add().fromHL7String(cmp, options);
87
- }
88
- }
89
- toHL7String(options) {
90
- if (!this._repetitions.length)
91
- return '';
92
- const { repetitionSeparator } = this.segment.message;
93
- let str = this._repetitions
94
- .map(component => component.toHL7String(options))
95
- .join(repetitionSeparator);
96
- while (str.endsWith(repetitionSeparator))
97
- str = str.substring(0, str.length - 1);
98
- if (options?.serializeField) {
99
- return options.serializeField(this, str, options) || '';
100
- }
101
- return str;
102
- }
103
- [Symbol.toStringTag]() {
104
- return this.toHL7String();
105
- }
106
- }
107
- exports.HL7Field = HL7Field;
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HL7MessageNode = void 0;
4
- const hl7_segment_js_1 = require("./hl7-segment.js");
5
- class HL7MessageNode {
6
- name = '';
7
- items = [];
8
- constructor(name) {
9
- this.name = name;
10
- }
11
- /**
12
- * Searches for a segment of a given type
13
- */
14
- getSegment(segmentType, indexOrAfter) {
15
- let k = 0;
16
- for (let i = 0; i < this.items.length; i++) {
17
- const seg = this.items[i];
18
- if (seg instanceof hl7_segment_js_1.HL7Segment && seg.segmentType === segmentType) {
19
- if (!indexOrAfter)
20
- return seg;
21
- if (typeof indexOrAfter === 'number') {
22
- if (indexOrAfter === k++)
23
- return seg;
24
- }
25
- else {
26
- if (indexOrAfter === seg)
27
- indexOrAfter = undefined;
28
- }
29
- }
30
- }
31
- }
32
- /**
33
- * Searches for a segment of a given type in reverse order
34
- */
35
- getSegmentFromLast(segmentType, indexOrAfter) {
36
- let k = 0;
37
- for (let i = this.items.length - 1; i >= 0; i--) {
38
- const seg = this.items[i];
39
- if (seg instanceof hl7_segment_js_1.HL7Segment && seg.segmentType === segmentType) {
40
- if (!indexOrAfter)
41
- return seg;
42
- if (typeof indexOrAfter === 'number') {
43
- if (indexOrAfter === k++)
44
- return seg;
45
- }
46
- else {
47
- if (indexOrAfter === seg)
48
- indexOrAfter = undefined;
49
- }
50
- }
51
- }
52
- }
53
- /**
54
- * Searches for a node of a given name
55
- */
56
- getNode(nodeName, indexOrAfter) {
57
- let k = 0;
58
- for (let i = 0; i < this.items.length; i++) {
59
- const node = this.items[i];
60
- if (node instanceof HL7MessageNode && node.name === nodeName) {
61
- if (!indexOrAfter)
62
- return node;
63
- if (typeof indexOrAfter === 'number') {
64
- if (indexOrAfter === k++)
65
- return node;
66
- }
67
- else {
68
- if (indexOrAfter === node)
69
- indexOrAfter = undefined;
70
- }
71
- }
72
- }
73
- }
74
- /**
75
- * Searches for a node of a given name in reverse order
76
- */
77
- getNodeFromLast(nodeName, indexOrAfter) {
78
- let k = 0;
79
- for (let i = this.items.length - 1; i >= 0; i--) {
80
- const node = this.items[i];
81
- if (node instanceof HL7MessageNode && node.name === nodeName) {
82
- if (!indexOrAfter)
83
- return node;
84
- if (typeof indexOrAfter === 'number') {
85
- if (indexOrAfter === k++)
86
- return node;
87
- }
88
- else {
89
- if (indexOrAfter === node)
90
- indexOrAfter = undefined;
91
- }
92
- }
93
- }
94
- }
95
- }
96
- exports.HL7MessageNode = HL7MessageNode;