Commit 77bcfade authored by Almouhannad's avatar Almouhannad

(B) Update Gender, Personal info, Patient domain objects

parent 6874b64f
......@@ -3,29 +3,105 @@ using Domain.Entities.People.Patients.Relations.PatientMedicines;
using Domain.Entities.People.Shared;
using Domain.Entities.People.Shared.GenderValues;
using Domain.Entities.Visits;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.People.Patients;
// TODO: Potential aggregate?
public sealed class Patient(int id) : Entity(id)
public sealed class Patient : Entity
{
#region Private ctor
private Patient(int id) : base(id) { }
private Patient(int id, PersonalInfo personalInfo, DateOnly dateOfBirth, Gender gender) : base(id)
{
PersonalInfo = personalInfo;
DateOfBirth = dateOfBirth;
Gender = gender;
Diseases = [];
Medicines = [];
Visits = [];
}
#endregion
#region Properties
public PersonalInfo PersonalInfo { get; set; } = null!;
public PersonalInfo PersonalInfo { get; private set; } = null!;
public DateOnly DateOfBirth { get; set; }
public DateOnly DateOfBirth { get; private set; }
public Gender Gender { get; set; } = null!;
public int Age
{
get
{
var today = DateOnly.FromDateTime(DateTime.Today);
var age = today.Year - DateOfBirth.Year;
if (today.Month < DateOfBirth.Month || (today.Month == DateOfBirth.Month && today.Day < DateOfBirth.Day))
{
age--;
}
return age;
}
}
public Gender Gender { get; private set; } = null!;
#region Navigations
public ICollection<PatientDisease> Diseases { get; set; } = [];
public ICollection<PatientDisease> Diseases { get; set; }
public ICollection<PatientMedicine> Medicines { get; set; }
public ICollection<Visit> Visits { get; set; }
#endregion
public ICollection<PatientMedicine> Medicines { get; set; } = [];
#endregion
#region Methods
#region Static factory
public static Patient Create(string firstName, string middleName, string lastName,
DateOnly dateOfBirth,
string gender
)
{
#region Personal info
PersonalInfo? personalInfo;
try
{
personalInfo = PersonalInfo.Create(firstName, middleName, lastName);
}
catch
{
throw;
}
#endregion
#region Gender
Gender? selectedGender;
Gender male = Genders.Male;
Gender female = Genders.Female;
if (gender == male.Name)
selectedGender = male;
else if (gender == female.Name)
selectedGender = female;
else selectedGender = null;
if (selectedGender is null)
throw new InvalidValuesDomainException<Gender>();
#endregion
public ICollection<Visit> Visits { get; set; } = [];
return new Patient(0, personalInfo, dateOfBirth, selectedGender);
}
#endregion
#endregion
......
using Domain.Primitives;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.People.Shared.GenderValues;
// TODO: Convert to a value object
public sealed class Gender(int id) : Entity(id)
public sealed class Gender : Entity
{
#region Private ctor
private Gender(int id) : base(id) { }
private Gender(int id, string name) : base(id)
{
Name = name;
}
#endregion
#region Properties
public string Name { get; set; } = null!;
public string Name { get; private set; } = null!;
#endregion
#region Methods
#region Static factory
public static Gender Create(string name, int? id)
{
if (name is null)
throw new InvalidValuesDomainException<Gender>();
if (id < 0)
throw new InvalidValuesDomainException<Gender>();
if (id is not null)
return new Gender(id.Value, name);
return new Gender(0, name);
}
#endregion
#endregion
}
......@@ -4,9 +4,9 @@ public static class Genders
{
#region Constant id values
public static int Male => 1;
public static Gender Male => Gender.Create("ذكر", 1);
public static int Female => 2;
public static Gender Female => Gender.Create("أنثى", 2);
#endregion
}
using Domain.Primitives;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.People.Shared;
// TODO: Convert props to value objects
public sealed class PersonalInfo(int id) : Entity(id)
public sealed class PersonalInfo : Entity
{
#region Private ctor
private PersonalInfo(int id) : base(id) { }
private PersonalInfo(int id, string firstName, string middleName, string lastName) : base(id)
{
FirstName = firstName;
MiddleName = middleName;
LastName = lastName;
}
#endregion
#region Properties
public string FirstName { get; set; } = null!;
public string FirstName { get; private set; } = null!;
public string MiddleName { get; private set; } = null!;
public string MiddleName { get; set; } = null!;
public string LastName { get; private set; } = null!;
public string LastName { get; set; } = null!;
public string FullName
{
get
{
return $"{FirstName} {MiddleName} {LastName}";
}
}
#endregion
#region Methods
#region Static factory
public static PersonalInfo Create(string firstName, string middleName, string lastName)
{
if (firstName is null || middleName is null || lastName is null)
throw new InvalidValuesDomainException<PersonalInfo>();
return new PersonalInfo(0, firstName, middleName, lastName);
}
#endregion
#endregion
}
......@@ -10,6 +10,8 @@ internal class PatientConfiguration : IEntityTypeConfiguration<Patient>
{
builder.ToTable(nameof(Patient));
builder.Ignore(patient => patient.Age);
builder.HasOne(patient => patient.PersonalInfo)
.WithOne()
.HasForeignKey<Patient>("PersonalInfoId")
......
......@@ -10,8 +10,12 @@ internal class PersonalInfoConfiguration : IEntityTypeConfiguration<PersonalInfo
{
builder.ToTable(nameof(PersonalInfo));
builder.Ignore(personalInfo => personalInfo.FullName);
builder.Property(personalInfo => personalInfo.FirstName).HasMaxLength(50);
builder.Property(personalInfo => personalInfo.LastName).HasMaxLength(50);
builder.Property(personalInfo => personalInfo.MiddleName).HasMaxLength(50);
}
}
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