import React, { useState, useEffect } from 'react';
import { useParams, Link, useNavigate } from 'react-router-dom';
import { doctorService } from '../../services/doctorService';
import Loading from '../../components/Loading';
import ErrorAlert from '../../components/ErrorAlert';
function DoctorDetail() {
const formatDepartmentName = (name) => {
if (!name) return 'N/A';
return name.replace(/_DEPT$/, '').replace(/_/g, ' ').split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ');
};
const { id } = useParams();
const navigate = useNavigate();
const user = JSON.parse(localStorage.getItem('user') || '{}');
const isPatient = user.role === 'PATIENT';
const isAdmin = user.role === 'ADMIN';
const isLabTechnician = user.role === 'LAB_TECHNICIAN';
const isBillingAdmin = user.role === 'BILLING_ADMIN';
const [doctor, setDoctor] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const fetchDoctor = async () => {
try {
setLoading(true);
const response = await doctorService.getDoctorById(id);
setDoctor(response.data);
} catch (err) {
setError('Failed to fetch doctor details');
console.error(err);
} finally {
setLoading(false);
}
};
fetchDoctor();
}, [id]);
if (loading) return