Commit 219cd6d0 authored by Almouhannad's avatar Almouhannad

(B) update doctor-related entities

parent f1582a50
using Domain.Entities.People.Doctors.Shared; using Domain.Entities.People.Doctors.Shared;
using Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues; using Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues;
using Domain.Entities.People.Shared; using Domain.Entities.People.Shared;
using Domain.Exceptions.InvalidValue;
using Domain.Primitives; using Domain.Primitives;
namespace Domain.Entities.People.Doctors; namespace Domain.Entities.People.Doctors;
public sealed class Doctor(int id) : Entity(id) public sealed class Doctor : Entity
{ {
#region Private ctor
private Doctor(int id) : base(id)
{
}
private Doctor(int id, PersonalInfo personalInfo) : base(id)
{
PersonalInfo = personalInfo;
Status = DoctorStatuses.Available;
}
#endregion
#region Properties #region Properties
public PersonalInfo PersonalInfo { get; set; } = null!; public PersonalInfo PersonalInfo { get; set; } = null!;
...@@ -20,4 +33,54 @@ public sealed class Doctor(int id) : Entity(id) ...@@ -20,4 +33,54 @@ public sealed class Doctor(int id) : Entity(id)
#endregion #endregion
#endregion #endregion
#region Methods
#region Static factory
public static Doctor Create(string firstName, string middleName, string lastName)
{
PersonalInfo personalInfo;
try
{
personalInfo = PersonalInfo.Create(firstName, middleName, lastName);
}
catch
{
throw;
}
return new Doctor(0, personalInfo);
}
#endregion
#region Add phone
public void AddPhone(string phone, string? number = null)
{
DoctorPhone doctorPhone;
try
{
doctorPhone = DoctorPhone.Create(phone, number);
}
catch
{
throw;
}
if (Phones is null)
Phones = [];
Phones.Add(doctorPhone);
}
#endregion
#region Change status
public void ChangeStatusTo(DoctorStatus status)
{
if (status == DoctorStatuses.Available || status == DoctorStatuses.Busy || status == DoctorStatuses.Working)
Status = status;
throw new InvalidValuesDomainException<DoctorStatus>();
}
#endregion
#endregion
} }
using Domain.Primitives;
namespace Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues;
public sealed class DoctorStatus(int id) : Entity(id)
{
#region Properties
public string Name { get; set; } = null!;
#endregion
}
using Domain.Primitives; using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.People.Doctors.Shared; namespace Domain.Entities.People.Doctors.Shared;
// TODO: Convert phone property to a value object // TODO: Convert phone property to a value object
public sealed class DoctorPhone(int id) : Entity(id) public sealed class DoctorPhone : Entity
{ {
#region Private ctor
private DoctorPhone(int id) : base(id) { }
private DoctorPhone(int id, string phone, string? name = null) : base(id)
{
Phone = phone;
Name = name;
}
#endregion
#region Properties #region Properties
public string? Name { get; set; } public string? Name { get; set; }
...@@ -12,4 +23,19 @@ public sealed class DoctorPhone(int id) : Entity(id) ...@@ -12,4 +23,19 @@ public sealed class DoctorPhone(int id) : Entity(id)
public string Phone { get; set; } = null!; public string Phone { get; set; } = null!;
#endregion #endregion
#region Methods
#region Static factory
public static DoctorPhone Create(string phone, string? name)
{
if (phone is null)
throw new InvalidValuesDomainException<DoctorPhone>();
return new DoctorPhone(0, phone, name);
}
#endregion
#endregion
} }
using Domain.Exceptions.InvalidValue;
using Domain.Primitives;
namespace Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues;
public sealed class DoctorStatus : Entity
{
#region Private ctor
private DoctorStatus(int id) : base(id)
{
}
private DoctorStatus(int id, string name) : base(id)
{
Name = name;
}
#endregion
#region Properties
public string Name { get; set; } = null!;
#endregion
#region Methods
#region Static factory
public static DoctorStatus Create(string name, int? id)
{
if (name is null)
throw new InvalidValuesDomainException<DoctorStatus>();
if (id is not null)
{
if (id < 0)
throw new InvalidValuesDomainException<DoctorStatus>();
return new DoctorStatus(id.Value, name);
}
return new DoctorStatus(0, name);
}
#endregion
#endregion
}
...@@ -4,11 +4,11 @@ public static class DoctorStatuses ...@@ -4,11 +4,11 @@ public static class DoctorStatuses
{ {
#region Constant id values #region Constant id values
public static int Available => 1; public static DoctorStatus Available => DoctorStatus.Create("متاح", 1);
public static int Working => 2; public static DoctorStatus Working => DoctorStatus.Create("لديه مريض", 1);
public static int Busy => 3; public static DoctorStatus Busy => DoctorStatus.Create("مشغول", 1);
#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