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,7 +1,7 @@
using Application.Endpoints;
using Application.Endpoints.Appointments;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
@@ -9,8 +9,8 @@ namespace API.Controllers;
public class AppointmentsController : BaseApiController
{
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
private readonly IPatientRepository _patientRepository;
private readonly IDoctorRepository _doctorRepository;
private readonly IPatientRepository _patientRepository;
public AppointmentsController(IAppointmentsMongoDbService appointmentsMongoDbService,
IPatientRepository patientRepository, IDoctorRepository doctorRepository)
@@ -23,7 +23,8 @@ public class AppointmentsController : BaseApiController
[HttpPost]
public async Task<ActionResult<BaseResponse>> CreateAppointment(AppointmentManagementDto dto)
{
var handler = new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
var handler =
new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
var response = await handler.HandleCreateAppointment(dto).ConfigureAwait(false);
return StatusCode(response.StatusCode, response);
}
@@ -31,7 +32,8 @@ public class AppointmentsController : BaseApiController
[HttpDelete]
public async Task<ActionResult<BaseResponse>> DeleteAppointment(AppointmentManagementDto dto)
{
var handler = new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
var handler =
new AppointmentManagementHandler(_appointmentsMongoDbService, _patientRepository, _doctorRepository);
var response = await handler.HandleDeleteAppointment(dto).ConfigureAwait(false);
return StatusCode(response.StatusCode, response);
}
+2 -2
View File
@@ -1,7 +1,7 @@
using Application.Endpoints;
using Application.Endpoints.Chats;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
@@ -9,8 +9,8 @@ namespace API.Controllers;
public class ChatController : BaseApiController
{
private readonly IChatMongoDbService _chatMongoDbService;
private readonly IPatientRepository _patientRepository;
private readonly IDoctorRepository _doctorRepository;
private readonly IPatientRepository _patientRepository;
public ChatController(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
IDoctorRepository doctorRepository)
+5 -17
View File
@@ -3,8 +3,8 @@ using Application.Endpoints.Doctors.Login;
using Application.Endpoints.Doctors.Profile;
using Application.Endpoints.Doctors.Registration;
using Application.Endpoints.Doctors.ResetPassword;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
using Application.Services.Jwt;
using Core.Entities;
@@ -16,10 +16,10 @@ namespace API.Controllers;
[Route("api/[controller]")]
public class DoctorsController : ControllerBase
{
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
private readonly IDoctorRepository _database;
private readonly IHashingAlgorithms _hashingAlgorithms;
private readonly IJwtService _jwtService;
private readonly IAppointmentsMongoDbService _appointmentsMongoDbService;
public DoctorsController(IDoctorRepository database, IHashingAlgorithms hashingAlgorithms,
IJwtService jwtService, IAppointmentsMongoDbService appointmentsMongoDbService)
@@ -61,28 +61,23 @@ public class DoctorsController : ControllerBase
{
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
{
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
{
StatusCode = HttpStatusCodes.BadRequest,
Message = "Invalid request header format.",
Data = null
});
}
var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim();
if (!_jwtService.ValidateJwtToken(oldToken))
{
return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse
{
StatusCode = HttpStatusCodes.Unauthorized,
Message = "Invalid JWT token.",
Data = null
});
}
else
{
var newToken = _jwtService.RefreshToken(oldToken);
return StatusCode(HttpStatusCodes.OK, new BaseResponse
{
@@ -91,7 +86,6 @@ public class DoctorsController : ControllerBase
Data = new { Token = newToken }
});
}
}
[HttpPost("reset_password")]
public async Task<ActionResult<BaseResponse>> ResetPassword(DoctorResetPasswordDto resetDoctorDto)
@@ -131,10 +125,7 @@ public class DoctorsController : ControllerBase
var handler = new DoctorProfileHandler(_database, _hashingAlgorithms);
var response = await handler.HandleDelete(id).ConfigureAwait(false);
if (response.StatusCode < HttpStatusCodes.BadRequest)
{
DeleteDoctorAppointments(id);
}
if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteDoctorAppointments(id);
return StatusCode(response.StatusCode, response);
}
@@ -146,10 +137,7 @@ public class DoctorsController : ControllerBase
("DoctorId", doctorId.ToString())
};
var appointments = await _appointmentsMongoDbService.FindAsync<Appointment>(criteria);
if (!appointments.Any())
{
return;
}
if (!appointments.Any()) return;
await _appointmentsMongoDbService.DeleteByIdAsync<Appointment>(appointments[0].Id);
}
}
@@ -1,8 +1,8 @@
using Application.Endpoints;
using Application.Endpoints.MedicalHistories.FileManagement;
using Application.Endpoints.MedicalHistories.ManageAuthorization;
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
@@ -11,10 +11,10 @@ namespace API.Controllers;
[Route("api/[controller]")]
public class MedicalHistoryController : ControllerBase
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IPatientRepository _patientRepository;
private readonly IDoctorRepository _doctorRepository;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryController(IMedicalHistoryRepository medicalHistoryRepository,
IPatientRepository patientRepository, IMedicalHistoryMongoDbService mongoDbService,
+20 -11
View File
@@ -3,10 +3,9 @@ using Application.Endpoints.Patients.Login;
using Application.Endpoints.Patients.Profile;
using Application.Endpoints.Patients.Registration;
using Application.Endpoints.Patients.ResetPassword;
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
using Application.Services.Jwt;
using Core.Entities;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
@@ -16,15 +15,17 @@ namespace API.Controllers;
public class PatientsController : ControllerBase
{
private readonly IHashingAlgorithms _hashingAlgorithms;
private readonly IPatientRepository _patientRepository;
private readonly IJwtService _jwtService;
private readonly IMedicalHistoryRepository _medicalHistory;
private readonly IPatientRepository _patientRepository;
public PatientsController(IPatientRepository patientRepository, IHashingAlgorithms hashingAlgorithms,
IJwtService jwtService)
IJwtService jwtService, IMedicalHistoryRepository medicalHistory)
{
_patientRepository = patientRepository;
_hashingAlgorithms = hashingAlgorithms;
_jwtService = jwtService;
_medicalHistory = medicalHistory;
}
[HttpGet]
@@ -65,28 +66,23 @@ public class PatientsController : ControllerBase
{
var authorizationHeader = Request.Headers["Authorization"].FirstOrDefault();
if (string.IsNullOrEmpty(authorizationHeader) || !authorizationHeader.StartsWith("Bearer "))
{
return StatusCode(HttpStatusCodes.BadRequest, new BaseResponse
{
StatusCode = HttpStatusCodes.BadRequest,
Message = "Invalid request header format.",
Data = null
});
}
var oldToken = authorizationHeader.Substring("Bearer ".Length).Trim();
if (!_jwtService.ValidateJwtToken(oldToken))
{
return StatusCode(HttpStatusCodes.Unauthorized, new BaseResponse
{
StatusCode = HttpStatusCodes.Unauthorized,
Message = "Invalid JWT token.",
Data = null
});
}
else
{
var newToken = _jwtService.RefreshToken(oldToken);
return StatusCode(HttpStatusCodes.OK, new BaseResponse
{
@@ -95,7 +91,6 @@ public class PatientsController : ControllerBase
Data = new { Token = newToken }
});
}
}
[HttpPost("register")]
public async Task<ActionResult<BaseResponse>> Register(PatientRegistrationDto patientRegistrationDto)
@@ -126,6 +121,20 @@ public class PatientsController : ControllerBase
{
var handler = new PatientProfileHandler(_patientRepository, _hashingAlgorithms);
var response = await handler.HandleDelete(id).ConfigureAwait(false);
if (response.StatusCode < HttpStatusCodes.BadRequest) DeleteMedicalHistory(id);
return StatusCode(response.StatusCode, response);
}
private async void DeleteMedicalHistory(Guid patientId)
{
var medicalHistoryList = await _medicalHistory.GetAllAsync();
foreach (var med in medicalHistoryList)
if (med.UserId == patientId)
{
await _medicalHistory.DeleteAsync(med);
return;
}
}
}
@@ -2,15 +2,11 @@
namespace API.Middlewares;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
public class ApiKeyMiddleware
{
private readonly RequestDelegate _next;
private const string API_KEY_HEADER_NAME = "ApiKey";
private readonly string _apiKey;
private readonly RequestDelegate _next;
public ApiKeyMiddleware(RequestDelegate next, IConfiguration configuration)
{
+3 -7
View File
@@ -1,17 +1,13 @@
using System.Text.Json;
using Application.Endpoints;
using Application.Services.Jwt;
namespace API.Middlewares;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using System.Linq;
using Application.Services.Jwt;
public class JwtMiddleware
{
private readonly RequestDelegate _next;
private readonly IJwtService _jwtService;
private readonly RequestDelegate _next;
public JwtMiddleware(RequestDelegate next, IJwtService jwtService)
{
@@ -24,7 +20,7 @@ public class JwtMiddleware
var path = context.Request.Path.ToString().ToLower();
// Define the paths that should bypass JWT validation
var bypassPaths = new string[]
var bypassPaths = new[]
{
"/api/doctors/login",
"/api/doctors/register",
-6
View File
@@ -1,15 +1,9 @@
using System.Text;
using API.Middlewares;
using Infrastructure;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using System.Text;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("API")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8663a186a056b0dfbfeebf9ae16be42b40101093")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+13bfa2bdd901a8b258d4cf881b5bb079066ab1c6")]
[assembly: System.Reflection.AssemblyProductAttribute("API")]
[assembly: System.Reflection.AssemblyTitleAttribute("API")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
a61f57beead854c5be97ca0cf9336ea23b19a3b596fd07a95a410574950b1887
8e0774eef99f1b59f0ed0c9c924ec32f6e145f2aa7df39a7b5a2d83ccc6da96b
@@ -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,7 +41,7 @@ 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);
@@ -62,7 +62,7 @@ public class AppointmentManagementHandler
await _appointmentsMongoDbService.ModifyAsync("_id", appointmentId, appointment);
}
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.Created,
Message = "Appointment successfully created.",
@@ -93,25 +93,23 @@ 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())
{
return new BaseResponse()
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;
@@ -50,7 +50,7 @@ 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)
@@ -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;
@@ -51,7 +50,7 @@ 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)
@@ -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.Chats;
@@ -7,8 +7,8 @@ namespace Application.Endpoints.Chats;
public class ChatHandler
{
private readonly IChatMongoDbService _chatMongoDbService;
private readonly IPatientRepository _patientRepository;
private readonly IDoctorRepository _doctorRepository;
private readonly IPatientRepository _patientRepository;
public ChatHandler(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
IDoctorRepository doctorRepository)
@@ -38,14 +38,12 @@ public class ChatHandler
}
if (!await CheckForUsersExistence(sendMessageDto.Sender, sendMessageDto.Receiver))
{
return new BaseResponse
{
StatusCode = HttpStatusCodes.BadRequest,
Message = "Users can't be found in the system.",
Data = null
};
}
var chatId = IdentifierGenerator.GenerateId(sendMessageDto.Sender, sendMessageDto.Receiver);
@@ -54,14 +52,12 @@ public class ChatHandler
var documents = await _chatMongoDbService.FindAsync<Chat>(criteria);
if (!documents.Any())
{
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
Message = "Access to medical history not found.",
Data = null
};
}
var chat = documents[0].Messages;
chat.Add(new Message(sendMessageDto.Sender, sendMessageDto.Message));
@@ -100,14 +96,12 @@ public class ChatHandler
}
if (!await CheckForUsersExistence(getConversationDto.IdUser1, getConversationDto.IdUser2))
{
return new BaseResponse
{
StatusCode = HttpStatusCodes.BadRequest,
Message = "Users can't be found in the system.",
Data = null
};
}
var chatId = IdentifierGenerator.GenerateId(getConversationDto.IdUser1, getConversationDto.IdUser2);
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
namespace Application.Endpoints.Doctors.Login;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Doctors.Login;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
namespace Application.Endpoints.Doctors.Profile;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Doctors.Profile;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
using Core.Entities;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Doctors.Registration;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
namespace Application.Endpoints.Doctors.ResetPassword;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Doctors.ResetPassword;
@@ -5,12 +5,12 @@ public class IdentifierGenerator
public static string GenerateId(Guid id1, Guid id2)
{
// Convert GUIDs to strings
string strId1 = id1.ToString();
string strId2 = id2.ToString();
var strId1 = id1.ToString();
var strId2 = id2.ToString();
// Sort the GUID strings
string firstId = strId1.CompareTo(strId2) < 0 ? strId1 : strId2;
string secondId = strId1.CompareTo(strId2) < 0 ? strId2 : strId1;
var firstId = strId1.CompareTo(strId2) < 0 ? strId1 : strId2;
var secondId = strId1.CompareTo(strId2) < 0 ? strId2 : strId1;
// Combine them to get a symmetric string
return firstId + "-" + secondId;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.MedicalHistories.FileManagement;
@@ -1,13 +1,13 @@
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.MedicalHistories.FileManagement;
public class MedicalHistoryFileManagementHandler
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryFileManagementHandler(IMedicalHistoryRepository medicalHistoryRepository,
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.MedicalHistories.FileManagement;
@@ -1,13 +1,13 @@
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
public class MedicalHistoryManageAuthorizationHandler
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IDoctorRepository _doctorRepository;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
public MedicalHistoryManageAuthorizationHandler(IMedicalHistoryRepository medicalHistoryRepository,
IMedicalHistoryMongoDbService medicalHistoryMongoDbService, IDoctorRepository doctorRepository)
@@ -41,28 +41,24 @@ public class MedicalHistoryManageAuthorizationHandler
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
if (!documents.Any())
{
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
Message = "Access to medical history not found.",
Data = null
};
}
var authorisations = documents[0].Authorisation;
if (authorisations.Contains(infoDto.ToString()))
{
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.Conflict,
Message = "Access to medical history already granted.",
Data = null
};
}
authorisations.Add(infoDto.DoctorId.ToString());
var authorizationModel = new MedicalHistoryAuthorisationModel()
var authorizationModel = new MedicalHistoryAuthorisationModel
{
Id = infoDto.MedicalRecordId.ToString(),
Authorisation = authorisations
@@ -70,7 +66,7 @@ public class MedicalHistoryManageAuthorizationHandler
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.OK,
Message = "Access to medical history granted.",
@@ -102,28 +98,24 @@ public class MedicalHistoryManageAuthorizationHandler
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
if (!documents.Any())
{
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.NotFound,
Message = "Access to medical history not found.",
Data = null
};
}
var authorisations = documents[0].Authorisation;
if (!authorisations.Contains(infoDto.DoctorId.ToString()))
{
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.Conflict,
Message = "Access to medical history already revoked.",
Data = null
};
}
authorisations.Remove(infoDto.DoctorId.ToString());
var authorizationModel = new MedicalHistoryAuthorisationModel()
var authorizationModel = new MedicalHistoryAuthorisationModel
{
Id = infoDto.MedicalRecordId.ToString(),
Authorisation = authorisations
@@ -131,7 +123,7 @@ public class MedicalHistoryManageAuthorizationHandler
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
return new BaseResponse()
return new BaseResponse
{
StatusCode = HttpStatusCodes.OK,
Message = "Access to medical history granted.",
@@ -1,12 +1,12 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
public class MedicalHistoryManageAuthorizationValidation : AbstractValidator<MedicalHistoryManageAuthorizationDoctorDto>
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IDoctorRepository _doctorRepository;
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
public MedicalHistoryManageAuthorizationValidation(IMedicalHistoryRepository medicalHistoryRepository,
IDoctorRepository doctorRepository)
@@ -3,5 +3,5 @@
public class MedicalHistoryAuthorisationModel
{
public string Id { get; set; }
public List<string> Authorisation { get; set; } = new List<string>();
public List<string> Authorisation { get; set; } = new();
}
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.MedicalHistories;
@@ -1,13 +1,13 @@
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.MedicalHistories;
public class MedicalHistoryHandler
{
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
private readonly IPatientRepository _patientRepository;
public MedicalHistoryHandler(IMedicalHistoryRepository medicalHistoryRepository,
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.MedicalHistories;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
namespace Application.Endpoints.Patients.Login;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Patients.Login;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
namespace Application.Endpoints.Patients.Profile;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Patients.Profile;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
using Core.Entities;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Patients.Registration;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
namespace Application.Endpoints.Patients.ResetPassword;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using FluentValidation;
namespace Application.Endpoints.Patients.ResetPassword;
@@ -1,5 +1,4 @@
using Application.Endpoints.MedicalHistories;
using MongoDB.Driver;
using MongoDB.Driver;
namespace Application.Services.Database.MongoDB;
@@ -1,5 +0,0 @@
namespace Application.Services.Database;
public interface IConversationRepository
{
}
@@ -1,6 +1,6 @@
using Core.Entities;
namespace Application.Services.Database;
namespace Application.Services.Database.PostgreSQL;
public interface IDoctorRepository
{
@@ -1,6 +1,6 @@
using Core.Entities;
namespace Application.Services.Database;
namespace Application.Services.Database.PostgreSQL;
public interface IMedicalHistoryRepository
{
@@ -1,6 +1,6 @@
using Core.Entities;
namespace Application.Services.Database;
namespace Application.Services.Database.PostgreSQL;
public interface IPatientRepository
{
@@ -10,9 +10,9 @@ public interface IPatientRepository
Task<Patient?> FindByEmailAsync(string email);
Task UpdateAsync(Patient doctor);
Task UpdateAsync(Patient patient);
Task DeleteAsync(Patient doctor);
Task DeleteAsync(Patient patient);
Task<IEnumerable<Patient>> GetAllAsync();
}
@@ -1,6 +1,4 @@
using System.Security.Claims;
namespace Application.Services.Jwt;
namespace Application.Services.Jwt;
public interface IJwtService
{
+19 -6
View File
@@ -10,21 +10,34 @@ public class Appointment
public string Id { get; private set; }
public string PatientId { get; private set; }
public string DoctorId { get; private set; }
public List<DateTime> AppointmentsList { get; private set; }
public List<DateTime> AppointmentsList { get; }
public void SetId(string id) { Id = id; }
public void SetPatientId(string patientId) { PatientId = patientId; }
public void SetDoctorIid(string doctorId) { DoctorId = doctorId; }
public void SetId(string id)
{
Id = id;
}
public void SetPatientId(string patientId)
{
PatientId = patientId;
}
public void SetDoctorIid(string doctorId)
{
DoctorId = doctorId;
}
public void AddAppointment(DateTime appointmentDate)
{
DateTime utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0, DateTimeKind.Utc);
var utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0,
DateTimeKind.Utc);
AppointmentsList.Add(utcAppointmentDate);
}
public void RemoveAppointment(DateTime appointmentDate)
{
DateTime utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0, DateTimeKind.Utc);
var utcAppointmentDate = new DateTime(appointmentDate.Year, appointmentDate.Month, appointmentDate.Day, 0, 0, 0,
DateTimeKind.Utc);
AppointmentsList.Remove(utcAppointmentDate);
}
}
+19 -6
View File
@@ -8,8 +8,15 @@ public class Chat
public string Id { get; private set; }
public List<Message> Messages { get; private set; } = new();
public void SetId(string id) { Id = id; }
public void SetMessages(List<Message> messages) { Messages = messages; }
public void SetId(string id)
{
Id = id;
}
public void SetMessages(List<Message> messages)
{
Messages = messages;
}
}
public class Message
@@ -20,11 +27,17 @@ public class Message
Content = content;
}
[BsonRepresentation(BsonType.String)]
public Guid UserId { get; private set; }
[BsonRepresentation(BsonType.String)] public Guid UserId { get; private set; }
public string Content { get; private set; }
public void SetUserId(Guid userId) { UserId = userId; }
public void SetContent(string content) { Content = content; }
public void SetUserId(Guid userId)
{
UserId = userId;
}
public void SetContent(string content)
{
Content = content;
}
}
+2 -6
View File
@@ -1,17 +1,14 @@
using Application.Services.Database;
using Application.Services.Database.MongoDB;
using Application.Services.Database.MongoDB;
using Application.Services.Database.PostgreSQL;
using Application.Services.HashingAlgorithms;
using Application.Services.Jwt;
using Infrastructure.Data;
using Infrastructure.Services.HashingAlgorithms;
using Infrastructure.Services.MongoDB;
using Infrastructure.Services.PostgreSQL;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Driver;
namespace Infrastructure;
@@ -72,5 +69,4 @@ public static class DependencyInjection
return services;
}
}
@@ -1,17 +1,16 @@
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Application.Services.Jwt;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
public class JwtService : IJwtService
{
private readonly string _secretKey;
private readonly string _issuer;
private readonly string _audience;
private readonly double _expiryMinutes;
private readonly string _issuer;
private readonly string _secretKey;
public JwtService(IConfiguration configuration)
{
@@ -34,7 +33,8 @@ public class JwtService : IJwtService
Expires = DateTime.UtcNow.AddMinutes(_expiryMinutes),
Issuer = _issuer,
Audience = _audience,
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
SigningCredentials =
new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
};
var token = tokenHandler.CreateToken(tokenDescriptor);
@@ -58,8 +58,8 @@ public class JwtService : IJwtService
ValidateAudience = true,
ValidIssuer = _issuer,
ValidAudience = _audience,
ClockSkew = TimeSpan.Zero,
}, out SecurityToken validatedToken);
ClockSkew = TimeSpan.Zero
}, out var validatedToken);
return true;
}
@@ -72,16 +72,10 @@ public class JwtService : IJwtService
public string RefreshToken(string token)
{
var principal = ValidateTokenAndGetPrincipal(token);
if (principal == null)
{
throw new SecurityTokenException("Invalid token.");
}
if (principal == null) throw new SecurityTokenException("Invalid token.");
var emailClaim = principal.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);
if (emailClaim == null)
{
throw new SecurityTokenException("Token does not contain an email claim.");
}
if (emailClaim == null) throw new SecurityTokenException("Token does not contain an email claim.");
return GenerateJwtToken(emailClaim.Value);
}
@@ -100,7 +94,7 @@ public class JwtService : IJwtService
ValidateAudience = true,
ValidIssuer = _issuer,
ValidAudience = _audience,
ClockSkew = TimeSpan.Zero,
ClockSkew = TimeSpan.Zero
}, out _);
return principal;
@@ -111,5 +105,4 @@ public class JwtService : IJwtService
return null;
}
}
}
@@ -24,12 +24,8 @@ public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbSe
var appointments = await FindAsync<Appointment>(criteria);
foreach (var app in appointments)
{
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
{
return false;
}
}
return true;
}
@@ -47,12 +43,8 @@ public class AppointmentsMongoDbService : MongoDbService, IAppointmentsMongoDbSe
var appointments = await FindAsync<Appointment>(criteria);
foreach (var app in appointments)
{
if (app.AppointmentsList.Any(a => a.Date == appointment.Date))
{
return true;
}
}
return false;
}
@@ -1,14 +1,13 @@
using Application.Services.Database;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Bson;
namespace Infrastructure.Services.MongoDB
{
namespace Infrastructure.Services.MongoDB;
public class MongoDbService
{
private readonly string _collectionName;
private readonly IMongoClient _database;
private readonly string _databaseName;
private readonly string _collectionName;
public MongoDbService(string connectionString, string databaseName, string collectionName)
{
@@ -78,4 +77,3 @@ namespace Infrastructure.Services.MongoDB
await collection.DeleteOneAsync(filter);
}
}
}
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Core.Entities;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Core.Entities;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -1,4 +1,4 @@
using Application.Services.Database;
using Application.Services.Database.PostgreSQL;
using Core.Entities;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8663a186a056b0dfbfeebf9ae16be42b40101093")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+13bfa2bdd901a8b258d4cf881b5bb079066ab1c6")]
[assembly: System.Reflection.AssemblyProductAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyTitleAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
90add3a549a5ad86ae4df2628a148c5a9756bdaa56fd8988b963942aa2b42329
30fec65cc45becf276dcf8ed6696bf02cadfb1a90989db6bf5e21ba21d2c8f27