Implement US-12 consolidated health overview service
This commit is contained in:
1 parent
cc76c9bde4
commit
076e675c81
26 files changed
+804
-16
No files matched your search
@@ -0,0 +1,34 @@
|
||||
using HealthOverviewService.Application;
|
||||
using HealthOverviewService.Contracts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace HealthOverviewService.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/patients/{patientId:guid}/overview")]
|
||||
public sealed class HealthOverviewController(HealthOverviewApplicationService service) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<HealthOverviewDto>> GetOverview(Guid patientId,
|
||||
[FromQuery, BindRequired] DateTime from, [FromQuery, BindRequired] DateTime to,
|
||||
[FromQuery] ContextSelection selection, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await service.GetOverviewAsync(patientId, from, to, selection, cancellationToken);
|
||||
return result is null ? Problem(statusCode: 404, title: "Patient does not exist.") : Ok(result);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
ModelState.AddModelError(nameof(to), "The end time must not be earlier than the start time.");
|
||||
return ValidationProblem(ModelState);
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{ return Problem(statusCode: 502, title: "Overview source service is unavailable."); }
|
||||
catch (System.Text.Json.JsonException)
|
||||
{ return Problem(statusCode: 502, title: "Overview source response is invalid."); }
|
||||
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
|
||||
{ return Problem(statusCode: 504, title: "Overview source request timed out."); }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user