Skip to content

Architecture / Decision records / ADR-HIS-081

ADR-HIS-081 Queues and flow boards: rule order as a sort key, a projection folded from retained events, freshness from what holds the feed back, and wall displays named by the board definition

Status Accepted
Decided 2026-11-26 by session RC-2-S06
Record Drafted 2026-11-26; approved 2026-11-30 by the Enterprise Architecture Board
Where the rule lives services/adm-scheduling-flow/ (its README.md; module mod-adm-008, its migration mod-adm-008/src/main/resources/db/mod_adm_008/, the freshness watermarks in mod-adm-008/src/main/java/care/cema/his/adm/mod008/board/Freshness.java, the contract test in mod-adm-008/src/test/java/care/cema/his/adm/mod008/contract/)

Context

Session RC-2-S06 builds MOD-ADM-008 in the unit services/adm-scheduling-flow, next to MOD-ADM-007 (ADR-HIS-077). It covers arrivals and priority queues (FR-ADM-FLW-001) and real-time flow boards (FR-ADM-FLW-002), and serves flow.v1 (IF-ADM-007) of ADR-HIS-067. Two of these are safety-critical functions of D01-ADM 11.1: - triage routing and queue order (hazard: an urgent patient delayed by a wrong queue position); - flow boards (hazard: decisions made on stale data).

The specification and the contract leave these points to the design: - where the governed queue and board definitions come from; - how a rule order, an override and a past order are kept; - how the projection stays ordered and can be rebuilt; - how a board knows it is stale; - how a wall display is recognised; - what the board shows while Domains 3 and 4 have no contract.

Decision

  1. MOD-ADM-008 uses MOD-ADM-007 only through mod007.api.
  2. It implements QueueArrivals, so a check-in creates the queue item in the check-in's transaction.
  3. It calls AppointmentProgress when an item linked to an appointment starts or completes.
  4. Its build depends on :mod-adm-007, and ModuleBoundaryTest keeps the boundary.
  5. Its own support package (request reading, commands with Idempotency-Key, ETags, audit) is a copy of MOD-ADM-007's. Modules share only api packages.

  6. Queue and board definitions are D10 configuration items, read and never written.

  7. CFG-ADM-019 and CFG-ADM-020 are the item type adm.queue-definitions, and CFG-ADM-021 is adm.flow-boards. Each has key default and is resolved per facility through configuration.v1 resolveConfiguration (IF-ESS-012).
  8. The content is a list of flow.v1 Queue or FlowBoard objects. Two extensions are not in the contract:
    • ticketPrefix of a queue;
    • displays of a board: the wall-display devices registered to it, by D10 service identity name, each with its privacy setting (CFG-ADM-021).
  9. What was read is used for his.flow.configuration-cache (30 s).
  10. When the service cannot answer, the last definitions read for the facility are used (resolveConfiguration part 10). With none read yet, the answer is 503.
  11. Without a configuration URL, a JSON file (his.flow.configuration-file) stands in, for an environment before D10 holds the items.

  12. A queue is ordered only by attributes the unit can apply. These are triage-category, priority-flag, appointment-time and arrival-time.

  13. urgency is a value of PriorityAttribute, but D01-ADM does not say what it orders by. No default rule of CFG-ADM-019 uses it.
  14. Ordering by a guessed meaning would decide clinical behaviour (session rule 3). So a definition that names it, or any other unknown attribute, is not served and is logged.
  15. The question is on issue #51.

  16. The rule order is a sort key per item, and the position is derived on every read.

  17. The key has one component per rule attribute, in order of precedence:

    • the triage level's place in the scale his.flow.triage-order (CFG-ADM-028: 1 to 5, most urgent first);
    • any priority flag before none;
    • the appointment time for a patient who arrived within the window around the slot, otherwise the arrival time (CFG-ADM-019 clinic queue);
    • the arrival time.

    Then come the arrival time and the queue number's sequence. So equal items are served first come, first served, and no two items tie. - A change of a priority attribute recomputes the key (PR-FLW-001-1). - A supervised override gives the item the key of the item it goes before and an override_rank one lower, so it sorts just ahead of it. This holds also when that item was itself moved. - A later change of a priority attribute puts the item back under the rule. The override stays in the history. - Every change writes a history row with the item's state, key and document after it. listQueueItems?asAt takes the last row of each item at that time, so the order at any past time can be rebuilt (AC-04). - The database sorts keys byte-wise (collate "C"), as Java does.

  18. Arrival and placement are two steps, as section 4.3 has them.

  19. The arrival is recorded in Arrived (actor: the clerk). The system then places the item in the same transaction:
    • on a triage queue without a triage category, in Triage with awaitingTriage;
    • otherwise in Waiting.
  20. Each step publishes QueueStateChanged.
  21. The queue number is <prefix>-<nnn>, counted per queue and service day in the facility time zone (his.flow.time-zone).
  22. A triage category assigned to an item in Triage places it in Waiting.

  23. older-adult is derived at arrival and is never set by hand (Q-RC2-2).

  24. The flag needs an age of 60 or more on the service day. The age is counted from the latest date a partial date of birth allows, so the flag is given only when the age is certain.
  25. When the person index cannot answer, the arrival still goes ahead without the flag. The unit's rules derive it once the index answers, as a priority change of the unit.
  26. A request that sets it is refused. A change of the other flags keeps it.

  27. Calls, moves and the one active item.

  28. Out-of-order calls (BR-ADM-018, Q-RC2-3). Calling any item but the head needs a reason, which is shown and audited.
    • Passing over a waiting item of a higher triage category also needs the decision point's override permit, and a person.
    • Without that permit the answer is 403 "Supervisor authority required.", and the enforcement point audits it.
    • No position moves.
  29. Duplicate arrival (PR-FLW-001-2). A second open item of the encounter at the same service point is refused, naming the existing item.
  30. One active item (part 6.6). An open item elsewhere refuses the arrival, unless the new queue or the other queue allows parallel queues.
  31. Moving on. linkedFrom names an item in service, which the move completes.
  32. Check-in. It links an item of the encounter that is in service in the same way.

  33. Policy actions. On adm.QueueItem:

  34. view-queues, create, query, view, view-call-display;
  35. every action name of actOnQueueItem;
  36. triage, change-priority and override.

