forked from taranjeetsingh9/PetConnectBackend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvet-dashboard.html
More file actions
743 lines (661 loc) · 31.6 KB
/
vet-dashboard.html
File metadata and controls
743 lines (661 loc) · 31.6 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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
<!DOCTYPE html>
<html>
<head>
<title>Vet Dashboard - PetConnect</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
.loading { opacity: 0.6; pointer-events: none; }
</style>
</head>
<body class="bg-gray-50 min-h-screen p-6">
<div class="max-w-6xl mx-auto">
<!-- Header -->
<div class="flex justify-between items-center mb-8">
<div>
<h1 class="text-3xl font-bold text-indigo-700">🏥 Vet Dashboard</h1>
<p id="vetInfo" class="text-gray-600">Loading...</p>
</div>
<div class="space-x-4">
<button onclick="refreshData()" class="bg-green-600 text-white px-4 py-2 rounded-lg hover:bg-green-700">
🔄 Refresh
</button>
<button onclick="window.location.href='index.html'" class="bg-gray-600 text-white px-4 py-2 rounded-lg hover:bg-gray-700">
← Back to Main
</button>
<button onclick="window.location.href='user-profile.html'"
class="bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700">
👤 My Profile
</button>
</div>
</div>
<!-- Stats Overview -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-8">
<div class="bg-white p-4 rounded-lg shadow border">
<h3 class="text-lg font-semibold text-gray-700">My Patients</h3>
<p id="patientsCount" class="text-2xl font-bold text-indigo-600">-</p>
</div>
<div class="bg-white p-4 rounded-lg shadow border">
<h3 class="text-lg font-semibold text-gray-700">Overdue Vaccinations</h3>
<p id="overdueCount" class="text-2xl font-bold text-red-600">-</p>
</div>
<div class="bg-white p-4 rounded-lg shadow border">
<h3 class="text-lg font-semibold text-gray-700">Upcoming Checkups</h3>
<p id="checkupsCount" class="text-2xl font-bold text-yellow-600">-</p>
</div>
<div class="bg-white p-4 rounded-lg shadow border">
<h3 class="text-lg font-semibold text-gray-700">Today's Date</h3>
<p id="todayDate" class="text-lg font-medium text-gray-600">-</p>
</div>
</div>
<!-- Main Content Tabs -->
<div class="bg-white rounded-lg shadow-lg mb-6">
<div class="border-b">
<nav class="flex -mb-px">
<button id="tabPatients" class="py-4 px-6 font-medium border-b-2 border-indigo-600 text-indigo-600">
My Patients
</button>
<button id="tabMedical" class="py-4 px-6 font-medium text-gray-500 hover:text-gray-700">
Medical Records
</button>
<button id="tabVaccinations" class="py-4 px-6 font-medium text-gray-500 hover:text-gray-700">
Vaccinations
</button>
</nav>
</div>
<!-- Tab Content -->
<div class="p-6">
<!-- Patients Tab -->
<div id="contentPatients">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-semibold">My Assigned Pets</h2>
<div class="text-sm text-gray-500" id="patientsStatus"></div>
</div>
<div id="patientsList" class="space-y-4">
<!-- Patients will be loaded here -->
</div>
</div>
<!-- Medical Records Tab -->
<div id="contentMedical" class="hidden">
<h2 class="text-xl font-semibold mb-4">Medical Records</h2>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div>
<h3 class="text-lg font-medium mb-3">Add Medical Record</h3>
<!-- In vet-dashboard.html, inside the medical records form -->
<div class="space-y-3">
<select id="medicalPetSelect" class="w-full p-3 border rounded-lg">
<option value="">Select a pet</option>
</select>
<input type="text" id="diagnosis" placeholder="Diagnosis *" class="w-full p-3 border rounded-lg" required>
<input type="text" id="treatment" placeholder="Treatment" class="w-full p-3 border rounded-lg">
<!-- ADD MEDICATIONS SECTION -->
<div class="border rounded-lg p-4 bg-gray-50">
<h4 class="font-medium mb-3">💊 Medications</h4>
<div id="medicationsContainer">
<!-- Medications will be added here dynamically -->
</div>
<button type="button" onclick="addMedicationField()" class="mt-2 bg-blue-500 text-white px-3 py-1 rounded text-sm hover:bg-blue-600">
+ Add Medication
</button>
</div>
<textarea id="medicalNotes" placeholder="Notes" class="w-full p-3 border rounded-lg h-24"></textarea>
<select id="urgency" class="w-full p-3 border rounded-lg">
<option value="low">Low Urgency</option>
<option value="medium">Medium Urgency</option>
<option value="high">High Urgency</option>
<option value="critical">Critical</option>
</select>
<input type="date" id="nextCheckup" class="w-full p-3 border rounded-lg">
<button onclick="addMedicalRecord()" class="w-full bg-indigo-600 text-white p-3 rounded-lg hover:bg-indigo-700">
Add Medical Record
</button>
</div>
</div>
<div>
<h3 class="text-lg font-medium mb-3">Recent Medical Records & Medications</h3>
<div id="recentMedicalRecords" class="space-y-4 max-h-96 overflow-y-auto">
<!-- Recent records with medications will appear here -->
</div>
</div>
</div>
</div>
<!-- Vaccinations Tab -->
<div id="contentVaccinations" class="hidden">
<h2 class="text-xl font-semibold mb-4">Vaccination Management</h2>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<div>
<h3 class="text-lg font-medium mb-3">Record Vaccination</h3>
<div class="space-y-3">
<select id="vaccinePetSelect" class="w-full p-3 border rounded-lg">
<option value="">Select a pet</option>
</select>
<input type="text" id="vaccineName" placeholder="Vaccine Name" class="w-full p-3 border rounded-lg">
<input type="date" id="dateAdministered" class="w-full p-3 border rounded-lg">
<input type="date" id="nextDueDate" class="w-full p-3 border rounded-lg">
<textarea id="vaccineNotes" placeholder="Notes" class="w-full p-3 border rounded-lg h-20"></textarea>
<button onclick="addVaccination()" class="w-full bg-green-600 text-white p-3 rounded-lg hover:bg-green-700">
Record Vaccination
</button>
</div>
</div>
<div>
<h3 class="text-lg font-medium mb-3">Overdue Vaccinations</h3>
<div id="overdueVaccinationsList" class="space-y-3">
<!-- Overdue vaccinations will appear here -->
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Loading Overlay -->
<div id="loadingOverlay" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white p-6 rounded-lg shadow-lg">
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-indigo-600 mx-auto"></div>
<p class="mt-3 text-gray-600">Loading...</p>
</div>
</div>
</div>
<script>
const VET_API_URL = 'http://localhost:5001/api/vet';
let vetToken = localStorage.getItem('vetToken') || localStorage.getItem('token');
let currentUser = JSON.parse(localStorage.getItem('user') || '{}');
let myPatients = [];
// Initialize dashboard
document.addEventListener('DOMContentLoaded', function() {
if (!vetToken) {
alert('No authentication token found. Please login again.');
window.location.href = 'index.html';
return;
}
document.getElementById('vetInfo').textContent = `Welcome, ${currentUser.name || 'Vet'} | ${currentUser.email || ''}`;
document.getElementById('todayDate').textContent = new Date().toLocaleDateString();
setupTabNavigation();
loadInitialData();
});
function setupTabNavigation() {
const tabs = ['tabPatients', 'tabMedical', 'tabVaccinations'];
const contents = ['contentPatients', 'contentMedical', 'contentVaccinations'];
tabs.forEach(tabId => {
document.getElementById(tabId).addEventListener('click', function() {
// Update tab styles
tabs.forEach(t => {
const tab = document.getElementById(t);
tab.classList.remove('border-indigo-600', 'text-indigo-600');
tab.classList.add('text-gray-500');
});
this.classList.add('border-indigo-600', 'text-indigo-600');
this.classList.remove('text-gray-500');
// Show corresponding content
contents.forEach(contentId => {
document.getElementById(contentId).classList.add('hidden');
});
const contentId = 'content' + tabId.replace('tab', '');
document.getElementById(contentId).classList.remove('hidden');
});
});
}
async function loadInitialData() {
showLoading();
try {
await Promise.all([
loadMyPatients(),
loadOverdueVaccinations(),
loadUpcomingCheckups()
]);
} catch (error) {
console.error('Error loading initial data:', error);
alert('Failed to load data. Please check your connection.');
} finally {
hideLoading();
}
}
async function loadMyPatients() {
try {
const response = await fetch(`${VET_API_URL}/my-patients`, {
headers: { 'x-auth-token': vetToken }
});
const data = await response.json();
if (data.success) {
myPatients = data.pets;
document.getElementById('patientsCount').textContent = data.count;
renderPatientsList();
updatePetSelects();
} else {
throw new Error(data.msg);
}
} catch (error) {
console.error('Error loading patients:', error);
document.getElementById('patientsStatus').textContent = 'Error loading patients';
}
}
function renderPatientsList() {
const container = document.getElementById('patientsList');
if (myPatients.length === 0) {
container.innerHTML = '<p class="text-center text-gray-500 py-8">No patients assigned to you yet.</p>';
return;
}
container.innerHTML = myPatients.map(patient => `
<div class="bg-gray-50 border rounded-lg p-4 hover:shadow-md transition-shadow">
<div class="flex justify-between items-start">
<div class="flex-1">
<h3 class="text-lg font-semibold text-indigo-700">${patient.name}</h3>
<div class="grid grid-cols-2 md:grid-cols-4 gap-2 text-sm text-gray-600 mt-2">
<div><strong>Breed:</strong> ${patient.breed || 'Unknown'}</div>
<div><strong>Age:</strong> ${patient.age || 'Unknown'} years</div>
<div><strong>Gender:</strong> ${patient.gender || 'Unknown'}</div>
<div><strong>Status:</strong> <span class="px-2 py-1 rounded-full text-xs ${getStatusColor(patient.status)}">${patient.status}</span></div>
</div>
<div class="mt-2">
<strong>Health Notes:</strong>
<span class="text-gray-700">${patient.healthNotes || 'No notes yet'}</span>
</div>
</div>
<div class="space-y-2 ml-4">
<button onclick="viewMedicalHistory('${patient._id}')" class="block w-full bg-blue-600 text-white px-3 py-1 rounded text-sm hover:bg-blue-700">
View History
</button>
<button onclick="quickHealthUpdate('${patient._id}')" class="block w-full bg-green-600 text-white px-3 py-1 rounded text-sm hover:bg-green-700">
Quick Update
</button>
</div>
</div>
</div>
`).join('');
}
function getStatusColor(status) {
const colors = {
'Available': 'bg-green-100 text-green-800',
'In Treatment': 'bg-yellow-100 text-yellow-800',
'Adopted': 'bg-blue-100 text-blue-800',
'Unavailable': 'bg-red-100 text-red-800'
};
return colors[status] || 'bg-gray-100 text-gray-800';
}
function updatePetSelects() {
const petSelects = ['medicalPetSelect', 'vaccinePetSelect'];
petSelects.forEach(selectId => {
const select = document.getElementById(selectId);
select.innerHTML = '<option value="">Select a pet</option>' +
myPatients.map(patient =>
`<option value="${patient._id}">${patient.name} (${patient.breed})</option>`
).join('');
});
}
async function loadOverdueVaccinations() {
try {
const response = await fetch(`${VET_API_URL}/overdue-vaccinations`, {
headers: { 'x-auth-token': vetToken }
});
const data = await response.json();
if (data.success) {
document.getElementById('overdueCount').textContent = data.count;
renderOverdueVaccinations(data.overdueVaccinations);
}
} catch (error) {
console.error('Error loading overdue vaccinations:', error);
}
}
function renderOverdueVaccinations(vaccinations) {
const container = document.getElementById('overdueVaccinationsList');
container.innerHTML = '';
vaccinations.forEach(vac => {
const petName = vac.pet?.name || 'Unknown Pet';
const breed = vac.pet?.breed || '-';
const age = vac.pet?.age || '-';
const gender = vac.pet?.gender || '-';
const item = document.createElement('div');
item.textContent = `${petName} (${breed}, ${age}y, ${gender}) - Vaccine: ${vac.vaccineName}`;
container.appendChild(item);
});
}
async function loadUpcomingCheckups() {
try {
const response = await fetch(`${VET_API_URL}/upcoming-checkups`, {
headers: { 'x-auth-token': vetToken }
});
const data = await response.json();
if (data.success) {
document.getElementById('checkupsCount').textContent = data.count;
}
} catch (error) {
console.error('Error loading upcoming checkups:', error);
}
}
async function addMedicalRecord() {
const petId = document.getElementById('medicalPetSelect').value;
const diagnosis = document.getElementById('diagnosis').value.trim();
if (!petId) {
alert('Please select a pet');
return;
}
if (!diagnosis) {
alert('Please enter a diagnosis');
document.getElementById('diagnosis').focus();
return;
}
const medications = getMedicationsData();
showLoading();
try {
const response = await fetch(`${VET_API_URL}/pets/${petId}/medical-records`, {
method: 'POST',
headers: {
'x-auth-token': vetToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
diagnosis: diagnosis,
treatment: document.getElementById('treatment').value.trim(),
medications: medications, // ✅ Now sending medications!
notes: document.getElementById('medicalNotes').value.trim(),
urgency: document.getElementById('urgency').value,
nextCheckup: document.getElementById('nextCheckup').value
})
});
const data = await response.json();
if (data.success) {
alert('✅ Medical record added successfully!');
// Clear form
document.getElementById('diagnosis').value = '';
document.getElementById('treatment').value = '';
document.getElementById('medicalNotes').value = '';
document.getElementById('nextCheckup').value = '';
// Clear medications
document.getElementById('medicationsContainer').innerHTML = '';
medicationCount = 0;
// Reload data
await loadInitialData();
} else {
throw new Error(data.msg || 'Failed to add medical record');
}
} catch (error) {
console.error('Error adding medical record:', error);
alert('❌ Failed to add medical record: ' + error.message);
} finally {
hideLoading();
}
}
async function addVaccination() {
const petId = document.getElementById('vaccinePetSelect').value;
const vaccineName = document.getElementById('vaccineName').value;
const dateAdministered = document.getElementById('dateAdministered').value;
const nextDueDate = document.getElementById('nextDueDate').value;
if (!petId || !vaccineName || !dateAdministered || !nextDueDate) {
alert('Please fill all required fields');
return;
}
showLoading();
try {
const response = await fetch(`${VET_API_URL}/pets/${petId}/vaccinations`, {
method: 'POST',
headers: {
'x-auth-token': vetToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
vaccineName: vaccineName,
dateAdministered: dateAdministered,
nextDueDate: nextDueDate,
notes: document.getElementById('vaccineNotes').value
})
});
const data = await response.json();
if (data.success) {
alert('Vaccination recorded successfully!');
// Clear form
document.getElementById('vaccineName').value = '';
document.getElementById('dateAdministered').value = '';
document.getElementById('nextDueDate').value = '';
document.getElementById('vaccineNotes').value = '';
// Reload data
await loadInitialData();
} else {
throw new Error(data.msg);
}
} catch (error) {
console.error('Error recording vaccination:', error);
alert('Failed to record vaccination: ' + error.message);
} finally {
hideLoading();
}
}
function viewMedicalHistory(petId) {
const pet = myPatients.find(p => p._id === petId);
if (pet) {
alert(`Medical history for ${pet.name}\n\nThis would open a detailed view with full medical records, vaccinations, and treatment history.`);
// In a real app, you'd navigate to a detailed medical history page
}
}
function quickHealthUpdate(petId) {
const pet = myPatients.find(p => p._id === petId);
if (pet) {
const notes = prompt(`Quick health update for ${pet.name}:`, pet.healthNotes || '');
if (notes !== null) {
// This would call your existing health notes endpoint
alert(`Would update health notes for ${pet.name} to: ${notes}`);
}
}
}
function recordVaccinationNow(petId, vaccineName) {
const today = new Date().toISOString().split('T')[0];
const nextYear = new Date();
nextYear.setFullYear(nextYear.getFullYear() + 1);
const nextDue = nextYear.toISOString().split('T')[0];
document.getElementById('vaccinePetSelect').value = petId;
document.getElementById('vaccineName').value = vaccineName + ' (Booster)';
document.getElementById('dateAdministered').value = today;
document.getElementById('nextDueDate').value = nextDue;
document.getElementById('vaccineNotes').value = 'Booster vaccination administered';
// Switch to vaccinations tab
document.getElementById('tabVaccinations').click();
}
function refreshData() {
loadInitialData();
}
function showLoading() {
document.getElementById('loadingOverlay').classList.remove('hidden');
document.body.classList.add('loading');
}
function hideLoading() {
document.getElementById('loadingOverlay').classList.add('hidden');
document.body.classList.remove('loading');
}
let medicationCount = 0;
function addMedicationField(medication = { name: '', dosage: '', frequency: '', duration: '' }) {
medicationCount++;
const container = document.getElementById('medicationsContainer');
const medicationHtml = `
<div class="medication-field border-b pb-3 mb-3" data-id="${medicationCount}">
<div class="flex justify-between items-center mb-2">
<span class="font-medium text-sm">Medication #${medicationCount}</span>
<button type="button" onclick="removeMedicationField(${medicationCount})" class="text-red-500 hover:text-red-700 text-sm">
🗑️ Remove
</button>
</div>
<div class="grid grid-cols-2 gap-2">
<input type="text"
id="medName_${medicationCount}"
placeholder="Medication Name"
value="${medication.name}"
class="p-2 border rounded text-sm">
<input type="text"
id="medDosage_${medicationCount}"
placeholder="Dosage (e.g., 10mg)"
value="${medication.dosage}"
class="p-2 border rounded text-sm">
<input type="text"
id="medFrequency_${medicationCount}"
placeholder="Frequency (e.g., 2x daily)"
value="${medication.frequency}"
class="p-2 border rounded text-sm">
<input type="text"
id="medDuration_${medicationCount}"
placeholder="Duration (e.g., 7 days)"
value="${medication.duration}"
class="p-2 border rounded text-sm">
</div>
</div>
`;
container.insertAdjacentHTML('beforeend', medicationHtml);
}
function removeMedicationField(id) {
const field = document.querySelector(`.medication-field[data-id="${id}"]`);
if (field) {
field.remove();
}
}
function getMedicationsData() {
const medications = [];
const fields = document.querySelectorAll('.medication-field');
fields.forEach(field => {
const id = field.getAttribute('data-id');
const name = document.getElementById(`medName_${id}`)?.value.trim();
const dosage = document.getElementById(`medDosage_${id}`)?.value.trim();
const frequency = document.getElementById(`medFrequency_${id}`)?.value.trim();
const duration = document.getElementById(`medDuration_${id}`)?.value.trim();
// Only add if at least name is provided
if (name) {
medications.push({
name: name,
dosage: dosage || '',
frequency: frequency || '',
duration: duration || ''
});
}
});
return medications;
}
async function loadRecentMedicalRecords() {
try {
// Since we don't have a direct endpoint for recent records,
// we'll use the existing data or create a new endpoint
const container = document.getElementById('recentMedicalRecords');
container.innerHTML = '<p class="text-gray-500 text-center py-4">Loading recent records...</p>';
// Get medical records for all assigned pets
let allRecords = [];
for (const patient of myPatients) {
try {
const response = await fetch(`${VET_API_URL}/pets/${patient._id}/medical-history`, {
headers: { 'x-auth-token': vetToken }
});
const data = await response.json();
if (data.success && data.medicalRecords) {
// Add pet name to each record
const recordsWithPetName = data.medicalRecords.map(record => ({
...record,
petName: patient.name
}));
allRecords = allRecords.concat(recordsWithPetName);
}
} catch (error) {
console.error(`Error loading records for ${patient.name}:`, error);
}
}
// Sort by date (newest first) and take last 10
const recentRecords = allRecords
.sort((a, b) => new Date(b.date) - new Date(a.date))
.slice(0, 10);
renderRecentMedicalRecords(recentRecords);
} catch (error) {
console.error('Error loading recent medical records:', error);
document.getElementById('recentMedicalRecords').innerHTML =
'<p class="text-red-500 text-center py-4">Error loading recent records</p>';
}
}
function renderRecentMedicalRecords(records) {
const container = document.getElementById('recentMedicalRecords');
if (records.length === 0) {
container.innerHTML = '<p class="text-gray-500 text-center py-4">No medical records yet</p>';
return;
}
container.innerHTML = records.map(record => `
<div class="bg-white border rounded-lg p-4 shadow-sm">
<div class="flex justify-between items-start mb-2">
<div>
<h4 class="font-semibold text-indigo-700">${record.petName || 'Unknown Pet'}</h4>
<p class="text-sm text-gray-600">${new Date(record.date).toLocaleDateString()}</p>
</div>
<span class="px-2 py-1 rounded-full text-xs ${getUrgencyColor(record.urgency)}">
${record.urgency.toUpperCase()}
</span>
</div>
<div class="mb-2">
<strong class="text-gray-700">Diagnosis:</strong>
<p class="text-sm">${record.diagnosis}</p>
</div>
${record.treatment ? `
<div class="mb-2">
<strong class="text-gray-700">Treatment:</strong>
<p class="text-sm">${record.treatment}</p>
</div>
` : ''}
<!-- MEDICATIONS SECTION -->
${record.medications && record.medications.length > 0 ? `
<div class="mb-2">
<strong class="text-gray-700">💊 Medications:</strong>
<div class="mt-1 space-y-1">
${record.medications.map(med => `
<div class="bg-blue-50 border border-blue-200 rounded p-2 text-sm">
<div class="flex justify-between">
<strong>${med.name}</strong>
${med.dosage ? `<span class="text-blue-600">${med.dosage}</span>` : ''}
</div>
${med.frequency || med.duration ? `
<div class="text-xs text-gray-600 mt-1">
${med.frequency ? `Frequency: ${med.frequency}` : ''}
${med.frequency && med.duration ? ' • ' : ''}
${med.duration ? `Duration: ${med.duration}` : ''}
</div>
` : ''}
</div>
`).join('')}
</div>
</div>
` : `
<div class="mb-2">
<strong class="text-gray-700">💊 Medications:</strong>
<p class="text-sm text-gray-500 italic">No medications prescribed</p>
</div>
`}
${record.notes ? `
<div class="mb-2">
<strong class="text-gray-700">Notes:</strong>
<p class="text-sm">${record.notes}</p>
</div>
` : ''}
${record.nextCheckup ? `
<div class="text-xs text-green-600">
<strong>Next Checkup:</strong> ${new Date(record.nextCheckup).toLocaleDateString()}
</div>
` : ''}
</div>
`).join('');
}
function getUrgencyColor(urgency) {
const colors = {
'low': 'bg-green-100 text-green-800',
'medium': 'bg-yellow-100 text-yellow-800',
'high': 'bg-orange-100 text-orange-800',
'critical': 'bg-red-100 text-red-800'
};
return colors[urgency] || 'bg-gray-100 text-gray-800';
}
async function loadInitialData() {
showLoading();
try {
await Promise.all([
loadMyPatients(),
loadOverdueVaccinations(),
loadUpcomingCheckups()
]);
// Load recent medical records after patients are loaded
await loadRecentMedicalRecords();
} catch (error) {
console.error('Error loading initial data:', error);
alert('Failed to load data. Please check your connection.');
} finally {
hideLoading();
}
}
</script>
</body>
</html>