Hospital Management System - Full Project Code
Frontend - [Link]
import React, { useEffect, useState } from "react";
import { BrowserRouter as Router, Route, Routes, Navigate } from "react-router-dom";
import { Toaster } from "react-hot-toast";
import Navbar from "./components/Navbar";
import ProtectedRoute from "./components/ProtectedRoute";
import ThemeToggle from "./components/ThemeToggle";
import Notifications from "./components/Notifications";
import "./styles/[Link]";
import Dashboard from "./pages/Dashboard";
import Login from "./pages/Login";
import Patients from "./pages/Patients";
import Doctors from "./pages/Doctors";
import Appointments from "./pages/Appointments";
import Billing from "./pages/Billing";
import Profile from "./pages/Profile";
import NotFound from "./pages/NotFound";
function App() {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [theme, setTheme] = useState([Link]("theme") || "light");
useEffect(() => {
const token = [Link]("token");
if (token) {
setIsAuthenticated(true);
}
}, []);
useEffect(() => {
[Link]("data-theme", theme);
[Link]("theme", theme);
}, [theme]);
return (
<Router>
<Toaster position="top-right" />
{isAuthenticated && <Navbar />}
{isAuthenticated && <Notifications />}
{isAuthenticated && <ThemeToggle theme={theme} setTheme={setTheme} />}
<Routes>
<Route path="/login" element={<Login setAuth={setIsAuthenticated} />} />
<Route element={<ProtectedRoute isAuthenticated={isAuthenticated} />}>
<Route path="/" element={<Dashboard />} />
<Route path="/patients" element={<Patients />} />
<Route path="/doctors" element={<Doctors />} />
<Route path="/appointments" element={<Appointments />} />
<Route path="/billing" element={<Billing />} />
<Route path="/profile" element={<Profile />} />
</Route>
<Route path="*" element={<NotFound />} />
</Routes>
</Router>
);
}
export default App;
Backend - [Link]
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");
const app = express();
[Link](cors());
[Link]([Link]());
[Link]("mongodb://localhost:27017/hospitalDB", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const userRoutes = require("./routes/userRoutes");
const patientRoutes = require("./routes/patientRoutes");
const doctorRoutes = require("./routes/doctorRoutes");
const appointmentRoutes = require("./routes/appointmentRoutes");
[Link]("/api/users", userRoutes);
[Link]("/api/patients", patientRoutes);
[Link]("/api/doctors", doctorRoutes);
[Link]("/api/appointments", appointmentRoutes);
const PORT = [Link] || 5000;
[Link](PORT, () => [Link](`Server running on port ${PORT}`));