Implement US-04 structured measurement context recording
This commit is contained in:
1 parent
5996481081
commit
cfacaa0c24
13 files changed
+646
-5
No files matched your search
+45
-3
@@ -64,9 +64,51 @@ the account’s profile when its generated identifier is not yet known.
|
||||
|
||||
`PUT /api/patients/{patientId}` updates the name and contact information and returns `200` with the updated profile. It preserves the patient identifier, date of birth and creation timestamp, and updates the modification timestamp. Names must be nonblank, consistent with profile creation; omitted or null contact information clears that optional value. A missing patient returns `404` without creating a profile. Invalid requests return `400` without changing stored information.
|
||||
|
||||
`POST /api/patients/{patientId}/observations` records a blood-pressure observation. Supply `measuredAt`, positive integer `systolic`, `diastolic` and `pulse`, plus optional `context` and `note`. It returns `201`, the saved observation including its generated `observationId` and `patientId`, and `Location: /api/observations/{observationId}`. `GET` at that location retrieves the persisted observation, or returns `404` if absent. Retrieval is included to satisfy US-04's requirement that a recorded observation can be retrieved later.
|
||||
`POST /api/patients/{patientId}/observations` records a blood-pressure observation. Supply `measuredAt`, positive integer `systolic`, `diastolic` and `pulse`, plus optional `measurementContext`, legacy `context` and `note`. It returns `201`, the saved observation including its generated `observationId` and `patientId`, and `Location: /api/observations/{observationId}`. `GET` at that location retrieves the persisted observation, or returns `404` if absent. Retrieval is included to satisfy US-04's requirement that a recorded observation can be retrieved later.
|
||||
|
||||
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 are stored as supplied; timestamps with an offset are normalized to UTC. PostgreSQL uses the diagram's `timestamp` columns without a time-zone component.
|
||||
US-04 now supports structured context independently of legacy free text:
|
||||
|
||||
```json
|
||||
{
|
||||
"measuredAt": "2026-09-12T08:00:00Z",
|
||||
"systolic": 128,
|
||||
"diastolic": 82,
|
||||
"pulse": 68,
|
||||
"measurementContext": {
|
||||
"setting": "Home",
|
||||
"activityCondition": "AtRest",
|
||||
"restDurationMinutes": 5.5,
|
||||
"bodyPosition": "Seated",
|
||||
"measuredArm": "Left",
|
||||
"deviceDetails": "Example upper-arm device",
|
||||
"cuffDetails": "Example cuff",
|
||||
"additionalCircumstances": "Recent stress"
|
||||
},
|
||||
"context": "Before breakfast",
|
||||
"note": "Actual reading"
|
||||
}
|
||||
```
|
||||
|
||||
Supported `setting` values are `Home`, `Clinic`, `Other`, and `Unknown`;
|
||||
`activityCondition` values are `AtRest`, `DuringActivity`, `AfterActivity`, and
|
||||
`Unknown`. Category names are case-sensitive. Omitted/null categories, or an
|
||||
omitted/null object, become `Unknown`; other omitted details stay null. Unsupported
|
||||
categories and malformed fields return `400` validation details without saving.
|
||||
Rest duration is optional, in minutes, and may be zero or any nonnegative decimal.
|
||||
There is no minimum rest duration or posture requirement for accepting a reading.
|
||||
The remaining optional details are narrative text, not technique certification.
|
||||
Legacy context and notes are retained verbatim, including conflicts with categories;
|
||||
no category is inferred from free text. Interpretation of conflicts belongs to
|
||||
US-11. The structured object is included on observation reads and numeric-update
|
||||
responses, including latest/history through their existing observation DTO.
|
||||
|
||||
Apply the `RecordedMeasurementContext` Observation migration before starting the
|
||||
updated service. EF Core maps the owned value to columns in the same observation
|
||||
table; no new table, service or dependency is introduced. Existing rows receive
|
||||
unknown categories and null details without changing their measurements, timestamps
|
||||
or text. Context filtering and context-only updates remain under US-07/US-08.
|
||||
|
||||
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.
|
||||
|
||||
@@ -138,7 +180,7 @@ The xUnit tests send HTTP requests to the gateway; the gateway reaches a real Ke
|
||||
|
||||
US-02 retrieval scenarios are covered by the creation tests. US-03 tests cover persisted updates after restart, preservation of identity and date of birth, missing-patient rejection without insertion, and invalid-name rejection without changing the profile.
|
||||
|
||||
US-04 tests use real HTTP between all three hosts and separate temporary patient and observation databases. They cover every recording acceptance scenario, retrieval after restart, optional fields, distinct identifiers, malformed/missing fields, missing observations, and patient-lookup failure without database writes. Both services' committed migrations are applied twice to verify idempotence. The Observation Service uses the same EF Core PostgreSQL dependencies as Patient/Profile for its independent persistence; no new library types are introduced.
|
||||
US-04 tests use real HTTP between the hosts and separate temporary patient and observation databases. They cover every recording acceptance scenario, retrieval after restart, optional fields, distinct identifiers, malformed/missing fields, missing observations, and patient-lookup failure without database writes. Both services' committed migrations are applied twice to verify idempotence. Context tests also verify complete/partial/absent context, departures from guidance, validation without writes, authorised professional reads, restart persistence, numeric-update preservation, and upgrading historical observations without deriving categories from free text. The Observation Service uses the same EF Core PostgreSQL dependencies as Patient/Profile for its independent persistence; no new library types are introduced.
|
||||
|
||||
Dependencies: Npgsql's EF Core PostgreSQL provider supplies persistence; EF Core Relational is pinned to the same patch as EF Core Design to keep runtime/tooling versions aligned; EF Core Design supports migration maintenance. xUnit, its Visual Studio runner, Microsoft.NET.Test.Sdk, and ASP.NET Core MVC Testing are used only for automated tests. The gateway uses the platform's HttpClient and has no extra package dependency.
|
||||
|
||||
|
||||
Reference in new issue
Block a user