Index: frontend/src/App.js
===================================================================
--- frontend/src/App.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/App.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -65,63 +65,63 @@
 
   return (
-      <Router>
-        <div className="min-h-screen bg-gray-50">
-          {user && <Navbar />}
-          <main className={user ? "container mx-auto px-4 py-8" : ""}>
-            <Routes>
-              <Route path="/login" element={<Login />} />
+    <Router>
+      <div className="min-h-screen bg-gray-50">
+        {user && <Navbar />}
+        <main className={user ? "container mx-auto px-4 py-8" : ""}>
+          <Routes>
+            <Route path="/login" element={<Login />} />
 
-              <Route path="/" element={
-                <ProtectedRoute>
-                  <Dashboard />
-                </ProtectedRoute>
-              } />
+            <Route path="/" element={
+              <ProtectedRoute>
+                <Dashboard />
+              </ProtectedRoute>
+            } />
 
-              {/* Patient Routes */}
-              <Route path="/patients" element={<ProtectedRoute><PatientList /></ProtectedRoute>} />
-              <Route path="/patients/new" element={<ProtectedRoute><PatientForm /></ProtectedRoute>} />
-              <Route path="/patients/:id" element={<ProtectedRoute><PatientDetail /></ProtectedRoute>} />
-              <Route path="/patients/:id/edit" element={<ProtectedRoute><PatientForm /></ProtectedRoute>} />
+            {/* Patient Routes */}
+            <Route path="/patients" element={<ProtectedRoute><PatientList /></ProtectedRoute>} />
+            <Route path="/patients/new" element={<ProtectedRoute><PatientForm /></ProtectedRoute>} />
+            <Route path="/patients/:id" element={<ProtectedRoute><PatientDetail /></ProtectedRoute>} />
+            <Route path="/patients/:id/edit" element={<ProtectedRoute><PatientForm /></ProtectedRoute>} />
 
-              {/* Doctor Routes */}
-              <Route path="/doctors" element={<ProtectedRoute><DoctorList /></ProtectedRoute>} />
-              <Route path="/doctors/new" element={<ProtectedRoute><DoctorForm /></ProtectedRoute>} />
-              <Route path="/doctors/:id" element={<ProtectedRoute><DoctorDetail /></ProtectedRoute>} />
-              <Route path="/doctors/:id/edit" element={<ProtectedRoute><DoctorForm /></ProtectedRoute>} />
+            {/* Doctor Routes */}
+            <Route path="/doctors" element={<ProtectedRoute><DoctorList /></ProtectedRoute>} />
+            <Route path="/doctors/new" element={<ProtectedRoute><DoctorForm /></ProtectedRoute>} />
+            <Route path="/doctors/:id" element={<ProtectedRoute><DoctorDetail /></ProtectedRoute>} />
+            <Route path="/doctors/:id/edit" element={<ProtectedRoute><DoctorForm /></ProtectedRoute>} />
 
-              {/* Department Routes */}
-              <Route path="/departments" element={<ProtectedRoute><DepartmentList /></ProtectedRoute>} />
-              <Route path="/departments/:departmentId" element={<ProtectedRoute><DepartmentDetail /></ProtectedRoute>} />
-              <Route path="/departments/:departmentId/doctors" element={<ProtectedRoute><DoctorsByDepartment /></ProtectedRoute>} />
+            {/* Department Routes */}
+            <Route path="/departments" element={<ProtectedRoute><DepartmentList /></ProtectedRoute>} />
+            <Route path="/departments/:departmentId" element={<ProtectedRoute><DepartmentDetail /></ProtectedRoute>} />
+            <Route path="/departments/:departmentId/doctors" element={<ProtectedRoute><DoctorsByDepartment /></ProtectedRoute>} />
 
-              {/* Appointment Routes */}
-              <Route path="/appointments" element={<ProtectedRoute><AppointmentList /></ProtectedRoute>} />
-              <Route path="/appointments/new" element={<ProtectedRoute><AppointmentForm /></ProtectedRoute>} />
+            {/* Appointment Routes */}
+            <Route path="/appointments" element={<ProtectedRoute><AppointmentList /></ProtectedRoute>} />
+            <Route path="/appointments/new" element={<ProtectedRoute><AppointmentForm /></ProtectedRoute>} />
 
-              {/* Medical Record Routes */}
-              <Route path="/medical-records" element={<ProtectedRoute><MedicalRecordList /></ProtectedRoute>} />
-              <Route path="/medical-records/:id" element={<ProtectedRoute><MedicalRecordDetail /></ProtectedRoute>} />
+            {/* Medical Record Routes */}
+            <Route path="/medical-records" element={<ProtectedRoute><MedicalRecordList /></ProtectedRoute>} />
+            <Route path="/medical-records/:id" element={<ProtectedRoute><MedicalRecordDetail /></ProtectedRoute>} />
 
-              {/* Medical Report Routes */}
-              <Route path="/medical-reports" element={<ProtectedRoute><MedicalReportList /></ProtectedRoute>} />
+            {/* Medical Report Routes */}
+            <Route path="/medical-reports" element={<ProtectedRoute><MedicalReportList /></ProtectedRoute>} />
 
-              {/* Lab Test Routes */}
-              <Route path="/lab-tests" element={<ProtectedRoute><LabTestList /></ProtectedRoute>} />
-              <Route path="/lab-tests/results" element={<ProtectedRoute><LabResultForm /></ProtectedRoute>} />
+            {/* Lab Test Routes */}
+            <Route path="/lab-tests" element={<ProtectedRoute><LabTestList /></ProtectedRoute>} />
+            <Route path="/lab-tests/results" element={<ProtectedRoute><LabResultForm /></ProtectedRoute>} />
 
-              {/* Procedure Routes */}
-              <Route path="/procedures" element={<ProtectedRoute><ProcedureList /></ProtectedRoute>} />
-              <Route path="/procedures/results" element={<ProtectedRoute><ProcedureResultForm /></ProtectedRoute>} />
+            {/* Procedure Routes */}
+            <Route path="/procedures" element={<ProtectedRoute><ProcedureList /></ProtectedRoute>} />
+            <Route path="/procedures/results" element={<ProtectedRoute><ProcedureResultForm /></ProtectedRoute>} />
 
-              {/* Billing Routes */}
-              <Route path="/billing" element={<ProtectedRoute><BillingList /></ProtectedRoute>} />
-              <Route path="/billing/:id" element={<ProtectedRoute><BillingDetail /></ProtectedRoute>} />
+            {/* Billing Routes */}
+            <Route path="/billing" element={<ProtectedRoute><BillingList /></ProtectedRoute>} />
+            <Route path="/billing/:id" element={<ProtectedRoute><BillingDetail /></ProtectedRoute>} />
 
-              {/* Referral Routes */}
-              <Route path="/referrals" element={<ProtectedRoute><ReferralList /></ProtectedRoute>} />
-            </Routes>
-          </main>
-        </div>
-      </Router>
+            {/* Referral Routes */}
+            <Route path="/referrals" element={<ProtectedRoute><ReferralList /></ProtectedRoute>} />
+          </Routes>
+        </main>
+      </div>
+    </Router>
   );
 }
Index: frontend/src/components/Navbar.js
===================================================================
--- frontend/src/components/Navbar.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/components/Navbar.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -18,6 +18,8 @@
     };
 
+    // Load user on mount
     loadUser();
 
+    // Listen for storage changes (when user logs in/out)
     window.addEventListener('storage', loadUser);
     return () => window.removeEventListener('storage', loadUser);
@@ -29,5 +31,5 @@
     setUser(null);
 
-
+    // Dispatch custom event to notify components on the same tab
     window.dispatchEvent(new CustomEvent('userStorageChange', {
       detail: { userData: null }
@@ -45,142 +47,142 @@
 
   return (
-      <nav className="navbar">
-        <div className="navbar-brand">
-          <img src="/logo.png" alt="Medora Logo" style={{ height: '40px', width: 'auto' }} />
-        </div>
+    <nav className="navbar">
+      <div className="navbar-brand">
+        <img src="/logo.png" alt="Medora Logo" style={{ height: '40px', width: 'auto' }} />
+      </div>
 
-        <div className="navbar-links">
-          <Link to="/" className={`navbar-link ${isActive('/') ? 'active' : ''}`}>
-            Overview
+      <div className="navbar-links">
+        <Link to="/" className={`navbar-link ${isActive('/') ? 'active' : ''}`}>
+          Overview
+        </Link>
+        {user?.role !== 'PATIENT' && user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
+          <Link to="/patients" className={`navbar-link ${isActive('/patients') ? 'active' : ''}`}>
+            Patients
           </Link>
-          {user?.role !== 'PATIENT' && user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
-              <Link to="/patients" className={`navbar-link ${isActive('/patients') ? 'active' : ''}`}>
-                Patients
+        )}
+        <Link to="/doctors" className={`navbar-link ${isActive('/doctors') ? 'active' : ''}`}>
+          Doctors
+        </Link>
+        <Link to="/departments" className={`navbar-link ${isActive('/departments') ? 'active' : ''}`}>
+          Departments
+        </Link>
+        {user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
+          <>
+            <Link to="/appointments" className={`navbar-link ${isActive('/appointments') ? 'active' : ''}`}>
+              Appointments
+            </Link>
+            {user?.role === 'PATIENT' && (
+              <>
+                <Link to="/medical-records" className={`navbar-link ${isActive('/medical-records') ? 'active' : ''}`}>
+                  Medical Records
+                </Link>
+                <Link to="/billing" className={`navbar-link ${isActive('/billing') ? 'active' : ''}`}>
+                  Billing
+                </Link>
+              </>
+            )}
+          </>
+        )}
+        {(user?.role === 'ADMIN' || user?.role === 'LAB_TECHNICIAN' || user?.role === 'DOCTOR') && (
+          <Link to="/lab-tests" className={`navbar-link ${isActive('/lab-tests') ? 'active' : ''}`}>
+            Lab Tests
+          </Link>
+        )}
+        {!user?.role || user?.role === 'ADMIN' || user?.role === 'DOCTOR' ? (
+          <>
+            {user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
+              <Link to="/medical-records" className={`navbar-link ${isActive('/medical-records') ? 'active' : ''}`}>
+                Medical Records
               </Link>
-          )}
-          <Link to="/doctors" className={`navbar-link ${isActive('/doctors') ? 'active' : ''}`}>
-            Doctors
+            )}
+            {user?.role !== 'PATIENT' && user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
+              <>
+                <Link to="/medical-reports" className={`navbar-link ${isActive('/medical-reports') ? 'active' : ''}`}>
+                  Medical Reports
+                </Link>
+                <Link to="/procedures" className={`navbar-link ${isActive('/procedures') ? 'active' : ''}`}>
+                  Procedures
+                </Link>
+                <Link to="/referrals" className={`navbar-link ${isActive('/referrals') ? 'active' : ''}`}>
+                  Referrals
+                </Link>
+              </>
+            )}
+          </>
+        ) : null}
+        {(user?.role === 'ADMIN' || user?.role === 'BILLING_ADMIN') && (
+          <Link to="/billing" className={`navbar-link ${isActive('/billing') ? 'active' : ''}`}>
+            Billing
           </Link>
-          <Link to="/departments" className={`navbar-link ${isActive('/departments') ? 'active' : ''}`}>
-            Departments
-          </Link>
-          {user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
-              <>
-                <Link to="/appointments" className={`navbar-link ${isActive('/appointments') ? 'active' : ''}`}>
-                  Appointments
-                </Link>
-                {user?.role === 'PATIENT' && (
-                    <>
-                      <Link to="/medical-records" className={`navbar-link ${isActive('/medical-records') ? 'active' : ''}`}>
-                        Medical Records
-                      </Link>
-                      <Link to="/billing" className={`navbar-link ${isActive('/billing') ? 'active' : ''}`}>
-                        Billing
-                      </Link>
-                    </>
-                )}
-              </>
-          )}
-          {(user?.role === 'ADMIN' || user?.role === 'LAB_TECHNICIAN' || user?.role === 'DOCTOR') && (
-              <Link to="/lab-tests" className={`navbar-link ${isActive('/lab-tests') ? 'active' : ''}`}>
-                Lab Tests
-              </Link>
-          )}
-          {!user?.role || user?.role === 'ADMIN' || user?.role === 'DOCTOR' ? (
-              <>
-                {user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
-                    <Link to="/medical-records" className={`navbar-link ${isActive('/medical-records') ? 'active' : ''}`}>
-                      Medical Records
-                    </Link>
-                )}
-                {user?.role !== 'PATIENT' && user?.role !== 'LAB_TECHNICIAN' && user?.role !== 'BILLING_ADMIN' && (
-                    <>
-                      <Link to="/medical-reports" className={`navbar-link ${isActive('/medical-reports') ? 'active' : ''}`}>
-                        Medical Reports
-                      </Link>
-                      <Link to="/procedures" className={`navbar-link ${isActive('/procedures') ? 'active' : ''}`}>
-                        Procedures
-                      </Link>
-                      <Link to="/referrals" className={`navbar-link ${isActive('/referrals') ? 'active' : ''}`}>
-                        Referrals
-                      </Link>
-                    </>
-                )}
-              </>
-          ) : null}
-          {(user?.role === 'ADMIN' || user?.role === 'BILLING_ADMIN') && (
-              <Link to="/billing" className={`navbar-link ${isActive('/billing') ? 'active' : ''}`}>
-                Billing
-              </Link>
-          )}
-        </div>
+        )}
+      </div>
 
-        <div className="navbar-right">
-          {user && (
-              <div className="navbar-avatar" style={{ position: 'relative' }}>
-                <div className="navbar-avatar-circle">{getInitials()}</div>
-                <div className="navbar-avatar-name">{user.firstName}</div>
+      <div className="navbar-right">
+        {user && (
+          <div className="navbar-avatar" style={{ position: 'relative' }}>
+            <div className="navbar-avatar-circle">{getInitials()}</div>
+            <div className="navbar-avatar-name">{user.firstName}</div>
+            <button
+              onClick={() => setShowMenu(!showMenu)}
+              style={{
+                background: 'none',
+                border: 'none',
+                cursor: 'pointer',
+                marginLeft: '4px',
+                color: 'var(--color-neutral-600)',
+                fontSize: '12px'
+              }}
+            >
+              ▼
+            </button>
+            {showMenu && (
+              <div style={{
+                position: 'absolute',
+                top: '100%',
+                right: 0,
+                background: 'white',
+                border: '1px solid var(--color-neutral-400)',
+                borderRadius: '6px',
+                minWidth: '150px',
+                marginTop: '4px',
+                boxShadow: '0 4px 6px rgba(0,0,0,0.1)',
+                zIndex: 1000
+              }}>
+                <div style={{
+                  padding: '8px 0',
+                  fontSize: '11px',
+                  color: 'var(--color-neutral-600)',
+                  borderBottom: '1px solid var(--color-neutral-400)',
+                  paddingLeft: '12px',
+                  paddingRight: '12px',
+                  paddingTop: '8px',
+                  paddingBottom: '8px'
+                }}>
+                  {user.role}
+                </div>
                 <button
-                    onClick={() => setShowMenu(!showMenu)}
-                    style={{
-                      background: 'none',
-                      border: 'none',
-                      cursor: 'pointer',
-                      marginLeft: '4px',
-                      color: 'var(--color-neutral-600)',
-                      fontSize: '12px'
-                    }}
+                  onClick={handleLogout}
+                  style={{
+                    width: '100%',
+                    padding: '8px 12px',
+                    background: 'none',
+                    border: 'none',
+                    textAlign: 'left',
+                    cursor: 'pointer',
+                    fontSize: '12px',
+                    color: 'var(--color-status-red)',
+                    transition: 'background 0.2s'
+                  }}
+                  onMouseEnter={(e) => e.target.style.background = 'var(--color-neutral-200)'}
+                  onMouseLeave={(e) => e.target.style.background = 'none'}
                 >
-                  ▼
+                  Logout
                 </button>
-                {showMenu && (
-                    <div style={{
-                      position: 'absolute',
-                      top: '100%',
-                      right: 0,
-                      background: 'white',
-                      border: '1px solid var(--color-neutral-400)',
-                      borderRadius: '6px',
-                      minWidth: '150px',
-                      marginTop: '4px',
-                      boxShadow: '0 4px 6px rgba(0,0,0,0.1)',
-                      zIndex: 1000
-                    }}>
-                      <div style={{
-                        padding: '8px 0',
-                        fontSize: '11px',
-                        color: 'var(--color-neutral-600)',
-                        borderBottom: '1px solid var(--color-neutral-400)',
-                        paddingLeft: '12px',
-                        paddingRight: '12px',
-                        paddingTop: '8px',
-                        paddingBottom: '8px'
-                      }}>
-                        {user.role}
-                      </div>
-                      <button
-                          onClick={handleLogout}
-                          style={{
-                            width: '100%',
-                            padding: '8px 12px',
-                            background: 'none',
-                            border: 'none',
-                            textAlign: 'left',
-                            cursor: 'pointer',
-                            fontSize: '12px',
-                            color: 'var(--color-status-red)',
-                            transition: 'background 0.2s'
-                          }}
-                          onMouseEnter={(e) => e.target.style.background = 'var(--color-neutral-200)'}
-                          onMouseLeave={(e) => e.target.style.background = 'none'}
-                      >
-                        Logout
-                      </button>
-                    </div>
-                )}
               </div>
-          )}
-        </div>
-      </nav>
+            )}
+          </div>
+        )}
+      </div>
+    </nav>
   );
 }
Index: frontend/src/components/ProtectedRoute.js
===================================================================
--- frontend/src/components/ProtectedRoute.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/components/ProtectedRoute.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -1,2 +1,3 @@
+
 import React from 'react';
 import { Navigate } from 'react-router-dom';
Index: frontend/src/index.css
===================================================================
--- frontend/src/index.css	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/index.css	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -0,0 +1,22 @@
+@tailwind base;
+@tailwind components;
+@tailwind utilities;
+
+* {
+  margin: 0;
+  padding: 0;
+  box-sizing: border-box;
+}
+
+body {
+  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
+    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
+    sans-serif;
+  -webkit-font-smoothing: antialiased;
+  -moz-osx-font-smoothing: grayscale;
+}
+
+code {
+  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
+    monospace;
+}
Index: frontend/src/index.js
===================================================================
--- frontend/src/index.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/index.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -7,6 +7,6 @@
 const root = ReactDOM.createRoot(document.getElementById('root'));
 root.render(
-    <React.StrictMode>
-        <App />
-    </React.StrictMode>
+  <React.StrictMode>
+    <App />
+  </React.StrictMode>
 );
