Commit de273e03 authored by Almouhannad's avatar Almouhannad

(B) Apply result on visit, waitingList entities

parent 7198c837
......@@ -124,7 +124,7 @@ public sealed class Employee : Entity
#endregion
#region Check duplicate
if (FamilyMembers.Where(fm => fm.FamilyMemberId == familyMember.Id).ToList().Count > 0)
if (FamilyMembers.Where(fm => fm.FamilyMember == familyMember).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.RelationAlreadyExist);
#endregion
......@@ -151,8 +151,8 @@ public sealed class Employee : Entity
#region Check duplicate
if (RelatedEmployees.Where(re => re.Id == employee.Id).ToList().Count > 0
|| RelatedTo.Where(rt => rt.Id == employee.Id).ToList().Count > 0
if (RelatedEmployees.Where(re => re == employee).ToList().Count > 0
|| RelatedTo.Where(rt => rt == employee).ToList().Count > 0
)
return Result.Failure(Errors.DomainErrors.RelationAlreadyExist);
......
using Domain.Entities.Medicals.MedicalImages;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.Visits.Relations.VisitMedicalImages;
......@@ -25,21 +25,21 @@ public sealed class VisitMedicalImage : Entity
#region Visit
public int VisitId { get; set; }
public Visit Visit { get; set; } = null!;
public int VisitId { get; private set; }
public Visit Visit { get; private set; } = null!;
#endregion
#region Medical image
public int MedicalImageId { get; set; }
public MedicalImage MedicalImage { get; set; } = null!;
public int MedicalImageId { get; private set; }
public MedicalImage MedicalImage { get; private set; } = null!;
#endregion
#region Additional
public string? Result { get; set; }
public string? Result { get; private set; }
#endregion
......@@ -48,22 +48,23 @@ public sealed class VisitMedicalImage : Entity
#region Methods
#region Static factory
public static VisitMedicalImage Create(int visitId, int medicalImageId)
public static Result<VisitMedicalImage> Create(int visitId, int medicalImageId)
{
if (visitId <= 0 || medicalImageId <= 0)
throw new InvalidValuesDomainException<VisitMedicalImage>();
return Shared.Result.Failure<VisitMedicalImage>(Errors.DomainErrors.InvalidValuesError);
return new VisitMedicalImage(0, visitId, medicalImageId);
}
#endregion
#region Add result
public void AddResult(string result)
public Result AddResult(string result)
{
if (result is null)
throw new InvalidValuesDomainException<VisitMedicalImage>();
return Shared.Result.Failure(Errors.DomainErrors.InvalidValuesError);
Result = result;
return Shared.Result.Success();
}
#endregion
......
using Domain.Entities.Medicals.MedicalTests;
using Domain.Entities.Visits.Relations.VisitMedicalImages;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.Visits.Relations.VisitMedicalTests;
......@@ -26,21 +25,21 @@ public sealed class VisitMedicalTest : Entity
#region Visit
public int VisitId { get; set; }
public Visit Visit { get; set; } = null!;
public int VisitId { get; private set; }
public Visit Visit { get; private set; } = null!;
#endregion
#region Medical test
public int MedicalTestId { get; set; }
public MedicalTest MedicalTest { get; set; } = null!;
public int MedicalTestId { get; private set; }
public MedicalTest MedicalTest { get; private set; } = null!;
#endregion
#region Additional
public string? Result { get; set; }
public string? Result { get; private set; }
#endregion
......@@ -49,22 +48,23 @@ public sealed class VisitMedicalTest : Entity
#region Methods
#region Static factory
public static VisitMedicalTest Create(int visitId, int medicalTestId)
public static Result<VisitMedicalTest> Create(int visitId, int medicalTestId)
{
if (visitId <= 0 || medicalTestId <= 0)
throw new InvalidValuesDomainException<VisitMedicalTest>();
return Shared.Result.Failure<VisitMedicalTest>(Errors.DomainErrors.InvalidValuesError);
return new VisitMedicalTest(0, visitId, medicalTestId);
}
#endregion
#region Add result
public void AddResult(string result)
public Result AddResult(string result)
{
if (result is null)
throw new InvalidValuesDomainException<VisitMedicalTest>();
return Shared.Result.Failure(Errors.DomainErrors.InvalidValuesError);
Result = result;
return Shared.Result.Success();
}
#endregion
......
using Domain.Entities.Medicals.Medicines;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.Visits.Relations.VisitMedicines;
......@@ -23,21 +23,21 @@ public sealed class VisitMedicine : Entity
#region Visit
public int VisitId { get; set; }
public Visit Visit { get; set; } = null!;
public int VisitId { get; private set; }
public Visit Visit { get; private set; } = null!;
#endregion
#region Medicine
public int MedicineId { get; set; }
public Medicine Medicine { get; set; } = null!;
public int MedicineId { get; private set; }
public Medicine Medicine { get; private set; } = null!;
#endregion
#region Additional
public int Number { get; set; }
public int Number { get; private set; }
#endregion
......@@ -46,10 +46,10 @@ public sealed class VisitMedicine : Entity
#region Methods
#region Static factory
public static VisitMedicine Create(int visitId, int medicineId, int number)
public static Result<VisitMedicine> Create(int visitId, int medicineId, int number)
{
if (visitId <= 0 || medicineId <= 0 || number <= 0)
throw new InvalidValuesDomainException<VisitMedicine>();
return Result.Failure<VisitMedicine>(Errors.DomainErrors.InvalidValuesError);
return new VisitMedicine(0, visitId, medicineId, number);
}
......
......@@ -7,8 +7,8 @@ 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;
using Domain.Shared;
namespace Domain.Entities.Visits;
......@@ -34,23 +34,23 @@ public sealed class Visit : Entity
#region Patient
public int PatientId { get; set; }
public Patient Patient { get; set; } = null!;
public int PatientId { get; private set; }
public Patient Patient { get; private set; } = null!;
#endregion
#region Doctor
public int DoctorId { get; set; }
public Doctor Doctor { get; set; } = null!;
public int DoctorId { get; private set; }
public Doctor Doctor { get; private set; } = null!;
#endregion
#region Additional
public DateOnly Date { get; set; }
public DateOnly Date { get; private set; }
public string Diagnosis { get; set; } = null!;
public string Diagnosis { get; private set; } = null!;
#region Hospital
......@@ -88,73 +88,81 @@ public sealed class Visit : Entity
#region Methods
#region Static factory
public static Visit Create(int patientId, int doctorId, DateOnly date, string diagnosis)
public static Result<Visit> Create(int patientId, int doctorId, DateOnly date, string diagnosis)
{
if (patientId <= 0 || doctorId <= 0 || diagnosis is null)
throw new InvalidValuesDomainException<Visit>();
return Result.Failure<Visit>(Errors.DomainErrors.InvalidValuesError);
return new Visit(0, patientId, doctorId, date, diagnosis);
}
#endregion
#region Add medical image
public void AddMedicalImage(MedicalImage medicalImage)
public Result AddMedicalImage(MedicalImage medicalImage)
{
VisitMedicalImage entry;
try
{
entry = VisitMedicalImage.Create(Id, medicalImage.Id);
}
catch
{
throw;
}
_medicalImages.Add(entry);
#region Create medical image to attach
Result<VisitMedicalImage> entry = VisitMedicalImage.Create(Id, medicalImage.Id);
if (entry.IsFailure)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Check duplicate
if (MedicalImages.Where(mi => mi.MedicalImage == medicalImage).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.VisitAlreadyHasThisMedicalImage);
#endregion
_medicalImages.Add(entry.Value);
return Result.Success();
}
#endregion
#region Add medical test
public void AddMedicalTest(MedicalTest medicalTest)
public Result AddMedicalTest(MedicalTest medicalTest)
{
VisitMedicalTest entry;
try
{
entry = VisitMedicalTest.Create(Id, medicalTest.Id);
}
catch
{
throw;
}
_medicalTests.Add(entry);
#region Create medical test to attach
Result<VisitMedicalTest> entry = VisitMedicalTest.Create(Id, medicalTest.Id);
if (entry.IsFailure)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Check duplicate
if (MedicalTests.Where(mt => mt.MedicalTest == medicalTest).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.VisitAlreadyHasThisMedicalTest);
#endregion
_medicalTests.Add(entry.Value);
return Result.Success();
}
#endregion
#region Add medicine
public void AddMedicine (Medicine medicine, int number)
public Result AddMedicine(Medicine medicine, int number)
{
VisitMedicine entry;
try
{
entry = VisitMedicine.Create(Id, medicine.Id, number);
}
catch
{
throw;
}
_medicines.Add(entry);
#region Create medicine to attach
Result<VisitMedicine> entry = VisitMedicine.Create(Id, medicine.Id, number);
if (entry.IsFailure)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
#endregion
#region Check duplicate
if (Medicines.Where(m => m.Medicine == medicine).ToList().Count > 0)
return Result.Failure(Errors.DomainErrors.VisitAlreadyHasThisMedicine);
#endregion
_medicines.Add(entry.Value);
return Result.Success();
}
#endregion
#region Add hospital
public void AddHospital(Hospital hospital)
public Result AddHospital(Hospital hospital)
{
if (hospital is null)
throw new InvalidValuesDomainException<Visit>();
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
Hospital = hospital;
HospitalId = hospital.Id;
return Result.Success();
}
#endregion
......
using Domain.Entities.People.Doctors;
using Domain.Entities.People.Patients;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.WaitingList;
......@@ -46,21 +46,23 @@ public sealed class WaitingListRecord : Entity
#region Static factory
public static WaitingListRecord Create(int patientId)
public static Result<WaitingListRecord> Create(int patientId)
{
if (patientId <= 0)
throw new InvalidValuesDomainException<WaitingListRecord>();
return Result.Failure<WaitingListRecord>(Errors.DomainErrors.InvalidValuesError);
return new WaitingListRecord(0, patientId);
}
#endregion
#region Link to doctor
public void LinkToDoctor(int doctorId)
public Result LinkToDoctor(int doctorId)
{
if (doctorId <= 0)
throw new InvalidValuesDomainException<WaitingListRecord>();
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
DoctorId = doctorId;
return Result.Success();
}
#endregion
......
......@@ -25,6 +25,13 @@ public static class DomainErrors
public static Error PhoneAlreadyExist =>
new("Domain.PhoneAlreadyExist", "رقم الهاتف موجود بالفعل");
public static Error VisitAlreadyHasThisMedicine =>
new("Domain.VisitAlreadyHasThisMedicine", "تحتوي الوصفة الطبية بالفعل على الدواء الذي تحاول اضافته");
public static Error VisitAlreadyHasThisMedicalTest =>
new("Domain.VisitAlreadyHasThisMedicalTest", "تحتوي هذه الزيارة بالفعل على التحليل الطبي الذي تحاول اضافته");
public static Error VisitAlreadyHasThisMedicalImage =>
new("Domain.PatientAlreadyHasThisMedicine", "تحتوي هذه الزيارة بالفعل على الصورة التي تحاول اضافتها");
}
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