diff --git a/backend/Controllers/doctorController.js b/backend/Controllers/doctorController.js
index 0fbcb67..6a2d032 100644
--- a/backend/Controllers/doctorController.js
+++ b/backend/Controllers/doctorController.js
@@ -69,7 +69,7 @@ exports.selectPatient = async (req, res) => {
};
exports.viewAllPatients = async (req, res) => {
- const doctorUsername = req.user.username; //modifed to be used in scedule follow up
+ const doctorUsername = req.user.username; //modifed to be used in scedule follow up
try {
const doctor = await Doctor.findOne({ username: doctorUsername }).populate('registeredPatients');
res.status(200).send(doctor.registeredPatients);
@@ -170,43 +170,41 @@ exports.filterDoctors = async (req, res) => {
}
};
- //-------------- SPRINT 2 -------------------
-
- exports.addAvailableSlot = async (req, res) => {
-
- try {
-
- const {slotDate} = req.query;
-
- if(!slotDate) return res.status(400).json({ message: 'Enter the slot time and date.'});
-
- if(slotDate < new Date()) res.status(400).json({ message: 'Date and time has already passed.'});
-
- const doctor = await Doctor.findOneAndUpdate(
- { username: req.user.username },
- {$pull: { availableSlots: { $lt: new Date() } }},
- { new: true }
- );
-
- const updatedDoctor = await Doctor.updateOne({ username: req.user.username }, { $addToSet: { availableSlots: slotDate } });
-
- res.status(200).json(updatedDoctor);
- } catch (error) {
- res.status(500).json({ message: error.message });
- }
- };
-
- exports.viewDoctorAppointments = async (req,res) => {
-
- try{
- const appointments = await Appointment.find({doctor: req.user.username}).exec();
- filterAppointments(req, res, appointments);
-
- } catch(err){
- res.status(500).json({ message: err.message });
- }
- };
+//-------------- SPRINT 2 -------------------
+
+exports.addAvailableSlot = async (req, res) => {
+ try {
+ const { slotDate } = req.query;
+
+ if (!slotDate) return res.status(400).json({ message: 'Enter the slot time and date.' });
+
+ if (slotDate < new Date()) res.status(400).json({ message: 'Date and time has already passed.' });
+
+ const doctor = await Doctor.findOneAndUpdate(
+ { username: req.user.username },
+ { $pull: { availableSlots: { $lt: new Date() } } },
+ { new: true }
+ );
+
+ const updatedDoctor = await Doctor.updateOne(
+ { username: req.user.username },
+ { $addToSet: { availableSlots: slotDate } }
+ );
+
+ res.status(200).json(updatedDoctor);
+ } catch (error) {
+ res.status(500).json({ message: error.message });
+ }
+};
+exports.viewDoctorAppointments = async (req, res) => {
+ try {
+ const appointments = await Appointment.find({ doctor: req.user.username }).exec();
+ filterAppointments(req, res, appointments);
+ } catch (err) {
+ res.status(500).json({ message: err.message });
+ }
+};
exports.acceptContract = async (req, res) => {
try {
@@ -237,22 +235,23 @@ exports.acceptContract = async (req, res) => {
};
exports.addAvailableSlot = async (req, res) => {
-
try {
+ const { slotDate } = req.query;
- const {slotDate} = req.query;
-
- if(!slotDate) return res.status(400).json({ message: 'Enter the slot time and date.'});
+ if (!slotDate) return res.status(400).json({ message: 'Enter the slot time and date.' });
- if(slotDate < new Date()) res.status(400).json({ message: 'Date and time has already passed.'});
+ if (slotDate < new Date()) res.status(400).json({ message: 'Date and time has already passed.' });
const doctor = await Doctor.findOneAndUpdate(
{ username: req.user.username },
- {$pull: { availableSlots: { $lt: new Date() } }},
+ { $pull: { availableSlots: { $lt: new Date() } } },
{ new: true }
);
- const updatedDoctor = await Doctor.updateOne({ username: req.user.username }, { $addToSet: { availableSlots: slotDate } });
+ const updatedDoctor = await Doctor.updateOne(
+ { username: req.user.username },
+ { $addToSet: { availableSlots: slotDate } }
+ );
res.status(200).json(updatedDoctor);
} catch (error) {
@@ -262,7 +261,6 @@ exports.addAvailableSlot = async (req, res) => {
exports.scheduleFollowUp = async (req, res) => {
try {
-
const { patientId, dateTime } = req.body;
const [date, time] = dateTime.split('T');
@@ -270,7 +268,7 @@ exports.scheduleFollowUp = async (req, res) => {
const doctorId = req.user._id;
// Use populate to get the registered patients' data
-
+
const doctor = await Doctor.findById(doctorId);
const registeredPatients = await doctor.populate('registeredPatients');
@@ -280,7 +278,6 @@ exports.scheduleFollowUp = async (req, res) => {
return res.status(404).json({ error: 'Doctor not found' });
}
-
// Find the patient by id
const patient = await Patient.findById(patientId);
@@ -290,9 +287,7 @@ exports.scheduleFollowUp = async (req, res) => {
}
// Check if patient is registered with the doctor
- const isPatientRegistered = doctor.registeredPatients.some(
- (registeredPatient) => registeredPatient.id === patientId
- );
+ const isPatientRegistered = doctor.registeredPatients.some(registeredPatient => registeredPatient.id === patientId);
if (!isPatientRegistered) {
return res.status(404).json({ error: 'Patient not registered with this doctor' });
@@ -305,7 +300,6 @@ exports.scheduleFollowUp = async (req, res) => {
date: date,
time: time,
status: 'upcoming',
-
});
//remove the slot from available slots TODO
const updatedDoctor = await Doctor.findOneAndUpdate(
@@ -338,7 +332,7 @@ exports.viewAvailableSlots = async (req, res) => {
exports.getPatientMedicalHistory = async (req, res) => {
try {
- const {patientId} = req.query;
+ const { patientId } = req.query;
const patient = await Patient.findById(patientId);
@@ -354,3 +348,18 @@ exports.getPatientMedicalHistory = async (req, res) => {
res.status(500).json({ message: 'Error fetching medical history' });
}
};
+
+exports.viewAllPrescriptionsByDoctor = async (req, res) => {
+ try {
+ // Find the doctor
+ const doctorId = req.user._id;
+
+ // Find all prescriptions made by the doctor
+ const prescriptions = await Prescription.find({ doctor: doctorId });
+
+ res.status(200).json({ success: true, prescriptions });
+ } catch (error) {
+ console.error('Error fetching prescriptions:', error);
+ res.status(500).json({ success: false, message: 'Internal server error' });
+ }
+};
diff --git a/backend/Controllers/patientController.js b/backend/Controllers/patientController.js
index 50142e7..c751ef0 100644
--- a/backend/Controllers/patientController.js
+++ b/backend/Controllers/patientController.js
@@ -124,9 +124,11 @@ exports.viewAllPatients = async (req, res) => {
exports.getAllPrescriptionsForPatient = async (req, res) => {
try {
- const username = req.query.username;
- const patient = await Patient.findOne({ username: username });
- const patientId = patient.id;
+ const patientId = req.user._id;
+ const patient = await Patient.findById(patientId);
+ if (!patient) {
+ return res.status(404).json({ message: 'Patient not found' });
+ }
const prescriptions = await Prescription.find({ patient: patientId }).populate('doctor');
diff --git a/backend/Routes/doctorRoutes.js b/backend/Routes/doctorRoutes.js
index 31ce887..0e920e9 100644
--- a/backend/Routes/doctorRoutes.js
+++ b/backend/Routes/doctorRoutes.js
@@ -8,7 +8,9 @@ router.route('/register').post(doctorController.registerDoctor);
router.route('/updateDoctor').put(doctorController.updateDoctor);
-router.route('/viewPatients').get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.viewAllPatients);
+router
+ .route('/viewPatients')
+ .get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.viewAllPatients);
router.route('/searchPatientsByName').get(authMiddlewares.protect, doctorController.searchPatientsByName);
@@ -16,24 +18,42 @@ router.route('/selectPatient').get(doctorController.selectPatient);
router.route('/doctordetails/:username').get(doctorController.viewDoctorDetails);
-router.route('/viewAllDoctors').get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor', 'patient'), doctorController.viewAllDoctors);
+router
+ .route('/viewAllDoctors')
+ .get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor', 'patient'), doctorController.viewAllDoctors);
router.route('/viewPatientInfo').get(doctorController.viewPatientInfo);
router.route('/filterDoctors').get(doctorController.filterDoctors);
-router.route('/addAvailableSlot').put(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.addAvailableSlot);
+router
+ .route('/addAvailableSlot')
+ .put(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.addAvailableSlot);
-router.route('/viewDoctorAppointments').get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.viewDoctorAppointments);
+router
+ .route('/viewDoctorAppointments')
+ .get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.viewDoctorAppointments);
router.route('/acceptContract').put(doctorController.acceptContract);
-router.route('/scheduleFollowUp').put(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.scheduleFollowUp);
+router
+ .route('/scheduleFollowUp')
+ .put(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.scheduleFollowUp);
-router.route('/viewAvailableSlots').get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.viewAvailableSlots);
+router
+ .route('/viewAvailableSlots')
+ .get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.viewAvailableSlots);
-router.route('/addAvailableSlot').put(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.addAvailableSlot);
+router
+ .route('/addAvailableSlot')
+ .put(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.addAvailableSlot);
-router.route('/getPatientMedicalHistory').get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.getPatientMedicalHistory);
+router
+ .route('/getPatientMedicalHistory')
+ .get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.getPatientMedicalHistory);
+
+router
+ .route('/viewAllPrescriptionsByDoctor')
+ .get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'), doctorController.viewAllPrescriptionsByDoctor);
module.exports = router;
diff --git a/backend/Routes/patientRoutes.js b/backend/Routes/patientRoutes.js
index 6fc72dc..4d30c99 100644
--- a/backend/Routes/patientRoutes.js
+++ b/backend/Routes/patientRoutes.js
@@ -7,7 +7,9 @@ const { protect, restrictTo } = require('../Middlewares/authMiddlewares');
const router = express.Router();
router.route('/register').post(patientController.registerPatient);
-router.route('/getAllPrescriptionsForPatient').get(patientController.getAllPrescriptionsForPatient);
+router
+ .route('/getAllPrescriptionsForPatient')
+ .get(protect, restrictTo('patient'), patientController.getAllPrescriptionsForPatient);
router.route('/getPrescriptionById').get(patientController.getPrescriptionById);
router.route('/filterPrescriptions').get(patientController.filterPrescriptions);
router.route('/viewDoctors/:username').get(patientController.viewAllDoctors);
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 0f0b24a..0ee0f45 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -37,6 +37,8 @@ import MedicalHistoryViewer from "./components/MedicalHistoryViewer";
import MedicalHistoryDoctorViewer from "./components/MedicalHistoryDoctorViewer";
import "./App.css";
import ScheduleFollowUpForm from "./components/ScheduleFollowUp";
+import ViewDoctorPrescriptions from "./components/ViewDoctorPrescriptions";
+import ViewPatientPrescription from "./components/ViewPatientPrescription";
function App() {
return (
@@ -103,6 +105,17 @@ function App() {
element={
Loading...
; + } + + if (error) { + returnError: {error}
; + } return (| Date | -Status | -
|---|---|
| - - | -{prescription.filled ? "Filled" : "Not Filled"} | -
Loading...
; + } + + if (error) { + returnError: {error}
; + } + + return ( +Loading...
; + } + + if (error) { + returnError: {error}
; + } + + return ( +