Index: frontend/src/pages/Dashboard.js
===================================================================
--- frontend/src/pages/Dashboard.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/Dashboard.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -6,5 +6,4 @@
 import { labService } from '../services/labService';
 import { billingService } from '../services/billingService';
-import { medicalRecordService } from '../services/medicalRecordService';
 import Loading from '../components/Loading';
 
@@ -19,5 +18,4 @@
   const [pendingLabTests, setPendingLabTests] = useState([]);
   const [billings, setBillings] = useState([]);
-  const [medicalRecords, setMedicalRecords] = useState([]);
   const [patientBillings, setPatientBillings] = useState([]);
   const [loading, setLoading] = useState(true);
@@ -33,14 +31,9 @@
         if (isPatient) {
           // For patients, fetch their own appointments, medical records, and billing
-          const [appointmentsRes, medicalRes, billingRes] = await Promise.all([
+          const [appointmentsRes, billingRes] = await Promise.all([
             appointmentService.getAppointmentsForPatient(user.patientId),
-            medicalRecordService.getMedicalRecordByPatientId(user.patientId),
             billingService.getBillingHistoryForPatient(user.patientId)
           ]);
           setUserAppointments(appointmentsRes.data || []);
-          // Handle medical records - could be single object or array
-          const medicalData = medicalRes.data;
-          const medicalArray = Array.isArray(medicalData) ? medicalData : (medicalData ? [medicalData] : []);
-          setMedicalRecords(medicalArray);
           setPatientBillings(billingRes.data || []);
         } else if (isDoctor) {
@@ -82,5 +75,5 @@
 
     fetchStats();
-  }, [user.userId, isPatient, isDoctor, isLabTechnician]);
+  }, []);
 
   if (loading) return <Loading />;
Index: frontend/src/pages/Login.js
===================================================================
--- frontend/src/pages/Login.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/Login.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -75,66 +75,66 @@
 
   return (
-      <div className="min-h-screen bg-blue-200 flex items-center justify-center p-4">
-        <div className="bg-white rounded-lg shadow-2xl p-8 w-full max-w-md">
-          <div className="text-center mb-8">
-            <h1 className="text-5xl font-bold text-purple-600 mb-2">Medora</h1>
-            <p className="text-gray-600">Hospital Management System</p>
+    <div className="min-h-screen bg-blue-200 flex items-center justify-center p-4">
+      <div className="bg-white rounded-lg shadow-2xl p-8 w-full max-w-md">
+        <div className="text-center mb-8">
+          <h1 className="text-5xl font-bold text-purple-600 mb-2">Medora</h1>
+          <p className="text-gray-600">Hospital Management System</p>
+        </div>
+
+        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+        {success && <SuccessAlert message={success} onClose={() => setSuccess(null)} />}
+
+        <form onSubmit={handleLogin} className="space-y-6">
+          <div>
+            <label className="block text-sm font-normal text-gray-700 mb-2">
+              Username (EMBG for Patients)
+            </label>
+            <input
+              type="text"
+              value={username}
+              onChange={(e) => setUsername(e.target.value)}
+              placeholder="Enter your username or EMBG"
+              className="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-purple-500 transition"
+              disabled={loading}
+            />
           </div>
 
-          {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
-          {success && <SuccessAlert message={success} onClose={() => setSuccess(null)} />}
+          <div>
+            <label className="block text-sm font-normal text-gray-700 mb-2">
+              Password
+            </label>
+            <input
+              type="password"
+              value={password}
+              onChange={(e) => setPassword(e.target.value)}
+              placeholder="Enter your password"
+              className="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-purple-500 transition"
+              disabled={loading}
+            />
+          </div>
 
-          <form onSubmit={handleLogin} className="space-y-6">
-            <div>
-              <label className="block text-sm font-normal text-gray-700 mb-2">
-                Username (EMBG for Patients)
-              </label>
-              <input
-                  type="text"
-                  value={username}
-                  onChange={(e) => setUsername(e.target.value)}
-                  placeholder="Enter your username or EMBG"
-                  className="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-purple-500 transition"
-                  disabled={loading}
-              />
-            </div>
+          <button
+            type="submit"
+            disabled={loading}
+            className="w-full bg-purple-600 text-white font-bold py-3 rounded-lg hover:bg-purple-700 transition disabled:opacity-50 disabled:cursor-not-allowed"
+          >
+            {loading ? 'Logging in...' : 'Login'}
+          </button>
+        </form>
 
-            <div>
-              <label className="block text-sm font-normal text-gray-700 mb-2">
-                Password
-              </label>
-              <input
-                  type="password"
-                  value={password}
-                  onChange={(e) => setPassword(e.target.value)}
-                  placeholder="Enter your password"
-                  className="w-full px-4 py-3 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-purple-500 transition"
-                  disabled={loading}
-              />
-            </div>
-
-            <button
-                type="submit"
-                disabled={loading}
-                className="w-full bg-purple-600 text-white font-bold py-3 rounded-lg hover:bg-purple-700 transition disabled:opacity-50 disabled:cursor-not-allowed"
-            >
-              {loading ? 'Logging in...' : 'Login'}
-            </button>
-          </form>
-
-          <div className="mt-8 p-4 bg-purple-50 rounded-lg border border-purple-200">
-            <p className="text-sm text-gray-700 font-normal mb-2">Demo Credentials:</p>
-            <p className="text-sm text-gray-600 mb-2">
-              <strong>Admin:</strong> username: admin | password: admin123
-            </p>
-            <p className="text-sm text-gray-600 mb-2">
-              <strong>Doctor:</strong> username: ivan.stojanov@medora.com | password: doctor123
-            </p>
-            <p className="text-sm text-gray-600">
-              <strong>Patient:</strong> username: [EMBG] | password: password123
-            </p>
-          </div>
+        <div className="mt-8 p-4 bg-purple-50 rounded-lg border border-purple-200">
+          <p className="text-sm text-gray-700 font-normal mb-2">Demo Credentials:</p>
+          <p className="text-sm text-gray-600 mb-2">
+            <strong>Admin:</strong> username: admin | password: admin123
+          </p>
+          <p className="text-sm text-gray-600 mb-2">
+            <strong>Doctor:</strong> username: ivan.stojanov@medora.com | password: doctor123
+          </p>
+          <p className="text-sm text-gray-600">
+            <strong>Patient:</strong> username: [EMBG] | password: password123
+          </p>
         </div>
       </div>
+    </div>
   );
 }
Index: frontend/src/pages/ProtectedRoute.js
===================================================================
--- frontend/src/pages/ProtectedRoute.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ 	(revision )
@@ -1,24 +1,0 @@
-import React from 'react';
-import { Navigate } from 'react-router-dom';
-
-function ProtectedRoute({ children, requiredRoles = [] }) {
-  const token = localStorage.getItem('token');
-  const userStr = localStorage.getItem('user');
-
-  // If no token, redirect to login
-  if (!token) {
-    return <Navigate to="/login" replace />;
-  }
-
-  // If roles are specified and user's role is not in the list, redirect to dashboard
-  if (requiredRoles.length > 0 && userStr) {
-    const user = JSON.parse(userStr);
-    if (!requiredRoles.includes(user.role)) {
-      return <Navigate to="/" replace />;
-    }
-  }
-
-  return children;
-}
-
-export default ProtectedRoute;
Index: frontend/src/pages/appointments/AppointmentForm.js
===================================================================
--- frontend/src/pages/appointments/AppointmentForm.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/appointments/AppointmentForm.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -26,21 +26,20 @@
 
   useEffect(() => {
+    const fetchData = async () => {
+      try {
+        if (!isPatient) {
+          const patientsRes = await patientService.getAllPatients();
+          setPatients(patientsRes.data);
+        }
+
+        const doctorsRes = await doctorService.getAllDoctors();
+        setDoctors(doctorsRes.data);
+      } catch (err) {
+        setError('Failed to fetch doctors');
+      }
+    };
+
     fetchData();
-  }, []);
-
-  const fetchData = async () => {
-    try {
-      // For patients, we don't need to fetch all patients
-      if (!isPatient) {
-        const patientsRes = await patientService.getAllPatients();
-        setPatients(patientsRes.data);
-      }
-
-      const doctorsRes = await doctorService.getAllDoctors();
-      setDoctors(doctorsRes.data);
-    } catch (err) {
-      setError('Failed to fetch doctors');
-    }
-  };
+  }, [isPatient]);
 
   const handleChange = (e) => {
Index: frontend/src/pages/appointments/AppointmentList.js
===================================================================
--- frontend/src/pages/appointments/AppointmentList.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/appointments/AppointmentList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -15,30 +15,26 @@
 
   useEffect(() => {
-    fetchAppointments();
+    const fetchAppointmentsData = async () => {
+      try {
+        setLoading(true);
+        let response;
+        if (patientId) {
+          response = await appointmentService.getAppointmentsForPatient(patientId);
+        } else if (doctorId) {
+          response = await appointmentService.getAppointmentsForDoctor(doctorId);
+        } else {
+          response = await appointmentService.getAllAppointments();
+        }
+        setAppointments(response.data || []);
+      } catch (err) {
+        setError('Failed to fetch appointments');
+        console.error(err);
+      } finally {
+        setLoading(false);
+      }
+    };
+
+    fetchAppointmentsData();
   }, [doctorId, patientId]);
-
-  const fetchAppointments = async () => {
-    try {
-      setLoading(true);
-      let response;
-      if (patientId) {
-        response = await appointmentService.getAppointmentsForPatient(patientId);
-      } else if (doctorId) {
-        response = await appointmentService.getAppointmentsForDoctor(doctorId);
-      } else if (user.role === 'PATIENT') {
-        response = await appointmentService.getAppointmentsForPatient(user.patientId);
-      } else if (user.role === 'DOCTOR') {
-        response = await appointmentService.getAppointmentsForDoctor(user.doctorId);
-      } else {
-        response = await appointmentService.getAllAppointments();
-      }
-      setAppointments(response.data);
-    } catch (err) {
-      setError('Failed to fetch appointments');
-      console.error(err);
-    } finally {
-      setLoading(false);
-    }
-  };
 
   const handleCancelAppointment = async (id) => {
@@ -47,5 +43,5 @@
         await appointmentService.cancelAppointment(id);
         setAppointments(appointments.map(apt =>
-            apt.appointmentId === id ? { ...apt, status: 'CANCELLED' } : apt
+          apt.appointmentId === id ? { ...apt, status: 'CANCELLED' } : apt
         ));
       } catch (err) {
@@ -58,28 +54,28 @@
 
   return (
-      <div>
-        <div className="flex justify-between items-center mb-6">
-          <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>
-            {patientId ? 'Patient Appointments' : doctorId ? 'My Appointments' : 'All Appointments'}
-          </h1>
-          <Link to="/appointments/new" style={{
-            display: 'inline-block',
-            background: '#bfdbfe',
-            color: '#1e1035',
-            padding: '8px 16px',
-            borderRadius: '6px',
-            textDecoration: 'none',
-            fontSize: '14px',
-            fontWeight: '400'
-          }} onMouseEnter={(e) => e.currentTarget.style.background = '#93c5fd'} onMouseLeave={(e) => e.currentTarget.style.background = '#bfdbfe'}>
-            New Appointment
-          </Link>
-        </div>
+    <div>
+      <div className="flex justify-between items-center mb-6">
+        <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>
+          {patientId ? 'Patient Appointments' : doctorId ? 'My Appointments' : 'All Appointments'}
+        </h1>
+        <Link to="/appointments/new" style={{
+          display: 'inline-block',
+          background: '#bfdbfe',
+          color: '#1e1035',
+          padding: '8px 16px',
+          borderRadius: '6px',
+          textDecoration: 'none',
+          fontSize: '14px',
+          fontWeight: '400'
+        }} onMouseEnter={(e) => e.currentTarget.style.background = '#93c5fd'} onMouseLeave={(e) => e.currentTarget.style.background = '#bfdbfe'}>
+          New Appointment
+        </Link>
+      </div>
 
-        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
 
-        <div className="bg-white rounded-lg shadow overflow-hidden">
-          <table className="w-full">
-            <thead className="bg-gray-100">
+      <div className="bg-white rounded-lg shadow overflow-hidden">
+        <table className="w-full">
+          <thead className="bg-gray-100">
             <tr>
               <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
@@ -90,39 +86,39 @@
               <th className="px-6 py-3 text-left text-sm font-semibold">Actions</th>
             </tr>
-            </thead>
-            <tbody>
+          </thead>
+          <tbody>
             {appointments.map(appointment => (
-                <tr key={appointment.appointmentId} className="border-t hover:bg-gray-50">
-                  <td className="px-6 py-3">{appointment.patient?.firstName} {appointment.patient?.lastName}</td>
-                  <td className="px-6 py-3">Dr. {appointment.doctor?.firstName} {appointment.doctor?.lastName}</td>
-                  <td className="px-6 py-3">{appointment.appointmentDate}</td>
-                  <td className="px-6 py-3">{appointment.appointmentTime}</td>
-                  <td className="px-6 py-3">
+              <tr key={appointment.appointmentId} className="border-t hover:bg-gray-50">
+                <td className="px-6 py-3">{appointment.patient?.firstName} {appointment.patient?.lastName}</td>
+                <td className="px-6 py-3">Dr. {appointment.doctor?.firstName} {appointment.doctor?.lastName}</td>
+                <td className="px-6 py-3">{appointment.appointmentDate}</td>
+                <td className="px-6 py-3">{appointment.appointmentTime}</td>
+                <td className="px-6 py-3">
                   <span className={`px-3 py-1 rounded text-sm font-semibold ${
-                      appointment.status === 'SCHEDULED' ? 'bg-purple-100 text-purple-800' :
-                          appointment.status === 'COMPLETED' ? 'bg-green-100 text-green-800' :
-                              'bg-red-100 text-red-800'
+                    appointment.status === 'SCHEDULED' ? 'bg-purple-100 text-purple-800' :
+                    appointment.status === 'COMPLETED' ? 'bg-green-100 text-green-800' :
+                    'bg-red-100 text-red-800'
                   }`}>
                     {appointment.status}
                   </span>
-                  </td>
-                  <td className="px-6 py-3">
-                    {appointment.status === 'SCHEDULED' && (
-                        (user.role === 'DOCTOR' && appointment.doctor?.doctorId !== user.doctorId) ? null : (
-                            <button
-                                onClick={() => handleCancelAppointment(appointment.appointmentId)}
-                                className="text-red-600 hover:underline px-3 py-2 text-sm font-medium"
-                            >
-                              Cancel
-                            </button>
-                        )
-                    )}
-                  </td>
-                </tr>
+                </td>
+                <td className="px-6 py-3">
+                  {appointment.status === 'SCHEDULED' && (
+                    (user.role === 'DOCTOR' && appointment.doctor?.doctorId !== user.doctorId) ? null : (
+                      <button
+                        onClick={() => handleCancelAppointment(appointment.appointmentId)}
+                        className="text-red-600 hover:underline px-3 py-2 text-sm font-medium"
+                      >
+                        Cancel
+                      </button>
+                    )
+                  )}
+                </td>
+              </tr>
             ))}
-            </tbody>
-          </table>
-        </div>
+          </tbody>
+        </table>
       </div>
+    </div>
   );
 }
Index: frontend/src/pages/billing/BillingDetail.js
===================================================================
--- frontend/src/pages/billing/BillingDetail.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/billing/BillingDetail.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -22,11 +22,8 @@
 
   useEffect(() => {
-    fetchBilling();
-  }, [id]);
-
-  const fetchBilling = async () => {
-    try {
-      setLoading(true);
-      const response = await billingService.getBillingById(id);
+    const fetchBilling = async () => {
+      try {
+        setLoading(true);
+        const response = await billingService.getBillingById(id);
       setBilling(response.data);
       setPaymentStatus(response.data.paymentStatus);
@@ -39,11 +36,14 @@
         console.error('Could not fetch billing details:', err);
       }
-    } catch (err) {
-      setError('Failed to fetch billing record');
-      console.error(err);
-    } finally {
-      setLoading(false);
-    }
-  };
+      } catch (err) {
+        setError('Failed to fetch billing record');
+        console.error(err);
+      } finally {
+        setLoading(false);
+      }
+    };
+
+    fetchBilling();
+  }, [id]);
 
   const handleUpdatePaymentStatus = async () => {
@@ -81,8 +81,8 @@
   if (user.role === 'DOCTOR' || user.role === 'LAB_TECHNICIAN') {
     return (
-        <div style={{ padding: '20px', textAlign: 'center' }}>
-          <h1 className="text-2xl font-bold" style={{ color: '#7c3aed', marginBottom: '10px' }}>Access Denied</h1>
-          <p style={{ color: 'var(--color-neutral-600)' }}>You do not have permission to access billing records.</p>
-        </div>
+      <div style={{ padding: '20px', textAlign: 'center' }}>
+        <h1 className="text-2xl font-bold" style={{ color: '#7c3aed', marginBottom: '10px' }}>Access Denied</h1>
+        <p style={{ color: 'var(--color-neutral-600)' }}>You do not have permission to access billing records.</p>
+      </div>
     );
   }
@@ -90,144 +90,144 @@
   if (!billing) {
     return (
-        <div>
-          <ErrorAlert message="Billing record not found" onClose={() => navigate('/billing')} />
-        </div>
+      <div>
+        <ErrorAlert message="Billing record not found" onClose={() => navigate('/billing')} />
+      </div>
     );
   }
 
   return (
-      <div>
-        <div className="flex justify-between items-center mb-6">
-          <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>Billing Record #{billing.billId}</h1>
-          <div className="space-x-2">
-            <button
-                onClick={handleDownloadInvoice}
-                disabled={downloading}
-                className="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700 disabled:opacity-50"
-            >
-              {downloading ? 'Downloading...' : 'Download Invoice (PDF)'}
-            </button>
-            <button onClick={() => navigate('/billing')} className="bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400">
-              Back
-            </button>
-          </div>
+    <div>
+      <div className="flex justify-between items-center mb-6">
+        <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>Billing Record #{billing.billId}</h1>
+        <div className="space-x-2">
+          <button
+            onClick={handleDownloadInvoice}
+            disabled={downloading}
+            className="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700 disabled:opacity-50"
+          >
+            {downloading ? 'Downloading...' : 'Download Invoice (PDF)'}
+          </button>
+          <button onClick={() => navigate('/billing')} className="bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400">
+            Back
+          </button>
         </div>
-
-        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
-        {success && <SuccessAlert message={success} onClose={() => setSuccess(null)} />}
-
-        <div className={`grid gap-6 mb-6 ${isPatient ? 'grid-cols-1 lg:grid-cols-2' : 'grid-cols-1 lg:grid-cols-3'}`}>
+      </div>
+
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+      {success && <SuccessAlert message={success} onClose={() => setSuccess(null)} />}
+
+      <div className={`grid gap-6 mb-6 ${isPatient ? 'grid-cols-1 lg:grid-cols-2' : 'grid-cols-1 lg:grid-cols-3'}`}>
+        <div className="bg-white rounded-lg shadow p-6">
+          <h2 className="text-xl font-bold mb-4">Billing Information</h2>
+          <div className="space-y-3">
+            <InfoRow label="Patient" value={billing.patientName} />
+            <InfoRow label="Total Cost" value={`$${billing.totalCost}`} />
+            <InfoRow label="Current Status" value={billing.paymentStatus} />
+            <InfoRow label="Payment Date" value={billing.paymentDate || 'Not paid'} />
+          </div>
+        </div>
+
+        {!isPatient && (
           <div className="bg-white rounded-lg shadow p-6">
-            <h2 className="text-xl font-bold mb-4">Billing Information</h2>
-            <div className="space-y-3">
-              <InfoRow label="Patient" value={billing.patientName} />
-              <InfoRow label="Total Cost" value={`$${billing.totalCost}`} />
-              <InfoRow label="Current Status" value={billing.paymentStatus} />
-              <InfoRow label="Payment Date" value={billing.paymentDate || 'Not paid'} />
+            <h2 className="text-xl font-bold mb-4">Update Payment Status</h2>
+            <div className="space-y-4">
+              <div>
+                <label className="block text-sm font-semibold mb-2">Payment Status</label>
+                <select
+                  value={paymentStatus}
+                  onChange={(e) => setPaymentStatus(e.target.value)}
+                  className="w-full px-4 py-2 border rounded-lg"
+                >
+                  <option value="PENDING">Pending</option>
+                  <option value="PAID">Paid</option>
+                  <option value="CANCELLED">Cancelled</option>
+                </select>
+              </div>
+              <button
+                onClick={handleUpdatePaymentStatus}
+                disabled={updating || paymentStatus === billing.paymentStatus}
+                className="w-full bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700 disabled:opacity-50"
+              >
+                {updating ? 'Updating...' : 'Update Status'}
+              </button>
             </div>
           </div>
-
-          {!isPatient && (
-              <div className="bg-white rounded-lg shadow p-6">
-                <h2 className="text-xl font-bold mb-4">Update Payment Status</h2>
-                <div className="space-y-4">
-                  <div>
-                    <label className="block text-sm font-semibold mb-2">Payment Status</label>
-                    <select
-                        value={paymentStatus}
-                        onChange={(e) => setPaymentStatus(e.target.value)}
-                        className="w-full px-4 py-2 border rounded-lg"
-                    >
-                      <option value="PENDING">Pending</option>
-                      <option value="PAID">Paid</option>
-                      <option value="CANCELLED">Cancelled</option>
-                    </select>
-                  </div>
-                  <button
-                      onClick={handleUpdatePaymentStatus}
-                      disabled={updating || paymentStatus === billing.paymentStatus}
-                      className="w-full bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700 disabled:opacity-50"
-                  >
-                    {updating ? 'Updating...' : 'Update Status'}
-                  </button>
-                </div>
-              </div>
-          )}
-
-          <div className="bg-white rounded-lg shadow p-6">
-            <h2 className="text-xl font-bold mb-4">Patient Details</h2>
-            <div className="space-y-3">
-              {billingDetail && (
-                  <>
-                    <InfoRow label="EMBG" value={billingDetail.patientEmbg} />
-                    <InfoRow label="Phone" value={billingDetail.patientPhone} />
-                    <InfoRow label="Bill Date" value={billingDetail.billDate} />
-                  </>
-              )}
+        )}
+
+        <div className="bg-white rounded-lg shadow p-6">
+          <h2 className="text-xl font-bold mb-4">Patient Details</h2>
+          <div className="space-y-3">
+            {billingDetail && (
+              <>
+                <InfoRow label="EMBG" value={billingDetail.patientEmbg} />
+                <InfoRow label="Phone" value={billingDetail.patientPhone} />
+                <InfoRow label="Bill Date" value={billingDetail.billDate} />
+              </>
+            )}
+          </div>
+        </div>
+      </div>
+
+      <div className="bg-white rounded-lg shadow p-6">
+        <h2 className="text-xl font-bold mb-4">Itemized Services</h2>
+
+        {billingDetail && (billingDetail.procedures.length > 0 || billingDetail.labTests.length > 0) ? (
+          <div className="space-y-4">
+            {billingDetail.procedures.length > 0 && (
+              <div>
+                <h3 className="font-semibold text-lg mb-2">Procedures</h3>
+                <table className="w-full">
+                  <thead className="bg-gray-100">
+                    <tr>
+                      <th className="px-4 py-2 text-left">Description</th>
+                      <th className="px-4 py-2 text-right">Cost</th>
+                    </tr>
+                  </thead>
+                  <tbody>
+                    {billingDetail.procedures.map((proc, idx) => (
+                      <tr key={idx} className="border-t">
+                        <td className="px-4 py-2">{proc.description}</td>
+                        <td className="px-4 py-2 text-right">${proc.cost}</td>
+                      </tr>
+                    ))}
+                  </tbody>
+                </table>
+              </div>
+            )}
+
+            {billingDetail.labTests.length > 0 && (
+              <div>
+                <h3 className="font-semibold text-lg mb-2">Lab Tests</h3>
+                <table className="w-full">
+                  <thead className="bg-gray-100">
+                    <tr>
+                      <th className="px-4 py-2 text-left">Description</th>
+                      <th className="px-4 py-2 text-right">Cost</th>
+                    </tr>
+                  </thead>
+                  <tbody>
+                    {billingDetail.labTests.map((test, idx) => (
+                      <tr key={idx} className="border-t">
+                        <td className="px-4 py-2">{test.description}</td>
+                        <td className="px-4 py-2 text-right">${test.cost}</td>
+                      </tr>
+                    ))}
+                  </tbody>
+                </table>
+              </div>
+            )}
+
+            <div className="border-t-2 pt-4 mt-4 flex justify-end">
+              <div className="text-right">
+                <p className="text-gray-600">Total Amount:</p>
+                <p className="text-2xl font-bold text-purple-600">${billing.totalCost}</p>
+              </div>
             </div>
           </div>
-        </div>
-
-        <div className="bg-white rounded-lg shadow p-6">
-          <h2 className="text-xl font-bold mb-4">Itemized Services</h2>
-
-          {billingDetail && (billingDetail.procedures.length > 0 || billingDetail.labTests.length > 0) ? (
-              <div className="space-y-4">
-                {billingDetail.procedures.length > 0 && (
-                    <div>
-                      <h3 className="font-semibold text-lg mb-2">Procedures</h3>
-                      <table className="w-full">
-                        <thead className="bg-gray-100">
-                        <tr>
-                          <th className="px-4 py-2 text-left">Description</th>
-                          <th className="px-4 py-2 text-right">Cost</th>
-                        </tr>
-                        </thead>
-                        <tbody>
-                        {billingDetail.procedures.map((proc, idx) => (
-                            <tr key={idx} className="border-t">
-                              <td className="px-4 py-2">{proc.description}</td>
-                              <td className="px-4 py-2 text-right">${proc.cost}</td>
-                            </tr>
-                        ))}
-                        </tbody>
-                      </table>
-                    </div>
-                )}
-
-                {billingDetail.labTests.length > 0 && (
-                    <div>
-                      <h3 className="font-semibold text-lg mb-2">Lab Tests</h3>
-                      <table className="w-full">
-                        <thead className="bg-gray-100">
-                        <tr>
-                          <th className="px-4 py-2 text-left">Description</th>
-                          <th className="px-4 py-2 text-right">Cost</th>
-                        </tr>
-                        </thead>
-                        <tbody>
-                        {billingDetail.labTests.map((test, idx) => (
-                            <tr key={idx} className="border-t">
-                              <td className="px-4 py-2">{test.description}</td>
-                              <td className="px-4 py-2 text-right">${test.cost}</td>
-                            </tr>
-                        ))}
-                        </tbody>
-                      </table>
-                    </div>
-                )}
-
-                <div className="border-t-2 pt-4 mt-4 flex justify-end">
-                  <div className="text-right">
-                    <p className="text-gray-600">Total Amount:</p>
-                    <p className="text-2xl font-bold text-purple-600">${billing.totalCost}</p>
-                  </div>
-                </div>
-              </div>
-          ) : (
-              <p className="text-gray-500">No services itemized for this billing record.</p>
-          )}
-        </div>
-      </div>
+        ) : (
+          <p className="text-gray-500">No services itemized for this billing record.</p>
+        )}
+      </div>
+    </div>
   );
 }
