@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,636 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/escape.ts
|
|
4
|
+
function escRx(s) {
|
|
5
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6
|
+
}
|
|
7
|
+
function decodeEscapes(value, enc) {
|
|
8
|
+
const esc = enc.escape;
|
|
9
|
+
if (!value.includes(esc)) return value;
|
|
10
|
+
const pattern = new RegExp(`${escRx(esc)}([^${escRx(esc)}]*)${escRx(esc)}`, "g");
|
|
11
|
+
return value.replace(pattern, (match, seq) => {
|
|
12
|
+
switch (seq) {
|
|
13
|
+
case "F":
|
|
14
|
+
return enc.field;
|
|
15
|
+
case "S":
|
|
16
|
+
return enc.component;
|
|
17
|
+
case "T":
|
|
18
|
+
return enc.subComponent;
|
|
19
|
+
case "R":
|
|
20
|
+
return enc.repetition;
|
|
21
|
+
case "E":
|
|
22
|
+
return enc.escape;
|
|
23
|
+
case "H":
|
|
24
|
+
return "\x1B[1m";
|
|
25
|
+
case "N":
|
|
26
|
+
return "\x1B[0m";
|
|
27
|
+
case ".br":
|
|
28
|
+
return "\n";
|
|
29
|
+
default: {
|
|
30
|
+
if (seq.startsWith("X") && seq.length > 1) {
|
|
31
|
+
try {
|
|
32
|
+
const hex = seq.slice(1);
|
|
33
|
+
const bytes = new Uint8Array(hex.match(/.{1,2}/g)?.map((b) => parseInt(b, 16)) ?? []);
|
|
34
|
+
return new TextDecoder().decode(bytes);
|
|
35
|
+
} catch {
|
|
36
|
+
return match;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return match;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/errors.ts
|
|
46
|
+
var HL7ParseError = class extends Error {
|
|
47
|
+
constructor(message, options) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = "HL7ParseError";
|
|
50
|
+
this.line = options?.line;
|
|
51
|
+
this.segmentId = options?.segmentId;
|
|
52
|
+
if (options?.cause !== void 0) {
|
|
53
|
+
Object.defineProperty(this, "cause", {
|
|
54
|
+
value: options.cause,
|
|
55
|
+
writable: true,
|
|
56
|
+
configurable: true
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/datetime.ts
|
|
63
|
+
function parseHL7DateTime(raw) {
|
|
64
|
+
const s = raw.trim();
|
|
65
|
+
if (!s) return void 0;
|
|
66
|
+
if (s.length < 4) {
|
|
67
|
+
throw new HL7ParseError(`Cannot parse HL7 date/time: "${s}" \u2014 minimum format is YYYY`);
|
|
68
|
+
}
|
|
69
|
+
let base = s;
|
|
70
|
+
let offsetMin = 0;
|
|
71
|
+
const tzMatch = /([+-])(\d{2})(\d{2})$/.exec(s);
|
|
72
|
+
if (tzMatch) {
|
|
73
|
+
const sign = tzMatch[1] === "+" ? 1 : -1;
|
|
74
|
+
const tzHours = parseInt(tzMatch[2] ?? "0", 10);
|
|
75
|
+
const tzMins = parseInt(tzMatch[3] ?? "0", 10);
|
|
76
|
+
offsetMin = sign * (tzHours * 60 + tzMins);
|
|
77
|
+
base = s.slice(0, s.length - 5);
|
|
78
|
+
}
|
|
79
|
+
let fracMs = 0;
|
|
80
|
+
const dotIdx = base.indexOf(".");
|
|
81
|
+
if (dotIdx !== -1) {
|
|
82
|
+
const fracStr = base.slice(dotIdx);
|
|
83
|
+
fracMs = Math.round(parseFloat(fracStr) * 1e3);
|
|
84
|
+
base = base.slice(0, dotIdx);
|
|
85
|
+
}
|
|
86
|
+
const year = parseInt(base.slice(0, 4), 10);
|
|
87
|
+
const month = parseInt(base.slice(4, 6) || "01", 10) - 1;
|
|
88
|
+
const day = parseInt(base.slice(6, 8) || "01", 10);
|
|
89
|
+
const hour = parseInt(base.slice(8, 10) || "00", 10);
|
|
90
|
+
const min = parseInt(base.slice(10, 12) || "00", 10);
|
|
91
|
+
const sec = parseInt(base.slice(12, 14) || "00", 10);
|
|
92
|
+
if (isNaN(year) || isNaN(month) || isNaN(day)) {
|
|
93
|
+
throw new HL7ParseError(`Cannot parse HL7 date/time: "${s}"`);
|
|
94
|
+
}
|
|
95
|
+
const utcMs = Date.UTC(year, month, day, hour, min, sec, fracMs) - offsetMin * 6e4;
|
|
96
|
+
const result = new Date(utcMs);
|
|
97
|
+
if (isNaN(result.getTime())) {
|
|
98
|
+
throw new HL7ParseError(`Cannot parse HL7 date/time: "${s}"`);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/segments/base.ts
|
|
104
|
+
var TypedSegment = class {
|
|
105
|
+
constructor(seg, enc) {
|
|
106
|
+
this.seg = seg;
|
|
107
|
+
this.enc = enc;
|
|
108
|
+
}
|
|
109
|
+
/** The raw underlying {@link HL7Segment}. */
|
|
110
|
+
get raw() {
|
|
111
|
+
return this.seg;
|
|
112
|
+
}
|
|
113
|
+
/** Return the raw field structure at the given 1-based field number. */
|
|
114
|
+
field(num) {
|
|
115
|
+
return this.seg.fields[num - 1];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Extract a scalar string value from the segment.
|
|
119
|
+
* All arguments are 1-based. Missing elements return `''`.
|
|
120
|
+
* Escape sequences are decoded automatically.
|
|
121
|
+
*/
|
|
122
|
+
str(fieldNum, component = 1, subComponent = 1, repetition = 1) {
|
|
123
|
+
const f = this.field(fieldNum);
|
|
124
|
+
if (!f) return "";
|
|
125
|
+
const raw = f[repetition - 1]?.[component - 1]?.[subComponent - 1] ?? "";
|
|
126
|
+
return decodeEscapes(raw, this.enc);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Extract a string value from the segment without escape decoding.
|
|
130
|
+
* Useful when you need to preserve the raw HL7 encoding.
|
|
131
|
+
*/
|
|
132
|
+
rawStr(fieldNum, component = 1, subComponent = 1, repetition = 1) {
|
|
133
|
+
const f = this.field(fieldNum);
|
|
134
|
+
if (!f) return "";
|
|
135
|
+
return f[repetition - 1]?.[component - 1]?.[subComponent - 1] ?? "";
|
|
136
|
+
}
|
|
137
|
+
/** Extract a Date from an HL7 date/time field. Returns `undefined` if empty. */
|
|
138
|
+
date(fieldNum, component = 1) {
|
|
139
|
+
const raw = this.rawStr(fieldNum, component);
|
|
140
|
+
if (!raw) return void 0;
|
|
141
|
+
try {
|
|
142
|
+
return parseHL7DateTime(raw);
|
|
143
|
+
} catch {
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Extract a numeric value from a field. Returns `undefined` if empty or non-numeric. */
|
|
148
|
+
num(fieldNum, component = 1) {
|
|
149
|
+
const raw = this.str(fieldNum, component);
|
|
150
|
+
if (!raw) return void 0;
|
|
151
|
+
const n = parseFloat(raw);
|
|
152
|
+
return isNaN(n) ? void 0 : n;
|
|
153
|
+
}
|
|
154
|
+
/** Return all repetitions of a field as an array of first-component strings. */
|
|
155
|
+
repetitions(fieldNum, component = 1) {
|
|
156
|
+
const f = this.field(fieldNum);
|
|
157
|
+
if (!f) return [];
|
|
158
|
+
return f.map((rep) => {
|
|
159
|
+
const raw = rep[component - 1]?.[0] ?? "";
|
|
160
|
+
return decodeEscapes(raw, this.enc);
|
|
161
|
+
}).filter((v) => v !== "");
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// src/segments/msh.ts
|
|
166
|
+
var MSH = class extends TypedSegment {
|
|
167
|
+
constructor(seg, enc) {
|
|
168
|
+
super(seg, enc);
|
|
169
|
+
}
|
|
170
|
+
/** MSH.3 — Sending Application */
|
|
171
|
+
sendingApplication() {
|
|
172
|
+
return this.str(3);
|
|
173
|
+
}
|
|
174
|
+
/** MSH.4 — Sending Facility */
|
|
175
|
+
sendingFacility() {
|
|
176
|
+
return this.str(4);
|
|
177
|
+
}
|
|
178
|
+
/** MSH.5 — Receiving Application */
|
|
179
|
+
receivingApplication() {
|
|
180
|
+
return this.str(5);
|
|
181
|
+
}
|
|
182
|
+
/** MSH.6 — Receiving Facility */
|
|
183
|
+
receivingFacility() {
|
|
184
|
+
return this.str(6);
|
|
185
|
+
}
|
|
186
|
+
/** MSH.7 — Date/Time of Message */
|
|
187
|
+
dateTimeOfMessage() {
|
|
188
|
+
return this.date(7);
|
|
189
|
+
}
|
|
190
|
+
/** MSH.9 — Message Type (e.g., `{ type: 'ADT', event: 'A01', structure: 'ADT_A01' }`). */
|
|
191
|
+
messageType() {
|
|
192
|
+
const field = this.field(9);
|
|
193
|
+
const firstRep = field?.[0] ?? [];
|
|
194
|
+
const struct = firstRep[2]?.[0];
|
|
195
|
+
return {
|
|
196
|
+
type: firstRep[0]?.[0] ?? "",
|
|
197
|
+
event: firstRep[1]?.[0] ?? "",
|
|
198
|
+
structure: struct !== void 0 && struct !== "" ? struct : void 0
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** MSH.10 — Message Control ID (used for ACK correlation). */
|
|
202
|
+
messageControlId() {
|
|
203
|
+
return this.str(10);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* MSH.11 — Processing ID.
|
|
207
|
+
* `'P'` = Production, `'D'` = Debugging, `'T'` = Training.
|
|
208
|
+
*/
|
|
209
|
+
processingId() {
|
|
210
|
+
return this.str(11);
|
|
211
|
+
}
|
|
212
|
+
/** MSH.12 — HL7 version (e.g., `'2.5.1'`). */
|
|
213
|
+
version() {
|
|
214
|
+
return this.str(12);
|
|
215
|
+
}
|
|
216
|
+
/** MSH.15 — Accept Acknowledgement Type. */
|
|
217
|
+
acceptAcknowledgementType() {
|
|
218
|
+
return this.str(15);
|
|
219
|
+
}
|
|
220
|
+
/** MSH.16 — Application Acknowledgement Type. */
|
|
221
|
+
applicationAcknowledgementType() {
|
|
222
|
+
return this.str(16);
|
|
223
|
+
}
|
|
224
|
+
/** MSH.17 — Country Code (ISO 3166). */
|
|
225
|
+
countryCode() {
|
|
226
|
+
return this.str(17);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/segments/pid.ts
|
|
231
|
+
var PID = class extends TypedSegment {
|
|
232
|
+
constructor(seg, enc) {
|
|
233
|
+
super(seg, enc);
|
|
234
|
+
}
|
|
235
|
+
/** PID.1 — Set ID (1-based sequence number within the message). */
|
|
236
|
+
setId() {
|
|
237
|
+
return this.num(1);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* PID.3 — Patient Identifier List.
|
|
241
|
+
*
|
|
242
|
+
* Returns all patient identifiers (MRN, SSN, national ID, etc.).
|
|
243
|
+
* Each identifier has its own type code and assigning authority.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* pid.patientIdentifiers()
|
|
247
|
+
* // [{ id: 'MRN123', assigningAuthority: 'HOSPITAL', identifierTypeCode: 'MR' }]
|
|
248
|
+
*/
|
|
249
|
+
patientIdentifiers() {
|
|
250
|
+
const field = this.field(3);
|
|
251
|
+
if (!field) return [];
|
|
252
|
+
return field.map((rep) => ({
|
|
253
|
+
id: rep[0]?.[0] ?? "",
|
|
254
|
+
checkDigit: rep[1]?.[0] ?? "",
|
|
255
|
+
assigningAuthority: rep[3]?.[0] ?? "",
|
|
256
|
+
identifierTypeCode: rep[4]?.[0] ?? ""
|
|
257
|
+
}));
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* PID.3 — Primary patient identifier (first in the list).
|
|
261
|
+
* Returns the raw identifier string (e.g., `'MRN123'`).
|
|
262
|
+
*/
|
|
263
|
+
patientId() {
|
|
264
|
+
return this.str(3, 1);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* PID.5 — Patient Name (first/primary name).
|
|
268
|
+
*
|
|
269
|
+
* Patient names follow the XPN (Extended Person Name) data type.
|
|
270
|
+
* Components: family ^ given ^ middle ^ suffix ^ prefix ^ degree
|
|
271
|
+
*/
|
|
272
|
+
patientName() {
|
|
273
|
+
return {
|
|
274
|
+
family: this.str(5, 1),
|
|
275
|
+
given: this.str(5, 2),
|
|
276
|
+
middle: this.str(5, 3),
|
|
277
|
+
suffix: this.str(5, 4),
|
|
278
|
+
prefix: this.str(5, 5),
|
|
279
|
+
degree: this.str(5, 6)
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* PID.5 — All patient names (legal, alias, display, etc.).
|
|
284
|
+
* Most messages contain a single name; some include aliases or prior names.
|
|
285
|
+
*/
|
|
286
|
+
allPatientNames() {
|
|
287
|
+
const field = this.field(5);
|
|
288
|
+
if (!field) return [];
|
|
289
|
+
return field.map((rep) => ({
|
|
290
|
+
family: rep[0]?.[0] ?? "",
|
|
291
|
+
given: rep[1]?.[0] ?? "",
|
|
292
|
+
middle: rep[2]?.[0] ?? "",
|
|
293
|
+
suffix: rep[3]?.[0] ?? "",
|
|
294
|
+
prefix: rep[4]?.[0] ?? "",
|
|
295
|
+
degree: rep[5]?.[0] ?? ""
|
|
296
|
+
}));
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* PID.7 — Date/Time of Birth.
|
|
300
|
+
* Returns `undefined` if absent or unparseable.
|
|
301
|
+
*/
|
|
302
|
+
dateOfBirth() {
|
|
303
|
+
return this.date(7);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* PID.8 — Administrative Sex (HL7 table 0001).
|
|
307
|
+
* `'M'` Male · `'F'` Female · `'O'` Other · `'U'` Unknown
|
|
308
|
+
* `'A'` Ambiguous · `'N'` Not applicable · `'C'` Complex
|
|
309
|
+
*/
|
|
310
|
+
sex() {
|
|
311
|
+
return this.str(8);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* PID.10 — Race (HL7 table 0005, CWE data type).
|
|
315
|
+
* Returns the race code (first component).
|
|
316
|
+
*/
|
|
317
|
+
race() {
|
|
318
|
+
return this.str(10, 1);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* PID.11 — Patient Address (first address).
|
|
322
|
+
* Addresses follow the XAD (Extended Address) data type.
|
|
323
|
+
*/
|
|
324
|
+
address() {
|
|
325
|
+
return {
|
|
326
|
+
streetAddress: this.str(11, 1),
|
|
327
|
+
otherDesignation: this.str(11, 2),
|
|
328
|
+
city: this.str(11, 3),
|
|
329
|
+
state: this.str(11, 4),
|
|
330
|
+
postalCode: this.str(11, 5),
|
|
331
|
+
country: this.str(11, 6),
|
|
332
|
+
addressType: this.str(11, 7)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/** PID.13 — Phone Number - Home (first number, XTN data type). */
|
|
336
|
+
homePhone() {
|
|
337
|
+
return this.str(13, 1);
|
|
338
|
+
}
|
|
339
|
+
/** PID.14 — Phone Number - Business (first number, XTN data type). */
|
|
340
|
+
workPhone() {
|
|
341
|
+
return this.str(14, 1);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* PID.15 — Primary Language (CE data type).
|
|
345
|
+
* Returns the language code (e.g., `'ENG'`, `'SPA'`).
|
|
346
|
+
*/
|
|
347
|
+
primaryLanguage() {
|
|
348
|
+
return this.str(15, 1);
|
|
349
|
+
}
|
|
350
|
+
/** PID.16 — Marital Status (HL7 table 0002). */
|
|
351
|
+
maritalStatus() {
|
|
352
|
+
return this.str(16, 1);
|
|
353
|
+
}
|
|
354
|
+
/** PID.17 — Religion (HL7 table 0006). */
|
|
355
|
+
religion() {
|
|
356
|
+
return this.str(17, 1);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* PID.18 — Patient Account Number.
|
|
360
|
+
* The billing/visit account number (distinct from the medical record number).
|
|
361
|
+
*/
|
|
362
|
+
accountNumber() {
|
|
363
|
+
return this.str(18, 1);
|
|
364
|
+
}
|
|
365
|
+
/** PID.19 — SSN Number - Patient (US Social Security Number). */
|
|
366
|
+
ssn() {
|
|
367
|
+
return this.str(19);
|
|
368
|
+
}
|
|
369
|
+
/** PID.22 — Ethnic Group (HL7 table 0189, CWE data type). */
|
|
370
|
+
ethnicGroup() {
|
|
371
|
+
return this.str(22, 1);
|
|
372
|
+
}
|
|
373
|
+
/** PID.29 — Patient Death Date and Time. `undefined` if patient is not deceased. */
|
|
374
|
+
deathDateTime() {
|
|
375
|
+
return this.date(29);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* PID.30 — Patient Death Indicator.
|
|
379
|
+
* `'Y'` = deceased, `'N'` = not deceased.
|
|
380
|
+
*/
|
|
381
|
+
deathIndicator() {
|
|
382
|
+
return this.str(30);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// src/segments/obx.ts
|
|
387
|
+
var OBX = class extends TypedSegment {
|
|
388
|
+
constructor(seg, enc) {
|
|
389
|
+
super(seg, enc);
|
|
390
|
+
}
|
|
391
|
+
/** OBX.1 — Set ID (sequence number within the message, 1-based). */
|
|
392
|
+
setId() {
|
|
393
|
+
return this.num(1);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* OBX.2 — Value Type.
|
|
397
|
+
* Indicates the data type of the observation value in OBX.5.
|
|
398
|
+
* Common values: `'NM'` (numeric), `'ST'` (string), `'CWE'` (coded).
|
|
399
|
+
*/
|
|
400
|
+
valueType() {
|
|
401
|
+
return this.str(2);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* OBX.3 — Observation Identifier.
|
|
405
|
+
* Typically a LOINC code identifying what was measured.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* obx.observationIdentifier()
|
|
409
|
+
* // { code: '718-7', description: 'Hemoglobin [Mass/volume] in Blood', codingSystem: 'LN' }
|
|
410
|
+
*/
|
|
411
|
+
observationIdentifier() {
|
|
412
|
+
return {
|
|
413
|
+
code: this.str(3, 1),
|
|
414
|
+
description: this.str(3, 2),
|
|
415
|
+
codingSystem: this.str(3, 3)
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
/** OBX.4 — Observation Sub-ID (groups related OBX segments). */
|
|
419
|
+
observationSubId() {
|
|
420
|
+
return this.str(4);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* OBX.5 — Observation Value (raw string).
|
|
424
|
+
*
|
|
425
|
+
* The interpretation depends on OBX.2 (value type).
|
|
426
|
+
* Use {@link numericValue} for `NM`, {@link codedValue} for `CWE`/`CE`.
|
|
427
|
+
*/
|
|
428
|
+
observationValue() {
|
|
429
|
+
return this.str(5);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* OBX.5 — Observation value interpreted as a number.
|
|
433
|
+
* Returns `undefined` if the value type is not `NM` or the value is absent.
|
|
434
|
+
*
|
|
435
|
+
* For structured numerics (SN type like `'>10.5'`), use {@link observationValue}.
|
|
436
|
+
*/
|
|
437
|
+
numericValue() {
|
|
438
|
+
if (this.str(2) !== "NM") return void 0;
|
|
439
|
+
return this.num(5);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* OBX.5 — Observation value as a coded element (CWE/CE value type).
|
|
443
|
+
* Returns `{ code, description, codingSystem }`.
|
|
444
|
+
*/
|
|
445
|
+
codedValue() {
|
|
446
|
+
return {
|
|
447
|
+
code: this.str(5, 1),
|
|
448
|
+
description: this.str(5, 2),
|
|
449
|
+
codingSystem: this.str(5, 3)
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* OBX.6 — Units (CWE data type).
|
|
454
|
+
* Returns the unit code (e.g., `'g/dL'`, `'10*3/uL'`, `'mmHg'`).
|
|
455
|
+
*/
|
|
456
|
+
units() {
|
|
457
|
+
return this.str(6, 1);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* OBX.7 — References Range.
|
|
461
|
+
* The normal range as a string (e.g., `'3.5-5.0'`, `'<200'`).
|
|
462
|
+
*/
|
|
463
|
+
referenceRange() {
|
|
464
|
+
return this.str(7);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* OBX.8 — Interpretation Codes (formerly Abnormal Flags).
|
|
468
|
+
* Returns all flags for this result (a field can have multiple repetitions).
|
|
469
|
+
*
|
|
470
|
+
* Common values: `'H'` high, `'L'` low, `'HH'` critical high, `'LL'` critical low,
|
|
471
|
+
* `'N'` normal, `'A'` abnormal, `'POS'` positive, `'NEG'` negative.
|
|
472
|
+
*/
|
|
473
|
+
abnormalFlags() {
|
|
474
|
+
return this.repetitions(8);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* OBX.8 — Primary interpretation code (first flag).
|
|
478
|
+
* Returns `''` if the result has no flags (i.e., it is normal / in-range).
|
|
479
|
+
*/
|
|
480
|
+
primaryAbnormalFlag() {
|
|
481
|
+
return this.str(8);
|
|
482
|
+
}
|
|
483
|
+
/** OBX.11 — Observation Result Status (HL7 table 0085). */
|
|
484
|
+
resultStatus() {
|
|
485
|
+
return this.str(11);
|
|
486
|
+
}
|
|
487
|
+
/** OBX.14 — Date/Time of Observation. */
|
|
488
|
+
observationDateTime() {
|
|
489
|
+
return this.date(14);
|
|
490
|
+
}
|
|
491
|
+
/** OBX.15 — Producer's ID (the lab or device that produced the result). */
|
|
492
|
+
producerId() {
|
|
493
|
+
return this.str(15, 1);
|
|
494
|
+
}
|
|
495
|
+
/** OBX.16 — Responsible Observer (clinician who verified the result). */
|
|
496
|
+
responsibleObserver() {
|
|
497
|
+
return this.str(16, 1);
|
|
498
|
+
}
|
|
499
|
+
/** OBX.19 — Date/Time of Analysis. */
|
|
500
|
+
analysisDateTime() {
|
|
501
|
+
return this.date(19);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Convenience: return `true` if this result has a critical abnormal flag
|
|
505
|
+
* (`'HH'` or `'LL'`).
|
|
506
|
+
*/
|
|
507
|
+
isCritical() {
|
|
508
|
+
const flags = this.abnormalFlags();
|
|
509
|
+
return flags.includes("HH") || flags.includes("LL");
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Convenience: return `true` if the result is finalised (`resultStatus() === 'F'`).
|
|
513
|
+
*/
|
|
514
|
+
isFinal() {
|
|
515
|
+
return this.str(11) === "F";
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// src/segments/pv1.ts
|
|
520
|
+
var PV1 = class extends TypedSegment {
|
|
521
|
+
constructor(seg, enc) {
|
|
522
|
+
super(seg, enc);
|
|
523
|
+
}
|
|
524
|
+
/** PV1.1 — Set ID. */
|
|
525
|
+
setId() {
|
|
526
|
+
return this.num(1);
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* PV1.2 — Patient Class (HL7 table 0004).
|
|
530
|
+
* `'I'` Inpatient · `'O'` Outpatient · `'E'` Emergency · `'P'` Preadmit
|
|
531
|
+
*/
|
|
532
|
+
patientClass() {
|
|
533
|
+
return this.str(2);
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* PV1.3 — Assigned Patient Location.
|
|
537
|
+
* The bed the patient is currently assigned to.
|
|
538
|
+
*/
|
|
539
|
+
assignedLocation() {
|
|
540
|
+
return {
|
|
541
|
+
pointOfCare: this.str(3, 1),
|
|
542
|
+
room: this.str(3, 2),
|
|
543
|
+
bed: this.str(3, 3),
|
|
544
|
+
facility: this.str(3, 4),
|
|
545
|
+
buildingCode: this.str(3, 7),
|
|
546
|
+
floor: this.str(3, 8)
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
/** PV1.4 — Admission Type (e.g., `'A'` = accident, `'E'` = emergency). */
|
|
550
|
+
admissionType() {
|
|
551
|
+
return this.str(4);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* PV1.7 — Attending Doctor.
|
|
555
|
+
* The physician primarily responsible for the patient's care.
|
|
556
|
+
*/
|
|
557
|
+
attendingDoctor() {
|
|
558
|
+
return {
|
|
559
|
+
id: this.str(7, 1),
|
|
560
|
+
family: this.str(7, 2),
|
|
561
|
+
given: this.str(7, 3),
|
|
562
|
+
middle: this.str(7, 4),
|
|
563
|
+
credential: this.str(7, 7)
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* PV1.8 — Referring Doctor.
|
|
568
|
+
* The physician who referred the patient.
|
|
569
|
+
*/
|
|
570
|
+
referringDoctor() {
|
|
571
|
+
return {
|
|
572
|
+
id: this.str(8, 1),
|
|
573
|
+
family: this.str(8, 2),
|
|
574
|
+
given: this.str(8, 3),
|
|
575
|
+
middle: this.str(8, 4),
|
|
576
|
+
credential: this.str(8, 7)
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* PV1.9 — Consulting Doctor.
|
|
581
|
+
* Returns all consulting doctors (field can repeat).
|
|
582
|
+
*/
|
|
583
|
+
consultingDoctors() {
|
|
584
|
+
const field = this.field(9);
|
|
585
|
+
if (!field) return [];
|
|
586
|
+
return field.map((rep) => ({
|
|
587
|
+
id: rep[0]?.[0] ?? "",
|
|
588
|
+
family: rep[1]?.[0] ?? "",
|
|
589
|
+
given: rep[2]?.[0] ?? "",
|
|
590
|
+
middle: rep[3]?.[0] ?? "",
|
|
591
|
+
credential: rep[7]?.[0] ?? ""
|
|
592
|
+
}));
|
|
593
|
+
}
|
|
594
|
+
/** PV1.10 — Hospital Service (e.g., `'MED'`, `'SUR'`, `'CAR'`). */
|
|
595
|
+
hospitalService() {
|
|
596
|
+
return this.str(10);
|
|
597
|
+
}
|
|
598
|
+
/** PV1.14 — Admit Source (HL7 table 0023). */
|
|
599
|
+
admitSource() {
|
|
600
|
+
return this.str(14);
|
|
601
|
+
}
|
|
602
|
+
/** PV1.18 — Patient Type. */
|
|
603
|
+
patientType() {
|
|
604
|
+
return this.str(18);
|
|
605
|
+
}
|
|
606
|
+
/** PV1.19 — Visit Number (account number for this specific visit). */
|
|
607
|
+
visitNumber() {
|
|
608
|
+
return this.str(19, 1);
|
|
609
|
+
}
|
|
610
|
+
/** PV1.36 — Discharge Disposition (HL7 table 0112). */
|
|
611
|
+
dischargeDisposition() {
|
|
612
|
+
return this.str(36);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* PV1.44 — Admit Date/Time.
|
|
616
|
+
* When the patient was admitted to this care setting.
|
|
617
|
+
*/
|
|
618
|
+
admitDateTime() {
|
|
619
|
+
return this.date(44);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* PV1.45 — Discharge Date/Time.
|
|
623
|
+
* `undefined` if the patient has not yet been discharged.
|
|
624
|
+
*/
|
|
625
|
+
dischargeDateTime() {
|
|
626
|
+
return this.date(45);
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
exports.MSH = MSH;
|
|
631
|
+
exports.OBX = OBX;
|
|
632
|
+
exports.PID = PID;
|
|
633
|
+
exports.PV1 = PV1;
|
|
634
|
+
exports.TypedSegment = TypedSegment;
|
|
635
|
+
//# sourceMappingURL=index.cjs.map
|
|
636
|
+
//# sourceMappingURL=index.cjs.map
|