emr-types
Version:
Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation
106 lines • 3.75 kB
JavaScript
// ============================================================================
// EVENT FACTORIES
// ============================================================================
/**
* Factory functions for creating appointment domain events
*/
export const AppointmentEventFactory = {
/**
* Create an AppointmentScheduledEvent
*/
createAppointmentScheduledEvent(appointment, scheduledBy, schedulingMethod, source, previousAppointmentId) {
return {
eventId: crypto.randomUUID(),
eventType: 'AppointmentScheduled',
occurredAt: new Date(),
aggregateId: appointment.id.value,
aggregateVersion: 1,
appointmentId: appointment.id,
tenantId: appointment.tenantId,
data: {
appointment,
scheduledBy,
schedulingMethod,
...(source && { source }),
...(previousAppointmentId && { previousAppointmentId })
}
};
},
/**
* Create an AppointmentConfirmedEvent
*/
createAppointmentConfirmedEvent(appointment, confirmedBy, confirmationMethod, confirmationNotes) {
return {
eventId: crypto.randomUUID(),
eventType: 'AppointmentConfirmed',
occurredAt: new Date(),
aggregateId: appointment.id.value,
aggregateVersion: 1,
appointmentId: appointment.id,
tenantId: appointment.tenantId,
data: {
appointment,
confirmedBy,
confirmationMethod,
...(confirmationNotes && { confirmationNotes })
}
};
},
/**
* Create an AppointmentCancelledEvent
*/
createAppointmentCancelledEvent(appointment, cancelledBy, cancellationReason, cancellationFee, refundAmount, rescheduleOffered = false, rescheduleDate, notes) {
return {
eventId: crypto.randomUUID(),
eventType: 'AppointmentCancelled',
occurredAt: new Date(),
aggregateId: appointment.id.value,
aggregateVersion: 1,
appointmentId: appointment.id,
tenantId: appointment.tenantId,
data: {
appointment,
cancelledBy,
cancellationTime: new Date(),
cancellationReason,
...(cancellationFee && { cancellationFee }),
...(refundAmount && { refundAmount }),
rescheduleOffered,
...(rescheduleDate && { rescheduleDate }),
...(notes && { notes })
}
};
}
};
// ============================================================================
// TYPE GUARDS
// ============================================================================
/**
* Type guard to check if an event is an AppointmentScheduledEvent
*/
export function isAppointmentScheduledEvent(event) {
return event.eventType === 'AppointmentScheduled';
}
/**
* Type guard to check if an event is an AppointmentConfirmedEvent
*/
export function isAppointmentConfirmedEvent(event) {
return event.eventType === 'AppointmentConfirmed';
}
/**
* Type guard to check if an event is an AppointmentCancelledEvent
*/
export function isAppointmentCancelledEvent(event) {
return event.eventType === 'AppointmentCancelled';
}
/**
* Type guard to check if an event is an AppointmentDomainEvent
*/
export function isAppointmentDomainEvent(event) {
return (typeof event === 'object' &&
event !== null &&
'eventType' in event &&
'appointmentId' in event &&
'tenantId' in event);
}
//# sourceMappingURL=AppointmentDomainEvent.js.map