Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new health record. #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions backend/Controllers/doctorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ exports.acceptContract = async (req, res) => {
}
};

exports.addHealthRecord = async (req, res) => {
try {
const patientUsername = req.body.patientUsername;
const patient = await Patient.findOne({ username: patientUsername });

const medicines = req.body.medicines.map(medicine => ({
name: medicine.name,
dosage: medicine.dosage,
duration: medicine.duration,
}));

const newHealthRecord = await new Prescription({
patient: patient,
doctor: req.user,
medicines: medicines,
notes: req.body.notes,
filled: req.body.filled,
}).save();

res.status(201).json(newHealthRecord);
} catch (error) {
res.status(500).json({ message: error.message });
}
};

exports.addAvailableSlot = async (req, res) => {

try {
Expand Down
2 changes: 2 additions & 0 deletions backend/Routes/doctorRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ router.route('/viewDoctorAppointments').get(authMiddlewares.protect, authMiddlew

router.route('/acceptContract').put(doctorController.acceptContract);

router.route('/addHealthRecord').post(protect, restrictTo('doctor'), doctorController.addHealthRecord);

router.route('/scheduleFollowUp').put(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.scheduleFollowUp);

router.route('/viewAvailableSlots').get(authMiddlewares.protect, authMiddlewares.restrictTo('doctor'),doctorController.viewAvailableSlots);
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import AddTimeSlot from "./components/AddTimeSlot";
import ViewAvailableAppointments from "./components/ViewAvailableAppointments";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import HealthPackages from "./components/HealthPackages";
import Contract from "./components/Contract";
import SubscribeHealthPackages from "./components/SubscribeHealthPackages";
import AddHealthRecord from "./components/AddHealthRecord";
import VerifyOTP from "./components/VerifyOTP";
import ForgetPassword from "./components/ForgetPassword";
import ResetPassword from "./components/ResetPassword";
Expand Down Expand Up @@ -88,6 +91,8 @@ function App() {
element={<MedicalHistoryDoctorViewer />}
/>
<Route path="/patients/home" element={<PatientHome />} />
<Route path="/doctors/AddHealthRecord" element={<AddHealthRecord />} />

<Route
path="/patients/view-all-patient-appointments"
element={<ViewAllPatientAppointments />}
Expand Down
83 changes: 83 additions & 0 deletions frontend/src/components/AddHealthRecord.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { useState } from "react";
import axios from "axios";

const AddHealthRecordForm = () => {
const [patientUsername, setPatientUsername] = useState('');
const [medicineName, setMedicineName] = useState('');
const [dosage, setDosage] = useState('');
const [duration, setDuration] = useState('');
const [notes, setNotes] = useState('');
const [filled, setFilled] = useState(true);
const [msg, setMsg] = useState('');

const handleAddHealthRecord = async (e) => {
e.preventDefault();
try {
const response = await axios.post('http://localhost:8000/api/v1/doctors/addHealthRecord',
{
patientUsername: patientUsername,
medicines: [
{
name: medicineName,
dosage: dosage,
duration: duration,
},
],
notes: notes,
filled: filled},
{ withCredentials: true });
setPatientUsername(patientUsername);
setMedicineName(medicineName);
setDosage(dosage);
setDuration(duration);
setNotes(notes);
setFilled(filled);
const newHealthRecord = response.data;
console.log('Health Record added successfully:', newHealthRecord);
setMsg('Health Record added successfully!');
} catch (error) {
console.error('Error:', error.message);
}
};

return (
<div>
<h2>Add Health Record</h2>
<label>
Patient UserName:
<input type="text" value={patientUsername} onChange={(e) => setPatientUsername(e.target.value)} />
</label>
<br />
<label>
Medicine Name:
<input type="text" value={medicineName} onChange={(e) => setMedicineName(e.target.value)} />
</label>
<br />
<label>
Dosage:
<input type="text" value={dosage} onChange={(e) => setDosage(e.target.value)} />
</label>
<br />
<label>
Duration:
<input type="text" value={duration} onChange={(e) => setDuration(e.target.value)} />
</label>
<br />
<label>
Notes:
<textarea value={notes} onChange={(e) => setNotes(e.target.value)} />
</label>
<br />
<label>
Filled:
<input type="checkbox" checked={filled} onChange={() => setFilled(!filled)} />
</label>
<br />
<button onClick={handleAddHealthRecord}>Add Health Record</button>
<br />
{msg && <p>{msg}</p>}
</div>
);
};

export default AddHealthRecordForm ;
3 changes: 3 additions & 0 deletions frontend/src/components/DoctorHome.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ function DoctorHome() {
<li>
<Link to="/doctors/search">Search Patient</Link>
</li>
<li>
<Link to="/doctors/addHealthRecord">Add Health Record</Link>
</li>
<li>
<Link to="/doctors/scheduleFollowUp">Schedule Follow-Up</Link>
</li>
Expand Down