Project app.
js
[Link] //[Link]
import React from 'react';
// [Link] import {
const express = require('express'); BrowserRouter as Router,
const mongoose = require('mongoose'); Routes, Route,
const cors = require('cors'); Link, useNavigate
const bodyParser = require('body-parser'); } from 'react-router-dom';
const patientsRouter = import Appointments
require('./routes/patients'); from './components/Appointments';
const doctorsRouter = import Doctors from './components/Doctors';
require('./routes/doctors'); import Patients from './components/Patients';
const appoinmentsRouter = import './[Link]'
require('./routes/appointments')
const app = express(); const App = () => {
const PORT = [Link] || 5000; const isLinkActive =
(path) =>
[Link](cors());
[Link] === path;
[Link]([Link]());
return (
<Router>
// Connect to MongoDB <div
[Link]( className="container">
'mongodb://localhost:27017/hospital' <h1 style={{
, color: "green" }}>
{ GFG-
Hospital Managment App
useNewUrlParser: true,
</h1>
useUnifiedTopology: true <nav>
}); <ul>
const connection = [Link];
[Link]('open', () => { <li className={
[Link]('MongoDB database isLinkActive('/appointments')
? 'active' : ''}>
connection established successfully');
<Link to="/appointments">
}); Appointments
</Link>
[Link]('/patients', patientsRouter); </li>
[Link]('/doctors', doctorsRouter);
[Link]('/appointments', appoinmentsRouter) <li className={
isLinkActive('/doctors') ?
'active' : ''}>
[Link](PORT, () => {
<Link to="/doctors">
[Link](`Server is running on port Doctors
${PORT}`); </Link>
}); </li>
<li className={
// models/[Link]
isLinkActive('/patients') ?
const mongoose = require('mongoose');
'active' : ''}> const Schema = [Link];
const doctorSchema = new Schema({
<Link to="/patients"> name: { type: String, required: true },
Patients
specialty: { type: String, required: true
</Link>
</li> },
</ul> // Add more fields as needed
</nav> });
<Routes>
const Doctor =
<Route path="/appointments" [Link]('Doctor',
element={<Appointments />} />
doctorSchema);
<Route path="/"
element={<Appointments />} />
<Route path="/doctors" [Link] = Doctor;
element={<Doctors />} />
<Route path="/patients" // models/[Link]
element={<Patients />} />
</Routes>
const mongoose = require('mongoose');
</div>
</Router> const Schema = [Link];
); const patientSchema = new Schema({
} name: { type: String, required: true },
age: { type: Number, required: true },
export default App; gender: { type: String, required: true },
// Add more fields as needed
// models/[Link] });
const Patient = [Link]('Patient',
const mongoose = require('mongoose'); patientSchema);
const Schema = [Link]; [Link] = Patient;
const appointmentSchema = new Schema({
patientName: { type: String, required: // routes/[Link]
true },
doctorName: { type: String, required: const express = require('express');
true }, const router = [Link]();
const Appointment =
date: { type: Date, required: true },
require('../models/Appointment');
// Add more fields as needed
}); // Get all appointments
[Link]('/').get((req, res) => {
const Appointment = [Link]()
[Link]('Appointment', .then(appointments =>
appointmentSchema);
[Link](appointments))
[Link] = Appointment;
.catch(err =>
[Link](400).json('Error: ' + err));
}); [Link]('/delete/:id')
.delete((req, res) => {
// Add new appointment
[Link]('/add').post((req, res) => { [Link](req.
const { patientName, doctorName, [Link])
date } = [Link]; .then(
const newAppointment = () => res
new Appointment({
patientName, doctorName, date }); .json('Appointment deleted.'))
.catch(
[Link]() err => res
.then(savedAppointment =>
[Link](savedAppointment)) .status(400).json('Error: ' + err));
.catch(err => });
[Link](400).json('Error: ' + err));
}); [Link] = router;
// Update appointment data
[Link]('/update/:id').post((req, res) => {
[Link]([Link])
.then(appointment => {
[Link] =
[Link];
[Link] =
[Link];
[Link] =
[Link];
[Link]()
.then(
() =>
[Link]('Appointment updated!'))
.catch(
err =>
[Link](400)
.json('Error: ' + err));
})
.catch(
err => [Link](400)
.json('Error: '
+ err));
});
// Delete appointment