Implement US-06 latest blood-pressure observation retrieval
This commit is contained in:
1 parent
05f57dcba3
commit
df47bcbbd7
8 files changed
+97
-2
No files matched your search
@@ -37,4 +37,7 @@ public sealed class ObservationApplicationService(ObservationRepository reposito
|
||||
|
||||
public Task<BloodPressureObservation?> GetByIdAsync(Guid observationId, CancellationToken cancellationToken) =>
|
||||
repository.FindByIdAsync(observationId, cancellationToken);
|
||||
|
||||
public Task<BloodPressureObservation?> GetLatestAsync(Guid patientId, CancellationToken cancellationToken) =>
|
||||
repository.FindLatestByPatientIdAsync(patientId, cancellationToken);
|
||||
}
|
||||
@@ -6,4 +6,5 @@ public interface ObservationRepository
|
||||
{
|
||||
Task<BloodPressureObservation> SaveAsync(BloodPressureObservation observation, CancellationToken cancellationToken);
|
||||
Task<BloodPressureObservation?> FindByIdAsync(Guid observationId, CancellationToken cancellationToken);
|
||||
Task<BloodPressureObservation?> FindLatestByPatientIdAsync(Guid patientId, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -37,6 +37,13 @@ public sealed class ObservationController(ObservationApplicationService service)
|
||||
return observation is null ? NotFound() : Ok(ToDto(observation));
|
||||
}
|
||||
|
||||
[HttpGet("patients/{patientId:guid}/observations/latest")]
|
||||
public async Task<ActionResult<ObservationDto>> GetLatest(Guid patientId, CancellationToken cancellationToken)
|
||||
{
|
||||
var observation = await service.GetLatestAsync(patientId, 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);
|
||||
|
||||
@@ -15,4 +15,9 @@ public sealed class SqlObservationRepository(ObservationDbContext db) : Observat
|
||||
|
||||
public Task<BloodPressureObservation?> FindByIdAsync(Guid observationId, CancellationToken cancellationToken) =>
|
||||
db.Observations.AsNoTracking().SingleOrDefaultAsync(o => o.ObservationId == observationId, cancellationToken);
|
||||
|
||||
public Task<BloodPressureObservation?> FindLatestByPatientIdAsync(Guid patientId, CancellationToken cancellationToken) =>
|
||||
db.Observations.AsNoTracking().Where(o => o.PatientId == patientId)
|
||||
.OrderByDescending(o => o.MeasuredAt).ThenByDescending(o => o.ObservationId)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
Reference in new issue
Block a user