@@ -235,8 +235,8 @@
 function InfoRow({ label, value }) {
   return (
-      <div className="flex justify-between">
-        <span className="text-gray-800">{label}:</span>
-        <span className="text-gray-800">{value || 'N/A'}</span>
-      </div>
+    <div className="flex justify-between">
+      <span className="text-gray-800">{label}:</span>
+      <span className="text-gray-800">{value || 'N/A'}</span>
+    </div>
   );
 }
Index: frontend/src/pages/billing/BillingList.js
===================================================================
--- frontend/src/pages/billing/BillingList.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/billing/BillingList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -89,6 +89,6 @@
       // Refresh the list
       const response = user.role === 'BILLING_ADMIN'
-          ? await billingService.getAllBillings()
-          : await billingService.getBillingHistoryForPatient(patientId || user.patientId);
+        ? await billingService.getAllBillings()
+        : await billingService.getBillingHistoryForPatient(patientId || user.patientId);
       setBillings(response.data || []);
     } catch (err) {
@@ -101,8 +101,8 @@
   if (user.role === 'DOCTOR' || user.role === 'LAB_TECHNICIAN') {
     return (
-        <div style={{ padding: '20px', textAlign: 'center' }}>
-          <h1 className="text-2xl font-bold" style={{ color: '#7c3aed', marginBottom: '10px' }}>Access Denied</h1>
-          <p style={{ color: 'var(--color-neutral-600)' }}>You do not have permission to access billing records.</p>
-        </div>
+      <div style={{ padding: '20px', textAlign: 'center' }}>
+        <h1 className="text-2xl font-bold" style={{ color: '#7c3aed', marginBottom: '10px' }}>Access Denied</h1>
+        <p style={{ color: 'var(--color-neutral-600)' }}>You do not have permission to access billing records.</p>
+      </div>
     );
   }
@@ -111,73 +111,73 @@
 
   return (
-      <div>
-        <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>{patientId ? 'Patient Billing History' : 'Billing Records'}</h1>
-
-        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
-        {success && <SuccessAlert message={success} onClose={() => setSuccess(null)} />}
-
-        {/* Filters for Billing Admin */}
-        {user.role === 'BILLING_ADMIN' && (
-            <div className="bg-white rounded-lg shadow p-6 mb-6">
-              <h2 className="text-lg font-bold mb-4">Filters</h2>
-              <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
+    <div>
+      <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>{patientId ? 'Patient Billing History' : 'Billing Records'}</h1>
+
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+      {success && <SuccessAlert message={success} onClose={() => setSuccess(null)} />}
+
+      {/* Filters for Billing Admin */}
+      {user.role === 'BILLING_ADMIN' && (
+        <div className="bg-white rounded-lg shadow p-6 mb-6">
+          <h2 className="text-lg font-bold mb-4">Filters</h2>
+          <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
+            <div>
+              <label className="block text-sm font-semibold mb-2">Status</label>
+              <select
+                value={statusFilter}
+                onChange={(e) => setStatusFilter(e.target.value)}
+                className="w-full px-4 py-2 border rounded-lg"
+              >
+                <option value="">All Statuses</option>
+                <option value="PENDING">Pending</option>
+                <option value="PAID">Paid</option>
+                <option value="PROCESSING">Processing</option>
+              </select>
+            </div>
+            <div>
+              <label className="block text-sm font-semibold mb-2">Patient</label>
+              <select
+                value={patientFilter}
+                onChange={(e) => setPatientFilter(e.target.value)}
+                className="w-full px-4 py-2 border rounded-lg"
+              >
+                <option value="">All Patients</option>
+                {patients.map(p => (
+                  <option key={p.patientId} value={`${p.firstName} ${p.lastName}`}>
+                    {p.firstName} {p.lastName}
+                  </option>
+                ))}
+              </select>
+            </div>
+          </div>
+        </div>
+      )}
+
+      {/* Pending Billing Records Section (for Billing Admin) */}
+      {user.role === 'BILLING_ADMIN' && pendingBillings.length > 0 && (
+        <div className="bg-yellow-50 rounded-lg shadow p-6 mb-6 border-l-4 border-yellow-500">
+          <h2 className="text-lg font-bold mb-4">Pending Billing Records ({pendingBillings.length})</h2>
+          <div className="space-y-3">
+            {pendingBillings.map(billing => (
+              <div key={billing.billId} className="bg-white rounded p-4 flex justify-between items-center">
                 <div>
-                  <label className="block text-sm font-semibold mb-2">Status</label>
-                  <select
-                      value={statusFilter}
-                      onChange={(e) => setStatusFilter(e.target.value)}
-                      className="w-full px-4 py-2 border rounded-lg"
-                  >
-                    <option value="">All Statuses</option>
-                    <option value="PENDING">Pending</option>
-                    <option value="PAID">Paid</option>
-                    <option value="PROCESSING">Processing</option>
-                  </select>
+                  <p className="font-semibold">{billing.patientName}</p>
+                  <p className="text-sm text-gray-600">${billing.totalCost}</p>
                 </div>
-                <div>
-                  <label className="block text-sm font-semibold mb-2">Patient</label>
-                  <select
-                      value={patientFilter}
-                      onChange={(e) => setPatientFilter(e.target.value)}
-                      className="w-full px-4 py-2 border rounded-lg"
-                  >
-                    <option value="">All Patients</option>
-                    {patients.map(p => (
-                        <option key={p.patientId} value={`${p.firstName} ${p.lastName}`}>
-                          {p.firstName} {p.lastName}
-                        </option>
-                    ))}
-                  </select>
-                </div>
+                <button
+                  onClick={() => handleUpdateStatus(billing.billId, 'PAID')}
+                  className="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 text-sm"
+                >
+                  Mark Paid
+                </button>
               </div>
-            </div>
-        )}
-
-        {/* Pending Billing Records Section (for Billing Admin) */}
-        {user.role === 'BILLING_ADMIN' && pendingBillings.length > 0 && (
-            <div className="bg-yellow-50 rounded-lg shadow p-6 mb-6 border-l-4 border-yellow-500">
-              <h2 className="text-lg font-bold mb-4">Pending Billing Records ({pendingBillings.length})</h2>
-              <div className="space-y-3">
-                {pendingBillings.map(billing => (
-                    <div key={billing.billId} className="bg-white rounded p-4 flex justify-between items-center">
-                      <div>
-                        <p className="font-semibold">{billing.patientName}</p>
-                        <p className="text-sm text-gray-600">${billing.totalCost}</p>
-                      </div>
-                      <button
-                          onClick={() => handleUpdateStatus(billing.billId, 'PAID')}
-                          className="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 text-sm"
-                      >
-                        Mark Paid
-                      </button>
-                    </div>
-                ))}
-              </div>
-            </div>
-        )}
-
-        <div className="bg-white rounded-lg shadow overflow-hidden">
-          <table className="w-full">
-            <thead className="bg-gray-100">
+            ))}
+          </div>
+        </div>
+      )}
+
+      <div className="bg-white rounded-lg shadow overflow-hidden">
+        <table className="w-full">
+          <thead className="bg-gray-100">
             <tr>
               <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
@@ -187,37 +187,37 @@
               <th className="px-6 py-3 text-left text-sm font-semibold">Actions</th>
             </tr>
-            </thead>
-            <tbody>
+          </thead>
+          <tbody>
             {filteredBillings.map(billing => (
-                <tr key={billing.billId} className="border-t hover:bg-gray-50">
-                  <td className="px-6 py-3">{billing.patientName}</td>
-                  <td className="px-6 py-3">${billing.totalCost}</td>
-                  <td className="px-6 py-3">
+              <tr key={billing.billId} className="border-t hover:bg-gray-50">
+                <td className="px-6 py-3">{billing.patientName}</td>
+                <td className="px-6 py-3">${billing.totalCost}</td>
+                <td className="px-6 py-3">
                   <span className={`px-3 py-1 rounded text-sm font-semibold ${
-                      billing.paymentStatus === 'PENDING' ? 'bg-yellow-100 text-yellow-800' :
-                          billing.paymentStatus === 'PAID' ? 'bg-green-100 text-green-800' :
-                              'bg-red-100 text-red-800'
+                    billing.paymentStatus === 'PENDING' ? 'bg-yellow-100 text-yellow-800' :
+                    billing.paymentStatus === 'PAID' ? 'bg-green-100 text-green-800' :
+                    'bg-red-100 text-red-800'
                   }`}>
                     {billing.paymentStatus}
                   </span>
-                  </td>
-                  <td className="px-6 py-3">{billing.paymentDate || 'Not paid'}</td>
-                  <td className="px-6 py-3">
-                    <Link to={`/billing/${billing.billId}`} style={{ color: '#7c3aed', textDecoration: 'none', fontWeight: '400' }} onMouseEnter={(e) => e.currentTarget.style.textDecoration = 'underline'} onMouseLeave={(e) => e.currentTarget.style.textDecoration = 'none'}>
-                      View
-                    </Link>
-                  </td>
-                </tr>
+                </td>
+                <td className="px-6 py-3">{billing.paymentDate || 'Not paid'}</td>
+                <td className="px-6 py-3">
+                  <Link to={`/billing/${billing.billId}`} style={{ color: '#7c3aed', textDecoration: 'none', fontWeight: '400' }} onMouseEnter={(e) => e.currentTarget.style.textDecoration = 'underline'} onMouseLeave={(e) => e.currentTarget.style.textDecoration = 'none'}>
+                    View
+                  </Link>
+                </td>
+              </tr>
             ))}
-            </tbody>
-          </table>
-
-          {filteredBillings.length === 0 && (
-              <div className="p-6 text-center text-gray-500">
-                {billings.length === 0 ? 'No billing records found' : 'No records match the selected filters'}
-              </div>
-          )}
-        </div>
+          </tbody>
+        </table>
+
+        {filteredBillings.length === 0 && (
+          <div className="p-6 text-center text-gray-500">
+            {billings.length === 0 ? 'No billing records found' : 'No records match the selected filters'}
+          </div>
+        )}
       </div>
+    </div>
   );
 }
