首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >预约应用程序DB模式:医生、预约、TimeSlots、病人之间的正确关系是什么?

预约应用程序DB模式:医生、预约、TimeSlots、病人之间的正确关系是什么?
EN

Stack Overflow用户
提问于 2014-08-29 07:22:24
回答 2查看 4.3K关注 0票数 1

[更新的模式:http://i.imgur.com/fX9CGNh.png ]

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

我很难设计一个对我来说有意义的数据库模式

问题:给出了以下信息,医生、病人、预约、椅子和time_slots之间的正确关系是什么?

病人需要和医生办公室预约。根据约会类型的不同,每个约会都是为一个或多个相邻的time_slots排定的,而对于具有相同start_time和end_time的time_slots是否可以安排两个约会,则由约会类型决定。(根据约会类型,允许双重预订。)

App规范:

  1. 注册用户通过网站上的预约申请表进行预约。
  2. 约会占用一定的预置数量的相邻time_slots。这是根据任用类别/类型确定的。这个长度可以由管理员以及每个time_slot的长度来调整。
  3. 为了帮助加快请求处理,约会请求表单中的日历中隐藏了不可用/已预订的时间。
  4. 在面向管理的界面上,管理员可以确认约会请求并进行约会,还可以更新、创建和删除预定的约会。
  5. 所有的预约都是在“椅子”里进行的--就像牙医的椅子。一间办公室有多把椅子。在预定的时段内,每把椅子上有一位病人。
  6. 约会有日期、时间、长度、appointment_type、double_bookable字段吗?(由appointment_type测定)。Time_slots有一个start_time和end_time,还有一个约会。
  7. 这间办公室只有一位医生。但是,某些类型的预约-对医生的时间要求较低-可能是双重预约。在本质上,两次清洁牙齿可以在同一时间,只要他们是在**分开的椅子**。

我的关系

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-30 02:49:11

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

代码语言:javascript
复制
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
代码语言:javascript
复制
 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
票数 3
EN

Stack Overflow用户

发布于 2014-08-29 08:49:58

我会这样做:

代码语言:javascript
复制
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

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25563459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档