Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
29 changes: 29 additions & 0 deletions server/routes/hospitals.js
Original file line number Diff line number Diff line change
@@ -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;

Check warning on line 16 in server/routes/hospitals.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless assignment to variable "lat".

See more on https://sonarcloud.io/project/issues?id=vallabhatech_CareSync&issues=AZ-jvoTrKxuH45haSWfW&open=AZ-jvoTrKxuH45haSWfW&pullRequest=336

Check warning on line 16 in server/routes/hospitals.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of the unused 'lon' variable.

See more on https://sonarcloud.io/project/issues?id=vallabhatech_CareSync&issues=AZ-jvoTrKxuH45haSWfX&open=AZ-jvoTrKxuH45haSWfX&pullRequest=336

Check warning on line 16 in server/routes/hospitals.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless assignment to variable "lon".

See more on https://sonarcloud.io/project/issues?id=vallabhatech_CareSync&issues=AZ-jvoTrKxuH45haSWfY&open=AZ-jvoTrKxuH45haSWfY&pullRequest=336

Check warning on line 16 in server/routes/hospitals.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the declaration of the unused 'lat' variable.

See more on https://sonarcloud.io/project/issues?id=vallabhatech_CareSync&issues=AZ-jvoTrKxuH45haSWfV&open=AZ-jvoTrKxuH45haSWfV&pullRequest=336

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;
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -346,6 +347,7 @@ function App() {
<Route path="/clinics-nearby" element={<ClinicsNearby />} />
<Route path="/dosage-calculator" element={<DosageCalculator />} />
<Route path="/health-metrics" element={<HealthMetrics />} />
<Route path="/hospitals" element={<HospitalFinder />} />
<Route path="/settings" element={<Settings />} />
<Route path="/login" element={<Login />} />
<Route path="/profile" element={<Profile />} />
Expand Down
117 changes: 117 additions & 0 deletions src/pages/HospitalFinder.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<Container maxWidth="lg" sx={{ mt: 4, mb: 8 }}>
<Box sx={{ display: 'flex', alignItems: 'center', mb: 4 }}>
<HospitalIcon sx={{ fontSize: 40, mr: 2, color: 'primary.main' }} />
<Typography variant="h4" fontWeight={700}>
Hospital & Bed Availability
</Typography>
</Box>

<Box component="form" onSubmit={handleSearch} sx={{ display: 'flex', gap: 2, mb: 4 }}>
<TextField
fullWidth
label="Search by name or specialty..."
variant="outlined"
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
<Button variant="contained" color="primary" type="submit" startIcon={<SearchIcon />} sx={{ px: 4 }}>
Search
</Button>
</Box>

{error && <Typography color="error">{error}</Typography>}

{loading ? (
<Box display="flex" justifyContent="center" mt={4}>
<CircularProgress />
</Box>
) : (
<Grid container spacing={4}>
{hospitals.map((hospital) => (
<Grid item xs={12} md={6} key={hospital.id}>
<Card sx={{ boxShadow: 3, '&:hover': { boxShadow: 6 } }}>
<CardContent>
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start' }}>
<Typography variant="h6" fontWeight={700} color="primary.main" gutterBottom>
{hospital.name}
</Typography>
<Chip
label={`${hospital.availableBeds} Beds Available`}
color={hospital.availableBeds > 10 ? 'success' : hospital.availableBeds > 0 ? 'warning' : 'error'}

Check warning on line 86 in src/pages/HospitalFinder.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=vallabhatech_CareSync&issues=AZ-jvoZrKxuH45haSWfZ&open=AZ-jvoZrKxuH45haSWfZ&pullRequest=336
size="small"
sx={{ fontWeight: 'bold' }}
/>
</Box>
<Typography variant="body2" color="text.secondary" gutterBottom>
{hospital.address}
</Typography>
<Typography variant="body2" sx={{ mt: 1 }}>
<strong>Specialty:</strong> {hospital.specialty}
</Typography>
<Button variant="outlined" color="primary" sx={{ mt: 2 }} fullWidth>
Contact Hospital
</Button>
</CardContent>
</Card>
</Grid>
))}
{hospitals.length === 0 && (
<Grid item xs={12}>
<Typography variant="body1" align="center" color="text.secondary">
No hospitals found matching your criteria.
</Typography>
</Grid>
)}
</Grid>
)}
</Container>
);
}

export default HospitalFinder;
Loading