import React, { useState, useEffect } from 'react'; import { useParams, Link, useNavigate } from 'react-router-dom'; import { patientService } from '../../services/patientService'; import Loading from '../../components/Loading'; import ErrorAlert from '../../components/ErrorAlert'; function PatientDetail() { const user = JSON.parse(localStorage.getItem('user') || '{}'); const isAdmin = user.role === 'ADMIN'; const isLabTechnician = user.role === 'LAB_TECHNICIAN'; const { id } = useParams(); const navigate = useNavigate(); const [patient, setPatient] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchPatient = async () => { try { setLoading(true); const response = await patientService.getPatientById(id); setPatient(response.data); } catch (err) { setError('Failed to fetch patient details'); console.error(err); } finally { setLoading(false); } }; fetchPatient(); }, [id]); if (loading) return ; if (!patient) { return (
navigate('/patients')} />
); } return (

{patient.firstName} {patient.lastName}

{isAdmin && ( Edit )}
{error && setError(null)} />}

Personal Information

{!isLabTechnician && (

Quick Links

View Appointments View Medical Records View Billing History
)}
); } function InfoRow({ label, value }) { return (
{label}: {value || 'N/A'}
); } export default PatientDetail;