|
| 1 | +document.addEventListener("DOMContentLoaded", function () { |
| 2 | + const container = document.getElementById("records-container"); |
| 3 | + const previewBody = document.getElementById("preview-body"); |
| 4 | + const downloadBtn = document.getElementById("download-btn"); |
| 5 | + const confirmDownloadBtn = document.getElementById("confirm-download"); |
| 6 | + const retryBtn = document.getElementById("retry-btn"); |
| 7 | + const errorContainer = document.getElementById("error-container"); |
| 8 | + const recordMessage = document.getElementById("record-message"); |
| 9 | + |
| 10 | + const records = [ |
| 11 | + { title: "Annual Physical Exam", date: "2024-01-15", summary: "Routine check-up. Vitals normal. No follow-up needed." }, |
| 12 | + { title: "Blood Test Report", date: "2024-02-20", summary: "Slightly elevated cholesterol. Recommended dietary changes." }, |
| 13 | + { title: "Flu Vaccination", date: "2024-03-05", summary: "Administered seasonal influenza vaccine. No side effects." }, |
| 14 | + { title: "Dermatology Consultation", date: "2024-04-12", summary: "Treated for mild eczema. Prescribed topical corticosteroid." }, |
| 15 | + { title: "Eye Examination", date: "2024-05-18", summary: "20/20 vision confirmed. No corrective lenses required." }, |
| 16 | + { title: "MRI Scan (Knee)", date: "2024-06-22", summary: "Minor inflammation observed. Recommended physiotherapy." }, |
| 17 | + { title: "Cardiology Checkup", date: "2024-07-15", summary: "Heart function normal. No abnormalities detected." }, |
| 18 | + { title: "Dental Cleaning", date: "2024-08-05", summary: "Teeth cleaned. No cavities or issues noted." }, |
| 19 | + { title: "Allergy Testing", date: "2024-09-10", summary: "Positive for dust mites and pollen. Prescribed antihistamines." }, |
| 20 | + { title: "COVID-19 Booster Shot", date: "2024-10-02", summary: "Booster administered. Mild soreness at injection site." }, |
| 21 | + { title: "Nutrition Counseling", date: "2024-11-08", summary: "Advised on low-sodium diet for better blood pressure management." }, |
| 22 | + { title: "Physical Therapy Follow-Up", date: "2024-12-15", summary: "Improved mobility after 6 sessions. Continued exercises recommended." }, |
| 23 | + { title: "Annual Physical Exam", date: "2025-01-10", summary: "Routine check-up. Vitals normal. Follow-up appointment scheduled." }, |
| 24 | + { title: "Blood Test Report", date: "2025-02-11", summary: "Cholesterol levels improved. Continue current diet plan." }, |
| 25 | + { title: "Flu Vaccination", date: "2025-03-12", summary: "Administered seasonal influenza vaccine. No adverse reactions." }, |
| 26 | + { title: "Dermatology Consultation", date: "2025-04-13", summary: "Eczema well-controlled. Continue current treatment regimen." }, |
| 27 | + { title: "Eye Examination", date: "2025-05-14", summary: "Vision remains stable at 20/20. Annual follow-up recommended." }, |
| 28 | + { title: "MRI Scan (Knee)", date: "2025-06-15", summary: "Significant improvement in inflammation. Continue physiotherapy." } |
| 29 | + ]; |
| 30 | + |
| 31 | + // Update dashboard stats |
| 32 | + localStorage.setItem("medical_records_count", records.length); |
| 33 | + |
| 34 | + function loadRecords() { |
| 35 | + container.innerHTML = ""; |
| 36 | + |
| 37 | + if (records.length === 0) { |
| 38 | + if (recordMessage) { |
| 39 | + recordMessage.style.display = "block"; |
| 40 | + } |
| 41 | + downloadBtn.disabled = true; |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + records.forEach((r) => { |
| 46 | + const col = document.createElement("div"); |
| 47 | + col.className = "col-md-4"; |
| 48 | + col.innerHTML = ` |
| 49 | + <div class='record-card'> |
| 50 | + <div class='record-title'>${r.title}</div> |
| 51 | + <div class='record-date'>${r.date}</div> |
| 52 | + <div class='record-summary'>${r.summary}</div> |
| 53 | + </div>`; |
| 54 | + container.appendChild(col); |
| 55 | + }); |
| 56 | + |
| 57 | + container.style.display = "flex"; |
| 58 | + errorContainer.style.display = "none"; |
| 59 | + downloadBtn.disabled = false; |
| 60 | + |
| 61 | + if (recordMessage) { |
| 62 | + recordMessage.style.display = "none"; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + retryBtn?.addEventListener("click", loadRecords); |
| 67 | + |
| 68 | + downloadBtn.addEventListener("click", () => { |
| 69 | + let html = "<h4>Preview</h4>"; |
| 70 | + records.forEach((r) => { |
| 71 | + html += `<div><b>${r.title}</b><br>Date: ${r.date}<br>${r.summary}</div><hr>`; |
| 72 | + }); |
| 73 | + previewBody.innerHTML = html; |
| 74 | + new bootstrap.Modal(document.getElementById("previewModal")).show(); |
| 75 | + }); |
| 76 | + |
| 77 | + confirmDownloadBtn.addEventListener("click", () => { |
| 78 | + const { jsPDF } = window.jspdf; |
| 79 | + const doc = new jsPDF(); |
| 80 | + let y = 20; |
| 81 | + records.forEach((r) => { |
| 82 | + doc.text(`• ${r.title}`, 10, y += 10); |
| 83 | + doc.text(`Date: ${r.date}`, 15, y += 8); |
| 84 | + doc.text(`Summary: ${r.summary}`, 15, y += 8); |
| 85 | + y += 10; |
| 86 | + }); |
| 87 | + doc.save("Medical_Records.pdf"); |
| 88 | + }); |
| 89 | + |
| 90 | + loadRecords(); |
| 91 | +}); |
0 commit comments