L
Leaphealth - OSDocs

Emergency Leave

What happens when a doctor is suddenly unavailable and how the system handles affected appointments.

Emergency Leave

When a doctor needs to take sudden leave, the emergency leave system handles the entire cascade: blocking the doctor's availability, finding affected appointments, cancelling them, processing refunds, and notifying patients — all in a single operation.

Initiating Emergency Leave

To declare emergency leave, specify:

  • Doctor: which doctor is taking leave
  • Centre: which centre is affected
  • Block Period: start and end times (epoch seconds) defining the leave window
  • Reason: optional text explaining the leave

Validation Rules

The system validates the request before processing:

  • The block end time must be after the block start time
  • The block start time must be in the future (cannot retroactively declare leave)
  • The doctor and centre must exist and be valid

What Happens During Emergency Leave

The system performs these steps automatically:

  1. Create Availability Block: a BLOCK entry is added to the doctor's availability calendar for the specified time range, preventing new bookings
  2. Find Affected Appointments: the system identifies all appointments with that doctor at that centre during the block period that are in CONFIRMED, PENDING_APPROVAL, or CHECKED_IN status
  3. Cancel Appointments: each affected appointment is cancelled with the reason 'Doctor emergency leave' and the actor set to SYSTEM
  4. Process Refunds: for appointments with payments, a full refund (100% of the amount) is processed via the payment system
  5. Notify Patients: each affected patient receives a notification via WhatsApp and Email with appointment details, refund amount, and a reschedule link

Checked-In Appointments

Appointments that have already been checked in are also affected by emergency leave:

  • The appointment is cancelled even though the patient has arrived
  • If a visit record exists, it is also cancelled
  • A full refund is processed the same way as confirmed appointments
  • The patient is notified with a reschedule link

Emergency leave affects all qualifying appointments in the block window, including those where patients have already checked in. Ensure the block period is accurate.


Batch Tracking

Every emergency leave operation creates a batch record for tracking and auditing:

Field

Description

Batch UUID

Unique identifier for this emergency leave operation

Doctor

The doctor taking leave

Centre

The affected centre

Block Period

Start and end times of the leave

Total Affected

Number of appointments found in the block window

Total Cancelled

Number successfully cancelled

Total Refunded

Number with refunds processed

Total Notified

Number of patients notified

Total Refund Amount

Sum of all refunds (in paise)

Status

Overall batch status

Error Details

Details of any failures

Batch Status

The batch status reflects the outcome of the operation:

Status

Meaning

COMPLETED

All affected appointments were cancelled, refunded, and notified successfully

PARTIALLY_COMPLETED

Some appointments were processed but others failed

FAILED

No appointments could be cancelled (all failed)

If no appointments fall within the block period, the batch is marked as COMPLETED with zero affected.

Error Tracking

If any appointment fails to cancel or refund, the error is captured:

  • The specific appointment ID that failed
  • The error reason
  • The attempted refund amount

This allows administrators to manually handle any failed cancellations or refunds.


Viewing Emergency Leave History

Administrators can:

  • List all emergency leave batches with pagination
  • View details of a specific batch including all affected appointments
  • Track refund amounts and notification status per batch
emergencyleaveunavailablereschedulebatch-tracking

Last updated on

On this page