0% found this document useful (0 votes)
17 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)
17 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
You are on page 1/ 2

Hospital Management System - Full Project Code

Frontend - App.js
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/globals.css";

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(localStorage.getItem("theme") || "light");

useEffect(() => {
const token = localStorage.getItem("token");
if (token) {
setIsAuthenticated(true);
}
}, []);

useEffect(() => {
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem("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 - Server.js
const express = require("express");
const cors = require("cors");
const mongoose = require("mongoose");

const app = express();


app.use(cors());
app.use(express.json());

mongoose.connect("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");

app.use("/api/users", userRoutes);
app.use("/api/patients", patientRoutes);
app.use("/api/doctors", doctorRoutes);
app.use("/api/appointments", appointmentRoutes);

const PORT = process.env.PORT || 5000;


app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy