medicalHistory: deletion when patient is deleted
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Core.Entities;
|
||||
|
||||
namespace Application.Endpoints.Appointments;
|
||||
@@ -7,8 +7,8 @@ namespace Application.Endpoints.Appointments;
|
||||
public class AppointmentManagementHandler
|
||||
{
|
||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public AppointmentManagementHandler(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
|
||||
@@ -41,18 +41,18 @@ public class AppointmentManagementHandler
|
||||
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("_id", appointmentId),
|
||||
("_id", appointmentId)
|
||||
};
|
||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||
|
||||
if(!appointments.Any())
|
||||
|
||||
if (!appointments.Any())
|
||||
{
|
||||
var appointment = new Appointment();
|
||||
appointment.SetId(appointmentId);
|
||||
appointment.SetDoctorIid(dto.DoctorId.ToString());
|
||||
appointment.SetPatientId(dto.PatientId.ToString());
|
||||
appointment.AddAppointment(dto.Appointment);
|
||||
|
||||
|
||||
await _appointmentsMongoDbService.AddAsync(appointment);
|
||||
}
|
||||
else
|
||||
@@ -62,14 +62,14 @@ public class AppointmentManagementHandler
|
||||
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
|
||||
}
|
||||
|
||||
return new BaseResponse()
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.Created,
|
||||
Message = "Appointment successfully created.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public async Task<BaseResponse> HandleDeleteAppointment(AppointmentManagementDto dto)
|
||||
{
|
||||
var validation = new DeleteAppointmentValidator(_appointmentsMongoDbService,
|
||||
@@ -89,29 +89,27 @@ public class AppointmentManagementHandler
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("_id", appointmentId),
|
||||
("_id", appointmentId)
|
||||
};
|
||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||
|
||||
if(!appointments.Any())
|
||||
{
|
||||
return new BaseResponse()
|
||||
|
||||
if (!appointments.Any())
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NotFound,
|
||||
Message = "Appointment not found in system.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var appointment = appointments[0];
|
||||
appointment.RemoveAppointment(dto.Appointment);
|
||||
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
|
||||
|
||||
return new BaseResponse()
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Appointment successfully removed.",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.Appointments;
|
||||
@@ -9,7 +9,7 @@ public class CreateAppointmentValidator : AbstractValidator<AppointmentManagemen
|
||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
|
||||
public CreateAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
|
||||
{
|
||||
@@ -17,7 +17,7 @@ public class CreateAppointmentValidator : 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")
|
||||
@@ -30,18 +30,18 @@ public class CreateAppointmentValidator : AbstractValidator<AppointmentManagemen
|
||||
RuleFor(x => x)
|
||||
.MustAsync(IsAppointmentUnique).WithMessage("Appointment already in system.")
|
||||
.WithErrorCode(HttpStatusCodes.Conflict.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);
|
||||
@@ -50,9 +50,9 @@ public class CreateAppointmentValidator : AbstractValidator<AppointmentManagemen
|
||||
|
||||
private bool IsAppointmentValidFormat(DateTime appointment)
|
||||
{
|
||||
if (appointment == default(DateTime))
|
||||
if (appointment == default)
|
||||
return false;
|
||||
|
||||
|
||||
if (appointment.Date < DateTime.UtcNow.Date)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user