source: frontend/src/pages/patients/PatientDetail.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.7 KB
Line 
1import React, { useState, useEffect } from 'react';
2import { useParams, Link, useNavigate } from 'react-router-dom';
3import { patientService } from '../../services/patientService';
4import Loading from '../../components/Loading';
5import ErrorAlert from '../../components/ErrorAlert';
6
7function PatientDetail() {
8 const user = JSON.parse(localStorage.getItem('user') || '{}');
9 const isAdmin = user.role === 'ADMIN';
10 const isLabTechnician = user.role === 'LAB_TECHNICIAN';
11 const { id } = useParams();
12 const navigate = useNavigate();
13 const [patient, setPatient] = useState(null);
14 const [loading, setLoading] = useState(true);
15 const [error, setError] = useState(null);
16
17 useEffect(() => {
18 const fetchPatient = async () => {
19 try {
20 setLoading(true);
21 const response = await patientService.getPatientById(id);
22 setPatient(response.data);
23 } catch (err) {
24 setError('Failed to fetch patient details');
25 console.error(err);
26 } finally {
27 setLoading(false);
28 }
29 };
30
31 fetchPatient();
32 }, [id]);
33
34 if (loading) return <Loading />;
35
36 if (!patient) {
37 return (
38 <div>
39 <ErrorAlert message="Patient not found" onClose={() => navigate('/patients')} />
40 </div>
41 );
42 }
43
44 return (
45 <div>
46 <div className="flex justify-between items-center mb-6">
47 <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>{patient.firstName} {patient.lastName}</h1>
48 <div className="space-x-2">
49 {isAdmin && (
50 <Link to={`/patients/${id}/edit`} className="bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700">
51 Edit
52 </Link>
53 )}
54 <button onClick={() => navigate('/patients')} className="bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400">
55 Back
56 </button>
57 </div>
58 </div>
59
60 {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
61
62 <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
63 <div className="bg-white rounded-lg shadow p-6">
64 <h2 className="text-xl font-bold mb-4">Personal Information</h2>
65 <div className="space-y-3">
66 <InfoRow label="EMBG" value={patient.embg} />
67 <InfoRow label="Email" value={patient.emailAddress} />
68 <InfoRow label="Phone" value={patient.phoneNumber} />
69 <InfoRow label="Date of Birth" value={patient.dateOfBirth} />
70 <InfoRow label="Gender" value={patient.gender} />
71 <InfoRow label="Blood Type" value={patient.bloodType} />
72 </div>
73 </div>
74
75 {!isLabTechnician && (
76 <div className="bg-white rounded-lg shadow p-6">
77 <h2 className="text-xl font-bold mb-4">Quick Links</h2>
78 <div className="space-y-2">
79 <Link to={`/appointments?patientId=${id}`} className="block p-3 bg-blue-50 hover:bg-purple-100 rounded text-purple-600">
80 View Appointments
81 </Link>
82 <Link to={`/medical-records?patientId=${id}`} className="block p-3 bg-green-50 hover:bg-green-100 rounded text-green-600">
83 View Medical Records
84 </Link>
85 <Link to={`/billing?patientId=${id}`} className="block p-3 bg-purple-50 hover:bg-purple-100 rounded text-purple-600">
86 View Billing History
87 </Link>
88 </div>
89 </div>
90 )}
91 </div>
92 </div>
93 );
94}
95
96function InfoRow({ label, value }) {
97 return (
98 <div className="flex justify-between">
99 <span className="font-semibold text-gray-600">{label}:</span>
100 <span className="text-gray-800">{value || 'N/A'}</span>
101 </div>
102 );
103}
104
105export default PatientDetail;
Note: See TracBrowser for help on using the repository browser.