Skip to content

Commit

Permalink
fix clinic errors
Browse files Browse the repository at this point in the history
  • Loading branch information
YehiaFarghaly committed Oct 14, 2023
1 parent 7c8aca5 commit 285fb28
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 68 deletions.
4 changes: 2 additions & 2 deletions authentication/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export const user = (app) => {
maxAge: ONE_DAY_MAX_AGE_IN_MILLEMIINUTS,
});
res.send({
id: logedinUser._id,
name: logedinUser.userName,
id: logedinUser.userId,
userName: logedinUser.userName,
type: logedinUser.type,
});
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"@tabler/icons": "^1.72.0",
"apexcharts": "^3.35.3",
"axios": "^1.5.1",
"dayjs": "^1.11.10",
"date-fns": "^2.30.0",
"dayjs": "^1.11.10",
"formik": "^2.2.9",
"framer-motion": "^6.3.16",
"install": "^0.13.0",
"lodash": "^4.17.21",
"material-ui-popup-state": "^4.0.1",
"npm": "^10.2.0",
"prop-types": "^15.8.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ const ProfileSection = () => {
selectedIndex === 1
}
onClick={() => {
navigate('/profile');
navigate('pages/profile');
}}
>
<ListItemIcon>
Expand Down
12 changes: 2 additions & 10 deletions client/src/layout/MainLayout/Sidebar/MenuList/menu-items/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ const pages = {
},
],
},
{
id: 'profile',
title: 'Profile',
type: 'item',
icon: icons.AccountBoxIcon,
url: '/pages/profile',
target: false,
},
{
id: 'admins',
title: 'Admins',
Expand Down Expand Up @@ -146,10 +138,10 @@ const pages = {
},
{
id: 'ListOfPatients',
title: 'ListOfPatientsRegiested',
title: 'My Patients',
type: 'item',
icon: icons.IconStethoscope,
url: '/pages/listOfPatients',
url: '/pages/my-patients',
target: false,
},
],
Expand Down
9 changes: 6 additions & 3 deletions client/src/pages/Appointment/Appointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ import { useUserContext } from 'hooks/useUserContext.js';
import { useFilter } from 'contexts/FilterContext.js';
import { APPOINTMENT_FILTER_ARRAY } from 'utils/Constants.js';
import { filterAppointmentsByDate } from 'utils/AppointmentUtils.js';
// import _ from 'lodash';