Index: frontend/src/pages/departments/DepartmentDetail.js
===================================================================
--- frontend/src/pages/departments/DepartmentDetail.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/departments/DepartmentDetail.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -19,8 +19,5 @@
 
   useEffect(() => {
-    fetchDepartmentAndDoctors();
-  }, [departmentId]);
-
-  const fetchDepartmentAndDoctors = async () => {
+    const fetchDepartmentAndDoctors = async () => {
     try {
       setLoading(true);
@@ -39,5 +36,8 @@
       setLoading(false);
     }
-  };
+    };
+
+    fetchDepartmentAndDoctors();
+  }, [departmentId]);
 
   if (loading) return <Loading />;
Index: frontend/src/pages/departments/DoctorsByDepartment.js
===================================================================
--- frontend/src/pages/departments/DoctorsByDepartment.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/departments/DoctorsByDepartment.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -19,8 +19,5 @@
 
   useEffect(() => {
-    fetchDepartmentAndDoctors();
-  }, [departmentId]);
-
-  const fetchDepartmentAndDoctors = async () => {
+    const fetchDepartmentAndDoctors = async () => {
     try {
       setLoading(true);
@@ -39,5 +36,8 @@
       setLoading(false);
     }
-  };
+    };
+
+    fetchDepartmentAndDoctors();
+  }, [departmentId]);
 
   if (loading) return <Loading />;
Index: frontend/src/pages/doctors/DoctorDetail.js
===================================================================
--- frontend/src/pages/doctors/DoctorDetail.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/doctors/DoctorDetail.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -24,19 +24,19 @@
 
   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]);
-
-  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);
-    }
-  };
 
   if (loading) return <Loading />;
Index: frontend/src/pages/doctors/DoctorForm.js
===================================================================
--- frontend/src/pages/doctors/DoctorForm.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/doctors/DoctorForm.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -22,26 +22,26 @@
   useEffect(() => {
     if (id) {
+      const fetchDoctor = async () => {
+        try {
+          setLoading(true);
+          const response = await doctorService.getDoctorById(id);
+          setFormData({
+            firstName: response.data.firstName,
+            lastName: response.data.lastName,
+            emailAddress: response.data.emailAddress,
+            levelId: response.data.level?.levelId || '',
+            specializationId: response.data.specialization?.specializationId || '',
+            departmentId: response.data.department?.departmentId || '',
+          });
+        } catch (err) {
+          setError('Failed to fetch doctor');
+        } finally {
+          setLoading(false);
+        }
+      };
+
       fetchDoctor();
     }
   }, [id]);
-
-  const fetchDoctor = async () => {
-    try {
-      setLoading(true);
-      const response = await doctorService.getDoctorById(id);
-      setFormData({
-        firstName: response.data.firstName,
-        lastName: response.data.lastName,
-        emailAddress: response.data.emailAddress,
-        levelId: response.data.level?.levelId || '',
-        specializationId: response.data.specialization?.specializationId || '',
-        departmentId: response.data.department?.departmentId || '',
-      });
-    } catch (err) {
-      setError('Failed to fetch doctor');
-    } finally {
-      setLoading(false);
-    }
-  };
 
   const handleChange = (e) => {
Index: frontend/src/pages/lab-tests/LabResultForm.js
===================================================================
--- frontend/src/pages/lab-tests/LabResultForm.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/lab-tests/LabResultForm.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -1,3 +1,3 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState } from 'react';
 import { useNavigate } from 'react-router-dom';
 import { labService } from '../../services/labService';
Index: frontend/src/pages/lab-tests/LabTestList.js
===================================================================
--- frontend/src/pages/lab-tests/LabTestList.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/lab-tests/LabTestList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -5,5 +5,5 @@
 
 function LabTestList() {
-  const user = JSON.parse(localStorage.getItem('user') || '{}');
+  const [user, setUser] = useState({});
   const isLabTechnician = user.role === 'LAB_TECHNICIAN';
 
@@ -46,4 +46,39 @@
     testDate: '',
   });
