Orders Service — Sync Contract
Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template
1. Sync Philosophy
The orders-service is server-authoritative. Orders are clinical instructions requiring CDS validation at the time of entry; offline-created orders must be queued and validated against live CDS rules on submission. No offline-first write pattern is permitted for medication orders due to patient safety requirements. Non-medication orders (lab, radiology requisitions) may be queued offline with re-validation on sync.
2. Conflict Policies by Aggregate
| Aggregate | Conflict policy | Resolution rule |
|---|---|---|
Order (medication) | Server-authoritative; no offline create | Mobile app must buffer and submit only when connected; CDS runs on server at submission time |
Order (lab/radiology) | Server-authoritative with offline queue | clientMutationId deduplication; submitted on reconnect; CDS runs on server |
Order (referral) | Server-authoritative | Referral cannot be created offline |
OrderSet | Server-authoritative | Order set templates are read-only on mobile; created only via connected session |
3. Offline Scenarios
| Scenario | Behaviour |
|---|---|
| Clinician creates medication order offline | App rejects offline creation; shows connectivity required message |
| Clinician creates lab requisition offline | Order stored in device queue with clientMutationId; submitted on reconnect; CDS validation runs at submission |
| Patient allergy added while order is being created offline | CDS on server at activation time catches allergy; app must fetch updated CDS alerts before activation |
| Order cancelled offline | Cancellation queued; submitted on reconnect; if order already completed, server returns ORDER_TERMINAL_STATE |
4. Version Field Usage
- All
Ordermutations require the currentversionin the request body. - Server increments
versionon each state transition. - Mismatch returns 409
OPTIMISTIC_LOCK_CONFLICT. - Client must re-fetch, re-apply intent, and resubmit.
5. Idempotency
POST /v1/ordersacceptsclientMutationIdin request body.- Server caches processed
clientMutationIdin Redis for 24 hours. - Duplicate submission within 24 hours returns the original 201 response.
POST /v1/orders/batchaccepts per-itemclientMutationId.
6. CDS at Sync Time
When a queued non-medication order is submitted after offline period:
- CDS allergy and duplicate checks run against current server state.
- If a new allergy was added while offline, the CDS check may produce alerts not present at queue time.
- Client must re-present CDS alerts to clinician before activation.