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
113 changes: 61 additions & 52 deletions backend/Controllers/doctorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -262,15 +261,14 @@ exports.addAvailableSlot = async (req, res) => {

exports.scheduleFollowUp = async (req, res) => {
try {

const { patientId, dateTime } = req.body;

const [date, time] = dateTime.split('T');

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');
Expand All @@ -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);

Expand All @@ -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' });
Expand All @@ -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(
Expand Down Expand Up @@ -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);

Expand All @@ -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' });
}
};
8 changes: 5 additions & 3 deletions backend/Controllers/patientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
36 changes: 28 additions & 8 deletions backend/Routes/doctorRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,52 @@ 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);

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;
4 changes: 3 additions & 1 deletion backend/Routes/patientRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -103,6 +105,17 @@ function App() {
element={<MedicalHistoryViewer />}
/>
</Routes>
<Routes>
<Route
path="/doctors/view-all-prescriptions"
element={<ViewDoctorPrescriptions />} />
</Routes>
<Routes>
<Route
path="/patients/view-patient-prescriptions"
element={<ViewPatientPrescription />}
/>
</Routes>
</BrowserRouter>
</>
);
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/DoctorHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ function DoctorHome() {
View Patient Medical History
</Link>
</li>
<li>
<Link to="/doctors/view-all-prescriptions">
View All Prescriptions
</Link>
</li>
<li>
<Link to="/" onClick={handleLogout}>
Logout
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/PatientHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ function PatientHome() {
<li>
<Link to="/patients/view-medical-history">View Medical History</Link>
</li>
<li>
<Link to="/patients/view-patient-prescriptions">View All Prescriptions</Link>
</li>
<li>
<Link to="/" onClick={handleLogout}>
Logout
Expand Down
Loading