Laboratory Service — Sync Contract
Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template · 03 platform-services · 02 DDD
1. Per-Aggregate Conflict Policy
| Aggregate / Entity | Conflict policy | Rationale |
|---|---|---|
Accession | server_authoritative | State machine transitions are strictly ordered; client cannot win a conflict |
Specimen | server_authoritative | Chain-of-custody integrity requires server to be the single truth |
LabResult (draft) | server_authoritative | Only one technologist owns a result at a time; optimistic lock via version |
LabResult (verified/released) | append_only | Corrections create new versions; prior versions are immutable |
ResultAcknowledgment | append_only | Acks are additive facts; cannot be retracted |
TestCatalogItem | server_authoritative | Admin-only mutations; no client-side write expected |
CriticalValuePolicy | server_authoritative | Admin-only; safety policy must be authoritative |
2. Offline / Edge Considerations
Laboratory service is deployed at facility level and requires network connectivity to the platform hub for:
- FHIR publish on result release
- Critical alert event dispatch
- Terminology validation
Offline degradation rules:
- Accession creation and result entry may proceed offline using locally cached test catalog.
- Terminology validation is flagged
terminology_validated=falseand re-validated on reconnect. - Release to chart is queued and executed when platform connectivity is restored; the outbox pattern handles this.
- Critical alerts are buffered in the outbox and delivered as soon as NATS connection is re-established.
3. Optimistic Locking
All mutable rows include a version column. Concurrent updates use:
UPDATE lab_results
SET status = $newStatus, version = version + 1, updated_at = NOW()
WHERE id = $id AND version = $expectedVersion;
If 0 rows updated → 409 CONFLICT returned to client.