Live demo: dental.arturmrowicki.pl · Source code: GitHub
An easy calendar, difficult edge cases
Booking an appointment looks simple: the patient picks a doctor and a time, and pays. The difficulty appears when two people click the last free slot almost at the same moment, or when the payment confirmation arrives late.
I built this project as a live demo for several independent practices. Each one has its own calendar and sees only its own patients. Payments run in test mode, so the demo does not take real money.
Four things that cannot be left to chance
- The same slot. Two people cannot get a confirmation of the same appointment.
- The practices’ data. Practice A cannot see the patients of practice B.
- The order of payment. A patient should not pay for a time the system has not secured.
- An up-to-date calendar. A taken slot should also disappear for someone who already has the page open.
How the system makes sure of it
The database has the last word
It is not the screen that decides whether a slot is free. The database allows only one active booking for a given doctor and time. If two requests arrive simultaneously, the first takes the slot and the second gets a clear message that someone has just beaten them to it.
Each practice stays in its own area
The access restriction is written next to the data itself, not only in the page view. Even a faulty query from the application should not return another practice’s records to an employee. A patient can book an appointment without creating an account, but gets no direct access to the database.
First the slot, then on to the payment
The system locks the chosen time for 15 minutes, and only then opens the payment page. A repeated confirmation from the payment provider does not create a second appointment or change it again. If the message arrives after the lock has expired, the event is saved for a refund to be handled.
The calendar changes without a reload
When someone takes a slot, it disappears from the screens of other people viewing the same doctor’s calendar. There is no need to refresh the page by hand.
How I checked the full path
An automated run creates a booking in the working live demo, rejects a second attempt for the same time, starts the payment, accepts a signed confirmation and sends it again to make sure nothing is charged twice. All 9 steps checked completed correctly.
Check it yourself
The demo runs in test mode and does not take real payments:
- choose a clinic and a free slot on the demo site,
- use the Stripe test card
4242 4242 4242 4242, any future date and any CVC code, - open the same calendar in two windows and watch the taken slot disappear in the other one.
What is ready, and what would need more work
What is ready is the booking core, the separation of practices, the test payment and the live calendar updates. Before use in a specific chain, the doctors’ schedules, cancellation rules, automatic refunds, the wording of consents and the way medical data is processed would have to be adapted. The live demo does not pretend to be a finished product for every clinic.
For the technically interested
The project uses Next.js, a PostgreSQL database provided by Supabase and Stripe test payments. The one-booking limit and the split of data between practices are enforced in the database, so they do not depend solely on the screen’s code being correct.