Skip to main content

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 / EntityConflict policyRationale
Accessionserver_authoritativeState machine transitions are strictly ordered; client cannot win a conflict
Specimenserver_authoritativeChain-of-custody integrity requires server to be the single truth
LabResult (draft)server_authoritativeOnly one technologist owns a result at a time; optimistic lock via version
LabResult (verified/released)append_onlyCorrections create new versions; prior versions are immutable
ResultAcknowledgmentappend_onlyAcks are additive facts; cannot be retracted
TestCatalogItemserver_authoritativeAdmin-only mutations; no client-side write expected
CriticalValuePolicyserver_authoritativeAdmin-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=false and 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.