+
+  // Load user from localStorage and listen for changes
+  useEffect(() => {
+    const loadUser = () => {
+      const userStr = localStorage.getItem('user');
+      console.log('[LabTestList] Loading user from localStorage:', userStr);
+      if (userStr) {
+        try {
+          const parsedUser = JSON.parse(userStr);
+          console.log('[LabTestList] Parsed user:', parsedUser);
+          setUser(parsedUser);
+        } catch (err) {
+          console.error('Failed to parse user:', err);
+          setUser({});
+        }
+      } else {
+        console.log('[LabTestList] No user in localStorage');
+        setUser({});
+      }
+    };
+
+    console.log('[LabTestList] useEffect running - loading user');
+    loadUser();
+
+    // Listen for storage changes (other tabs/windows)
+    window.addEventListener('storage', loadUser);
+
+    // Listen for custom event (same tab changes)
+    window.addEventListener('userStorageChange', loadUser);
+
+    return () => {
+      window.removeEventListener('storage', loadUser);
+      window.removeEventListener('userStorageChange', loadUser);
+    };
+  }, []);
 
   useEffect(() => {
@@ -134,6 +169,6 @@
       setLoading(true);
 
-      // Get doctor ID from localStorage (set during login)
-      const doctorId = localStorage.getItem('doctorId') || 1;
+      // Get doctor ID from logged-in user
+      const doctorId = user.doctorId;
 
       const request = {
@@ -145,4 +180,7 @@
         notes: requestData.notes,
       };
+
+      console.log('User object:', user);
+      console.log('Sending lab test request with doctorId:', doctorId, 'Full request:', request);
 
       await labService.requestLabTest(request);
@@ -228,494 +266,494 @@
   if (isLabTechnician) {
     return (
-        <div>
-          <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>Lab Tests - Submit Results</h1>
-
-          {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
-
-          {selectedTest ? (
-              // Submit Result Form
-              <div className="bg-white rounded-lg shadow p-6 mb-6">
-                <h2 className="text-xl font-bold mb-4">Submit Lab Result</h2>
-                <div className="mb-4 p-4 bg-gray-50 rounded-lg">
-                  <p className="mb-2"><strong>Test:</strong> {selectedTest.testName}</p>
-                  <p className="mb-2"><strong>Patient:</strong> {selectedTest.patientName}</p>
-                  <p className="mb-2"><strong>Doctor:</strong> {selectedTest.doctorName}</p>
-                  <p className="mb-2"><strong>Test Date:</strong> {selectedTest.testDate}</p>
-                  {selectedTest.notes && <p><strong>Notes:</strong> {selectedTest.notes}</p>}
+      <div>
+        <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>Lab Tests - Submit Results</h1>
+
+        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+
+        {selectedTest ? (
+          // Submit Result Form
+          <div className="bg-white rounded-lg shadow p-6 mb-6">
+            <h2 className="text-xl font-bold mb-4">Submit Lab Result</h2>
+            <div className="mb-4 p-4 bg-gray-50 rounded-lg">
+              <p className="mb-2"><strong>Test:</strong> {selectedTest.testName}</p>
+              <p className="mb-2"><strong>Patient:</strong> {selectedTest.patientName}</p>
+              <p className="mb-2"><strong>Doctor:</strong> {selectedTest.doctorName}</p>
+              <p className="mb-2"><strong>Test Date:</strong> {selectedTest.testDate}</p>
+              {selectedTest.notes && <p><strong>Notes:</strong> {selectedTest.notes}</p>}
+            </div>
+
+            <form onSubmit={handleSubmitResult} className="space-y-4">
+              <div>
+                <label className="block text-sm font-semibold mb-2">Test Results *</label>
+                <textarea
+                  value={submitFormData.results}
+                  onChange={(e) => setSubmitFormData({ ...submitFormData, results: e.target.value })}
+                  placeholder="Enter detailed test results"
+                  className="w-full px-4 py-2 border rounded-lg"
+                  rows="4"
+                  required
+                />
+              </div>
+
+              <div>
+                <label className="block text-sm font-semibold mb-2">Result Date *</label>
+                <input
+                  type="date"
+                  value={submitFormData.resultDate}
+                  onChange={(e) => setSubmitFormData({ ...submitFormData, resultDate: e.target.value })}
+                  className="w-full px-4 py-2 border rounded-lg"
+                  required
+                />
+              </div>
+
+              <div className="flex gap-4">
+                <button
+                  type="submit"
+                  disabled={loading}
+                  style={{
+                    background: loading ? '#d1d5db' : '#bfdbfe',
+                    color: '#1e1035',
+                    padding: '8px 24px',
+                    borderRadius: '6px',
+                    border: 'none',
+                    cursor: loading ? 'not-allowed' : 'pointer',
+                    fontSize: '14px',
+                    fontWeight: '400'
+                  }}
+                  onMouseEnter={(e) => !loading && (e.currentTarget.style.background = '#93c5fd')}
+                  onMouseLeave={(e) => !loading && (e.currentTarget.style.background = '#bfdbfe')}
+                >
+                  {loading ? 'Submitting...' : 'Submit Result'}
+                </button>
+                <button
+                  type="button"
+                  onClick={() => {
+                    setSelectedTest(null);
+                    setSubmitFormData({
+                      results: '',
+                      resultDate: new Date().toISOString().split('T')[0],
+                    });
+                  }}
+                  className="bg-gray-400 text-white px-6 py-2 rounded hover:bg-gray-500"
+                >
+                  Cancel
+                </button>
+              </div>
+            </form>
+          </div>
+        ) : (
+          // Pending Tests List
+          <div className="bg-white rounded-lg shadow overflow-hidden">
+            <div className="p-6 border-b">
+              <h2 className="text-xl font-bold">Pending Lab Tests ({pendingTests.length})</h2>
+            </div>
+
+            {pendingTests.length === 0 ? (
+              <div className="p-6 text-center text-gray-600">
+                No pending lab tests
+              </div>
+            ) : (
+              <>
+                {/* Filters */}
+                <div className="p-6 border-b bg-gray-50">
+                  <h3 className="text-sm font-semibold mb-4">Filters</h3>
+                  <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
+                    <div>
+                      <label className="block text-sm font-semibold mb-2">Test</label>
+                      <input
+                        type="text"
+                        placeholder="Filter by test name..."
+                        value={pendingFilters.testName}
+                        onChange={(e) => setPendingFilters({...pendingFilters, testName: e.target.value})}
+                        className="w-full px-3 py-2 border rounded-lg text-sm"
+                      />
+                    </div>
+                    <div>
+                      <label className="block text-sm font-semibold mb-2">Patient</label>
+                      <input
+                        type="text"
+                        placeholder="Filter by patient name..."
+                        value={pendingFilters.patientName}
+                        onChange={(e) => setPendingFilters({...pendingFilters, patientName: e.target.value})}
+                        className="w-full px-3 py-2 border rounded-lg text-sm"
+                      />
+                    </div>
+                    <div>
+                      <label className="block text-sm font-semibold mb-2">Test Date</label>
+                      <input
+                        type="date"
+                        value={pendingFilters.testDate}
+                        onChange={(e) => setPendingFilters({...pendingFilters, testDate: e.target.value})}
+                        className="w-full px-3 py-2 border rounded-lg text-sm"
+                      />
+                    </div>
+                  </div>
+                  <button
+                    onClick={() => setPendingFilters({testName: '', patientName: '', testDate: ''})}
+                    className="mt-4 bg-gray-300 text-gray-700 px-4 py-2 rounded text-sm hover:bg-gray-400"
+                  >
+                    Clear Filters
+                  </button>
                 </div>
 
-                <form onSubmit={handleSubmitResult} className="space-y-4">
-                  <div>
-                    <label className="block text-sm font-semibold mb-2">Test Results *</label>
-                    <textarea
-                        value={submitFormData.results}
-                        onChange={(e) => setSubmitFormData({ ...submitFormData, results: e.target.value })}
-                        placeholder="Enter detailed test results"
-                        className="w-full px-4 py-2 border rounded-lg"
-                        rows="4"
-                        required
-                    />
+                {/* Filtered Table */}
+                <table className="w-full">
+                  <thead className="bg-gray-100">
+                    <tr>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Test</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Doctor</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Requested</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Test Date</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Notes</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Action</th>
+                    </tr>
+                  </thead>
+                  <tbody>
+                    {pendingTests
+                      .filter((test) => {
+                        const testName = (test.testName || '').toLowerCase();
+                        const patientName = (test.patientName || '').toLowerCase();
+                        const testDate = (test.testDate || '');
+
+                        return (
+                          testName.includes(pendingFilters.testName.toLowerCase()) &&
+                          patientName.includes(pendingFilters.patientName.toLowerCase()) &&
+                          (pendingFilters.testDate === '' || testDate === pendingFilters.testDate)
+                        );
+                      })
+                      .map((test, index) => (
+                    <tr key={index} className="border-t hover:bg-gray-50">
+                      <td className="px-6 py-3 font-medium">{test.testName}</td>
+                      <td className="px-6 py-3">{test.patientName}</td>
+                      <td className="px-6 py-3">{test.doctorName}</td>
+                      <td className="px-6 py-3 text-green-600">{test.requestDate}</td>
+                      <td className="px-6 py-3 text-purple-600">{test.testDate}</td>
+                      <td className="px-6 py-3 text-gray-600 text-sm">{test.notes || '-'}</td>
+                      <td className="px-6 py-3">
+                        <button
+                          onClick={() => setSelectedTest(test)}
+                          style={{
+                            background: '#bfdbfe',
+                            color: '#1e1035',
+                            padding: '6px 12px',
+                            borderRadius: '4px',
+                            border: 'none',
+                            cursor: 'pointer',
+                            fontSize: '12px',
+                            fontWeight: '400'
+                          }}
+                          onMouseEnter={(e) => e.currentTarget.style.background = '#93c5fd'}
+                          onMouseLeave={(e) => e.currentTarget.style.background = '#bfdbfe'}
+                        >
+                          Submit Result
+                        </button>
+                      </td>
+                    </tr>
+                  ))}
+                  </tbody>
+                </table>
+              </>
+            )}
+          </div>
+        )}
+
+        {/* Submitted Tests History */}
+        {!selectedTest && (
+          <div className="bg-white rounded-lg shadow overflow-hidden mt-6">
+            <div className="p-6 border-b">
+              <h2 className="text-xl font-bold">Submitted Lab Results History ({submittedTests.length})</h2>
+            </div>
+
+            {submittedTests.length === 0 ? (
+              <div className="p-6 text-center text-gray-600">
+                No submitted lab results yet
+              </div>
+            ) : (
+              <>
+                {/* Filters */}
+                <div className="p-6 border-b bg-gray-50">
+                  <h3 className="text-sm font-semibold mb-4">Filters</h3>
+                  <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
+                    <div>
+                      <label className="block text-sm font-semibold mb-2">Test</label>
+                      <input
+                        type="text"
+                        placeholder="Filter by test name..."
+                        value={submittedFilters.testName}
+                        onChange={(e) => setSubmittedFilters({...submittedFilters, testName: e.target.value})}
+                        className="w-full px-3 py-2 border rounded-lg text-sm"
+                      />
+                    </div>
+                    <div>
+                      <label className="block text-sm font-semibold mb-2">Patient</label>
+                      <input
+                        type="text"
+                        placeholder="Filter by patient name..."
+                        value={submittedFilters.patientName}
+                        onChange={(e) => setSubmittedFilters({...submittedFilters, patientName: e.target.value})}
+                        className="w-full px-3 py-2 border rounded-lg text-sm"
+                      />
+                    </div>
+                    <div>
+                      <label className="block text-sm font-semibold mb-2">Test Date</label>
+                      <input
+                        type="date"
+                        value={submittedFilters.testDate}
+                        onChange={(e) => setSubmittedFilters({...submittedFilters, testDate: e.target.value})}
+                        className="w-full px-3 py-2 border rounded-lg text-sm"
+                      />
+                    </div>
                   </div>
-
-                  <div>
-                    <label className="block text-sm font-semibold mb-2">Result Date *</label>
-                    <input
-                        type="date"
-                        value={submitFormData.resultDate}
-                        onChange={(e) => setSubmitFormData({ ...submitFormData, resultDate: e.target.value })}
-                        className="w-full px-4 py-2 border rounded-lg"
-                        required
-                    />
-                  </div>
-
-                  <div className="flex gap-4">
-                    <button
-                        type="submit"
-                        disabled={loading}
-                        style={{
-                          background: loading ? '#d1d5db' : '#bfdbfe',
-                          color: '#1e1035',
-                          padding: '8px 24px',
-                          borderRadius: '6px',
-                          border: 'none',
-                          cursor: loading ? 'not-allowed' : 'pointer',
-                          fontSize: '14px',
-                          fontWeight: '400'
-                        }}
-                        onMouseEnter={(e) => !loading && (e.currentTarget.style.background = '#93c5fd')}
-                        onMouseLeave={(e) => !loading && (e.currentTarget.style.background = '#bfdbfe')}
-                    >
-                      {loading ? 'Submitting...' : 'Submit Result'}
-                    </button>
-                    <button
-                        type="button"
-                        onClick={() => {
-                          setSelectedTest(null);
-                          setSubmitFormData({
-                            results: '',
-                            resultDate: new Date().toISOString().split('T')[0],
-                          });
-                        }}
-                        className="bg-gray-400 text-white px-6 py-2 rounded hover:bg-gray-500"
-                    >
-                      Cancel
-                    </button>
-                  </div>
-                </form>
-              </div>
-          ) : (
-              // Pending Tests List
-              <div className="bg-white rounded-lg shadow overflow-hidden">
-                <div className="p-6 border-b">
-                  <h2 className="text-xl font-bold">Pending Lab Tests ({pendingTests.length})</h2>
+                  <button
+                    onClick={() => setSubmittedFilters({testName: '', patientName: '', testDate: ''})}
+                    className="mt-4 bg-gray-300 text-gray-700 px-4 py-2 rounded text-sm hover:bg-gray-400"
+                  >
+                    Clear Filters
+                  </button>
                 </div>
 
-                {pendingTests.length === 0 ? (
-                    <div className="p-6 text-center text-gray-600">
-                      No pending lab tests
-                    </div>
-                ) : (
-                    <>
-                      {/* Filters */}
-                      <div className="p-6 border-b bg-gray-50">
-                        <h3 className="text-sm font-semibold mb-4">Filters</h3>
-                        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
-                          <div>
-                            <label className="block text-sm font-semibold mb-2">Test</label>
-                            <input
-                                type="text"
-                                placeholder="Filter by test name..."
-                                value={pendingFilters.testName}
-                                onChange={(e) => setPendingFilters({...pendingFilters, testName: e.target.value})}
-                                className="w-full px-3 py-2 border rounded-lg text-sm"
-                            />
-                          </div>
-                          <div>
-                            <label className="block text-sm font-semibold mb-2">Patient</label>
-                            <input
-                                type="text"
-                                placeholder="Filter by patient name..."
-                                value={pendingFilters.patientName}
-                                onChange={(e) => setPendingFilters({...pendingFilters, patientName: e.target.value})}
-                                className="w-full px-3 py-2 border rounded-lg text-sm"
-                            />
-                          </div>
-                          <div>
-                            <label className="block text-sm font-semibold mb-2">Test Date</label>
-                            <input
-                                type="date"
-                                value={pendingFilters.testDate}
-                                onChange={(e) => setPendingFilters({...pendingFilters, testDate: e.target.value})}
-                                className="w-full px-3 py-2 border rounded-lg text-sm"
-                            />
-                          </div>
-                        </div>
-                        <button
-                            onClick={() => setPendingFilters({testName: '', patientName: '', testDate: ''})}
-                            className="mt-4 bg-gray-300 text-gray-700 px-4 py-2 rounded text-sm hover:bg-gray-400"
-                        >
-                          Clear Filters
-                        </button>
-                      </div>
-
-                      {/* Filtered Table */}
-                      <table className="w-full">
-                        <thead className="bg-gray-100">
-                        <tr>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Test</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Doctor</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Requested</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Test Date</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Notes</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Action</th>
-                        </tr>
-                        </thead>
-                        <tbody>
-                        {pendingTests
-                            .filter((test) => {
-                              const testName = (test.testName || '').toLowerCase();
-                              const patientName = (test.patientName || '').toLowerCase();
-                              const testDate = (test.testDate || '');
-
-                              return (
-                                  testName.includes(pendingFilters.testName.toLowerCase()) &&
-                                  patientName.includes(pendingFilters.patientName.toLowerCase()) &&
-                                  (pendingFilters.testDate === '' || testDate === pendingFilters.testDate)
-                              );
-                            })
-                            .map((test, index) => (
-                                <tr key={index} className="border-t hover:bg-gray-50">
-                                  <td className="px-6 py-3 font-medium">{test.testName}</td>
-                                  <td className="px-6 py-3">{test.patientName}</td>
-                                  <td className="px-6 py-3">{test.doctorName}</td>
-                                  <td className="px-6 py-3 text-green-600">{test.requestDate}</td>
-                                  <td className="px-6 py-3 text-purple-600">{test.testDate}</td>
-                                  <td className="px-6 py-3 text-gray-600 text-sm">{test.notes || '-'}</td>
-                                  <td className="px-6 py-3">
-                                    <button
-                                        onClick={() => setSelectedTest(test)}
-                                        style={{
-                                          background: '#bfdbfe',
-                                          color: '#1e1035',
-                                          padding: '6px 12px',
-                                          borderRadius: '4px',
-                                          border: 'none',
-                                          cursor: 'pointer',
-                                          fontSize: '12px',
-                                          fontWeight: '400'
-                                        }}
-                                        onMouseEnter={(e) => e.currentTarget.style.background = '#93c5fd'}
-                                        onMouseLeave={(e) => e.currentTarget.style.background = '#bfdbfe'}
-                                    >
-                                      Submit Result
-                                    </button>
-                                  </td>
-                                </tr>
-                            ))}
-                        </tbody>
-                      </table>
-                    </>
-                )}
-              </div>
-          )}
-
-          {/* Submitted Tests History */}
-          {!selectedTest && (
-              <div className="bg-white rounded-lg shadow overflow-hidden mt-6">
-                <div className="p-6 border-b">
-                  <h2 className="text-xl font-bold">Submitted Lab Results History ({submittedTests.length})</h2>
-                </div>
-
-                {submittedTests.length === 0 ? (
-                    <div className="p-6 text-center text-gray-600">
-                      No submitted lab results yet
-                    </div>
-                ) : (
-                    <>
-                      {/* Filters */}
-                      <div className="p-6 border-b bg-gray-50">
-                        <h3 className="text-sm font-semibold mb-4">Filters</h3>
-                        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
-                          <div>
-                            <label className="block text-sm font-semibold mb-2">Test</label>
-                            <input
-                                type="text"
-                                placeholder="Filter by test name..."
-                                value={submittedFilters.testName}
-                                onChange={(e) => setSubmittedFilters({...submittedFilters, testName: e.target.value})}
-                                className="w-full px-3 py-2 border rounded-lg text-sm"
-                            />
-                          </div>
-                          <div>
-                            <label className="block text-sm font-semibold mb-2">Patient</label>
-                            <input
-                                type="text"
-                                placeholder="Filter by patient name..."
-                                value={submittedFilters.patientName}
-                                onChange={(e) => setSubmittedFilters({...submittedFilters, patientName: e.target.value})}
-                                className="w-full px-3 py-2 border rounded-lg text-sm"
-                            />
-                          </div>
-                          <div>
-                            <label className="block text-sm font-semibold mb-2">Test Date</label>
-                            <input
-                                type="date"
-                                value={submittedFilters.testDate}
-                                onChange={(e) => setSubmittedFilters({...submittedFilters, testDate: e.target.value})}
-                                className="w-full px-3 py-2 border rounded-lg text-sm"
-                            />
-                          </div>
-                        </div>
-                        <button
-                            onClick={() => setSubmittedFilters({testName: '', patientName: '', testDate: ''})}
-                            className="mt-4 bg-gray-300 text-gray-700 px-4 py-2 rounded text-sm hover:bg-gray-400"
-                        >
-                          Clear Filters
-                        </button>
-                      </div>
-
-                      {/* Filtered Results Table */}
-                      <table className="w-full">
-                        <thead className="bg-gray-100">
-                        <tr>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Test</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Test Date</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Result Date</th>
-                          <th className="px-6 py-3 text-left text-sm font-semibold">Status</th>
-                        </tr>
-                        </thead>
-                        <tbody>
-                        {submittedTests
-                            .filter((test) => {
-                              const testName = (test.testName || '').toLowerCase();
-                              const patientName = (test.patientName || '').toLowerCase();
-                              const testDate = (test.testDate || '');
-
-                              return (
-                                  testName.includes(submittedFilters.testName.toLowerCase()) &&
-                                  patientName.includes(submittedFilters.patientName.toLowerCase()) &&
-                                  (submittedFilters.testDate === '' || testDate === submittedFilters.testDate)
-                              );
-                            })
-                            .map((test, index) => (
-                                <tr key={index} className="border-t hover:bg-gray-50">
-                                  <td className="px-6 py-3 font-medium">{test.testName || test.description || 'Lab Test'}</td>
-                                  <td className="px-6 py-3">{test.patientName || 'N/A'}</td>
-                                  <td className="px-6 py-3">{test.testDate || 'N/A'}</td>
-                                  <td className="px-6 py-3 text-green-600">{test.resultDate || test.createdDate || 'N/A'}</td>
-                                  <td className="px-6 py-3">
+                {/* Filtered Results Table */}
+                <table className="w-full">
+                  <thead className="bg-gray-100">
+                    <tr>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Test</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Patient</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Test Date</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Result Date</th>
+                      <th className="px-6 py-3 text-left text-sm font-semibold">Status</th>
+                    </tr>
+                  </thead>
+                  <tbody>
+                    {submittedTests
+                      .filter((test) => {
+                        const testName = (test.testName || '').toLowerCase();
+                        const patientName = (test.patientName || '').toLowerCase();
+                        const testDate = (test.testDate || '');
+
+                        return (
+                          testName.includes(submittedFilters.testName.toLowerCase()) &&
+                          patientName.includes(submittedFilters.patientName.toLowerCase()) &&
+                          (submittedFilters.testDate === '' || testDate === submittedFilters.testDate)
+                        );
+                      })
+                      .map((test, index) => (
+                        <tr key={index} className="border-t hover:bg-gray-50">
+                          <td className="px-6 py-3 font-medium">{test.testName || test.description || 'Lab Test'}</td>
+                          <td className="px-6 py-3">{test.patientName || 'N/A'}</td>
+                          <td className="px-6 py-3">{test.testDate || 'N/A'}</td>
+                          <td className="px-6 py-3 text-green-600">{test.resultDate || test.createdDate || 'N/A'}</td>
+                          <td className="px-6 py-3">
                             <span className="px-3 py-1 bg-green-100 text-green-800 rounded-full text-sm font-semibold">
                               Submitted
                             </span>
-                                  </td>
-                                </tr>
-                            ))}
-                        </tbody>
-                      </table>
-                    </>
-                )}
-              </div>
+                          </td>
+                        </tr>
+                      ))}
+                  </tbody>
+                </table>
+              </>
+            )}
+          </div>
+        )}
+      </div>
+    );
+  }
+
+  return (
+    <div>
+      <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>Lab Tests</h1>
+
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+
+      {/* Search Form */}
+      <div className="bg-white rounded-lg shadow p-6 mb-6">
+        <h2 className="text-xl font-bold mb-4">Search Patient</h2>
+        <form onSubmit={handleSearch} className="space-y-4">
+          <div className="flex gap-4">
+            <div className="flex-1">
+              <label className="block text-sm font-semibold mb-2">Patient EMBG</label>
+              <input
+                type="text"
+                value={embg}
+                onChange={(e) => setEmbg(e.target.value)}
+                placeholder="e.g., 1402994123456"
+                className="w-full px-4 py-2 border rounded-lg"
+              />
+            </div>
+            <div className="flex items-end">
+              <button
+                type="submit"
+                disabled={loading}
+                className="bg-purple-600 text-white px-8 py-2 rounded-full hover:bg-purple-700 disabled:bg-gray-400"
+              >
+                {loading ? 'Searching...' : 'Search'}
+              </button>
+            </div>
+          </div>
+        </form>
+      </div>
+
+      {/* Patient Lab Tests */}
+      {searched && patient && (
+        <div className="space-y-6">
+          {/* Patient Info */}
+          <div className="bg-white rounded-lg shadow p-6">
+            <div className="flex justify-between items-start mb-4">
+              <h2 className="text-2xl font-bold">{patient.firstName} {patient.lastName}</h2>
+              {!showRequestForm && (
+                <button
+                  onClick={() => setShowRequestForm(true)}
+                  className="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700"
+                >
+                  Request Lab Test
+                </button>
+              )}
+            </div>
+            <div className="grid grid-cols-4 gap-4">
+              <div>
+                <p className="text-sm text-gray-600">EMBG</p>
+                <p className="font-semibold">{patient.embg}</p>
+              </div>
+              <div>
+                <p className="text-sm text-gray-600">Blood Type</p>
+                <p className="font-semibold">{patient.bloodType || 'N/A'}</p>
+              </div>
+              <div>
+                <p className="text-sm text-gray-600">Date of Birth</p>
+                <p className="font-semibold">{patient.dateOfBirth}</p>
+              </div>
+            </div>
+          </div>
+
+          {/* Request Lab Test Form */}
+          {showRequestForm && (
+            <div className="bg-white rounded-lg shadow p-6">
+              <h3 className="text-xl font-bold mb-4">Request Lab Test</h3>
+              <form onSubmit={handleRequestTest} className="space-y-4">
+                <div className="grid grid-cols-2 gap-4">
+                  <div>
+                    <label className="block text-sm font-semibold mb-2">Test</label>
+                    <select
+                      value={requestData.testId}
+                      onChange={(e) => setRequestData({ ...requestData, testId: e.target.value })}
+                      className="w-full px-4 py-2 border rounded-lg"
+                      required
+                    >
+                      <option value="">Select a test</option>
+                      {availableTests.map((test) => (
+                        <option key={test.testId} value={test.testId}>
+                          {test.testName} (${test.cost})
+                        </option>
+                      ))}
+                    </select>
+                  </div>
+                  <div>
+                    <label className="block text-sm font-semibold mb-2">Test Date</label>
+                    <input
+                      type="date"
+                      value={requestData.testDate}
+                      onChange={(e) => setRequestData({ ...requestData, testDate: e.target.value })}
+                      className="w-full px-4 py-2 border rounded-lg"
+                    />
+                  </div>
+                </div>
+                <div>
+                  <label className="block text-sm font-semibold mb-2">Notes</label>
+                  <textarea
+                    value={requestData.notes}
+                    onChange={(e) => setRequestData({ ...requestData, notes: e.target.value })}
+                    placeholder="Additional notes for the lab technician"
+                    className="w-full px-4 py-2 border rounded-lg"
+                    rows="3"
+                  />
+                </div>
+                <div className="flex gap-4">
+                  <button
+                    type="submit"
+                    disabled={loading}
+                    className="bg-green-600 text-white px-6 py-2 rounded hover:bg-green-700 disabled:bg-gray-400"
+                  >
+                    {loading ? 'Requesting...' : 'Request Test'}
+                  </button>
+                  <button
+                    type="button"
+                    onClick={() => setShowRequestForm(false)}
+                    className="bg-gray-400 text-white px-6 py-2 rounded hover:bg-gray-500"
+                  >
+                    Cancel
+                  </button>
+                </div>
+              </form>
+            </div>
+          )}
+
+          {/* Test Requests */}
+          {labTestRequests && labTestRequests.length > 0 && (
+            <div className="bg-white rounded-lg shadow p-6">
+              <h3 className="text-xl font-bold mb-4">Lab Test Requests</h3>
+              <div className="space-y-3">
+                {labTestRequests.map((request) => (
+                  <div key={request.testId} className="border-l-4 border-purple-500 pl-4 py-2">
+                    <p className="font-semibold text-lg">{request.testName}</p>
+                    <p className="text-sm text-gray-600">Requested by: {request.doctorName}</p>
+                    <p className="text-sm text-gray-600">Test Date: {request.requestDate}</p>
+                    {request.notes && (
+                      <p className="text-sm text-gray-600">Notes: {request.notes}</p>
+                    )}
+                  </div>
+                ))}
+              </div>
+            </div>
+          )}
+
+          {/* Lab Test Results */}
+          {labResults && labResults.length > 0 && (
+            <div className="bg-white rounded-lg shadow p-6">
+              <h3 className="text-xl font-bold mb-4">Lab Test Results</h3>
+              <div className="space-y-4">
+                {labResults.map((result) => (
+                  <div key={result.resultId} className="border-l-4 border-green-500 pl-4 py-3 bg-green-50 rounded">
+                    <p className="font-semibold text-lg text-green-700">{result.testName}</p>
+                    <p className="text-sm text-gray-700 mt-2"><strong>Results:</strong> {result.results}</p>
+                    <p className="text-sm text-gray-600">Result Date: {result.resultDate}</p>
+                  </div>
+                ))}
+              </div>
+            </div>
+          )}
+
+          {/* Link to submit results */}
+          {labTestRequests && labTestRequests.length > 0 && (
+            <div className="bg-yellow-50 rounded-lg p-6">
+              <h3 className="text-lg font-semibold text-yellow-800 mb-3">Lab Technician: Submit Test Results</h3>
+              <p className="text-sm text-gray-700 mb-4">
+                {labTestRequests.length} test{labTestRequests.length !== 1 ? 's' : ''} awaiting results
+              </p>
+              <a
+                href="/lab-tests/results"
+                className="inline-block bg-yellow-600 text-white px-6 py-2 rounded hover:bg-yellow-700"
+              >
+                Submit Lab Results
+              </a>
+            </div>
+          )}
+
+          {/* No requests message */}
+          {(!labTestRequests || labTestRequests.length === 0) && !labResults?.length && (
+            <div className="bg-blue-50 rounded-lg p-6 text-center">
+              <p className="text-gray-600">No lab test requests for this patient</p>
+            </div>
           )}
         </div>
-    );
-  }
-
-  return (
-      <div>
-        <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>Lab Tests</h1>
-
-        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
-
-        {/* Search Form */}
-        <div className="bg-white rounded-lg shadow p-6 mb-6">
-          <h2 className="text-xl font-bold mb-4">Search Patient</h2>
-          <form onSubmit={handleSearch} className="space-y-4">
-            <div className="flex gap-4">
-              <div className="flex-1">
-                <label className="block text-sm font-semibold mb-2">Patient EMBG</label>
-                <input
-                    type="text"
-                    value={embg}
-                    onChange={(e) => setEmbg(e.target.value)}
-                    placeholder="e.g., 1402994123456"
-                    className="w-full px-4 py-2 border rounded-lg"
-                />
-              </div>
-              <div className="flex items-end">
-                <button
-                    type="submit"
-                    disabled={loading}
-                    className="bg-purple-600 text-white px-8 py-2 rounded-full hover:bg-purple-700 disabled:bg-gray-400"
-                >
-                  {loading ? 'Searching...' : 'Search'}
-                </button>
-              </div>
-            </div>
-          </form>
+      )}
+
+      {/* No search performed */}
+      {!searched && (
+        <div className="bg-gray-50 rounded-lg p-12 text-center">
+          <p className="text-gray-600 text-lg">Enter a patient EMBG to request lab tests</p>
         </div>
-
-        {/* Patient Lab Tests */}
-        {searched && patient && (
-            <div className="space-y-6">
-              {/* Patient Info */}
-              <div className="bg-white rounded-lg shadow p-6">
-                <div className="flex justify-between items-start mb-4">
-                  <h2 className="text-2xl font-bold">{patient.firstName} {patient.lastName}</h2>
-                  {!showRequestForm && (
-                      <button
-                          onClick={() => setShowRequestForm(true)}
-                          className="bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700"
-                      >
-                        Request Lab Test
-                      </button>
-                  )}
-                </div>
-                <div className="grid grid-cols-4 gap-4">
-                  <div>
-                    <p className="text-sm text-gray-600">EMBG</p>
-                    <p className="font-semibold">{patient.embg}</p>
-                  </div>
-                  <div>
-                    <p className="text-sm text-gray-600">Blood Type</p>
-                    <p className="font-semibold">{patient.bloodType || 'N/A'}</p>
-                  </div>
-                  <div>
-                    <p className="text-sm text-gray-600">Date of Birth</p>
-                    <p className="font-semibold">{patient.dateOfBirth}</p>
-                  </div>
-                </div>
-              </div>
-
-              {/* Request Lab Test Form */}
-              {showRequestForm && (
-                  <div className="bg-white rounded-lg shadow p-6">
-                    <h3 className="text-xl font-bold mb-4">Request Lab Test</h3>
-                    <form onSubmit={handleRequestTest} className="space-y-4">
-                      <div className="grid grid-cols-2 gap-4">
-                        <div>
-                          <label className="block text-sm font-semibold mb-2">Test</label>
-                          <select
-                              value={requestData.testId}
-                              onChange={(e) => setRequestData({ ...requestData, testId: e.target.value })}
-                              className="w-full px-4 py-2 border rounded-lg"
-                              required
-                          >
-                            <option value="">Select a test</option>
-                            {availableTests.map((test) => (
-                                <option key={test.testId} value={test.testId}>
-                                  {test.testName} (${test.cost})
-                                </option>
-                            ))}
-                          </select>
-                        </div>
-                        <div>
-                          <label className="block text-sm font-semibold mb-2">Test Date</label>
-                          <input
-                              type="date"
-                              value={requestData.testDate}
-                              onChange={(e) => setRequestData({ ...requestData, testDate: e.target.value })}
-                              className="w-full px-4 py-2 border rounded-lg"
-                          />
-                        </div>
-                      </div>
-                      <div>
-                        <label className="block text-sm font-semibold mb-2">Notes</label>
-                        <textarea
-                            value={requestData.notes}
-                            onChange={(e) => setRequestData({ ...requestData, notes: e.target.value })}
-                            placeholder="Additional notes for the lab technician"
-                            className="w-full px-4 py-2 border rounded-lg"
-                            rows="3"
-                        />
-                      </div>
-                      <div className="flex gap-4">
-                        <button
-                            type="submit"
-                            disabled={loading}
-                            className="bg-green-600 text-white px-6 py-2 rounded hover:bg-green-700 disabled:bg-gray-400"
-                        >
-                          {loading ? 'Requesting...' : 'Request Test'}
-                        </button>
-                        <button
-                            type="button"
-                            onClick={() => setShowRequestForm(false)}
-                            className="bg-gray-400 text-white px-6 py-2 rounded hover:bg-gray-500"
-                        >
-                          Cancel
-                        </button>
-                      </div>
-                    </form>
-                  </div>
-              )}
-
-              {/* Test Requests */}
-              {labTestRequests && labTestRequests.length > 0 && (
-                  <div className="bg-white rounded-lg shadow p-6">
-                    <h3 className="text-xl font-bold mb-4">Lab Test Requests</h3>
-                    <div className="space-y-3">
-                      {labTestRequests.map((request) => (
-                          <div key={request.testId} className="border-l-4 border-purple-500 pl-4 py-2">
-                            <p className="font-semibold text-lg">{request.testName}</p>
-                            <p className="text-sm text-gray-600">Requested by: {request.doctorName}</p>
-                            <p className="text-sm text-gray-600">Test Date: {request.requestDate}</p>
-                            {request.notes && (
-                                <p className="text-sm text-gray-600">Notes: {request.notes}</p>
-                            )}
-                          </div>
-                      ))}
-                    </div>
-                  </div>
-              )}
-
-              {/* Lab Test Results */}
-              {labResults && labResults.length > 0 && (
-                  <div className="bg-white rounded-lg shadow p-6">
-                    <h3 className="text-xl font-bold mb-4">Lab Test Results</h3>
-                    <div className="space-y-4">
-                      {labResults.map((result) => (
-                          <div key={result.resultId} className="border-l-4 border-green-500 pl-4 py-3 bg-green-50 rounded">
-                            <p className="font-semibold text-lg text-green-700">{result.testName}</p>
-                            <p className="text-sm text-gray-700 mt-2"><strong>Results:</strong> {result.results}</p>
-                            <p className="text-sm text-gray-600">Result Date: {result.resultDate}</p>
-                          </div>
-                      ))}
-                    </div>
-                  </div>
-              )}
-
-              {/* Link to submit results */}
-              {labTestRequests && labTestRequests.length > 0 && (
-                  <div className="bg-yellow-50 rounded-lg p-6">
-                    <h3 className="text-lg font-semibold text-yellow-800 mb-3">Lab Technician: Submit Test Results</h3>
-                    <p className="text-sm text-gray-700 mb-4">
-                      {labTestRequests.length} test{labTestRequests.length !== 1 ? 's' : ''} awaiting results
-                    </p>
-                    <a
-                        href="/lab-tests/results"
-                        className="inline-block bg-yellow-600 text-white px-6 py-2 rounded hover:bg-yellow-700"
-                    >
-                      Submit Lab Results
-                    </a>
-                  </div>
-              )}
-
-              {/* No requests message */}
-              {!labTestRequests || labTestRequests.length === 0 && !labResults?.length && (
-                  <div className="bg-blue-50 rounded-lg p-6 text-center">
-                    <p className="text-gray-600">No lab test requests for this patient</p>
-                  </div>
-              )}
-            </div>
-        )}
-
-        {/* No search performed */}
-        {!searched && (
-            <div className="bg-gray-50 rounded-lg p-12 text-center">
-              <p className="text-gray-600 text-lg">Enter a patient EMBG to request lab tests</p>
-            </div>
-        )}
-      </div>
+      )}
+    </div>
   );
 }
Index: frontend/src/pages/medical-records/MedicalRecordDetail.js
===================================================================
--- frontend/src/pages/medical-records/MedicalRecordDetail.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/medical-records/MedicalRecordDetail.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -1,3 +1,3 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useCallback } from 'react';
 import { useParams, useNavigate } from 'react-router-dom';
 import { medicalRecordService } from '../../services/medicalRecordService';
@@ -77,45 +77,5 @@
   const [procedureResults, setProcedureResults] = useState([]);
 
-  useEffect(() => {
-    fetchRecord();
-    fetchDoctors();
-    fetchDropdownOptions();
-  }, [id]);
-
-  const fetchDropdownOptions = async () => {
-    try {
-      console.log('Fetching dropdown options...');
-      const diagnosesRes = await apiClient.get('/medical-records/dropdown/diagnoses');
-      console.log('Diagnoses:', diagnosesRes.data);
-
-      const symptomsRes = await apiClient.get('/medical-records/dropdown/symptoms');
-      console.log('Symptoms:', symptomsRes.data);
-
-      const allergiesRes = await apiClient.get('/medical-records/dropdown/allergies');
-      console.log('Allergies:', allergiesRes.data);
-
-      const prescriptionsRes = await apiClient.get('/medical-records/dropdown/prescriptions');
-      console.log('Prescriptions:', prescriptionsRes.data);
-
-      const testsRes = await labService.getAllLabTests();
-      console.log('Lab Tests:', testsRes.data);
-
-      const proceduresRes = await procedureService.getAllProcedures();
-      console.log('Procedures:', proceduresRes.data);
-
-      setDiagnoses(diagnosesRes.data || []);
-      setSymptoms(symptomsRes.data || []);
-      setAllergies(allergiesRes.data || []);
-      setPrescriptions(prescriptionsRes.data || []);
-      setLabTests(testsRes.data || []);
-      setProcedures(proceduresRes.data || []);
-      console.log('Dropdown options set successfully');
-    } catch (err) {
-      console.error('Error fetching dropdown options:', err);
-      setError('Failed to load dropdown options: ' + (err.response?.data?.error || err.message));
-    }
-  };
-
-  const fetchRecord = async () => {
+  const fetchRecord = useCallback(async () => {
     try {
       setLoading(true);
@@ -146,19 +106,59 @@
       setLoading(false);
     }
-  };
-
-  const fetchDoctors = async () => {
-    try {
-      if (!isDoctor) {
-        const response = await doctorService.getAllDoctors();
-        setDoctors(response.data);
-        if (response.data.length > 0 && !selectedDoctorId) {
-          setSelectedDoctorId(response.data[0].doctorId);
+  }, [id]);
+
+  useEffect(() => {
+    const fetchDoctors = async () => {
+      try {
+        if (!isDoctor) {
+          const response = await doctorService.getAllDoctors();
+          setDoctors(response.data);
+          if (response.data.length > 0 && !selectedDoctorId) {
+            setSelectedDoctorId(response.data[0].doctorId);
+          }
         }
-      }
-    } catch (err) {
-      console.error('Failed to fetch doctors', err);
-    }
-  };
+      } catch (err) {
+        console.error('Failed to fetch doctors', err);
+      }
+    };
+
+    const fetchDropdownOptions = async () => {
+      try {
+        console.log('Fetching dropdown options...');
+        const diagnosesRes = await apiClient.get('/medical-records/dropdown/diagnoses');
+        console.log('Diagnoses:', diagnosesRes.data);
+
+        const symptomsRes = await apiClient.get('/medical-records/dropdown/symptoms');
+        console.log('Symptoms:', symptomsRes.data);
+
+        const allergiesRes = await apiClient.get('/medical-records/dropdown/allergies');
+        console.log('Allergies:', allergiesRes.data);
+
+        const prescriptionsRes = await apiClient.get('/medical-records/dropdown/prescriptions');
+        console.log('Prescriptions:', prescriptionsRes.data);
+
+        const testsRes = await labService.getAllLabTests();
+        console.log('Lab Tests:', testsRes.data);
+
+        const proceduresRes = await procedureService.getAllProcedures();
+        console.log('Procedures:', proceduresRes.data);
+
+        setDiagnoses(diagnosesRes.data || []);
+        setSymptoms(symptomsRes.data || []);
+        setAllergies(allergiesRes.data || []);
+        setPrescriptions(prescriptionsRes.data || []);
+        setLabTests(testsRes.data || []);
+        setProcedures(proceduresRes.data || []);
+        console.log('Dropdown options set successfully');
+      } catch (err) {
+        console.error('Error fetching dropdown options:', err);
+        setError('Failed to load dropdown options: ' + (err.response?.data?.error || err.message));
+      }
+    };
+
+    fetchRecord();
+    fetchDoctors();
+    fetchDropdownOptions();
+  }, [id, isDoctor, fetchRecord, selectedDoctorId]);
 
   const handleAddDiagnosis = async (e) => {
@@ -857,5 +857,5 @@
             try {
               setLoading(true);
-              const doctorId = localStorage.getItem('doctorId') || 1;
+              const doctorId = user.doctorId || 1;
 
               const request = {
@@ -964,5 +964,5 @@
             try {
               setLoading(true);
-              const doctorId = localStorage.getItem('doctorId') || 1;
+              const doctorId = user.doctorId || 1;
 
               const request = {
Index: frontend/src/pages/medical-records/MedicalRecordList.js
===================================================================
--- frontend/src/pages/medical-records/MedicalRecordList.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/medical-records/MedicalRecordList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -23,20 +23,12 @@
   const [loading, setLoading] = useState(false);
 
-
+  // Auto-load patient's own records if logged in as patient, or load specific patient records if patientId is provided
   React.useEffect(() => {
-    if (patientId) {
-
-      loadPatientRecords(patientId);
-    } else if (isPatient && user.username) {
-      handleAutoSearch();
-    }
-  }, [patientId]);
-
-  const loadPatientRecords = async (pId) => {
+    const loadPatientRecords = async (pId) => {
     setError(null);
     setLoading(true);
 
     try {
-      // Get patient by id
+      // Get patient by ID
       const patientResponse = await patientService.getPatientById(pId);
       setPatient(patientResponse.data);
@@ -73,48 +65,56 @@
       setLoading(false);
     }
-  };
-
-  const handleAutoSearch = async () => {
-    const searchEmbg = user.username;
-    setError(null);
-    setLoading(true);
-
-    try {
-      // Search patient by EMBG
-      const patientResponse = await patientService.getPatientByEmbg(searchEmbg);
-      setPatient(patientResponse.data);
-
-      // Get medical records for this patient
-      const recordsResponse = await medicalRecordService.getMedicalRecordByPatientId(patientResponse.data.patientId);
-      setMedicalData(recordsResponse.data);
-
-      // Get lab results
+    };
+
+    const handleAutoSearch = async () => {
+      const searchEmbg = user.username;
+      setError(null);
+      setLoading(true);
+
       try {
-        const labRes = await labService.getLabResultsForMedicalRecord(recordsResponse.data.recordId);
-        setLabResults(labRes.data || []);
+        // Search patient by EMBG
+        const patientResponse = await patientService.getPatientByEmbg(searchEmbg);
+        setPatient(patientResponse.data);
+
+        // Get medical records for this patient
+        const recordsResponse = await medicalRecordService.getMedicalRecordByPatientId(patientResponse.data.patientId);
+        setMedicalData(recordsResponse.data);
+
+        // Get lab results
+        try {
+          const labRes = await labService.getLabResultsForMedicalRecord(recordsResponse.data.recordId);
+          setLabResults(labRes.data || []);
+        } catch (err) {
+          setLabResults([]);
+        }
+
+        // Get procedure results
+        try {
+          const procRes = await procedureService.getProcedureResultsForMedicalRecord(recordsResponse.data.recordId);
+          setProcedureResults(procRes.data || []);
+        } catch (err) {
+          setProcedureResults([]);
+        }
+
+        setSearched(true);
       } catch (err) {
+        setError(`Patient with EMBG ${searchEmbg} not found`);
+        setSearched(true);
+        setPatient(null);
+        setMedicalData(null);
         setLabResults([]);
-      }
-
-      // Get procedure results
-      try {
-        const procRes = await procedureService.getProcedureResultsForMedicalRecord(recordsResponse.data.recordId);
-        setProcedureResults(procRes.data || []);
-      } catch (err) {
         setProcedureResults([]);
-      }
-
-      setSearched(true);
-    } catch (err) {
-      setError(`Patient with EMBG ${searchEmbg} not found`);
-      setSearched(true);
-      setPatient(null);
-      setMedicalData(null);
-      setLabResults([]);
-      setProcedureResults([]);
-    } finally {
-      setLoading(false);
+      } finally {
+        setLoading(false);
+      }
+    };
+
+    // Call appropriate function based on conditions
+    if (patientId) {
+      loadPatientRecords(patientId);
+    } else if (isPatient && user.username) {
+      handleAutoSearch();
     }
-  };
+  }, [patientId, isPatient, user.username]);
 
   const handleSearch = async (e) => {
@@ -168,245 +168,245 @@
 
   return (
-      <div>
-        <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>Medical Records</h1>
-
-        {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
-
-        {/* Search Form - Only show for non-patients */}
-        {!isPatient && (
-            <div className="bg-white rounded-lg shadow p-6 mb-6">
-              <h2 className="text-xl font-bold mb-4">Search Medical Records</h2>
-              <form onSubmit={handleSearch} className="space-y-4">
-                <div className="flex gap-4">
-                  <div className="flex-1">
-                    <label className="block text-sm font-semibold mb-2">Patient EMBG</label>
-                    <input
-                        type="text"
-                        value={embg}
-                        onChange={(e) => setEmbg(e.target.value)}
-                        placeholder="e.g., 1402994123456"
-                        className="w-full px-4 py-2 border rounded-lg"
-                    />
-                  </div>
-                  <div className="flex items-end">
-                    <button
-                        type="submit"
-                        disabled={loading}
-                        className="bg-purple-600 text-white px-8 py-2 rounded-full hover:bg-purple-700 disabled:bg-gray-400"
-                    >
-                      {loading ? 'Searching...' : 'Search'}
-                    </button>
-                  </div>
-                </div>
-              </form>
+    <div>
+      <h1 className="text-3xl font-bold mb-6" style={{ color: '#7c3aed' }}>Medical Records</h1>
+
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+
+      {/* Search Form - Only show for non-patients */}
+      {!isPatient && (
+        <div className="bg-white rounded-lg shadow p-6 mb-6">
+          <h2 className="text-xl font-bold mb-4">Search Medical Records</h2>
+          <form onSubmit={handleSearch} className="space-y-4">
+            <div className="flex gap-4">
+              <div className="flex-1">
+                <label className="block text-sm font-semibold mb-2">Patient EMBG</label>
+                <input
+                  type="text"
+                  value={embg}
+                  onChange={(e) => setEmbg(e.target.value)}
+                  placeholder="e.g., 1402994123456"
+                  className="w-full px-4 py-2 border rounded-lg"
+                />
+              </div>
+              <div className="flex items-end">
+                <button
+                  type="submit"
+                  disabled={loading}
+                  className="bg-purple-600 text-white px-8 py-2 rounded-full hover:bg-purple-700 disabled:bg-gray-400"
+                >
+                  {loading ? 'Searching...' : 'Search'}
+                </button>
+              </div>
             </div>
-        )}
-
-        {/* Loading indicator for patients fetching their records */}
-        {isPatient && loading && (
-            <div className="bg-blue-50 rounded-lg shadow p-6 mb-6">
-              <p className="text-sm text-gray-700">
-                <strong>Loading your medical records...</strong>
-              </p>
+          </form>
+        </div>
+      )}
+
+      {/* Loading indicator for patients fetching their records */}
+      {isPatient && loading && (
+        <div className="bg-blue-50 rounded-lg shadow p-6 mb-6">
+          <p className="text-sm text-gray-700">
+            <strong>Loading your medical records...</strong>
+          </p>
+        </div>
+      )}
+
+      {/* Patient Info Message for Patients */}
+      {isPatient && searched && !loading && (
+        <div className="bg-blue-50 rounded-lg shadow p-6 mb-6">
+          <p className="text-sm text-gray-700">
+            <strong>Viewing your medical records</strong>
+          </p>
+        </div>
+      )}
+
+      {/* Patient Medical Records */}
+      {searched && patient && (
+        <div className="space-y-6">
+          {/* Patient Info */}
+          <div className="bg-white rounded-lg shadow p-6">
+            <div className="flex justify-between items-start mb-4">
+              <h2 className="text-2xl font-bold">{patient.firstName} {patient.lastName}</h2>
+              {!isPatient && (
+                <button
+                  onClick={() => navigate(`/medical-records/${patient.patientId}`)}
+                  className="bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700"
+                >
+                  Add Medical Data
+                </button>
+              )}
             </div>
-        )}
-
-        {/* Patient Info Message for Patients */}
-        {isPatient && searched && !loading && (
-            <div className="bg-blue-50 rounded-lg shadow p-6 mb-6">
-              <p className="text-sm text-gray-700">
-                <strong>Viewing your medical records</strong>
-              </p>
+            <div className="grid grid-cols-4 gap-4">
+              <div>
+                <p className="text-sm text-gray-600">EMBG</p>
+                <p className="font-semibold">{patient.embg}</p>
+              </div>
+              <div>
+                <p className="text-sm text-gray-600">Email</p>
+                <p className="font-semibold">{patient.emailAddress}</p>
+              </div>
+              <div>
+                <p className="text-sm text-gray-600">Blood Type</p>
+                <p className="font-semibold">{patient.bloodType || 'N/A'}</p>
+              </div>
+              <div>
+                <p className="text-sm text-gray-600">Date of Birth</p>
+                <p className="font-semibold">{patient.dateOfBirth}</p>
+              </div>
             </div>
-        )}
-
-        {/* Patient Medical Records */}
-        {searched && patient && (
-            <div className="space-y-6">
-              {/* Patient Info */}
-              <div className="bg-white rounded-lg shadow p-6">
-                <div className="flex justify-between items-start mb-4">
-                  <h2 className="text-2xl font-bold">{patient.firstName} {patient.lastName}</h2>
-                  {!isPatient && (
-                      <button
-                          onClick={() => navigate(`/medical-records/${patient.patientId}`)}
-                          className="bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700"
-                      >
-                        Add Medical Data
-                      </button>
-                  )}
-                </div>
-                <div className="grid grid-cols-4 gap-4">
-                  <div>
-                    <p className="text-sm text-gray-600">EMBG</p>
-                    <p className="font-semibold">{patient.embg}</p>
-                  </div>
-                  <div>
-                    <p className="text-sm text-gray-600">Email</p>
-                    <p className="font-semibold">{patient.emailAddress}</p>
-                  </div>
-                  <div>
-                    <p className="text-sm text-gray-600">Blood Type</p>
-                    <p className="font-semibold">{patient.bloodType || 'N/A'}</p>
-                  </div>
-                  <div>
-                    <p className="text-sm text-gray-600">Date of Birth</p>
-                    <p className="font-semibold">{patient.dateOfBirth}</p>
-                  </div>
-                </div>
-              </div>
-
-              {/* Medical Data Sections */}
-              {medicalData && (
-                  <>
-                    {/* Diagnoses */}
-                    {medicalData.diagnoses && medicalData.diagnoses.length > 0 && (
-                        <div className="bg-white rounded-lg shadow p-6">
-                          <h3 className="text-xl font-bold mb-4">Diagnoses</h3>
-                          <div className="space-y-3">
-                            {medicalData.diagnoses.map((diagnosis) => (
-                                <div key={diagnosis.diagnosisId} className="border-l-4 border-purple-500 pl-4 py-2">
-                                  <p className="font-semibold text-lg">{diagnosis.name}</p>
-                                  {diagnosis.description && (
-                                      <p className="text-gray-600 text-sm">{diagnosis.description}</p>
-                                  )}
-                                  <p className="text-xs text-gray-500">By: {diagnosis.doctorName}</p>
-                                </div>
-                            ))}
-                          </div>
-                        </div>
-                    )}
-
-                    {/* Symptoms */}
-                    {medicalData.symptoms && medicalData.symptoms.length > 0 && (
-                        <div className="bg-white rounded-lg shadow p-6">
-                          <h3 className="text-xl font-bold mb-4">Symptoms</h3>
-                          <div className="flex flex-wrap gap-2">
-                            {medicalData.symptoms.map((symptom) => (
-                                <span key={symptom.symptomId} className="bg-yellow-100 text-yellow-800 px-3 py-1 rounded-full text-sm">
+          </div>
+
+          {/* Medical Data Sections */}
+          {medicalData && (
+            <>
+              {/* Diagnoses */}
+              {medicalData.diagnoses && medicalData.diagnoses.length > 0 && (
+                <div className="bg-white rounded-lg shadow p-6">
+                  <h3 className="text-xl font-bold mb-4">Diagnoses</h3>
+                  <div className="space-y-3">
+                    {medicalData.diagnoses.map((diagnosis) => (
+                      <div key={diagnosis.diagnosisId} className="border-l-4 border-purple-500 pl-4 py-2">
+                        <p className="font-semibold text-lg">{diagnosis.name}</p>
+                        {diagnosis.description && (
+                          <p className="text-gray-600 text-sm">{diagnosis.description}</p>
+                        )}
+                        <p className="text-xs text-gray-500">By: {diagnosis.doctorName}</p>
+                      </div>
+                    ))}
+                  </div>
+                </div>
+              )}
+
+              {/* Symptoms */}
+              {medicalData.symptoms && medicalData.symptoms.length > 0 && (
+                <div className="bg-white rounded-lg shadow p-6">
+                  <h3 className="text-xl font-bold mb-4">Symptoms</h3>
+                  <div className="flex flex-wrap gap-2">
+                    {medicalData.symptoms.map((symptom) => (
+                      <span key={symptom.symptomId} className="bg-yellow-100 text-yellow-800 px-3 py-1 rounded-full text-sm">
                         {symptom.symptomName}
                       </span>
-                            ))}
-                          </div>
-                        </div>
-                    )}
-
-                    {/* Allergies */}
-                    {medicalData.allergies && medicalData.allergies.length > 0 && (
-                        <div className="bg-white rounded-lg shadow p-6">
-                          <h3 className="text-xl font-bold mb-4">Allergies</h3>
-                          <div className="space-y-3">
-                            {medicalData.allergies.map((allergy) => (
-                                <div key={allergy.allergyId} className="border-l-4 border-red-500 pl-4 py-2">
-                                  <p className="font-semibold">{allergy.allergyName}</p>
-                                  <p className="text-sm">
+                    ))}
+                  </div>
+                </div>
+              )}
+
+              {/* Allergies */}
+              {medicalData.allergies && medicalData.allergies.length > 0 && (
+                <div className="bg-white rounded-lg shadow p-6">
+                  <h3 className="text-xl font-bold mb-4">Allergies</h3>
+                  <div className="space-y-3">
+                    {medicalData.allergies.map((allergy) => (
+                      <div key={allergy.allergyId} className="border-l-4 border-red-500 pl-4 py-2">
+                        <p className="font-semibold">{allergy.allergyName}</p>
+                        <p className="text-sm">
                           <span className={`px-2 py-1 rounded text-white text-xs ${
-                              allergy.severity === 'CRITICAL' ? 'bg-red-600' :
-                                  allergy.severity === 'HIGH' ? 'bg-red-500' :
-                                      allergy.severity === 'MEDIUM' ? 'bg-yellow-500' :
-                                          'bg-green-500'
+                            allergy.severity === 'CRITICAL' ? 'bg-red-600' :
+                            allergy.severity === 'HIGH' ? 'bg-red-500' :
+                            allergy.severity === 'MEDIUM' ? 'bg-yellow-500' :
+                            'bg-green-500'
                           }`}>
                             {allergy.severity} Severity
                           </span>
-                                  </p>
-                                  {allergy.reaction && (
-                                      <p className="text-gray-600 text-sm">Reaction: {allergy.reaction}</p>
-                                  )}
-                                </div>
-                            ))}
-                          </div>
-                        </div>
-                    )}
-
-                    {/* Medical Reports */}
-                    {medicalData.reports && medicalData.reports.length > 0 && (
-                        <div className="bg-white rounded-lg shadow p-6">
-                          <h3 className="text-xl font-bold mb-4">Medical Reports</h3>
-                          <div className="space-y-3">
-                            {medicalData.reports.map((report) => (
-                                <div key={report.reportId} className="border-l-4 border-green-500 pl-4 py-2">
-                                  <p className="font-semibold">Report from {report.doctorName}</p>
-                                  <p className="text-gray-600 text-sm">{report.description}</p>
-                                  <p className="text-xs text-gray-500">Date: {report.reportDate}</p>
-                                </div>
-                            ))}
-                          </div>
-                        </div>
-                    )}
-
-                    {/* Lab Test Results */}
-                    {labResults && labResults.length > 0 && (
-                        <div className="bg-white rounded-lg shadow p-6">
-                          <h3 className="text-xl font-bold mb-4">Lab Test Results</h3>
-                          <div className="space-y-3">
-                            {labResults.map((result) => (
-                                <div key={result.labResultId} className="border-l-4 border-purple-500 pl-4 py-2">
-                                  <p className="font-semibold">{result.testName}</p>
-                                  <p className="text-gray-600 text-sm">{result.result}</p>
-                                  {result.notes && (
-                                      <p className="text-gray-600 text-sm">Notes: {result.notes}</p>
-                                  )}
-                                  <p className="text-xs text-gray-500">Date: {result.resultDate}</p>
-                                  {result.technicianName && (
-                                      <p className="text-xs text-gray-500">Technician: {result.technicianName}</p>
-                                  )}
-                                </div>
-                            ))}
-                          </div>
-                        </div>
-                    )}
-
-                    {/* Procedure Results */}
-                    {procedureResults && procedureResults.length > 0 && (
-                        <div className="bg-white rounded-lg shadow p-6">
-                          <h3 className="text-xl font-bold mb-4">Procedure Results</h3>
-                          <div className="space-y-3">
-                            {procedureResults.map((result) => (
-                                <div key={result.procedureResultId} className="border-l-4 border-orange-500 pl-4 py-2">
-                                  <p className="font-semibold">{result.procedureName}</p>
-                                  <p className="text-gray-600 text-sm">{result.result}</p>
-                                  {result.notes && (
-                                      <p className="text-gray-600 text-sm">Notes: {result.notes}</p>
-                                  )}
-                                  <p className="text-xs text-gray-500">Date: {result.resultDate}</p>
-                                  {result.doctorName && (
-                                      <p className="text-xs text-gray-500">Doctor: {result.doctorName}</p>
-                                  )}
-                                </div>
-                            ))}
-                          </div>
-                        </div>
-                    )}
-
-                    {/* No data message */}
-                    {(!medicalData.diagnoses || medicalData.diagnoses.length === 0) &&
-                        (!medicalData.symptoms || medicalData.symptoms.length === 0) &&
-                        (!medicalData.allergies || medicalData.allergies.length === 0) &&
-                        (!medicalData.reports || medicalData.reports.length === 0) &&
-                        (!labResults || labResults.length === 0) &&
-                        (!procedureResults || procedureResults.length === 0) && (
-                            <div className="bg-blue-50 rounded-lg p-6 text-center">
-                              <p className="text-gray-600">No medical records found for this patient</p>
-                            </div>
-                        )}
-                  </>
-              )}
-            </div>
-        )}
-
-        {/* No search performed */}
-        {!searched && !isPatient && (
-            <div className="bg-gray-50 rounded-lg p-12 text-center">
-              <p className="text-gray-600 text-lg">Enter a patient EMBG to view their medical records</p>
-            </div>
-        )}
-
-        {/* Loading message for patients */}
-        {isPatient && loading && (
-            <div className="bg-gray-50 rounded-lg p-12 text-center">
-              <p className="text-gray-600 text-lg">Loading your medical records...</p>
-            </div>
-        )}
-      </div>
+                        </p>
+                        {allergy.reaction && (
+                          <p className="text-gray-600 text-sm">Reaction: {allergy.reaction}</p>
+                        )}
+                      </div>
+                    ))}
+                  </div>
+                </div>
+              )}
+
+              {/* Medical Reports */}
+              {medicalData.reports && medicalData.reports.length > 0 && (
+                <div className="bg-white rounded-lg shadow p-6">
+                  <h3 className="text-xl font-bold mb-4">Medical Reports</h3>
+                  <div className="space-y-3">
+                    {medicalData.reports.map((report) => (
+                      <div key={report.reportId} className="border-l-4 border-green-500 pl-4 py-2">
+                        <p className="font-semibold">Report from {report.doctorName}</p>
+                        <p className="text-gray-600 text-sm">{report.description}</p>
+                        <p className="text-xs text-gray-500">Date: {report.reportDate}</p>
+                      </div>
+                    ))}
+                  </div>
+                </div>
+              )}
+
+              {/* Lab Test Results */}
+              {labResults && labResults.length > 0 && (
+                <div className="bg-white rounded-lg shadow p-6">
+                  <h3 className="text-xl font-bold mb-4">Lab Test Results</h3>
+                  <div className="space-y-3">
+                    {labResults.map((result) => (
+                      <div key={result.labResultId} className="border-l-4 border-purple-500 pl-4 py-2">
+                        <p className="font-semibold">{result.testName}</p>
+                        <p className="text-gray-600 text-sm">{result.result}</p>
+                        {result.notes && (
+                          <p className="text-gray-600 text-sm">Notes: {result.notes}</p>
+                        )}
+                        <p className="text-xs text-gray-500">Date: {result.resultDate}</p>
+                        {result.technicianName && (
+                          <p className="text-xs text-gray-500">Technician: {result.technicianName}</p>
+                        )}
+                      </div>
+                    ))}
+                  </div>
+                </div>
+              )}
+
+              {/* Procedure Results */}
+              {procedureResults && procedureResults.length > 0 && (
+                <div className="bg-white rounded-lg shadow p-6">
+                  <h3 className="text-xl font-bold mb-4">Procedure Results</h3>
+                  <div className="space-y-3">
+                    {procedureResults.map((result) => (
+                      <div key={result.procedureResultId} className="border-l-4 border-orange-500 pl-4 py-2">
+                        <p className="font-semibold">{result.procedureName}</p>
+                        <p className="text-gray-600 text-sm">{result.result}</p>
+                        {result.notes && (
+                          <p className="text-gray-600 text-sm">Notes: {result.notes}</p>
+                        )}
+                        <p className="text-xs text-gray-500">Date: {result.resultDate}</p>
+                        {result.doctorName && (
+                          <p className="text-xs text-gray-500">Doctor: {result.doctorName}</p>
+                        )}
+                      </div>
+                    ))}
+                  </div>
+                </div>
+              )}
+
+              {/* No data message */}
+              {(!medicalData.diagnoses || medicalData.diagnoses.length === 0) &&
+                (!medicalData.symptoms || medicalData.symptoms.length === 0) &&
+                (!medicalData.allergies || medicalData.allergies.length === 0) &&
+                (!medicalData.reports || medicalData.reports.length === 0) &&
+                (!labResults || labResults.length === 0) &&
+                (!procedureResults || procedureResults.length === 0) && (
+                <div className="bg-blue-50 rounded-lg p-6 text-center">
+                  <p className="text-gray-600">No medical records found for this patient</p>
+                </div>
+              )}
+            </>
+          )}
+        </div>
+      )}
+
+      {/* No search performed */}
+      {!searched && !isPatient && (
+        <div className="bg-gray-50 rounded-lg p-12 text-center">
+          <p className="text-gray-600 text-lg">Enter a patient EMBG to view their medical records</p>
+        </div>
+      )}
+
+      {/* Loading message for patients */}
+      {isPatient && loading && (
+        <div className="bg-gray-50 rounded-lg p-12 text-center">
+          <p className="text-gray-600 text-lg">Loading your medical records...</p>
+        </div>
+      )}
+    </div>
   );
 }
Index: frontend/src/pages/medical-reports/MedicalReportList.js
===================================================================
--- frontend/src/pages/medical-reports/MedicalReportList.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/medical-reports/MedicalReportList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -4,5 +4,4 @@
 import { doctorService } from '../../services/doctorService';
 import { medicalRecordService } from '../../services/medicalRecordService';
-import { medicalItemsService } from '../../services/medicalItemsService';
 import ErrorAlert from '../../components/ErrorAlert';
 import SuccessAlert from '../../components/SuccessAlert';
@@ -19,9 +18,4 @@
   const [loading, setLoading] = useState(false);
 
-  const [availableDiagnoses, setAvailableDiagnoses] = useState([]);
-  const [availablePrescriptions, setAvailablePrescriptions] = useState([]);
-  const [availableAllergies, setAvailableAllergies] = useState([]);
-  const [availableSymptoms, setAvailableSymptoms] = useState([]);
-
   const [selectedDiagnosisIds, setSelectedDiagnosisIds] = useState(new Set());
   const [selectedPrescriptionIds, setSelectedPrescriptionIds] = useState(new Set());
@@ -70,41 +64,7 @@
       const medicalRecordRes = await medicalRecordService.getMedicalRecordByPatientId(patientRes.data.patientId);
       const medicalRecordId = medicalRecordRes.data.recordId;
-      const patientId = patientRes.data.patientId;
 
       const reportsRes = await medicalReportService.getReportsForMedicalRecord(medicalRecordId);
       setReports(Array.isArray(reportsRes.data) ? reportsRes.data : [reportsRes.data]);
-
-      // Fetch available medical items
-      try {
-        const diagnosesRes = await medicalItemsService.getDiagnosesForPatient(patientId);
-        setAvailableDiagnoses(diagnosesRes.data || []);
-      } catch (err) {
-        console.error('Error loading diagnoses:', err);
-        setAvailableDiagnoses([]);
-      }
-
-      try {
-        const prescriptionsRes = await medicalItemsService.getPrescriptionsForMedicalRecord(medicalRecordId);
-        setAvailablePrescriptions(prescriptionsRes.data || []);
-      } catch (err) {
-        console.error('Error loading prescriptions:', err);
-        setAvailablePrescriptions([]);
-      }
-
-      try {
-        const allergiesRes = await medicalItemsService.getAllergiesForMedicalRecord(medicalRecordId);
-        setAvailableAllergies(allergiesRes.data || []);
-      } catch (err) {
-        console.error('Error loading allergies:', err);
-        setAvailableAllergies([]);
-      }
-
-      try {
-        const symptomsRes = await medicalItemsService.getSymptomsForMedicalRecord(medicalRecordId);
-        setAvailableSymptoms(symptomsRes.data || []);
-      } catch (err) {
-        console.error('Error loading symptoms:', err);
-        setAvailableSymptoms([]);
-      }
 
       setSelectedReport(null);
@@ -117,8 +77,4 @@
       setReports([]);
       setSearchedPatient(null);
-      setAvailableDiagnoses([]);
-      setAvailablePrescriptions([]);
-      setAvailableAllergies([]);
-      setAvailableSymptoms([]);
     } finally {
       setLoading(false);
@@ -175,52 +131,4 @@
       [name]: value
     }));
-  };
-
-  const toggleDiagnosisSelection = (diagnosisId) => {
-    setSelectedDiagnosisIds(prev => {
-      const newSet = new Set(prev);
-      if (newSet.has(diagnosisId)) {
-        newSet.delete(diagnosisId);
-      } else {
-        newSet.add(diagnosisId);
-      }
-      return newSet;
-    });
-  };
-
-  const togglePrescriptionSelection = (prescriptionId) => {
-    setSelectedPrescriptionIds(prev => {
-      const newSet = new Set(prev);
-      if (newSet.has(prescriptionId)) {
-        newSet.delete(prescriptionId);
-      } else {
-        newSet.add(prescriptionId);
-      }
-      return newSet;
-    });
-  };
-
-  const toggleAllergySelection = (allergyId) => {
-    setSelectedAllergyIds(prev => {
-      const newSet = new Set(prev);
-      if (newSet.has(allergyId)) {
-        newSet.delete(allergyId);
-      } else {
-        newSet.add(allergyId);
-      }
-      return newSet;
-    });
-  };
-
-  const toggleSymptomSelection = (symptomId) => {
-    setSelectedSymptomIds(prev => {
-      const newSet = new Set(prev);
-      if (newSet.has(symptomId)) {
-        newSet.delete(symptomId);
-      } else {
-        newSet.add(symptomId);
-      }
-      return newSet;
-    });
   };
 
Index: frontend/src/pages/patients/PatientDetail.js
===================================================================
--- frontend/src/pages/patients/PatientDetail.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
+++ frontend/src/pages/patients/PatientDetail.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -0,0 +1,105 @@
+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 <Loading />;
+
+  if (!patient) {
+    return (
+      <div>
+        <ErrorAlert message="Patient not found" onClose={() => navigate('/patients')} />
+      </div>
+    );
+  }
+
+  return (
+    <div>
+      <div className="flex justify-between items-center mb-6">
+        <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>{patient.firstName} {patient.lastName}</h1>
+        <div className="space-x-2">
+          {isAdmin && (
+            <Link to={`/patients/${id}/edit`} className="bg-purple-600 text-white px-4 py-2 rounded hover:bg-purple-700">
+              Edit
+            </Link>
+          )}
+          <button onClick={() => navigate('/patients')} className="bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400">
+            Back
+          </button>
+        </div>
+      </div>
+
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+
+      <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
+        <div className="bg-white rounded-lg shadow p-6">
+          <h2 className="text-xl font-bold mb-4">Personal Information</h2>
+          <div className="space-y-3">
+            <InfoRow label="EMBG" value={patient.embg} />
+            <InfoRow label="Email" value={patient.emailAddress} />
+            <InfoRow label="Phone" value={patient.phoneNumber} />
+            <InfoRow label="Date of Birth" value={patient.dateOfBirth} />
+            <InfoRow label="Gender" value={patient.gender} />
+            <InfoRow label="Blood Type" value={patient.bloodType} />
+          </div>
+        </div>
+
+        {!isLabTechnician && (
+          <div className="bg-white rounded-lg shadow p-6">
+            <h2 className="text-xl font-bold mb-4">Quick Links</h2>
+            <div className="space-y-2">
+              <Link to={`/appointments?patientId=${id}`} className="block p-3 bg-blue-50 hover:bg-purple-100 rounded text-purple-600">
+                View Appointments
+              </Link>
+              <Link to={`/medical-records?patientId=${id}`} className="block p-3 bg-green-50 hover:bg-green-100 rounded text-green-600">
+                View Medical Records
+              </Link>
+              <Link to={`/billing?patientId=${id}`} className="block p-3 bg-purple-50 hover:bg-purple-100 rounded text-purple-600">
+                View Billing History
+              </Link>
+            </div>
+          </div>
+        )}
+      </div>
+    </div>
+  );
+}
+
+function InfoRow({ label, value }) {
+  return (
+    <div className="flex justify-between">
+      <span className="font-semibold text-gray-600">{label}:</span>
+      <span className="text-gray-800">{value || 'N/A'}</span>
+    </div>
+  );
+}
+
+export default PatientDetail;
Index: frontend/src/pages/patients/PatientForm.js
===================================================================
--- frontend/src/pages/patients/PatientForm.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
+++ frontend/src/pages/patients/PatientForm.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -0,0 +1,214 @@
+import React, { useState, useEffect } from 'react';
+import { useNavigate, useParams } from 'react-router-dom';
+import { patientService } from '../../services/patientService';
+import ErrorAlert from '../../components/ErrorAlert';
+import SuccessAlert from '../../components/SuccessAlert';
+
+function PatientForm() {
+  const { id } = useParams();
+  const navigate = useNavigate();
+  const [formData, setFormData] = useState({
+    firstName: '',
+    lastName: '',
+    emailAddress: '',
+    embg: '',
+    phoneNumber: '',
+    dateOfBirth: '',
+    gender: '',
+    bloodType: '',
+  });
+  const [error, setError] = useState(null);
+  const [success, setSuccess] = useState(null);
+  const [loading, setLoading] = useState(false);
+
+  useEffect(() => {
+    if (id) {
+      const fetchPatient = async () => {
+        try {
+          setLoading(true);
+          const response = await patientService.getPatientById(id);
+          setFormData(response.data);
+        } catch (err) {
+          setError('Failed to fetch patient');
+        } finally {
+          setLoading(false);
+        }
+      };
+
+      fetchPatient();
+    }
+  }, [id]);
+
+  const handleChange = (e) => {
+    const { name, value } = e.target;
+    setFormData(prev => ({
+      ...prev,
+      [name]: value
+    }));
+  };
+
+  const handleSubmit = async (e) => {
+    e.preventDefault();
+
+    if (!formData.firstName || !formData.lastName || !formData.embg) {
+      setError('Please fill in all required fields');
+      return;
+    }
+
+    try {
+      setLoading(true);
+      if (id) {
+        await patientService.updatePatient(id, formData);
+        setSuccess('Patient updated successfully!');
+      } else {
+        await patientService.createPatient(formData);
+        setSuccess('Patient created successfully!');
+      }
+      setTimeout(() => navigate('/patients'), 1500);
+    } catch (err) {
+      setError(err.response?.data?.error || 'Failed to save patient');
+    } finally {
+      setLoading(false);
+    }
+  };
+
+  return (
+    <div className="max-w-2xl mx-auto">
+      <h1 className="text-3xl font-bold mb-6">
+        {id ? 'Edit Patient' : 'Add New Patient'}
+      </h1>
+
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+      {success && <SuccessAlert message={success} onClose={() => setSuccess(null)} />}
+
+      <form onSubmit={handleSubmit} className="bg-white rounded-lg shadow p-6 space-y-4">
+        <div className="grid grid-cols-2 gap-4">
+          <div>
+            <label className="block text-sm font-semibold mb-2">First Name *</label>
+            <input
+              type="text"
+              name="firstName"
+              value={formData.firstName}
+              onChange={handleChange}
+              className="w-full px-4 py-2 border rounded-lg"
+              required
+            />
+          </div>
+          <div>
+            <label className="block text-sm font-semibold mb-2">Last Name *</label>
+            <input
+              type="text"
+              name="lastName"
+              value={formData.lastName}
+              onChange={handleChange}
+              className="w-full px-4 py-2 border rounded-lg"
+              required
+            />
+          </div>
+        </div>
+
+        <div>
+          <label className="block text-sm font-semibold mb-2">EMBG *</label>
+          <input
+            type="text"
+            name="embg"
+            value={formData.embg}
+            onChange={handleChange}
+            className="w-full px-4 py-2 border rounded-lg"
+            required
+            disabled={!!id}
+          />
+        </div>
+
+        <div>
+          <label className="block text-sm font-semibold mb-2">Email</label>
+          <input
+            type="email"
+            name="emailAddress"
+            value={formData.emailAddress}
+            onChange={handleChange}
+            className="w-full px-4 py-2 border rounded-lg"
+          />
+        </div>
+
+        <div className="grid grid-cols-2 gap-4">
+          <div>
+            <label className="block text-sm font-semibold mb-2">Phone</label>
+            <input
+              type="tel"
+              name="phoneNumber"
+              value={formData.phoneNumber}
+              onChange={handleChange}
+              className="w-full px-4 py-2 border rounded-lg"
+            />
+          </div>
+          <div>
+            <label className="block text-sm font-semibold mb-2">Date of Birth</label>
+            <input
+              type="date"
+              name="dateOfBirth"
+              value={formData.dateOfBirth}
+              onChange={handleChange}
+              className="w-full px-4 py-2 border rounded-lg"
+            />
+          </div>
+        </div>
+
+        <div className="grid grid-cols-2 gap-4">
+          <div>
+            <label className="block text-sm font-semibold mb-2">Gender</label>
+            <select
+              name="gender"
+              value={formData.gender}
+              onChange={handleChange}
+              className="w-full px-4 py-2 border rounded-lg"
+            >
+              <option value="">Select Gender</option>
+              <option value="MALE">Male</option>
+              <option value="FEMALE">Female</option>
+              <option value="OTHER">Other</option>
+            </select>
+          </div>
+          <div>
+            <label className="block text-sm font-semibold mb-2">Blood Type</label>
+            <select
+              name="bloodType"
+              value={formData.bloodType}
+              onChange={handleChange}
+              className="w-full px-4 py-2 border rounded-lg"
+            >
+              <option value="">Select Blood Type</option>
+              <option value="O_POSITIVE">O+</option>
+              <option value="O_NEGATIVE">O-</option>
+              <option value="A_POSITIVE">A+</option>
+              <option value="A_NEGATIVE">A-</option>
+              <option value="B_POSITIVE">B+</option>
+              <option value="B_NEGATIVE">B-</option>
+              <option value="AB_POSITIVE">AB+</option>
+              <option value="AB_NEGATIVE">AB-</option>
+            </select>
+          </div>
+        </div>
+
+        <div className="flex gap-4 pt-4">
+          <button
+            type="submit"
+            disabled={loading}
+            className="bg-purple-600 text-white px-6 py-2 rounded hover:bg-purple-700 disabled:opacity-50"
+          >
+            {loading ? 'Saving...' : 'Save Patient'}
+          </button>
+          <button
+            type="button"
+            onClick={() => navigate('/patients')}
+            className="bg-gray-300 text-gray-700 px-6 py-2 rounded hover:bg-gray-400"
+          >
+            Cancel
+          </button>
+        </div>
+      </form>
+    </div>
+  );
+}
+
+export default PatientForm;
Index: frontend/src/pages/patients/PatientList.js
===================================================================
--- frontend/src/pages/patients/PatientList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
+++ frontend/src/pages/patients/PatientList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -0,0 +1,104 @@
+import React, { useState, useEffect } from 'react';
+import { Link } from 'react-router-dom';
+import { patientService } from '../../services/patientService';
+import Loading from '../../components/Loading';
+import ErrorAlert from '../../components/ErrorAlert';
+
+function PatientList() {
+  const user = JSON.parse(localStorage.getItem('user') || '{}');
+  const isAdmin = user.role === 'ADMIN';
+  const [patients, setPatients] = useState([]);
+  const [loading, setLoading] = useState(true);
+  const [error, setError] = useState(null);
+  const [searchTerm, setSearchTerm] = useState('');
+
+  useEffect(() => {
+    fetchPatients();
+  }, []);
+
+  const fetchPatients = async () => {
+    try {
+      setLoading(true);
+      const response = await patientService.getAllPatients();
+      setPatients(response.data);
+    } catch (err) {
+      setError('Failed to fetch patients');
+      console.error(err);
+    } finally {
+      setLoading(false);
+    }
+  };
+
+  const filteredPatients = patients.filter(patient =>
+    patient.firstName.toLowerCase().includes(searchTerm.toLowerCase()) ||
+    patient.lastName.toLowerCase().includes(searchTerm.toLowerCase()) ||
+    patient.embg.includes(searchTerm)
+  );
+
+  if (loading) return <Loading />;
+
+  return (
+    <div>
+      <div className="flex justify-between items-center mb-6">
+        <h1 className="text-3xl font-bold" style={{ color: '#7c3aed' }}>Patients</h1>
+        {isAdmin && (
+          <Link to="/patients/new" style={{
+            display: 'inline-block',
+            background: '#bfdbfe',
+            color: '#1e1035',
+            padding: '8px 16px',
+            borderRadius: '6px',
+            textDecoration: 'none',
+            fontSize: '14px',
+            fontWeight: '400'
+          }} onMouseEnter={(e) => e.currentTarget.style.background = '#93c5fd'} onMouseLeave={(e) => e.currentTarget.style.background = '#bfdbfe'}>
+            Add Patient
+          </Link>
+        )}
+      </div>
+
+      {error && <ErrorAlert message={error} onClose={() => setError(null)} />}
+
+      <div className="mb-6">
+        <input
+          type="text"
+          placeholder="Search by name or EMBG..."
+          className="w-full px-4 py-2 border rounded-lg"
+          value={searchTerm}
+          onChange={(e) => setSearchTerm(e.target.value)}
+        />
+      </div>
+
+      <div className="bg-white rounded-lg shadow overflow-hidden">
+        <table className="w-full">
+          <thead className="bg-gray-100">
+            <tr>
+              <th className="px-6 py-3 text-left text-sm font-semibold">Name</th>
+              <th className="px-6 py-3 text-left text-sm font-semibold">EMBG</th>
+              <th className="px-6 py-3 text-left text-sm font-semibold">Email</th>
+              <th className="px-6 py-3 text-left text-sm font-semibold">Phone</th>
+              <th className="px-6 py-3 text-left text-sm font-semibold">Actions</th>
+            </tr>
+          </thead>
+          <tbody>
+            {filteredPatients.map(patient => (
+              <tr key={patient.patientId} className="border-t hover:bg-gray-50">
+                <td className="px-6 py-3">{patient.firstName} {patient.lastName}</td>
+                <td className="px-6 py-3">{patient.embg}</td>
+                <td className="px-6 py-3">{patient.emailAddress}</td>
+                <td className="px-6 py-3">{patient.phoneNumber}</td>
+                <td className="px-6 py-3">
+                  <Link to={`/patients/${patient.patientId}`} className="text-purple-600 hover:underline">
+                    View
+                  </Link>
+                </td>
+              </tr>
+            ))}
+          </tbody>
+        </table>
+      </div>
+    </div>
+  );
+}
+
+export default PatientList;
Index: frontend/src/pages/procedures/ProcedureList.js
===================================================================
--- frontend/src/pages/procedures/ProcedureList.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/procedures/ProcedureList.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -6,4 +6,5 @@
 
 function ProcedureList() {
+  const [user, setUser] = useState({});
   const [patient, setPatient] = useState(null);
   const [embg, setEmbg] = useState('');
@@ -22,4 +23,39 @@
     notes: '',
   });
+
+  // Load user from localStorage and listen for changes
+  useEffect(() => {
+    const loadUser = () => {
+      const userStr = localStorage.getItem('user');
+      console.log('[ProcedureList] Loading user from localStorage:', userStr);
+      if (userStr) {
+        try {
+          const parsedUser = JSON.parse(userStr);
+          console.log('[ProcedureList] Parsed user:', parsedUser);
+          setUser(parsedUser);
+        } catch (err) {
+          console.error('Failed to parse user:', err);
+          setUser({});
+        }
+      } else {
+        console.log('[ProcedureList] No user in localStorage');
+        setUser({});
+      }
+    };
+
+    console.log('[ProcedureList] useEffect running - loading user');
+    loadUser();
+
+    // Listen for storage changes (other tabs/windows)
+    window.addEventListener('storage', loadUser);
+
+    // Listen for custom event (same tab changes)
+    window.addEventListener('userStorageChange', loadUser);
+
+    return () => {
+      window.removeEventListener('storage', loadUser);
+      window.removeEventListener('userStorageChange', loadUser);
+    };
+  }, []);
 
   const handleSearch = async (e) => {
@@ -97,6 +133,6 @@
       setLoading(true);
 
-      // Get doctor ID from localStorage (set during login)
-      const doctorId = localStorage.getItem('doctorId') || 1;
+      // Get doctor ID from logged-in user
+      const doctorId = user.doctorId;
 
       const request = {
@@ -108,5 +144,6 @@
       };
 
-      console.log('Sending request:', request);
+      console.log('User object:', user);
+      console.log('Sending procedure request with doctorId:', doctorId, 'Full request:', request);
       await procedureService.recordProcedure(request);
 
@@ -313,5 +350,5 @@
 
           {/* No procedures message */}
-          {!performedProcedures || (performedProcedures.length === 0 && !procedureResults?.length) && (
+          {(!performedProcedures || performedProcedures.length === 0) && !procedureResults?.length && (
             <div className="bg-blue-50 rounded-lg p-6 text-center">
               <p className="text-gray-600">No procedures for this patient</p>
Index: frontend/src/pages/procedures/ProcedureResultForm.js
===================================================================
--- frontend/src/pages/procedures/ProcedureResultForm.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/pages/procedures/ProcedureResultForm.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -1,3 +1,3 @@
-import React, { useState, useEffect } from 'react';
+import React, { useState } from 'react';
 import { useNavigate } from 'react-router-dom';
 import { procedureService } from '../../services/procedureService';
Index: frontend/src/services/api.js
===================================================================
--- frontend/src/services/api.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/services/api.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -4,32 +4,32 @@
 
 const apiClient = axios.create({
-    baseURL: API_URL,
-    headers: {
-        'Content-Type': 'application/json',
-    },
+  baseURL: API_URL,
+  headers: {
+    'Content-Type': 'application/json',
+  },
 });
 
 // Request interceptor to add JWT token
 apiClient.interceptors.request.use(
-    config => {
-        const token = localStorage.getItem('token');
-        if (token) {
-            config.headers.Authorization = `Bearer ${token}`;
-            console.log(' Token added to request:', config.url);
-        } else {
-            console.warn(' No token found for request:', config.url);
-        }
-        return config;
-    },
-    error => Promise.reject(error)
+  config => {
+    const token = localStorage.getItem('token');
+    if (token) {
+      config.headers.Authorization = `Bearer ${token}`;
+      console.log('✅ Token added to request:', config.url);
+    } else {
+      console.warn('⚠️ No token found for request:', config.url);
+    }
+    return config;
+  },
+  error => Promise.reject(error)
 );
 
 // Error handling interceptor
 apiClient.interceptors.response.use(
-    response => response,
-    error => {
-        console.error('API Error:', error.response?.data || error.message);
-        return Promise.reject(error);
-    }
+  response => response,
+  error => {
+    console.error('API Error:', error.response?.data || error.message);
+    return Promise.reject(error);
+  }
 );
 
Index: frontend/src/services/labService.js
===================================================================
--- frontend/src/services/labService.js	(revision e1f74f6c04f9d460135de378f659fedfd9c74b44)
+++ frontend/src/services/labService.js	(revision cdcff72e9765342b84a5e4b5d98ca5cb050a5500)
@@ -47,10 +47,10 @@
   },
 
-  // Get pending lab tests for lab technicians
+  // Get pending lab tests (for lab technicians)
   getPendingLabTests: () => {
     return api.get('/lab-tests/requests/pending');
   },
 
-  // Get all submitted lab results for lab technicians
+  // Get all submitted lab results (for lab technicians)
   getAllSubmittedLabResults: () => {
     return api.get('/lab-tests/results');
