Implement US-04 blood-pressure observation recording

This commit is contained in:
Steffen committed 2026-10-01 11:55:31 +02:00
1 parent a9633e49e1
commit 05f57dcba3
25 files changed
+843 -9

No files matched your search

@@ -0,0 +1,43 @@
using Microsoft.AspNetCore.Mvc;
using ObservationService.Application;
using ObservationService.Contracts;
using ObservationService.Domain;
namespace ObservationService.Controllers;
[ApiController]
[Route("api")]
public sealed class ObservationController(ObservationApplicationService service) : ControllerBase
{
[HttpPost("patients/{patientId:guid}/observations")]
public async Task<ActionResult<ObservationDto>> RecordObservation(Guid patientId, RecordObservationRequest request,
CancellationToken cancellationToken)
{
try
{
var observation = await service.RecordAsync(patientId, request, cancellationToken);
return observation is null
? NotFound()
: CreatedAtAction(nameof(GetObservation), new { observationId = observation.ObservationId }, ToDto(observation));
}
catch (HttpRequestException)
{
return Problem(statusCode: StatusCodes.Status502BadGateway, title: "Patient lookup is unavailable.");
}
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
{
return Problem(statusCode: StatusCodes.Status504GatewayTimeout, title: "Patient lookup timed out.");
}
}
[HttpGet("observations/{observationId:guid}")]
public async Task<ActionResult<ObservationDto>> GetObservation(Guid observationId, CancellationToken cancellationToken)
{
var observation = await service.GetByIdAsync(observationId, cancellationToken);
return observation is null ? NotFound() : Ok(ToDto(observation));
}
private static ObservationDto ToDto(BloodPressureObservation observation) =>
new(observation.ObservationId, observation.PatientId, observation.MeasuredAt, observation.Systolic,
observation.Diastolic, observation.Pulse, observation.Context, observation.Note);
}