Emma
Emma

Reputation: 317

How to design model for storing day wise timings?

I am designing a schema for doctor's appointments. The doctor will be given the option to update his/her timings for individual days of the month. Also there is no limit to months. For instance, the doctors will be able to update the timings for any days of future or current month. (Only previous dates will be disabled). The front end part has been done but what I fail to understand is how to create the mongo model for it. Of course I can not have dates for all months stored in the model. What is the method to address this problem? TIA

Upvotes: 1

Views: 229

Answers (2)

balexandre
balexandre

Reputation: 75083

If it was me that had such project, I would start with 5 collections:

  • one for users (so you know who did what)
  • one for patients (recording all about the patient, including mobile number)
  • one for doctors (so you can show a list while registering time)
  • one for time registrations (with all details of the registration)
  • one for logging everything a user does

so you can go back in time and to know how did what... it's never to point the finger to the person that made the mistake but look at it as a very easy way to find out what it happened and how can you prevent it from happening again.

the content of each document is entirely up to you as that will change with exactly what and how you are doing

I would think about something between these lines:

// Users
{
  username, hashedPassword, // credentials
  permissions: [], // for when you start using permissions
  active, // never delete data, just set the flag to "false", if, by GDPR rules you need to delete, you can change the name to "DELETED BY GDPR" and still maintain all references
}

// Patients
{
  name,
  address: { street, street2, city, zipcode, country }, // for invoicing proposes
  mobile, // so you send them an SMS 24h before saying their appointment is "tomorrow"
}

// Doctors
{
  name,
  weekAvailability: [], // days of the week that a doctor is available as they normally work in more than one clinique
  active, // never delete data, just set the flag to "false", if, by GDPR rules you need to delete, you can change the name to "DELETED BY GDPR" and still maintain all references
}

// Logs
{
  action, // for example, "save", "add", "change"...
  entity, // the collection name that the change happened
  originalEntry, // the full document before changes
  newEntry, // the full document after changes
  timestamp, // the exact time of the change
  user, // ref to users
}

// TimeRegistrations
{
  user, // ref to users
  patient, // ref to patients
  doctor, // ref to doctors
  title, description, appointmentStart, durationInMinutes,
}

regarding the infrastructure ... create an API (REST or GRAPHQL, the one you're most comfortable with) so you can separate the business logic from the frontend right from the start

your frontend (maybe React, Angular, VueJs) should call a proxy (nodeJs server running aside the frontend) to make authentications and call the API so all you should do in the frontend to be something like

fetch('/api/doctors')
  .then(res => res.toJson())
  .then(json => {
    this.doctorsList = json
  })

same as for authentication os a user where you can easily make use of a library to provide you with a JWT and easily maintain user logged in and with the right set of permissions

Upvotes: 1

Ashutosh
Ashutosh

Reputation: 1095

First approach but not good in your case i.e. One collection,

//doctors
{
   _id: "",
   appointments: [] // all appointments there
}

Second will be better but note in NoSql collection totally depends on how you want to get the data. Two collections:

//doctors
{
   _id: "SOMETHING",
   name: "SOMETHING"
}


//appointments
{
   _id: "SOMETHING",
   doctorId: "", // ref of doctor collection
   appointmentAt: "",
   appointmentAtMilli: "",
}

Upvotes: 1

Related Questions