Commit 069b3d66 authored by Almouhannad's avatar Almouhannad

(B) Add holiday, edit domain

parent ef8c64f8
using Domain.Errors;
using Domain.Primitives;
using Domain.Shared;
namespace Domain.Entities.Visits;
public sealed class Holiday : Entity
{
#region Private ctor
private Holiday(int id) : base(id)
{
}
private Holiday(int id, int visitId, DateOnly from, int duration) : base(id)
{
VisitId = visitId;
From = from;
Duration = duration;
}
#endregion
#region Properties
#region Visit
public int VisitId { get; private set; }
#endregion
public DateOnly From { get; private set; }
public int Duration { get; private set; }
#endregion
#region Methods
#region Static factory
public static Result<Holiday> Create (int visitId, DateOnly from, int duration)
{
if (visitId <= 0 || duration <= 0)
return Result.Failure<Holiday>(DomainErrors.InvalidValuesError);
if (duration > 5)
return Result.Failure<Holiday>(DomainErrors.InvalidHolidayDuration);
return new Holiday(0, visitId, from, duration);
}
#endregion
#endregion
}
...@@ -83,6 +83,10 @@ public sealed class Visit : Entity ...@@ -83,6 +83,10 @@ public sealed class Visit : Entity
#endregion #endregion
#region Holiday
public Holiday? Holiday { get; private set; }
#endregion
#endregion #endregion
#region Methods #region Methods
...@@ -166,5 +170,17 @@ public sealed class Visit : Entity ...@@ -166,5 +170,17 @@ public sealed class Visit : Entity
} }
#endregion #endregion
#region Add holiday
public Result AddHoliday(DateOnly from, int duration)
{
var holidayResult = Holiday.Create(Id, from, duration);
if (holidayResult.IsFailure)
return Result.Failure(holidayResult.Error);
Holiday = holidayResult.Value;
return Result.Success();
}
#endregion
#endregion #endregion
} }
...@@ -13,7 +13,6 @@ public sealed class WaitingListRecord : Entity ...@@ -13,7 +13,6 @@ public sealed class WaitingListRecord : Entity
private WaitingListRecord(int id, int patientId) : base(id) private WaitingListRecord(int id, int patientId) : base(id)
{ {
PatientId = patientId; PatientId = patientId;
IsServed = false;
} }
#endregion #endregion
...@@ -27,16 +26,9 @@ public sealed class WaitingListRecord : Entity ...@@ -27,16 +26,9 @@ public sealed class WaitingListRecord : Entity
#endregion #endregion
#region Doctor
public int? DoctorId { get; set; }
public Doctor? Doctor { get; set; }
#endregion
#region Additional #region Additional
public bool IsServed { get; set; } = false; DateTime ArrivalTime { get; set; }
#endregion #endregion
...@@ -55,16 +47,5 @@ public sealed class WaitingListRecord : Entity ...@@ -55,16 +47,5 @@ public sealed class WaitingListRecord : Entity
#endregion #endregion
#region Link to doctor
public Result LinkToDoctor(int doctorId)
{
if (doctorId <= 0)
return Result.Failure(Errors.DomainErrors.InvalidValuesError);
DoctorId = doctorId;
return Result.Success();
}
#endregion
#endregion #endregion
} }
...@@ -37,4 +37,7 @@ public static class DomainErrors ...@@ -37,4 +37,7 @@ public static class DomainErrors
public static Error VisitAlreadyHasThisMedicalImage => public static Error VisitAlreadyHasThisMedicalImage =>
new("Domain.PatientAlreadyHasThisMedicine", "تحتوي هذه الزيارة بالفعل على الصورة التي تحاول اضافتها"); new("Domain.PatientAlreadyHasThisMedicine", "تحتوي هذه الزيارة بالفعل على الصورة التي تحاول اضافتها");
public static Error InvalidHolidayDuration =>
new("Domain.InvalidHolidayDuration", "الحد الأقصى للإجازة المرضية هو خمس أيام");
} }
using Domain.Entities.Visits;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Persistence.Configurations.Visits;
public class HolidayConfiguration : IEntityTypeConfiguration<Holiday>
{
public void Configure(EntityTypeBuilder<Holiday> builder)
{
builder.ToTable(nameof(Holiday));
builder.Property(holiday => holiday.From).IsRequired();
builder.Property(holiday => holiday.Duration).IsRequired();
}
}
...@@ -21,5 +21,10 @@ internal class VisitConfiguration : IEntityTypeConfiguration<Visit> ...@@ -21,5 +21,10 @@ internal class VisitConfiguration : IEntityTypeConfiguration<Visit>
.WithMany() .WithMany()
.HasForeignKey(visit => visit.HospitalId) .HasForeignKey(visit => visit.HospitalId)
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
builder.HasOne(visit => visit.Holiday)
.WithOne()
.HasForeignKey<Holiday>(holiday => holiday.VisitId)
.OnDelete(DeleteBehavior.NoAction);
} }
} }
\ No newline at end of file
...@@ -10,18 +10,9 @@ internal class WaitingListRecordConfiguration : IEntityTypeConfiguration<Waiting ...@@ -10,18 +10,9 @@ internal class WaitingListRecordConfiguration : IEntityTypeConfiguration<Waiting
{ {
builder.ToTable(nameof(WaitingListRecord)); builder.ToTable(nameof(WaitingListRecord));
builder.Property(waitingListRecord => waitingListRecord.IsServed)
.HasDefaultValue(false)
.IsRequired();
builder.HasOne(waitingListRecord => waitingListRecord.Patient) builder.HasOne(waitingListRecord => waitingListRecord.Patient)
.WithMany() .WithMany()
.HasForeignKey(waitingListRecord => waitingListRecord.PatientId) .HasForeignKey(waitingListRecord => waitingListRecord.PatientId)
.OnDelete(DeleteBehavior.NoAction); .OnDelete(DeleteBehavior.NoAction);
builder.HasOne(waitingListRecord => waitingListRecord.Doctor)
.WithMany()
.HasForeignKey(waitingListRecord => waitingListRecord.DoctorId)
.OnDelete(DeleteBehavior.NoAction);
} }
} }
\ No newline at end of file
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Persistence.Migrations
{
/// <inheritdoc />
public partial class Add_Holiday : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_WaitingListRecord_Doctor_DoctorId",
table: "WaitingListRecord");
migrationBuilder.DropIndex(
name: "IX_WaitingListRecord_DoctorId",
table: "WaitingListRecord");
migrationBuilder.DropColumn(
name: "DoctorId",
table: "WaitingListRecord");
migrationBuilder.DropColumn(
name: "IsServed",
table: "WaitingListRecord");
migrationBuilder.CreateTable(
name: "Holiday",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
VisitId = table.Column<int>(type: "int", nullable: false),
From = table.Column<DateOnly>(type: "date", nullable: false),
Duration = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Holiday", x => x.Id);
table.ForeignKey(
name: "FK_Holiday_Visit_VisitId",
column: x => x.VisitId,
principalTable: "Visit",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Holiday_VisitId",
table: "Holiday",
column: "VisitId",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Holiday");
migrationBuilder.AddColumn<int>(
name: "DoctorId",
table: "WaitingListRecord",
type: "int",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsServed",
table: "WaitingListRecord",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.CreateIndex(
name: "IX_WaitingListRecord_DoctorId",
table: "WaitingListRecord",
column: "DoctorId");
migrationBuilder.AddForeignKey(
name: "FK_WaitingListRecord_Doctor_DoctorId",
table: "WaitingListRecord",
column: "DoctorId",
principalTable: "Doctor",
principalColumn: "Id");
}
}
}
...@@ -543,6 +543,31 @@ namespace Persistence.Migrations ...@@ -543,6 +543,31 @@ namespace Persistence.Migrations
b.ToTable("PersonalInfo", (string)null); b.ToTable("PersonalInfo", (string)null);
}); });
modelBuilder.Entity("Domain.Entities.Visits.Holiday", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Duration")
.HasColumnType("int");
b.Property<DateOnly>("From")
.HasColumnType("date");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("VisitId")
.IsUnique();
b.ToTable("Holiday", (string)null);
});
modelBuilder.Entity("Domain.Entities.Visits.Relations.VisitMedicalImages.VisitMedicalImage", b => modelBuilder.Entity("Domain.Entities.Visits.Relations.VisitMedicalImages.VisitMedicalImage", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
...@@ -670,21 +695,11 @@ namespace Persistence.Migrations ...@@ -670,21 +695,11 @@ namespace Persistence.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("DoctorId")
.HasColumnType("int");
b.Property<bool>("IsServed")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false);
b.Property<int>("PatientId") b.Property<int>("PatientId")
.HasColumnType("int"); .HasColumnType("int");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("DoctorId");
b.HasIndex("PatientId"); b.HasIndex("PatientId");
b.ToTable("WaitingListRecord", (string)null); b.ToTable("WaitingListRecord", (string)null);
...@@ -905,6 +920,15 @@ namespace Persistence.Migrations ...@@ -905,6 +920,15 @@ namespace Persistence.Migrations
b.Navigation("Patient"); b.Navigation("Patient");
}); });
modelBuilder.Entity("Domain.Entities.Visits.Holiday", b =>
{
b.HasOne("Domain.Entities.Visits.Visit", null)
.WithOne("Holiday")
.HasForeignKey("Domain.Entities.Visits.Holiday", "VisitId")
.OnDelete(DeleteBehavior.NoAction)
.IsRequired();
});
modelBuilder.Entity("Domain.Entities.Visits.Relations.VisitMedicalImages.VisitMedicalImage", b => modelBuilder.Entity("Domain.Entities.Visits.Relations.VisitMedicalImages.VisitMedicalImage", b =>
{ {
b.HasOne("Domain.Entities.Medicals.MedicalImages.MedicalImage", "MedicalImage") b.HasOne("Domain.Entities.Medicals.MedicalImages.MedicalImage", "MedicalImage")
...@@ -990,19 +1014,12 @@ namespace Persistence.Migrations ...@@ -990,19 +1014,12 @@ namespace Persistence.Migrations
modelBuilder.Entity("Domain.Entities.WaitingList.WaitingListRecord", b => modelBuilder.Entity("Domain.Entities.WaitingList.WaitingListRecord", b =>
{ {
b.HasOne("Domain.Entities.People.Doctors.Doctor", "Doctor")
.WithMany()
.HasForeignKey("DoctorId")
.OnDelete(DeleteBehavior.NoAction);
b.HasOne("Domain.Entities.People.Patients.Patient", "Patient") b.HasOne("Domain.Entities.People.Patients.Patient", "Patient")
.WithMany() .WithMany()
.HasForeignKey("PatientId") .HasForeignKey("PatientId")
.OnDelete(DeleteBehavior.NoAction) .OnDelete(DeleteBehavior.NoAction)
.IsRequired(); .IsRequired();
b.Navigation("Doctor");
b.Navigation("Patient"); b.Navigation("Patient");
}); });
...@@ -1052,6 +1069,8 @@ namespace Persistence.Migrations ...@@ -1052,6 +1069,8 @@ namespace Persistence.Migrations
modelBuilder.Entity("Domain.Entities.Visits.Visit", b => modelBuilder.Entity("Domain.Entities.Visits.Visit", b =>
{ {
b.Navigation("Holiday");
b.Navigation("MedicalImages"); b.Navigation("MedicalImages");
b.Navigation("MedicalTests"); b.Navigation("MedicalTests");
......
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