Table of Contents

Class SchedulerService

Namespace
Core.CliniCore.Service
Assembly
Core.CliniCore.dll

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

repository IAppointmentRepository

Methods

AddFacilityUnavailableBlock(UnavailableTimeInterval)

Adds a facility-wide unavailable block (holidays, emergencies, etc.)

public void AddFacilityUnavailableBlock(UnavailableTimeInterval block)

Parameters

block UnavailableTimeInterval

AddPhysicianUnavailableBlock(Guid, UnavailableTimeInterval)

Adds a physician-specific unavailable block

public void AddPhysicianUnavailableBlock(Guid physicianId, UnavailableTimeInterval block)

Parameters

physicianId Guid
block UnavailableTimeInterval

CancelAppointment(Guid, Guid, string)

Cancels an appointment

public bool CancelAppointment(Guid physicianId, Guid appointmentId, string reason = "")

Parameters

physicianId Guid
appointmentId Guid
reason string

Returns

bool

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

proposedAppointment AppointmentTimeInterval

The appointment to check for conflicts

excludeAppointmentId Guid?

Optional appointment ID to exclude (for updates)

includeSuggestions bool

If 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

beforeDate DateTime

Returns

int

DeleteAppointment(Guid, Guid)

Deletes an appointment from the schedule

public bool DeleteAppointment(Guid physicianId, Guid appointmentId)

Parameters

physicianId Guid
appointmentId Guid

Returns

bool

FindAppointmentById(Guid)

Finds a specific appointment by ID

public AppointmentTimeInterval? FindAppointmentById(Guid appointmentId)

Parameters

appointmentId Guid

Returns

AppointmentTimeInterval

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

physicianId Guid
duration TimeSpan
afterTime DateTime?
strategy IBookingStrategy

Returns

AppointmentSlot

GetAllAppointments()

Gets all appointments across all physician schedules

public IEnumerable<AppointmentTimeInterval> GetAllAppointments()

Returns

IEnumerable<AppointmentTimeInterval>

GetDailySchedule(Guid, DateTime)

Gets all appointments for a physician on a specific date

public IEnumerable<AppointmentTimeInterval> GetDailySchedule(Guid physicianId, DateTime date)

Parameters

physicianId Guid
date DateTime

Returns

IEnumerable<AppointmentTimeInterval>

GetPatientAppointments(Guid)

Gets all appointments for a patient

public IEnumerable<AppointmentTimeInterval> GetPatientAppointments(Guid patientId)

Parameters

patientId Guid

Returns

IEnumerable<AppointmentTimeInterval>

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

physicianId Guid

Returns

PhysicianSchedule

GetPhysicianStatistics(Guid, DateTime, DateTime)

Gets utilization statistics for a physician

public ScheduleStatistics GetPhysicianStatistics(Guid physicianId, DateTime startDate, DateTime endDate)

Parameters

physicianId Guid
startDate DateTime
endDate DateTime

Returns

ScheduleStatistics

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

physicianId Guid
startDate DateTime
endDate DateTime

Returns

IEnumerable<AppointmentTimeInterval>

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

appointmentId Guid

The appointment to update

clinicalDocumentId Guid?

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

appointment AppointmentTimeInterval

Returns

ScheduleResult

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

physicianId Guid
availability Dictionary<DayOfWeek, (TimeSpan Start, TimeSpan End)>

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

appointmentId Guid
reason string
notes string
durationMinutes int?
newStartTime DateTime?
roomNumber int?

Returns

ScheduleResult

UpdateAppointmentStatus(Guid, AppointmentStatus)

Updates an appointment's status and persists the change

public bool UpdateAppointmentStatus(Guid appointmentId, AppointmentStatus newStatus)

Parameters

appointmentId Guid
newStatus AppointmentStatus

Returns

bool