health.appointment-slots Unreviewed
Bookable appointment slots from clinic sessions, a slot length, breaks and existing bookings.
1.0.1 · published 2026-10-03 by charlie · Anterra
Pinned by 20 tests, run in TypeScript, Python and Rust.
Unreviewed. This capability’s implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified clinician has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.
Not professional advice. This capability calculates health figures from published rules. It is a software component for developers, not medical advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed in its README, and have a clinician review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.
Not a medical device. It is not intended to diagnose, treat or support clinical decisions about any individual. Anyone building it into clinical software is responsible for that software’s regulatory status, and must validate it under their own clinical governance.
What it does
Lists the appointment slots that can still be booked. It takes clinic sessions (a date with a start and end time), a slot length, breaks and the bookings already made. It is pure scheduling arithmetic on wall-clock times: no time zones, no clock reads, and the same input always gives the same list.
## How the slots are laid out
For example
appointment_slots(sessions ×1, 15, , )→ ×12 a 09:00-12:00 morning in 15-minute slots is twelve slotsappointment_slots(sessions ×1, 20, breaks ×1, )→ ×20 a daily 12:30-13:30 lunch splits 09:00-17:00; 20-minute slots restart at 13:30 and the 10 minutes left before lunch and at the end are droppedappointment_slots(sessions ×2, 30, breaks ×1, )→ ×3 a break with a date applies to that day only
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
def appointment_slots(sessions: Sequence[ClinicSession], slot_minutes: int, breaks: Sequence[ClinicBreak], bookings: Sequence[Booking]) -> List[AppointmentSlot]
| sessions | ClinicSession[] | clinic sessions in any order; sessions on one date must not overlap |
| slot_minutes | int | the length of every slot, 1 to 480 |
| breaks | ClinicBreak[] | times the clinic is closed inside a session; a null date means every day |
| bookings | Booking[] | appointments already booked; a slot they overlap is not offered |
| returns | AppointmentSlot[] | the free slots, by date then start time |
The types it declares, generated into your project
@dataclass(frozen=True)
class ClinicSession:
"""One clinic session on one day; it cannot cross midnight."""
date: str
#: HH:MM, 24-hour
start: str
#: HH:MM, after start
end: str
@dataclass(frozen=True)
class ClinicBreak:
"""A break inside sessions, such as lunch; slots restart after it."""
#: null for a break on every session day
date: Optional[str]
#: HH:MM
start: str
#: HH:MM, after start
end: str
@dataclass(frozen=True)
class Booking:
"""An existing appointment."""
date: str
#: HH:MM
start: str
#: HH:MM, after start
end: str
@dataclass(frozen=True)
class AppointmentSlot:
"""One bookable slot."""
date: str
#: HH:MM
start: str
#: HH:MM
end: str
Your code names it in one line, in the file that uses it
from fune.health.appointment_slots import appointment_slots # health.appointment-slots@^1
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
from typing import List, Optional, Sequence, Tuple
from .health_appointment_slots_types import AppointmentSlot, Booking, ClinicBreak, ClinicSession
from .time_minutes_between import minutes_between ← from time.minutes-between ^1.0.0 · built alongside by fune
#: A break without a date still needs a real date for the time check.
_ANY_DATE = "2000-01-01"
def _minute_of_day(date: str, time: str) -> int:
"""Minute of the day, 0 to 1439; raises on a malformed date or time."""
return minutes_between(date, "00:00", date, time)
def _interval(kind: str, date: Optional[str], start: str, end: str) -> Tuple[str, int, int]:
on = _ANY_DATE if date is None else date
begin = _minute_of_day(on, start)
finish = _minute_of_day(on, end)
if finish <= begin:
raise ValueError(
"%s on %s must end after it starts (%s to %s)" % (kind, "every day" if date is None else date, start, end)
)
return on, begin, finish
def _clock(minute: int) -> str:
return "%02d:%02d" % (minute // 60, minute % 60)
def appointment_slots(
sessions: Sequence[ClinicSession],
slot_minutes: int,
breaks: Sequence[ClinicBreak],
bookings: Sequence[Booking],
) -> List[AppointmentSlot]:
"""Free appointment slots.
Breaks split a session into segments and the slot grid restarts at the
start of each segment, so a 12:30-13:30 lunch gives slots from 13:30.
Bookings only take slots away: they never move the grid, because they are
booked into slots. Intervals are half-open, so a booking ending at 09:15
does not touch the 09:15 slot.
"""
if isinstance(slot_minutes, bool) or not isinstance(slot_minutes, int) or slot_minutes < 1 or slot_minutes > 480:
raise ValueError("slotMinutes must be a whole number from 1 to 480, received %r" % (slot_minutes,))
clinic = [_interval("session", s.date, s.start, s.end) for s in sessions]
closed = [(b.date is None,) + _interval("break", b.date, b.start, b.end) for b in breaks]
booked = [_interval("booking", b.date, b.start, b.end) for b in bookings]
clinic.sort(key=lambda s: (s[0], s[1]))
for previous, current in zip(clinic, clinic[1:]):
if current[0] == previous[0] and current[1] < previous[2]:
raise ValueError("sessions overlap on %s" % (current[0],))
slots: List[AppointmentSlot] = []
for date, start, end in clinic:
pauses = sorted(
((b_start, b_end) for always, b_date, b_start, b_end in closed if always or b_date == date),
)
segments: List[Tuple[int, int]] = []
cursor = start
for p_start, p_end in pauses:
if p_end <= cursor or p_start >= end:
continue
if p_start > cursor:
segments.append((cursor, p_start))
cursor = max(cursor, p_end)
if cursor < end:
segments.append((cursor, end))
for seg_start, seg_end in segments:
t = seg_start
while t + slot_minutes <= seg_end:
slot_end = t + slot_minutes
taken = any(b_date == date and b_start < slot_end and b_end > t for b_date, b_start, b_end in booked)
if not taken:
slots.append(AppointmentSlot(date=date, start=_clock(t), end=_clock(slot_end)))
t += slot_minutes
return slotsInstall
fune build
With that line in your source, in a Python project (language python in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the Python package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add health.appointment-slots
The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./health.appointment-slots-1.0.1-python.fune, or fetch it from a terminal with fune pull health.appointment-slots@1.0.1:python.
The whole function, every language, is one file too: health.appointment-slots-1.0.1.fune, 28,395 bytes, sha256 9b81b0c2ed4032adce8b962d58a67032ce0817f7dcf79e05cf4ec899e66e00a1. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
# fune: before health.appointment-slots
after — your function gets the result and the arguments, and returns the final result.
# fune: after health.appointment-slots
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
# fune: replace time.minutes-between in health.appointment-slots
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show health.appointment-slots --steps.
# fune: step health.appointment-slots after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| a 09:00-12:00 morning in 15-minute slots is twelve slots | sessions ×1, 15, , | → | ×12 |
| a daily 12:30-13:30 lunch splits 09:00-17:00; 20-minute slots restart at 13:30 and the 10 minutes left before lunch and at the end are dropped | sessions ×1, 20, breaks ×1, | → | ×20 |
| a break with a date applies to that day only | sessions ×2, 30, breaks ×1, | → | ×3 |
| a booking straddling two slots removes both | sessions ×1, 15, , bookings ×1 | → | ×2 |
| bookings that only touch a slot's edge do not remove it | sessions ×1, 15, , bookings ×2 | → | ×3 |
| a booking that does not fill its slot does not shift the grid | sessions ×1, 20, , bookings ×1 | → | ×2 |
| bookings on other dates are ignored | sessions ×1, 15, , bookings ×1 | → | ×4 |
| sessions given out of order come back by date and time | sessions ×3, 30, , | → | ×5 |
| a break overlapping the session start moves the first slot to the break's end | sessions ×1, 30, breaks ×1, | → | ×3 |
| a break covering the whole session leaves no slots | sessions ×1, 15, breaks ×1, | → |
Show the other 10 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| a slot longer than the session gives no slots | sessions ×1, 45, , | → | |
| no sessions, no slots | , 15, , | → | |
| sessions that overlap on one day are an error | sessions ×2, 15, , | → | error: sessions overlap on 2026-10-05 |
| a time without a leading zero is an error | sessions ×1, 15, , | → | error: is not a time of day |
| 24:00 is not a time of day | sessions ×1, 15, , | → | error: is not a time of day |
| a session cannot cross midnight: 22:00-00:00 ends before it starts | sessions ×1, 15, , | → | error: session on 2026-10-05 must end after it starts |
| a booking that ends before it starts is an error | sessions ×1, 15, , bookings ×1 | → | error: booking on 2026-10-05 must end after it starts |
| an impossible date is an error | sessions ×1, 15, , | → | error: is not a real calendar date |
| a zero slot length is an error | sessions ×1, 0, , | → | error: slotMinutes must be a whole number from 1 to 480 |
| a fractional slot length is an error | sessions ×1, 7.5, , | → | error: slotMinutes must be a whole number from 1 to 480 |
More from the author
- **Breaks reshape a session.** A break (lunch, a team meeting) splits the session into free segments. Slots are laid back to back from the start of each segment, so after a 12:30-13:30 lunch the first slot is at 13:30, not wherever the morning's grid would have landed. A break with a null date applies to every session day. A break with a date applies to that day only. - **Leftovers are dropped.** A slot must fit wholly inside its segment. With 20-minute slots, 09:00-12:30 gives ten slots ending at 12:20, and the last 10 minutes are not offered. - **Bookings only take slots away.** A slot that overlaps any booking on the same date is removed, but the grid does not move. Bookings are made into slots, so a 5-minute booking at 09:05 removes the 09:00 slot and leaves 09:20 where it was. A booking across two slots removes both. - **Touching is not overlapping.** Intervals are half-open (start included, end excluded), so a booking ending at 09:15 leaves the 09:15 slot free.
Sessions may be given in any order. The result is sorted by date, then start time.
## Errors
The function refuses, rather than guessing, when:
- a time is not `HH:MM` from 00:00 to 23:59 (`9:00` and `24:00` are refused) - a date is not a real ISO date - a session, break or booking does not end after it starts - two sessions on the same date overlap - `slotMinutes` is not a whole number from 1 to 480
A session cannot cross midnight. Split an overnight clinic into two sessions, one on each date.
## What it does not do
It does not handle clinicians, rooms or appointment types. Call it once per clinician or resource. It does not handle double-booking capacity (more than one patient per slot) or daylight-saving changes. It does not keep slots in the past out of the list, because it never reads the clock: pass only the sessions still to come.
## Before you rely on this
**Not professional advice.** This capability calculates health figures from published rules. It is a software component for developers, not medical advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed above, and have a clinician review how you use it, before anyone relies on the output. Provided "as is" under its licence, without warranty.
**Not a medical device.** It is not intended to diagnose, treat or support clinical decisions about any individual. Anyone building it into clinical software is responsible for that software's regulatory status, and must validate it under their own clinical governance.
**Unreviewed.** This capability's implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified clinician has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.
1.0.1 marks it unreviewed. The code and the tests are unchanged.
Files
| Path | Bytes |
|---|---|
| README.md | 3,561 |
| impl/python.py | 3,310 |
| impl/rust.rs | 5,132 |
| impl/typescript.ts | 3,510 |
| vectors.json | 7,400 |