emr-types
Version:
Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation
161 lines • 5.65 kB
JavaScript
// ============================================================================
// APPOINTMENT DOMAIN EXPORTS
// ============================================================================
// Entities
export * from './entities/Appointment';
// Value Objects
export * from './value-objects/AppointmentId';
// Events
export * from './events/AppointmentDomainEvent';
export { AppointmentStatus, AppointmentType, SlotType, BookingMethod, LocationType, FacilityType, AppointmentInsuranceType, BillingStatus, AppointmentPaymentMethod, ReminderMethod, AppointmentContactMethod, RefundPolicy, ReschedulePolicy, NoShowPolicy, ApprovalStatus, TreatmentEffectiveness, PatientCompliance, ReadmissionRisk, RecurrenceFrequency, DayOfWeek } from './entities/Appointment';
// ============================================================================
// DOMAIN-SPECIFIC UTILITIES
// ============================================================================
/**
* Appointment domain utilities for common operations
*/
export const AppointmentDomainUtils = {
/**
* Calculate appointment duration in minutes
*/
calculateDuration(startTime, endTime) {
const diffMs = endTime.getTime() - startTime.getTime();
return Math.round(diffMs / (1000 * 60));
},
/**
* Check if appointment is overdue
*/
isOverdue(appointment) {
const now = new Date();
return appointment.startTime < now && appointment.status !== 'completed' && appointment.status !== 'cancelled';
},
/**
* Check if appointment is within cancellation window
*/
isWithinCancellationWindow(appointment, cancellationWindowHours) {
const now = new Date();
const appointmentTime = appointment.startTime;
const diffMs = appointmentTime.getTime() - now.getTime();
const diffHours = diffMs / (1000 * 60 * 60);
return diffHours >= cancellationWindowHours;
},
/**
* Generate appointment code
*/
generateAppointmentCode(tenantId, sequence) {
const tenantPrefix = tenantId.substring(0, 3).toUpperCase();
const datePrefix = new Date().toISOString().slice(2, 8).replace(/-/g, '');
const paddedSequence = sequence.toString().padStart(4, '0');
return `${tenantPrefix}${datePrefix}${paddedSequence}`;
},
/**
* Validate appointment data
*/
validateAppointmentData(appointment) {
const errors = [];
if (!appointment.startTime) {
errors.push('Start time is required');
}
if (!appointment.endTime) {
errors.push('End time is required');
}
if (appointment.startTime && appointment.endTime && appointment.startTime >= appointment.endTime) {
errors.push('Start time must be before end time');
}
if (!appointment.patientId) {
errors.push('Patient ID is required');
}
if (!appointment.doctorId) {
errors.push('Doctor ID is required');
}
if (!appointment.appointmentType) {
errors.push('Appointment type is required');
}
return {
isValid: errors.length === 0,
errors
};
},
/**
* Calculate wait time in minutes
*/
calculateWaitTime(checkInTime, appointmentStartTime) {
const diffMs = appointmentStartTime.getTime() - checkInTime.getTime();
return Math.round(diffMs / (1000 * 60));
},
/**
* Check if appointment is in progress
*/
isInProgress(appointment) {
const now = new Date();
return (appointment.status === 'in_progress' &&
appointment.startTime <= now &&
appointment.endTime >= now);
},
/**
* Get appointment status category
*/
getStatusCategory(status) {
switch (status) {
case 'scheduled':
case 'confirmed':
case 'pending':
return 'scheduled';
case 'checked_in':
case 'in_progress':
case 'on_hold':
return 'active';
case 'completed':
return 'completed';
case 'cancelled':
case 'no_show':
case 'rescheduled':
return 'cancelled';
default:
return 'scheduled';
}
}
};
// ============================================================================
// TYPE GUARDS
// ============================================================================
/**
* Type guard to check if a value is an Appointment entity
*/
export function isAppointment(value) {
return (typeof value === 'object' &&
value !== null &&
'id' in value &&
'tenantId' in value &&
'appointmentCode' in value &&
'appointmentType' in value &&
'startTime' in value &&
'endTime' in value);
}
/**
* Type guard to check if a value is an AppointmentSlot
*/
export function isAppointmentSlot(value) {
return (typeof value === 'object' &&
value !== null &&
'id' in value &&
'tenantId' in value &&
'doctorId' in value &&
'date' in value &&
'startTime' in value &&
'endTime' in value &&
'slotType' in value);
}
/**
* Type guard to check if a value is an AppointmentLocation
*/
export function isAppointmentLocation(value) {
return (typeof value === 'object' &&
value !== null &&
'id' in value &&
'name' in value &&
'type' in value &&
'address' in value &&
'facilityType' in value);
}
//# sourceMappingURL=index.js.map