medicalHistory: deletion when patient is deleted

This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 22:06:01 +03:00
parent 13bfa2bdd9
commit 7b24c178b3
62 changed files with 321 additions and 356 deletions
@@ -1,6 +1,5 @@
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Core.Entities;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Appointments;
@@ -10,7 +9,7 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
private readonly IDoctorRepository _doctorRepository;
private readonly IPatientRepository _patientRepository;
public DeleteAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
{
@@ -18,7 +17,7 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is not registered in system")
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
RuleFor(x => x.PatientId)
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
.MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system")
@@ -31,18 +30,18 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
RuleFor(x => x)
.MustAsync(DoesAppointmentExists).WithMessage("Appointment not found in system")
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
_appointmentsMongoDbService = appointmentsMongoDbService;
_doctorRepository = doctorRepository;
_patientRepository = patientRepository;
}
private async Task<bool> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
{
var doctor = await _doctorRepository.GetByIdAsync(id);
return doctor != null;
}
private async Task<bool> IsPatientRegistered(Guid id, CancellationToken cancellationToken)
{
var patient = await _patientRepository.GetByIdAsync(id);
@@ -51,9 +50,9 @@ public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagemen
private bool IsAppointmentValidFormat(DateTime appointment)
{
if (appointment == default(DateTime))
if (appointment == default)
return false;
if (appointment.Date < DateTime.UtcNow.Date)
return false;