Skip to content

Commit 38e8d71

Browse files
committed
Patient tab information now being read realtime
1 parent 01a0d7c commit 38e8d71

File tree

12 files changed

+1082
-495
lines changed

12 files changed

+1082
-495
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/Healvista--hospital-management-system.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

back_end/.env

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PORT=5000
2-
DB_USER=sa
3-
DB_PASSWORD=hammad123
4-
DB_SERVER=DESKTOP-C0O50OH
5-
DB_DATABASE=Healvista
2+
DB_USER=ta
3+
DB_PASSWORD=12345678
4+
DB_SERVER=localhost
5+
DB_DATABASE=HMS

back_end/config/db.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const config = {
1414
};
1515

1616
sql.connect(config)
17-
.then(() => console.log('✅ MSSQL Connected'))
18-
.catch(err => console.error('❌ DB Connection Failed', err));
17+
.then(() => console.log('✅ MSSQL Connected'))
18+
.catch(err => console.error('❌ DB Connection Failed', err));
1919

2020
module.exports = sql;
21+
22+

back_end/controller/patientController.js

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,72 @@
11
const sql = require('mssql');
22

3-
const createPatient = async (req, res) => {
4-
const { full_name, date_of_birth, gender, contact_info } = req.body;
5-
3+
// Get total number of patients
4+
exports.getTotalPatientsCount = async (req, res) => {
65
try {
7-
const request = new sql.Request();
8-
request.input('full_name', sql.VarChar(100), full_name);
9-
request.input('date_of_birth', sql.Date, date_of_birth);
10-
request.input('gender', sql.VarChar(10), gender);
11-
request.input('contact_info', sql.VarChar(255), contact_info);
12-
13-
const result = await request.query(`
14-
INSERT INTO Patients (full_name, date_of_birth, gender, contact_info)
15-
OUTPUT INSERTED.patient_id
16-
VALUES (@full_name, @date_of_birth, @gender, @contact_info)
17-
`);
18-
19-
res.status(201).json({
20-
patient_id: result.recordset[0].patient_id
21-
});
6+
const result = await sql.query`SELECT COUNT(*) AS total FROM Patients`;
7+
res.status(200).json({ total: result.recordset[0].total });
228
} catch (err) {
23-
console.error('Database error:', err);
24-
res.status(500).json({ message: 'Error creating patient', error: err.message });
9+
console.error("Error fetching total patient count:", err);
10+
res.status(500).json({ error: 'Failed to fetch patient count' });
11+
}
12+
};
13+
14+
// Get patients admitted today
15+
exports.getTodayAdmittedPatients = async (req, res) => {
16+
try {
17+
const today = new Date().toISOString().split('T')[0]; // 'YYYY-MM-DD'
18+
const result = await sql.query`
19+
SELECT COUNT(*) AS admittedToday
20+
FROM patients
21+
WHERE CONVERT(date, registration_date) = ${today}
22+
`;
23+
res.json({ admittedToday: result.recordset[0].admittedToday });
24+
} catch (err) {
25+
console.error('Error fetching today\'s admitted patients:', err.message);
26+
res.status(500).json({ error: err.message });
27+
}
28+
};
29+
// Get number of critical patients
30+
exports.getCriticalPatientsCount = async (req, res) => {
31+
try {
32+
const result = await sql.query`
33+
SELECT COUNT(*) AS criticalCount
34+
FROM patients
35+
WHERE status = 'Critical'
36+
`;
37+
res.json({ criticalCount: result.recordset[0].criticalCount });
38+
} catch (err) {
39+
console.error('Error fetching critical patients count:', err.message);
40+
res.status(500).json({ error: err.message });
41+
}
42+
};
43+
// Get all patients
44+
exports.getAllPatients = async (req, res) => {
45+
try {
46+
const result = await sql.query`
47+
SELECT
48+
patient_id,
49+
full_name,
50+
CONVERT(date, date_of_birth) AS date_of_birth,
51+
gender,
52+
CONVERT(date, registration_date) AS admissionDate,
53+
status,
54+
diagnosis,
55+
room
56+
FROM Patients;
57+
`;
58+
59+
// Format date fields in JavaScript
60+
const formattedPatients = result.recordset.map(patient => ({
61+
...patient,
62+
date_of_birth: patient.date_of_birth?.toISOString().split('T')[0],
63+
admissionDate: patient.admissionDate?.toISOString().split('T')[0]
64+
}));
65+
66+
res.status(200).json(formattedPatients);
67+
} catch (err) {
68+
console.error('Error fetching patients:', err.message);
69+
res.status(500).json({ error: 'Failed to fetch patients' });
2570
}
2671
};
2772

28-
module.exports = { createPatient };

back_end/routes/patient_routes.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const patientController = require('../controller/patientController');
4+
5+
// Get total patient count
6+
router.get('/stats/total', patientController.getTotalPatientsCount);
7+
8+
// Get patients admitted today
9+
router.get('/stats/today', patientController.getTodayAdmittedPatients);
10+
11+
router.get('/stats/critical', patientController.getCriticalPatientsCount);
12+
13+
// Get all patients
14+
router.get('/', patientController.getAllPatients);
15+
16+
17+
module.exports = router;

back_end/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const app = express();
88
app.use(cors());
99
app.use(express.json());
1010

11-
const patientRoutes = require('./routes/patientRoutes');
11+
1212
const pharmacyRoutes = require('./routes/pharmacy_routes');
1313
const labRoutes = require('./routes/lab_routes');
1414
const doctorRoutes = require('./routes/doctorRoutes');
@@ -18,8 +18,8 @@ app.use('/api/pharmacy', pharmacyRoutes);
1818
app.use('/api/lab', labRoutes);
1919
app.use('/api/doctors', doctorRoutes);
2020
app.use('/api/appointments', appointmentRoutes);
21+
const patientRoutes = require('./routes/patient_routes');
2122
app.use('/api/patients', patientRoutes);
22-
2323
app.get('/', (req, res) => {
2424
res.send("🚀 Healvista Backend Running");
2525
});

0 commit comments

Comments
 (0)