0% found this document useful (0 votes)
214 views2 pages

Hospital Management System Code

The document outlines a Hospital Management System with a React frontend and an Express backend. The frontend includes components for authentication, theme management, and routing for various pages like Dashboard, Patients, and Doctors. The backend connects to a MongoDB database and sets up API routes for users, patients, doctors, and appointments.

Uploaded by

solocamper598
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
214 views2 pages

Hospital Management System Code

The document outlines a Hospital Management System with a React frontend and an Express backend. The frontend includes components for authentication, theme management, and routing for various pages like Dashboard, Patients, and Doctors. The backend connects to a MongoDB database and sets up API routes for users, patients, doctors, and appointments.

Uploaded by

solocamper598
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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}`));

You might also like