curaflow/dashboard.js

191 lines
7.3 KiB
JavaScript

// Core Modal & UI Elements
const modal = document.getElementById("consultationModal");
const addMedBtn = document.getElementById("addMed");
const medList = document.getElementById("medicineList");
const sendRxBtn = document.getElementById("sendRx");
const closeModal = document.querySelector(".close-modal");
const startRecordBtn = document.getElementById("startRecording");
const recordingStatus = document.getElementById("recordingStatus");
const aiInsightsBox = document.getElementById("aiInsights");
const insightText = document.getElementById("insightText");
const queueDateInput = document.getElementById("queueDate");
const newWalkinBtn = document.getElementById("newWalkinBtn");
const labList = document.getElementById("labTestList");
const addLabBtn = document.getElementById("addLabTest");
// 1. Initialize View on Load
document.addEventListener("DOMContentLoaded", () => {
const userRole = localStorage.getItem('userRole') || 'OWNER';
const userEmail = localStorage.getItem('userEmail') || 'admin@curio.app';
// Set Sidebar Profile
const roleDisplay = document.querySelector(".user-profile .info strong");
const emailDisplay = document.querySelector(".user-profile .info span");
if (roleDisplay) roleDisplay.innerText = userRole.charAt(0) + userRole.slice(1).toLowerCase();
if (emailDisplay) emailDisplay.innerText = userEmail;
// Apply Role-Based Filtering
if (userRole === 'DOCTOR') {
document.querySelectorAll('.side-nav a').forEach(link => {
const text = link.innerText;
if (text.includes('Billing') || text.includes('Staff') || text.includes('Overview')) {
link.style.display = 'none';
}
});
showSection('zen');
} else if (userRole === 'RECEPTIONIST') {
document.querySelectorAll('.side-nav a').forEach(link => {
const text = link.innerText;
if (text.includes('Lab') || text.includes('Staff')) {
link.style.display = 'none';
}
});
showSection('overview');
} else {
showSection('overview');
}
// Set Default Date
if (queueDateInput) {
const today = new Date().toISOString().split('T')[0];
queueDateInput.value = today;
}
});
// 2. Section Switching Logic
window.showSection = (sectionId) => {
const sections = ['overview-section', 'patients-section', 'pharmacy-section', 'lab-section', 'doctor-zen-section'];
sections.forEach(id => {
const el = document.getElementById(id);
if (el) el.classList.add('hidden');
});
if (sectionId === 'overview') {
document.getElementById('overview-section').classList.remove('hidden');
} else if (sectionId === 'zen') {
document.getElementById('doctor-zen-section').classList.remove('hidden');
} else if (sectionId === 'queue') {
const role = localStorage.getItem('userRole');
if (role === 'DOCTOR') {
document.getElementById('doctor-zen-section').classList.remove('hidden');
} else {
document.getElementById('overview-section').classList.remove('hidden');
document.getElementById('queue-section').scrollIntoView({ behavior: 'smooth' });
}
} else if (sectionId === 'patients') {
document.getElementById('patients-section').classList.remove('hidden');
} else if (sectionId === 'pharmacy') {
document.getElementById('pharmacy-section').classList.remove('hidden');
} else if (sectionId === 'lab') {
document.getElementById('lab-section').classList.remove('hidden');
}
// Nav Active State
document.querySelectorAll('.side-nav a').forEach(link => {
link.classList.remove('active');
if (link.innerText.toLowerCase().includes(sectionId)) link.classList.add('active');
});
// Mobile Auto-hide Sidebar
if (window.innerWidth <= 768) {
const sb = document.getElementById('sidebar');
if (sb) sb.style.display = 'none';
}
};
// 3. Clinical Consultation Logic
if (addMedBtn) {
addMedBtn.onclick = () => {
const row = document.createElement("div");
row.className = "med-row";
row.innerHTML = `
<input type="text" placeholder="Medicine Name" class="med-name">
<input type="text" placeholder="Dosage (e.g. 1-0-1)" class="med-dosage">
<input type="text" placeholder="Duration" class="med-duration">
`;
medList.appendChild(row);
};
}
if (addLabBtn) {
addLabBtn.onclick = () => {
const row = document.createElement("div");
row.className = "lab-row";
row.style = "display: flex; gap: 0.5rem; margin-bottom: 0.5rem;";
row.innerHTML = `<input type="text" placeholder="Test Name" class="lab-test-name" style="flex: 1; padding: 0.6rem; border-radius: 8px; border: 1px solid var(--border);">`;
labList.appendChild(row);
};
}
// 4. Voice AI Simulation
if (startRecordBtn) {
startRecordBtn.onclick = () => {
startRecordBtn.classList.add("hidden");
recordingStatus.classList.remove("hidden");
setTimeout(() => {
recordingStatus.classList.add("hidden");
aiInsightsBox.classList.remove("hidden");
insightText.innerText = "Viral infection detected. Avoid cold drinks for 3 days. Follow-up in 1 week.";
document.getElementById("rxDiagnosis").value = "Viral Infection";
}, 2000);
};
}
// 6. AI Scribe & Context Switching Logic
let isScribing = false;
window.toggleZenScribe = () => {
const btn = document.getElementById("zenScribeBtn");
const status = document.getElementById("scribeStatus");
const notes = document.querySelector(".zen-textarea");
isScribing = !isScribing;
if (isScribing) {
btn.innerText = "🛑 Stop AI Scribe";
btn.style.background = "#EF4444";
status.classList.remove("hidden");
// Simulate AI Scribe capturing notes
setTimeout(() => {
if (isScribing) {
notes.value += "Patient reports symptoms of fatigue and persistent dry cough for 3 days. No fever recorded today. \n";
}
}, 3000);
} else {
btn.innerText = "🎙️ Start AI Scribe";
btn.style.background = "";
status.classList.add("hidden");
}
};
window.switchPatientContext = (name, token, triage) => {
// 1. Reset Scribe State
isScribing = false;
const btn = document.getElementById("zenScribeBtn");
if (btn) {
btn.innerText = "🎙️ Start AI Scribe";
btn.style.background = "";
}
const status = document.getElementById("scribeStatus");
if (status) status.classList.add("hidden");
// 2. Clear Current Workspace
const notes = document.querySelector(".zen-textarea");
if (notes) notes.value = "";
// 3. Update Headers
const h1 = document.querySelector(".current-patient h1");
if (h1) h1.innerHTML = `${name} <small>(32y, Female)</small>`;
const meta = document.querySelector(".patient-meta");
if (meta) meta.innerHTML = `<span>${token}</span> • <span>${triage}</span> • <span class="visit-timer">00:00</span>`;
alert(`Switched context to: ${name}. AI Scribe reset.`);
};
// Close Modals
if (closeModal) closeModal.onclick = () => modal.style.display = "none";
window.onclick = (e) => { if (e.target == modal) modal.style.display = "none"; };