Skip to content

aliaasaudi14/Smart-Clinic-Management-System

Repository files navigation

πŸ₯ Clinic Management System β€” MongoDB Project

A multi-doctor SaaS platform built on MongoDB Atlas for managing clinic appointments, medical rep visits, and doctor schedules.

MongoDB Collections Aggregations Status


πŸ“Œ Overview

This project is a Clinic Management System built using MongoDB Atlas, designed to manage doctors, patients, appointments, medical representatives, and clinic schedules.

The system demonstrates:

  • βœ… Data Modeling β€” Embedded & Referenced relationships
  • βœ… Aggregation Framework β€” 16 real-world queries
  • βœ… Business Logic β€” booking validation, scheduling conflicts
  • βœ… Multi-role Authentication β€” doctor, patient, medical rep, admin
  • βœ… SaaS Architecture β€” multiple doctors on one platform

🎯 Features

Feature Description
πŸ” Authentication Users collection with 4 roles
πŸ‘¨β€βš•οΈ Doctors Profile + clinic info + consultation fee
πŸ§‘β€πŸ€β€πŸ§‘ Patients Profile + blood type + medical info
πŸ“… Appointments Booking with day, time, status
πŸ’Š Medical Reps Company info + drug specialty
πŸ”„ Rep Visits Full visit lifecycle + embedded summary
πŸ•’ Schedules Weekly working hours per doctor
🚫 Clinic Days Closed dates + exception handling

πŸ—‚οΈ Database Structure

1️⃣ users

Stores accounts for all system users.

Field Type Description
_id int Custom ID
name string Full name
email string Unique email
password string Hashed password
role string doctor Β· patient Β· medical rep Β· admin

2️⃣ doctors

Doctor-specific profile data.

Field Type Description
_id ObjectId Auto-generated
user_id int β†’ users._id
specialization string e.g. Cardiology
clinic_name string Display name
consultation_fee int Fee in EGP

3️⃣ patients

Patient profile and medical info.

Field Type Description
_id ObjectId Auto-generated
user_id int β†’ users._id
age int Patient age
gender string male / female
phone string Contact number
blood_type string A+, B-, O+, etc.

4️⃣ appointments

Patient bookings linked to doctors.

Field Type Description
_id ObjectId Auto-generated
doctor_id ObjectId β†’ doctors._id
patient_id ObjectId β†’ patients._id
day string Sunday–Saturday
time string HH:MM format
status string booked / cancelled

5️⃣ medical_reps

Medical representative data.

Field Type Description
_id ObjectId Auto-generated
user_id int β†’ users._id
company_name string Pharma company
company_phone string Company number
drug_specialty string Medical field
phone string Rep direct number

6️⃣ rep_visits

Visit requests + embedded visit summary.

Field Type Description
_id ObjectId Auto-generated
doctor_id ObjectId β†’ doctors._id
rep_id ObjectId β†’ medical_reps._id
date ISODate Visit date
status string completed Β· cancelled Β· no-show Β· rescheduled
visit_summary embedded samples Β· duration Β· topic Β· feedback

Embedded document example:

"visit_summary": {
  "samples": 3,
  "duration_min": 22,
  "discussion_topic": "Cardio drug",
  "feedback": "Doctor accepted samples"
}

7️⃣ Schedules

Weekly working hours per doctor.

Field Type Description
_id ObjectId Auto-generated
doctor_id ObjectId β†’ doctors._id
day string Working day
patient_start_time string e.g. "09:00"
patient_end_time string e.g. "13:00"
rep_start_time string e.g. "13:00"
rep_end_time string e.g. "14:00"
max_patients int Daily patient limit
max_reps int Daily rep limit

8️⃣ clinic_days

Handles closed days and exceptions.

Field Type Description
_id ObjectId Auto-generated
doctor_id ObjectId β†’ doctors._id
date ISODate Specific date
is_open boolean false = closed
reason string e.g. "National Holiday"

πŸ”— Relationships

users
 β”œβ”€β”€ doctors        (user_id  β†’ users._id)
 β”œβ”€β”€ patients       (user_id  β†’ users._id)
 └── medical_reps   (user_id  β†’ users._id)

doctors
 β”œβ”€β”€ appointments   (doctor_id β†’ doctors._id)
 β”œβ”€β”€ rep_visits     (doctor_id β†’ doctors._id)
 β”œβ”€β”€ Schedules      (doctor_id β†’ doctors._id)
 └── clinic_days    (doctor_id β†’ doctors._id)

appointments
 └── patients       (patient_id β†’ patients._id)

