119 lines
5.2 KiB
C#
119 lines
5.2 KiB
C#
using Application.Endpoints;
|
|
using Application.Endpoints.MedicalHistories.CreateMedicalHistory;
|
|
using Application.Endpoints.MedicalHistories.DeleteMedicalHistory;
|
|
using Application.Endpoints.MedicalHistories.ManageAuthorization;
|
|
using Application.Endpoints.MedicalHistories.ModifyMedicalHistory;
|
|
using Application.Endpoints.MedicalHistories.QuerriesMedicalHistories;
|
|
using Application.Services.Database.MongoDB;
|
|
using Application.Services.Database.PostgreSQL;
|
|
using Application.Services.Encryption;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace API.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class MedicalHistoryController(
|
|
IMedicalHistoryRepository medicalHistoryRepository,
|
|
IPatientRepository patientRepository,
|
|
IMedicalHistoryMongoDbService medicalHistoryMongoDbService,
|
|
IDoctorRepository doctorRepository,
|
|
IEncryptionService encryptionService)
|
|
: ControllerBase
|
|
{
|
|
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
|
|
[HttpGet("{id}")]
|
|
public async Task<ActionResult<BaseResponse>> GetMedicalHistory(Guid id, CancellationToken token)
|
|
{
|
|
var handler = new QuerriesMedicalHistoriesHandler(medicalHistoryRepository, encryptionService);
|
|
var response = await handler.HandleGet(id, token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
|
|
[HttpGet("user/{userId}")]
|
|
public async Task<ActionResult<BaseResponse>> GetMedicalHistoryByUserId(Guid userId, CancellationToken token)
|
|
{
|
|
var handler = new QuerriesMedicalHistoriesHandler(medicalHistoryRepository, encryptionService);
|
|
var response = await handler.HandleGetByPatientId(userId, token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
|
|
[HttpGet]
|
|
public async Task<ActionResult<BaseResponse>> GetAllMedicalHistories(CancellationToken token)
|
|
{
|
|
var handler = new QuerriesMedicalHistoriesHandler(medicalHistoryRepository, encryptionService);
|
|
var response = await handler.HandleGetAll(token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.PatientPolicy)]
|
|
[HttpPost]
|
|
public async Task<ActionResult<BaseResponse>> CreateMedicalHistory(
|
|
CreateMedicalHistoryCommand request, CancellationToken token)
|
|
{
|
|
var handler =
|
|
new CreateMedicalHistoryHandler(medicalHistoryRepository, patientRepository,
|
|
medicalHistoryMongoDbService, encryptionService);
|
|
var response = await handler.Handle(request, token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.ClientsOnlyPolicy)]
|
|
[HttpPut]
|
|
public async Task<ActionResult<BaseResponse>> ModifyMedicalHistory(
|
|
ModifyMedicalHistoryCommand request, CancellationToken token)
|
|
{
|
|
var handler = new ModifyMedicalHistoryHandler(medicalHistoryRepository, encryptionService);
|
|
var response = await handler.Handle(request, token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.PatientPolicy)]
|
|
[HttpDelete("{id}")]
|
|
public async Task<ActionResult<BaseResponse>> DeleteMedicalHistory(Guid id, CancellationToken token)
|
|
{
|
|
var handler = new DeleteMedicalHistoryHandler(medicalHistoryRepository, medicalHistoryMongoDbService);
|
|
var response = await handler.Handle(id, token);
|
|
if (response.StatusCode == HttpStatusCodes.NoContent)
|
|
{
|
|
return NoContent();
|
|
}
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.AuthenticatedPolicy)]
|
|
[HttpPost("check_access")]
|
|
public async Task<ActionResult<BaseResponse>> CheckAccessToMedicalHistory(
|
|
MedicalHistoryAuthorizationInfo request, CancellationToken token)
|
|
{
|
|
var handler = new MedicalHistoryManageAuthorizationHandler(medicalHistoryRepository,
|
|
medicalHistoryMongoDbService, doctorRepository);
|
|
var response = await handler.HandleCheckAccessToMedicalHistory(request, token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.PatientPolicy)]
|
|
[HttpPut("grant_access")]
|
|
public async Task<ActionResult<BaseResponse>> GrantAccessToMedicalHistory(
|
|
MedicalHistoryAuthorizationInfo request, CancellationToken token)
|
|
{
|
|
var handler = new MedicalHistoryManageAuthorizationHandler(medicalHistoryRepository,
|
|
medicalHistoryMongoDbService, doctorRepository);
|
|
var response = await handler.HandleGrantDoctorAccess(request, token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.PatientPolicy)]
|
|
[HttpPut("revoke_access")]
|
|
public async Task<ActionResult<BaseResponse>> RevokeAccessToMedicalHistory(
|
|
MedicalHistoryAuthorizationInfo request, CancellationToken token)
|
|
{
|
|
var handler = new MedicalHistoryManageAuthorizationHandler(medicalHistoryRepository,
|
|
medicalHistoryMongoDbService, doctorRepository);
|
|
var response = await handler.HandleRevokeDoctorAccess(request, token);
|
|
return StatusCode(response.StatusCode, response);
|
|
}
|
|
} |