[ UPDATED SCHEMA: https://i.stack.imgur.com/kBtno.png ]
I'm tasked with developing an appointment booking system that is designed for a small medical office. It is a Rails 3.2 app.
I'm having difficulty designing a database schema that makes sense to me.
Question: Given the following information, what is the correct relationship between doctors, patients, appointments, chairs and time_slots?
Patients need to make appointments with a doctor's office. Depending on the type of appointment, each appointment is scheduled for one or more adjacent time_slots, and whether or not there can be two appointments scheduled for time_slots with the same start_time and end_time is determined by appointment type. (Double-booking is allowed based on the type of appointments.)
App Specs:
- Registered users make appointments via an appointment request form on the website.
- Appointments take up a certain pre-set amount of adjacent time_slots. This is determined by appointment category/type. This length can be adjusted by the admin, as well as the length of each time_slot.
- To help speed up the request process, unavailable/already-booked times are hidden from the calendar on the appointment request form.
- On the admin-facing interface, administrators can confirm an appointment-request and make an appointment, and they can also update, create and delete scheduled appointments.
- All appointments are held in a "chair"--like a dentist's chair. An office has multiple chairs. One patient per chair for a given booked time slot.
- Appointments have fields for date, time of day, length appointment_type, double_bookable? (determined by appointment_type). Time_slots have a start_time and end_time, and a date.
- There is only one doctor in this office. But, certain types of appointments--that are less demanding of the doc's time-can be double-booked. In essence, two teeth cleanings can be booked for the same time slot, as long as they are held in **separate chairs**.
My Relationships:
Office < ActiveRecord::Base
has_many :doctors
Doctor < ActiveRecord::Base
has_many :patients
belongs_to :offices
Patient < ActiveRecord::Base
belongs_to :doctor
has_many :appointments
Appointment < ActiveRecord::Base
belongs_to :patient
has_many :filled_time_slots
FilledTimeSlot < ActiveRecord::Base
belongs_to :appointment
belongs_to :time_slot
TimeSlot < ActiveRecord::Base
has_many :filled_time_slots
belongs_to :chair
Chair < ActiveRecord::Base
has_many :time_slots