[更新的模式:http://i.imgur.com/fX9CGNh.png ]
我的任务是开发一个预约系统,是为一个小型医疗办公室设计的。这是一个Rails 3.2应用程序。
我很难设计一个对我来说有意义的数据库模式。
问题:给出了以下信息,医生、病人、预约、椅子和time_slots之间的正确关系是什么?
病人需要和医生办公室预约。根据约会类型的不同,每个约会都是为一个或多个相邻的time_slots排定的,而对于具有相同start_time和end_time的time_slots是否可以安排两个约会,则由约会类型决定。(根据约会类型,允许双重预订。)
App规范:
我的关系
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发布于 2014-08-30 02:49:11
我将向TimeSlot添加一个布尔字段,并编写一个自定义验证,允许在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 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发布于 2014-08-29 08:49:58
我会这样做:
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预订表将包括获取所有可用的时隙,然后,对每个时段,显示在该时段内没有预约的椅子。
https://stackoverflow.com/questions/25563459
复制相似问题