Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion appointments/appointment-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
updateAppointmentStatus,
updateDoctorAvailability,
postAvailability,
getAppointmentsForPatient,
} = require("../utils/queries");
const uuid = require("uuid");

Expand Down Expand Up @@ -58,15 +59,34 @@ module.exports = (app) => {

app.get("/appointments/:doctorEmail", verify_token, async (req, res) => {
let { doctorEmail } = req.params;
let { created_at } = req.query;

try {
let result = await getAppointments(doctorEmail);
let result = await getAppointments(doctorEmail, created_at);

res.send({ success: true, result });
} catch (err) {
res.status(500).send({ success: false, msg: "Internal server err" });
}
});

app.get(
"/patientappointments/:patientEmail",
verify_token,
async (req, res) => {
let { patientEmail } = req.params;
console.log("patient appointment history", patientEmail);

try {
let result = await getAppointmentsForPatient(patientEmail);

res.send({ success: true, result });
} catch (err) {
res.status(500).send({ success: false, msg: "Internal server err" });
}
}
);

app.put(
"/appointmentStatus/:appointmentID/status",
verify_token,
Expand Down
107 changes: 60 additions & 47 deletions client/src/components/Doctor/DoctorAppointments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { FunctionComponent, useContext, useEffect, useState } from 'react
import { AuthContext } from '../../providers/AuthProvider';
import { useAuthFetch } from '../../hooks/api';
import { HealthContext } from '../../providers/HealthProvider';
import moment from 'moment';
interface AppointmentDetails {
name: string;
patient_email: string;
Expand All @@ -18,16 +19,15 @@ const DoctorAppointments: FunctionComponent<{}> = () => {
const { user, role, logout } = useContext(AuthContext);
const { fetch } = useAuthFetch();
const { fetchAllDoctors, doctorList } = useContext(HealthContext);
const [filterDate, setFilterDate] = useState('all');
const [appointmentData, setAppointmentData] = useState<AppointmentDetails[]>([]);

useEffect(() => {
//fetchDoctors();

getAppointment();
}, []);

const getAppointment = async () => {
let resp = await fetch('GET', '/appointments/' + user?.email);
let resp = await fetch('GET', '/appointments/' + user?.email + `?created_at= ${filterDate}`);
if (resp && resp.data && resp.data.result) {
setAppointmentData(resp.data.result);
} else {
Expand Down Expand Up @@ -68,9 +68,19 @@ const DoctorAppointments: FunctionComponent<{}> = () => {
type='date'
id='date'
name='date'
value={filterDate}
onChange={(e) => {
let date = moment(e.target.value).format('YYYY-MM-DD');
setFilterDate(date);
}}
className='border border-gray-300 rounded-md px-4 py-2'
/>
<button className='bg-blue-500 text-white font-bold rounded-md px-4 py-2 ml-2'>
<button
onClick={() => {
getAppointment();
}}
className='bg-blue-500 text-white font-bold rounded-md px-4 py-2 ml-2'
>
Filter
</button>
</div>
Expand Down Expand Up @@ -114,50 +124,53 @@ const DoctorAppointments: FunctionComponent<{}> = () => {
</tr>
</thead>
<tbody className='bg-white divide-y divide-gray-200'>
{appointmentData.map((appointment) => (
<tr key={appointment.appointment_id}>
<td className='px-6 py-4 whitespace-nowrap'>
<div className='text-sm text-gray-900'>{appointment.patient_name}</div>
</td>
<td className='px-6 py-4 whitespace-nowrap'>
<div className='text-sm text-gray-900'>{appointment.patient_email}</div>
</td>
<td className='px-6 py-4 whitespace-nowrap text-sm text-gray-500'>
{appointment.created_at}
</td>
{appointmentData.length > 0 &&
appointmentData.map((appointment) => (
<tr key={appointment.appointment_id}>
<td className='px-6 py-4 whitespace-nowrap'>
<div className='text-sm text-gray-900'>{appointment.patient_name}</div>
</td>
<td className='px-6 py-4 whitespace-nowrap'>
<div className='text-sm text-gray-900'>{appointment.patient_email}</div>
</td>
<td className='px-6 py-4 whitespace-nowrap text-sm text-gray-500'>
{appointment.created_at}
</td>

<td className='px-6 py-4 whitespace-nowrap text-sm text-gray-500'>
{appointment.appointment_time}
</td>
<td className='px-6 py-4 whitespace-nowrap'>
<span
className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getStatusColor(
appointment.appointment_status,
)}`}
>
{appointment.appointment_status == 'pending' ? (
<div className='flex justify-between'>
<button
className='bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded'
onClick={() => updateStatus('reject', appointment.appointment_id)}
>
Reject
</button>
<div className='w-4'></div>
<button
className='bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded'
onClick={() => updateStatus('confirmed', appointment.appointment_id)}
>
Confirm
</button>
</div>
) : (
<div>{appointment.appointment_status}</div>
)}
</span>
</td>
</tr>
))}
<td className='px-6 py-4 whitespace-nowrap text-sm text-gray-500'>
{appointment.appointment_time}
</td>
<td className='px-6 py-4 whitespace-nowrap'>
<span
className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getStatusColor(
appointment.appointment_status,
)}`}
>
{appointment.appointment_status == 'pending' ? (
<div className='flex justify-between'>
<button
className='bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded'
onClick={() => updateStatus('reject', appointment.appointment_id)}
>
Reject
</button>
<div className='w-4'></div>
<button
className='bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded'
onClick={() =>
updateStatus('confirmed', appointment.appointment_id)
}
>
Confirm
</button>
</div>
) : (
<div>{appointment.appointment_status}</div>
)}
</span>
</td>
</tr>
))}
</tbody>
</table>
</div>
Expand Down
17 changes: 14 additions & 3 deletions client/src/components/Doctor/UpdateProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ interface AppointmentDetails {
const UpdateProfile: FunctionComponent<{}> = () => {
const [address, setAddress] = useState('');
const [hc, setHc] = useState('');
const { updateProfile, currentAccount } = useContext(HealthContext);
const { user } = useContext(AuthContext);
const { updateProfile, currentAccount, handleDocToHCRaiseRequest } = useContext(HealthContext);
const account = currentAccount || '';

let providers = [
Expand All @@ -27,7 +28,7 @@ const UpdateProfile: FunctionComponent<{}> = () => {
},
{
name: 'Sutter Health Care',
address: '0xEE619586e0826CA2F00772701eADc2065E5D5A47',
address: '0xb3cc507e752dcc3da1cef955b58e97ae77160103',
},
{
name: 'El Camino',
Expand Down Expand Up @@ -64,7 +65,17 @@ const UpdateProfile: FunctionComponent<{}> = () => {
</select>
</div>
<button
onClick={() => updateProfile?.(hc, account)}
onClick={() => {
if (user?.name) {
handleDocToHCRaiseRequest?.(
user?.name,
account,
'0xb3cc507e752dcc3da1cef955b58e97ae77160103',
);

updateProfile?.(hc, account, 'confirm');
}
}}
className='flex-shrink-0 bg-teal-500 hover:bg-teal-700 border-teal-500 hover:border-teal-700 text-sm border-4 text-white py-1 px-2 rounded'
type='button'
>
Expand Down
106 changes: 106 additions & 0 deletions client/src/components/HealthCareProvider/HCDoctorsRequest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import React, { FunctionComponent, useContext, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { AuthContext } from '../../providers/AuthProvider';
import { HealthContext } from '../../providers/HealthProvider';

const HCDoctorRequest: FunctionComponent<{}> = () => {
const { fetchDocToProviderRequests, reqArr, updateProfile } = useContext(HealthContext);
useEffect(() => {
fetchDocToProviderRequests?.('0xb3cc507e752dcc3da1cef955b58e97ae77160103');
}, []);
const getStatusColor = (status: String) => {
switch (status) {
case 'confirmed':
return 'bg-green-200';
case 'reject':
return 'bg-red-200';
default:
return '';
}
};
console.log('reqArr-->', reqArr);

return (
<div>
<div className='-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8 mt-8'>
<div className='py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8'>
<div className='shadow overflow-hidden border-b border-gray-200 sm:rounded-lg'>
<table className='min-w-full divide-y divide-gray-200'>
<thead className='bg-gray-50'>
<tr>
<th
scope='col'
className='px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider'
>
Doctor Name
</th>
<th
scope='col'
className='px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider'
>
Doctor Address
</th>
<th
scope='col'
className='px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider'
>
Status
</th>
</tr>
</thead>
<tbody className='bg-white divide-y divide-gray-200'>
{reqArr &&
reqArr.length > 0 &&
reqArr.map((req) => (
<tr>
<td className='px-6 py-4 whitespace-nowrap'>
<div className='text-sm text-gray-900'>{req.doctorName}</div>
</td>
<td className='px-6 py-4 whitespace-nowrap'>
<div className='text-sm text-gray-900'>{req.doctor}</div>
</td>

<td className='px-6 py-4 whitespace-nowrap'>
<span
className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getStatusColor(
req.status,
)}`}
>
{req.status == 'pending' ? (
<div className='flex justify-between'>
<button
className='bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded'
// onClick={() => }
>
Reject
</button>
<div className='w-4'></div>
<button
className='bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded'
onClick={() =>
updateProfile?.(
'0xb3cc507e752dcc3da1cef955b58e97ae77160103',
'0xEE619586e0826CA2F00772701eADc2065E5D5A47',
'confirm',
)
}
>
Confirm
</button>
</div>
) : (
<div>{req.status}</div>
)}
</span>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
);
};
export default HCDoctorRequest;
14 changes: 14 additions & 0 deletions client/src/components/HealthCareProvider/HCProviderDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,22 @@ const HCProviderDashboard: FunctionComponent<{}> = () => {
})();
}, []);

const _renderManageRequestsSection = () => {
return (
<div className='bg-gradient-to-br from-purple-400 to-blue-500 rounded-lg shadow-lg p-6 flex justify-center w-400 h-300"'>
<button
onClick={() => navigate('/manage-doctor-requests')}
className='bg-white text-gray-800 py-2 px-6 rounded-full font-medium'
>
Manage Requests
</button>
</div>
);
};

return (
<div className='flex flex-col justify-center items-center'>
{_renderManageRequestsSection()}
<div className='w-full max-w-sm bg-white border border-gray-200 rounded-lg shadow-md dark:bg-gray-800 dark:border-gray-700 flex flex-col items-center mt-0'>
<h5 className='mt-4 mb-1 text-xl font-medium text-gray-900 dark:text-white'>
{user?.name}
Expand Down
Loading