How to model a doctor and patient appointments in rails?

流过昼夜 提交于 2019-12-11 08:04:06

问题


Rails and stackoverflow beginner here so please pardon me for any mistakes.

I am developing an appointment booking system between doctors and patients. Now, the flow goes like this A doctor will create its available time slots and the patients can see the available time slots of a particular doctor and can book the time slot.

class Doctor < ApplicationRecord
  has_many :availabilities
  has_many :appointments
  has_many :patients, through: :appointments
end

class Availibilities < ApplicationRecord
  #table columns:  id | start_date | start_time | end_date | end_time | slot_taken(boolean) 
  belongs_to :doctor
end

class Patient < ApplicationRecord
  has_many :appointments
  has_many :doctors, through:appointments
end

class Appointment < ApplicationRecord
  belongs_to :patient
  belongs_to :doctor
end

Now, how do I connect the patient to the availabilities model? How can I make a relationship which will fetch me which doctor's slots the patient has booked? Any other method through which I can achieve the above relationships/ functionality?

Also correct me if the above relationships are wrong.

来源:https://stackoverflow.com/questions/45062049/how-to-model-a-doctor-and-patient-appointments-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!