hl7v2 1.2.3 → 1.2.5

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.
@@ -46,6 +46,17 @@ class Hl7Component {
46
46
  else
47
47
  this._subComponents = [];
48
48
  }
49
+ isEmpty() {
50
+ if (this._data)
51
+ return this._data.value == null;
52
+ if (this._subComponents) {
53
+ for (const sub of this._subComponents) {
54
+ if (!sub.isEmpty())
55
+ return false;
56
+ }
57
+ }
58
+ return true;
59
+ }
49
60
  subcomp(position) {
50
61
  if (this.field.isPrimitive)
51
62
  throw new Error('Primitive fields have no sub-component');
package/cjs/hl7-field.js CHANGED
@@ -35,6 +35,13 @@ class HL7Field {
35
35
  clear() {
36
36
  this._repetitions = [];
37
37
  }
38
+ isEmpty() {
39
+ for (const rep of this._repetitions) {
40
+ if (!rep.isEmpty())
41
+ return false;
42
+ }
43
+ return true;
44
+ }
38
45
  repetition(repetitionIndex = 0) {
39
46
  while (repetitionIndex >= this._repetitions.length)
40
47
  this.add();
@@ -33,7 +33,10 @@ class HL7Message {
33
33
  return this._version;
34
34
  }
35
35
  get messageType() {
36
- return this.header.field(hl7v2_dictionary_1.MSHSegment.MessageType).toHL7String();
36
+ const f = this.header.field(hl7v2_dictionary_1.MSHSegment.MessageType);
37
+ if (!f)
38
+ return '';
39
+ return f.getValue(1) + '^' + f.getValue(2);
37
40
  }
38
41
  get controlId() {
39
42
  return this.header.field(hl7v2_dictionary_1.MSHSegment.MessageControlID).toHL7String();
@@ -96,7 +99,7 @@ class HL7Message {
96
99
  this.repetitionSeparator = raw.repetitionSeparator;
97
100
  this.escapeCharacter = raw.escapeCharacter;
98
101
  this.subComponentSeparator = raw.subComponentSeparator;
99
- const lines = raw.data.split(constants_js_1.CR);
102
+ const lines = raw.data.replaceAll(constants_js_1.CR + constants_js_1.LF, constants_js_1.CR).split(constants_js_1.CR);
100
103
  const headerItems = raw.header.split(this.fieldSeparator);
101
104
  for (const [i, line] of lines.entries()) {
102
105
  if (!line)
@@ -22,6 +22,13 @@ class HL7Repetition {
22
22
  clear() {
23
23
  this._components = [];
24
24
  }
25
+ isEmpty() {
26
+ for (const component of this._components) {
27
+ if (!component.isEmpty())
28
+ return false;
29
+ }
30
+ return true;
31
+ }
25
32
  /**
26
33
  *
27
34
  */
@@ -30,7 +37,7 @@ class HL7Repetition {
30
37
  throw new Error('Invalid component position');
31
38
  let component = this._components[position - 1];
32
39
  if (!component) {
33
- let fDef = this.field.typeDef.fields?.[String(position)];
40
+ let fDef = this.field.typeDef.fields?.[String(position - 1)];
34
41
  if (!fDef) {
35
42
  if (position === 1)
36
43
  fDef = this.field.definition;
@@ -36,6 +36,9 @@ class Hl7SubComponent {
36
36
  const decode = this.definition.decode || this.typeDef.decode;
37
37
  this._value = decode && value != null ? decode(value) : value;
38
38
  }
39
+ isEmpty() {
40
+ return this._value == null;
41
+ }
39
42
  fromHL7String(value) {
40
43
  this._value = undefined;
41
44
  if (!value)
@@ -43,6 +43,17 @@ export class Hl7Component {
43
43
  else
44
44
  this._subComponents = [];
45
45
  }
46
+ isEmpty() {
47
+ if (this._data)
48
+ return this._data.value == null;
49
+ if (this._subComponents) {
50
+ for (const sub of this._subComponents) {
51
+ if (!sub.isEmpty())
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ }
46
57
  subcomp(position) {
47
58
  if (this.field.isPrimitive)
48
59
  throw new Error('Primitive fields have no sub-component');
package/esm/hl7-field.js CHANGED
@@ -32,6 +32,13 @@ export class HL7Field {
32
32
  clear() {
33
33
  this._repetitions = [];
34
34
  }
35
+ isEmpty() {
36
+ for (const rep of this._repetitions) {
37
+ if (!rep.isEmpty())
38
+ return false;
39
+ }
40
+ return true;
41
+ }
35
42
  repetition(repetitionIndex = 0) {
36
43
  while (repetitionIndex >= this._repetitions.length)
37
44
  this.add();
@@ -2,7 +2,7 @@ import process from 'node:process';
2
2
  import { dictionaries as defaultDictionaries, ERLType, ERRSegment, findNearestHL7Version, HL7Version, MSASegment, MSHSegment, } from 'hl7v2-dictionary';
3
3
  import iconv from 'iconv-lite';
4
4
  import { uid } from 'uid';
5
- import { COMPONENT_SEPARATOR, CR, ESCAPE_CHARACTER, FIELD_SEPARATOR, FS, REPETITION_SEPARATOR, SUBCOMPONENT_SEPARATOR, VT, } from './constants.js';
5
+ import { COMPONENT_SEPARATOR, CR, ESCAPE_CHARACTER, FIELD_SEPARATOR, FS, LF, REPETITION_SEPARATOR, SUBCOMPONENT_SEPARATOR, VT, } from './constants.js';
6
6
  import { HL7Error } from './hl7-error.js';
7
7
  import { HL7Segment } from './hl7-segment.js';
8
8
  export class HL7Message {
@@ -29,7 +29,10 @@ export class HL7Message {
29
29
  return this._version;
30
30
  }
31
31
  get messageType() {
32
- return this.header.field(MSHSegment.MessageType).toHL7String();
32
+ const f = this.header.field(MSHSegment.MessageType);
33
+ if (!f)
34
+ return '';
35
+ return f.getValue(1) + '^' + f.getValue(2);
33
36
  }
34
37
  get controlId() {
35
38
  return this.header.field(MSHSegment.MessageControlID).toHL7String();
@@ -92,7 +95,7 @@ export class HL7Message {
92
95
  this.repetitionSeparator = raw.repetitionSeparator;
93
96
  this.escapeCharacter = raw.escapeCharacter;
94
97
  this.subComponentSeparator = raw.subComponentSeparator;
95
- const lines = raw.data.split(CR);
98
+ const lines = raw.data.replaceAll(CR + LF, CR).split(CR);
96
99
  const headerItems = raw.header.split(this.fieldSeparator);
97
100
  for (const [i, line] of lines.entries()) {
98
101
  if (!line)
@@ -19,6 +19,13 @@ export class HL7Repetition {
19
19
  clear() {
20
20
  this._components = [];
21
21
  }
22
+ isEmpty() {
23
+ for (const component of this._components) {
24
+ if (!component.isEmpty())
25
+ return false;
26
+ }
27
+ return true;
28
+ }
22
29
  /**
23
30
  *
24
31
  */
@@ -27,7 +34,7 @@ export class HL7Repetition {
27
34
  throw new Error('Invalid component position');
28
35
  let component = this._components[position - 1];
29
36
  if (!component) {
30
- let fDef = this.field.typeDef.fields?.[String(position)];
37
+ let fDef = this.field.typeDef.fields?.[String(position - 1)];
31
38
  if (!fDef) {
32
39
  if (position === 1)
33
40
  fDef = this.field.definition;
@@ -33,6 +33,9 @@ export class Hl7SubComponent {
33
33
  const decode = this.definition.decode || this.typeDef.decode;
34
34
  this._value = decode && value != null ? decode(value) : value;
35
35
  }
36
+ isEmpty() {
37
+ return this._value == null;
38
+ }
36
39
  fromHL7String(value) {
37
40
  this._value = undefined;
38
41
  if (!value)
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.3",
4
+ "version": "1.2.5",
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.3"
18
+ "hl7v2-dictionary": "^1.2.5"
19
19
  },
20
20
  "type": "module",
21
21
  "exports": {
@@ -20,6 +20,7 @@ export declare class Hl7Component {
20
20
  get isPrimitive(): boolean;
21
21
  get subComponents(): Hl7SubComponent[] | undefined;
22
22
  clear(): void;
23
+ isEmpty(): boolean;
23
24
  subcomp(position: number): Hl7SubComponent;
24
25
  getValue(subComponent?: number): any | undefined;
25
26
  setValue(value: any, subComponent?: number): this;
@@ -18,6 +18,7 @@ export declare class HL7Field {
18
18
  get repetitions(): HL7Repetition[];
19
19
  add(): HL7Repetition;
20
20
  clear(): void;
21
+ isEmpty(): boolean;
21
22
  repetition(repetitionIndex?: number): HL7Repetition;
22
23
  component(position: number): Hl7Component;
23
24
  subComponent(componentPos: number, subComponentPos: number): Hl7SubComponent;
@@ -12,6 +12,7 @@ export declare class HL7Repetition {
12
12
  get components(): Hl7Component[] | undefined;
13
13
  get index(): number;
14
14
  clear(): void;
15
+ isEmpty(): boolean;
15
16
  /**
16
17
  *
17
18
  */
@@ -17,6 +17,7 @@ export declare class Hl7SubComponent {
17
17
  get typeDef(): HL7DataTypeDefinition;
18
18
  get value(): any | undefined;
19
19
  set value(value: any);
20
+ isEmpty(): boolean;
20
21
  fromHL7String(value: string): void;
21
22
  toHL7String(options?: Hl7SubComponentSerializeOptions): string;
22
23
  [Symbol.toStringTag](): string;