document.addEventListener("DOMContentLoaded", () => { const radios = document.querySelectorAll(".patient-radio"); const sidebarPatientInfo = document.getElementById("sidebarPatientInfo"); const sbOverview = document.getElementById("sbOverview"); const sbHistory = document.getElementById("sbHistory"); const sbEdit = document.getElementById("sbEdit"); const sbMeds = document.getElementById("sbMeds"); const sbWaitingRoomWrapper = document.getElementById("sbWaitingRoomWrapper"); const sbActiveWrapper = document.getElementById("sbActiveWrapper"); const sbUploadForm = document.getElementById("sbUploadForm"); const sbUploadInput = document.getElementById("sbUploadInput"); const sbUploadBtn = document.getElementById("sbUploadBtn"); if ( !radios.length || !sidebarPatientInfo || !sbOverview || !sbHistory || !sbEdit || !sbMeds || !sbWaitingRoomWrapper || !sbActiveWrapper || !sbUploadForm || !sbUploadInput || !sbUploadBtn ) { return; } // ✅ Sicherheit: Upload blocken falls nicht aktiv sbUploadForm.addEventListener("submit", (e) => { if (!sbUploadForm.action || sbUploadForm.action.endsWith("#")) { e.preventDefault(); } }); radios.forEach((radio) => { radio.addEventListener("change", () => { const id = radio.value; const firstname = radio.dataset.firstname; const lastname = radio.dataset.lastname; const waiting = radio.dataset.waiting === "1"; const active = radio.dataset.active === "1"; // ✅ Patient Info sidebarPatientInfo.innerHTML = `
${firstname} ${lastname}
ID: ${id}
`; // ✅ Übersicht sbOverview.href = "/patients/" + id; sbOverview.classList.remove("disabled"); // ✅ Verlauf sbHistory.href = "/patients/" + id + "/overview"; sbHistory.classList.remove("disabled"); // ✅ Bearbeiten sbEdit.href = "/patients/edit/" + id; sbEdit.classList.remove("disabled"); // ✅ Medikamente sbMeds.href = "/patients/" + id + "/medications"; sbMeds.classList.remove("disabled"); // ✅ Wartezimmer (NUR wenn Patient aktiv ist) if (!active) { sbWaitingRoomWrapper.innerHTML = ` `; } else if (waiting) { sbWaitingRoomWrapper.innerHTML = ` `; } else { sbWaitingRoomWrapper.innerHTML = `
`; } // ✅ Sperren / Entsperren if (active) { sbActiveWrapper.innerHTML = `
`; } else { sbActiveWrapper.innerHTML = `
`; } // ✅ Upload nur aktiv wenn Patient ausgewählt sbUploadForm.action = "/patients/" + id + "/files"; sbUploadInput.disabled = false; sbUploadBtn.disabled = false; }); }); });