Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
#20 notifications pushed at patient status updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fadi-albasha committed Mar 31, 2022
1 parent 93861d9 commit fdb5603
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 70 deletions.
14 changes: 9 additions & 5 deletions src/components/dashboard/AdminDashboard/AdminDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import React, { useState, useEffect } from 'react';
import EmojiPeopleIcon from '@mui/icons-material/EmojiPeople';
import DashboardOutlinedIcon from '@mui/icons-material/DashboardOutlined';
import PersonAddIcon from '@mui/icons-material/PersonAdd';
import {
Button,
Box,
CssBaseline,
Divider,
List,
ListItem,
ListItemIcon,
ListItemText,
Typography,
Modal,
Badge,
} from '@mui/material';
Expand All @@ -24,6 +23,7 @@ import theme from '../../../static/style/theme';
import UnassignedPatientTable from './UnassignedPatientTable';
import NotificationsMenuItem from '../../layout/NotificationsMenuItem';
import Firebase, { firestore } from '../../../config/firebase_config';
import NotificationsButton from '../../layout/NotificationsButton';

const style = {
position: 'absolute' as const,
Expand Down Expand Up @@ -97,9 +97,7 @@ function AdminDashboard() {
<Box sx={{ display: 'flex', width: '100%' }}>
<CssBaseline />
<Header title={`Welcome ${state.firstName}`} subtitle="Track and manage staff">
<Button variant="contained" color="info" onClick={handleOpen}>
Add Account
</Button>
<NotificationsButton />
</Header>
<SideBar>
<List>
Expand All @@ -117,6 +115,12 @@ function AdminDashboard() {
</ListItemIcon>
<ListItemText primary="Unassigned Patients" />
</ListItem>
<ListItem button onClick={handleOpen}>
<ListItemIcon>
<PersonAddIcon />
</ListItemIcon>
<ListItemText primary="Add Account" />
</ListItem>
<NotificationsMenuItem />
<ListItem button onClick={handleNotifyTest}>
<ListItemIcon>
Expand Down
37 changes: 3 additions & 34 deletions src/components/dashboard/MedicalView/MedicalDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,26 @@
import React from 'react';
import {
Button,
Box,
Modal,
} from '@mui/material';
import { Box } from '@mui/material';
import Header from '../../layout/Header';
import MainContent from '../../layout/MainContent';
import { UserContext } from '../../../context/UserContext';
import MedicalTable from './MedicalTable/MedicalTable';

const style = {
position: 'absolute' as const,
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: '50%',
boxShadow: 0,
margin: 0,
p: 4,
};
import NotificationsButton from '../../layout/NotificationsButton';

type Props = {
handlePatientClick: any,
};

function MedicalDashboard({ handlePatientClick }: Props) {
const [modalOpen, setModalOpen] = React.useState(false);
const handleOpen = () => setModalOpen(true);
const handleClose = () => setModalOpen(false);

const { state, update } = React.useContext(UserContext);

return (
<Box sx={{ display: 'flex', width: '100%' }}>
<Header title={`Welcome Dr. ${state.lastName}`} subtitle="Track and manage your patients">
<Button variant="contained" color="info" onClick={handleOpen}>
View Appointments
</Button>
<NotificationsButton />
</Header>
<MainContent>
<MedicalTable handlePatientClick={handlePatientClick} />
</MainContent>

<Modal
open={modalOpen}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box sx={style}>
apointments
</Box>
</Modal>
</Box>
);
}
Expand Down
54 changes: 54 additions & 0 deletions src/components/dashboard/MedicalView/MedicalView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import DashboardOutlinedIcon from '@mui/icons-material/DashboardOutlined';
import DateRangeOutlinedIcon from '@mui/icons-material/DateRangeOutlined';
import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined';
import {
Box,
CssBaseline,
Expand All @@ -8,6 +10,7 @@ import {
ListItem,
ListItemIcon,
ListItemText,
Modal,
} from '@mui/material';
import SideBar from '../../layout/SideBar';
import MedicalDashboard from './MedicalDashboard';
Expand All @@ -19,12 +22,30 @@ function MedicalView() {
// patient's into: 1
const [contentId, setContentId] = React.useState<number>(0);
const [patientId, setPatientId] = React.useState<string>('');
// modal content
// appointments: 0
// clode patient's file: 1
const [modalContent, setModalContent] = React.useState<number>(0);
const [modalOpen, setModalOpen] = React.useState(false);
const handleOpen = () => setModalOpen(true);
const handleClose = () => setModalOpen(false);

const viewPatient = ((PID: string) => {
setPatientId(PID);
setContentId(1);
});

const style = {
position: 'absolute' as const,
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: '50%',
boxShadow: 0,
margin: 0,
p: 4,
};

return (
<Box sx={{ display: 'flex', width: '100%' }}>
<CssBaseline />
Expand All @@ -40,12 +61,45 @@ function MedicalView() {
</ListItemIcon>
<ListItemText primary="Dashboard" />
</ListItem>
<ListItem
button
key="appointments"
onClick={() => { setModalContent(0); handleOpen(); }}
>
<ListItemIcon>
<DateRangeOutlinedIcon />
</ListItemIcon>
<ListItemText primary="View Appointments" />
</ListItem>
{ contentId === 1 && (
<ListItem
button
key="close"
onClick={() => { setModalContent(1); handleOpen(); }}
>
<ListItemIcon>
<CloseOutlinedIcon />
</ListItemIcon>
<ListItemText primary="Close Patient's File" />
</ListItem>
) }
</List>
<Divider />
</SideBar>
{ contentId === 0 && <MedicalDashboard handlePatientClick={viewPatient} /> }
{ contentId === 1 && <PatientInfo PID={patientId} />}

<Modal
open={modalOpen}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box sx={style}>
{modalContent === 0 && 'appointments'}
{modalContent === 1 && 'delete patient'}
</Box>
</Modal>
</Box>
);
}
Expand Down
29 changes: 6 additions & 23 deletions src/components/dashboard/MedicalView/PatientInfo/PatientInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import PatientTimeline from './PatientTimeline';
import PatientInfoList from './PatientInfoList';
import { firestore } from '../../../../config/firebase_config';
import theme from '../../../../static/style/theme';
import NotificationsButton from '../../../layout/NotificationsButton';

const style = {
position: 'absolute' as const,
Expand Down Expand Up @@ -263,29 +264,7 @@ function PatientInfo({ PID }: Props) {
title={`${patientData.name}`}
subtitle={`RAMQ ${patientData.healthCardNumber} Age: ${patientData.age} years`}
>
<Grid
container
textAlign="right"
spacing={1}
sx={{ width: { md: '520px', sm: '200px' } }}
>
<Grid
textAlign="left"
item
md={4}
sm={12}
/>
<Grid item md={4} sm={12}>
<Button sx={headerButtonStyle} variant="contained" color="warning" onClick={handleCloseFile}>
Close Patient&apos;s File
</Button>
</Grid>
<Grid item md={4} sm={12}>
<Button sx={headerButtonStyle} variant="contained" color="info" onClick={handleViewAppointments}>
View Appointments
</Button>
</Grid>
</Grid>
<NotificationsButton />
</Header>
<MainContent>
<Grid container spacing={2}>
Expand All @@ -302,6 +281,7 @@ function PatientInfo({ PID }: Props) {
</ListSubheader>
)}
>
{ patientData.latestTestResult && (
<ListItem key="Latest Covid Test">
<ListItemText
primary="Latest Covid Test"
Expand All @@ -317,7 +297,9 @@ function PatientInfo({ PID }: Props) {
)}
/>
</ListItem>
)}
<Divider variant="middle" />
{ patientData.score && (
<ListItem key="Case Severity">
<ListItemText
primary="Case Severity"
Expand All @@ -336,6 +318,7 @@ function PatientInfo({ PID }: Props) {
)}
/>
</ListItem>
)}
{extendedInfo && extendedInfo()}
</List>
<PatientInfoList
Expand Down
36 changes: 29 additions & 7 deletions src/components/dashboard/PatientView/UpdateTestResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
import { arrayUnion, doc, setDoc, Timestamp } from 'firebase/firestore';
import { DatePicker, LocalizationProvider } from '@mui/lab';
import AdapterDateFns from '@mui/lab/AdapterDateFns';
import { auth, firestore } from '../../../config/firebase_config';
import { format } from 'date-fns';
import Firebase, { auth, firestore } from '../../../config/firebase_config';

type Props = {
handleTestClose: any;
Expand All @@ -35,12 +36,33 @@ function UpdateTestResult({ handleTestClose }: Props) {
const addPatientTestResults = () => {
const uid = auth.currentUser?.uid;
const user = firestore.collection('users').doc(uid);
user.update({
testsResults: arrayUnion({
testResult,
testType,
testDate,
}),
const updatePatient = async () => {
await user.update({
testsResults: arrayUnion({
testResult,
testType,
testDate,
}),
});
};
updatePatient().then(() => {
const fetchData = async () => {
const patientDataSnapshot = await user.get();
const patient = patientDataSnapshot.data();
if (patient) {
const { assignedDoctor } = patient;
if (assignedDoctor) {
const dispatchDoctor = Firebase.functions().httpsCallable('sendNotification');
dispatchDoctor({
title: `${patient.firstName} ${patient.lastName} has updated their test results`,
message: `Tested ${testResult} using ${testType} ${testDate
? `on ${format(testDate, 'yyyy-LL-dd')}` : ''}`,
userId: assignedDoctor,
});
}
}
};
fetchData();
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export default function SymptomsUpdateResponse() {
>
<Grid item>
<Typography variant="h5" align="center">Your symptoms have been updated.</Typography>
<Typography
variant="h5"
align="center"
>
Your doctor has been notified of your symptoms&apos; update.
</Typography>
</Grid>
</Grid>
</Paper>
Expand Down
19 changes: 18 additions & 1 deletion src/components/formLayout/UpdateSymptomsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,24 @@ export default function UpdateSymptomsLayout({ changeState }: any) {

useEffect(() => {
if (symptomsDone) {
updateUserSymptoms();
updateUserSymptoms().then(() => {
const fetchData = async () => {
const patientDataSnapshot = await users.doc(state.id).get();
const patient = patientDataSnapshot.data();
if (patient) {
const { assignedDoctor } = patient;
if (assignedDoctor) {
const dispatchDoctor = Firebase.functions().httpsCallable('sendNotification');
dispatchDoctor({
title: `${patient.firstName} ${patient.lastName} has updated their symptoms`,
message: userSymptoms.join('. '),
userId: assignedDoctor,
});
}
}
};
fetchData();
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [symptomsDone]);
Expand Down

0 comments on commit fdb5603

Please sign in to comment.