Skip to content

Instantly share code, notes, and snippets.

@chrismahon
Last active February 14, 2016 21:35
Show Gist options
  • Save chrismahon/dabed212c59fe7d6c60f to your computer and use it in GitHub Desktop.
Save chrismahon/dabed212c59fe7d6c60f to your computer and use it in GitHub Desktop.
Appointment Scheduler
# Show me all available TimeSlots for a Staff member for a Service on a Day
@staff_member.available_time_slots.where( service=1, day=Today )
# Show me all available TimeSlots for a Service on a Day
@service.available_time_slots.where( day=Today )
# Show me all available TimeSlots for a Staff member for a Service between 2 Days grouped by Day
@staff_member.available_time_slots.where( service=1, day=>Today, day<=Today+5 ).grouped_by_day()
# Show me all available TimeSlots for a Service between 2 Days grouped by Day
@service.available_time_slots.where( day=>Today, day<=Today+5 ).grouped_by_day()
# Show me next available TimeSlot for a Staff member
@staff_member.next_available_time_slot( service=1 )
# Show me next available TimeSlot for a Service
@service.next_available_time_slot()
# Show me all Appointments for a Day
Appointments.where( day=Today )
# Show me all Appointments for a Staff member on a Day
@staff_member.appointments.where( day=Today )
# Show me all Appointments for a Service on a Day
@service.appointments.where( day=Today )
# Show me all Appointments between 2 Dates grouped by Day
Appointments.where( day=>Today, day<=Today+5).grouped_by_day()
# Show me all Appointments for a Staff member between 2 Dates grouped by Day
@staff_member.appointments.where( day=>Today, day<=Today+5 ).grouped_by_day()
# Show me all Appointments for a Staff member for a Service between 2 Dates grouped by Day
@service.appointments.where( day=>Today, day<=Today+5 ).grouped_by_day()
# Create an Appointment in a Time Slot
@time_slot.create_appointment( staff=>@staff_member, service=>@service, user=>@user )
# Modify an existing Appointment and move it to a new Time Slot
@appointment.change_time_slot( @new_time_slot )
class Appointment < ActiveRecord::Base
belongs_to :user
has_one :staff
has_one :time_slot, through: :staff
has_one :service, through: :treatments
end
class Holiday < ActiveRecord::Base
belongs_to :staff
end
class Service < ActiveRecord::Base
belongs_to :treatment
end
class Staff < ActiveRecord::Base
has_many :time_slots
has_many :appointments
has_many :holidays
has_many :services, through: :treatments
end
class TimeSlot < ActiveRecord::Base
belongs_to :staff
has_one :appointment
end
class Service < ActiveRecord::Base
has_many :services
end
@chrismahon
Copy link
Author

A TimeSlot can start at 00, 15, 30, 45 (i.e. 10:00, 10:15, 10:30, 10:45, 11:00, 11:15 etc.)
A TimeSlot can only be available/booked during a Staff members working hours (see below)

A Service has a different price depending on Staff member
A Service has a duration (i.e. one might be 10mins, one might be 1hr)
A Service has the same duration for all Staff members

A Staff member has a set of working hours (i.e. 9am to 5pm)
A Staff member cannot be booked to a TimeSlot that overlaps another TimeSlot (i.e. )
A Staff member cannot be booked when on Holiday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment