预约应用程序的DB模式:医生,约会,时间段,患者之间的正确关系是什么?

[更新的计划: http : //i.imgur.com/fX9CGNh.png ]

我的任务是开发一个专为小型医疗办公室设计的预约系统。 这是一个Rails 3.2应用程序。

我在设计一个对我有意义的数据库模式时遇到了困难。

问题: 鉴于以下信息,医生,患者,预约,椅子和时间段之间的正确关系是什么?

患者需要到医生办公室预约。 根据约会的类型,每个约会被安排为一个或多个相邻的time_slots,并且是否可以为具有相同start_time和end_time的time_slots安排两个约会由约会类型确定。 (根据约会类型允许双重预订。)

应用规格:

  1. 注册用户通过网站上的预约申请表进行预约。
  2. 约会占用相邻time_slots的某个预设量。 这由约会类别/类型决定。 管理员可以调整此长度,以及每个time_slot的长度。
  3. 为了帮助加快请求流程,在约会请求表单上的日历中隐藏了不可用/已预订的时间。
  4. 在面向管理员的界面上,管理员可以确认约会请求并进行预约,他们还可以更新,创建和删除预定约会。
  5. 所有约会都在“椅子”中举行 – 就像牙医的椅子一样。 办公室有多把椅子。 对于给定的预定时间段,每个椅子一名患者。
  6. 约会有日期,时间,长度约会类型,double_bookable的字段? (由appointment_type确定)。 Time_slots有一个start_time和end_time,以及一个日期。
  7. 这个办公室里只有一位医生。 但是,某些类型的约会 – 对文档的时间要求不高 – 可以加倍预订。 从本质上讲,可以在同一时间段预订两次牙齿清洁,只要它们被固定在**单独的椅子上**。

我的关系

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 

我会在TimeSlot中添加一个布尔字段,并编写一个自定义validation,允许在TimeSlot上进行条件双重预订。 下面的协会。 (使用TimeSlots迁移中的布尔字段,可以删除FilledTimeSlots表。)

 Office < ActiveRecord::Base has_many :doctors Doctor < ActiveRecord::Base has_many :patients, through: :appointments has_many :appointments belongs_to :office Patient < ActiveRecord::Base has_many :doctors, through: :appointments has_many :appointments Appointment < ActiveRecord::Base belongs_to :patient belongs_to :doctor belongs_to :chair belongs_to :timeslot TimeSlot < ActiveRecord::Base validates_with :availability, unless: "appointments.nil?" validates_with :workday has_many :appointments has_many :chairs, through: :appointments #you could then specify a maximum of 2 chairs in your validation depending on the appointment type, something like this: def availability if self.chairs.count == 0 self.booked? == false elsif self.chairs.count == 2 self.booked? == true elsif self.chairs.count == 1 and self.appointment.type == "cleaning" self.booked? == false else self.booked? == true end end Chair < ActiveRecord::Base has_many :appointments belongs_to :timeslot, through: :appointment end 

------------ Max Williams的替代回答------------------

  Doctor has_many :appointments Patient has_many :appointments Office has_many :chairs Chair #key-fields: office_id belongs_to :office has_many :appointments TimeSlot #key-fields: starts_at, :ends_at Appointment #key-fields: doctor_id, chair_id, time_slot_id, patient_id belongs_to :doctor belongs_to :chair belongs_to :time_slot belongs_to :patient 

我会这样做:

 Doctor has_many :appointments Patient has_many :appointments Office has_many :chairs Chair #key-fields: office_id belongs_to :office has_many :appointments TimeSlot #key-fields: starts_at, :ends_at Appointment #key-fields: doctor_id, chair_id, time_slot_id, patient_id belongs_to :doctor belongs_to :chair belongs_to :time_slot belongs_to :patient 

预订表格将包括获取所有可用的时段,然后,对于每个时段,显示在该时段中没有预约的椅子。