Implement US-06 latest observation recording-time ties
This commit is contained in:
1 parent
3bfa7ea149
commit
ac6b42f32e
3 files changed
+100
-4
No files matched your search
@@ -38,7 +38,8 @@ public sealed class SqlObservationRepository(ObservationDbContext db) : Observat
|
||||
|
||||
public Task<BloodPressureObservation?> FindLatestByPatientIdAsync(Guid patientId, CancellationToken cancellationToken) =>
|
||||
db.Observations.AsNoTracking().Where(o => o.PatientId == patientId)
|
||||
.OrderByDescending(o => o.MeasuredAt).ThenByDescending(o => o.ObservationId)
|
||||
.OrderByDescending(o => o.MeasuredAt).ThenByDescending(o => o.CreatedAt)
|
||||
.ThenByDescending(o => o.ObservationId)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
public Task<List<BloodPressureObservation>> FindByPatientIdAndPeriodAsync(Guid patientId, DateTime from, DateTime to,
|
||||
|
||||
+2
-2
@@ -118,9 +118,9 @@ with US-04; no further production code or migration is needed for US-05.
|
||||
|
||||
The Observation Service checks patient existence by calling the gateway's patient retrieval API over HTTP before saving. It has no reference to Patient/Profile implementation code and no access to that service's database. Missing patients return `404`; validation failures return `400`. Patient lookup failures return `502` or `504` and do not save an observation. Measurement timestamps without an offset represent UTC clock values and are stored as supplied, independently of the host time zone; timestamps with an offset are normalized to UTC. PostgreSQL uses the diagram's `timestamp` columns without a time-zone component.
|
||||
|
||||
`GET /api/patients/{patientId}/observations/latest` returns `200` with that patient's observation having the greatest measurement timestamp, regardless of recording order. It returns `404` when no observation is available. Equal measurement timestamps are resolved consistently by observation identifier; US-06 does not prescribe which tied observation to return. Selection happens in the Observation Service's own database through the documented controller/application-service/repository layers.
|
||||
`GET /api/patients/{patientId}/observations/latest` returns `200` with that patient's observation having the greatest measurement timestamp, regardless of recording order. It returns `404` when no observation is available. Equal measurement timestamps are resolved by greatest original recording timestamp (`created_at`), then greatest observation UUID under PostgreSQL UUID ordering if recording times also tie. Edits preserve original recording time and do not affect tie selection. Context completeness does not affect selection; the returned observation includes its own saved context. Selection happens in the Observation Service's own database through the documented controller/application-service/repository layers.
|
||||
|
||||
US-06 acceptance tests cover out-of-order measurements, patient-specific selection, retrieval after restart, and no available observation even when another patient has recorded measurements. No new dependencies or schema changes are required.
|
||||
US-06 acceptance tests cover out-of-order measurements, patient-specific selection, context independent of suitability/completeness, recording-time ties, later edits, reproducible complete ties across restart, and no available observation even when another patient has recorded measurements. No new dependencies or schema changes are required.
|
||||
|
||||
`GET /api/patients/{patientId}/observations?from=2026-09-03T00:00:00&to=2026-09-08T23:59:59` returns `200` with a JSON array of that patient's observations within the inclusive measurement-time bounds, ordered chronologically. A valid period with no matches returns `[]`. Both timestamps are required; missing, malformed, or reversed bounds return `400` validation problem details. Equal bounds are valid. Offset timestamps are normalized to UTC consistently with recording; encode `+` as `%2B` in query parameters. Equal measurement timestamps are ordered by observation identifier. The query runs in the Observation Service's own database; no patient-profile lookup is needed.
|
||||
|
||||
|
||||
Reference in new issue
Block a user