Skip to main content
Version: v0.0.3

Function: defineProfile()

defineProfile(opts): Profile

Build a readonly Profile from a validated options object. Invalid input throws ProfileDefinitionError with an actionable message (PROF-02): bad Z-segment names (D-05), malformed date formats (D-08), unknown top-level keys with typo hints (D-07), and missing/empty name.

opts.extends accepts a single parent Profile or an array of them. Parents are merged into the result: lineage is the parents' lineages followed by this profile's own name, dateFormats and customSegments are merged, description inherits when not supplied, and onWarning handlers are composed. With no parent, lineage === [opts.name].

Parameters

opts

DefineProfileOptions

Returns

Profile

Example

import { defineProfile } from "@cosyte/hl7";
const epic = defineProfile({
name: "epic",
description: "Epic-specific quirks and ADT date formats",
dateFormats: ["MM/DD/YYYY HH:mm:ss", "MM/DD/YYYY"],
customSegments: {
ZDP: { fields: { departmentCode: 3, departmentName: 4 } },
ZRS: { fields: { resultStatus: 1, statusDateTime: 2 } },
},
});
console.log(epic.name); // "epic"
console.log(epic.lineage); // ["epic"]
console.log(epic.describe?.());