Making a recurrent appointment scheduling software with django and python

I am trying to make a recurrent scheduling software for patient scheduling. I am a doctor and new to programming.
Each appointment slot is for 15mins. starting from xam to ypm everyday from Monday to Friday.
In the front end we provide the patient details and the no. of days (d) to be booked.
So… if i plan to start the treatment on a particular day, I give the system a preferred date and the system lets me know the available slots for the day and then books the same slot (preferably) for the next d days.
If there are no slots on the available days, it should give back the nearest slot available in the coming days.
How do i approach this?

1 Like

Well, this is a pretty open-ended question, but I’ll try and at least get you started down the right path.

First thing you’ll need is a model to store your appointments. You mentioned a front-end that supplies some details, so I’m not sure what other system(s) you have in place, but my first thought would be to create an Appointment model that would store some patient identifier (ID #, whatever you use) and a start and end datetime for each appointment you have booked. You’ll also need to code in the bounds of your schedule - the earliest and latest times you can schedule an appointment for.

Then you need to write some logic that will handle things like identifying all open timeslots for a particular day, and seeking forward in the calendar for the next available timeslot. So if you fed the system 25-May-2020 as the preferred date, you can query the database for any appointments scheduled for that date and display all of the possible times that aren’t already booked. You’ll also need logic to handle the multiple days aspect - if you are trying to book an appointment where d = 5 days, you’ll need to look at all times available today that are also available over the next 4 days.

Stuff like this seems trivially easy at first glance, but once you get into the weeds you can see how it can get pretty tricky.

I would Google “conference room scheduling algorithms” - there are a lot of examples of algos that deal with comparing calendars and finding free times/conflicts as this is a common question for programming courses/interview prep.You might find this video interesting - it’s a former Google engineer doing a mock interview with a college student and they use a calendar algorithm as the problem to work through. You can see some of the thought process and logic involved in working with blocks of time:

As a new programmer, this is a pretty complex case to muscle through (and, if I’m being honest, you’d probably be better off designing how you want the system to work and passing that off to a freelancer to code it for you) – but I don’t want to discourage you, and kudos to trying to learn how to do this on your own.

Working with dates is not trivial, and depending on how robust you want to make the system, you might also have to work around holidays, vacation days, cancellations, rescheduling, etc…

If you want some more specific advice, post what you’ve tried and where you’re getting stuck. Are you still in the planning phase? Are you halfway through building the thing and are having a specific problem?

Hope that helps a little bit at least…



I am trying to make a recurrent scheduling software for patient scheduling. I am a doctor and new to programming.

Hi, great that you are thinking outside of the box and trying to find practical uses of your developing programming skills :slight_smile:

In the front end we provide the patient details and the no. of days (d) to be booked.

You probably shouldn’t enter any patient details in anything you build until you’ve spent a lot of time studying how Python or databases work in general, and data security aspects in particular. You might want to collaborate with a data security expert, and you’d probably want to have some kind of legal expert involved. Patient details are highly sensitive information and you must be absolutely certain that you can store them in secure ways that are not vulnerable to data leaks on your/your company’s part, or intrusion (hacking) from external agents. You could end up in a lot of trouble if you aren’t very careful about these things, so please refrain from entering any patient details for now. What you could do is try to exchange patient details for a generic name, like ‘patient 1’, ‘patient 2’, et c. But even then, if you write meeting information in the time slots, like say ‘chemotherapy session 1’, ‘chemotherapy session 2’… then the information might still be considered sensitive. Please try to make the system as non-sensitive as possible. Build something that you would be totally fine with anyone seeing, because you should assume that bad actors could gain access to it if they try hard enough.

Do you know how base Python works? If not, this book is often recommended as a good start:

If you know Python very well, but don’t know Django yet, you probably want to start by going through the official Django tutorial, here’s a video on YouTube that helps you through it (I haven’t watched the whole thing myself, but what I did watch seemed helpful) That is, if Django is the most appropriate tool for what you want to do. It might not be, since you probably shouldn’t share the project over the web (again, unless you use very thorough security measures), and Django is a web framework.

If you don’t know Python and Django well already there’s a risk that your experience trying to build this might be very frustrating. Which would be a shame! If you find it too hard to tackle this now, please give more basic tasks a go and try to work up your experience before giving this a go again.

I see that as I was writing, jimwritescode already gave more practical advice than I could anyway, so I’ll leave the post like this. I hope it doesn’t sound too negative and that it’s helpful. Happy coding :star:

Edit: I should add that there are different opinions on whether or not you should practice base Python before starting to learn Django. If you don’t know either one but want to get going with Django right away, you can try the django girls tutorial. I’m not allowed to post more than two links as a new user, so you can just do an online search for ‘django girls tutorial’.


Thanks @jimwritescode and @datalowe for the inputs.
I do have some basic knowledge of both.

I have made the basic framework of the program too (i think). But I think i cant get my head around the relationships in django even after lots of hours trying to learn it.
I am stuck at making the timeslots and linking the patient data to the same. And yes… i will be anonymizing the names.
I have made 2 classes - Patients and Rooms. ( i have not yet made a Doctor class, but do plan to add it later and they will have a username and password for logging in).

Well… the issue is i work for a public hospital which is quite cash strapped and low in staff. We deal with a huge patient load and the patients experience quite a bit of discomfort due to the inherent inefficiencies of the system including long waiting periods. I just want to try to see I i could help in smoothing up the process and reduce the discomfort to the patients.

This is my Here ‘Machines’ = the rooms. special techniques are the

from django.db import models

from django.contrib.auth.models import User
from multiselectfield import MultiSelectField
from django.urls import reverse

(‘none’, ‘NONE’),
(‘abc’, ‘ABC’),
(‘tbi’, ‘TBI’),
(‘tset’, ‘TSET’),
(‘srs_cone’, ‘SRS cone’),
(‘srs_apex’, ‘SRS APEX’),
(‘csi’, ‘CSI’),

(‘none’, ‘NONE’),
(‘head_and_neck’, ‘Head and neck’),
(‘brain’, ‘Brain’),
(‘thorax’, ‘Thorax’),
(‘pelvis’, ‘Pelvis’),


class Machine(models.Model):
name = models.CharField(max_length=50)
location = models.CharField(max_length=50)
special_techniques = models.CharField(max_length=10, choices=SPECIAL_TECHNIQUES, default=“none”)
site = MultiSelectField(choices=SITES, default=‘none’)

def __str__(self):

def get_absolute_url(self):
    return reverse("sched_app_1:detail", kwargs={'pk':})

class Patient(models.Model):
name = models.CharField(max_length=50)
Mr_no = models.CharField(max_length=10, unique=True)
age = models.PositiveIntegerField()
machine = models.ForeignKey(Machine, related_name=‘patients’, on_delete=models.DO_NOTHING)
treatment_site = MultiSelectField(choices=SITES, default=‘none’)
special_techniques = models.CharField(max_length=10, choices=SPECIAL_TECHNIQUES, default=“none”)
treatment_start = models.DateField

def __str__(self):

this is my

from django.shortcuts import render
from . import forms
from .forms import PatientDataEntryForm

from django.views.generic import (View,
                                TemplateView, ListView, DetailView,
                                CreateView, UpdateView, DeleteView)
from django.http import HttpResponse
from . import models
from django.urls import reverse_lazy

class IndexView(TemplateView):
    template_name = 'sched_app_1/index.html'

class MachineListView(ListView):
    context_object_name = 'machinelist'
    model = models.Machine
    template_name = 'sched_app_1/machinelist.html'

class MachineDetailView(DetailView):
    context_object_name = 'machine_detail'
    model = models.Machine
    template_name = 'sched_app_1/machinedetails.html'

class MachineCreateView(CreateView):
    fields = ('name', 'location')
    model = models.Machine

class MachineUpdateView(UpdateView):
    fields = ('name', 'location')
    model = models.Machine

class MachineDeleteView(DeleteView):
    model = models.Machine
    success_url = reverse_lazy("sched_app_1:list")

class PatientDetailView(DetailView):
    context_object_name = 'patient_detail'
    model = models.Patient
    template_name = 'sched_app_1/patient_details.html'

def patient_register(request):

    registered = False

    if request.method == 'POST':
        patient_details_form = PatientDataEntryForm(data=request.POST)

        if patient_details_form.is_valid():
            ptdet =

            registered = True
        patient_details_form = PatientDataEntryForm()

    return render(request, 'sched_app_1/patient_registration.html',
                  {'patient_details_form': patient_details_form})

Forgive me if all this look too stupid.

As you rightly said. I am finding it difficult to work with calender. I will look into the video you have send.

Thanks again

1 Like

Hey guys… any help with this?

If I were implementing this, I’d be encoding time slots as integers where the individual time slots were 15-minute intervals starting at midnight. (In other words, 00:00 would = 0, 00:15 = 1, 00:30 = 2, 01:00 = 4, and so on.) (Makes it easy to define different lengths of days - you could have a calendar identifying the first and last slot of each day.)

What I’m not seeing in your description is the concurrency of appointments. Can you only handle 1 person per time slot? Or is it one person per “special technique” per time slot? Or something else? (This all affects the data model needing to be created.)

Assuming for the moment that it’s actually one person per technique per time slot, I would then have an “Appointment” model with columns for the following:
date, time_slot, technique, patient
This will facilitate the various queries needing to be written to identify what slots are open for each technique.

But I’ll also echo what others have said - this type of scheduling application is not trivial, and likely to be frustrating for someone just starting out. It’s almost certainly beyond what you can expect from the type of assistance that can be provided here - these types of applications, in practice, are why the professional consulting firms exist.

Thanks @KenWhitesell.
The rooms can handle only one person per time slot (a slot of 15 mins).
Thanks for the inputs.

Hi there!
That’s great that you are a doctor yourself, so you really understand the pain of end-users haha.
Here is a great tutorial on creating appointment scheduling software, a list of ready-made software, and some other tips. All the info is based on several years of healthcare software development.