Architecture / Decision records / ADR-HIS-077
ADR-HIS-077 Appointment scheduling: derived slots, locked reservations, derived version states, and the ports check-in and the waiting list need¶
| Status | Accepted |
| Decided | 2026-11-26 by session RC-2-S05 |
| 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-007, its migration mod-adm-007/src/main/resources/db/mod_adm_007/, the contract test in mod-adm-007/src/test/java/care/cema/his/adm/mod007/contract/; the ports for MOD-ADM-008 in mod-adm-007/src/main/java/care/cema/his/adm/mod007/api/) |
Context¶
Session RC-2-S05 makes the unit services/adm-scheduling-flow and builds MOD-ADM-007 in it. That is templates and resource calendars, slots across several resources, the appointment lifecycle with reminders, and prioritized waiting lists (FR-ADM-SCH-001 to FR-ADM-SCH-004). It serves scheduling.v1 (IF-ADM-006) of ADR-HIS-067. RC-2-S06 builds MOD-ADM-008 (queues, flow boards) in the same unit after it. Domains 4 and 7 will read its slots. The specification and the contract leave these points to the design:
- how slots are derived and identified, since the contract says they are not stored;
- how "all reservations or none" is made safe against a concurrent booking;
- how the version states of part 11 follow from effective dates;
- what reminders send and how their status comes back;
- how the waiting-list policy is applied;
- what check-in does while MOD-ADM-008 is not built.
Decision¶
- The unit's kit is the one RC-1-S09 brought up to date. The unit is made with
services/_template/new-unit.sh adm-scheduling-flow MOD-ADM-007 MOD-ADM-008. Itsservice-kit/is then replaced by that ofservices/adm-patient-administration, which already has: - the audit payload of the ESS intake schema;
- the policy request of
policy-decision.v1; - the client helpers
kit.client.DownstreamandServiceTokens; - the dependency constraints that keep the compression libraries of kafka-clients free of known vulnerabilities.
The template's own kit is unchanged, which is a follow-up for a session whose card covers the template. MOD-ADM-008 is an empty module until RC-2-S06.
2. Version states are derived, not stored. A template or calendar version is stored as draft, approved or retired. On a given day:
- the effective version is the highest approved one whose period contains that day;
- an approved version whose date has not come is approved;
- an earlier approved one is superseded.
So a version with a future date takes over on its date with no job (AC-03). An appointment keeps the version it was booked under (PR-SCH-001-2). A sweep of the unit's rules lists the affected appointments once a version is effective (part 6.4), once per version.
3. Slots are derived on every search and identified by a token.
- Slot starts follow the template's duration from the start of each availability window of the operating calendar, or else of the first required resource, in the calendar's time zone.
- The block a slot holds is preparation, duration and turnaround. Every required resource, named or chosen by type, must be available for the whole block and have capacity left (PR-SCH-003-1).
- Availability is the patterns of the calendar version effective on the day, less leave, maintenance, closure and ad hoc unavailable exceptions, plus ad hoc available ones. A resource made inactive in the registry has none.
- The slot identifier is S-<first 8 characters of the template>-<start, UTC, yyyyMMdd'T'HHmm'Z'>, as in the contract's examples. For a requirement by type, a suffix (. and base64url of the resource identifiers) carries the resources the search chose, so that booking reserves what the scheduler saw. A token without the suffix books the first free resource.
4. Reservations are rows held under transaction locks.
- A booking, reschedule or waitlist offer takes a PostgreSQL advisory transaction lock on every resource the template can use, in sorted order.
- It then reads the reservations again, evaluates the slot again and writes one reservation row per resource over the block, in the same transaction.
- So either all are held or none (PR-SCH-003-2), and two concurrent bookings of the last place cannot both succeed.
- A resource is counted by its registry identifier across facilities, since a practitioner works in several.
- Capacity is the template's patients per slot.
- Overbooking past it is accepted only where the template allows it, from a caller the decision point permits overbook, with a reason, and never for an exclusive resource (PR-SCH-003-3).
- A refused booking answers "Slot is no longer available." (or "Room is no longer available for this time." for a full exclusive resource), with up to three alternatives in the problem's errors.
5. The unmet dependency is the resource that is never available on its own. When a search finds no slot (part 6.5, AC-03), it reports each required resource that is never available alone in the period. When each is available alone but never together, it reports the one available at the fewest times. A template with no effective version, a lead time that leaves no time, or a closed operating calendar is a template-rule dependency. Patient availability is checked against the patient's appointments in every facility, and answered only as patientConflict (part 13).
6. Reminders: planned at booking, requested when due, status from the notification service.
- Booking plans one reminder for each point of CFG-ADM-017 (72 and 24 hours before), and none for an appointment booked less than 24 hours ahead.
- When a reminder is due, the unit sends requestNotification (notification.v1):
- type adm.appointment-reminder, priority normal;
- recipient the patient, subject adm.Appointment;
- Idempotency-Key the reminder's identifier;
- content parameters only appointmentStart and facilityName (the facility register's name). These are the facility, date and time of Q-RC2-6, never the service (part 13).
- While the service cannot take the request the reminder is pending and is sent again after his.scheduling.reminder-retry (part 10).
- Its delivery status and channel come from NotificationStatusChanged (his.ess.notification.v1) (AC-04).
- Cancellation, reschedule, no-show and check-in withdraw the reminders not yet sent.
7. Policy actions. On each resource type the unit asks the decision point for the action, with the patient for appointment, request and waitlist records:
- adm.AppointmentTemplate and adm.ResourceCalendar: create, update, view, query, approve, retire; add-exception on a calendar;
- adm.Appointment: book, search-slots, view, query, reschedule, cancel, check-in, no-show, progress, overbook;
- adm.AppointmentRequest: submit, query, decide;
- adm.WaitlistEntry: create, view, query, update, change-urgency, override, offer, respond, close.
Roles stay with the decision point: the responsible clinician (change-urgency), the registration supervisor (override, overbook), and the clerk's own clinic (add-exception). Approval of a version is refused to a service identity.
8. The waiting list applies CFG-ADM-018 as configured.
- The order is the configured urgency codes in priority order, then the date placed.
- A code the policy does not order is refused, rather than ranked by guess.
- An authorized override puts the entry at the position set. A reason is required for every priority change (BR-ADM-019).
- An offer holds its slot with a reservation of the offer. It expires after the response time by the unit's rules.
- A declined offer keeps the entry's place unless his.scheduling.decline-keeps-place is false.
- After the configured number of declines the entry is flagged clinic-review ("goes to the clinic for review").
- Proposals (part 6.5) are computed on read from the capacity released by cancellation, reschedule, no-show, or a declined or expired offer. They list the active entries of the slot's service in policy order whose availability admits the slot's time and which have not refused that slot.
- A duplicate entry is refused, or merged into the open one with duplicate-entry: merge (PR-SCH-004-3).
9. Check-in opens the encounter through encounters.v1, and the queue item through a port that MOD-ADM-008 implements.
- Check-in calls createEncounter (with appointmentId and source appointment), or readEncounter for an encounter to link, within the check-in's transaction. Its Idempotency-Key is derived from the check-in's own. When the encounter cannot be created the answer is 503 and the appointment stays Booked.
- The queue item comes from mod007.api.QueueArrivals, which MOD-ADM-008 implements in RC-2-S06. Until then there is no such bean, and check-in creates no queue item (queueItemId absent).
- mod007.api.AppointmentProgress is the way MOD-ADM-008 sets In progress and Completed from its queue item.
10. What the contract does not carry follows the answers to Q-S05-1 to Q-S05-3 on issue #50.
- Eligibility (Q-S05-1): the pre-scheduling eligibility check of part 6.9 is left to registration and check-in until slice BC-1. An appointment whose template asks for the check records eligibility.verificationStatus: not-verified. scheduling.v1 carries no payer data to send to requestEligibility.
- Carried-out requests (Q-S05-3): a Domain 7 request that the unit carries out, at once or on a scheduler's book decision, is answered with state booked and completedAt (scheduling 1.1). A new state value would be a breaking change, because AppointmentRequestState is closed in responses.
- Missing referral (Q-S05-2): a staff booking with a missing referral is refused, even where the template routes Domain 7 requests to a pending request. The scheduler submits a request instead.
11. The unit's time-driven rules run in one place. Rules.tick runs every his.scheduling.scheduler-interval (tests call it). It does four things: lists the appointments of versions now effective, requests due reminders, applies the no-show rule (CFG-ADM-016), and expires offers (CFG-ADM-018). The no-show and the expiry act as the unit's service identity (section 4.3, actor System).
- Every read that discloses a patient's scheduling record is audited as
adm.person.view(D01-ADM 9.5).- A record read names the record and its patient.
- A list or search writes one record per distinct patient in the page it answers, with the criteria and the decision. An empty answer writes one record without a patient.
- So an auditor can find every disclosure of one patient's appointments, requests, waitlist entries and conflicts, whatever filter the caller used.
- A list names its resource type in
queryCriteria, because the intake'sresourceRefneeds an id. - The policy decision of a command is returned with the record it permits, never kept in thread state.
Consequences¶
- RC-2-S06 implements
QueueArrivalsand callsAppointmentProgressin MOD-ADM-008; check-in then fillsqueueItemIdwith no change to MOD-ADM-007. - D10 registers the policy actions of point 7, the notification type
adm.appointment-reminderwith a patient template of facility, date and time (parametersappointmentStart,facilityName), and the waitlist policy of CFG-ADM-018 per service. - A next minor version of
scheduling.v1can add payer data for the eligibility check (slice BC-1), with no change to the stored records. Portal screens readcompletedAtto show a carried-out reschedule or cancellation as done. - Slots stay cheap to change: a template or calendar change applies to the next search, and nothing stored needs rebuilding.