Skip to content

Commit

Permalink
fix: enhancing doctor's patients ui
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmadHoseiny committed Dec 16, 2023
1 parent 8abd4e6 commit 67fb8ae
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 279 deletions.
60 changes: 26 additions & 34 deletions client/src/pages/doctorPatients/DoctorListofPatients.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React, { useState, useEffect } from 'react';
import {
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Paper,
List
} from '@mui/material';
import MainCard from 'ui-component/cards/MainCard';
import PatientRow from './DoctorPatientRow';
import DoctorPatientCard from './DoctorPatientCard';
import DoctorPatientDialog from './DoctorPatientDialog';
import { useUserContext } from 'hooks/useUserContext';
import { useSearch } from 'contexts/SearchContext';
import { useFilter } from 'contexts/FilterContext';
Expand All @@ -20,6 +15,7 @@ const Patients = () => {
const [isLoading, setIsLoading] = useState(true);
const [appointments, setAppointments] = useState([]);
const [loggedInDoctor, setLoggedInDoctor] = useState(null);
const [selectedPatient, setSelectedPatient] = useState(null);
const { searchQuery } = useSearch();
const { filterData, updateFilter } = useFilter();
const { user } = useUserContext();
Expand Down Expand Up @@ -99,37 +95,33 @@ const Patients = () => {
});
}, []);

const handleDoctorPatientDetailsClose = () => {
setSelectedPatient(null);
};
return (
<MainCard title='Patients'>
{isLoading ? (
<>Loading...</>
) : (
<div>
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Email</TableCell>
<TableCell>Date of Birth</TableCell>
<TableCell>Gender</TableCell>
<TableCell>Mobile Number</TableCell>
<TableCell>Follow up</TableCell>
</TableRow>
</TableHead>
<TableBody>
{Array.isArray(patients) &&
patients.map((patient) => (
<PatientRow
key={patient._id}
patient={patient}
loggedInDoctor={loggedInDoctor}
/>
))}
</TableBody>
</Table>
</TableContainer>
</div>
<>
<List>
{Array.isArray(patients) &&
patients.map((patient, index) => (
<div key={index}>
<DoctorPatientCard
patient={patient}
setSelectedPatient={setSelectedPatient}
/>
</div>
))}
</List>
<DoctorPatientDialog
selectedPatient={selectedPatient}
handleDialogClose={handleDoctorPatientDetailsClose}
loggedInDoctor={loggedInDoctor}
setLoggedInDoctor={setLoggedInDoctor}
/>
</>
)}
</MainCard>
);
Expand Down
34 changes: 34 additions & 0 deletions client/src/pages/doctorPatients/DoctorPatientCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
ListItemButton,
ListItemText,
ListItemAvatar,
} from '@mui/material';
import DoctorIcon from '../../assets/images/icons/DoctorIcon.png';

const DoctorPatientCard = ({ patient, setSelectedPatient }) => {
const title = (patient.gender=='MALE')? 'Mr.':'Miss.';

return(
<ListItemButton onClick={() => setSelectedPatient(patient)}>
<ListItemAvatar sx={{ paddingRight: '2%' }}>
<img
src={DoctorIcon}
alt={patient.name}
width='40'
height='40'
/>
</ListItemAvatar>
<ListItemText
primary={`${title} ${patient.name}`}
secondary={patient.email}
sx={{
width: '60%',
lineHeight: '1.5em',
maxHeight: '3em',
}}
/>
</ListItemButton>
);
};

export default DoctorPatientCard;
94 changes: 94 additions & 0 deletions client/src/pages/doctorPatients/DoctorPatientDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Typography, Button } from '@mui/material';
import DoctorIcon from '../../assets/images/icons/DoctorIcon.png';
import EmailIcon from '@mui/icons-material/Email';
import PregnantWomanIcon from '@mui/icons-material/PregnantWoman';
import WcIcon from '@mui/icons-material/Wc';
import PhoneIcon from '@mui/icons-material/Phone';
import ContactEmergencyIcon from '@mui/icons-material/ContactEmergency';
import { useNavigate } from 'react-router';
import { getDay } from '../../utils/DateFormatter.js';

