-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
User Story
As a practitioner, I want the system to trigger a background worker to generate or update Slot resources every time my PractitionerRole resource is created or updated so that the system availability accurately and automatically reflects my current schedule.
Description
Currently, changes to a practitioner's availability stored in the PractitionerRole are not automatically reflected as Slot resources. This requires waiting for the daily cron job to execute or when unavailable time trigger is set. We need a reliable mechanism where any creation or update to PractitionerRole with active status emits an event that causes the worker to generate the appropriate Slot resources for that practitioner role.
Key requirements:
- Changes to
PractitionerRole(create, update, patch, delete, activation toggles) must cause slot generation. - Generated
Slotresources must be idempotent, consistent, and auditable. - Existing appointment bookings must be respected (do not delete
Slotwhichstatusisbusyorbusy-tentative).
Proposed Flow
- Emit a domain event when
PractitionerRoleis created, updated, or deleted. The event payload should includepractitionerRoleId,practitionerId, timestamp, and a diff/summary of changed availability-related fields (if available). - Worker consumes the event and performs the following steps atomically where possible:
- Load the authoritative
PractitionerRoleand relatedPractitionerandLocationresources. - Compute desired Slot set for a configurable window (e.g., next 90 days) using availability rules.
- Compare computed slots against persisted
Slotresources:- Upsert new
Slots where missing. - Update changed
Slotmetadata (status, start/end) where safe. - Delete obsolete
Slotonly if the status isfree. - Never delete or override
Slots that are linked to confirmed appointments.
- Upsert new
- Persist changes using bulk/batched FHIR operations where available (e.g., transaction bundles).
- Emit a completion event with counts (created/updated/retired/retained/conflicts) and diagnostics.
- Load the authoritative
- Add monitoring and alerts: Log detailed audit trails that capture inputs, computed slot list, and decisions for conflict cases.
- Document the behavior and provide guidance for practitioners/admins on how changes in
PractitionerRoletranslate into slots and how to request manual regeneration.
Notes:
- Idempotency: ensure each run can be safely re-applied (e.g., include a
generationRunId/sourceEventIdin Slot metadata) to prevent duplicate slots. - Concurrency & Ordering: handle concurrent updates to the same
PractitionerRole(use event ordering, versioning, or optimistic locking). - Timezone and DST: compute slots in the practitioner's primary timezone and store slot timestamps in UTC with timezone metadata.
- Appointments: treat
Slots with linked confirmedAppointments as immutable; do not remove or convert them without special reconciliation. - Performance: use batched FHIR transactions for writes and paginate comparisons to avoid memory pressure.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
No status