diff --git a/server/index.js b/server/index.js
index a566b9b..3974682 100644
--- a/server/index.js
+++ b/server/index.js
@@ -158,6 +158,7 @@ app.use('/api/reports', require('./routes/reports'));
app.use('/api/risk-assessment', require('./routes/riskAssessment'));
app.use('/api/family', require('./routes/family'));
app.use('/api/security', require('./routes/security'));
+app.use('/api/hospitals', require('./routes/hospitals'));
// Health Check / Default route
app.get('/', (req, res) => {
diff --git a/server/routes/hospitals.js b/server/routes/hospitals.js
new file mode 100644
index 0000000..6ea4b88
--- /dev/null
+++ b/server/routes/hospitals.js
@@ -0,0 +1,29 @@
+const express = require('express');
+const router = express.Router();
+const auth = require('../middleware/auth');
+
+// Mock data for hospitals
+const mockHospitals = [
+ { id: '1', name: 'City General Hospital', address: '123 Main St, Cityville', lat: 40.7128, lon: -74.0060, availableBeds: 42, specialty: 'Trauma Center' },
+ { id: '2', name: 'St. Mary Medical Center', address: '456 Oak Ave, Townsburg', lat: 40.7150, lon: -74.0100, availableBeds: 15, specialty: 'Cardiology' },
+ { id: '3', name: 'Valley Health Clinic', address: '789 Pine Rd, Villagetown', lat: 40.7100, lon: -74.0200, availableBeds: 0, specialty: 'Pediatrics' },
+ { id: '4', name: 'Metro Medical Hub', address: '321 Elm St, Metropolis', lat: 40.7300, lon: -73.9900, availableBeds: 120, specialty: 'General' }
+];
+
+// GET /api/hospitals
+// Search for nearby hospitals and their bed availability
+router.get('/', auth, (req, res) => {
+ const { query, lat, lon } = req.query;
+
+ let results = [...mockHospitals];
+
+ if (query) {
+ const lowerQuery = query.toLowerCase();
+ results = results.filter(h => h.name.toLowerCase().includes(lowerQuery) || h.specialty.toLowerCase().includes(lowerQuery));
+ }
+
+ // Return the results
+ res.json(results);
+});
+
+module.exports = router;
diff --git a/src/App.jsx b/src/App.jsx
index c92a8a0..931e0d8 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -44,6 +44,7 @@ import Login from './pages/Login';
import Profile from './pages/Profile';
import DosageCalculator from './pages/DosageCalculator';
import HealthMetrics from './pages/HealthMetrics';
+import HospitalFinder from './pages/HospitalFinder';
import Footer from './components/Footer';
import NotFound from './pages/NotFound';
@@ -346,6 +347,7 @@ function App() {
} />
} />
} />
+ } />
} />
} />
} />
diff --git a/src/pages/HospitalFinder.jsx b/src/pages/HospitalFinder.jsx
new file mode 100644
index 0000000..49bf95e
--- /dev/null
+++ b/src/pages/HospitalFinder.jsx
@@ -0,0 +1,117 @@
+import React, { useState, useEffect } from 'react';
+import {
+ Box,
+ Typography,
+ Container,
+ TextField,
+ Button,
+ Card,
+ CardContent,
+ Grid,
+ Chip,
+ CircularProgress
+} from '@mui/material';
+import { LocalHospital as HospitalIcon, Search as SearchIcon } from '@mui/icons-material';
+import API from '../utils/api';
+
+function HospitalFinder() {
+ const [query, setQuery] = useState('');
+ const [hospitals, setHospitals] = useState([]);
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState(null);
+
+ const fetchHospitals = async (searchQuery = '') => {
+ setLoading(true);
+ setError(null);
+ try {
+ const res = await API.get('/api/hospitals', { params: { query: searchQuery } });
+ setHospitals(res.data);
+ } catch (err) {
+ console.error(err);
+ setError('Failed to fetch hospital data.');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ fetchHospitals();
+ }, []);
+
+ const handleSearch = (e) => {
+ e.preventDefault();
+ fetchHospitals(query);
+ };
+
+ return (
+
+
+
+
+ Hospital & Bed Availability
+
+
+
+
+ setQuery(e.target.value)}
+ />
+ } sx={{ px: 4 }}>
+ Search
+
+
+
+ {error && {error}}
+
+ {loading ? (
+
+
+
+ ) : (
+
+ {hospitals.map((hospital) => (
+
+
+
+
+
+ {hospital.name}
+
+ 10 ? 'success' : hospital.availableBeds > 0 ? 'warning' : 'error'}
+ size="small"
+ sx={{ fontWeight: 'bold' }}
+ />
+
+
+ {hospital.address}
+
+
+ Specialty: {hospital.specialty}
+
+
+
+
+
+ ))}
+ {hospitals.length === 0 && (
+
+
+ No hospitals found matching your criteria.
+
+
+ )}
+
+ )}
+
+ );
+}
+
+export default HospitalFinder;