const Appointment = () => {
const [appointments, setAppointments] = useState([]);
const [appointments, setAppointments] = useState(null);
const [originalAppointments, setOriginalAppointments] = useState([]);
const [selectedAppointment, setSelectedAppointment] = useState(null);
const { filterData, updateFilter } = useFilter();
const { user } = useUserContext();
const userId = user.id;
console.log({ userId });
useEffect(() => {
clinicAxios
.get('/appointments/' + userId)
.then((response) => {
setAppointments(response.data);
setOriginalAppointments(response.data);
updateFilter(APPOINTMENT_FILTER_ARRAY);
console.log('appoitments = ', response.data);
})
.catch((error) => {
console.log(error);
Expand All @@ -42,10 +45,10 @@ const Appointment = () => {

return (
<MainCard title='Appointments'>
<AppointmentList
{appointments && <AppointmentList
appointments={appointments}
setSelectedAppointment={setSelectedAppointment}
/>
/>}
<AppointmentDetails
selectedAppointment={selectedAppointment}
handleDialogClose={handleDialogClose}
Expand Down
40 changes: 36 additions & 4 deletions client/src/pages/DoctorListofPatients.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,32 @@ import {
import MainCard from 'ui-component/cards/MainCard';
import PatientRow from './DoctorPatientRow';
import { useUserContext } from 'hooks/useUserContext';

import { useSearch } from 'contexts/SearchContext';
import { useFilter } from 'contexts/FilterContext';
import { clinicAxios } from 'utils/AxiosConfig';
const Patients = () => {
const [finalListOFPatients, setPatients] = useState([]);
const [patients, setPatients] = useState([]);
const [originalPatients, setOriginalPatients] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [appointments, setAppointments] = useState([]);
const { searchQuery } = useSearch();
const { filterData, updateFilter } = useFilter();
const { user } = useUserContext();
const id = user.id;

useEffect(() => {
clinicAxios.get(`/appointments/${id}`).then((response) => {
setAppointments(response.data);
}).catch(err => console.log(err.message));
fetch('http://localhost:8001/doctors/' + id + '/patients')
.then((response) => response.json())
.then((data) => {
setPatients(data.finalListOFPatients);
setOriginalPatients(data.finalListOFPatients);
updateFilter([{
attribute: 'Appointments',
values: ['Upcoming', 'Finished']
}]);
setIsLoading(false);
})
.catch((error) => {
Expand All @@ -30,6 +45,23 @@ const Patients = () => {
});
}, []);

const isUpcomingAppointment = (id) => {
for (let i = 0; i < appointments.length; i++) {
const appointment = appointments[i];
const currentDate = new Date();
if (appointment.date > currentDate && appointment.patientId === id) return true;
}
return false;
};

useEffect(() => {
const filteredPatients = originalPatients.filter((patient) =>
patient.name.includes(searchQuery) &&
(!filterData[0].selectedValue || filterData[0].selectedValue === 'Finished' || (filterData[0].selectedValue === 'Upcoming' && isUpcomingAppointment(patient._id)))
);
setPatients(filteredPatients);
}, [originalPatients, searchQuery, filterData]);

return (
<MainCard title='Patients'>
{isLoading ? (
Expand All @@ -48,8 +80,8 @@ const Patients = () => {
</TableRow>
</TableHead>
<TableBody>
{Array.isArray(finalListOFPatients) &&
finalListOFPatients.map((patient) => (
{Array.isArray(patients) &&
patients.map((patient) => (
<PatientRow
key={patient._id}
patient={patient}
Expand Down
24 changes: 14 additions & 10 deletions client/src/pages/DoctorPatientRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ const PatientRow = ({ patient }) => {
setPatientDetailsOpen(true);
};

// const handleClose = () => {
// setPatientDetailsOpen(false);
// console.log('close',isPatientDetailsOpen);
// };
const handleClose = () => {
console.log('here');
setPatientDetailsOpen(false);
};


return (

<>
<TableRow
key={patient._id}
hover={true}
onClick={handleOpen}
onClick={handleOpen}
sx={ { cursor: 'pointer' } }
>
<TableCell>{patient.name}</TableCell>
<TableCell>{patient.email}</TableCell>
Expand All @@ -36,14 +38,16 @@ const PatientRow = ({ patient }) => {
<TableCell>{patient.mobileNumber}</TableCell>

{/* Conditionally render the popup based on the 'open' state */}
<HealthRecordDetails
isPatientDetailsOpen={isPatientDetailsOpen}
setPatientDetailsOpen={setPatientDetailsOpen}
patient={patient}
/>



</TableRow>
<HealthRecordDetails
isPatientDetailsOpen={isPatientDetailsOpen}
handleClose={handleClose}
patient={patient}
/>
</>
);
};

Expand Down
46 changes: 21 additions & 25 deletions client/src/pages/HealthRecordDetails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
Expand All @@ -23,62 +23,58 @@ function formatHealthRecord(healthRecord) {
healthRecordString += `Health Issue: ${healthRecord.healthIssue},\nHealth Issue Date: ${formatDate(healthRecord.healthIssueDate)},\nHealth Issue Description: ${healthRecord.healthIssueDescription}\n`;
healthRecordString += '----------\n';
});

return healthRecordString;
}
function HealthRecordDetails({ isPatientDetailsOpen,setPatientDetailsOpen, patient }) {

const HealthRecordDetails = ( { isPatientDetailsOpen, handleClose, patient } ) => {

const emergencyContact = formateEmergencyContact(patient.emergencyContact);
const healthRecord = formatHealthRecord(patient.healthrecords);

console.log({ isPatientDetailsOpen });
return (
<Dialog open={isPatientDetailsOpen}
onClose={() => setPatientDetailsOpen(false)}
<Dialog
open={isPatientDetailsOpen}
onClose={handleClose}
PaperProps={{
sx: { minWidth: window.outerWidth > 800 ? 500 : 1000 },
}}>

<>
<DialogTitle>Patient Details</DialogTitle>
<DialogContent>

<DialogContentText>
<Typography variant='body2'>
Name: {patient.name}
Name: {patient.name}
</Typography>
<Typography variant='body2'>
Gender: {patient.gender}
Gender: {patient.gender}
</Typography>
<Typography variant='body2'>
mobileNumber: {patient.mobileNumber}
mobileNumber: {patient.mobileNumber}
</Typography>
<Typography variant='body2'>
dateOfBirth: {formatDate(patient.dateOfBirth)}
</Typography>
dateOfBirth: {formatDate(patient.dateOfBirth)}
</Typography>
<Typography variant='body2'>
{emergencyContact}
</Typography>

<Typography variant='body2'>
healthRecords:
healthRecords:
<pre>{healthRecord}</pre>
</Typography>

{/* Add more patient details as needed */}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={() => {setPatientDetailsOpen(false);
console.log(isPatientDetailsOpen);}} color="primary">
Close
<Button onClick={handleClose} color="primary">
Close
</Button>
{console.log('ewew',isPatientDetailsOpen)}
</DialogActions>
</>


</Dialog>
);
}
};

export default HealthRecordDetails;
2 changes: 1 addition & 1 deletion client/src/pages/family-member/FamilyMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const FamilyMembers = () => {
.then((data) => {
setFamilyMembers(data.familyMembers);
setIsLoading(false);
});
}).catch(() => setIsLoading(false));
};
fetch();
}, []);
Expand Down
6 changes: 5 additions & 1 deletion client/src/routes/MainRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ const MainRoutes = {
path: 'prescriptions',
element: <LazyPrescriptions />,
},
{
path: 'my-patients',
element: <LazyDoctorListofPatients/>
},
{
path: 'packages',
element: <LazyPackages />,
Expand All @@ -107,7 +111,7 @@ const MainRoutes = {

{
path: 'My Patients',
element: <LazyDoctorListofPatients />,
element: <lazyDoctorListofPatients />,
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion clinic/src/api/DoctorAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const doctor = (app) => {
.json({ message: 'Invalid ID' });
const deletedDoctor = await service.deleteDoctor(id);
if (deletedDoctor) {
axios.delete(`${AUTH_BASE_URL}/users/${id}`);
await axios.delete(`${AUTH_BASE_URL}/users/${id}`);

res.status(OK_STATUS_CODE).json({
message: 'doctor deleted!',
Expand Down
10 changes: 4 additions & 6 deletions clinic/src/database/repository/appointment-repository.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import AppointmentModel from '../models/Appointment.js';
import mongoose from 'mongoose';

class AppointmentRepository {
async findAppointmentsByUserId(id) {
const userID = new mongoose.Types.ObjectId(id);
const appointments = await AppointmentModel.find({
$or: [{ patientId: userID }, { doctorId: userID }],
});
return appointments;
const appointments = await AppointmentModel.find({});
return appointments.filter((appointment) =>
appointment.patientId.toString() === id.toString() || appointment.doctorId.toString() === id.toString()
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions patient/src/database/models/Patient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mongoose from 'mongoose';
import { FAMILY_RELATIONS, GENDERS } from '../../utils/Constants.js';
import { FAMILIY_EMERGENCY, GENDERS } from '../../utils/Constants.js';
import bcrypt from 'bcrypt';

const patientSchema = mongoose.Schema({
Expand Down Expand Up @@ -50,7 +50,7 @@ const patientSchema = mongoose.Schema({
relation: {
type: String,
required: true,
enum: FAMILY_RELATIONS,
enum: FAMILIY_EMERGENCY,
},
},
familyMembers: [
Expand All @@ -76,7 +76,7 @@ const patientSchema = mongoose.Schema({
},
relation: {
type: String,
enum: FAMILY_RELATIONS,
enum: FAMILIY_EMERGENCY,
required: true,
},
},
Expand Down
Loading

0 comments on commit 285fb28

Please sign in to comment.