Hospital Management System
Introduction
This is a simple example of how to model a hospital management system using Mongoose. We will be using the following schema:
- Patient
- Doctor
- Hospital
- Medical Report
- Address
The Folder structure will look like this:
- address.models.js
- doctor.models.js
- hospital.models.js
- medical_report.models.js
- paitent.models.js
Patient
model/patient.models.js
import mongoose from "mongoose";
const patientSchema = new mongoose.Schema(
{
name: { type: String, required: true },
age: { type: Number, required: true },
diagnosedWith: { type: String, required: true },
bloodGroup: { type: String, required: true },
gender: {
type: String,
required: true,
enum: ["M", "F", "Others"],
},
address: {
type: mongoose.Schema.Types.ObjectId,
ref: "Address",
required: true,
},
contact: { type: Number, required: true },
email: { type: String, required: true },
medicalReports: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "MedicalReport",
},
],
whichHospital: {
type: mongoose.Schema.Types.ObjectId,
ref: "Hospital",
required: true,
},
},
{ timestamps: true }
);
export const Patient = mongoose.model("Patient", patientSchema);
Doctor
model/doctor.models.js
import mongoose from "mongoose";
const doctorSchema = new mongoose.Schema(
{
name: {
type: String,
required: true,
},
specialization: {
type: String,
required: true,
},
salary: {
type: Number,
required: true,
},
qualification: {
type: String,
required: true,
},
contact: {
type: Number,
required: true,
},
email: {
type: String,
required: true,
},
experience: {
type: Number,
required: true,
default: 0,
},
worksInHospital: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Hospital",
required: true,
},
],
address: {
type: mongoose.Schema.Types.ObjectId,
ref: "Address",
required: true,
},
},
{ timestamp: true }
);
export const Doctor = mongoose.model("Doctor", doctorSchema);
Hospital
model/hospital.models.js
import mongoose from "mongoose";
const hospitalSchema = new mongoose.Schema(
{
name: { type: String, required: true },
address: {
type: mongoose.Schema.Types.ObjectId,
ref: "Address",
required: true,
},
contact: { type: Number, required: true },
email: { type: String, required: true },
doctors: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Doctor",
},
],
patients: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Patient",
},
],
specialization: [
{
type: String,
required: true,
},
],
},
{ timestamps: true }
);
export const Hospital = mongoose.model("Hospital", hospitalSchema);
Medical Report
model/medical_report.models.js
import mongoose from "mongoose";
const medicalReportSchema = new mongoose.Schema({}, { timestamps: true });
export const MedicalReport = mongoose.model(
"MedicalReport",
medicalReportSchema
);
Address
model/address.models.js
import mongoose from "mongoose";
const addressSchema = new mongoose.Schema({
street: { type: String, required: true },
city: { type: String, required: true },
state: { type: String, required: true },
country: { type: String, required: true },
pincode: { type: String, required: true },
});
export const Address = mongoose.model("Address", addressSchema);