Skip to content

Commit

Permalink
feat: integration with payment after booking added
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmadHoseiny committed Nov 8, 2023
1 parent 3765cf6 commit b8c07b4
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 29 deletions.
4 changes: 2 additions & 2 deletions client/src/pages/Doctors/DoctorCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import DoctorIcon from '../../assets/images/icons/DoctorIcon.png';
import { calcPrice } from '../../utils/PriceCalculator.js';


const DoctorCard = ({ doctor, setSelectedDoctor }) => {
const price = calcPrice(doctor.hourlyRate);
const DoctorCard = ({ doctor, setSelectedDoctor, loggedInPatientHealthPackage }) => {
const price = calcPrice(doctor.hourlyRate, loggedInPatientHealthPackage.doctorDiscount);
return (
<ListItemButton onClick={() => setSelectedDoctor(doctor)}>
<ListItemAvatar sx={{ paddingRight: '2%' }}>
Expand Down
8 changes: 6 additions & 2 deletions client/src/pages/Doctors/DoctorDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import DoctorDetailsAppointmentsList from './DoctorDetailsAppointmentsList.js';



const DoctorDetails = ({ selectedDoctor, handleDialogClose, loggedInPatient }) => {
const DoctorDetails = ({ selectedDoctor, handleDialogClose, loggedInPatient, loggedInPatientHealthPackage }) => {
return (
<Dialog
open={selectedDoctor}
Expand All @@ -27,10 +27,14 @@ const DoctorDetails = ({ selectedDoctor, handleDialogClose, loggedInPatient }) =
</DialogTitle>

<DialogContent>
<DoctorDetailsHeader selectedDoctor={selectedDoctor} />
<DoctorDetailsHeader
selectedDoctor={selectedDoctor}
loggedInPatientHealthPackage={loggedInPatientHealthPackage}
/>
<DoctorDetailsAppointmentsList
selectedDoctor={selectedDoctor}
loggedInPatient={loggedInPatient}
loggedInPatientHealthPackage={loggedInPatientHealthPackage}
/>
</DialogContent>

Expand Down
33 changes: 15 additions & 18 deletions client/src/pages/Doctors/DoctorDetailsAppointmentsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import {
Autocomplete,
TextField
} from '@mui/material';
import { doctorAxios } from 'pages/utilities/AxiosConfig';
import Swal from 'sweetalert2';
import '../../assets/css/swalStyle.css';

import { getDay, getTime } from '../../utils/DateFormatter.js';

import { calcPrice } from '../../utils/PriceCalculator.js';
// to be uncommented after merge
// import { choosePayment } from '../../utils/PaymentOptions';

const DoctorDetailsAppointmentsCard = ({
selectedDoctor,
availableSlotsIdx,
loggedInPatient
}) => {
loggedInPatient,
loggedInPatientHealthPackage
}
) => {
const { availableSlots } = selectedDoctor;
const slot = availableSlots[availableSlotsIdx];

Expand All @@ -38,6 +40,7 @@ const DoctorDetailsAppointmentsCard = ({
setAllFamilyMembers(familyMembers);
});


const handleExpand = () => {
setExpanded(oldExpanded => !oldExpanded);
};
Expand All @@ -55,7 +58,7 @@ const DoctorDetailsAppointmentsCard = ({
// patientName: (to be filled in later)
doctorName: selectedDoctor.userData.name,
date: slot.from,
status: 'pending',
status: 'Incomplete',
type: 'appointment',
availableSlotsIdx
};
Expand All @@ -66,18 +69,12 @@ const DoctorDetailsAppointmentsCard = ({
appointment.patientId = loggedInPatient.familyMembers[selectedMember.index].id;
appointment.patientName = loggedInPatient.familyMembers[selectedMember.index].name;
}
await doctorAxios
.post('/appointments', appointment)
.then(() => {
Swal.fire(
'Appointment Booked!',
'Your appointment has been booked successfully!',
'success'
);
})
.catch((error) => {
console.log(error);
});

const price = calcPrice(selectedDoctor.hourlyRate, loggedInPatientHealthPackage.doctorDiscount);
console.log(price);
// to be uncommented after merge
// choosePayment(appointment, price, 'appointment');

};
return(
<>
Expand Down
3 changes: 2 additions & 1 deletion client/src/pages/Doctors/DoctorDetailsAppointmentsList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Grid, Typography } from '@mui/material';
import DoctorDetailsAppointmentsCard from './DoctorDetailsAppointmentsCard';

const DoctorDetailsAppointmentsList = ({ selectedDoctor, loggedInPatient }) => {
const DoctorDetailsAppointmentsList = ({ selectedDoctor, loggedInPatient, loggedInPatientHealthPackage }) => {
const { availableSlots } = selectedDoctor;
return (
<>
Expand All @@ -15,6 +15,7 @@ const DoctorDetailsAppointmentsList = ({ selectedDoctor, loggedInPatient }) => {
selectedDoctor={selectedDoctor}
availableSlotsIdx={index}
loggedInPatient={loggedInPatient}
loggedInPatientHealthPackage={loggedInPatientHealthPackage}
/>
</Grid>
))}
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/Doctors/DoctorDetailsHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import WorkIcon from '@mui/icons-material/Work';
import SchoolIcon from '@mui/icons-material/School';
import AttachMoneyIcon from '@mui/icons-material/AttachMoney';

const DoctorDetailsHeader = ({ selectedDoctor }) => {
const DoctorDetailsHeader = ({ selectedDoctor, loggedInPatientHealthPackage }) => {
return (
<>
<div
Expand Down Expand Up @@ -46,7 +46,7 @@ const DoctorDetailsHeader = ({ selectedDoctor }) => {
<div style={{ display: 'flex', alignItems: 'center', flexDirection: 'row' }}>
<AttachMoneyIcon style={{ marginRight: '0.4em' }}/>
<Typography variant='body1'>
{`${calcPrice(selectedDoctor.hourlyRate)}`}
{`${calcPrice(selectedDoctor.hourlyRate, loggedInPatientHealthPackage.doctorDiscount)}`}
</Typography>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion client/src/pages/Doctors/DoctorList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { List } from '@mui/material';
import DoctorCard from './DoctorCard.js';

const DoctorList = ({ doctors, setSelectedDoctor }) => {
const DoctorList = ({ doctors, setSelectedDoctor, loggedInPatientHealthPackage }) => {
return (
<List>
{Array.isArray(doctors) &&
Expand All @@ -12,6 +12,7 @@ const DoctorList = ({ doctors, setSelectedDoctor }) => {
<DoctorCard
doctor={doctor}
setSelectedDoctor={setSelectedDoctor}
loggedInPatientHealthPackage={loggedInPatientHealthPackage}
></DoctorCard>
</div>
</div>
Expand Down
26 changes: 26 additions & 0 deletions client/src/pages/Doctors/Doctors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Doctors = () => {
const [selectedDoctor, setSelectedDoctor] = useState(null);
const [originalDoctors, setOriginalDoctors] = useState([]);
const [loggedInPatient, setLoggedInPatient] = useState(null);
const [loggedInPatientHealthPackage, setLoggedInPatientHealthPackage] = useState(null);
const { filterData, updateFilter } = useFilter();
const { searchQuery } = useSearch();
const specialities = [];
Expand Down Expand Up @@ -105,16 +106,41 @@ const Doctors = () => {
});
}, []);

useEffect(() => {
setLoggedInPatientHealthPackage({
doctorDiscount: '0.2'
});

// to be uncommented after merge
// patientAxios
// .get(`/patient/${patientID}/health-packages`)
// .then((response) => {
// let healthPackage = {
// doctorDiscount: '0'
// };
// const healthPackages = response.data.healthPackages;
// if(healthPackages.length){
// healthPackage = healthPackages[0];
// }
// setLoggedInPatientHealthPackage(healthPackage);
// })
// .catch((error) => {
// console.log(error);
// });
}, []);

return (
<MainCard title='Doctors'>
<DoctorList
doctors={doctors}
setSelectedDoctor={setSelectedDoctor}
loggedInPatientHealthPackage={loggedInPatientHealthPackage}
/>
<DoctorDetails
selectedDoctor={selectedDoctor}
handleDialogClose={handleDialogClose}
loggedInPatient={loggedInPatient}
loggedInPatientHealthPackage={loggedInPatientHealthPackage}
/>
</MainCard>
);
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/Constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const CLINIC_BASE_URL = 'http://localhost:8001';
export const PATIENT_BASE_URL = 'http://localhost:8002';
export const PHARMACY_BASE_URL = 'http://localhost:8003';
const APPOINTMENT_STATUS = ['COMPLETE', 'INCOMPLETE', 'CANCELLED', 'PENDING', 'RESCHEDULED', 'ACTIVE'];
const APPOINTMENT_STATUS = ['COMPLETE', 'INCOMPLETE', 'CANCELLED', 'RESCHEDULED'];
const APPOINTMENT_CHRONOLGY = ['UPCOMING', 'PAST'];
export const DATE_FILTER_ARRAY = ['Last week', 'Last month', 'Last year'];

Expand Down
3 changes: 1 addition & 2 deletions client/src/utils/PriceCalculator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const calcPrice = (price) => {
const userDiscount = 0.2; // needs user to get the id to get the discount
export const calcPrice = (price, userDiscount) => {
const priceWithDiscount = price * (1 - userDiscount);
const final = 1.1 * priceWithDiscount;
return final.toFixed(2);
Expand Down

0 comments on commit b8c07b4

Please sign in to comment.