Class SchedulerService
High-level facade for managing scheduling operations across the system. This service provides conflict detection and resolution while delegating persistence to IAppointmentRepository.
public class SchedulerService
- Inheritance
-
SchedulerService
- Inherited Members
Constructors
SchedulerService(IAppointmentRepository)
public SchedulerService(IAppointmentRepository repository)
Parameters
repositoryIAppointmentRepository
Methods
AddFacilityUnavailableBlock(UnavailableTimeInterval)
Adds a facility-wide unavailable block (holidays, emergencies, etc.)
public void AddFacilityUnavailableBlock(UnavailableTimeInterval block)
Parameters
blockUnavailableTimeInterval
AddPhysicianUnavailableBlock(Guid, UnavailableTimeInterval)
Adds a physician-specific unavailable block
public void AddPhysicianUnavailableBlock(Guid physicianId, UnavailableTimeInterval block)
Parameters
physicianIdGuidblockUnavailableTimeInterval
CancelAppointment(Guid, Guid, string)
Cancels an appointment
public bool CancelAppointment(Guid physicianId, Guid appointmentId, string reason = "")
Parameters
Returns
CheckForConflicts(AppointmentTimeInterval, Guid?, bool)
Checks for scheduling conflicts without making any changes. Used by commands for validation before execution.
public ConflictCheckResult CheckForConflicts(AppointmentTimeInterval proposedAppointment, Guid? excludeAppointmentId = null, bool includeSuggestions = false)
Parameters
proposedAppointmentAppointmentTimeIntervalThe appointment to check for conflicts
excludeAppointmentIdGuid?Optional appointment ID to exclude (for updates)
includeSuggestionsboolIf true and conflicts exist, also finds alternative time slots
Returns
- ConflictCheckResult
Conflict check result with any detected conflicts and optional suggestions
CleanupOldAppointments(DateTime)
Performs cleanup of old appointments
public int CleanupOldAppointments(DateTime beforeDate)
Parameters
beforeDateDateTime
Returns
DeleteAppointment(Guid, Guid)
Deletes an appointment from the schedule
public bool DeleteAppointment(Guid physicianId, Guid appointmentId)
Parameters
Returns
FindAppointmentById(Guid)
Finds a specific appointment by ID
public AppointmentTimeInterval? FindAppointmentById(Guid appointmentId)
Parameters
appointmentIdGuid
Returns
FindNextAvailableSlot(Guid, TimeSpan, DateTime?, IBookingStrategy?)
Finds the next available appointment slot using the specified strategy
public AppointmentSlot? FindNextAvailableSlot(Guid physicianId, TimeSpan duration, DateTime? afterTime = null, IBookingStrategy? strategy = null)
Parameters
physicianIdGuiddurationTimeSpanafterTimeDateTime?strategyIBookingStrategy
Returns
GetAllAppointments()
Gets all appointments across all physician schedules
public IEnumerable<AppointmentTimeInterval> GetAllAppointments()
Returns
GetDailySchedule(Guid, DateTime)
Gets all appointments for a physician on a specific date
public IEnumerable<AppointmentTimeInterval> GetDailySchedule(Guid physicianId, DateTime date)
Parameters
Returns
GetPatientAppointments(Guid)
Gets all appointments for a patient
public IEnumerable<AppointmentTimeInterval> GetPatientAppointments(Guid patientId)
Parameters
patientIdGuid
Returns
GetPhysicianSchedule(Guid)
Builds a physician's schedule from repository data. The schedule is built fresh each time to reflect current database state.
public PhysicianSchedule GetPhysicianSchedule(Guid physicianId)
Parameters
physicianIdGuid
Returns
GetPhysicianStatistics(Guid, DateTime, DateTime)
Gets utilization statistics for a physician
public ScheduleStatistics GetPhysicianStatistics(Guid physicianId, DateTime startDate, DateTime endDate)
Parameters
Returns
GetScheduleInRange(Guid, DateTime, DateTime)
Gets all appointments for a physician in a date range
public IEnumerable<AppointmentTimeInterval> GetScheduleInRange(Guid physicianId, DateTime startDate, DateTime endDate)
Parameters
Returns
LinkClinicalDocument(Guid, Guid?)
Links or unlinks a clinical document to/from an appointment. This persists the change to the database.
public bool LinkClinicalDocument(Guid appointmentId, Guid? clinicalDocumentId)
Parameters
appointmentIdGuidThe appointment to update
clinicalDocumentIdGuid?The document ID to link, or null to unlink
Returns
- bool
True if successful, false if appointment not found
ScheduleAppointment(AppointmentTimeInterval)
Schedules an appointment after checking for conflicts
public ScheduleResult ScheduleAppointment(AppointmentTimeInterval appointment)
Parameters
appointmentAppointmentTimeInterval
Returns
SetPhysicianAvailability(Guid, Dictionary<DayOfWeek, (TimeSpan Start, TimeSpan End)>)
Sets standard weekly availability for a physician
public void SetPhysicianAvailability(Guid physicianId, Dictionary<DayOfWeek, (TimeSpan Start, TimeSpan End)> availability)
Parameters
UpdateAppointment(Guid, string?, string?, int?, DateTime?, int?)
Updates an appointment's details (start time, duration, reason, notes, room) Validates that time/duration/room changes don't create conflicts using whitelist pattern
public ScheduleResult UpdateAppointment(Guid appointmentId, string? reason = null, string? notes = null, int? durationMinutes = null, DateTime? newStartTime = null, int? roomNumber = null)
Parameters
appointmentIdGuidreasonstringnotesstringdurationMinutesint?newStartTimeDateTime?roomNumberint?
Returns
UpdateAppointmentStatus(Guid, AppointmentStatus)
Updates an appointment's status and persists the change
public bool UpdateAppointmentStatus(Guid appointmentId, AppointmentStatus newStatus)
Parameters
appointmentIdGuidnewStatusAppointmentStatus