Implement US-08 blood-pressure observation corrections

This commit is contained in:
Steffen committed 2026-10-02 09:31:58 +02:00
1 parent 0ea7866f82
commit e4379ad2f4
8 files changed
+182 -2

No files matched your search

@@ -10,6 +10,10 @@ public sealed class ObservationController(IHttpClientFactory clients) : Controll
public Task RecordObservation(Guid patientId, CancellationToken cancellationToken) =>
ForwardAsync(HttpMethod.Post, $"api/patients/{patientId}/observations", cancellationToken);
[HttpPut("observations/{observationId:guid}")]
public Task UpdateObservation(Guid observationId, CancellationToken cancellationToken) =>
ForwardAsync(HttpMethod.Put, $"api/observations/{observationId}", cancellationToken);
[HttpGet("observations/{observationId:guid}")]
public Task GetObservation(Guid observationId, CancellationToken cancellationToken) =>
ForwardAsync(HttpMethod.Get, $"api/observations/{observationId}", cancellationToken);
@@ -25,7 +29,7 @@ public sealed class ObservationController(IHttpClientFactory clients) : Controll
private async Task ForwardAsync(HttpMethod method, string path, CancellationToken cancellationToken)
{
using var request = new HttpRequestMessage(method, path);
if (method == HttpMethod.Post)
if (method == HttpMethod.Post || method == HttpMethod.Put)
{
request.Content = new StreamContent(Request.Body);
if (Request.ContentType is not null)
@@ -6,6 +6,16 @@ namespace ObservationService.Application;
public sealed class ObservationApplicationService(ObservationRepository repository, IHttpClientFactory clients)
{
public Task<BloodPressureObservation?> UpdateAsync(Guid observationId, UpdateObservationRequest request,
CancellationToken cancellationToken)
{
if (request.Systolic is null or <= 0 || request.Diastolic is null or <= 0 || request.Pulse is null or <= 0)
throw new ArgumentException("Positive measured values are required.", nameof(request));
return repository.UpdateValuesAsync(observationId, request.Systolic.Value, request.Diastolic.Value,
request.Pulse.Value, DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Unspecified), cancellationToken);
}
public async Task<BloodPressureObservation?> RecordAsync(Guid patientId, RecordObservationRequest request,
CancellationToken cancellationToken)
{
@@ -4,6 +4,8 @@ namespace ObservationService.Application;
public interface ObservationRepository
{
Task<BloodPressureObservation?> UpdateValuesAsync(Guid observationId, int systolic, int diastolic, int pulse,
DateTime updatedAt, CancellationToken cancellationToken);
Task<BloodPressureObservation> SaveAsync(BloodPressureObservation observation, CancellationToken cancellationToken);
Task<BloodPressureObservation?> FindByIdAsync(Guid observationId, CancellationToken cancellationToken);
Task<BloodPressureObservation?> FindLatestByPatientIdAsync(Guid patientId, CancellationToken cancellationToken);
@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace ObservationService.Contracts;
public sealed record UpdateObservationRequest
{
[Required, Range(1, int.MaxValue)]
public int? Systolic { get; init; }
[Required, Range(1, int.MaxValue)]
public int? Diastolic { get; init; }
[Required, Range(1, int.MaxValue)]
public int? Pulse { get; init; }
}
@@ -31,6 +31,14 @@ public sealed class ObservationController(ObservationApplicationService service)
}
}
[HttpPut("observations/{observationId:guid}")]
public async Task<ActionResult<ObservationDto>> UpdateObservation(Guid observationId, UpdateObservationRequest request,
CancellationToken cancellationToken)
{
var observation = await service.UpdateAsync(observationId, request, cancellationToken);
return observation is null ? NotFound() : Ok(ToDto(observation));
}
[HttpGet("observations/{observationId:guid}")]
public async Task<ActionResult<ObservationDto>> GetObservation(Guid observationId, CancellationToken cancellationToken)
{
@@ -6,6 +6,22 @@ namespace ObservationService.Persistence;
public sealed class SqlObservationRepository(ObservationDbContext db) : ObservationRepository
{
public async Task<BloodPressureObservation?> UpdateValuesAsync(Guid observationId, int systolic, int diastolic,
int pulse, DateTime updatedAt, CancellationToken cancellationToken)
{
var observation = await db.Observations.SingleOrDefaultAsync(o => o.ObservationId == observationId,
cancellationToken);
if (observation is null)
return null;
observation.Systolic = systolic;
observation.Diastolic = diastolic;
observation.Pulse = pulse;
observation.UpdatedAt = updatedAt;
await db.SaveChangesAsync(cancellationToken);
return observation;
}
public async Task<BloodPressureObservation> SaveAsync(BloodPressureObservation observation, CancellationToken cancellationToken)
{
db.Observations.Add(observation);
+5 -1
View File
@@ -1,4 +1,4 @@
# US-01–US-07: Patient profiles and blood-pressure observations
# US-01–US-08: Patient profiles and blood-pressure observations
Implemented with .NET 10 LTS (see the [official download page](https://dotnet.microsoft.com/en-us/download/dotnet/10.0)), ASP.NET Core controllers, and PostgreSQL/EF Core. The API gateway, Patient/Profile service and Observation Service are separate executables and can run on separate machines. Each domain service owns its database.
@@ -56,6 +56,10 @@ US-06 acceptance tests cover out-of-order measurements, patient-specific selecti
US-07 tests cover all four acceptance scenarios, patient-specific filtering, persistence after restart, inclusive and equal bounds, offset normalization, and malformed/missing bounds without changing saved observations. No new dependencies or schema changes are required.
`PUT /api/observations/{observationId}` corrects the measured values using a JSON body containing required positive integer `systolic`, `diastolic`, and `pulse` fields. It returns `200` with the updated observation, preserving its identifier, patient, measurement time, context, note, and creation timestamp while updating the modification timestamp. Missing observations return `404` without insertion; invalid requests return `400` without changes. Corrections are visible through specific retrieval, latest retrieval, and history. The Observation Service owns the update; no patient-profile lookup or database schema change is required.
US-08 tests cover the documented correction and rejection scenarios, correction of all three values, persistence after restart, preservation of other fields and creation time, modification timestamps, visibility in latest/history, unaffected other observations, and missing/malformed values. No new dependencies are introduced.
Authentication and access control are defined in US-13, US-14 and `Docs/Design/authentication-and-access-control-design.md`, and remain to be implemented as separate stories, as explicitly instructed. These endpoints currently have no access restrictions.
## Automated acceptance tests