@pritiranjan/hl7v2 0.1.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/LICENSE +21 -0
- package/README.md +434 -0
- package/dist/chunk-Q6NISXHR.js +130 -0
- package/dist/chunk-Q6NISXHR.js.map +1 -0
- package/dist/index.cjs +344 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +309 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.js +200 -0
- package/dist/index.js.map +1 -0
- package/dist/schema-qr-scwmL.d.cts +106 -0
- package/dist/schema-qr-scwmL.d.ts +106 -0
- package/dist/segments/index.cjs +636 -0
- package/dist/segments/index.cjs.map +1 -0
- package/dist/segments/index.d.cts +457 -0
- package/dist/segments/index.d.ts +457 -0
- package/dist/segments/index.js +532 -0
- package/dist/segments/index.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { decodeEscapes, parseHL7DateTime } from '../chunk-Q6NISXHR.js';
|
|
2
|
+
|
|
3
|
+
// src/segments/base.ts
|
|
4
|
+
var TypedSegment = class {
|
|
5
|
+
constructor(seg, enc) {
|
|
6
|
+
this.seg = seg;
|
|
7
|
+
this.enc = enc;
|
|
8
|
+
}
|
|
9
|
+
/** The raw underlying {@link HL7Segment}. */
|
|
10
|
+
get raw() {
|
|
11
|
+
return this.seg;
|
|
12
|
+
}
|
|
13
|
+
/** Return the raw field structure at the given 1-based field number. */
|
|
14
|
+
field(num) {
|
|
15
|
+
return this.seg.fields[num - 1];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extract a scalar string value from the segment.
|
|
19
|
+
* All arguments are 1-based. Missing elements return `''`.
|
|
20
|
+
* Escape sequences are decoded automatically.
|
|
21
|
+
*/
|
|
22
|
+
str(fieldNum, component = 1, subComponent = 1, repetition = 1) {
|
|
23
|
+
const f = this.field(fieldNum);
|
|
24
|
+
if (!f) return "";
|
|
25
|
+
const raw = f[repetition - 1]?.[component - 1]?.[subComponent - 1] ?? "";
|
|
26
|
+
return decodeEscapes(raw, this.enc);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extract a string value from the segment without escape decoding.
|
|
30
|
+
* Useful when you need to preserve the raw HL7 encoding.
|
|
31
|
+
*/
|
|
32
|
+
rawStr(fieldNum, component = 1, subComponent = 1, repetition = 1) {
|
|
33
|
+
const f = this.field(fieldNum);
|
|
34
|
+
if (!f) return "";
|
|
35
|
+
return f[repetition - 1]?.[component - 1]?.[subComponent - 1] ?? "";
|
|
36
|
+
}
|
|
37
|
+
/** Extract a Date from an HL7 date/time field. Returns `undefined` if empty. */
|
|
38
|
+
date(fieldNum, component = 1) {
|
|
39
|
+
const raw = this.rawStr(fieldNum, component);
|
|
40
|
+
if (!raw) return void 0;
|
|
41
|
+
try {
|
|
42
|
+
return parseHL7DateTime(raw);
|
|
43
|
+
} catch {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Extract a numeric value from a field. Returns `undefined` if empty or non-numeric. */
|
|
48
|
+
num(fieldNum, component = 1) {
|
|
49
|
+
const raw = this.str(fieldNum, component);
|
|
50
|
+
if (!raw) return void 0;
|
|
51
|
+
const n = parseFloat(raw);
|
|
52
|
+
return isNaN(n) ? void 0 : n;
|
|
53
|
+
}
|
|
54
|
+
/** Return all repetitions of a field as an array of first-component strings. */
|
|
55
|
+
repetitions(fieldNum, component = 1) {
|
|
56
|
+
const f = this.field(fieldNum);
|
|
57
|
+
if (!f) return [];
|
|
58
|
+
return f.map((rep) => {
|
|
59
|
+
const raw = rep[component - 1]?.[0] ?? "";
|
|
60
|
+
return decodeEscapes(raw, this.enc);
|
|
61
|
+
}).filter((v) => v !== "");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/segments/msh.ts
|
|
66
|
+
var MSH = class extends TypedSegment {
|
|
67
|
+
constructor(seg, enc) {
|
|
68
|
+
super(seg, enc);
|
|
69
|
+
}
|
|
70
|
+
/** MSH.3 — Sending Application */
|
|
71
|
+
sendingApplication() {
|
|
72
|
+
return this.str(3);
|
|
73
|
+
}
|
|
74
|
+
/** MSH.4 — Sending Facility */
|
|
75
|
+
sendingFacility() {
|
|
76
|
+
return this.str(4);
|
|
77
|
+
}
|
|
78
|
+
/** MSH.5 — Receiving Application */
|
|
79
|
+
receivingApplication() {
|
|
80
|
+
return this.str(5);
|
|
81
|
+
}
|
|
82
|
+
/** MSH.6 — Receiving Facility */
|
|
83
|
+
receivingFacility() {
|
|
84
|
+
return this.str(6);
|
|
85
|
+
}
|
|
86
|
+
/** MSH.7 — Date/Time of Message */
|
|
87
|
+
dateTimeOfMessage() {
|
|
88
|
+
return this.date(7);
|
|
89
|
+
}
|
|
90
|
+
/** MSH.9 — Message Type (e.g., `{ type: 'ADT', event: 'A01', structure: 'ADT_A01' }`). */
|
|
91
|
+
messageType() {
|
|
92
|
+
const field = this.field(9);
|
|
93
|
+
const firstRep = field?.[0] ?? [];
|
|
94
|
+
const struct = firstRep[2]?.[0];
|
|
95
|
+
return {
|
|
96
|
+
type: firstRep[0]?.[0] ?? "",
|
|
97
|
+
event: firstRep[1]?.[0] ?? "",
|
|
98
|
+
structure: struct !== void 0 && struct !== "" ? struct : void 0
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** MSH.10 — Message Control ID (used for ACK correlation). */
|
|
102
|
+
messageControlId() {
|
|
103
|
+
return this.str(10);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* MSH.11 — Processing ID.
|
|
107
|
+
* `'P'` = Production, `'D'` = Debugging, `'T'` = Training.
|
|
108
|
+
*/
|
|
109
|
+
processingId() {
|
|
110
|
+
return this.str(11);
|
|
111
|
+
}
|
|
112
|
+
/** MSH.12 — HL7 version (e.g., `'2.5.1'`). */
|
|
113
|
+
version() {
|
|
114
|
+
return this.str(12);
|
|
115
|
+
}
|
|
116
|
+
/** MSH.15 — Accept Acknowledgement Type. */
|
|
117
|
+
acceptAcknowledgementType() {
|
|
118
|
+
return this.str(15);
|
|
119
|
+
}
|
|
120
|
+
/** MSH.16 — Application Acknowledgement Type. */
|
|
121
|
+
applicationAcknowledgementType() {
|
|
122
|
+
return this.str(16);
|
|
123
|
+
}
|
|
124
|
+
/** MSH.17 — Country Code (ISO 3166). */
|
|
125
|
+
countryCode() {
|
|
126
|
+
return this.str(17);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/segments/pid.ts
|
|
131
|
+
var PID = class extends TypedSegment {
|
|
132
|
+
constructor(seg, enc) {
|
|
133
|
+
super(seg, enc);
|
|
134
|
+
}
|
|
135
|
+
/** PID.1 — Set ID (1-based sequence number within the message). */
|
|
136
|
+
setId() {
|
|
137
|
+
return this.num(1);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* PID.3 — Patient Identifier List.
|
|
141
|
+
*
|
|
142
|
+
* Returns all patient identifiers (MRN, SSN, national ID, etc.).
|
|
143
|
+
* Each identifier has its own type code and assigning authority.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* pid.patientIdentifiers()
|
|
147
|
+
* // [{ id: 'MRN123', assigningAuthority: 'HOSPITAL', identifierTypeCode: 'MR' }]
|
|
148
|
+
*/
|
|
149
|
+
patientIdentifiers() {
|
|
150
|
+
const field = this.field(3);
|
|
151
|
+
if (!field) return [];
|
|
152
|
+
return field.map((rep) => ({
|
|
153
|
+
id: rep[0]?.[0] ?? "",
|
|
154
|
+
checkDigit: rep[1]?.[0] ?? "",
|
|
155
|
+
assigningAuthority: rep[3]?.[0] ?? "",
|
|
156
|
+
identifierTypeCode: rep[4]?.[0] ?? ""
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* PID.3 — Primary patient identifier (first in the list).
|
|
161
|
+
* Returns the raw identifier string (e.g., `'MRN123'`).
|
|
162
|
+
*/
|
|
163
|
+
patientId() {
|
|
164
|
+
return this.str(3, 1);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* PID.5 — Patient Name (first/primary name).
|
|
168
|
+
*
|
|
169
|
+
* Patient names follow the XPN (Extended Person Name) data type.
|
|
170
|
+
* Components: family ^ given ^ middle ^ suffix ^ prefix ^ degree
|
|
171
|
+
*/
|
|
172
|
+
patientName() {
|
|
173
|
+
return {
|
|
174
|
+
family: this.str(5, 1),
|
|
175
|
+
given: this.str(5, 2),
|
|
176
|
+
middle: this.str(5, 3),
|
|
177
|
+
suffix: this.str(5, 4),
|
|
178
|
+
prefix: this.str(5, 5),
|
|
179
|
+
degree: this.str(5, 6)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* PID.5 — All patient names (legal, alias, display, etc.).
|
|
184
|
+
* Most messages contain a single name; some include aliases or prior names.
|
|
185
|
+
*/
|
|
186
|
+
allPatientNames() {
|
|
187
|
+
const field = this.field(5);
|
|
188
|
+
if (!field) return [];
|
|
189
|
+
return field.map((rep) => ({
|
|
190
|
+
family: rep[0]?.[0] ?? "",
|
|
191
|
+
given: rep[1]?.[0] ?? "",
|
|
192
|
+
middle: rep[2]?.[0] ?? "",
|
|
193
|
+
suffix: rep[3]?.[0] ?? "",
|
|
194
|
+
prefix: rep[4]?.[0] ?? "",
|
|
195
|
+
degree: rep[5]?.[0] ?? ""
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* PID.7 — Date/Time of Birth.
|
|
200
|
+
* Returns `undefined` if absent or unparseable.
|
|
201
|
+
*/
|
|
202
|
+
dateOfBirth() {
|
|
203
|
+
return this.date(7);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* PID.8 — Administrative Sex (HL7 table 0001).
|
|
207
|
+
* `'M'` Male · `'F'` Female · `'O'` Other · `'U'` Unknown
|
|
208
|
+
* `'A'` Ambiguous · `'N'` Not applicable · `'C'` Complex
|
|
209
|
+
*/
|
|
210
|
+
sex() {
|
|
211
|
+
return this.str(8);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* PID.10 — Race (HL7 table 0005, CWE data type).
|
|
215
|
+
* Returns the race code (first component).
|
|
216
|
+
*/
|
|
217
|
+
race() {
|
|
218
|
+
return this.str(10, 1);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* PID.11 — Patient Address (first address).
|
|
222
|
+
* Addresses follow the XAD (Extended Address) data type.
|
|
223
|
+
*/
|
|
224
|
+
address() {
|
|
225
|
+
return {
|
|
226
|
+
streetAddress: this.str(11, 1),
|
|
227
|
+
otherDesignation: this.str(11, 2),
|
|
228
|
+
city: this.str(11, 3),
|
|
229
|
+
state: this.str(11, 4),
|
|
230
|
+
postalCode: this.str(11, 5),
|
|
231
|
+
country: this.str(11, 6),
|
|
232
|
+
addressType: this.str(11, 7)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/** PID.13 — Phone Number - Home (first number, XTN data type). */
|
|
236
|
+
homePhone() {
|
|
237
|
+
return this.str(13, 1);
|
|
238
|
+
}
|
|
239
|
+
/** PID.14 — Phone Number - Business (first number, XTN data type). */
|
|
240
|
+
workPhone() {
|
|
241
|
+
return this.str(14, 1);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* PID.15 — Primary Language (CE data type).
|
|
245
|
+
* Returns the language code (e.g., `'ENG'`, `'SPA'`).
|
|
246
|
+
*/
|
|
247
|
+
primaryLanguage() {
|
|
248
|
+
return this.str(15, 1);
|
|
249
|
+
}
|
|
250
|
+
/** PID.16 — Marital Status (HL7 table 0002). */
|
|
251
|
+
maritalStatus() {
|
|
252
|
+
return this.str(16, 1);
|
|
253
|
+
}
|
|
254
|
+
/** PID.17 — Religion (HL7 table 0006). */
|
|
255
|
+
religion() {
|
|
256
|
+
return this.str(17, 1);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* PID.18 — Patient Account Number.
|
|
260
|
+
* The billing/visit account number (distinct from the medical record number).
|
|
261
|
+
*/
|
|
262
|
+
accountNumber() {
|
|
263
|
+
return this.str(18, 1);
|
|
264
|
+
}
|
|
265
|
+
/** PID.19 — SSN Number - Patient (US Social Security Number). */
|
|
266
|
+
ssn() {
|
|
267
|
+
return this.str(19);
|
|
268
|
+
}
|
|
269
|
+
/** PID.22 — Ethnic Group (HL7 table 0189, CWE data type). */
|
|
270
|
+
ethnicGroup() {
|
|
271
|
+
return this.str(22, 1);
|
|
272
|
+
}
|
|
273
|
+
/** PID.29 — Patient Death Date and Time. `undefined` if patient is not deceased. */
|
|
274
|
+
deathDateTime() {
|
|
275
|
+
return this.date(29);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* PID.30 — Patient Death Indicator.
|
|
279
|
+
* `'Y'` = deceased, `'N'` = not deceased.
|
|
280
|
+
*/
|
|
281
|
+
deathIndicator() {
|
|
282
|
+
return this.str(30);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/segments/obx.ts
|
|
287
|
+
var OBX = class extends TypedSegment {
|
|
288
|
+
constructor(seg, enc) {
|
|
289
|
+
super(seg, enc);
|
|
290
|
+
}
|
|
291
|
+
/** OBX.1 — Set ID (sequence number within the message, 1-based). */
|
|
292
|
+
setId() {
|
|
293
|
+
return this.num(1);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* OBX.2 — Value Type.
|
|
297
|
+
* Indicates the data type of the observation value in OBX.5.
|
|
298
|
+
* Common values: `'NM'` (numeric), `'ST'` (string), `'CWE'` (coded).
|
|
299
|
+
*/
|
|
300
|
+
valueType() {
|
|
301
|
+
return this.str(2);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* OBX.3 — Observation Identifier.
|
|
305
|
+
* Typically a LOINC code identifying what was measured.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* obx.observationIdentifier()
|
|
309
|
+
* // { code: '718-7', description: 'Hemoglobin [Mass/volume] in Blood', codingSystem: 'LN' }
|
|
310
|
+
*/
|
|
311
|
+
observationIdentifier() {
|
|
312
|
+
return {
|
|
313
|
+
code: this.str(3, 1),
|
|
314
|
+
description: this.str(3, 2),
|
|
315
|
+
codingSystem: this.str(3, 3)
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/** OBX.4 — Observation Sub-ID (groups related OBX segments). */
|
|
319
|
+
observationSubId() {
|
|
320
|
+
return this.str(4);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* OBX.5 — Observation Value (raw string).
|
|
324
|
+
*
|
|
325
|
+
* The interpretation depends on OBX.2 (value type).
|
|
326
|
+
* Use {@link numericValue} for `NM`, {@link codedValue} for `CWE`/`CE`.
|
|
327
|
+
*/
|
|
328
|
+
observationValue() {
|
|
329
|
+
return this.str(5);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* OBX.5 — Observation value interpreted as a number.
|
|
333
|
+
* Returns `undefined` if the value type is not `NM` or the value is absent.
|
|
334
|
+
*
|
|
335
|
+
* For structured numerics (SN type like `'>10.5'`), use {@link observationValue}.
|
|
336
|
+
*/
|
|
337
|
+
numericValue() {
|
|
338
|
+
if (this.str(2) !== "NM") return void 0;
|
|
339
|
+
return this.num(5);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* OBX.5 — Observation value as a coded element (CWE/CE value type).
|
|
343
|
+
* Returns `{ code, description, codingSystem }`.
|
|
344
|
+
*/
|
|
345
|
+
codedValue() {
|
|
346
|
+
return {
|
|
347
|
+
code: this.str(5, 1),
|
|
348
|
+
description: this.str(5, 2),
|
|
349
|
+
codingSystem: this.str(5, 3)
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* OBX.6 — Units (CWE data type).
|
|
354
|
+
* Returns the unit code (e.g., `'g/dL'`, `'10*3/uL'`, `'mmHg'`).
|
|
355
|
+
*/
|
|
356
|
+
units() {
|
|
357
|
+
return this.str(6, 1);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* OBX.7 — References Range.
|
|
361
|
+
* The normal range as a string (e.g., `'3.5-5.0'`, `'<200'`).
|
|
362
|
+
*/
|
|
363
|
+
referenceRange() {
|
|
364
|
+
return this.str(7);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* OBX.8 — Interpretation Codes (formerly Abnormal Flags).
|
|
368
|
+
* Returns all flags for this result (a field can have multiple repetitions).
|
|
369
|
+
*
|
|
370
|
+
* Common values: `'H'` high, `'L'` low, `'HH'` critical high, `'LL'` critical low,
|
|
371
|
+
* `'N'` normal, `'A'` abnormal, `'POS'` positive, `'NEG'` negative.
|
|
372
|
+
*/
|
|
373
|
+
abnormalFlags() {
|
|
374
|
+
return this.repetitions(8);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* OBX.8 — Primary interpretation code (first flag).
|
|
378
|
+
* Returns `''` if the result has no flags (i.e., it is normal / in-range).
|
|
379
|
+
*/
|
|
380
|
+
primaryAbnormalFlag() {
|
|
381
|
+
return this.str(8);
|
|
382
|
+
}
|
|
383
|
+
/** OBX.11 — Observation Result Status (HL7 table 0085). */
|
|
384
|
+
resultStatus() {
|
|
385
|
+
return this.str(11);
|
|
386
|
+
}
|
|
387
|
+
/** OBX.14 — Date/Time of Observation. */
|
|
388
|
+
observationDateTime() {
|
|
389
|
+
return this.date(14);
|
|
390
|
+
}
|
|
391
|
+
/** OBX.15 — Producer's ID (the lab or device that produced the result). */
|
|
392
|
+
producerId() {
|
|
393
|
+
return this.str(15, 1);
|
|
394
|
+
}
|
|
395
|
+
/** OBX.16 — Responsible Observer (clinician who verified the result). */
|
|
396
|
+
responsibleObserver() {
|
|
397
|
+
return this.str(16, 1);
|
|
398
|
+
}
|
|
399
|
+
/** OBX.19 — Date/Time of Analysis. */
|
|
400
|
+
analysisDateTime() {
|
|
401
|
+
return this.date(19);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Convenience: return `true` if this result has a critical abnormal flag
|
|
405
|
+
* (`'HH'` or `'LL'`).
|
|
406
|
+
*/
|
|
407
|
+
isCritical() {
|
|
408
|
+
const flags = this.abnormalFlags();
|
|
409
|
+
return flags.includes("HH") || flags.includes("LL");
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Convenience: return `true` if the result is finalised (`resultStatus() === 'F'`).
|
|
413
|
+
*/
|
|
414
|
+
isFinal() {
|
|
415
|
+
return this.str(11) === "F";
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// src/segments/pv1.ts
|
|
420
|
+
var PV1 = class extends TypedSegment {
|
|
421
|
+
constructor(seg, enc) {
|
|
422
|
+
super(seg, enc);
|
|
423
|
+
}
|
|
424
|
+
/** PV1.1 — Set ID. */
|
|
425
|
+
setId() {
|
|
426
|
+
return this.num(1);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* PV1.2 — Patient Class (HL7 table 0004).
|
|
430
|
+
* `'I'` Inpatient · `'O'` Outpatient · `'E'` Emergency · `'P'` Preadmit
|
|
431
|
+
*/
|
|
432
|
+
patientClass() {
|
|
433
|
+
return this.str(2);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* PV1.3 — Assigned Patient Location.
|
|
437
|
+
* The bed the patient is currently assigned to.
|
|
438
|
+
*/
|
|
439
|
+
assignedLocation() {
|
|
440
|
+
return {
|
|
441
|
+
pointOfCare: this.str(3, 1),
|
|
442
|
+
room: this.str(3, 2),
|
|
443
|
+
bed: this.str(3, 3),
|
|
444
|
+
facility: this.str(3, 4),
|
|
445
|
+
buildingCode: this.str(3, 7),
|
|
446
|
+
floor: this.str(3, 8)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
/** PV1.4 — Admission Type (e.g., `'A'` = accident, `'E'` = emergency). */
|
|
450
|
+
admissionType() {
|
|
451
|
+
return this.str(4);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* PV1.7 — Attending Doctor.
|
|
455
|
+
* The physician primarily responsible for the patient's care.
|
|
456
|
+
*/
|
|
457
|
+
attendingDoctor() {
|
|
458
|
+
return {
|
|
459
|
+
id: this.str(7, 1),
|
|
460
|
+
family: this.str(7, 2),
|
|
461
|
+
given: this.str(7, 3),
|
|
462
|
+
middle: this.str(7, 4),
|
|
463
|
+
credential: this.str(7, 7)
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* PV1.8 — Referring Doctor.
|
|
468
|
+
* The physician who referred the patient.
|
|
469
|
+
*/
|
|
470
|
+
referringDoctor() {
|
|
471
|
+
return {
|
|
472
|
+
id: this.str(8, 1),
|
|
473
|
+
family: this.str(8, 2),
|
|
474
|
+
given: this.str(8, 3),
|
|
475
|
+
middle: this.str(8, 4),
|
|
476
|
+
credential: this.str(8, 7)
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* PV1.9 — Consulting Doctor.
|
|
481
|
+
* Returns all consulting doctors (field can repeat).
|
|
482
|
+
*/
|
|
483
|
+
consultingDoctors() {
|
|
484
|
+
const field = this.field(9);
|
|
485
|
+
if (!field) return [];
|
|
486
|
+
return field.map((rep) => ({
|
|
487
|
+
id: rep[0]?.[0] ?? "",
|
|
488
|
+
family: rep[1]?.[0] ?? "",
|
|
489
|
+
given: rep[2]?.[0] ?? "",
|
|
490
|
+
middle: rep[3]?.[0] ?? "",
|
|
491
|
+
credential: rep[7]?.[0] ?? ""
|
|
492
|
+
}));
|
|
493
|
+
}
|
|
494
|
+
/** PV1.10 — Hospital Service (e.g., `'MED'`, `'SUR'`, `'CAR'`). */
|
|
495
|
+
hospitalService() {
|
|
496
|
+
return this.str(10);
|
|
497
|
+
}
|
|
498
|
+
/** PV1.14 — Admit Source (HL7 table 0023). */
|
|
499
|
+
admitSource() {
|
|
500
|
+
return this.str(14);
|
|
501
|
+
}
|
|
502
|
+
/** PV1.18 — Patient Type. */
|
|
503
|
+
patientType() {
|
|
504
|
+
return this.str(18);
|
|
505
|
+
}
|
|
506
|
+
/** PV1.19 — Visit Number (account number for this specific visit). */
|
|
507
|
+
visitNumber() {
|
|
508
|
+
return this.str(19, 1);
|
|
509
|
+
}
|
|
510
|
+
/** PV1.36 — Discharge Disposition (HL7 table 0112). */
|
|
511
|
+
dischargeDisposition() {
|
|
512
|
+
return this.str(36);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* PV1.44 — Admit Date/Time.
|
|
516
|
+
* When the patient was admitted to this care setting.
|
|
517
|
+
*/
|
|
518
|
+
admitDateTime() {
|
|
519
|
+
return this.date(44);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* PV1.45 — Discharge Date/Time.
|
|
523
|
+
* `undefined` if the patient has not yet been discharged.
|
|
524
|
+
*/
|
|
525
|
+
dischargeDateTime() {
|
|
526
|
+
return this.date(45);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
export { MSH, OBX, PID, PV1, TypedSegment };
|
|
531
|
+
//# sourceMappingURL=index.js.map
|
|
532
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/segments/base.ts","../../src/segments/msh.ts","../../src/segments/pid.ts","../../src/segments/obx.ts","../../src/segments/pv1.ts"],"names":[],"mappings":";;;AAsBO,IAAe,eAAf,MAA4B;AAAA,EACjC,WAAA,CACqB,KACA,GAAA,EACnB;AAFmB,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AACA,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA;AAAA,EAClB;AAAA;AAAA,EAGH,IAAI,GAAA,GAAkB;AACpB,IAAA,OAAO,IAAA,CAAK,GAAA;AAAA,EACd;AAAA;AAAA,EAGU,MAAM,GAAA,EAAmC;AACjD,IAAA,OAAO,IAAA,CAAK,GAAA,CAAI,MAAA,CAAO,GAAA,GAAM,CAAC,CAAA;AAAA,EAChC;AAAA;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BAAA,GAA+B;AAAE,IAAA,OAAO,IAAA,CAAK,IAAI,EAAE,CAAA;AAAA,EAAG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtD,aAAA,GAAkC;AAAE,IAAA,OAAO,IAAA,CAAK,KAAK,EAAE,CAAA;AAAA,EAAG;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1D,iBAAA,GAAsC;AAAE,IAAA,OAAO,IAAA,CAAK,KAAK,EAAE,CAAA;AAAA,EAAG;AAChE","file":"index.js","sourcesContent":["import { decodeEscapes } from '../escape.js';\nimport { parseHL7DateTime } from '../datetime.js';\nimport type { EncodingChars, HL7Field, HL7Segment } from '../schema.js';\n\n/**\n * Base class for typed HL7 v2 segment accessors.\n *\n * Typed segments wrap an {@link HL7Segment} and provide strongly-typed,\n * documented accessor methods for each field — eliminating the need to\n * remember field numbers or component positions.\n *\n * @example\n * import { PID } from 'hl7v2/segments';\n * import { parse, segment } from 'hl7v2';\n *\n * const msg = parse(rawString);\n * const pid = new PID(segment(msg, 'PID'), msg.encoding);\n *\n * pid.patientName() // { family: 'Doe', given: 'John', middle: 'A' }\n * pid.dateOfBirth() // Date | undefined\n * pid.sex() // 'M' | 'F' | 'O' | 'U' | undefined\n */\nexport abstract class TypedSegment {\n constructor(\n protected readonly seg: HL7Segment,\n protected readonly enc: EncodingChars,\n ) {}\n\n /** The raw underlying {@link HL7Segment}. */\n get raw(): HL7Segment {\n return this.seg;\n }\n\n /** Return the raw field structure at the given 1-based field number. */\n protected field(num: number): HL7Field | undefined {\n return this.seg.fields[num - 1];\n }\n\n /**\n * Extract a scalar string value from the segment.\n * All arguments are 1-based. Missing elements return `''`.\n * Escape sequences are decoded automatically.\n */\n protected str(\n fieldNum: number,\n component = 1,\n subComponent = 1,\n repetition = 1,\n ): string {\n const f = this.field(fieldNum);\n if (!f) return '';\n const raw = f[repetition - 1]?.[component - 1]?.[subComponent - 1] ?? '';\n return decodeEscapes(raw, this.enc);\n }\n\n /**\n * Extract a string value from the segment without escape decoding.\n * Useful when you need to preserve the raw HL7 encoding.\n */\n protected rawStr(\n fieldNum: number,\n component = 1,\n subComponent = 1,\n repetition = 1,\n ): string {\n const f = this.field(fieldNum);\n if (!f) return '';\n return f[repetition - 1]?.[component - 1]?.[subComponent - 1] ?? '';\n }\n\n /** Extract a Date from an HL7 date/time field. Returns `undefined` if empty. */\n protected date(fieldNum: number, component = 1): Date | undefined {\n const raw = this.rawStr(fieldNum, component);\n if (!raw) return undefined;\n try {\n return parseHL7DateTime(raw);\n } catch {\n return undefined;\n }\n }\n\n /** Extract a numeric value from a field. Returns `undefined` if empty or non-numeric. */\n protected num(fieldNum: number, component = 1): number | undefined {\n const raw = this.str(fieldNum, component);\n if (!raw) return undefined;\n const n = parseFloat(raw);\n return isNaN(n) ? undefined : n;\n }\n\n /** Return all repetitions of a field as an array of first-component strings. */\n protected repetitions(fieldNum: number, component = 1): string[] {\n const f = this.field(fieldNum);\n if (!f) return [];\n return f.map(rep => {\n const raw = rep[component - 1]?.[0] ?? '';\n return decodeEscapes(raw, this.enc);\n }).filter(v => v !== '');\n }\n}\n","import type { EncodingChars, HL7Segment, MessageType } from '../schema.js';\nimport { TypedSegment } from './base.js';\n\n/** Processing ID values defined in HL7 v2 table 0103. */\nexport type ProcessingId = 'P' | 'D' | 'T';\n\n/**\n * Typed accessor for the MSH (Message Header) segment.\n *\n * MSH is mandatory and always the first segment in any HL7 v2 message.\n * It identifies the message type, version, sender, receiver, and timestamp.\n *\n * @example\n * import { parse, segment } from 'hl7v2';\n * import { MSH } from 'hl7v2/segments';\n *\n * const msg = parse(raw);\n * const msh = new MSH(segment(msg, 'MSH'), msg.encoding);\n *\n * msh.sendingApplication() // 'HOSPITAL_ADT'\n * msh.messageType() // { type: 'ADT', event: 'A01', structure: 'ADT_A01' }\n * msh.messageControlId() // 'MSG000001'\n * msh.version() // '2.5.1'\n */\nexport class MSH extends TypedSegment {\n constructor(seg: HL7Segment, enc: EncodingChars) {\n super(seg, enc);\n }\n\n /** MSH.3 — Sending Application */\n sendingApplication(): string { return this.str(3); }\n\n /** MSH.4 — Sending Facility */\n sendingFacility(): string { return this.str(4); }\n\n /** MSH.5 — Receiving Application */\n receivingApplication(): string { return this.str(5); }\n\n /** MSH.6 — Receiving Facility */\n receivingFacility(): string { return this.str(6); }\n\n /** MSH.7 — Date/Time of Message */\n dateTimeOfMessage(): Date | undefined { return this.date(7); }\n\n /** MSH.9 — Message Type (e.g., `{ type: 'ADT', event: 'A01', structure: 'ADT_A01' }`). */\n messageType(): MessageType {\n const field = this.field(9);\n const firstRep = field?.[0] ?? [];\n const struct = firstRep[2]?.[0];\n return {\n type: firstRep[0]?.[0] ?? '',\n event: firstRep[1]?.[0] ?? '',\n structure: struct !== undefined && struct !== '' ? struct : undefined,\n };\n }\n\n /** MSH.10 — Message Control ID (used for ACK correlation). */\n messageControlId(): string { return this.str(10); }\n\n /**\n * MSH.11 — Processing ID.\n * `'P'` = Production, `'D'` = Debugging, `'T'` = Training.\n */\n processingId(): ProcessingId | string { return this.str(11); }\n\n /** MSH.12 — HL7 version (e.g., `'2.5.1'`). */\n version(): string { return this.str(12); }\n\n /** MSH.15 — Accept Acknowledgement Type. */\n acceptAcknowledgementType(): string { return this.str(15); }\n\n /** MSH.16 — Application Acknowledgement Type. */\n applicationAcknowledgementType(): string { return this.str(16); }\n\n /** MSH.17 — Country Code (ISO 3166). */\n countryCode(): string { return this.str(17); }\n}\n","import type { EncodingChars, HL7Segment } from '../schema.js';\nimport { TypedSegment } from './base.js';\n\n/** Administrative sex codes from HL7 v2 table 0001. */\nexport type AdministrativeSex = 'M' | 'F' | 'O' | 'U' | 'A' | 'N' | 'C';\n\n/** A structured patient name following HL7 XPN (Extended Person Name). */\nexport interface PersonName {\n /** Family (last) name. */\n family: string;\n /** Given (first) name. */\n given: string;\n /** Middle name or initial. */\n middle: string;\n /** Name suffix (e.g., `'JR'`, `'SR'`, `'III'`). */\n suffix: string;\n /** Name prefix (e.g., `'DR'`, `'MR'`, `'MS'`). */\n prefix: string;\n /** Degree (e.g., `'MD'`, `'PHD'`). */\n degree: string;\n}\n\n/** A structured address following HL7 XAD (Extended Address). */\nexport interface Address {\n streetAddress: string;\n otherDesignation: string;\n city: string;\n state: string;\n postalCode: string;\n country: string;\n addressType: string;\n}\n\n/** A patient identifier from PID.3 (Patient Identifier List). */\nexport interface PatientIdentifier {\n /** The identifier value (e.g., MRN, SSN). */\n id: string;\n /** Check digit. */\n checkDigit: string;\n /** Assigning authority (e.g., `'HOSPITAL'`). */\n assigningAuthority: string;\n /** Identifier type code (e.g., `'MR'` = Medical Record, `'PI'` = Patient Internal). */\n identifierTypeCode: string;\n}\n\n/**\n * Typed accessor for the PID (Patient Identification) segment.\n *\n * PID carries all core patient demographic information and appears in\n * virtually every HL7 v2 message type (ADT, ORU, ORM, SIU, etc.).\n *\n * @example\n * import { parse, segment } from 'hl7v2';\n * import { PID } from 'hl7v2/segments';\n *\n * const msg = parse(raw);\n * const pid = new PID(segment(msg, 'PID'), msg.encoding);\n *\n * pid.patientName() // { family: 'Doe', given: 'John', middle: 'A', ... }\n * pid.dateOfBirth() // Date | undefined\n * pid.sex() // 'M' | 'F' | ...\n * pid.patientIdentifiers() // PatientIdentifier[]\n */\nexport class PID extends TypedSegment {\n constructor(seg: HL7Segment, enc: EncodingChars) {\n super(seg, enc);\n }\n\n /** PID.1 — Set ID (1-based sequence number within the message). */\n setId(): number | undefined { return this.num(1); }\n\n /**\n * PID.3 — Patient Identifier List.\n *\n * Returns all patient identifiers (MRN, SSN, national ID, etc.).\n * Each identifier has its own type code and assigning authority.\n *\n * @example\n * pid.patientIdentifiers()\n * // [{ id: 'MRN123', assigningAuthority: 'HOSPITAL', identifierTypeCode: 'MR' }]\n */\n patientIdentifiers(): PatientIdentifier[] {\n const field = this.field(3);\n if (!field) return [];\n return field.map(rep => ({\n id: rep[0]?.[0] ?? '',\n checkDigit: rep[1]?.[0] ?? '',\n assigningAuthority: rep[3]?.[0] ?? '',\n identifierTypeCode: rep[4]?.[0] ?? '',\n }));\n }\n\n /**\n * PID.3 — Primary patient identifier (first in the list).\n * Returns the raw identifier string (e.g., `'MRN123'`).\n */\n patientId(): string { return this.str(3, 1); }\n\n /**\n * PID.5 — Patient Name (first/primary name).\n *\n * Patient names follow the XPN (Extended Person Name) data type.\n * Components: family ^ given ^ middle ^ suffix ^ prefix ^ degree\n */\n patientName(): PersonName {\n return {\n family: this.str(5, 1),\n given: this.str(5, 2),\n middle: this.str(5, 3),\n suffix: this.str(5, 4),\n prefix: this.str(5, 5),\n degree: this.str(5, 6),\n };\n }\n\n /**\n * PID.5 — All patient names (legal, alias, display, etc.).\n * Most messages contain a single name; some include aliases or prior names.\n */\n allPatientNames(): PersonName[] {\n const field = this.field(5);\n if (!field) return [];\n return field.map(rep => ({\n family: rep[0]?.[0] ?? '',\n given: rep[1]?.[0] ?? '',\n middle: rep[2]?.[0] ?? '',\n suffix: rep[3]?.[0] ?? '',\n prefix: rep[4]?.[0] ?? '',\n degree: rep[5]?.[0] ?? '',\n }));\n }\n\n /**\n * PID.7 — Date/Time of Birth.\n * Returns `undefined` if absent or unparseable.\n */\n dateOfBirth(): Date | undefined { return this.date(7); }\n\n /**\n * PID.8 — Administrative Sex (HL7 table 0001).\n * `'M'` Male · `'F'` Female · `'O'` Other · `'U'` Unknown\n * `'A'` Ambiguous · `'N'` Not applicable · `'C'` Complex\n */\n sex(): AdministrativeSex | string { return this.str(8); }\n\n /**\n * PID.10 — Race (HL7 table 0005, CWE data type).\n * Returns the race code (first component).\n */\n race(): string { return this.str(10, 1); }\n\n /**\n * PID.11 — Patient Address (first address).\n * Addresses follow the XAD (Extended Address) data type.\n */\n address(): Address {\n return {\n streetAddress: this.str(11, 1),\n otherDesignation: this.str(11, 2),\n city: this.str(11, 3),\n state: this.str(11, 4),\n postalCode: this.str(11, 5),\n country: this.str(11, 6),\n addressType: this.str(11, 7),\n };\n }\n\n /** PID.13 — Phone Number - Home (first number, XTN data type). */\n homePhone(): string { return this.str(13, 1); }\n\n /** PID.14 — Phone Number - Business (first number, XTN data type). */\n workPhone(): string { return this.str(14, 1); }\n\n /**\n * PID.15 — Primary Language (CE data type).\n * Returns the language code (e.g., `'ENG'`, `'SPA'`).\n */\n primaryLanguage(): string { return this.str(15, 1); }\n\n /** PID.16 — Marital Status (HL7 table 0002). */\n maritalStatus(): string { return this.str(16, 1); }\n\n /** PID.17 — Religion (HL7 table 0006). */\n religion(): string { return this.str(17, 1); }\n\n /**\n * PID.18 — Patient Account Number.\n * The billing/visit account number (distinct from the medical record number).\n */\n accountNumber(): string { return this.str(18, 1); }\n\n /** PID.19 — SSN Number - Patient (US Social Security Number). */\n ssn(): string { return this.str(19); }\n\n /** PID.22 — Ethnic Group (HL7 table 0189, CWE data type). */\n ethnicGroup(): string { return this.str(22, 1); }\n\n /** PID.29 — Patient Death Date and Time. `undefined` if patient is not deceased. */\n deathDateTime(): Date | undefined { return this.date(29); }\n\n /**\n * PID.30 — Patient Death Indicator.\n * `'Y'` = deceased, `'N'` = not deceased.\n */\n deathIndicator(): 'Y' | 'N' | string { return this.str(30); }\n}\n","import type { EncodingChars, HL7Segment } from '../schema.js';\nimport { TypedSegment } from './base.js';\n\n/** OBX.2 — Value type codes from HL7 v2 table 0125. */\nexport type ObservationValueType =\n | 'NM' // Numeric\n | 'ST' // String\n | 'TX' // Text\n | 'FT' // Formatted text\n | 'CWE' // Coded with Exceptions\n | 'CE' // Coded Element (deprecated in v2.7+)\n | 'DT' // Date\n | 'TM' // Time\n | 'TS' // Time Stamp (deprecated in v2.7+)\n | 'DTM' // Date/Time (v2.7+)\n | 'SN' // Structured Numeric\n | 'RP' // Reference Pointer (e.g., image URL)\n | 'ED' // Encapsulated Data\n | string;\n\n/** OBX.11 — Observation Result Status codes from HL7 v2 table 0085. */\nexport type ResultStatus =\n | 'F' // Final\n | 'P' // Preliminary\n | 'C' // Correction\n | 'X' // Result cannot be obtained\n | 'I' // Specimen in lab — results pending\n | 'R' // Results entered — not yet verified\n | 'S' // Partial results\n | 'D' // Deletes the OBX record\n | 'N' // Not asked — not reported\n | 'W' // Post original as wrong (in error)\n | string;\n\n/** Abnormal flags from HL7 v2 table 0078. */\nexport type AbnormalFlag =\n | 'H' // Above high normal\n | 'HH' // Above upper panic limits\n | 'L' // Below low normal\n | 'LL' // Below lower panic limits\n | 'A' // Abnormal (generic)\n | 'AA' // Very abnormal\n | 'N' // Normal\n | 'IND' // Indeterminate\n | 'NEG' // Negative\n | 'POS' // Positive\n | string;\n\n/** A coded observation identifier (LOINC, SNOMED, local). */\nexport interface ObservationIdentifier {\n /** Identifier code (e.g., LOINC code `'718-7'`). */\n code: string;\n /** Human-readable description (e.g., `'Hemoglobin'`). */\n description: string;\n /** Coding system (e.g., `'LN'` for LOINC, `'SCT'` for SNOMED CT). */\n codingSystem: string;\n}\n\n/**\n * Typed accessor for the OBX (Observation/Result) segment.\n *\n * OBX carries a single clinical observation — a lab result, vital sign,\n * pathology finding, or any structured clinical measurement. A message\n * typically contains multiple OBX segments, one per result.\n *\n * @example\n * import { parse, segments } from 'hl7v2';\n * import { OBX } from 'hl7v2/segments';\n *\n * const msg = parse(raw);\n * const obxs = segments(msg, 'OBX').map(s => new OBX(s, msg.encoding));\n *\n * for (const obx of obxs) {\n * console.log(obx.observationIdentifier().description); // 'Hemoglobin'\n * console.log(obx.numericValue()); // 13.5\n * console.log(obx.units()); // 'g/dL'\n * console.log(obx.referenceRange()); // '13.5-17.5'\n * console.log(obx.abnormalFlags()); // ['H']\n * console.log(obx.resultStatus()); // 'F'\n * }\n */\nexport class OBX extends TypedSegment {\n constructor(seg: HL7Segment, enc: EncodingChars) {\n super(seg, enc);\n }\n\n /** OBX.1 — Set ID (sequence number within the message, 1-based). */\n setId(): number | undefined { return this.num(1); }\n\n /**\n * OBX.2 — Value Type.\n * Indicates the data type of the observation value in OBX.5.\n * Common values: `'NM'` (numeric), `'ST'` (string), `'CWE'` (coded).\n */\n valueType(): ObservationValueType { return this.str(2); }\n\n /**\n * OBX.3 — Observation Identifier.\n * Typically a LOINC code identifying what was measured.\n *\n * @example\n * obx.observationIdentifier()\n * // { code: '718-7', description: 'Hemoglobin [Mass/volume] in Blood', codingSystem: 'LN' }\n */\n observationIdentifier(): ObservationIdentifier {\n return {\n code: this.str(3, 1),\n description: this.str(3, 2),\n codingSystem: this.str(3, 3),\n };\n }\n\n /** OBX.4 — Observation Sub-ID (groups related OBX segments). */\n observationSubId(): string { return this.str(4); }\n\n /**\n * OBX.5 — Observation Value (raw string).\n *\n * The interpretation depends on OBX.2 (value type).\n * Use {@link numericValue} for `NM`, {@link codedValue} for `CWE`/`CE`.\n */\n observationValue(): string { return this.str(5); }\n\n /**\n * OBX.5 — Observation value interpreted as a number.\n * Returns `undefined` if the value type is not `NM` or the value is absent.\n *\n * For structured numerics (SN type like `'>10.5'`), use {@link observationValue}.\n */\n numericValue(): number | undefined {\n if (this.str(2) !== 'NM') return undefined;\n return this.num(5);\n }\n\n /**\n * OBX.5 — Observation value as a coded element (CWE/CE value type).\n * Returns `{ code, description, codingSystem }`.\n */\n codedValue(): ObservationIdentifier {\n return {\n code: this.str(5, 1),\n description: this.str(5, 2),\n codingSystem: this.str(5, 3),\n };\n }\n\n /**\n * OBX.6 — Units (CWE data type).\n * Returns the unit code (e.g., `'g/dL'`, `'10*3/uL'`, `'mmHg'`).\n */\n units(): string { return this.str(6, 1); }\n\n /**\n * OBX.7 — References Range.\n * The normal range as a string (e.g., `'3.5-5.0'`, `'<200'`).\n */\n referenceRange(): string { return this.str(7); }\n\n /**\n * OBX.8 — Interpretation Codes (formerly Abnormal Flags).\n * Returns all flags for this result (a field can have multiple repetitions).\n *\n * Common values: `'H'` high, `'L'` low, `'HH'` critical high, `'LL'` critical low,\n * `'N'` normal, `'A'` abnormal, `'POS'` positive, `'NEG'` negative.\n */\n abnormalFlags(): AbnormalFlag[] {\n return this.repetitions(8);\n }\n\n /**\n * OBX.8 — Primary interpretation code (first flag).\n * Returns `''` if the result has no flags (i.e., it is normal / in-range).\n */\n primaryAbnormalFlag(): AbnormalFlag { return this.str(8); }\n\n /** OBX.11 — Observation Result Status (HL7 table 0085). */\n resultStatus(): ResultStatus { return this.str(11); }\n\n /** OBX.14 — Date/Time of Observation. */\n observationDateTime(): Date | undefined { return this.date(14); }\n\n /** OBX.15 — Producer's ID (the lab or device that produced the result). */\n producerId(): string { return this.str(15, 1); }\n\n /** OBX.16 — Responsible Observer (clinician who verified the result). */\n responsibleObserver(): string { return this.str(16, 1); }\n\n /** OBX.19 — Date/Time of Analysis. */\n analysisDateTime(): Date | undefined { return this.date(19); }\n\n /**\n * Convenience: return `true` if this result has a critical abnormal flag\n * (`'HH'` or `'LL'`).\n */\n isCritical(): boolean {\n const flags = this.abnormalFlags();\n return flags.includes('HH') || flags.includes('LL');\n }\n\n /**\n * Convenience: return `true` if the result is finalised (`resultStatus() === 'F'`).\n */\n isFinal(): boolean { return this.str(11) === 'F'; }\n}\n","import type { EncodingChars, HL7Segment } from '../schema.js';\nimport { TypedSegment } from './base.js';\n\n/** Patient class codes from HL7 v2 table 0004. */\nexport type PatientClass =\n | 'E' // Emergency\n | 'I' // Inpatient\n | 'O' // Outpatient\n | 'P' // Preadmit\n | 'R' // Recurring patient\n | 'B' // Obstetrics\n | 'C' // Commercial account\n | 'N' // Not applicable\n | 'U' // Unknown\n | string;\n\n/** A structured provider/clinician name and identifier. */\nexport interface Provider {\n /** Provider identifier (e.g., NPI number, employee ID). */\n id: string;\n /** Family (last) name. */\n family: string;\n /** Given (first) name. */\n given: string;\n /** Middle name or initial. */\n middle: string;\n /** Credential suffix (e.g., `'MD'`, `'DO'`, `'NP'`). */\n credential: string;\n}\n\n/** A patient location — room, bed, facility. */\nexport interface PatientLocation {\n pointOfCare: string;\n room: string;\n bed: string;\n facility: string;\n buildingCode: string;\n floor: string;\n}\n\n/**\n * Typed accessor for the PV1 (Patient Visit) segment.\n *\n * PV1 describes the context of a patient's current or historical visit:\n * the patient class (inpatient/outpatient), assigned location, attending\n * and referring physicians, and admission/discharge timestamps.\n *\n * @example\n * import { parse, segment } from 'hl7v2';\n * import { PV1 } from 'hl7v2/segments';\n *\n * const msg = parse(raw);\n * const pv1 = new PV1(segment(msg, 'PV1'), msg.encoding);\n *\n * pv1.patientClass() // 'I' (Inpatient)\n * pv1.assignedLocation() // { pointOfCare: 'CARDIOLOGY', room: '4A', bed: '101', ... }\n * pv1.attendingDoctor() // { id: '1234567', family: 'Smith', given: 'Richard', ... }\n * pv1.admitDateTime() // Date | undefined\n */\nexport class PV1 extends TypedSegment {\n constructor(seg: HL7Segment, enc: EncodingChars) {\n super(seg, enc);\n }\n\n /** PV1.1 — Set ID. */\n setId(): number | undefined { return this.num(1); }\n\n /**\n * PV1.2 — Patient Class (HL7 table 0004).\n * `'I'` Inpatient · `'O'` Outpatient · `'E'` Emergency · `'P'` Preadmit\n */\n patientClass(): PatientClass { return this.str(2); }\n\n /**\n * PV1.3 — Assigned Patient Location.\n * The bed the patient is currently assigned to.\n */\n assignedLocation(): PatientLocation {\n return {\n pointOfCare: this.str(3, 1),\n room: this.str(3, 2),\n bed: this.str(3, 3),\n facility: this.str(3, 4),\n buildingCode:this.str(3, 7),\n floor: this.str(3, 8),\n };\n }\n\n /** PV1.4 — Admission Type (e.g., `'A'` = accident, `'E'` = emergency). */\n admissionType(): string { return this.str(4); }\n\n /**\n * PV1.7 — Attending Doctor.\n * The physician primarily responsible for the patient's care.\n */\n attendingDoctor(): Provider {\n return {\n id: this.str(7, 1),\n family: this.str(7, 2),\n given: this.str(7, 3),\n middle: this.str(7, 4),\n credential: this.str(7, 7),\n };\n }\n\n /**\n * PV1.8 — Referring Doctor.\n * The physician who referred the patient.\n */\n referringDoctor(): Provider {\n return {\n id: this.str(8, 1),\n family: this.str(8, 2),\n given: this.str(8, 3),\n middle: this.str(8, 4),\n credential: this.str(8, 7),\n };\n }\n\n /**\n * PV1.9 — Consulting Doctor.\n * Returns all consulting doctors (field can repeat).\n */\n consultingDoctors(): Provider[] {\n const field = this.field(9);\n if (!field) return [];\n return field.map(rep => ({\n id: rep[0]?.[0] ?? '',\n family: rep[1]?.[0] ?? '',\n given: rep[2]?.[0] ?? '',\n middle: rep[3]?.[0] ?? '',\n credential: rep[7]?.[0] ?? '',\n }));\n }\n\n /** PV1.10 — Hospital Service (e.g., `'MED'`, `'SUR'`, `'CAR'`). */\n hospitalService(): string { return this.str(10); }\n\n /** PV1.14 — Admit Source (HL7 table 0023). */\n admitSource(): string { return this.str(14); }\n\n /** PV1.18 — Patient Type. */\n patientType(): string { return this.str(18); }\n\n /** PV1.19 — Visit Number (account number for this specific visit). */\n visitNumber(): string { return this.str(19, 1); }\n\n /** PV1.36 — Discharge Disposition (HL7 table 0112). */\n dischargeDisposition(): string { return this.str(36); }\n\n /**\n * PV1.44 — Admit Date/Time.\n * When the patient was admitted to this care setting.\n */\n admitDateTime(): Date | undefined { return this.date(44); }\n\n /**\n * PV1.45 — Discharge Date/Time.\n * `undefined` if the patient has not yet been discharged.\n */\n dischargeDateTime(): Date | undefined { return this.date(45); }\n}\n"]}
|