Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pakistanihaider's avatar

Database Schema for kind of Hospital Management System

Hi, i am trying to start an application but its not for managing hospital, it will be for doctors and patients. Where there will be multiple types for users will be able to login such as Doctor, Patients/Guardians.

Doctors can have multiple clinics at multiple locations and doctor can manage patient records. Once the patient account has been created by doctor then patient can take appointment from doctor or update his appointment status and many more stuff will be there next.

The thing is how to go with the ERD.??

I will have

User //User accounts used to login in to the system
Doctor 
Patient
Guardian
Role
Permission

These are the models i have currently created. but they doesnt seem right to me..

Should i remove role columns as i already have different tables for different pre defined roles.

or should it be there. but how to manage permissions on users if no roles table is there.

also most importantly..

How to go with one to one with users?? i mean should i go and create functions in user model such as.

public function doctor(){}
public function guardian(){}
public function patient(){}

or any other better approach is there to follow.

0 likes
3 replies
pakistanihaider's avatar

@waltz

So according to you, i should not go creating doctor, patients and guardian tables, instead everything should be through roles.

But how do then clinics and appointments relationships would work?

ayekoto's avatar

@pakistanihaider You can follow this schema:

roles has many user,

a user belongs to a role

meaning
roles => name: doctors, patients, guardian 
users =>  role_id: id for either doctor type of role or patient

A doctor can have multiple clinics and based on locations, okay, here i see need for Clinic Model and Location Model

meaning
user (type of doctor) has many clinics
a clinic belongs to a doctor

clinics: user_id, clinic_name, etc...

but then a clinic still depend on a location

meaning
a location has many clinics
a clinic belongs to a location

i.e
locations: name
clinics: location_id, clinic_name, etc...

therefore: you should have somethin like

roles: id, name
users: id, role_id
locations: id, name
clinics: id, user_id, location_id

As regards permission: you can create a middleware to: check that the person creating a clinic is has a role_id of doctor & check that the person managing a clinic actually is the owner of the clinic etc depending on your use case

uhmmm, read more about laravel eloquent relationships thanks to @bobbybouwmann for helping with understanding more about relationship back then

2 likes

Please or to participate in this conversation.