Commit fe7a2b72 authored by Almouhannad's avatar Almouhannad

(B) Edit collections implementation

parent 051a3ae6
...@@ -22,7 +22,11 @@ public sealed class Disease : Entity ...@@ -22,7 +22,11 @@ public sealed class Disease : Entity
#region Navigations #region Navigations
public ICollection<PatientDisease> Patients { get; set; } = []; #region Patients
private readonly List<PatientDisease> _patients = [];
public IReadOnlyCollection<PatientDisease> Patients => _patients;
#endregion
#endregion #endregion
......
...@@ -34,7 +34,12 @@ public sealed class Medicine : Entity ...@@ -34,7 +34,12 @@ public sealed class Medicine : Entity
#region Navigations #region Navigations
public ICollection<PatientMedicine> Patients { get; set; } = []; #region Patients
private readonly List<PatientMedicine> _patients = [];
public IReadOnlyCollection<PatientMedicine> Patients => _patients;
#endregion
#endregion #endregion
......
...@@ -28,7 +28,11 @@ public sealed class Doctor : Entity ...@@ -28,7 +28,11 @@ public sealed class Doctor : Entity
#region Navigations #region Navigations
public ICollection<DoctorPhone> Phones { get; set; } = []; #region Phones
private readonly List<DoctorPhone> _phones = [];
public IReadOnlyCollection<DoctorPhone> Phones => _phones;
#endregion
#endregion #endregion
...@@ -66,10 +70,7 @@ public sealed class Doctor : Entity ...@@ -66,10 +70,7 @@ public sealed class Doctor : Entity
throw; throw;
} }
if (Phones is null) _phones.Add(doctorPhone);
Phones = [];
Phones.Add(doctorPhone);
} }
#endregion #endregion
......
...@@ -42,11 +42,21 @@ public sealed class Employee : Entity ...@@ -42,11 +42,21 @@ public sealed class Employee : Entity
#region Navigations #region Navigations
public ICollection<EmployeeFamilyMember> FamilyMembers { get; set; } = []; #region Family members
private readonly List<EmployeeFamilyMember> _familyMembers = [];
public IReadOnlyCollection<EmployeeFamilyMember> FamilyMembers => _familyMembers;
public ICollection<Employee> RelatedEmployees { get; set; } = []; #endregion
#region Related employees
private readonly List<Employee> _relatedEmployees = [];
public IReadOnlyCollection<Employee> RelatedEmployees => _relatedEmployees;
private readonly List<Employee> _relatedTo = [];
public IReadOnlyCollection<Employee> RelatedTo => _relatedTo;
#endregion
public ICollection<Employee> RelatedTo { get; set; } = [];
#endregion #endregion
...@@ -115,26 +125,14 @@ public sealed class Employee : Entity ...@@ -115,26 +125,14 @@ public sealed class Employee : Entity
throw; throw;
} }
if (FamilyMembers is null) _familyMembers.Add(employeeFamilyMember);
FamilyMembers = [];
FamilyMembers.Add(employeeFamilyMember);
} }
#endregion #endregion
#region Add related employee #region Add related employee
public void AddRelatedEmployee( Employee employee ) public void AddRelatedEmployee(Employee employee)
{ {
// Add new employee to related _relatedEmployees.Add(employee);
if (RelatedEmployees is null)
RelatedEmployees = [];
RelatedEmployees.Add(employee);
// Make this related to new employee
if (employee.RelatedTo is null)
employee.RelatedTo = [];
employee.RelatedTo.Add(this);
} }
#endregion #endregion
......
...@@ -22,10 +22,6 @@ public sealed class Patient : Entity ...@@ -22,10 +22,6 @@ public sealed class Patient : Entity
PersonalInfo = personalInfo; PersonalInfo = personalInfo;
DateOfBirth = dateOfBirth; DateOfBirth = dateOfBirth;
Gender = gender; Gender = gender;
Diseases = [];
Medicines = [];
Visits = [];
} }
#endregion #endregion
...@@ -54,11 +50,23 @@ public sealed class Patient : Entity ...@@ -54,11 +50,23 @@ public sealed class Patient : Entity
#region Navigations #region Navigations
public ICollection<PatientDisease> Diseases { get; set; } #region Diseases
private readonly List<PatientDisease> _diseases = [];
public IReadOnlyCollection<PatientDisease> Diseases => _diseases;
#endregion
#region Medicines
private readonly List<PatientMedicine> _medicines = [];
public IReadOnlyCollection<PatientMedicine> Medicines => _medicines;
#endregion
public ICollection<PatientMedicine> Medicines { get; set; } #region Visits
private readonly List<Visit> _visits = [];
public IReadOnlyCollection<Visit> Visits => _visits;
public ICollection<Visit> Visits { get; set; } #endregion
#endregion #endregion
...@@ -122,9 +130,8 @@ public sealed class Patient : Entity ...@@ -122,9 +130,8 @@ public sealed class Patient : Entity
{ {
throw; throw;
} }
if (Medicines is null)
Medicines = []; _medicines.Add(entry);
Medicines.Add(entry);
} }
#endregion #endregion
...@@ -141,11 +148,7 @@ public sealed class Patient : Entity ...@@ -141,11 +148,7 @@ public sealed class Patient : Entity
throw; throw;
} }
if (Diseases is null) _diseases.Add(entry);
Diseases = [];
Diseases.Add(entry);
} }
#endregion #endregion
......
...@@ -63,9 +63,23 @@ public sealed class Visit : Entity ...@@ -63,9 +63,23 @@ public sealed class Visit : Entity
#region Navigations #region Navigations
public ICollection<VisitMedicalImage> MedicalImages { get; set; } = []; #region Medical images
public ICollection<VisitMedicalTest> MedicalTests { get; set; } = []; private readonly List<VisitMedicalImage> _medicalImages = [];
public ICollection<VisitMedicine> Medicines { get; set; } = []; public IReadOnlyCollection<VisitMedicalImage> MedicalImages => _medicalImages;
#endregion
#region Medical tests
private readonly List<VisitMedicalTest> _medicalTests = [];
public IReadOnlyCollection<VisitMedicalTest> MedicalTests => _medicalTests;
#endregion
#region Medicines
private readonly List<VisitMedicine> _medicines = [];
public IReadOnlyCollection<VisitMedicine> Medicines => _medicines;
#endregion
#endregion #endregion
...@@ -96,10 +110,7 @@ public sealed class Visit : Entity ...@@ -96,10 +110,7 @@ public sealed class Visit : Entity
throw; throw;
} }
if (MedicalImages is null) _medicalImages.Add(entry);
MedicalImages = [];
MedicalImages.Add(entry);
} }
#endregion #endregion
...@@ -115,9 +126,8 @@ public sealed class Visit : Entity ...@@ -115,9 +126,8 @@ public sealed class Visit : Entity
{ {
throw; throw;
} }
if (MedicalTests is null)
MedicalTests = []; _medicalTests.Add(entry);
MedicalTests.Add(entry);
} }
#endregion #endregion
...@@ -133,9 +143,8 @@ public sealed class Visit : Entity ...@@ -133,9 +143,8 @@ public sealed class Visit : Entity
{ {
throw; throw;
} }
if (Medicines is null)
Medicines = []; _medicines.Add(entry);
Medicines.Add(entry);
} }
#endregion #endregion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment