Function: setDefaultProfile()
setDefaultProfile(
profile):void
Register a process-scoped default profile. parseHL7(raw) (with no
explicit profile arg) consults getDefaultProfile() and applies the
returned profile if any. Pass null (or undefined) to clear.
Effects are IDENTICAL to passing the profile explicitly as the second
arg of parseHL7 (D-20): customSegments, dateFormats, onWarning chain,
and profile attribution all apply the same way.
Explicit args ALWAYS win: parseHL7(raw, myProfile) uses myProfile
regardless of the default; parseHL7(raw, { profile: null }) opts out
of the default for a single call without changing the registered
default.
Test hygiene: This is the ONLY mutable module-scoped state in the
library. Tests that call setDefaultProfile MUST clean up in
afterEach (setDefaultProfile(null)) or default-profile bleed will
infect subsequent tests.
Parameters
profile
Profile | null
Returns
void
Example
import { setDefaultProfile, profiles, parseHL7 } from "@cosyte/hl7";
// Set once at app startup
setDefaultProfile(profiles.epic);
// Every parseHL7 call in the app now uses profiles.epic unless
// another profile is passed explicitly.
const msg = parseHL7(raw);
console.log(msg.profile?.name); // "epic"
// Clear when done (or in test teardown):
setDefaultProfile(null);