Function: parseStream()
Internal
implementation signature; overloads above carry the public JSDoc.
Call Signature
parseStream(
source):AsyncGenerator<StreamMessageEntry,void,void>
Incrementally parse a chunked HL7 v2 byte / text stream, yielding one
StreamMessageEntry per MSH-delimited message as its boundary
completes, with O(one-message) memory: the whole stream is never
retained. Demarcates by MSH boundaries inside the optional
[FHS] { [BHS] { MSH… } [BTS] } [FTS] batch frame (HL7 v2 Ch. 2 §2.10.3):
- a message split across chunk boundaries (mid-segment, mid-field, even
mid-
MSH|^~\&) is reassembled correctly: feeding the same bytes in 1-byte chunks vs. one chunk yields identical messages; \r,\r\n, and\nsegment terminators are all tolerated (a\r\nsplit across a chunk boundary is not mistaken for a bare\r);- each message is parsed by the shipped parseHL7 (no second grammar),
okentries carry theHl7Message, a Tier-3 fatal is an isolated failure entry; a malformed message never suppresses later messages; - batch-envelope segments (
FHS/BHS/BTS/FTS) are treated as boundaries and never yielded as messages, soyielded count == MSH count(envelope count reconciliation is splitBatch's job); - a final message with no trailing terminator is still yielded, flagged with a stream-level unterminatedStreamMessage warning: never a throw, the tail is never dropped.
The second argument, when given, is forwarded verbatim to parseHL7 for
each message (profile, strict, charset, dateFormats, …), exactly as
splitBatch forwards it.
Parameters
source
Returns
AsyncGenerator<StreamMessageEntry, void, void>
Example
import { parseStream } from "@cosyte/hl7";
async function* chunks() {
yield "MSH|^~\\&|A|F|B|G|20260101||ADT^A01|1|P|2.5\rPID|||1\r";
yield "MSH|^~\\&|A|F|B|G|20260101||ADT^A01|2|P|2.5\rPID|||2\r";
}
let count = 0;
for await (const entry of parseStream(chunks())) {
if (entry.ok) count += 1; // 2: one per MSH, streamed, released each time
}
Call Signature
parseStream(
source,profile):AsyncGenerator<StreamMessageEntry,void,void>
Incrementally parse a chunked HL7 v2 byte / text stream, yielding one
StreamMessageEntry per MSH-delimited message as its boundary
completes, with O(one-message) memory: the whole stream is never
retained. Demarcates by MSH boundaries inside the optional
[FHS] { [BHS] { MSH… } [BTS] } [FTS] batch frame (HL7 v2 Ch. 2 §2.10.3):
- a message split across chunk boundaries (mid-segment, mid-field, even
mid-
MSH|^~\&) is reassembled correctly: feeding the same bytes in 1-byte chunks vs. one chunk yields identical messages; \r,\r\n, and\nsegment terminators are all tolerated (a\r\nsplit across a chunk boundary is not mistaken for a bare\r);- each message is parsed by the shipped parseHL7 (no second grammar),
okentries carry theHl7Message, a Tier-3 fatal is an isolated failure entry; a malformed message never suppresses later messages; - batch-envelope segments (
FHS/BHS/BTS/FTS) are treated as boundaries and never yielded as messages, soyielded count == MSH count(envelope count reconciliation is splitBatch's job); - a final message with no trailing terminator is still yielded, flagged with a stream-level unterminatedStreamMessage warning: never a throw, the tail is never dropped.
The second argument, when given, is forwarded verbatim to parseHL7 for
each message (profile, strict, charset, dateFormats, …), exactly as
splitBatch forwards it.
Parameters
source
profile
Returns
AsyncGenerator<StreamMessageEntry, void, void>
Example
import { parseStream } from "@cosyte/hl7";
async function* chunks() {
yield "MSH|^~\\&|A|F|B|G|20260101||ADT^A01|1|P|2.5\rPID|||1\r";
yield "MSH|^~\\&|A|F|B|G|20260101||ADT^A01|2|P|2.5\rPID|||2\r";
}
let count = 0;
for await (const entry of parseStream(chunks())) {
if (entry.ok) count += 1; // 2: one per MSH, streamed, released each time
}
Call Signature
parseStream(
source,options):AsyncGenerator<StreamMessageEntry,void,void>
Incrementally parse a chunked HL7 v2 byte / text stream, yielding one
StreamMessageEntry per MSH-delimited message as its boundary
completes, with O(one-message) memory: the whole stream is never
retained. Demarcates by MSH boundaries inside the optional
[FHS] { [BHS] { MSH… } [BTS] } [FTS] batch frame (HL7 v2 Ch. 2 §2.10.3):
- a message split across chunk boundaries (mid-segment, mid-field, even
mid-
MSH|^~\&) is reassembled correctly: feeding the same bytes in 1-byte chunks vs. one chunk yields identical messages; \r,\r\n, and\nsegment terminators are all tolerated (a\r\nsplit across a chunk boundary is not mistaken for a bare\r);- each message is parsed by the shipped parseHL7 (no second grammar),
okentries carry theHl7Message, a Tier-3 fatal is an isolated failure entry; a malformed message never suppresses later messages; - batch-envelope segments (
FHS/BHS/BTS/FTS) are treated as boundaries and never yielded as messages, soyielded count == MSH count(envelope count reconciliation is splitBatch's job); - a final message with no trailing terminator is still yielded, flagged with a stream-level unterminatedStreamMessage warning: never a throw, the tail is never dropped.
The second argument, when given, is forwarded verbatim to parseHL7 for
each message (profile, strict, charset, dateFormats, …), exactly as
splitBatch forwards it.
Parameters
source
options
Returns
AsyncGenerator<StreamMessageEntry, void, void>
Example
import { parseStream } from "@cosyte/hl7";
async function* chunks() {
yield "MSH|^~\\&|A|F|B|G|20260101||ADT^A01|1|P|2.5\rPID|||1\r";
yield "MSH|^~\\&|A|F|B|G|20260101||ADT^A01|2|P|2.5\rPID|||2\r";
}
let count = 0;
for await (const entry of parseStream(chunks())) {
if (entry.ok) count += 1; // 2: one per MSH, streamed, released each time
}