On adm.FlowBoard: view-boards, view and view-flow-state. view-flow-state carries the patient, the encounter and resourceFacility, so the decision point decides a read across facilities (Q-RC2-1).

The roles stay with the decision point: the triage nurse (triage) and the supervisor (override).

  1. The Domain 3 and Domain 4 feeds of D01-ADM 8.5 have no contract yet.
  2. contracts/cli and contracts/anc hold no events, so the unit subscribes to none.
  3. A board's diagnostics column is answered not-current, and the board continues on Domain 1 states (PR-FLW-002-3).
  4. The diagnostics state and sub-status come once those contracts exist.

  5. The flow state is derived from Domain 1 inputs.

    • A cancelled or closed encounter leaves the projection.
    • A discharged one is in discharge and stays on the board for its service day.
    • Otherwise the open queue item changed last decides:
    • without a triage category, awaiting-triage;
    • in Triage with one, triage;
    • Arrived, Waiting, Called and Not present are waiting;
    • In service is consultation (D01-ADM 8.5: the consultation start is the queue state In service).
    • When every item is closed and one is completed, the state is pending-discharge until the encounter ends.
    • Without a queue item, the appointment decides (arrived, in progress, completed), or the encounter (admission, or waiting).
    • The location is that of the decisive item. A board shows the encounters located in its units.
  6. A board's age is how far the projection is behind its feeds, measured by a watermark on each feed.

    • The unit's own feeds (his.adm.encounterflow.v1, his.adm.appointment.v1, both written by this unit). The watermark is the oldest event in the outbox that the projection's subscription has not applied. It catches a stalled relay and a stalled consumer alike. A backlog younger than his.flow.relay-lag (10 s) is ordinary delivery and is not counted.
    • The encounter feed of adm-patient-administration. Every arrival proves an open encounter (encounters.v1), so its EncounterOpened must reach the projection. The watermark is the oldest queue item whose encounter has no encounter event after his.flow.encounter-lag (60 s). It catches a producer that stopped publishing as well as a stalled consumer, while a quiet unit with nothing missing stays current.
    • A sequence gap. An event held for a missing earlier one on any feeding subscription means the source is known to be delayed.
    • The board's answer:
    • the last-updated time is now less the largest of these ages;
    • the board is stale when that age passes its threshold (CFG-ADM-021, 5 minutes), and at once when a source is known to be delayed;
    • staleMinutes is never below 1 when stale.
    • No backlog ages out (fail closed; review round 2). Neither watermark has a time window. A change missing for days keeps the board stale until it is applied, however long the feed has been silent.
    • The encounter watermark looks only at the queue items that still matter to a board: those open, and those of an encounter still in the projection. A visit that is closed and has left the projection does not hold the boards stale.
    • The one bound is the kit's outbox retention: a published event is purged 7 days after publication. An event published but not applied by the projection for 7 days drops out of the own-feed watermark. By then the inbox hold timeout (15 minutes) has raised a reconciliation exception for a gap, and the rules have logged the age for operations every interval.
    • Database time. Ages are measured in database time, where the outbox and the queue items record when they were written (queue_item.created_at).
    • Operations. The unit's rules log the age and its cause while the projection is behind.
    • Not caught. A feed with no Domain 1 witness is not caught this way: an encounter change of an encounter with no queue item, or the Domain 3 and Domain 4 feeds. The latter are already answered not current (point 9). A heartbeat on each topic, published by its producer, would close that gap; no contract has one yet.
  7. The projection is folded from retained events.

    • Every event applied is kept in flow_input. The encounter's state is folded again from all its inputs, in business-time order:
    • within a topic, the kit's ordered inbox keeps the sequence;
    • across topics, the business time does.

    So an older event never overwrites a later state (PR-FLW-002-1). - FlowProjection.rebuild folds every encounter again (part 6.7). - The time from the source event's commit to the projection is the timer his.flow.projection.lag, with p95 published. It is measured at integration against NFR-003 (p95 under 5 s).

  8. A wall display is a service identity named in a board's displays.

    • In a facility, such a caller may read:
    • the boards configured for it, with its own privacy setting (initials and bed by default; the CIN and names are left out);
    • the board list, limited to those boards;
    • the public call display.
    • Anything else is refused with 403 and audited by the module: another board, patient detail, a queue list or any write (PR-IAM-003-4).
    • A board or call display view is logged once per caller, board and his.flow.view-log-period (1 hour), without a patient. That holds for staff and displays alike (part 12: per device and board, not per patient).
    • Reads that disclose patients are audited per patient as adm.person.view: queue items, a queue item, the flow state.
  9. The no-response rule runs in the unit (CFG-ADM-020, PR-FLW-001-3 and -4).

    • It runs every his.flow.scheduler-interval as the unit's service identity.
    • A called item whose interval has passed takes the queue's first action on the first missed call, and the other action after that.
    • At the configured number of calls the item is closed as Cancelled with the reason "not present". Staff marking a patient not present follow the same count.

Consequences

  • D10 registers the configuration item types adm.queue-definitions and adm.flow-boards, the policy actions of point 8, the display devices of each board (FR-ESS-IAM-003), and the audit type adm.queue.change.
  • RC-2-S10 sets his.flow.encounters-url, patient-identity-url and configuration-url (or configuration-file) for the unit.
  • When the D03 and D04 contracts publish order and diagnostic status events, the projection subscribes to them. The diagnostics state, its sub-status and the column's current follow with no change to the stored projection: the fold takes the new inputs.
  • A urgency attribute can be applied once its meaning is specified. Until then a queue that names it is not served.
  • A heartbeat event per topic, if a contract adds one, would let the encounter feed be watched without a queue item as witness (point 11).
  • Restricted-location labels, beds, row indicators and responsible teams have no RC-2 source. The board leaves them empty until ADT (RC-3) and the D10 location labels provide them.