Manage Appointments DONE!
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
namespace Application.Endpoints.Appointments;
|
||||
|
||||
public class AppointmentManagementDto
|
||||
{
|
||||
public Guid DoctorId { get; set; }
|
||||
public Guid PatientId { get; set; }
|
||||
public DateTime Appointment { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Core.Entities;
|
||||
|
||||
namespace Application.Endpoints.Appointments;
|
||||
|
||||
public class AppointmentManagementHandler
|
||||
{
|
||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
|
||||
public AppointmentManagementHandler(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
|
||||
{
|
||||
_appointmentsMongoDbService = appointmentsMongoDbService;
|
||||
_patientRepository = patientRepository;
|
||||
_doctorRepository = doctorRepository;
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleCreateAppointment(AppointmentManagementDto dto)
|
||||
{
|
||||
var validation = new CreateAppointmentValidator(_appointmentsMongoDbService,
|
||||
_doctorRepository, _patientRepository);
|
||||
var validationResult = await validation.ValidateAsync(dto);
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
var firstError = validationResult.Errors.FirstOrDefault();
|
||||
var errorCode = int.TryParse(firstError.ErrorCode, out var code) ? code : -1;
|
||||
var errorMessage = firstError.ErrorMessage;
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = errorCode,
|
||||
Message = errorMessage,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("_id", appointmentId),
|
||||
};
|
||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||
|
||||
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
|
||||
{
|
||||
var appointment = appointments[0];
|
||||
appointment.AddAppointment(dto.Appointment);
|
||||
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
|
||||
}
|
||||
|
||||
return new BaseResponse()
|
||||
{
|
||||
StatusCode = HttpStatusCodes.Created,
|
||||
Message = "Appointment successfully created.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleDeleteAppointment(AppointmentManagementDto dto)
|
||||
{
|
||||
var validation = new DeleteAppointmentValidator(_appointmentsMongoDbService,
|
||||
_doctorRepository, _patientRepository);
|
||||
var validationResult = await validation.ValidateAsync(dto);
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
var firstError = validationResult.Errors.FirstOrDefault();
|
||||
var errorCode = int.TryParse(firstError.ErrorCode, out var code) ? code : -1;
|
||||
var errorMessage = firstError.ErrorMessage;
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = errorCode,
|
||||
Message = errorMessage,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
var appointmentId = IdentifierGenerator.GenerateId(dto.DoctorId, dto.PatientId);
|
||||
var criteria = new List<(string FieldName, string Value)>
|
||||
{
|
||||
("_id", appointmentId),
|
||||
};
|
||||
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
|
||||
|
||||
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()
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Appointment successfully removed.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.Appointments;
|
||||
|
||||
public class CreateAppointmentValidator : AbstractValidator<AppointmentManagementDto>
|
||||
{
|
||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public CreateAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
|
||||
{
|
||||
RuleFor(x => x.DoctorId)
|
||||
.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")
|
||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||
|
||||
RuleFor(x => x.Appointment)
|
||||
.Must(IsAppointmentValidFormat).WithMessage("Appointment is not valid")
|
||||
.WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
|
||||
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);
|
||||
return patient != null;
|
||||
}
|
||||
|
||||
private bool IsAppointmentValidFormat(DateTime appointment)
|
||||
{
|
||||
if (appointment == default(DateTime))
|
||||
return false;
|
||||
|
||||
if (appointment.Date < DateTime.UtcNow.Date)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> IsAppointmentUnique(AppointmentManagementDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _appointmentsMongoDbService.IsAppointmentUnique(dto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Core.Entities;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.Appointments;
|
||||
|
||||
public class DeleteAppointmentValidator : AbstractValidator<AppointmentManagementDto>
|
||||
{
|
||||
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public DeleteAppointmentValidator(IAppointmentsMongoDbService appointmentsMongoDbService,
|
||||
IDoctorRepository doctorRepository, IPatientRepository patientRepository)
|
||||
{
|
||||
RuleFor(x => x.DoctorId)
|
||||
.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")
|
||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||
|
||||
RuleFor(x => x.Appointment)
|
||||
.Must(IsAppointmentValidFormat).WithMessage("Appointment is not valid")
|
||||
.WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
|
||||
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);
|
||||
return patient != null;
|
||||
}
|
||||
|
||||
private bool IsAppointmentValidFormat(DateTime appointment)
|
||||
{
|
||||
if (appointment == default(DateTime))
|
||||
return false;
|
||||
|
||||
if (appointment.Date < DateTime.UtcNow.Date)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<bool> DoesAppointmentExists(AppointmentManagementDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _appointmentsMongoDbService.DoesAppointmentExists(dto);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class ChatHandler
|
||||
};
|
||||
}
|
||||
|
||||
var chatId = ChatIdentifier.GenerateChatId(sendMessageDto.Sender, sendMessageDto.Receiver);
|
||||
var chatId = IdentifierGenerator.GenerateId(sendMessageDto.Sender, sendMessageDto.Receiver);
|
||||
|
||||
var criteria = new List<(string, string)>();
|
||||
criteria.Add(("_id", chatId));
|
||||
@@ -109,7 +109,7 @@ public class ChatHandler
|
||||
};
|
||||
}
|
||||
|
||||
var chatId = ChatIdentifier.GenerateChatId(getConversationDto.IdUser1, getConversationDto.IdUser2);
|
||||
var chatId = IdentifierGenerator.GenerateId(getConversationDto.IdUser1, getConversationDto.IdUser2);
|
||||
|
||||
var criteria = new List<(string, string)>();
|
||||
criteria.Add(("_id", chatId));
|
||||
|
||||
@@ -13,7 +13,7 @@ public class DoctorProfileValidation : AbstractValidator<DoctorProfileUpdateDto>
|
||||
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is registered in system")
|
||||
.MustAsync(IsDoctorRegistered).WithMessage("Doctor is not registered in system")
|
||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
@@ -40,7 +40,7 @@ public class DoctorProfileValidation : AbstractValidator<DoctorProfileUpdateDto>
|
||||
private async Task<bool> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var doctor = await _doctorRepository.GetByIdAsync(id);
|
||||
return doctor == null;
|
||||
return doctor != null;
|
||||
}
|
||||
|
||||
private async Task<bool> BeUniqueEmail(string email, CancellationToken cancellationToken)
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
namespace Application.Endpoints.Chats;
|
||||
namespace Application.Endpoints;
|
||||
|
||||
public class ChatIdentifier
|
||||
public class IdentifierGenerator
|
||||
{
|
||||
public static string GenerateChatId(Guid id1, Guid id2)
|
||||
public static string GenerateId(Guid id1, Guid id2)
|
||||
{
|
||||
// Convert GUIDs to strings
|
||||
string strId1 = id1.ToString();
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class MedicalHistoryFileManagementHandler
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NoContent,
|
||||
StatusCode = HttpStatusCodes.NotFound,
|
||||
Message = "Medical histories not found",
|
||||
Data = null
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PatientProfileValidation : AbstractValidator<PatientProfileDto>
|
||||
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.MustAsync(IsPatientRegistered).WithMessage("Patient is registered in system")
|
||||
.MustAsync(IsPatientRegistered).WithMessage("Patient is not registered in system")
|
||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
@@ -35,8 +35,8 @@ public class PatientProfileValidation : AbstractValidator<PatientProfileDto>
|
||||
|
||||
private async Task<bool> IsPatientRegistered(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var doctor = await _patientRepository.GetByIdAsync(id);
|
||||
return doctor == null;
|
||||
var patient = await _patientRepository.GetByIdAsync(id);
|
||||
return patient != null;
|
||||
}
|
||||
|
||||
private async Task<bool> BeUniqueEmail(string email, CancellationToken cancellationToken)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Application.Endpoints.Appointments;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Application.Services.Database.MongoDB;
|
||||
|
||||
public interface IAppointmentsMongoDbService
|
||||
{
|
||||
IMongoCollection<T> GetCollection<T>();
|
||||
|
||||
Task<List<T>> FindAsync<T>(List<(string FieldName, string Value)> criteria);
|
||||
|
||||
Task AddAsync<T>(T document);
|
||||
|
||||
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
||||
|
||||
Task DeleteAsync<T>(string keyField, string keyValue);
|
||||
|
||||
Task DeleteByIdAsync<T>(string id);
|
||||
|
||||
public Task<bool> IsAppointmentUnique(AppointmentManagementDto dto);
|
||||
|
||||
public Task<bool> DoesAppointmentExists(AppointmentManagementDto dto);
|
||||
}
|
||||
@@ -13,4 +13,6 @@ public interface IChatMongoDbService
|
||||
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
||||
|
||||
Task DeleteAsync<T>(string keyField, string keyValue);
|
||||
|
||||
Task DeleteByIdAsync<T>(string id);
|
||||
}
|
||||
@@ -14,4 +14,6 @@ public interface IMedicalHistoryMongoDbService
|
||||
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
||||
|
||||
Task DeleteAsync<T>(string keyField, string keyValue);
|
||||
|
||||
Task DeleteByIdAsync<T>(string id);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Application")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+116405bd75830f3dec1c68562965bc78967039d5")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8663a186a056b0dfbfeebf9ae16be42b40101093")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Application")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Application")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
2c0d3af716a6d40ccc6e2610395f654ee8489b15d024a3e4172c975777258df5
|
||||
80601916b304e5754240a2dc14d4162100bc8fba5aed89bf6da00753d5c3920c
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
a14527b9f0436826149b6114fc93ca0d3615f169c5065e509d90189e6d49d7bf
|
||||
23c9f8ecc5e36ec26454d9182eac70caff389e981316327bbd7443ce0fba8796
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/48eb2adcbd149cd66c77ba558f492179d2bf29be/*"}}
|
||||
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/8663a186a056b0dfbfeebf9ae16be42b40101093/*"}}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user