rep_visits
 └── medical_reps   (rep_id β†’ medical_reps._id)

Referenced β€” all cross-collection links use ObjectId or int references.
Embedded β€” visit_summary lives inside each rep_visits document.


πŸ“Š Aggregation Queries (14)

πŸ‘€ Users & Doctors

# Query Stages Used
1 Count total doctors per specialization $group, $sum
2 Combine doctor info with total patients $lookup, $unwind, $addFields, $size
3 Identify low-utilization doctors $lookup, $addFields, $match

πŸ§‘β€πŸ€β€πŸ§‘ Patients & Appointments

# Query Stages Used
4 Count total patients per day $group, $sum
5 Identify peak day $group, $sort, $limit
6 Identify peak hour $group, $sort, $limit

πŸ’Š Medical Reps & Visits

# Query Stages Used
7 Total rep visits per day $group, $dateToString
8 Most active medical rep $group, $sort, $limit, $lookup
9 Compare patients vs rep visits per doctor $group, $lookup, $addFields

πŸ•’ Schedules & Clinic Logic

# Query Stages Used
10 Weekly schedule for a specific doctor $match, $lookup
11 Retrieve doctor closed days $match, $lookup
12 Calculate occupancy rate $group, $project, $divide, $multiply
13 Detect idle days $group, $push, $setDifference
14 Detect scheduling conflicts $match, $addFields, $switch, $dayOfWeek, $lookup

🧠 Business Logic

Booking Request
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 1. Is the clinic open?        β†’ clinic_days      β”‚
β”‚ 2. Does a schedule exist?     β†’ Schedules        β”‚
β”‚ 3. Is time within range?      β†’ patient/rep hoursβ”‚
β”‚ 4. Is the slot available?     β†’ appointments     β”‚
β”‚ 5. Is max capacity reached?   β†’ max_patients     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β”‚
      β–Ό
   βœ… Booking Confirmed  /  ❌ Rejected

πŸ“¦ Sample Data

Collection Records
users 50 (10 doctors + 10 reps + 30 patients)
doctors 10
patients 30
medical_reps 10
appointments 31
rep_visits 100
Schedules 25
clinic_days 10

πŸš€ Setup

1. MongoDB Atlas

  1. Create a free cluster at cloud.mongodb.com
  2. Create database named clinicDB
  3. Database Access β†’ Add DB User β†’ role: readWrite on clinicDB
  4. Network Access β†’ Add IP β†’ 0.0.0.0/0 (development)
  5. Copy your connection string

2. Run Scripts in Order

1.  users (doctors)       β†’ db.users.insertMany([...])
2.  doctors               β†’ db.doctors.insertMany([...])
3.  users (patients)      β†’ db.users.insertMany([...])
4.  patients              β†’ db.patients.insertMany([...])
5.  users (reps)          β†’ db.users.insertMany([...])
6.  medical_reps          β†’ db.medical_reps.insertMany([...])
7.  appointments          β†’ db.appointments.insertMany([...])
8.  rep_visits            β†’ db.rep_visits.insertMany([...])
9.  Schedules             β†’ db.Schedules.insertMany([...])
10. clinic_days           β†’ db.clinic_days.insertMany([...])

⚠️ Always insert users before any role-specific collection.


βœ… Requirements Coverage

Requirement Status How
Secure Authentication βœ… users collection β€” 4 roles
Business Logic Cycle βœ… 5-step booking validation
Embedded Documents βœ… visit_summary in rep_visits
Referenced Relationships βœ… user_id, doctor_id, patient_id, rep_id
Aggregation Pipelines βœ… 14 queries β€” $group, $lookup, $switch...
DB Users + Permissions βœ… Atlas β†’ readWrite on clinicDB
Network Access βœ… Atlas β†’ IP Whitelist
MongoDB Atlas Deployment βœ… clinicDB on Atlas Cluster

πŸ› οΈ Technologies

  • MongoDB Atlas β€” Cloud database
  • MongoDB Aggregation Framework β€” Data analysis
  • NoSQL Data Modeling β€” Embedded + Referenced

πŸ’‘ Key Insights

  • Efficient use of references for scalability
  • Separation of base schedules and exceptions
  • Embedded visit_summary demonstrates real-world nested documents
  • 14 aggregation queries cover the full analytics lifecycle
  • Ready for Dashboard integration (Power BI / Tableau / Metabase)

About

A smart clinic scheduling system that prevents conflicts between patient appointments and pharmaceutical representative visits using intelligent slot management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors