Commit 42981ba9 authored by Almouhannad's avatar Almouhannad

(B) Apply result on creation of medicals entities

parent 3164d1b2
using Domain.Entities.People.Patients.Relations.PatientDiseases; using Domain.Entities.People.Patients.Relations.PatientDiseases;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives; using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.Medicals.Diseases; namespace Domain.Entities.Medicals.Diseases;
...@@ -35,10 +35,10 @@ public sealed class Disease : Entity ...@@ -35,10 +35,10 @@ public sealed class Disease : Entity
#region Methods #region Methods
#region Static factory #region Static factory
public static Disease Create(string name) public static Result<Disease> Create(string name)
{ {
if (name is null) if (name is null)
throw new InvalidValuesDomainException<Disease>(); return Result.Failure<Disease>(Errors.DomainErrors.InvalidValuesError);
return new Disease(0, name); return new Disease(0, name);
} }
#endregion #endregion
......
using Domain.Exceptions.InvalidValue; using Domain.Primitives;
using Domain.Primitives; using Domain.Shared;
namespace Domain.Entities.Medicals.Hospitals; namespace Domain.Entities.Medicals.Hospitals;
...@@ -25,10 +25,10 @@ public sealed class Hospital : Entity ...@@ -25,10 +25,10 @@ public sealed class Hospital : Entity
#region Methods #region Methods
#region Static factory #region Static factory
public static Hospital Create(string name) public static Result<Hospital> Create(string name)
{ {
if (name is null) if (name is null)
throw new InvalidValuesDomainException<Hospital>(); return Result.Failure<Hospital>(Errors.DomainErrors.InvalidValuesError);
return new Hospital(0, name); return new Hospital(0, name);
} }
#endregion #endregion
......
using Domain.Exceptions.InvalidValue; using Domain.Primitives;
using Domain.Primitives; using Domain.Shared;
namespace Domain.Entities.Medicals.MedicalImages; namespace Domain.Entities.Medicals.MedicalImages;
...@@ -26,10 +26,10 @@ public sealed class MedicalImage : Entity ...@@ -26,10 +26,10 @@ public sealed class MedicalImage : Entity
#region Methods #region Methods
#region Static factory #region Static factory
public static MedicalImage Create(string name, string? description = null) public static Result<MedicalImage> Create(string name, string? description = null)
{ {
if (name is null) if (name is null)
throw new InvalidValuesDomainException<MedicalImage>(); return Result.Failure<MedicalImage>(Errors.DomainErrors.InvalidValuesError);
return new MedicalImage(0, name, description); return new MedicalImage(0, name, description);
} }
#endregion #endregion
......
using Domain.Exceptions.InvalidValue; using Domain.Primitives;
using Domain.Primitives; using Domain.Shared;
namespace Domain.Entities.Medicals.MedicalTests; namespace Domain.Entities.Medicals.MedicalTests;
...@@ -26,10 +26,10 @@ public sealed class MedicalTest : Entity ...@@ -26,10 +26,10 @@ public sealed class MedicalTest : Entity
#region Methods #region Methods
#region Static factory #region Static factory
public static MedicalTest Create(string name, string description) public static Result<MedicalTest> Create(string name, string description)
{ {
if (name is null) if (name is null)
throw new InvalidValuesDomainException<MedicalTest>(); return Result.Failure<MedicalTest>(Errors.DomainErrors.InvalidValuesError);
return new MedicalTest(0, name, description); return new MedicalTest(0, name, description);
} }
#endregion #endregion
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using Domain.Entities.People.Patients.Relations.PatientMedicines; using Domain.Entities.People.Patients.Relations.PatientMedicines;
using Domain.Exceptions.InvalidValue; using Domain.Exceptions.InvalidValue;
using Domain.Primitives; using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.Medicals.Medicines; namespace Domain.Entities.Medicals.Medicines;
...@@ -48,26 +49,27 @@ public sealed class Medicine : Entity ...@@ -48,26 +49,27 @@ public sealed class Medicine : Entity
#region Methods #region Methods
#region Static factory #region Static factory
public static Medicine Create(string form, int amount, string name, decimal dosage) public static Result<Medicine> Create(string form, int amount, string name, decimal dosage)
{ {
if (form is null || name is null || amount < 0 || dosage < 0) if (form is null || name is null || amount < 0 || dosage < 0)
throw new InvalidValuesDomainException<Medicine>(); return Result.Failure<Medicine>(Errors.DomainErrors.InvalidValuesError);
#region Check form #region Check form
MedicineForm selectedMedicineForm; Result<MedicineForm> selectedMedicineForm = new(null, false, Errors.DomainErrors.InvalidValuesError);
MedicineForm tablet = MedicineForms.Tablet; MedicineForm tablet = MedicineForms.Tablet;
MedicineForm syrup = MedicineForms.Syrup; MedicineForm syrup = MedicineForms.Syrup;
if (form == tablet.Name) if (form == tablet.Name)
selectedMedicineForm = tablet; selectedMedicineForm = Result.Success<MedicineForm>(tablet);
else if (form == syrup.Name) else if (form == syrup.Name)
selectedMedicineForm = syrup; selectedMedicineForm = Result.Success<MedicineForm>(syrup);
else throw new InvalidValuesDomainException<MedicineForm>();
if (selectedMedicineForm.IsFailure)
return Result.Failure<Medicine>(Errors.DomainErrors.InvalidValuesError);
#endregion #endregion
return new Medicine(0, selectedMedicineForm, amount, name, dosage); return new Medicine(0, selectedMedicineForm.Value, amount, name, dosage);
} }
#endregion #endregion
......
using Domain.Exceptions.InvalidValue; using Domain.Primitives;
using Domain.Primitives; using Domain.Shared;
namespace Domain.Entities.Medicals.Medicines.MedicineFormValues; namespace Domain.Entities.Medicals.Medicines.MedicineFormValues;
...@@ -23,15 +23,15 @@ public sealed class MedicineForm : Entity ...@@ -23,15 +23,15 @@ public sealed class MedicineForm : Entity
#region Methods #region Methods
#region Static factory #region Static factory
public static MedicineForm Create(string name, int? id) public static Result<MedicineForm> Create(string name, int? id)
{ {
if (name is null) if (name is null)
throw new InvalidValuesDomainException<MedicineForm>(); return Result.Failure<MedicineForm>(Errors.DomainErrors.InvalidValuesError);
if (id is not null) if (id is not null)
{ {
if (id < 0) if (id < 0)
throw new InvalidValuesDomainException<MedicineForm>(); return Result.Failure<MedicineForm>(Errors.DomainErrors.InvalidValuesError);
return new MedicineForm(id.Value, name); return new MedicineForm(id.Value, name);
} }
return new MedicineForm(0, name); return new MedicineForm(0, name);
......
namespace Domain.Entities.Medicals.Medicines.MedicineFormValues; using Domain.Exceptions.InvalidValue;
namespace Domain.Entities.Medicals.Medicines.MedicineFormValues;
public static class MedicineForms public static class MedicineForms
{ {
#region Constant id values #region Constant values
public static MedicineForm Tablet => MedicineForm.Create("حبوب", 1); public static MedicineForm Tablet
{
get
{
var result = MedicineForm.Create("حبوب", 1);
if (result.IsFailure)
throw new InvalidValuesDomainException<MedicineForm>();
return result.Value;
}
}
public static MedicineForm Syrup => MedicineForm.Create("شراب", 2); public static MedicineForm Syrup
{
get
{
var result = MedicineForm.Create("شراب", 2);
if (result.IsFailure)
throw new InvalidValuesDomainException<MedicineForm>();
return result.Value;
}
}
#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