System Design Atlas

Hospital medication orders

05 / 10Worked example

Data and states

What changes to medication order must apply jointly, and what remains protected after completion?

The contracts require a authoritative datastore for medication order M-26. The prescription revision identifies content, the aggregate version protects workflow state, and the documentation event records a reported action. A scan alone proves neither the actual action nor clinical suitability. The state is stored together with its command result; this keeps the same change task visible after restart. Dispensing record A-26 records the confirmed dispensing event and its reference to the verified prescription revision.

Starting point Dispensing requires the revision and verification evidence.

Assumptions for the example case

Own fictitious example design. A fictional documentation workflow for a single medication order whose clinical decisions have already been made, without recommendations on substances, doses or treatment. Technical feedback is marked for clarification from age 60 seconds onwards; this threshold does not provide medical clearance. All figures and test goals are illustrative assumptions.

Authoritative data and permitted state transitions

Revision, status of processing and action

Order M-26current processing status with aggregate version 7
Prescription revision R-26Immutable prescription content
Verification record P-26Domain verification of exactly R-26
Dispensing record A-26Reported dispensing; no evidence of administration
Auftrag M-26 → Verordnungsrevision R-26binds current revision
Prüfbeleg P-26 → Verordnungsrevision R-26Exactly checks this revision
Auftrag M-26 → Ausgabenachweis A-26Has at most one effective dispensing event
1entwurf → geprüft for the current revision
2geprüft → ausgegeben with a dispensing record
3New revision after dispensing → klärfall; evidence is preserved
4dokumentiert or storniert blocks new dispensing

The prescription revision identifies content, the aggregate version protects workflow state, and the documentation event records a reported action.

The prescription revision identifies content, the aggregate version protects workflow state, and the documentation event records a reported action. A scan alone proves neither the actual action nor clinical suitability.

Domain entities and relationships

EntityAuthoritative attributesRelationship
Medication orderM-26; ownership and aggregate versionContains exactly one currently valid prescription revision.
Prescription revisionR-26; immutable prescription contentA new revision requires verification of that revision.
Evidence of verification and dispensingRevision, acting professional, timeVerification and dispensing are separate records for the same revision.
Documentation eventD-26; actual action or omissionReferences the order and dispensing record; corrections are appended separately with a traceable history.

Medication order

Authoritative attributes
M-26; ownership and aggregate version
Relationship
Contains exactly one currently valid prescription revision.

Prescription revision

Authoritative attributes
R-26; immutable prescription content
Relationship
A new revision requires verification of that revision.

Evidence of verification and dispensing

Authoritative attributes
Revision, acting professional, time
Relationship
Verification and dispensing are separate records for the same revision.

Documentation event

Authoritative attributes
D-26; actual action or omission
Relationship
References the order and dispensing record; corrections are appended separately with a traceable history.

Permitted state transitions

Starting pointTargetPrecondition
VerifiedentwurfNew prescription revision before issuance; previous verification record only applies historically.
entwurfVerifiedVerifying professional confirms exactly the current prescription revision.
VerifiedausgegebenThe dispensing professional confirms the same verified revision.
entwurf or geprüftstorniertPrescriber cancels before dispensing.
ausgegebendokumentiertActual action or justified omission shall be documented.
ausgegebenklärfallA change request after dispensing requires domain review and evidence of the actual outcome before completion.
klärfalldokumentiertThe actual outcome is evidenced and domain review is confirmed.
dokumentiert or storniertterminalNew dispensing is blocked; corrections use a separate traceable revision.

Verified

Target
entwurf
Precondition
New prescription revision before issuance; previous verification record only applies historically.

entwurf

Target
Verified
Precondition
Verifying professional confirms exactly the current prescription revision.

Verified

Target
ausgegeben
Precondition
The dispensing professional confirms the same verified revision.

entwurf or geprüft

Target
storniert
Precondition
Prescriber cancels before dispensing.

ausgegeben

Target
dokumentiert
Precondition
Actual action or justified omission shall be documented.

ausgegeben

Target
klärfall
Precondition
A change request after dispensing requires domain review and evidence of the actual outcome before completion.

klärfall

Target
dokumentiert
Precondition
The actual outcome is evidenced and domain review is confirmed.

dokumentiert or storniert

Target
terminal
Precondition
New dispensing is blocked; corrections use a separate traceable revision.

Atomic changes and versions

Content reference
The prescription revision identifies content, the aggregate version protects workflow state, and the documentation event records a reported action. A scan alone proves neither the actual action nor clinical suitability.
Shared commit
Medication Documentation API reviews order, current prescription revision, review document, dispensing event and writes domain change, command result and, if applicable, pending work in a transaction. Commit means that these changes become permanently visible together. Before commit, a rollback ends the attempt without partial effect.
Concurrency
Change and dispensing both expect version 7. If the change wins, dispensing loses the old approval. If dispensing wins, the change is rejected and, after a fresh read, handled as an investigation case; dispensing that already occurred remains recorded.
Terminal completion
In dokumentiert and storniert, new dispensing creates a conflict. Cancellation does not retroactively undo an action already documented.

Cover the full scope of the case

Concrete rule
A investigation case ends only when the documenting professional proves the actual outcome and the prescribing professional confirms the clarification in the appropriate procedure. The platform operations has no substitute authorization for this.

Derive storage needs from access patterns

Authoritative relational datastore
Contains exactly one currently valid prescription revision. A new revision requires verification of that revision. The draft therefore selects a relational metadata store with uniqueness constraints and short transactions. Historical versions remain referenceable; a rebuildable read model must not overwrite the authoritative state.
Large content and measurement series
Derived views and extensive measurement or event histories are read separately according to their access patterns. Binding state decisions remain in the authoritative datastore.

The actual action retains its own evidence

The actual action retains its own evidence

The actual action retains its own evidence.

Change and dispensing both expect version 7. If the change wins, dispensing loses the old approval. If dispensing wins, the change is rejected and, after a fresh read, handled as an investigation case; dispensing that already occurred remains recorded.

In dokumentiert and storniert, new dispensing creates a conflict. Cancellation does not retroactively undo an action already documented. The exercise specifies the input and expected result.

Alternative considered
Separate unversioned changes allow an older state to overwrite the newer one.
Trade-off
Changes to medication order M-26 are briefly serialized.
Reassess
Measurable waiting times for two specialists to process the same order in a revision justify a check of the transaction duration.

Try it yourself

Explain the two possible winner orders in the case contract. Also determine the behaviour after terminal completion.

A hint for your attempt

Content revision and aggregate version have different tasks.

Compare with a possible solution
Concurrency
Change and dispensing both expect version 7. If the change wins, dispensing loses the old approval. If dispensing wins, the change is rejected and, after a fresh read, handled as an investigation case; dispensing that already occurred remains recorded.
Completion
In dokumentiert and storniert, new dispensing creates a conflict. Cancellation does not retroactively undo an action already documented.

Apply to your project

Which states must remain protected in your model against late replay?

Next, reconciliation works outside of the local verification transaction.