hl7v2 1.8.0 → 1.8.2
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/README.md +431 -2
- package/hl7-message.js +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
## About
|
|
9
9
|
|
|
10
|
-
HL7 v2.x parser, serializer and validator
|
|
10
|
+
HL7 v2.x parser, serializer and validator for Node.js.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -15,27 +15,456 @@ HL7 v2.x parser, serializer and validator
|
|
|
15
15
|
$ npm install hl7v2 --save
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## Usage Example
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { HL7Message } from 'hl7v2';
|
|
22
|
+
|
|
23
|
+
const hl7String = 'MSH|^~\\&|SENDING_APP|SENDING_FACILITY|RECEIVING_APP|RECEIVING_FACILITY|202305101000||ADT^A01|123|P|2.5\r' +
|
|
24
|
+
'PID|||PATIENT_ID||DOE^JOHN';
|
|
25
|
+
|
|
26
|
+
const message = HL7Message.parse(hl7String);
|
|
27
|
+
|
|
28
|
+
// Access segments
|
|
29
|
+
const pid = message.getSegment('PID');
|
|
30
|
+
console.log(pid.field(5).getValue()); // { familyName: 'DOE', givenName: 'JOHN' }
|
|
31
|
+
|
|
32
|
+
// Create new message
|
|
33
|
+
const msg = new HL7Message('2.5');
|
|
34
|
+
const msh = msg.header;
|
|
35
|
+
msh.field(3).setValue('MY_APP');
|
|
36
|
+
msg.addSegment('PID').field(5).setValue({ familyName: 'SMITH', givenName: 'JANE' });
|
|
37
|
+
|
|
38
|
+
console.log(msg.toHL7String());
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API Reference
|
|
42
|
+
|
|
43
|
+
### HL7Message
|
|
44
|
+
|
|
45
|
+
The root object representing an HL7 message.
|
|
46
|
+
|
|
47
|
+
#### Properties
|
|
48
|
+
|
|
49
|
+
- `version: string`: HL7 version (e.g., '2.5').
|
|
50
|
+
- `segments: HL7Segment[]`: Array of all segments in the message.
|
|
51
|
+
- `header: HL7Segment`: The MSH segment of the message.
|
|
52
|
+
- `fieldSeparator: string`: Character used to separate fields (default `|`).
|
|
53
|
+
- `componentSeparator: string`: Character used to separate components (default `^`).
|
|
54
|
+
- `repetitionSeparator: string`: Character used to separate repetitions (default `~`).
|
|
55
|
+
- `escapeCharacter: string`: Character used for escaping (default `\`).
|
|
56
|
+
- `subComponentSeparator: string`: Character used to separate sub-components (default `&`).
|
|
57
|
+
|
|
58
|
+
#### Methods
|
|
59
|
+
|
|
60
|
+
##### .parse()
|
|
61
|
+
|
|
62
|
+
Parses an HL7 string into an `HL7Message` object.
|
|
63
|
+
`static parse(input: string, options?: HL7MessageParseOptions): HL7Message`
|
|
64
|
+
example
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const message = HL7Message.parse('MSH|^~\\&|SENDING_APP|...');
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
##### .addSegment()
|
|
71
|
+
|
|
72
|
+
Adds a new segment to the message.
|
|
73
|
+
`addSegment(segmentType: string, index?: number): HL7Segment`
|
|
74
|
+
example
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const pid = message.addSegment('PID');
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
##### .getSegment()
|
|
81
|
+
|
|
82
|
+
Finds a segment by type.
|
|
83
|
+
`getSegment(segmentType: string, indexOrAfter?: number | HL7Segment): HL7Segment | undefined`
|
|
84
|
+
example
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const msh = message.getSegment('MSH');
|
|
88
|
+
const firstObx = message.getSegment('OBX');
|
|
89
|
+
const secondObx = message.getSegment('OBX', 1); // Get second OBX
|
|
90
|
+
const nextObx = message.getSegment('OBX', firstObx); // Get OBX after firstObx
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
##### .toHL7String()
|
|
94
|
+
|
|
95
|
+
Serializes the message back to an HL7 string.
|
|
96
|
+
`toHL7String(options?: HL7MessageSerializeOptions): string`
|
|
97
|
+
example
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const hl7 = message.toHL7String();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
##### .createAck()
|
|
104
|
+
|
|
105
|
+
Creates an ACK message for the current message.
|
|
106
|
+
`createAck(ackCode?: string, textMessage?: string): HL7Message`
|
|
107
|
+
example
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const ack = message.createAck('AA', 'Message accepted');
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
##### .createNak()
|
|
114
|
+
|
|
115
|
+
Creates a NAK message for the current message.
|
|
116
|
+
`createNak(errors: HL7Error[]): HL7Message`
|
|
117
|
+
example
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const error = new HL7Error('Invalid field value', { hl7ErrorCode: 102 });
|
|
121
|
+
const nak = message.createNak([error]);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### HL7Segment
|
|
127
|
+
|
|
128
|
+
Represents a single segment (e.g., PID, MSH) within an HL7 message.
|
|
129
|
+
|
|
130
|
+
#### Properties
|
|
131
|
+
|
|
132
|
+
- `segmentType: string`: The 3-character segment type (e.g., 'PID').
|
|
133
|
+
- `fields: HL7Field[]`: Array of fields in the segment.
|
|
134
|
+
- `message: HL7Message`: Reference to the parent message.
|
|
135
|
+
|
|
136
|
+
#### Methods
|
|
137
|
+
|
|
138
|
+
##### .field()
|
|
139
|
+
|
|
140
|
+
Returns the field at the specified position (1-indexed).
|
|
141
|
+
`field(position: number): HL7Field`
|
|
142
|
+
example
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const patientName = pid.field(5);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
##### .toHL7String()
|
|
149
|
+
|
|
150
|
+
Serializes the segment to an HL7 string.
|
|
151
|
+
`toHL7String(options?: Hl7SegmentSerializeOptions): string`
|
|
152
|
+
example
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const hl7 = pid.toHL7String();
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
### HL7Field
|
|
161
|
+
|
|
162
|
+
Represents a field within a segment. Fields can contain one or more repetitions.
|
|
163
|
+
|
|
164
|
+
#### Properties
|
|
165
|
+
|
|
166
|
+
- `position: number`: The position of the field within the segment (1-indexed).
|
|
167
|
+
- `repetitions: HL7Repetition[]`: Array of repetitions for this field.
|
|
168
|
+
- `segment: HL7Segment`: Reference to the parent segment.
|
|
169
|
+
|
|
170
|
+
#### Methods
|
|
171
|
+
|
|
172
|
+
##### .repetition()
|
|
173
|
+
|
|
174
|
+
Returns the repetition at the specified index (0-indexed).
|
|
175
|
+
`repetition(index?: number): HL7Repetition`
|
|
176
|
+
example
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
const firstRep = field.repetition(0);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
##### .rep()
|
|
183
|
+
|
|
184
|
+
Alias for `repetition()`.
|
|
185
|
+
`rep(index?: number): HL7Repetition`
|
|
186
|
+
example
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
const firstRep = field.rep(0);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
##### .component()
|
|
193
|
+
|
|
194
|
+
Shortcut to access a component in the first repetition.
|
|
195
|
+
`component(position: number): Hl7Component`
|
|
196
|
+
example
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const comp1 = field.component(1);
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
##### .comp()
|
|
203
|
+
|
|
204
|
+
Alias for `component()`.
|
|
205
|
+
`comp(position: number): Hl7Component`
|
|
206
|
+
example
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
const comp1 = field.comp(1);
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
##### .getValue()
|
|
213
|
+
|
|
214
|
+
Gets the value of the field.
|
|
215
|
+
`getValue(component?: number, subComponent?: number): any`
|
|
216
|
+
example
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
const value = field.getValue();
|
|
220
|
+
const compValue = field.getValue(1);
|
|
221
|
+
const subCompValue = field.getValue(1, 1);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
##### .setValue()
|
|
225
|
+
|
|
226
|
+
Sets the value of the field.
|
|
227
|
+
`setValue(value: any, component?: number, subComponent?: number): void`
|
|
228
|
+
example
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
field.setValue('DOE^JOHN');
|
|
232
|
+
field.setValue('DOE', 1);
|
|
233
|
+
field.setValue('JOHN', 1, 1);
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
##### .toHL7String()
|
|
237
|
+
|
|
238
|
+
Serializes the field to an HL7 string.
|
|
239
|
+
`toHL7String(options?: Hl7FieldSerializeOptions): string`
|
|
240
|
+
example
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const hl7 = field.toHL7String();
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
### HL7Repetition
|
|
249
|
+
|
|
250
|
+
Represents a single repetition of a field.
|
|
251
|
+
|
|
252
|
+
#### Properties
|
|
253
|
+
|
|
254
|
+
- `components: Hl7Component[]`: Array of components in this repetition.
|
|
255
|
+
- `field: HL7Field`: Reference to the parent field.
|
|
256
|
+
|
|
257
|
+
#### Methods
|
|
258
|
+
|
|
259
|
+
##### .component()
|
|
260
|
+
|
|
261
|
+
Returns the component at the specified position (1-indexed).
|
|
262
|
+
`component(position: number): Hl7Component`
|
|
263
|
+
example
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
const comp = repetition.component(1);
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
##### .comp()
|
|
270
|
+
|
|
271
|
+
Alias for `component()`.
|
|
272
|
+
`comp(position: number): Hl7Component`
|
|
273
|
+
example
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
const comp = repetition.comp(1);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
##### .getValue()
|
|
280
|
+
|
|
281
|
+
Gets the value.
|
|
282
|
+
`getValue(component?: number, subComponent?: number): any`
|
|
283
|
+
example
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
const value = repetition.getValue();
|
|
287
|
+
const subValue = repetition.getValue(1, 1);
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
##### .setValue()
|
|
291
|
+
|
|
292
|
+
Sets the value.
|
|
293
|
+
`setValue(value: any, component?: number, subComponent?: number): this`
|
|
294
|
+
example
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
repetition.setValue('DOE', 1);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
### Hl7Component
|
|
303
|
+
|
|
304
|
+
Represents a component within a field repetition.
|
|
305
|
+
|
|
306
|
+
#### Properties
|
|
307
|
+
|
|
308
|
+
- `position: number`: Position within the repetition (1-indexed).
|
|
309
|
+
- `subComponents: Hl7SubComponent[]`: Array of sub-components.
|
|
310
|
+
|
|
311
|
+
#### Methods
|
|
312
|
+
|
|
313
|
+
##### .subComponent()
|
|
314
|
+
|
|
315
|
+
Returns the sub-component at the specified position (1-indexed).
|
|
316
|
+
`subComponent(position: number): Hl7SubComponent`
|
|
317
|
+
example
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
const sub = component.subComponent(1);
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
##### .subcomp()
|
|
324
|
+
|
|
325
|
+
Alias for `subComponent()`.
|
|
326
|
+
`subcomp(position: number): Hl7SubComponent`
|
|
327
|
+
example
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
const sub = component.subcomp(1);
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
##### .getValue()
|
|
334
|
+
|
|
335
|
+
Gets the value.
|
|
336
|
+
`getValue(subComponent?: number): any`
|
|
337
|
+
example
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
const value = component.getValue();
|
|
341
|
+
const subValue = component.getValue(1);
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
##### .setValue()
|
|
345
|
+
|
|
346
|
+
Sets the value.
|
|
347
|
+
`setValue(value: any, subComponent?: number): this`
|
|
348
|
+
example
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
component.setValue('JOHN', 1);
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
### Hl7SubComponent
|
|
357
|
+
|
|
358
|
+
The smallest unit of data in an HL7 message.
|
|
359
|
+
|
|
360
|
+
#### Properties
|
|
361
|
+
|
|
362
|
+
- `position: number`: Position within the component (1-indexed).
|
|
363
|
+
- `value: any`: The actual data value.
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
### HL7MessageNode
|
|
368
|
+
|
|
369
|
+
Used for representing the hierarchical structure of a message (groups and segments).
|
|
370
|
+
|
|
371
|
+
#### Methods
|
|
372
|
+
|
|
373
|
+
##### .getSegment()
|
|
374
|
+
|
|
375
|
+
Searches for a segment within this node.
|
|
376
|
+
`getSegment(segmentType: string, indexOrAfter?: number | HL7Segment): HL7Segment | undefined`
|
|
377
|
+
example
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
const seg = node.getSegment('PID');
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
##### .getNode()
|
|
384
|
+
|
|
385
|
+
Searches for a child node by name.
|
|
386
|
+
`getNode(nodeName: string, indexOrAfter?: number | HL7MessageNode): HL7MessageNode | undefined`
|
|
387
|
+
example
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
const childNode = node.getNode('PATIENT_RESULT');
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
### HL7Error
|
|
396
|
+
|
|
397
|
+
Custom error class for HL7-related errors.
|
|
398
|
+
|
|
399
|
+
#### Properties
|
|
400
|
+
|
|
401
|
+
- `hl7ErrorCode?: number`: HL7 standard error code.
|
|
402
|
+
- `severity?: 'E' | 'W' | 'I'`: Error severity (Error, Warning, Information).
|
|
403
|
+
- `segmentType?: string`: Segment where the error occurred.
|
|
404
|
+
- `fieldPosition?: number`: Field position where the error occurred.
|
|
405
|
+
|
|
406
|
+
---
|
|
407
|
+
|
|
408
|
+
##### .hl7Escape()
|
|
409
|
+
|
|
410
|
+
Escapes a string for use in an HL7 message.
|
|
411
|
+
`hl7Escape(value: string, message?: HL7Message): string`
|
|
412
|
+
example
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
const escaped = hl7Escape('DOE^JOHN'); // "DOE\S\JOHN"
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
#### Methods
|
|
419
|
+
|
|
420
|
+
##### .hl7UnEscape()
|
|
421
|
+
|
|
422
|
+
Unescapes an HL7 string.
|
|
423
|
+
`hl7UnEscape(value: string, message?: HL7Message): string | Buffer | null`
|
|
424
|
+
example
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
const unescaped = hl7UnEscape('DOE\\S\\JOHN'); // "DOE^JOHN"
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
---
|
|
431
|
+
|
|
18
432
|
## Node Compatibility
|
|
19
433
|
|
|
20
|
-
- node >=
|
|
434
|
+
- node >= 20.x
|
|
21
435
|
|
|
22
436
|
### License
|
|
23
437
|
|
|
24
438
|
HL7v2 is available under [MIT](LICENSE) license.
|
|
25
439
|
|
|
26
440
|
[npm-image]: https://img.shields.io/npm/v/hl7v2.svg
|
|
441
|
+
|
|
27
442
|
[npm-url]: https://npmjs.org/package/hl7v2
|
|
443
|
+
|
|
28
444
|
[ci-test-image]: https://github.com/panates/hl7v2/actions/workflows/test.yml/badge.svg
|
|
445
|
+
|
|
29
446
|
[ci-test-url]: https://github.com/panates/hl7v2/actions/workflows/test.yml
|
|
447
|
+
|
|
30
448
|
[coveralls-image]: https://img.shields.io/coveralls/panates/hl7v2/master.svg
|
|
449
|
+
|
|
31
450
|
[coveralls-url]: https://coveralls.io/r/panates/hl7v2
|
|
451
|
+
|
|
32
452
|
[downloads-image]: https://img.shields.io/npm/dm/hl7v2.svg
|
|
453
|
+
|
|
33
454
|
[downloads-url]: https://npmjs.org/package/hl7v2
|
|
455
|
+
|
|
34
456
|
[gitter-image]: https://badges.gitter.im/panates/hl7v2.svg
|
|
457
|
+
|
|
35
458
|
[gitter-url]: https://gitter.im/panates/hl7v2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
459
|
+
|
|
36
460
|
[dependencies-image]: https://david-dm.org/panates/hl7v2/status.svg
|
|
461
|
+
|
|
37
462
|
[dependencies-url]: https://david-dm.org/panates/hl7v2
|
|
463
|
+
|
|
38
464
|
[devdependencies-image]: https://david-dm.org/panates/hl7v2/dev-status.svg
|
|
465
|
+
|
|
39
466
|
[devdependencies-url]: https://david-dm.org/panates/hl7v2?type=dev
|
|
467
|
+
|
|
40
468
|
[quality-image]: http://npm.packagequality.com/shield/hl7v2.png
|
|
469
|
+
|
|
41
470
|
[quality-url]: http://packagequality.com/#?package=hl7v2
|
package/hl7-message.js
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hl7v2",
|
|
3
3
|
"description": "HL7 v2 parser, serializer, validator for NodeJS",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.2",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@jsopen/objects": "^2.
|
|
8
|
+
"@jsopen/objects": "^2.2.1",
|
|
9
9
|
"iconv-lite": "^0.7.2",
|
|
10
10
|
"is-typedarray": "^1.0.0",
|
|
11
|
-
"node-events-async": "^1.5.
|
|
12
|
-
"ts-gems": "^3.11.
|
|
11
|
+
"node-events-async": "^1.5.2",
|
|
12
|
+
"ts-gems": "^3.11.6",
|
|
13
13
|
"tslib": "^2.8.1",
|
|
14
|
-
"valgen": "^
|
|
14
|
+
"valgen": "^6.0.3",
|
|
15
15
|
"uid": "^2.0.2"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"hl7v2-dictionary": "^1.8.
|
|
18
|
+
"hl7v2-dictionary": "^1.8.2"
|
|
19
19
|
},
|
|
20
20
|
"type": "module",
|
|
21
21
|
"module": "./index.js",
|