I am building Patient Appointment booking system and using the code first approach of the entity framework. I have designed the models and their relationships. Could somebody let me know if there is anything incorrect ?
I am assuming following are the relationships. Please correct me if I am wrong
One Patient can have many appointments and one appointment can belong to only one patient. Hence Patient has one to many relationship with appointments.
One Practioner can have many appointments and one appointment can belong to only one practioner. Hence Practioner has one to many relationship with appointments.
One Practioner can have many PractionerTypes(E.g Doctor,Nurse) and one PractionerType can belong to only one Practioner. Hence Practioner has one to many relationship with PractionerTypes.
One Appointment can have many AppointmentTypes(E.g Standard,Special) and one AppointmentTypes can belong to only one Appointment . Hence Appointment has one to many relationship with AppointmentTypes .
One Practioner can have many PractitionerAvailableHours and one PractitionerAvailableHours can belong to only one Practioner
I am bit confused after seeing this article http://www.entityframeworktutorial.net/code-first/configure-one-to-many-relationship-in-code-first.aspx
As per this article, when you are doing a one to many relationship , you need to define the property of the many class in the one class and have a collection property of one class in the many class. In their example. Student is the one class and Standard is the many class. The student has virtual property method of the standard class and the standard class has the virtual collection property of the student class In my design, Its just the other way round. Assuming Patient and Appointments have one to many relationship
Considering the above the enity design would look as follows
Appointment
public class Appointment
{
public int Id { get; set; }
public DateTime Date { get; set; }
public DateTime Time { get; set; }
public string Note { get; set; }
public virtual Patient Patient { get; set; }
public virtual Practioner Practioner { get; set; }
public int PatientId { get; set; }
public int PractionerId { get; set; }
public virtual ICollection<AppointmentType> AppointmentType { get; set; }
}
AppointmentType
public class AppointmentType
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Appointment Appointment { get; set; }
public int AppointmentId { get; set; }
}
Patient
public class Patient
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime DateOfBirth { get; set; }
public char Gender { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Postcode { get; set; }
public virtual ICollection<Appointment> Appointments { get; set; }
}
Practioner
public class Practioner
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Appointment> Appointments { get; set; }
public virtual ICollection<PractitionerAvailableHours> PractionerAvailableHours { get; set; }
}
PractionerType
public class PractionerType
{
public int Id { get; set; }
public string Name { get; set; }
public int PractionerId { get; set; }
public virtual Practioner Practioner { get; set; }
}
PractitionerAvailableHours
public class PractitionerAvailableHours
{
public int Id { get; set; }
public virtual Practioner Practioner { get; set; }
public int PractionerId { get; set; }
public DateTime AvailableDate { get; set; }
public int AvailableHours { get; set; }
}