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

Commit

Permalink
#46 - Closing Medical Case (Patient/Doctor) (#189)
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
MilitsaB committed Apr 13, 2022
1 parent f0a6ab3 commit 6d67f54
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cypress/integration/protect-together/medical.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ describe('Sprint 4 Medical Suite', () => {
cy.visit('/')
cy.contains('Patient 2').click()
cy.contains('Close Patient\'s File').click()
cy.contains('delete patient')
cy.contains('Keep Patient\'s File')
cy.contains('Close Patient\'s File')
})
it('View Appointments', () => {
cy.visit('/')
Expand Down
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ admin.initializeApp();

export {getDoctorAvailabilities, bookAppointment, enablePatientAppointment, cancelAppointment} from "./booking";
export {sendNotification, sendNotificationForConversation} from "./notifications";
export {requestDoctor, dispatchDoctor} from "./triage";
export {requestDoctor, dispatchDoctor, closePatientFile} from "./triage";


// // Start writing Firebase Functions
Expand Down
15 changes: 15 additions & 0 deletions functions/src/triage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ export const requestDoctor = functions.https.onCall(async (_data, context)=>{
return null;
}
});

export const closePatientFile = functions.https.onCall(async (_data) => {
const userId = _data.userId;
const userRef = db.doc(`users/${userId}`);
const userSnap = await userRef.get();
const FieldValue = admin.firestore.FieldValue;

return userSnap.ref.update({
disableBook: true,
score: FieldValue.delete(),
basePoints: FieldValue.delete(),
assignedDoctor: FieldValue.delete(),
doctorName: FieldValue.delete(),
});
});
2 changes: 1 addition & 1 deletion src/components/chat/chatroom.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
}

.message{
display: inline-block;
word-break: break-word;
}

.message p{
margin-right: 5px;
margin-left: 5px;
Expand Down
9 changes: 8 additions & 1 deletion src/components/dashboard/MedicalView/MedicalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import SideBar from '../../layout/SideBar';
import MedicalDashboard from './MedicalDashboard';
import PatientInfo from './PatientInfo/PatientInfo';
import ClosePatientFile from './PatientInfo/ClosePatientFile';
import AppointmentView from './appointmentView';

function MedicalView() {
Expand Down Expand Up @@ -112,7 +113,13 @@ function MedicalView() {
>
<Box sx={modalStyle}>
{modalContent === 0 && <AppointmentView />}
{modalContent === 1 && 'delete patient'}
{modalContent === 1 && (
<ClosePatientFile
PID={patientId}
handleClose={handleClose}
goDashboard={setContentId}
/>
)}
</Box>
</Modal>
</Box>
Expand Down
120 changes: 120 additions & 0 deletions src/components/dashboard/MedicalView/PatientInfo/ClosePatientFile.tsx
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&apos;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&apos;s File
</Button>
</Box>
<Box mt={2}>
<Button
onClick={closePatient}
type="submit"
variant="contained"
color="warning"
style={{ width: '200px' }}
>
Close Patient&apos;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&apos;s file until appointment is completed.
</p>
)}
</div>
</Box>
);
}
3 changes: 2 additions & 1 deletion src/components/formLayout/FormLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { arrayUnion } from 'firebase/firestore';
import Question1 from './QuestionsDesign/Question1Layout';
import Question2 from './QuestionsDesign/Question2Layout';
import Question3 from './QuestionsDesign/Question3Layout';
Expand Down Expand Up @@ -65,7 +66,7 @@ export default function FormLayout({ changeState }: any) {
basePoints: points - symptomsPoints,
assignedDoctor: 'requestedDoctor',
initialPatientHelpFormData: userAnswers,
patientSymptoms: [{ date, userSymptoms }],
patientSymptoms: arrayUnion({ date, userSymptoms }),
})
.then(() => {
const getDoctor = Firebase.functions().httpsCallable('requestDoctor');
Expand Down

0 comments on commit 6d67f54

Please sign in to comment.