const DoctorPatientDetails = ({ selectedPatient }) => {
const navigate = useNavigate();
let title = '';
if(selectedPatient){
title = (selectedPatient.gender=='MALE')? 'Mr.':'Miss.';
}
return (
<>
{
selectedPatient &&
(
<>
<div
style={{
display: 'flex',
justifyContent: 'space-around',
alignItems: 'center',
flexDirection: 'row',
marginBottom: '5em',
}}
>
<div>
<img
src={DoctorIcon}
alt={`${title} ${selectedPatient.name}`}
width='100'
height='100'
/>
<Typography variant='h4' sx={{ marginTop: '1em' }}>
{`${title} ${selectedPatient.name}`}
</Typography>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.7em' }}>
<div style={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<EmailIcon style={{ marginRight: '0.4em' }}/>
<Typography variant='body1'>
{`${selectedPatient.email}`}
</Typography>
</div>
<div style={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<PregnantWomanIcon style={{ marginRight: '0.4em' }}/>
<Typography variant='body1'>
{`Born on ${getDay(selectedPatient.dateOfBirth)}`}
</Typography>
</div>
<div style={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<WcIcon style={{ marginRight: '0.4em' }}/>
<Typography variant='body1'>
{`${selectedPatient.gender}`}
</Typography>
</div>
<div style={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<PhoneIcon style={{ marginRight: '0.4em' }}/>
<Typography variant='body1'>
{`${selectedPatient.mobileNumber}`}
</Typography>
</div>
<div style={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<ContactEmergencyIcon style={{ marginRight: '0.4em' }}/>
<Typography variant='body1'>
{`${selectedPatient.emergencyContact.name} - ${selectedPatient.emergencyContact.mobile}`}
</Typography>
</div>
</div>

</div>

<div style={{ display: 'flex', justifyContent: 'center' }}>
<Button variant='outlined' sx={{ marginTop: '2%' }} onClick={() => { navigate(`/doctor/pages/profile/${selectedPatient._id}`); }}>
View Pofile
</Button>

<Button variant='outlined' sx={{ marginTop: '2%', marginLeft: '5%' }} onClick={() => { navigate(`/doctor/pages/patients/${selectedPatient._id}/prescriptions`); }}>
View Prescriptions
</Button>
</div>
</>
)
}
</>
);
};

export default DoctorPatientDetails;
76 changes: 76 additions & 0 deletions client/src/pages/doctorPatients/DoctorPatientDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState } from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
Tab,
Box,
Button
} from '@mui/material';
import TabContext from '@mui/lab/TabContext';
import TabList from '@mui/lab/TabList';
import TabPanel from '@mui/lab/TabPanel';
import DoctorPatientDetails from './DoctorPatientDetails';
import FollowUp from './FollowUp';

const DoctorPatientDialog = ({
selectedPatient,
handleDialogClose,
loggedInDoctor,
setLoggedInDoctor
}) => {
const [tabValue, setTabValue] = useState('1');
const handleTabChange = (event, newTabValue) => {
setTabValue(newTabValue);
};
const handleDialogCloseHelper = () => {
setTabValue('1');
handleDialogClose();
};
return (
<Dialog
open={selectedPatient}
onClose={handleDialogCloseHelper}
PaperProps={{
sx: {
minWidth: window.outerWidth > 800 ? 700 : 500,
height: 500
}
}}
>
<TabContext value={tabValue}>
<DialogTitle align='center' variant='h2' sx={{ marginBottom: '1em' }}>
<Box sx={{ borderBottom: 1, borderColor: 'divider' }}>
<TabList value={tabValue} onChange={handleTabChange}>
<Tab label="Patient Details" value='1' />
<Tab label="Follow Up" value='2' />
</TabList>
</Box>
</DialogTitle>
<DialogContent>
<TabPanel value='1'>
<DoctorPatientDetails
selectedPatient={selectedPatient}
/>
</TabPanel>
<TabPanel value='2'>
<FollowUp
selectedPatient={selectedPatient}
loggedInDoctor={loggedInDoctor}
setLoggedInDoctor={setLoggedInDoctor}
/>
</TabPanel>
</DialogContent>
</TabContext>

<DialogActions>
<Button onClick={handleDialogCloseHelper} color='primary'>
Close
</Button>
</DialogActions>
</Dialog>
);
};

export default DoctorPatientDialog;
75 changes: 0 additions & 75 deletions client/src/pages/doctorPatients/DoctorPatientRow.js

This file was deleted.

Loading

0 comments on commit 67fb8ae

Please sign in to comment.