hl7-tstd 0.1.0 → 0.3.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.
package/README.md CHANGED
@@ -2,107 +2,325 @@
2
2
 
3
3
  A simple package to create, parse & transform HL7 message.
4
4
 
5
- ```js
6
- import HL7 from 'hl7-tstd';
5
+ ```typescript
6
+ import HL7, { Segment } from 'hl7-tstd';
7
7
 
8
- const hl7 = new HL7(raw);
8
+ const hl7 = new HL7(raw); // raw: raw HL7 message string
9
9
  ```
10
10
 
11
- _cjs support under development._
11
+ _Segment_ is only a typescript type.
12
+
13
+ ### parseOptions
14
+
15
+ Additional configs for hl7 parsing and building.
16
+
17
+ | Parameter | Default Value | Expected |
18
+ | :------------- | :-----------: | :-----------------------------------: |
19
+ | fieldDelim | `\|` | `string` |
20
+ | repeatingDelim | `~` | `string` |
21
+ | componentDelim | `^` | `string` |
22
+ | subCompDelim | `\&` | `string` |
23
+ | eolDelim | `\r?\n\|\r` | `\r?\n\|\r` \| `\r\n` \| `\n` \| `\r` |
24
+ | buildEolChar | `\r\n` | `string` |
12
25
 
13
26
  ## API References
14
27
 
15
28
  <details id="get">
16
29
  <summary><code>get</code></summary>
17
30
 
18
- _Documentation under progress._
31
+ Gets the value from a segment.
32
+
33
+ | Parameter | Type | Requirement |
34
+ | :---------------- | :------: | :----------: |
35
+ | field | `string` | **Required** |
36
+ | repeatingIndex | `number` | Default: 0 |
37
+ | subComponentIndex | `number` | Default: 0 |
38
+
39
+ Return: `string` | `null`
40
+
41
+ ```typescript
42
+ const zyxSegment = hl7.getSegment('ZYX');
43
+
44
+ zyxSegment?.get('ZYX.5.2', 1, 2);
45
+ ```
46
+
47
+ ### Examples
48
+
49
+ ```
50
+ ZYX|1|A|B|C|Repeat1~Component1^Component2~SubComp1&SubComp2^Component2~Repeat3
51
+ ```
52
+
53
+ ```typescript
54
+ // Get entire segment
55
+ zyxSegment.get('ZYX'); // ZYX|1|A|B|C|Repeat1~Component1^Component2~SubComp1&SubComp2^Component2~Repeat3
56
+
57
+ // Get repeating fields
58
+ zyxSegment.get('ZYX.5'); // Repeat1
59
+ zyxSegment.get('ZYX.5', 2); // SubComp1&SubComp2^Component2
60
+ zyxSegment.get('ZYX.5', -1); // Repeat1~Component1^Component2~SubComp1&SubComp2^Component2~Repeat3
61
+
62
+ // Get component
63
+ zyxSegment.get('ZYX.5.1', 1); // Component1
64
+
65
+ // Get subcomponent
66
+ zyxSegment.get('ZYX.5.1', 2); // SubComp1
67
+ zyxSegment.get('ZYX.5.1', 2, 1); // SubComp2
68
+ zyxSegment.get('ZYX.5.1', 2, -1); // SubComp1&SubComp2
69
+ ```
19
70
 
20
71
  </details>
21
72
 
22
73
  <details id="set">
23
74
  <summary><code>set</code></summary>
24
75
 
25
- _Documentation under progress._
76
+ Sets the value of on a segment.
77
+
78
+ | Parameter | Type | Requirement |
79
+ | :---------------- | :------: | :----------: |
80
+ | field | `string` | **Required** |
81
+ | value | `string` | **Required** |
82
+ | repeatingIndex | `number` | Default: 0 |
83
+ | subComponentIndex | `number` | Default: 0 |
84
+
85
+ ```typescript
86
+ const zyxSegment = hl7.getSegment('ZYX');
87
+
88
+ zyxSegment?.set('ZYX.5.2', 'ABCD', 1, 2); // ZYX|||||~^&&ABCD
89
+ ```
26
90
 
27
91
  </details>
28
92
 
29
93
  <details id="getSegment">
30
94
  <summary><code>getSegment</code></summary>
31
95
 
32
- _Documentation under progress._
96
+ Returns the first Segment matching the _type_ param or else null.
97
+
98
+ | Parameter | Type | Requirement |
99
+ | :-------- | :------: | :----------: |
100
+ | type | `string` | **Required** |
101
+
102
+ Return: `Segment` | `null`
103
+
104
+ ```typescript
105
+ const pidSegment = hl7.getSegment('PID');
106
+
107
+ pidSegment?.set('PID.5', 'PAT_NAME');
108
+ ```
33
109
 
34
110
  </details>
35
111
 
36
112
  <details id="getSegments">
37
113
  <summary><code>getSegments</code></summary>
38
114
 
39
- _Documentation under progress._
115
+ Returns an array of Segments matching the _type_ parameter, if provided; otherwise, returns an array of all Segments.
116
+
117
+ | Parameter | Type | Requirement |
118
+ | :-------- | :------: | :---------: |
119
+ | type | `string` | Optional |
120
+
121
+ Return: `Segment[]`
122
+
123
+ ```typescript
124
+ const obrSegments = hl7.getSegments('OBX');
125
+
126
+ for (const obrSegment of obrSegments) {
127
+ obrSegment.get('OBR.4');
128
+ }
129
+ ```
40
130
 
41
131
  </details>
42
132
 
43
133
  <details id="getSegmentsAfter">
44
134
  <summary><code>getSegmentsAfter</code></summary>
45
135
 
46
- _Documentation under progress._
136
+ Returns an array of Segments matching the _type_, starting from the _startSegment_ until encountering a segment listed in _stopSegmentType_.
137
+ Setting _consecutive_ as `true` will return first set consecutive of matching Segments.
138
+
139
+ | Parameter | Type | Requirement |
140
+ | :-------------- | :--------: | :------------: |
141
+ | startSegment | `Segment` | **Required** |
142
+ | type | `string` | **Required** |
143
+ | stopSegmentType | `string[]` | Optional |
144
+ | consecutive | `boolean` | Default: false |
145
+
146
+ Return: `Segment[]`
147
+
148
+ ```typescript
149
+ const obrSegment = hl7.getSegment('OBX');
150
+
151
+ const obxAfterObr = hl7.getSegmentsAfter(obrSegment!, 'OBX', ['OBR']);
152
+ ```
47
153
 
48
154
  </details>
49
155
 
50
156
  <details id="createSegment">
51
157
  <summary><code>createSegment</code></summary>
52
158
 
53
- _Documentation under progress._
159
+ Created a new segment of given _type_ and appends it at the end of existing segments.
160
+
161
+ | Parameter | Type | Requirement |
162
+ | :-------- | :------: | :----------: |
163
+ | type | `string` | **Required** |
164
+
165
+ Return: `Segment`
166
+
167
+ ```typescript
168
+ const nteSegment = hl7.createSegment('NTE');
169
+ ```
54
170
 
55
171
  </details>
56
172
 
57
173
  <details id="createSegmentAfter">
58
174
  <summary><code>createSegmentAfter</code></summary>
59
175
 
60
- _Documentation under progress._
176
+ Created a new segment of given _type_ and inserts it after _targetSegment_ segment.
177
+
178
+ | Parameter | Type | Requirement |
179
+ | :------------ | :-------: | :----------: |
180
+ | type | `string` | **Required** |
181
+ | targetSegment | `Segment` | **Required** |
182
+
183
+ Return: `Segment`
184
+
185
+ ```typescript
186
+ for (const obxSegment of hl7.getSegments('OBX')) {
187
+ const nteSegment = hl7.createSegmentAfter('NTE', obxSegment);
188
+
189
+ nteSegment.set('NTE.3', 'Notes');
190
+ }
191
+ ```
61
192
 
62
193
  </details>
63
194
 
64
195
  <details id="createSegmentBefore">
65
196
  <summary><code>createSegmentBefore</code></summary>
66
197
 
67
- _Documentation under progress._
198
+ Created a new segment of given _type_ and inserts it before _targetSegment_ segment.
199
+
200
+ | Parameter | Type | Requirement |
201
+ | :------------ | :-------: | :----------: |
202
+ | type | `string` | **Required** |
203
+ | targetSegment | `Segment` | **Required** |
204
+
205
+ Return: `Segment`
206
+
207
+ ```typescript
208
+ for (const obxSegment of hl7.getSegments('OBX')) {
209
+ const nteSegment = hl7.createSegmentBefore('NTE', obxSegment);
210
+
211
+ nteSegment.set('NTE.3', 'Notes');
212
+ }
213
+ ```
68
214
 
69
215
  </details>
70
216
 
71
217
  <details id="deleteSegment">
72
218
  <summary><code>deleteSegment</code></summary>
73
219
 
74
- _Documentation under progress._
220
+ Deletes an existing _segment_ if found.
221
+
222
+ | Parameter | Type | Requirement |
223
+ | :-------- | :-------: | :----------: |
224
+ | segment | `Segment` | **Required** |
225
+
226
+ ```typescript
227
+ const nteSegment = hl7.getSegment('NTE');
228
+
229
+ if (nteSegment) hl7.deleteSegment(nteSegment);
230
+ ```
75
231
 
76
232
  </details>
77
233
 
78
234
  <details id="deleteSegments">
79
235
  <summary><code>deleteSegments</code></summary>
80
236
 
81
- _Documentation under progress._
237
+ Deletes all existing _segments_ if found.
238
+
239
+ | Parameter | Type | Requirement |
240
+ | :-------- | :---------: | :----------: |
241
+ | segments | `Segment[]` | **Required** |
242
+
243
+ ```typescript
244
+ const nteSegments = hl7.getSegments('NTE');
245
+
246
+ hl7.deleteSegments(nteSegments);
247
+ ```
82
248
 
83
249
  </details>
84
250
 
85
251
  <details id="moveSegmentAfter">
86
252
  <summary><code>moveSegmentAfter</code></summary>
87
253
 
88
- _Documentation under progress._
254
+ Moves _segment_ after _targetSegment_.
255
+
256
+ | Parameter | Type | Requirement |
257
+ | :------------ | :-----: | :----------: |
258
+ | segment | Segment | **Required** |
259
+ | targetSegment | Segment | **Required** |
89
260
 
90
261
  </details>
91
262
 
92
263
  <details id="moveSegmentBefore">
93
264
  <summary><code>moveSegmentBefore</code></summary>
94
265
 
95
- _Documentation under progress._
266
+ Moves _segment_ before _targetSegment_.
267
+
268
+ | Parameter | Type | Requirement |
269
+ | :------------ | :-----: | :----------: |
270
+ | segment | Segment | **Required** |
271
+ | targetSegment | Segment | **Required** |
96
272
 
97
273
  </details>
98
274
 
99
275
  <details id="reindexSegments">
100
276
  <summary><code>reindexSegments</code></summary>
101
277
 
102
- _Documentation under progress._
278
+ Reindexes segments based on _resetRules_.
279
+
280
+ | Parameter | Type | Requirement |
281
+ | :--------- | :----: | :------------: |
282
+ | resetRules | object | **Required** |
283
+ | startIndex | number | Default: 1 |
284
+ | field | string | Default: '1.1' |
285
+
286
+ **resetRule**
287
+
288
+ An object where each **key** is a **segment type** and its **value** is an array of **segment types**.
289
+ The index of segment types specified in the keys will be set, and it will reset based on the segment types listed in its object value array.
290
+
291
+ **field**
292
+ Segment field where index will be set. Defaults to '1.1'.
293
+
294
+ Example:
295
+
296
+ ```typescript
297
+ hl7.reindexSegments({ OBR: [], OBX: ['OBR'], NTE: ['OBR', 'OBX'] });
298
+ ```
299
+
300
+ Here,
301
+
302
+ - NTE segments will have index restarting from 1 after each OBR or OBX segment is encountered.
303
+ - OBR segments will have index starting from one and incrementing since no reset segments were provided.
304
+
305
+ > _Note:_ `reindexSegments` sets the segment index value. This doesn't move the segments by itself.
103
306
 
104
307
  </details>
105
308
 
309
+ <details id="transform">
310
+ <summary><code>transform</code> 💀 </summary>
311
+
312
+ > ⚠️ **Deprecated**: This method is triggered internally and doesn't need to be invoked manually.
313
+
314
+ Transforms the raw HL7 message suitable for manipulation and building.
315
+
316
+ ```typescript
317
+ hl7.transform(); // depricated
318
+ ```
319
+
320
+ </details>
321
+
322
+ ---
323
+
106
324
  ### Attribution
107
325
 
108
326
  This project includes code inspired from [hl7-standard](https://github.com/ironbridgecorp/hl7-standard), licensed under the Apache License 2.0.