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