/**
 * Healthcare Data Domain Example
 *
 * This file demonstrates how to create a comprehensive healthcare data domain
 * using the API Client Core modeling system. It follows the business-first approach
 * and demonstrates proper use of namespaces, models, entities, properties,
 * associations, and semantic annotations.
 *
 * The example includes:
 * - Patient Management with demographics, medical history, and contact information
 * - Provider Management with doctors, nurses, specialists, and facilities
 * - Appointment Scheduling with availability, booking, and scheduling rules
 * - Medical Records with diagnoses, treatments, prescriptions, and lab results
 * - Insurance & Billing with claims, coverage, and payment processing
 * - Compliance features for HIPAA, audit trails, and data privacy
 *
 * @example
 * ```typescript
 * import { createHealthcareDomain } from './healthcare-domain.js'
 *
 * const domain = createHealthcareDomain()
 * console.log('Healthcare domain created with', domain.graph.nodeCount(), 'nodes')
 * ```
 */
import { DataDomain } from '../../../DataDomain.js';
import { createSummarySemantic } from '../../../definitions/Summary.js';
import { addIdField, addNameField, addDescriptionField, addEmailField, addFirstNameField, addLastNameField, addPhoneField, addCustomStatusField, addCreatedAtField, addUpdatedAtField, addBooleanField, addCurrencyAmountField, } from '../../../helpers/Intelisense.js';
function createDomain() {
    return new DataDomain({
        info: {
            name: 'Healthcare Management Platform',
            displayName: 'Healthcare Management Platform',
            description: 'A comprehensive healthcare management platform with patient care, provider management, ' +
                'appointment scheduling, and medical records',
        },
    });
}
/**
 * Creates a comprehensive healthcare data domain following domain-driven design principles.
 *
 * This function demonstrates the proper hierarchy and organization for a healthcare platform:
 * 1. Creates the root DataDomain for the healthcare platform
 * 2. Organizes functionality into logical namespaces (Patient Care, Provider Management, etc.)
 * 3. Groups related entities into models within each namespace
 * 4. Defines entities with proper semantic annotations for healthcare workflows
 * 5. Establishes associations with appropriate cardinality for patient-provider relationships
 *
 * @returns A fully configured DataDomain with all healthcare entities and relationships
 */
