-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdashboard.html
More file actions
610 lines (528 loc) Β· 20.1 KB
/
dashboard.html
File metadata and controls
610 lines (528 loc) Β· 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Medical Llama - Dashboard</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: #f3f4f6;
min-height: 100vh;
}
.navbar {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px 40px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.navbar-brand {
font-size: 24px;
font-weight: bold;
display: flex;
align-items: center;
gap: 10px;
}
.navbar-user {
display: flex;
align-items: center;
gap: 20px;
}
.user-info {
text-align: right;
}
.user-name {
font-weight: 600;
font-size: 16px;
}
.user-email {
font-size: 14px;
opacity: 0.9;
}
.logout-btn {
padding: 10px 20px;
background: rgba(255,255,255,0.2);
border: 1px solid white;
color: white;
border-radius: 8px;
cursor: pointer;
font-size: 14px;
transition: all 0.3s;
}
.logout-btn:hover {
background: rgba(255,255,255,0.3);
}
.container {
max-width: 1200px;
margin: 40px auto;
padding: 0 20px;
}
.welcome-section {
background: white;
padding: 40px;
border-radius: 20px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
.welcome-section h1 {
font-size: 32px;
color: #1f2937;
margin-bottom: 10px;
}
.welcome-section p {
font-size: 18px;
color: #6b7280;
}
.dashboard-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 25px;
}
.dashboard-card {
background: white;
padding: 30px;
border-radius: 20px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
cursor: pointer;
transition: all 0.3s;
border: 2px solid transparent;
}
.dashboard-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 30px rgba(0,0,0,0.15);
border-color: #667eea;
}
.card-icon {
font-size: 48px;
margin-bottom: 20px;
}
.card-title {
font-size: 24px;
font-weight: 700;
color: #1f2937;
margin-bottom: 10px;
}
.card-description {
font-size: 16px;
color: #6b7280;
line-height: 1.5;
}
.card-action {
margin-top: 20px;
padding: 12px 24px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 10px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
}
.card-action:hover {
transform: translateY(-2px);
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.appointments-section {
background: white;
padding: 30px;
border-radius: 20px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
.appointments-section h2 {
font-size: 24px;
color: #1f2937;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.appointment-card {
background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
border: 2px solid #e5e7eb;
border-left: 5px solid #667eea;
border-radius: 15px;
padding: 20px;
margin-bottom: 15px;
transition: all 0.3s;
}
.appointment-card:hover {
border-color: #667eea;
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}
.appointment-header {
display: flex;
justify-content: space-between;
align-items: start;
margin-bottom: 15px;
}
.appointment-time {
font-size: 18px;
font-weight: bold;
color: #1f2937;
}
.appointment-date {
font-size: 14px;
color: #6b7280;
margin-top: 5px;
}
.appointment-status {
padding: 5px 15px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
}
.status-scheduled {
background: #dbeafe;
color: #1e40af;
}
.status-confirmed {
background: #d1fae5;
color: #065f46;
}
.appointment-details {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-top: 15px;
}
.detail-item {
display: flex;
align-items: center;
gap: 8px;
color: #374151;
font-size: 14px;
}
.no-appointments {
text-align: center;
padding: 40px;
color: #6b7280;
}
.notifications-section {
background: white;
padding: 30px;
border-radius: 20px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
.notifications-section h2 {
font-size: 24px;
color: #1f2937;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.notification-item {
background: #f9fafb;
border-left: 4px solid #667eea;
border-radius: 10px;
padding: 15px;
margin-bottom: 12px;
transition: all 0.3s;
cursor: pointer;
}
.notification-item:hover {
background: #f3f4f6;
}
.notification-item.unread {
background: #ede9fe;
border-left-color: #7c3aed;
}
.notification-title {
font-weight: 600;
color: #1f2937;
margin-bottom: 5px;
font-size: 15px;
}
.notification-message {
color: #6b7280;
font-size: 14px;
line-height: 1.5;
}
.notification-time {
color: #9ca3af;
font-size: 12px;
margin-top: 8px;
}
.no-notifications {
text-align: center;
padding: 40px;
color: #6b7280;
}
.badge {
display: inline-block;
background: #ef4444;
color: white;
border-radius: 10px;
padding: 2px 8px;
font-size: 12px;
font-weight: bold;
margin-left: 10px;
}
</style>
</head>
<body>
<nav class="navbar">
<div class="navbar-brand">
π₯ Medical Llama
</div>
<div class="navbar-user">
<div class="user-info">
<div class="user-name" id="userName">Loading...</div>
<div class="user-email" id="userEmail"></div>
</div>
<button class="logout-btn" onclick="handleLogout()">Logout</button>
</div>
</nav>
<div class="container">
<div class="welcome-section">
<h1 id="welcomeMessage">Welcome back!</h1>
<p>What would you like to do today?</p>
</div>
<!-- Notifications Section -->
<div class="notifications-section" id="notificationsSection">
<h2>π Notifications <span class="badge" id="notificationBadge" style="display: none;">0</span></h2>
<div id="notificationsList">
<div class="loading-spinner">Loading notifications...</div>
</div>
</div>
<!-- Upcoming Appointments Section -->
<div class="appointments-section" id="appointmentsSection">
<h2>π
Upcoming Appointments</h2>
<div id="appointmentsList">
<div class="loading-spinner">Loading appointments...</div>
</div>
</div>
<div class="dashboard-grid">
<div class="dashboard-card" onclick="navigateTo('chat_ui.html')">
<div class="card-icon">π¬</div>
<div class="card-title">Start Consultation</div>
<div class="card-description">
Chat with our AI assistant about your symptoms and get personalized medical guidance.
</div>
<button class="card-action">Start Chat</button>
</div>
<div class="dashboard-card" onclick="navigateTo('medical_history.html')">
<div class="card-icon">π</div>
<div class="card-title">Medical History</div>
<div class="card-description">
View your complete medical history, past consultations, diagnoses, and prescribed medications.
</div>
<button class="card-action">View History</button>
</div>
<div class="dashboard-card" onclick="navigateTo('profile.html')">
<div class="card-icon">π€</div>
<div class="card-title">Profile Settings</div>
<div class="card-description">
Update your personal information, medical conditions, allergies, and current medications.
</div>
<button class="card-action">Edit Profile</button>
</div>
</div>
</div>
<script>
// Check if user is logged in
const currentUser = JSON.parse(localStorage.getItem('currentUser') || 'null');
if (!currentUser) {
window.location.href = '/';
} else {
// Display user info
document.getElementById('userName').textContent = `${currentUser.first_name} ${currentUser.last_name}`;
document.getElementById('userEmail').textContent = currentUser.email;
document.getElementById('welcomeMessage').textContent = `Welcome back, ${currentUser.first_name}!`;
// Load appointments and notifications
loadAppointments();
loadNotifications();
// Set up auto-refresh every 30 seconds
setInterval(() => {
loadNotifications();
}, 30000);
}
async function loadAppointments() {
const appointmentsList = document.getElementById('appointmentsList');
try {
const response = await fetch(`/appointments/user/${currentUser.id}?status=scheduled`);
const appointments = await response.json();
if (appointments.length === 0) {
appointmentsList.innerHTML = `
<div class="no-appointments">
<p style="font-size: 48px; margin-bottom: 10px;">π
</p>
<p>No upcoming appointments</p>
<p style="font-size: 14px; margin-top: 5px;">Start a consultation to book an appointment with a doctor</p>
</div>
`;
return;
}
// Only show upcoming appointments
const now = new Date();
const upcomingAppointments = appointments.filter(appt =>
new Date(appt.appointment_date) > now
);
if (upcomingAppointments.length === 0) {
appointmentsList.innerHTML = `
<div class="no-appointments">
<p style="font-size: 48px; margin-bottom: 10px;">π
</p>
<p>No upcoming appointments</p>
</div>
`;
return;
}
appointmentsList.innerHTML = upcomingAppointments.map(appt => {
const date = new Date(appt.appointment_date);
const dateStr = date.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric'
});
const timeStr = date.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit'
});
const statusClass = `status-${appt.status}`;
return `
<div class="appointment-card">
<div class="appointment-header">
<div>
<div class="appointment-time">${timeStr}</div>
<div class="appointment-date">${dateStr}</div>
</div>
<span class="appointment-status ${statusClass}">${appt.status}</span>
</div>
<div class="appointment-details">
<div class="detail-item">
<span>π¨ββοΈ</span>
<span><strong>Dr. ${appt.doctor_name}</strong></span>
</div>
<div class="detail-item">
<span>π</span>
<span>${appt.doctor_specialization}</span>
</div>
<div class="detail-item">
<span>π₯</span>
<span>${appt.hospital_name}</span>
</div>
<div class="detail-item">
<span>π</span>
<span>${appt.hospital_address}</span>
</div>
<div class="detail-item">
<span>π©Ί</span>
<span>${appt.reason}</span>
</div>
<div class="detail-item">
<span>β±οΈ</span>
<span>${appt.duration_minutes} minutes</span>
</div>
</div>
</div>
`;
}).join('');
} catch (error) {
console.error('Error loading appointments:', error);
appointmentsList.innerHTML = `
<div class="no-appointments">
<p style="color: #ef4444;">Failed to load appointments</p>
</div>
`;
}
}
async function loadNotifications() {
const notificationsList = document.getElementById('notificationsList');
const badge = document.getElementById('notificationBadge');
try {
const response = await fetch(`/notifications/user/${currentUser.id}`);
const notifications = await response.json();
const unreadCount = notifications.filter(n => !n.read).length;
if (unreadCount > 0) {
badge.textContent = unreadCount;
badge.style.display = 'inline-block';
} else {
badge.style.display = 'none';
}
if (notifications.length === 0) {
notificationsList.innerHTML = `
<div class="no-notifications">
<p style="font-size: 48px; margin-bottom: 10px;">π</p>
<p>No notifications yet</p>
</div>
`;
return;
}
// Show only last 5 notifications
const recentNotifications = notifications.slice(0, 5);
notificationsList.innerHTML = recentNotifications.map(notif => {
const date = new Date(notif.created_at);
const timeAgo = getTimeAgo(date);
const unreadClass = notif.read ? '' : 'unread';
return `
<div class="notification-item ${unreadClass}" onclick="markAsRead(${notif.id})">
<div class="notification-title">${notif.title}</div>
<div class="notification-message">${notif.message}</div>
<div class="notification-time">${timeAgo}</div>
</div>
`;
}).join('');
} catch (error) {
console.error('Error loading notifications:', error);
notificationsList.innerHTML = `
<div class="no-notifications">
<p style="color: #ef4444;">Failed to load notifications</p>
</div>
`;
}
}
async function markAsRead(notificationId) {
try {
await fetch(`/notifications/${notificationId}/read`, {
method: 'POST'
});
loadNotifications(); // Refresh notifications
} catch (error) {
console.error('Error marking notification as read:', error);
}
}
function getTimeAgo(date) {
const seconds = Math.floor((new Date() - date) / 1000);
let interval = Math.floor(seconds / 31536000);
if (interval >= 1) return interval + " year" + (interval === 1 ? "" : "s") + " ago";
interval = Math.floor(seconds / 2592000);
if (interval >= 1) return interval + " month" + (interval === 1 ? "" : "s") + " ago";
interval = Math.floor(seconds / 86400);
if (interval >= 1) return interval + " day" + (interval === 1 ? "" : "s") + " ago";
interval = Math.floor(seconds / 3600);
if (interval >= 1) return interval + " hour" + (interval === 1 ? "" : "s") + " ago";
interval = Math.floor(seconds / 60);
if (interval >= 1) return interval + " minute" + (interval === 1 ? "" : "s") + " ago";
return "Just now";
}
function handleLogout() {
if (confirm('Are you sure you want to logout?')) {
localStorage.removeItem('currentUser');
localStorage.removeItem('authToken');
window.location.href = '/';
}
}
function navigateTo(page) {
// Map old file names to new routes
const routeMap = {
'chat_ui.html': '/chat',
'medical_history.html': '/history',
'profile.html': '/profile'
};
window.location.href = routeMap[page] || page;
}
</script>
</body>
</html>