Function: validateAgainstProfile()
validateAgainstProfile(
message,profile):ConformanceResult
Validate a parsed HL7 v2 message against a user-authored declarative conformance profile and return typed findings.
Never throws. A well-formed profile is evaluated rule by rule; a
malformed profile is reported as PROFILE_MALFORMED findings (the engine
does not validate against a profile it cannot trust: never a silent pass).
Either way you get a ConformanceResult. For fail-fast authoring, run
defineConformanceProfile first: it throws on a malformed profile.
findings.length === 0 is NOT a conformance attestation. It means every
rule the profile declared was satisfied: nothing about the parts of the
message the profile did not cover, and nothing about clinical correctness.
No PHI in findings: each finding names the structural locus (segment / field / component / repetition) and the rule, never the offending value.
Read-only: the message is never mutated.
Parameters
message
a parsed message from parseHL7.
profile
the consumer's declarative ConformanceProfile.
Returns
the profile name and the ordered findings (empty ⇒ no declared rule violated).
Example
import { parseHL7, validateAgainstProfile, type ConformanceProfile } from "@cosyte/hl7";
const profile: ConformanceProfile = {
name: "example-adt-min",
segments: [
{ segment: "PID", usage: "R", fields: [
{ field: 3, name: "Patient Identifiers", usage: "R" },
{ field: 8, name: "Administrative Sex", usage: "RE", valueSet: ["M", "F", "U"] },
] },
],
};
const msg = parseHL7(raw);
const { findings } = validateAgainstProfile(msg, profile);
for (const f of findings) console.log(f.severity, f.code, f.message);
// findings.length === 0 ⇒ no declared rule violated (NOT an attestation)