Skip to content

Implementation plan / Session plan / Handover RC-2-S05

Handover RC-2-S05 Build: Scheduling and flow (part 1 of 2)

Card: RC-2-S05. Issue: cema-care/his#50. Branch: session/RC-2-S05. Slice: RC-2. Decision record: ADR-HIS-077.

What was built and where

The unit services/adm-scheduling-flow: - made from the service template: services/_template/new-unit.sh adm-scheduling-flow MOD-ADM-007 MOD-ADM-008, database adm_scheduling_flow; - its service-kit/ replaced by that of services/adm-patient-administration (ADR-HIS-077 point 1). That kit has the audit payload of the ESS intake schema, the policy request of policy-decision.v1, kit.client.Downstream and ServiceTokens, and the constraints on snappy-java and lz4-java that clear the dependency scan; - mod-adm-008 is the empty module of the template, for RC-2-S06; - the unit's README.md lists the packages and the settings (his.scheduling.*).

MOD-ADM-007 in mod-adm-007 serves all 33 operations of scheduling.v1 (IF-ADM-006). It publishes AppointmentBooked, AppointmentChanged, AppointmentArrived and ResourceReleased (EVT-ADM-019, 020, 021, 018) on his.adm.appointment.v1, aggregate Appointment. It publishes WaitlistEntryChanged (EVT-ADM-022) on his.adm.waitlistentry.v1, aggregate WaitlistEntry. Both go through the outbox, sequenced per aggregate. - Templates and calendars (FR-ADM-SCH-001): - versioned and effective-dated: a draft, approval, and effective or superseded derived from the effective dates (ADR-HIS-077 point 2); - approval refused for an inactive service or resource ("Resource is not active."); - a pattern overlapping another of the same resource refused ("Availability overlaps an existing pattern."), within one calendar or across calendars of the resource; - dated exceptions, with the booked appointments they overlap listed on the affected-appointment worklist and none cancelled; - a resource made inactive in the registry (MasterDataChanged, his.ess.masterdata.v1) leaves availability, and its appointments are listed; - a version that becomes effective lists the appointments it affects. Appointments keep their version; - a person approves, never a service identity; - audited as adm.config.change with before and after values, approver and effective date. - Slots and matching (FR-ADM-SCH-001 part 6.6, FR-ADM-SCH-003): - slots derived on each search from template and calendars in the calendar's time zone; - a time is offered only when every required resource, named or by type, is free for preparation, duration and turnaround; - patientConflict without the other appointment's content; - unmet preparation steps; - unmetDependencies naming the constraint (ADR-HIS-077 points 3 and 5); - the slot token S-<template>-<start> of the contract, with the chosen resources as a suffix. - Appointments (FR-ADM-SCH-002, FR-ADM-SCH-003 parts 6.4, 6.6): - booking reserves every resource atomically under transaction locks, or none (point 4); - the template's rules: channel, lead time, referral valid on the appointment date, patient overlap warn or block, preparation warn or block; - an active or provisional identity only, and a merged one booked against its survivor (patient-identity.v1 readPerson); - overbooking only where allowed, by a permitted caller with a reason, never for an exclusive resource; - one appointment per Idempotency-Key; - reschedule keeps the identifier and the history of both slots; - cancellation records canceller, reason and time; - check-in creates the encounter (encounters.v1 createEncounter with appointmentId and source appointment, or readEncounter to link one), with a key derived from the check-in's own. It answers 503 and stays Booked when the encounter cannot be made; - the no-show rule 30 minutes after the start (CFG-ADM-016), and the clerk's earlier no-show with a reason; - In progress and Completed; - each audited as adm.schedule.change. - Read audit (D01-ADM 9.5; review round 2; ADR-HIS-077 point 12). Every read that discloses a patient's scheduling record is audited as adm.person.view: - a record read: an appointment, its reminders, a waitlist entry; - a list or search: one record per patient in the answer, with the criteria, and one record without a patient when the answer is empty. This covers appointments with or without a patient filter, Domain 7 requests, waitlist entries, waitlist proposals, the affected-appointments worklist, and a slot search for a patient (which discloses that patient's conflicts); - a list names its resource type in queryCriteria, because the intake's resourceRef needs an id. - Reminders (part 6.5, AC-04; point 6): - planned at 72 and 24 hours before (CFG-ADM-017); - requested from notification.v1 when due, with Idempotency-Key the reminder's identifier and content appointmentStart and facilityName only; - pending while the service is unavailable, and sent again; - the delivery status and channel from NotificationStatusChanged (his.ess.notification.v1). - Domain 7 requests (part 6.8): carried out at once unless the template requires staff confirmation (or routes a missing referral to a pending request). From the worklist the scheduler books, offers other times, or declines with a reason. - Waiting list (FR-ADM-SCH-004; point 8): - ordered by the configured CFG-ADM-018 policy (urgency order, then date placed), with the basis of the order and flags; - every priority change and override recorded with actor, time, before, after, positions and reason; - an override needs the decision point's override permit, so a 403 is audited by the kit's enforcement point; - offers hold the slot, are declined (place kept) or expire after 24 hours; - clinic-review after the second decline; - proposals of released capacity to the highest-priority eligible entries; - closure with a reason; - duplicates refused, or merged with duplicate-entry: merge. - Ports for MOD-ADM-008 in mod007.api: QueueArrivals (the queue item of a check-in, which RC-2-S06 implements) and AppointmentProgress (In progress and Completed from a queue item, which RC-2-S06 calls). - Migration V1__scheduling.sql, schema mod_adm_007.

Outside the unit: - docs/architecture/decisions/ADR-HIS-077.md and its row in the index (76 records). ADR-HIS-073, 075 and 076 are taken by the open pull requests of RC-2-S02, RC-2-S04 and RC-1-S26. - contracts/adm/api/scheduling.v1.openapi.yaml, now version 1.1 (one example, and the optional completedAt of the answer to Q-S05-3), and the regenerated contracts/adm/stubs/stub.json; see "Contract changes".

Checks and their result

The integration environment ran as HIS_SESSION=RC-2-S05 (his-rc-2-s05), light profile.

Check Command Result
Build and every test of the unit (rerun after review round 2) ./gradlew build in services/adm-scheduling-flow passed: 96 tests (MOD-ADM-007 65, of which 34 are the contract test's; kit 27; app 3 with the module boundary test; MOD-ADM-008 1)
Provider contract test ./gradlew :mod-adm-007:test --tests '*SchedulingContractTest' passed: all 33 operations of scheduling.v1 pass his-contract verify contracts/adm, 156 cases (documented request, no credential, broken body, no X-Facility, a facility not permitted, a record of another facility hidden); the 21 events published pass his-contract validate-event
Contract check after the contract changes pnpm stub, pnpm build, pnpm test in contracts/adm (in the node:22.18-bookworm image) lint passed; check . --base origin/main passed (scheduling v1: 1.0 -> 1.1)
Dependency scan and SBOM platform/delivery-pipeline/bin/dependency-scan services/adm-scheduling-flow 0 blocking (5 medium), after ./gradlew dependencies --write-locks with the kit's constraints
Image scan platform/delivery-pipeline/bin/image-scan services/adm-scheduling-flow 0 blocking (15 low, 117 medium)
Static analysis platform/delivery-pipeline/bin/static-analysis services/adm-scheduling-flow no blocking finding
Secret scan secret-scan code origin/main HEAD and docs no secret; no exception file added
Documentation check_links.py; mkdocs build 0 broken links, 0 duplicate anchors; site builds

Requirements and test scenarios

Every test carries @Tag with its requirement and scenario, and its display name starts with them. They are in services/adm-scheduling-flow/mod-adm-007/src/test/java/care/cema/his/adm/mod007/.

Requirement, criterion Test
FR-ADM-SCH-001 AC-01 slots derived for a clinic, a diagnostic and a procedure template TemplatesAndCalendarsTest.slotsForEachKind
FR-ADM-SCH-001 AC-02 leave over booked appointments: listed, none cancelled; PR-SCH-001-1 TemplatesAndCalendarsTest.leaveExceptionListsAppointments
FR-ADM-SCH-001 AC-03 future-dated version: new slots from the date, existing unchanged; PR-SCH-001-2, part 11 TemplatesAndCalendarsTest.futureVersion
FR-ADM-SCH-001 part 10 (inactive resource, overlap), part 6.5 (resource made inactive), parts 3, 12 TemplatesAndCalendarsTest.validation, resourceInactive, auditedAndGoverned
FR-ADM-SCH-002 AC-01 book, reschedule, remind, check in, complete for each of the three templates AppointmentLifecycleTest.fullLifecycleForEachKind
FR-ADM-SCH-002 AC-02 reschedule frees the slot, history shows both AppointmentLifecycleTest.rescheduleKeepsHistory
FR-ADM-SCH-002 AC-03 cancellation stores reason and canceller, releases AppointmentLifecycleTest.cancellation
FR-ADM-SCH-002 AC-04 reminder requested when due, delivery status recorded; part 10 pending AppointmentLifecycleTest.reminders
FR-ADM-SCH-002 AC-05 same idempotency key: one appointment; PR-SCH-002-2 AppointmentLifecycleTest.idempotentBooking
FR-ADM-SCH-002 parts 6.2, 6.6, 6.7, 6.8, 7; BR-ADM-025; PR-SCH-002-4 noShow, checkIn, domain7Requests, templateRules, patientIdentity
FR-ADM-SCH-003 AC-01 only times when practitioner, room and equipment are all free; PR-SCH-003-1 MultiResourceTest.onlyWhenAllThreeFree
FR-ADM-SCH-003 AC-02 conflicting room: rejected, nothing else held; PR-SCH-003-2, -3 MultiResourceTest.conflictRejectedNothingHeld
FR-ADM-SCH-003 AC-03 no slot: the unmet dependency identified MultiResourceTest.unmetDependency
FR-ADM-SCH-003 AC-04 patient overlap exposed; PR-SCH-002-1 MultiResourceTest.patientOverlap
FR-ADM-SCH-003 parts 6.3, 6.6, 12 MultiResourceTest.overbooking, preparation
FR-ADM-SCH-004 AC-01 order follows the policy WaitlistTest.policyOrder
FR-ADM-SCH-004 AC-02 urgency change in the history: who, when, from, to, why; PR-SCH-004-1, BR-ADM-019 WaitlistTest.urgencyChangeTraceable
FR-ADM-SCH-004 AC-03 override without authority rejected and audited; PR-SCH-004-2 WaitlistTest.overrideNeedsAuthority
FR-ADM-SCH-004 AC-04 released capacity proposed to the highest-priority eligible entry; PR-SCH-002-3 WaitlistTest.proposalOnRelease
FR-ADM-SCH-004 AC-05 decline keeps the place; expiry returns to Active and proposes to the next; PR-SCH-004-4, -5 WaitlistTest.declineAndExpiry
FR-ADM-SCH-004 parts 6.4, 6.6, CFG-ADM-018 review WaitlistTest.flagsAndClosure
IF-ADM-006, EVT-ADM-018 to 022 contract/SchedulingContractTest
D01-ADM 9.5 read audit (adm.person.view) AppointmentLifecycleTest.readsAudited (appointment lists, reminders, slot search for a patient, Domain 7 requests), WaitlistTest.readsAudited (entries, proposals), TemplatesAndCalendarsTest.leaveExceptionListsAppointments (affected appointments), AppointmentLifecycleTest.patientIdentity

Scenarios: TEST-ADM-020 is TemplatesAndCalendarsTest, TEST-ADM-021 AppointmentLifecycleTest, TEST-ADM-022 MultiResourceTest, TEST-ADM-023 WaitlistTest. All pass.

Non-functional targets designed for: - NFR-ADM-005: the decision point on every action, audit, facility scope, and no patient data in URLs (search is a POST); - NFR-ADM-009: the contract and its events, checked by the contract test; - NFR-ADM-012: the kit's telemetry and correlation identifier, carried to the calls of other services; - NFR-ADM-013: times in UTC, slots in the calendar's zone, the facility's name in reminders; - NFR-ADM-014: instants to the millisecond, with the business time in each event.

Contract changes

  • scheduling.v1 readAppointmentTemplate: the example of the version query parameter is now 1, not 2.
  • Why: his-contract verify sends the example query against the template its setup createAppointmentTemplate has just made, which has only version 1. With 2, the documented request could only answer 404.
  • Only an example changed. his-contract check . --base origin/main passes, and the stub was regenerated (stubs/stub.json). This is the compatible change session rule 4 allows. The contract's owners may prefer a x-his-test way to name a version that the setup made.
  • scheduling.v1 1.1: AppointmentRequest has an optional completedAt.
  • Why: the answer to Q-S05-3 on #50. The portal must be able to tell that a reschedule or cancellation request was carried out.
  • The answer first chosen was a new AppointmentRequestState value (completed). The compatibility check refuses that, because the enum is closed in three responses (listAppointmentRequests, submitAppointmentRequest, decideAppointmentRequest). The person then chose the optional field instead.
  • The unit sets completedAt whenever it carries out what a request asks: a booking, reschedule or cancellation done at once, or a scheduler's book decision. A carried-out request keeps state booked.
  • An optional field added to a response is compatible. info.version went from 1.0 to 1.1, his-contract check . --base origin/main passes, and the stub was regenerated.

Done differently from the specification or contract, and why

  • Check-in creates no queue item yet (FR-ADM-SCH-002 part 6.6, BR-ADM-025). The queue is MOD-ADM-008, which RC-2-S06 builds after this card. Check-in calls the port mod007.api.QueueArrivals. While no bean implements it, the queue item is absent and queueItemId is left out (ADR-HIS-077 point 9).
  • Pre-scheduling eligibility (part 6.9; Q-S05-1, answer C): the check is left to registration and check-in (FR-ADM-REF-001) until slice BC-1. On a template that asks for the check, the appointment records eligibility.verificationStatus: not-verified, and no call is made.
  • A Domain 7 reschedule or cancellation carried out at once (part 6.8; Q-S05-3) is answered state booked with completedAt (scheduling 1.1).
  • A staff booking with a missing or expired referral is refused (part 10; Q-S05-2, answer A) with "A valid referral is required.", also where the template's referralMissing is pending-request. The scheduler submits a request instead, which then waits on the worklist.
  • CFG-ADM-018 "after the second decline the entry goes to the clinic for review" is the flag clinic-review (an extensible value of WaitlistFlag) on an entry that stays Active. A clinical-urgency code that the configured policy does not order is refused rather than ranked. The contract test configures very-urgent,urgent,soon,routine, because the contract's example uses very-urgent; the default is the section 13 order urgent,soon,routine.
  • A reason is required for every priority change, not only an override (BR-ADM-019: "no change without a record").
  • Admission status in the patient-availability check (FR-ADM-SCH-003 part 6.2, "where known") is not checked: no RC-2 contract gives it to this unit.
  • HL7 v2 SIU and the FHIR Appointment (FR-ADM-SCH-002 part 9, "where a partner requires it") are not produced here. They are the integration engine's mapping of the events.
  • Facility of a slot's reminder content: the D10 facility register's name (readFacility), and the facility code when the registry cannot answer.

Questions for a person

Review round 1 held that three readings settle financial, access and patient-facing behaviour, which session rule 3 leaves to a person. They were put on #50 as Q-S05-1 to Q-S05-3, and a person has answered them:

# Question Answer In the code
Q-S05-1 (financial, FR-ADM-SCH-002 part 6.9) How does booking ask Domain 5 for the pre-scheduling eligibility check, when scheduling.v1 carries no payer data? C. The check is left to registration and check-in (FR-ADM-REF-001) until slice BC-1. The appointment records not-verified. eligibility.verificationStatus: not-verified, no call (Appointments.java)
Q-S05-2 (access, FR-ADM-SCH-002 part 10) What happens to a staff booking with a missing or expired referral, where referralMissing is pending-request? A. The booking is refused, and the scheduler submits a request instead. Refused with "A valid referral is required." (Appointments.java)
Q-S05-3 (patient-facing, FR-ADM-SCH-002 part 6.8) Which state does the portal see for a reschedule or cancellation request carried out at once? An optional completedAt in scheduling 1.1, with state booked. The first choice, a new state completed (A), fails the compatibility check (see "Contract changes"). completedAt on every carried-out request (Requests.java); AppointmentLifecycleTest.domain7Requests

No question is left open.

The other readings under "Done differently" are technical or follow from the specification's text, and are recorded in ADR-HIS-077. The Board's approval of that record is under "Needs a person" in the pull request.

Follow-ups outside the card

  • RC-2-S06 (MOD-ADM-008): implement mod007.api.QueueArrivals (recordArrival with arrival type scheduled, key given). Call mod007.api.AppointmentProgress when an item linked to an appointment starts or completes (flow.v1 contract point 8). The module boundary test admits both, as api packages.
  • Service template (a session whose card covers services/_template): take the kit fixes of RC-1-S09 into the template's kit: the snappy-java and lz4-java constraints (the template's kit fails the dependency scan), the ESS intake audit payload, the policy request of policy-decision.v1, and kit.client.
  • D10 registrations before the unit goes live:
  • the policy actions of ADR-HIS-077 point 7 on adm.AppointmentTemplate, adm.ResourceCalendar, adm.Appointment, adm.AppointmentRequest and adm.WaitlistEntry (RC-1-S16);
  • the audit types adm.schedule.change and adm.config.change (RC-1-S04);
  • the notification type adm.appointment-reminder with parameters appointmentStart and facilityName (the seed in services/ess-coordination already has this form, as RC-2-S03 asked);
  • the code lists appointment-cancellation-reason, appointment-change-reason and clinical-urgency, and a decline-reason list for Domain 7 requests;
  • the CFG-ADM-018 waitlist policy per service.
  • ADM contract session (next minor version of scheduling.v1):
  • payer fields for the pre-scheduling eligibility check, for slice BC-1 (Q-S05-1);
  • perhaps clinic-review as a named WaitlistFlag;
  • the version example, if the owners prefer another way.
  • RC-2-S10 (integrate): add adm-scheduling-flow to e2e/scenarios/RC-2/stack.json. Set his.scheduling.master-data-url, patient-identity-url, encounters-url and notification-url, and his.clients.*.
  • Waitlist definitions: a waitlist is named by its waitlistId alone. No configuration item yet says which waitlists exist for a service; any identifier is accepted.
  • Design system: none from this session.