How do I model a "Connections" relation between Doctor-Patient on Ruby on Rails -


i'm using ruby on rails dissertation creating e-health monitoring web application doctors , patients. question is:

is there simple approach creating connection option seen on linkedin can use between doctors , patients?

i have been thinking , approach create new entity in database called connection store doctor_id , patient_id attributes.

how create necessary validations required? e.g example if patient not connected doctor cannot send message doctor or if not connected cannot see information.

i'm looking approach or guide how can solve problem.

thank you

one way approach write method in model make checking relationship nice , clean. example, if wanted check if patient connected doctor, add patient model:

patient model

def connected?(doc)   return true if connection.where(:patient_id => self.id, :doctor_id => doc.id).count > 0   false end 

then, whenever have instance of patient , doctor in app, can check if connected passing connected? method. example, assume have objects @patient , @doctor. check connection so:

if @patient.connected?(@doctor)   # stuff, send message end 

of course, how approach using method can vary depending on you're trying accomplish. can become messy keep writing if statements on place. but, tend app working first , focus on cleaning code.

edit

as phlip mentions, if connection model doesn't contain data, simpler rid of model , use has_and_belongs_to_many relationship between patient , doctor.

i still use method in patient and/or doctor models check whether connection exists. then, if ever need add data connection, create connection model , not have edit controllers/views.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -