Function: parseHL7()
Internal
implementation signature; overload signatures above carry the public JSDoc + @example.
Call Signature
parseHL7(
raw):Hl7Message
Parse a raw HL7 v2 message (string or Buffer) into an Hl7Message.
The parser is lenient by default: recoverable deviations from the HL7
spec are reported via msg.warnings and (optionally)
options.onWarning but do not throw. Four unrecoverable structural
errors throw Hl7ParseError: NO_MSH_SEGMENT, MSH_TOO_SHORT,
INVALID_ENCODING_CHARACTERS, EMPTY_INPUT. Opt into strict mode
with { strict: true } to escalate every Tier-2 warning into an
Hl7ParseError.
Parameters
raw
string | Buffer<ArrayBufferLike>
Returns
Example
import { parseHL7, WARNING_CODES } from "@cosyte/hl7";
const msg = parseHL7(
"MSH|^~\\&|APP|FAC|APP|FAC|20250101||ADT^A01|1|P|2.5\rPID|||123",
);
console.log(msg.version); // "2.5"
console.log(msg.warnings.length); // 0
for (const w of msg.warnings) {
if (w.code === WARNING_CODES.MLLP_FRAMING_STRIPPED) {
// handle MLLP-framed sender
}
}
Call Signature
parseHL7(
raw,profile):Hl7Message
Parse a raw HL7 v2 message (string or Buffer) into an Hl7Message.
The parser is lenient by default: recoverable deviations from the HL7
spec are reported via msg.warnings and (optionally)
options.onWarning but do not throw. Four unrecoverable structural
errors throw Hl7ParseError: NO_MSH_SEGMENT, MSH_TOO_SHORT,
INVALID_ENCODING_CHARACTERS, EMPTY_INPUT. Opt into strict mode
with { strict: true } to escalate every Tier-2 warning into an
Hl7ParseError.
Parameters
raw
string | Buffer<ArrayBufferLike>
profile
Returns
Example
import { parseHL7, WARNING_CODES } from "@cosyte/hl7";
const msg = parseHL7(
"MSH|^~\\&|APP|FAC|APP|FAC|20250101||ADT^A01|1|P|2.5\rPID|||123",
);
console.log(msg.version); // "2.5"
console.log(msg.warnings.length); // 0
for (const w of msg.warnings) {
if (w.code === WARNING_CODES.MLLP_FRAMING_STRIPPED) {
// handle MLLP-framed sender
}
}
Call Signature
parseHL7(
raw,options):Hl7Message
Parse a raw HL7 v2 message (string or Buffer) into an Hl7Message.
The parser is lenient by default: recoverable deviations from the HL7
spec are reported via msg.warnings and (optionally)
options.onWarning but do not throw. Four unrecoverable structural
errors throw Hl7ParseError: NO_MSH_SEGMENT, MSH_TOO_SHORT,
INVALID_ENCODING_CHARACTERS, EMPTY_INPUT. Opt into strict mode
with { strict: true } to escalate every Tier-2 warning into an
Hl7ParseError.
Parameters
raw
string | Buffer<ArrayBufferLike>
options
Returns
Example
import { parseHL7, WARNING_CODES } from "@cosyte/hl7";
const msg = parseHL7(
"MSH|^~\\&|APP|FAC|APP|FAC|20250101||ADT^A01|1|P|2.5\rPID|||123",
);
console.log(msg.version); // "2.5"
console.log(msg.warnings.length); // 0
for (const w of msg.warnings) {
if (w.code === WARNING_CODES.MLLP_FRAMING_STRIPPED) {
// handle MLLP-framed sender
}
}