Commit 051a3ae6 authored by Almouhannad's avatar Almouhannad

(B) Update visit-related entities, add FKs to visit

parent 9e7dc695
using Domain.Entities.Medicals.MedicalImages;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.Visits.Relations.VisitMedicalImages;
// TODO: Convert result to a value object
public sealed class VisitMedicalImage(int id) : Entity(id)
public sealed class VisitMedicalImage : Entity
{
#region Private ctor
private VisitMedicalImage(int id) : base(id) { }
private VisitMedicalImage(int id, int visitId, int medicalImageId) : base(id)
{
VisitId = visitId;
MedicalImageId = medicalImageId;
Result = null;
}
#endregion
#region Properties
#region Visit
......@@ -29,4 +44,28 @@ public sealed class VisitMedicalImage(int id) : Entity(id)
#endregion
#endregion
#region Methods
#region Static factory
public static VisitMedicalImage Create(int visitId, int medicalImageId)
{
if (visitId <= 0 || medicalImageId <= 0)
throw new InvalidValuesDomainException<VisitMedicalImage>();
return new VisitMedicalImage(0, visitId, medicalImageId);
}
#endregion
#region Add result
public void AddResult(string result)
{
if (result is null)
throw new InvalidValuesDomainException<VisitMedicalImage>();
Result = result;
}
#endregion
#endregion
}
using Domain.Entities.Medicals.MedicalTests;
using Domain.Entities.Visits.Relations.VisitMedicalImages;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.Visits.Relations.VisitMedicalTests;
// TODO: Convert result to a value object
public sealed class VisitMedicalTest(int id) : Entity(id)
public sealed class VisitMedicalTest : Entity
{
#region Private ctor
private VisitMedicalTest(int id) : base(id) { }
private VisitMedicalTest(int id, int visitId, int medicalTestId) : base(id)
{
VisitId = visitId;
MedicalTestId = medicalTestId;
Result = null;
}
#endregion
#region Properties
#region Visit
......@@ -29,4 +45,28 @@ public sealed class VisitMedicalTest(int id) : Entity(id)
#endregion
#endregion
#region Methods
#region Static factory
public static VisitMedicalTest Create(int visitId, int medicalTestId)
{
if (visitId <= 0 || medicalTestId <= 0)
throw new InvalidValuesDomainException<VisitMedicalTest>();
return new VisitMedicalTest(0, visitId, medicalTestId);
}
#endregion
#region Add result
public void AddResult(string result)
{
if (result is null)
throw new InvalidValuesDomainException<VisitMedicalTest>();
Result = result;
}
#endregion
#endregion
}
using Domain.Entities.Medicals.Medicines;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.Visits.Relations.VisitMedicines;
public sealed class VisitMedicine(int id) : Entity(id)
public sealed class VisitMedicine : Entity
{
#region Private ctor
private VisitMedicine(int id) : base(id) { }
private VisitMedicine(int id, int visitId, int medicineId, int number) : base(id)
{
VisitId = visitId;
MedicineId = medicineId;
Number = number;
}
#endregion
#region Properties
#region Visit
......@@ -28,4 +42,18 @@ public sealed class VisitMedicine(int id) : Entity(id)
#endregion
#endregion
#region Methods
#region Static factory
public static VisitMedicine Create(int visitId, int medicineId, int number)
{
if (visitId <= 0 || medicineId <= 0 || number <= 0)
throw new InvalidValuesDomainException<VisitMedicine>();
return new VisitMedicine(0, visitId, medicineId, number);
}
#endregion
#endregion
}
using Domain.Entities.Medicals.Hospitals;
using Domain.Entities.Medicals.MedicalImages;
using Domain.Entities.Medicals.MedicalTests;
using Domain.Entities.Medicals.Medicines;
using Domain.Entities.People.Doctors;
using Domain.Entities.People.Patients;
using Domain.Entities.Visits.Relations.VisitMedicalImages;
using Domain.Entities.Visits.Relations.VisitMedicalTests;
using Domain.Entities.Visits.Relations.VisitMedicines;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.Visits;
public sealed class Visit(int id) : Entity(id)
public sealed class Visit : Entity
{
#region Private ctor
private Visit(int id) : base(id) { }
private Visit(int id, int patientId, int doctorId, DateOnly date, string diagnosis) : base(id)
{
PatientId = patientId;
DoctorId = doctorId;
Date = date;
Diagnosis = diagnosis;
HospitalId = null;
}
#endregion
#region Properties
#region Patient
public int PatientId { get; set; }
public Patient Patient { get; set; } = null!;
#endregion
#region Doctor
public int DoctorId { get; set; }
public Doctor Doctor { get; set; } = null!;
public Hospital? Hospital { get; set; }
#endregion
#region Additional
public DateOnly Date { get; set; }
public string Diagnosis { get; set; } = null!;
#region Hospital
public int? HospitalId { get; set; }
public Hospital? Hospital { get; set; }
#endregion
#endregion
#region Navigations
public ICollection<VisitMedicalImage> MedicalImages { get; set; } = [];
......@@ -31,4 +70,84 @@ public sealed class Visit(int id) : Entity(id)
#endregion
#endregion
#region Methods
#region Static factory
public static Visit Create(int patientId, int doctorId, DateOnly date, string diagnosis)
{
if (patientId <= 0 || doctorId <= 0 || diagnosis is null)
throw new InvalidValuesDomainException<Visit>();
return new Visit(0, patientId, doctorId, date, diagnosis);
}
#endregion
#region Add medical image
public void AddMedicalImage(MedicalImage medicalImage)
{
VisitMedicalImage entry;
try
{
entry = VisitMedicalImage.Create(Id, medicalImage.Id);
}
catch
{
throw;
}
if (MedicalImages is null)
MedicalImages = [];
MedicalImages.Add(entry);
}
#endregion
#region Add medical test
public void AddMedicalTest(MedicalTest medicalTest)
{
VisitMedicalTest entry;
try
{
entry = VisitMedicalTest.Create(Id, medicalTest.Id);
}
catch
{
throw;
}
if (MedicalTests is null)
MedicalTests = [];
MedicalTests.Add(entry);
}
#endregion
#region Add medicine
public void AddMedicine (Medicine medicine, int number)
{
VisitMedicine entry;
try
{
entry = VisitMedicine.Create(Id, medicine.Id, number);
}
catch
{
throw;
}
if (Medicines is null)
Medicines = [];
Medicines.Add(entry);
}
#endregion
#region Add hospital
public void AddHospital(Hospital hospital)
{
if (hospital is null)
throw new InvalidValuesDomainException<Visit>();
Hospital = hospital;
HospitalId = hospital.Id;
}
#endregion
#endregion
}
......@@ -23,6 +23,7 @@ internal class PatientConfiguration : IEntityTypeConfiguration<Patient>
builder.HasMany(patient => patient.Visits)
.WithOne(visit => visit.Patient)
.HasForeignKey(visit => visit.PatientId)
.OnDelete(DeleteBehavior.NoAction);
}
}
\ No newline at end of file
......@@ -14,10 +14,12 @@ internal class VisitConfiguration : IEntityTypeConfiguration<Visit>
builder.HasOne(visit => visit.Doctor)
.WithMany()
.HasForeignKey(visit => visit.DoctorId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasOne(visit => visit.Hospital)
.WithMany()
.HasForeignKey(visit => visit.HospitalId)
.OnDelete(DeleteBehavior.NoAction);
}
}
\ No newline at end of file
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