---
# System prepended metadata

title: Consultation Booking

---

# Consultation Booking

Clinics API


## TODO

  [Krzyś?]
  SlotCalendarRelated:
    -> Create new SlotCalendar
    -> Rename ServiceCenterRules na `CalendarRules`, rearrange as STI

  API-related
    -> Make Consultations return current and close-future consultations
    -> make upcoming consultation pickable by SPs (3 minutes)
    -> if begins_at.future? add validation to prevent too many consultations at one time
    -> implement other validations (eg. margin/horizon of 1.hour or 30.minutes)



## MVP

1 patient every 15 minutes

sort consultations by begins_at ASC
greyed out

margin/horizon of 1.hour or 30.minutes


```
CONSULTATION_TIMESLOT_DURATION_MIN = 10
SLOT_DAYS_ADVANCE = 3
CANNOT_BOOK_EARLIER_THAN_MINUTES_FROM_NOW = 30
CLICKABILITY_MARGIN_UPFRONT_MINUTES = 3
then it's pickable
```

waiting time today average

mark_consultations_with_sla
consultation_type : indicate if SLA is at all applicable


mark consultations to differentiate: drop_in from booked


## ideas

2.days advance
- consultationSlots endpoint


- potentially different rules per flow (b2b vs b2c)


- omit certain timeslots
  - based of busiest hour


1st bookable hour 8:30
last bookable hour = 21:30


## notificaitons

- 25 hours prior consultation
- 1 hour prior consultation (or 30 min. TBC)





- add argument :begins_at to `createPatientConsultation` optional, defaults to now

scope :pending, -> { where.not(service_provider: nil).where(cancelled_at: nil).where("consultations.responded_at IS NULL", Time.zone.now) }

-> add a condition for (begins_at < Time.zone.now + 30.minutes

-> make it impossible for a doctor to start consultation before `begins_at` (frontend & backend validation)

make a fixed cap on existing overlapping consultation (3 or 5) and observe.

- make sure all BI is relevant to begins_at not created_at

- create a separate tab in Digimed Dashboard to preview future consultations?


- avg waiting time







1. Tak używamy CalendarBase
2. Rule -> Renameujemy, robimy na STI


    Rename ServiceCenterRules na `CalendarRules`
      -> ServiceCenterRule
      -> ConsultationRule
        