This repository has been archived by the owner on May 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #46 UI changes * #46 fixed logic and UI changes * #46 Code refactoring * #46 fixed cypress test * #46 Added test * #46 Change onSnapshot to get method
- Loading branch information
Showing
7 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/components/dashboard/MedicalView/PatientInfo/ClosePatientFile.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Typography, Box, Button } from '@mui/material'; | ||
import { doc, onSnapshot } from 'firebase/firestore'; | ||
import Firebase, { firestore } from '../../../../config/firebase_config'; | ||
|
||
const style = { | ||
position: 'absolute' as const, | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
width: 400, | ||
bgcolor: 'background.paper', | ||
border: '1px solid #ff003d', | ||
boxShadow: 24, | ||
pt: 2, | ||
px: 4, | ||
pb: 3, | ||
p: 4, | ||
borderRadius: 4, | ||
}; | ||
|
||
export default function ClosePatientFile({ PID, handleClose, goDashboard }: any) { | ||
const [patientName, setPatientName] = useState(''); | ||
const [error, setError] = useState(false); | ||
let hasNextAppointment = false; | ||
const users = firestore.collection('users'); | ||
|
||
useEffect(() => { | ||
const unsubscribe = onSnapshot(doc(firestore, 'users', `${PID}`), (docu) => { | ||
const data = docu.data(); | ||
if (data) { | ||
const name = [data.firstName, data.lastName].join(' '); | ||
setPatientName(name); | ||
} | ||
}); | ||
return () => { | ||
unsubscribe(); | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const updatePatient = async () => { | ||
if (!hasNextAppointment) { | ||
const closePatientFile = Firebase.functions().httpsCallable('closePatientFile '); | ||
const userId = PID; | ||
closePatientFile({ userId }); | ||
handleClose(); | ||
goDashboard(0); | ||
}; | ||
}; | ||
|
||
const canDoctorDelete = () => { | ||
users | ||
.doc(PID).get() | ||
.then(async (snapshot) => { | ||
const data = snapshot.data(); | ||
if (data) { | ||
if (data.appointments && data.appointments.length) { | ||
const appointmentData = data?.appointments[data.appointments.length - 1]?.selectedDate; | ||
const appointmentTime = appointmentData?.toDate(); | ||
const currentDate = new Date(); | ||
if (appointmentTime > currentDate) { | ||
setError(true); | ||
hasNextAppointment = true; | ||
} | ||
} | ||
} | ||
// calls Update Patient after going through validation checks | ||
updatePatient(); | ||
}); | ||
}; | ||
|
||
const closePatient = async () => { | ||
canDoctorDelete(); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ ...style }}> | ||
<Typography variant="h6" sx={{ alignItems: 'center', textAlign: 'center' }}> | ||
Are you sure you to discharge | ||
{' '} | ||
{patientName} | ||
{' '} | ||
and close this patient's file? | ||
</Typography> | ||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}> | ||
<Box mt={2}> | ||
<Button | ||
onClick={handleClose} | ||
type="submit" | ||
variant="contained" | ||
color="secondary" | ||
style={{ width: '200px' }} | ||
> | ||
Keep Patient's File | ||
</Button> | ||
</Box> | ||
<Box mt={2}> | ||
<Button | ||
onClick={closePatient} | ||
type="submit" | ||
variant="contained" | ||
color="warning" | ||
style={{ width: '200px' }} | ||
> | ||
Close Patient's File | ||
</Button> | ||
</Box> | ||
{error && ( | ||
<p className="validationError" style={{ marginTop: '1rem', alignItems: 'center', textAlign: 'center' }}> | ||
{patientName} | ||
{' '} | ||
has upcoming appointment scheduled with you. | ||
Unable to close this patient's file until appointment is completed. | ||
</p> | ||
)} | ||
</div> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters