jwt v1.0
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Core.Entities;
|
||||
|
||||
namespace Application.Endpoints.Chats;
|
||||
|
||||
public class ChatHandler
|
||||
{
|
||||
private readonly IChatMongoDbService _chatMongoDbService;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
|
||||
public ChatHandler(IChatMongoDbService chatMongoDbService, IPatientRepository patientRepository,
|
||||
IDoctorRepository doctorRepository)
|
||||
{
|
||||
_chatMongoDbService = chatMongoDbService;
|
||||
_patientRepository = patientRepository;
|
||||
_doctorRepository = doctorRepository;
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleSendMessage(SendMessageDto sendMessageDto)
|
||||
{
|
||||
var validation = new SendMessageValidator();
|
||||
var validationResult = await validation.ValidateAsync(sendMessageDto);
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
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 = ChatIdentifier.GenerateChatId(sendMessageDto.Sender, sendMessageDto.Receiver);
|
||||
|
||||
var criteria = new List<(string, string)>();
|
||||
criteria.Add(("_id", chatId));
|
||||
|
||||
var documents = await _chatMongoDbService.FindAsync<Chat>(criteria);
|
||||
if (!documents.Any())
|
||||
{
|
||||
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));
|
||||
|
||||
var newChat = new Chat();
|
||||
newChat.SetId(chatId);
|
||||
newChat.SetMessages(chat);
|
||||
|
||||
await _chatMongoDbService.ModifyAsync("_id", chatId, newChat);
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NoContent,
|
||||
Message = null,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleGetConversation(GetConversationDto getConversationDto)
|
||||
{
|
||||
var validation = new GetConversationValidator();
|
||||
var validationResult = await validation.ValidateAsync(getConversationDto);
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
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 = ChatIdentifier.GenerateChatId(getConversationDto.IdUser1, getConversationDto.IdUser2);
|
||||
|
||||
var criteria = new List<(string, string)>();
|
||||
criteria.Add(("_id", chatId));
|
||||
|
||||
Chat? chat = null;
|
||||
|
||||
var documents = await _chatMongoDbService.FindAsync<Chat>(criteria);
|
||||
if (!documents.Any())
|
||||
{
|
||||
chat = new Chat();
|
||||
chat.SetId(chatId);
|
||||
|
||||
await _chatMongoDbService.AddAsync(chat);
|
||||
}
|
||||
else
|
||||
{
|
||||
chat = documents[0];
|
||||
}
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Fetching messages.",
|
||||
Data = chat
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<bool> CheckForUsersExistence(Guid idUser1, Guid idUser2)
|
||||
{
|
||||
var firstCheck = await _patientRepository.GetByIdAsync(idUser1) != null &&
|
||||
await _doctorRepository.GetByIdAsync(idUser2) != null;
|
||||
|
||||
var secondCheck = await _patientRepository.GetByIdAsync(idUser2) != null &&
|
||||
await _doctorRepository.GetByIdAsync(idUser1) != null;
|
||||
|
||||
return firstCheck || secondCheck;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Application.Endpoints.Chats;
|
||||
|
||||
public class ChatIdentifier
|
||||
{
|
||||
public static string GenerateChatId(Guid id1, Guid id2)
|
||||
{
|
||||
// Convert GUIDs to strings
|
||||
string strId1 = id1.ToString();
|
||||
string strId2 = id2.ToString();
|
||||
|
||||
// Sort the GUID strings
|
||||
string firstId = strId1.CompareTo(strId2) < 0 ? strId1 : strId2;
|
||||
string secondId = strId1.CompareTo(strId2) < 0 ? strId2 : strId1;
|
||||
|
||||
// Combine them to get a symmetric string
|
||||
return firstId + "-" + secondId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Application.Endpoints.Chats;
|
||||
|
||||
public class GetConversationDto
|
||||
{
|
||||
public Guid IdUser1 { get; set; }
|
||||
public Guid IdUser2 { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.Chats;
|
||||
|
||||
public class GetConversationValidator : AbstractValidator<GetConversationDto>
|
||||
{
|
||||
public GetConversationValidator()
|
||||
{
|
||||
RuleFor(x => x.IdUser1)
|
||||
.NotEmpty().WithMessage("IdUser1 is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
|
||||
RuleFor(x => x.IdUser2)
|
||||
.NotEmpty().WithMessage("IdUser2 is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Application.Endpoints.Chats;
|
||||
|
||||
public class SendMessageDto
|
||||
{
|
||||
public Guid Sender { get; set; }
|
||||
public Guid Receiver { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.Chats;
|
||||
|
||||
public class SendMessageValidator : AbstractValidator<SendMessageDto>
|
||||
{
|
||||
public SendMessageValidator()
|
||||
{
|
||||
RuleFor(x => x.Sender)
|
||||
.NotEmpty().WithMessage("Sender Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
|
||||
RuleFor(x => x.Receiver)
|
||||
.NotEmpty().WithMessage("Receiver Id is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
|
||||
RuleFor(x => x.Message)
|
||||
.NotEmpty().WithMessage("Message is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||
|
||||
public class MedicalHistoryCreateDto
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public byte[] Content { get; set; } = [];
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
using Application.Services.Database;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||
|
||||
public class MedicalHistoryCreateValidation : AbstractValidator<MedicalHistoryCreateDto>
|
||||
{
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public MedicalHistoryCreateValidation(IPatientRepository patientRepository)
|
||||
{
|
||||
_patientRepository = patientRepository;
|
||||
|
||||
RuleFor(x => x.UserId)
|
||||
.NotEmpty().WithMessage("Patient is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.MustAsync(BeExistingUser).WithMessage("Specified patient doesn't exist.")
|
||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||
|
||||
RuleFor(x => x.Content)
|
||||
.NotEmpty().WithMessage("Description is required.").WithErrorCode(HttpStatusCodes.BadRequest.ToString());
|
||||
}
|
||||
|
||||
private async Task<bool> BeExistingUser(Guid userId, CancellationToken cancellationToken)
|
||||
{
|
||||
var patient = await _patientRepository.GetByIdAsync(userId);
|
||||
return patient != null;
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
using Core.Entities;
|
||||
|
||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||
|
||||
public class MedicalHistoryFileManagementHandler
|
||||
{
|
||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public MedicalHistoryFileManagementHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
||||
IPatientRepository patientRepository, IMedicalHistoryMongoDbService medicalHistoryMongoDbService)
|
||||
{
|
||||
_medicalHistoryRepository = medicalHistoryRepository;
|
||||
_patientRepository = patientRepository;
|
||||
_medicalHistoryMongoDbService = medicalHistoryMongoDbService;
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleGetAll()
|
||||
{
|
||||
var documents = await _medicalHistoryRepository.GetAllAsync().ConfigureAwait(false);
|
||||
if (documents.Any())
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Retrieved medical histories",
|
||||
Data = documents.ToList()
|
||||
};
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NoContent,
|
||||
Message = "Medical histories not found",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleGet(Guid id)
|
||||
{
|
||||
var medicalHistory = await _medicalHistoryRepository.GetByIdAsync(id).ConfigureAwait(false);
|
||||
if (medicalHistory != null)
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Medical history successfully retrieved",
|
||||
Data = medicalHistory
|
||||
};
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NotFound,
|
||||
Message = "Medical history not found in system.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleCreate(MedicalHistoryCreateDto medicalHistoryCreateDto)
|
||||
{
|
||||
var validation = new MedicalHistoryCreateValidation(_patientRepository);
|
||||
var validationResult = await validation.ValidateAsync(medicalHistoryCreateDto);
|
||||
|
||||
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 medicalHistory = new MedicalHistory
|
||||
{
|
||||
UserId = medicalHistoryCreateDto.UserId,
|
||||
Content = medicalHistoryCreateDto.Content
|
||||
};
|
||||
|
||||
var medicalHistoryId = medicalHistory.Id;
|
||||
var newMedicalHistory = new MedicalHistoryAuthorisationModel
|
||||
{
|
||||
Id = medicalHistoryId.ToString(),
|
||||
Authorisation = new List<string>()
|
||||
};
|
||||
|
||||
await _medicalHistoryMongoDbService.AddAsync(newMedicalHistory);
|
||||
await _medicalHistoryRepository.AddAsync(medicalHistory);
|
||||
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.Created,
|
||||
Message = "Medical history record registered successfully",
|
||||
Data = medicalHistory
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleUpdate(MedicalHistoryUpdateDto updateDto)
|
||||
{
|
||||
var validation = new MedicalHistoryUpdateValidation(_medicalHistoryRepository, _patientRepository);
|
||||
var validationResult = await validation.ValidateAsync(updateDto);
|
||||
|
||||
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 medicalHistoryToUpdate = await _medicalHistoryRepository.GetByIdAsync(updateDto.Id);
|
||||
medicalHistoryToUpdate.Content = updateDto.Content;
|
||||
|
||||
await _medicalHistoryRepository.UpdateAsync(medicalHistoryToUpdate);
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NoContent,
|
||||
Message = "Medical record updated successfully",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleDelete(Guid id)
|
||||
{
|
||||
var medicalRecord = await _medicalHistoryRepository.GetByIdAsync(id);
|
||||
if (medicalRecord == null)
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NotFound,
|
||||
Message = "Medical record is not in system.",
|
||||
Data = null
|
||||
};
|
||||
|
||||
await _medicalHistoryMongoDbService.DeleteAsync<MedicalHistoryAuthorisationModel>("_id", id.ToString());
|
||||
|
||||
await _medicalHistoryRepository.DeleteAsync(medicalRecord);
|
||||
|
||||
//TODO delete from MongoDB
|
||||
return new BaseResponse
|
||||
{
|
||||
StatusCode = HttpStatusCodes.NoContent,
|
||||
Message = null,
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||
|
||||
public class MedicalHistoryUpdateDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public byte[] Content { get; set; } = [];
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
using Application.Services.Database;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.MedicalHistories.FileManagement;
|
||||
|
||||
public class MedicalHistoryUpdateValidation : AbstractValidator<MedicalHistoryUpdateDto>
|
||||
{
|
||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||
private readonly IPatientRepository _patientRepository;
|
||||
|
||||
public MedicalHistoryUpdateValidation(IMedicalHistoryRepository medicalHistoryRepository,
|
||||
IPatientRepository patientRepository)
|
||||
{
|
||||
_medicalHistoryRepository = medicalHistoryRepository;
|
||||
_patientRepository = patientRepository;
|
||||
|
||||
RuleFor(x => x.Id)
|
||||
.NotEmpty().WithMessage("Id is required")
|
||||
.MustAsync(BeExistingMedicalHistoryRecord).WithMessage("Medical history record does not exist");
|
||||
|
||||
RuleFor(x => x.Content)
|
||||
.NotEmpty().WithMessage("Description is required.");
|
||||
}
|
||||
|
||||
private async Task<bool> BeExistingMedicalHistoryRecord(Guid guid, CancellationToken token)
|
||||
{
|
||||
var record = await _medicalHistoryRepository.GetByIdAsync(guid);
|
||||
return record != null;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
|
||||
|
||||
public class MedicalHistoryManageAuthorizationDoctorDto
|
||||
{
|
||||
public Guid MedicalRecordId { get; set; }
|
||||
public Guid DoctorId { get; set; }
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
using Application.Services.Database;
|
||||
using Application.Services.Database.MongoDB;
|
||||
|
||||
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
|
||||
|
||||
public class MedicalHistoryManageAuthorizationHandler
|
||||
{
|
||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
private readonly IMedicalHistoryMongoDbService _medicalHistoryMongoDbService;
|
||||
|
||||
public MedicalHistoryManageAuthorizationHandler(IMedicalHistoryRepository medicalHistoryRepository,
|
||||
IMedicalHistoryMongoDbService medicalHistoryMongoDbService, IDoctorRepository doctorRepository)
|
||||
{
|
||||
_medicalHistoryRepository = medicalHistoryRepository;
|
||||
_medicalHistoryMongoDbService = medicalHistoryMongoDbService;
|
||||
_doctorRepository = doctorRepository;
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleGrantDoctorAccess(MedicalHistoryManageAuthorizationDoctorDto infoDto)
|
||||
{
|
||||
var validation = new MedicalHistoryManageAuthorizationValidation(_medicalHistoryRepository, _doctorRepository);
|
||||
var validationResult = await validation.ValidateAsync(infoDto);
|
||||
|
||||
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 criteria = new List<(string, string)>();
|
||||
criteria.Add(("_id", infoDto.MedicalRecordId.ToString()));
|
||||
|
||||
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
|
||||
if (!documents.Any())
|
||||
{
|
||||
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()
|
||||
{
|
||||
StatusCode = HttpStatusCodes.Conflict,
|
||||
Message = "Access to medical history already granted.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
authorisations.Add(infoDto.DoctorId.ToString());
|
||||
var authorizationModel = new MedicalHistoryAuthorisationModel()
|
||||
{
|
||||
Id = infoDto.MedicalRecordId.ToString(),
|
||||
Authorisation = authorisations
|
||||
};
|
||||
|
||||
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
|
||||
|
||||
return new BaseResponse()
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Access to medical history granted.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<BaseResponse> HandleRevokeDoctorAccess(MedicalHistoryManageAuthorizationDoctorDto infoDto)
|
||||
{
|
||||
var validation = new MedicalHistoryManageAuthorizationValidation(_medicalHistoryRepository, _doctorRepository);
|
||||
var validationResult = await validation.ValidateAsync(infoDto);
|
||||
|
||||
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 criteria = new List<(string, string)>();
|
||||
criteria.Add(("_id", infoDto.MedicalRecordId.ToString()));
|
||||
|
||||
var documents = await _medicalHistoryMongoDbService.FindAsync<MedicalHistoryAuthorisationModel>(criteria);
|
||||
if (!documents.Any())
|
||||
{
|
||||
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()
|
||||
{
|
||||
StatusCode = HttpStatusCodes.Conflict,
|
||||
Message = "Access to medical history already revoked.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
|
||||
authorisations.Remove(infoDto.DoctorId.ToString());
|
||||
var authorizationModel = new MedicalHistoryAuthorisationModel()
|
||||
{
|
||||
Id = infoDto.MedicalRecordId.ToString(),
|
||||
Authorisation = authorisations
|
||||
};
|
||||
|
||||
await _medicalHistoryMongoDbService.ModifyAsync("_id", infoDto.MedicalRecordId.ToString(), authorizationModel);
|
||||
|
||||
return new BaseResponse()
|
||||
{
|
||||
StatusCode = HttpStatusCodes.OK,
|
||||
Message = "Access to medical history granted.",
|
||||
Data = null
|
||||
};
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
using Application.Services.Database;
|
||||
using FluentValidation;
|
||||
|
||||
namespace Application.Endpoints.MedicalHistories.ManageAuthorization;
|
||||
|
||||
public class MedicalHistoryManageAuthorizationValidation : AbstractValidator<MedicalHistoryManageAuthorizationDoctorDto>
|
||||
{
|
||||
private readonly IMedicalHistoryRepository _medicalHistoryRepository;
|
||||
private readonly IDoctorRepository _doctorRepository;
|
||||
|
||||
public MedicalHistoryManageAuthorizationValidation(IMedicalHistoryRepository medicalHistoryRepository,
|
||||
IDoctorRepository doctorRepository)
|
||||
{
|
||||
RuleFor(x => x.MedicalRecordId)
|
||||
.NotEmpty().WithMessage("Id is required").WithErrorCode(HttpStatusCodes.BadRequest.ToString())
|
||||
.MustAsync(BeExistingMedicalHistoryRecord).WithMessage("Medical history record does not exist")
|
||||
.WithErrorCode(HttpStatusCodes.NotFound.ToString());
|
||||
|
||||
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());
|
||||
|
||||
_medicalHistoryRepository = medicalHistoryRepository;
|
||||
_doctorRepository = doctorRepository;
|
||||
}
|
||||
|
||||
private async Task<bool> BeExistingMedicalHistoryRecord(Guid guid, CancellationToken token)
|
||||
{
|
||||
var record = await _medicalHistoryRepository.GetByIdAsync(guid);
|
||||
return record != null;
|
||||
}
|
||||
|
||||
private async Task<bool> IsDoctorRegistered(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var doctor = await _doctorRepository.GetByIdAsync(id);
|
||||
return doctor != null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,16 @@
|
||||
namespace Application.Services.Database.MongoDB;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Application.Services.Database.MongoDB;
|
||||
|
||||
public interface IChatMongoDbService
|
||||
{
|
||||
// Additional methods specific to Chat database
|
||||
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);
|
||||
}
|
||||
@@ -5,13 +5,13 @@ namespace Application.Services.Database.MongoDB;
|
||||
|
||||
public interface IMedicalHistoryMongoDbService
|
||||
{
|
||||
IMongoCollection<MedicalHistoryAuthorisationModel> GetCollection<MedicalHistoryAuthorisationModel>();
|
||||
IMongoCollection<T> GetCollection<T>();
|
||||
|
||||
Task<List<MedicalHistoryAuthorisationModel>> FindAsync<MedicalHistoryAuthorisationModel>(List<(string FieldName, string Value)> criteria);
|
||||
Task<List<T>> FindAsync<T>(List<(string FieldName, string Value)> criteria);
|
||||
|
||||
Task AddAsync<MedicalHistoryAuthorisationModel>(MedicalHistoryAuthorisationModel document);
|
||||
Task AddAsync<T>(T document);
|
||||
|
||||
Task ModifyAsync<MedicalHistoryAuthorisationModel>(string keyField, string keyValue, MedicalHistoryAuthorisationModel document);
|
||||
Task ModifyAsync<T>(string keyField, string keyValue, T document);
|
||||
|
||||
Task DeleteAsync<MedicalHistoryAuthorisationModel>(string keyField, string keyValue);
|
||||
Task DeleteAsync<T>(string keyField, string keyValue);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Application.Services.Jwt;
|
||||
|
||||
public interface IJwtService
|
||||
{
|
||||
string GenerateJwtToken(string email);
|
||||
bool ValidateJwtToken(string token);
|
||||
string? RefreshToken(string token);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,14 +14,12 @@
|
||||
"outputPath": "C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\Andrei Cerbu\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
"C:\\Users\\Andrei Cerbu\\AppData\\Roaming\\NuGet\\NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
@@ -69,7 +67,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Users\\Andrei Cerbu\\.dotnet\\sdk\\8.0.203/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -83,14 +81,12 @@
|
||||
"outputPath": "C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\Andrei Cerbu\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
"C:\\Users\\Andrei Cerbu\\AppData\\Roaming\\NuGet\\NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
@@ -130,7 +126,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Users\\Andrei Cerbu\\.dotnet\\sdk\\8.0.203/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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+61a55fa7353346bdad2d677f0ec3c044c3aa87d5")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+90604e48ae9f78fa417a446c05f7759001447de5")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Application")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Application")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@@ -1 +1 @@
|
||||
ca8d9dbfc6e022b60b63524e70a3acb8ce1eaa86a2b066fce9c4864553b6125d
|
||||
4068cc9959fca65509f12b041892bbe15b7b0ed4cb99494d72cf4e4d471b7ce1
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
e99f7362e6da84368608067cdbb0c281eef010bca303f59d33c712edf6a9964f
|
||||
a14527b9f0436826149b6114fc93ca0d3615f169c5065e509d90189e6d49d7bf
|
||||
|
||||
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/61a55fa7353346bdad2d677f0ec3c044c3aa87d5/*"}}
|
||||
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/48eb2adcbd149cd66c77ba558f492179d2bf29be/*"}}
|
||||
Binary file not shown.
Binary file not shown.
@@ -851,14 +851,12 @@
|
||||
"outputPath": "C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\Andrei Cerbu\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
"C:\\Users\\Andrei Cerbu\\AppData\\Roaming\\NuGet\\NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
@@ -906,7 +904,7 @@
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"
|
||||
"runtimeIdentifierGraphPath": "C:\\Users\\Andrei Cerbu\\.dotnet\\sdk\\8.0.203/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "+8cvg1kefgWQCHZNz0UFBqaMFHCU9vs6eKiSXlImrLEp7SlxQgKE4onuOThyjCArZTaU+iPlTxlBKu/wIdbkNg==",
|
||||
"dgSpecHash": "6rK5hZ4j6ClAzfxuWc17Wft98VDUQupYiEeI5viBfPq8M3e7wy2vBJ/LEy/lClFvezbz4wHPGdpeQDPOA9ZtBw==",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj",
|
||||
"expectedPackageFiles": [
|
||||
|
||||
@@ -1 +1 @@
|
||||
"restore":{"projectUniqueName":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj","projectName":"Application","projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj","outputPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\obj\\","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\":{},"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj":{"projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj"}}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net8.0":{"targetAlias":"net8.0","dependencies":{"FluentValidation":{"target":"Package","version":"[11.9.0, )"},"MongoDB.Driver":{"target":"Package","version":"[2.24.0, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"}}
|
||||
"restore":{"projectUniqueName":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj","projectName":"Application","projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj","outputPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\obj\\","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj":{"projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj"}}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net8.0":{"targetAlias":"net8.0","dependencies":{"FluentValidation":{"target":"Package","version":"[11.9.0, )"},"MongoDB.Driver":{"target":"Package","version":"[2.24.0, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Users\\Andrei Cerbu\\.dotnet\\sdk\\8.0.203/PortableRuntimeIdentifierGraph.json"}}
|
||||
@@ -1 +1 @@
|
||||
17122552827049708
|
||||
17125558124497896
|
||||
@@ -1 +1 @@
|
||||
17125075151933320
|
||||
17125685577729624
|
||||
Reference in New Issue
Block a user