export default function createHealthcareDomain(options = {}) {
    // Ensure the root data domain
    const domain = options.domain ?? createDomain();
    //
    // 1. PATIENT CARE NAMESPACE
    //
    const patientCare = domain.addNamespace({
        info: {
            name: 'PatientCare',
            displayName: 'Patient Care',
            description: 'Patient management, demographics, and medical history',
        },
    });
    // Patient Management Model
    const patientModel = patientCare.addModel({
        info: {
            name: 'Patients',
            displayName: 'Patient Management',
            description: 'Patient records and demographic information',
        },
    });
    // Patient Entity
    const patientEntity = patientModel.addEntity({
        info: {
            name: 'patient',
            displayName: 'Patient',
            description: 'Patient record with demographic and medical information',
        },
    });
    addIdField(patientEntity, { displayName: 'Patient ID', description: 'Unique identifier for the patient' });
    patientEntity.addProperty({
        info: { name: 'mrn', displayName: 'Medical Record Number', description: 'Medical record number for the patient' },
        type: 'string',
        required: true,
        unique: true,
        schema: { defaultValue: { type: 'function', value: 'uuid-v4' } },
    });
    addFirstNameField(patientEntity, { description: 'Patient first name' });
    addLastNameField(patientEntity, { description: 'Patient last name' });
    patientEntity.addProperty({
        info: { name: 'date_of_birth', displayName: 'Date of Birth', description: 'Patient date of birth' },
        type: 'date',
        required: true,
    });
    patientEntity.addProperty({
        info: { name: 'gender', displayName: 'Gender', description: 'Patient gender identity' },
        type: 'string',
        required: true,
        schema: {
            enum: ['male', 'female', 'other', 'prefer_not_to_say'],
        },
    });
    addPhoneField(patientEntity, { description: 'Patient primary phone number' });
    addEmailField(patientEntity, { description: 'Patient email address' });
    patientEntity.addProperty({
        info: {
            name: 'emergency_contact_name',
            displayName: 'Emergency Contact Name',
            description: 'Name of emergency contact',
        },
        type: 'string',
    });
    addPhoneField(patientEntity, {
        name: 'emergency_contact_phone',
        displayName: 'Emergency Contact Phone',
        description: 'Phone number of emergency contact',
    });
    patientEntity.addProperty({
        info: { name: 'blood_type', displayName: 'Blood Type', description: 'Patient blood type' },
        type: 'string',
        schema: {
            enum: ['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-'],
        },
    });
    patientEntity.addProperty({
        info: { name: 'allergies', displayName: 'Allergies', description: 'Known allergies and reactions' },
        type: 'string',
    });
    patientEntity.addProperty({
        info: { name: 'medical_history', displayName: 'Medical History', description: 'Summary of medical history' },
        type: 'string',
        semantics: [createSummarySemantic()],
    });
    addCustomStatusField(patientEntity, ['active', 'inactive', 'deceased'], {
        displayName: 'Patient Status',
        description: 'Current status of the patient',
    });
    addCreatedAtField(patientEntity, { description: 'When the patient record was created' });
    addUpdatedAtField(patientEntity, { description: 'When the patient record was last updated' });
    // Address Entity
    const addressEntity = patientModel.addEntity({
        info: {
            name: 'address',
            displayName: 'Address',
            description: 'Patient address information',
        },
    });
    addIdField(addressEntity, { displayName: 'Address ID', description: 'Unique identifier for the address' });
    addressEntity.addProperty({
        info: { name: 'type', displayName: 'Address Type', description: 'Type of address (home, work, billing)' },
        type: 'string',
        required: true,
        schema: {
            enum: ['home', 'work', 'billing', 'mailing'],
        },
    });
    addressEntity.addProperty({
        info: { name: 'line1', displayName: 'Address Line 1', description: 'Primary street address' },
        type: 'string',
        required: true,
    });
    addressEntity.addProperty({
        info: { name: 'line2', displayName: 'Address Line 2', description: 'Secondary address information' },
        type: 'string',
    });
    addressEntity.addProperty({
        info: { name: 'city', displayName: 'City', description: 'City name' },
        type: 'string',
        required: true,
    });
    addressEntity.addProperty({
        info: { name: 'state', displayName: 'State/Province', description: 'State or province' },
        type: 'string',
        required: true,
    });
    addressEntity.addProperty({
        info: { name: 'postal_code', displayName: 'ZIP/Postal Code', description: 'ZIP or postal code' },
        type: 'string',
        required: true,
    });
    addressEntity.addProperty({
        info: { name: 'country', displayName: 'Country', description: 'Country name' },
        type: 'string',
        required: true,
    });
    // Patient-Address Association (One-to-Many)
    patientEntity.addAssociation({ key: addressEntity.key }, {
        info: {
            name: 'addresses',
            displayName: 'Patient Addresses',
            description: 'Addresses associated with the patient',
        },
        required: false,
        multiple: true,
    });
    //
    // 2. PROVIDER MANAGEMENT NAMESPACE
    //
    const providerManagement = domain.addNamespace({
        info: {
            name: 'ProviderManagement',
            displayName: 'Provider Management',
            description: 'Healthcare providers, staff, and facility management',
        },
    });
    // Provider Model
    const providerModel = providerManagement.addModel({
        info: {
            name: 'Providers',
            displayName: 'Provider Management',
            description: 'Healthcare providers and staff',
        },
    });
    // Provider Entity
    const providerEntity = providerModel.addEntity({
        info: {
            name: 'provider',
            displayName: 'Healthcare Provider',
            description: 'Healthcare provider or medical staff member',
        },
    });
    addIdField(providerEntity, { displayName: 'Provider ID', description: 'Unique identifier for the provider' });
    addFirstNameField(providerEntity, { description: 'Provider first name' });
    addLastNameField(providerEntity, { description: 'Provider last name' });
    providerEntity.addProperty({
        info: { name: 'npi', displayName: 'NPI Number', description: 'National Provider Identifier' },
        type: 'string',
        required: true,
        unique: true,
    });
    providerEntity.addProperty({
        info: { name: 'license_number', displayName: 'License Number', description: 'Medical license number' },
        type: 'string',
        required: true,
    });
    addEmailField(providerEntity, { description: 'Provider email address' });
    addPhoneField(providerEntity, { description: 'Provider phone number' });
    addCustomStatusField(providerEntity, ['active', 'inactive', 'suspended'], {
        displayName: 'Provider Status',
        description: 'Current status of the provider',
    });
    providerEntity.addProperty({
        info: { name: 'provider_type', displayName: 'Provider Type', description: 'Type of healthcare provider' },
        type: 'string',
        required: true,
        schema: {
            enum: ['doctor', 'nurse', 'specialist', 'therapist', 'technician'],
        },
    });
    providerEntity.addProperty({
        info: {
            name: 'specialty',
            displayName: 'Medical Specialty',
            description: 'Medical specialty or area of expertise',
        },
        type: 'string',
        required: false,
        schema: {
            enum: ['cardiology', 'dermatology', 'neurology', 'orthopedics', 'pediatrics', 'general'],
        },
    });
    addCreatedAtField(providerEntity, { description: 'When the provider record was created' });
    addUpdatedAtField(providerEntity, { description: 'When the provider record was last updated' });
    // Facility Entity
    const facilityEntity = providerModel.addEntity({
        info: {
            name: 'facility',
            displayName: 'Healthcare Facility',
            description: 'Hospital, clinic, or medical facility',
        },
    });
    addIdField(facilityEntity, { displayName: 'Facility ID', description: 'Unique identifier for the facility' });
    addNameField(facilityEntity, { displayName: 'Facility Name', description: 'Name of the healthcare facility' });
    addDescriptionField(facilityEntity, { description: 'Description of the facility and services offered' });
    facilityEntity.addProperty({
        info: { name: 'facility_type', displayName: 'Facility Type', description: 'Type of healthcare facility' },
        type: 'string',
        required: true,
        schema: {
            enum: ['hospital', 'clinic', 'urgent_care', 'specialty_center', 'laboratory'],
        },
    });
    addPhoneField(facilityEntity, { description: 'Facility phone number' });
    facilityEntity.addProperty({
        info: { name: 'address', displayName: 'Facility Address', description: 'Physical address of the facility' },
        type: 'string',
        required: true,
    });
    addCustomStatusField(facilityEntity, ['active', 'inactive', 'temporary_closed'], {
        displayName: 'Facility Status',
        description: 'Current status of the facility',
    });
    addCreatedAtField(facilityEntity, { description: 'When the facility record was created' });
    // Provider-Facility Association (Many-to-Many)
    providerEntity.addAssociation({ key: facilityEntity.key }, {
        info: {
            name: 'facilities',
            displayName: 'Provider Facilities',
            description: 'Facilities where this provider works',
        },
        required: false,
        multiple: true,
    });
    //
    // 3. APPOINTMENT SCHEDULING NAMESPACE
    //
    const appointmentScheduling = domain.addNamespace({
        info: {
            name: 'AppointmentScheduling',
            displayName: 'Appointment Scheduling',
            description: 'Appointment booking, scheduling, and availability management',
        },
    });
    // Appointment Model
    const appointmentModel = appointmentScheduling.addModel({
        info: {
            name: 'Appointments',
            displayName: 'Appointment Management',
            description: 'Patient appointments and scheduling',
        },
    });
    // Appointment Entity
    const appointmentEntity = appointmentModel.addEntity({
        info: {
            name: 'appointment',
            displayName: 'Appointment',
            description: 'Patient appointment with healthcare provider',
        },
    });
    addIdField(appointmentEntity, { displayName: 'Appointment ID', description: 'Unique identifier for the appointment' });
    appointmentEntity.addProperty({
        info: { name: 'appointment_date', displayName: 'Appointment Date', description: 'Date of the appointment' },
        type: 'date',
        required: true,
    });
    appointmentEntity.addProperty({
        info: { name: 'start_time', displayName: 'Start Time', description: 'Appointment start time' },
        type: 'time',
        required: true,
    });
    appointmentEntity.addProperty({
        info: { name: 'end_time', displayName: 'End Time', description: 'Appointment end time' },
        type: 'time',
        required: true,
    });
    appointmentEntity.addProperty({
        info: {
            name: 'duration_minutes',
            displayName: 'Duration (Minutes)',
            description: 'Appointment duration in minutes',
        },
        type: 'number',
        required: true,
        schema: {
            minimum: 15,
            maximum: 480,
        },
    });
    addCustomStatusField(appointmentEntity, ['scheduled', 'confirmed', 'in_progress', 'completed', 'cancelled', 'no_show'], {
        displayName: 'Appointment Status',
        description: 'Current status of the appointment',
    });
    appointmentEntity.addProperty({
        info: { name: 'reason', displayName: 'Appointment Reason', description: 'Reason for the appointment' },
        type: 'string',
    });
    appointmentEntity.addProperty({
        info: { name: 'notes', displayName: 'Appointment Notes', description: 'Additional notes for the appointment' },
        type: 'string',
    });
    addCreatedAtField(appointmentEntity, { description: 'When the appointment was created' });
    addUpdatedAtField(appointmentEntity, { description: 'When the appointment was last updated' });
    // Appointment-Patient Association (Many-to-One)
    appointmentEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient for this appointment' },
        required: true,
        multiple: false,
    });
    // Appointment-Provider Association (Many-to-One)
    appointmentEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Healthcare provider for this appointment' },
        required: true,
        multiple: false,
    });
    // Appointment-Facility Association (Many-to-One)
    appointmentEntity.addAssociation({ key: facilityEntity.key }, {
        info: { name: 'facility', displayName: 'Facility', description: 'Facility where appointment takes place' },
        required: true,
        multiple: false,
    });
    // Availability Model
    const availabilityModel = appointmentScheduling.addModel({
        info: {
            name: 'Availability',
            displayName: 'Provider Availability',
            description: 'Provider availability and scheduling rules',
        },
    });
    // Provider Availability Entity
    const availabilityEntity = availabilityModel.addEntity({
        info: {
            name: 'provider_availability',
            displayName: 'Provider Availability',
            description: 'Provider availability schedule and rules',
        },
    });
    addIdField(availabilityEntity, { displayName: 'Availability ID', description: 'Unique identifier for availability' });
    availabilityEntity.addProperty({
        info: { name: 'day_of_week', displayName: 'Day of Week', description: 'Day of the week for availability' },
        type: 'string',
        required: true,
        schema: {
            enum: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'],
        },
    });
    availabilityEntity.addProperty({
        info: { name: 'start_time', displayName: 'Start Time', description: 'Start time for availability' },
        type: 'time',
        required: true,
    });
    availabilityEntity.addProperty({
        info: { name: 'end_time', displayName: 'End Time', description: 'End time for availability' },
        type: 'time',
        required: true,
    });
    addBooleanField(availabilityEntity, 'is_available', 'true', {
        displayName: 'Is Available',
        description: 'Whether the provider is available during this time',
    });
    // Availability-Provider Association (Many-to-One)
    availabilityEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Provider for this availability' },
        required: true,
        multiple: false,
    });
    //
    // 4. MEDICAL RECORDS NAMESPACE
    //
    const medicalRecords = domain.addNamespace({
        info: {
            name: 'MedicalRecords',
            displayName: 'Medical Records',
            description: 'Medical records, diagnoses, treatments, and lab results',
        },
    });
    // Medical Records Model
    const medicalRecordsModel = medicalRecords.addModel({
        info: {
            name: 'MedicalRecords',
            displayName: 'Medical Records Management',
            description: 'Patient medical records and documentation',
        },
    });
    // Diagnosis Entity
    const diagnosisEntity = medicalRecordsModel.addEntity({
        info: {
            name: 'diagnosis',
            displayName: 'Diagnosis',
            description: 'Medical diagnosis for a patient',
        },
    });
    addIdField(diagnosisEntity, { displayName: 'Diagnosis ID', description: 'Unique identifier for the diagnosis' });
    diagnosisEntity.addProperty({
        info: { name: 'icd_code', displayName: 'ICD Code', description: 'International Classification of Diseases code' },
        type: 'string',
        required: true,
    });
    diagnosisEntity.addProperty({
        info: { name: 'diagnosis_name', displayName: 'Diagnosis Name', description: 'Name of the diagnosis' },
        type: 'string',
        required: true,
    });
    addDescriptionField(diagnosisEntity, { description: 'Detailed description of the diagnosis' });
    diagnosisEntity.addProperty({
        info: { name: 'diagnosis_date', displayName: 'Diagnosis Date', description: 'Date when diagnosis was made' },
        type: 'date',
        required: true,
    });
    addCustomStatusField(diagnosisEntity, ['active', 'resolved', 'chronic'], {
        displayName: 'Diagnosis Status',
        description: 'Current status of the diagnosis',
    });
    addCreatedAtField(diagnosisEntity, { description: 'When the diagnosis was created' });
    // Diagnosis-Patient Association (Many-to-One)
    diagnosisEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient with this diagnosis' },
        required: true,
        multiple: false,
    });
    // Diagnosis-Provider Association (Many-to-One)
    diagnosisEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Provider who made the diagnosis' },
        required: true,
        multiple: false,
    });
    // Treatment Entity
    const treatmentEntity = medicalRecordsModel.addEntity({
        info: {
            name: 'treatment',
            displayName: 'Treatment',
            description: 'Medical treatment or procedure',
        },
    });
    addIdField(treatmentEntity, { displayName: 'Treatment ID', description: 'Unique identifier for the treatment' });
    addNameField(treatmentEntity, { displayName: 'Treatment Name', description: 'Name of the treatment or procedure' });
    addDescriptionField(treatmentEntity, { description: 'Detailed description of the treatment' });
    treatmentEntity.addProperty({
        info: { name: 'treatment_date', displayName: 'Treatment Date', description: 'Date when treatment was performed' },
        type: 'date',
        required: true,
    });
    addCustomStatusField(treatmentEntity, ['planned', 'in_progress', 'completed', 'cancelled'], {
        displayName: 'Treatment Status',
        description: 'Current status of the treatment',
    });
    addCreatedAtField(treatmentEntity, { description: 'When the treatment was created' });
    // Treatment-Patient Association (Many-to-One)
    treatmentEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient receiving the treatment' },
        required: true,
        multiple: false,
    });
    // Treatment-Provider Association (Many-to-One)
    treatmentEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Provider performing the treatment' },
        required: true,
        multiple: false,
    });
    // Treatment-Diagnosis Association (Many-to-Many)
    treatmentEntity.addAssociation({ key: diagnosisEntity.key }, {
        info: { name: 'diagnoses', displayName: 'Related Diagnoses', description: 'Diagnoses related to this treatment' },
        required: false,
        multiple: true,
    });
    // Prescription Entity
    const prescriptionEntity = medicalRecordsModel.addEntity({
        info: {
            name: 'prescription',
            displayName: 'Prescription',
            description: 'Medication prescription',
        },
    });
    addIdField(prescriptionEntity, {
        displayName: 'Prescription ID',
        description: 'Unique identifier for the prescription',
    });
    prescriptionEntity.addProperty({
        info: { name: 'medication_name', displayName: 'Medication Name', description: 'Name of the prescribed medication' },
        type: 'string',
        required: true,
    });
    prescriptionEntity.addProperty({
        info: { name: 'dosage', displayName: 'Dosage', description: 'Prescribed dosage information' },
        type: 'string',
        required: true,
    });
    prescriptionEntity.addProperty({
        info: { name: 'frequency', displayName: 'Frequency', description: 'How often to take the medication' },
        type: 'string',
        required: true,
    });
    prescriptionEntity.addProperty({
        info: { name: 'duration_days', displayName: 'Duration (Days)', description: 'Duration of prescription in days' },
        type: 'number',
        required: true,
        schema: {
            minimum: 1,
        },
    });
    prescriptionEntity.addProperty({
        info: {
            name: 'prescribed_date',
            displayName: 'Prescribed Date',
            description: 'Date when medication was prescribed',
        },
        type: 'date',
        required: true,
    });
    addCustomStatusField(prescriptionEntity, ['active', 'completed', 'discontinued'], {
        displayName: 'Prescription Status',
        description: 'Current status of the prescription',
    });
    addCreatedAtField(prescriptionEntity, { description: 'When the prescription was created' });
    // Prescription-Patient Association (Many-to-One)
    prescriptionEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient prescribed the medication' },
        required: true,
        multiple: false,
    });
    // Prescription-Provider Association (Many-to-One)
    prescriptionEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Provider who prescribed the medication' },
        required: true,
        multiple: false,
    });
    // Lab Result Entity
    const labResultEntity = medicalRecordsModel.addEntity({
        info: {
            name: 'lab_result',
            displayName: 'Lab Result',
            description: 'Laboratory test results',
        },
    });
    addIdField(labResultEntity, { displayName: 'Lab Result ID', description: 'Unique identifier for the lab result' });
    addNameField(labResultEntity, { displayName: 'Test Name', description: 'Name of the laboratory test' });
    labResultEntity.addProperty({
        info: { name: 'test_date', displayName: 'Test Date', description: 'Date when the test was performed' },
        type: 'date',
        required: true,
    });
    labResultEntity.addProperty({
        info: { name: 'result_value', displayName: 'Result Value', description: 'Numerical or text result value' },
        type: 'string',
        required: true,
    });
    labResultEntity.addProperty({
        info: {
            name: 'reference_range',
            displayName: 'Reference Range',
            description: 'Normal reference range for the test',
        },
        type: 'string',
    });
    addCustomStatusField(labResultEntity, ['normal', 'abnormal', 'critical', 'pending'], {
        displayName: 'Result Status',
        description: 'Status of the lab result',
    });
    addDescriptionField(labResultEntity, { description: 'Additional notes about the lab result' });
    addCreatedAtField(labResultEntity, { description: 'When the lab result was created' });
    // LabResult-Patient Association (Many-to-One)
    labResultEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient for this lab result' },
        required: true,
        multiple: false,
    });
    // LabResult-Provider Association (Many-to-One)
    labResultEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Provider who ordered the test' },
        required: true,
        multiple: false,
    });
    //
    // 5. INSURANCE & BILLING NAMESPACE
    //
    const insuranceBilling = domain.addNamespace({
        info: {
            name: 'InsuranceBilling',
            displayName: 'Insurance & Billing',
            description: 'Insurance coverage, claims, and billing management',
        },
    });
    // Insurance Model
    const insuranceModel = insuranceBilling.addModel({
        info: {
            name: 'Insurance',
            displayName: 'Insurance Management',
            description: 'Insurance coverage and policy information',
        },
    });
    // Insurance Policy Entity
    const insurancePolicyEntity = insuranceModel.addEntity({
        info: {
            name: 'insurance_policy',
            displayName: 'Insurance Policy',
            description: 'Patient insurance policy information',
        },
    });
    addIdField(insurancePolicyEntity, { displayName: 'Policy ID', description: 'Unique identifier for the policy' });
    insurancePolicyEntity.addProperty({
        info: { name: 'policy_number', displayName: 'Policy Number', description: 'Insurance policy number' },
        type: 'string',
        required: true,
        unique: true,
    });
    addNameField(insurancePolicyEntity, {
        displayName: 'Insurance Provider',
        description: 'Name of the insurance provider',
    });
    addCustomStatusField(insurancePolicyEntity, ['active', 'inactive', 'expired', 'pending'], {
        displayName: 'Policy Status',
        description: 'Current status of the insurance policy',
    });
    insurancePolicyEntity.addProperty({
        info: { name: 'effective_date', displayName: 'Effective Date', description: 'Date when policy becomes effective' },
        type: 'date',
        required: true,
    });
    insurancePolicyEntity.addProperty({
        info: { name: 'expiration_date', displayName: 'Expiration Date', description: 'Date when policy expires' },
        type: 'date',
        required: true,
    });
    addCurrencyAmountField(insurancePolicyEntity, 'deductible', 'Deductible Amount', {
        description: 'Annual deductible amount',
    });
    addCurrencyAmountField(insurancePolicyEntity, 'copay', 'Copay Amount', {
        description: 'Copay amount for office visits',
    });
    addCreatedAtField(insurancePolicyEntity, { description: 'When the policy was created' });
    // InsurancePolicy-Patient Association (Many-to-One)
    insurancePolicyEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient covered by this policy' },
        required: true,
        multiple: false,
    });
    // Claim Entity
    const claimEntity = insuranceModel.addEntity({
        info: {
            name: 'claim',
            displayName: 'Insurance Claim',
            description: 'Insurance claim for medical services',
        },
    });
    addIdField(claimEntity, { displayName: 'Claim ID', description: 'Unique identifier for the claim' });
    claimEntity.addProperty({
        info: { name: 'claim_number', displayName: 'Claim Number', description: 'Insurance claim number' },
        type: 'string',
        required: true,
        unique: true,
    });
    addCurrencyAmountField(claimEntity, 'billed_amount', 'Billed Amount', {
        description: 'Amount billed to insurance',
    });
    addCurrencyAmountField(claimEntity, 'approved_amount', 'Approved Amount', {
        description: 'Amount approved by insurance',
    });
    addCurrencyAmountField(claimEntity, 'patient_responsibility', 'Patient Responsibility', {
        description: 'Amount patient is responsible for',
    });
    addCustomStatusField(claimEntity, ['submitted', 'processing', 'approved', 'denied', 'paid'], {
        displayName: 'Claim Status',
        description: 'Current status of the insurance claim',
    });
    claimEntity.addProperty({
        info: { name: 'service_date', displayName: 'Service Date', description: 'Date when service was provided' },
        type: 'date',
        required: true,
    });
    addCreatedAtField(claimEntity, { description: 'When the claim was created' });
    // Claim-Patient Association (Many-to-One)
    claimEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient for this claim' },
        required: true,
        multiple: false,
    });
    // Claim-Provider Association (Many-to-One)
    claimEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Provider who provided the service' },
        required: true,
        multiple: false,
    });
    // Claim-InsurancePolicy Association (Many-to-One)
    claimEntity.addAssociation({ key: insurancePolicyEntity.key }, {
        info: {
            name: 'insurance_policy',
            displayName: 'Insurance Policy',
            description: 'Insurance policy for this claim',
        },
        required: true,
        multiple: false,
    });
    // Billing Model
    const billingModel = insuranceBilling.addModel({
        info: {
            name: 'Billing',
            displayName: 'Billing Management',
            description: 'Patient billing and payment processing',
        },
    });
    // Invoice Entity
    const invoiceEntity = billingModel.addEntity({
        info: {
            name: 'invoice',
            displayName: 'Invoice',
            description: 'Patient invoice for medical services',
        },
    });
    addIdField(invoiceEntity, { displayName: 'Invoice ID', description: 'Unique identifier for the invoice' });
    invoiceEntity.addProperty({
        info: { name: 'invoice_number', displayName: 'Invoice Number', description: 'Human-readable invoice number' },
        type: 'string',
        required: true,
        unique: true,
    });
    addCurrencyAmountField(invoiceEntity, 'total_amount', 'Total Amount', {
        description: 'Total amount due on the invoice',
    });
    addCurrencyAmountField(invoiceEntity, 'paid_amount', 'Paid Amount', {
        description: 'Amount already paid',
    });
    addCurrencyAmountField(invoiceEntity, 'balance_due', 'Balance Due', {
        description: 'Remaining balance due',
    });
    addCustomStatusField(invoiceEntity, ['draft', 'sent', 'paid', 'overdue', 'cancelled'], {
        displayName: 'Invoice Status',
        description: 'Current status of the invoice',
    });
    invoiceEntity.addProperty({
        info: { name: 'due_date', displayName: 'Due Date', description: 'Date when payment is due' },
        type: 'date',
        required: true,
    });
    addCreatedAtField(invoiceEntity, { description: 'When the invoice was created' });
    // Invoice-Patient Association (Many-to-One)
    invoiceEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient for this invoice' },
        required: true,
        multiple: false,
    });
    // Invoice-Provider Association (Many-to-One)
    invoiceEntity.addAssociation({ key: providerEntity.key }, {
        info: { name: 'provider', displayName: 'Provider', description: 'Provider who provided the services' },
        required: true,
        multiple: false,
    });
    // Payment Entity
    const paymentEntity = billingModel.addEntity({
        info: {
            name: 'payment',
            displayName: 'Payment',
            description: 'Payment transaction for medical services',
        },
    });
    addIdField(paymentEntity, { displayName: 'Payment ID', description: 'Unique identifier for the payment' });
    addCurrencyAmountField(paymentEntity, 'amount', 'Payment Amount', {
        description: 'Amount of the payment',
    });
    paymentEntity.addProperty({
        info: { name: 'payment_method', displayName: 'Payment Method', description: 'Method used for payment' },
        type: 'string',
        required: true,
        schema: {
            enum: ['cash', 'check', 'credit_card', 'debit_card', 'insurance', 'bank_transfer'],
        },
    });
    addCustomStatusField(paymentEntity, ['pending', 'completed', 'failed', 'refunded'], {
        displayName: 'Payment Status',
        description: 'Current status of the payment',
    });
    paymentEntity.addProperty({
        info: { name: 'payment_date', displayName: 'Payment Date', description: 'Date when payment was made' },
        type: 'date',
        required: true,
    });
    addCreatedAtField(paymentEntity, { description: 'When the payment was created' });
    // Payment-Patient Association (Many-to-One)
    paymentEntity.addAssociation({ key: patientEntity.key }, {
        info: { name: 'patient', displayName: 'Patient', description: 'Patient who made the payment' },
        required: true,
        multiple: false,
    });
    // Payment-Invoice Association (Many-to-One)
    paymentEntity.addAssociation({ key: invoiceEntity.key }, {
        info: { name: 'invoice', displayName: 'Invoice', description: 'Invoice this payment applies to' },
        required: true,
        multiple: false,
    });
    return domain;
}
//# sourceMappingURL=healthcare-domain.js.map