hl7v2-dictionary 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 +186 -14
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# hl7v2-dictionary
|
|
2
2
|
|
|
3
3
|
[![NPM Version][npm-image]][npm-url]
|
|
4
4
|
[![NPM Downloads][downloads-image]][downloads-url]
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
## About
|
|
9
9
|
|
|
10
|
-
HL7 v2.x
|
|
10
|
+
HL7 v2.x dictionary for Node.js. This package provides version-specific definitions for segments, data types, and messages, supporting versions from 2.1 to 2.8. It is used by the `hl7v2` parser and serializer to understand message structures.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -15,11 +15,191 @@ HL7 v2.x dictionaries
|
|
|
15
15
|
$ npm install hl7v2-dictionary --save
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
## Usage Example
|
|
19
|
+
|
|
20
|
+
### Accessing a Dictionary
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { dictionaries, HL7Version } from 'hl7v2-dictionary';
|
|
24
|
+
|
|
25
|
+
const dict25 = dictionaries[HL7Version.v2_5];
|
|
26
|
+
|
|
27
|
+
console.log('Version:', dict25.version);
|
|
28
|
+
console.log('PID Segment definition:', dict25.segments['PID']);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Extending a Dictionary
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { dictionaries, HL7Version } from 'hl7v2-dictionary';
|
|
35
|
+
|
|
36
|
+
const customDict = dictionaries[HL7Version.v2_5].extend({
|
|
37
|
+
version: '2.5-custom' as any,
|
|
38
|
+
segments: {
|
|
39
|
+
Z01: {
|
|
40
|
+
desc: 'Custom Segment',
|
|
41
|
+
fields: {
|
|
42
|
+
1: { type: 'ST', desc: 'Custom Field 1', opt: 'R' }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
console.log('Custom Segment:', customDict.segments['Z01']);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### HL7Dictionary
|
|
54
|
+
|
|
55
|
+
The `HL7Dictionary` class holds definitions for a specific HL7 version.
|
|
56
|
+
|
|
57
|
+
#### Properties
|
|
58
|
+
|
|
59
|
+
- `version: HL7Version` - The HL7 version this dictionary represents.
|
|
60
|
+
- `segments: Record<string, HL7SegmentDefinition>` - Segment definitions.
|
|
61
|
+
- `types: Record<string, HL7DataTypeDefinition>` - Data type definitions.
|
|
62
|
+
- `messages: Record<string, HL7MessageDefinition>` - Message structure definitions.
|
|
63
|
+
|
|
64
|
+
#### Methods
|
|
65
|
+
|
|
66
|
+
##### .extend()
|
|
67
|
+
Creates a new dictionary by extending the current one with new or overridden definitions.
|
|
68
|
+
`extend(args: { version?: HL7Version; segments?: Record<string, DeeperPartial<HL7SegmentDefinition>>; types?: Record<string, DeeperPartial<HL7DataTypeDefinition>>; messages?: Record<string, HL7MessageDefinition>; }): HL7Dictionary`
|
|
69
|
+
|
|
70
|
+
example
|
|
71
|
+
```typescript
|
|
72
|
+
const extendedDict = dict.extend({
|
|
73
|
+
segments: {
|
|
74
|
+
PID: {
|
|
75
|
+
fields: {
|
|
76
|
+
1: { desc: 'Overridden Description' }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
##### .overwriteSegments()
|
|
84
|
+
Merges new segment definitions into the current dictionary.
|
|
85
|
+
`overwriteSegments(segmentsDefs: Record<string, DeeperPartial<HL7SegmentDefinition>>): void`
|
|
86
|
+
|
|
87
|
+
example
|
|
88
|
+
```typescript
|
|
89
|
+
dict.overwriteSegments({
|
|
90
|
+
PID: {
|
|
91
|
+
fields: {
|
|
92
|
+
1: { desc: 'New Description' }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
##### .overwriteTypes()
|
|
99
|
+
Merges new data type definitions into the current dictionary.
|
|
100
|
+
`overwriteTypes(typeDefs: Record<string, DeeperPartial<HL7DataTypeDefinition>>): void`
|
|
101
|
+
|
|
102
|
+
example
|
|
103
|
+
```typescript
|
|
104
|
+
dict.overwriteTypes({
|
|
105
|
+
ST: {
|
|
106
|
+
desc: 'String Data Type'
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Utility Functions
|
|
112
|
+
|
|
113
|
+
##### .findNearestHL7Version()
|
|
114
|
+
Finds the nearest available HL7 version in the dictionary for a given version string.
|
|
115
|
+
`findNearestHL7Version(version: HL7Version): HL7Version`
|
|
116
|
+
|
|
117
|
+
example
|
|
118
|
+
```typescript
|
|
119
|
+
import { findNearestHL7Version, HL7Version } from 'hl7v2-dictionary';
|
|
120
|
+
|
|
121
|
+
const nearest = findNearestHL7Version('2.5.2' as any);
|
|
122
|
+
// Returns HL7Version.v2_5
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
##### .toHL7Date()
|
|
126
|
+
Formats a Date or string into an HL7 date string (YYYYMMDD).
|
|
127
|
+
`toHL7Date(value: Date | string): string`
|
|
128
|
+
|
|
129
|
+
example
|
|
130
|
+
```typescript
|
|
131
|
+
import { toHL7Date } from 'hl7v2-dictionary';
|
|
132
|
+
|
|
133
|
+
const dateStr = toHL7Date(new Date('2023-10-27'));
|
|
134
|
+
// Returns "20231027"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
##### .toHL7DateTime()
|
|
138
|
+
Formats a Date or string into an HL7 date-time string (YYYYMMDDHHMMSS).
|
|
139
|
+
`toHL7DateTime(value: Date | string): string`
|
|
140
|
+
|
|
141
|
+
example
|
|
142
|
+
```typescript
|
|
143
|
+
import { toHL7DateTime } from 'hl7v2-dictionary';
|
|
144
|
+
|
|
145
|
+
const dateTimeStr = toHL7DateTime(new Date('2023-10-27T10:30:00'));
|
|
146
|
+
// Returns "20231027103000"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
##### .toHL7Time()
|
|
150
|
+
Formats a Date or string into an HL7 time string (HHMMSS).
|
|
151
|
+
`toHL7Time(value: Date | string): string`
|
|
152
|
+
|
|
153
|
+
example
|
|
154
|
+
```typescript
|
|
155
|
+
import { toHL7Time } from 'hl7v2-dictionary';
|
|
156
|
+
|
|
157
|
+
const timeStr = toHL7Time(new Date('2023-10-27T10:30:00'));
|
|
158
|
+
// Returns "103000"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Interfaces
|
|
162
|
+
|
|
163
|
+
#### HL7SegmentDefinition
|
|
164
|
+
- `desc?: string` - Description of the segment.
|
|
165
|
+
- `fields: Record<string, HL7FieldDefinition>` - Map of field index to field definition.
|
|
166
|
+
|
|
167
|
+
#### HL7FieldDefinition
|
|
168
|
+
- `type: string` - The data type of the field.
|
|
169
|
+
- `desc?: string` - Description of the field.
|
|
170
|
+
- `opt?: HL7DatatypeOptional` - Optionality ('R', 'O', 'S', 'C', 'B').
|
|
171
|
+
- `rep?: HL7DatatypeRepetition` - Repetition (number or 'infinite').
|
|
172
|
+
- `len?: number` - Maximum length.
|
|
173
|
+
- `table?: number` - Associated table number.
|
|
174
|
+
|
|
175
|
+
#### HL7DataTypeDefinition
|
|
176
|
+
- `desc?: string` - Description of the data type.
|
|
177
|
+
- `fields?: Record<string, HL7FieldDefinition>` - Components of the data type (if complex).
|
|
178
|
+
|
|
179
|
+
#### HL7MessageDefinition
|
|
180
|
+
- `desc?: string` - Description of the message.
|
|
181
|
+
- `segments?: Record<string, HL7MessageSegmentsDefinition>` - Message structure definition.
|
|
182
|
+
|
|
183
|
+
### Enums
|
|
184
|
+
|
|
185
|
+
#### HL7Version
|
|
186
|
+
- `v2_1 = '2.1'`
|
|
187
|
+
- `v2_2 = '2.2'`
|
|
188
|
+
- `v2_3 = '2.3'`
|
|
189
|
+
- `v2_3_1 = '2.3.1'`
|
|
190
|
+
- `v2_4 = '2.4'`
|
|
191
|
+
- `v2_5 = '2.5'`
|
|
192
|
+
- `v2_5_1 = '2.5.1'`
|
|
193
|
+
- `v2_6 = '2.6'`
|
|
194
|
+
- `v2_7 = '2.7'`
|
|
195
|
+
- `v2_7_1 = '2.7.1'`
|
|
196
|
+
- `v2_8 = '2.8'`
|
|
197
|
+
|
|
18
198
|
## Node Compatibility
|
|
19
199
|
|
|
20
|
-
- node >=
|
|
200
|
+
- node >= 20.x
|
|
21
201
|
|
|
22
|
-
|
|
202
|
+
## License
|
|
23
203
|
|
|
24
204
|
HL7v2 is available under [MIT](LICENSE) license.
|
|
25
205
|
|
|
@@ -27,15 +207,7 @@ HL7v2 is available under [MIT](LICENSE) license.
|
|
|
27
207
|
[npm-url]: https://npmjs.org/package/hl7v2-dictionary
|
|
28
208
|
[ci-test-image]: https://github.com/panates/hl7v2/actions/workflows/test.yml/badge.svg
|
|
29
209
|
[ci-test-url]: https://github.com/panates/hl7v2/actions/workflows/test.yml
|
|
30
|
-
[coveralls-image]: https://img.shields.io/coveralls/panates/hl7v2
|
|
31
|
-
[coveralls-url]: https://coveralls.io/
|
|
210
|
+
[coveralls-image]: https://img.shields.io/coveralls/panates/hl7v2/master.svg
|
|
211
|
+
[coveralls-url]: https://coveralls.io/github/panates/hl7v2
|
|
32
212
|
[downloads-image]: https://img.shields.io/npm/dm/hl7v2-dictionary.svg
|
|
33
213
|
[downloads-url]: https://npmjs.org/package/hl7v2-dictionary
|
|
34
|
-
[gitter-image]: https://badges.gitter.im/panates/hl7v2-dictionary.svg
|
|
35
|
-
[gitter-url]: https://gitter.im/panates/hl7v2-dictionary?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
36
|
-
[dependencies-image]: https://david-dm.org/panates/hl7v2-dictionary/status.svg
|
|
37
|
-
[dependencies-url]: https://david-dm.org/panates/hl7v2-dictionary
|
|
38
|
-
[devdependencies-image]: https://david-dm.org/panates/hl7v2-dictionary/dev-status.svg
|
|
39
|
-
[devdependencies-url]: https://david-dm.org/panates/hl7v2-dictionary?type=dev
|
|
40
|
-
[quality-image]: http://npm.packagequality.com/shield/hl7v2-dictionary.png
|
|
41
|
-
[quality-url]: http://packagequality.com/#?package=hl7v2-dictionary
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hl7v2-dictionary",
|
|
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.
|
|
9
|
-
"ts-gems": "^3.11.
|
|
8
|
+
"@jsopen/objects": "^2.2.1",
|
|
9
|
+
"ts-gems": "^3.11.6",
|
|
10
10
|
"tslib": "^2.8.1",
|
|
11
|
-
"valgen": "^
|
|
11
|
+
"valgen": "^6.0.3"
|
|
12
12
|
},
|
|
13
13
|
"type": "module",
|
|
14
14
|
"module": "./index.js",
|