Surgeon: ${surgeon}
Time Elapsed: ${Math.round(elapsed)} of ${currentCase.ScheduledDurationMinutes} min
`;
} else if (lastFinishedCase && (currentTime - lastFinishedCase.ActualOutTime) / 60000 < 20) { // 20 min cleaning time
status = 'Cleaning';
content = `Cleaning for next case. Next up at ${nextCase ? nextCase.ScheduledStartTime.toLocaleTimeString([], {hour:'2-digit', minute:'2-digit'}) : 'N/A'}`;
}
orCard.classList.add(`or-status-${status.toLowerCase()}`);
orCard.innerHTML = `
${orName} - ${status}
${content}`;
orGrid.appendChild(orCard);
});
document.getElementById('kpi-turnover').textContent = turnoverCount > 0 ? `${Math.round(totalTurnoverTime / turnoverCount)}m` : 'N/A';
// Simplified OR Utilization
const totalCaseMinutes = todayCases.reduce((sum, c) => sum + (c.ActualOutTime && c.ActualInTime ? (c.ActualOutTime - c.ActualInTime)/60000 : 0), 0);
const totalAvailableMinutes = orNames.length * 8 * 60; // Assuming 8-hour day
document.getElementById('kpi-utilization').textContent = totalAvailableMinutes > 0 ? `${Math.round(totalCaseMinutes / totalAvailableMinutes * 100)}%` : '0%';
};
const renderAnalyticsDashboard = (todayCases) => {
if(charts.specialty) charts.specialty.destroy();
if(charts.payor) charts.payor.destroy();
const casesBySpecialty = todayCases.reduce((acc, c) => {
const specialty = sourceData.surgeons.find(s=>s.SurgeonID === c.SurgeonID)?.Specialty || 'Unknown';
acc[specialty] = (acc[specialty] || 0) + 1;
return acc;
}, {});
charts.specialty = new Chart(document.getElementById('casesBySpecialtyChart').getContext('2d'), {
type: 'bar', data: { labels: Object.keys(casesBySpecialty), datasets: [{ label: 'Case Volume', data: Object.values(casesBySpecialty), backgroundColor: var(--primary-color) }] },
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false }, title: { display: true, text: 'Case Volume by Specialty' } } }
});
const revenueByPayor = todayCases.reduce((acc, c) => {
acc[c.InsurancePayor] = (acc[c.InsurancePayor] || 0) + c.TotalCharges;
return acc;
}, {});
charts.payor = new Chart(document.getElementById('revenueByPayorChart').getContext('2d'), {
type: 'doughnut', data: { labels: Object.keys(revenueByPayor), datasets: [{ data: Object.values(revenueByPayor), backgroundColor: ['#00a8ff', '#9c88ff', '#fbc531', '#4cd137', '#e84118'] }] },
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' }, title: { display: true, text: 'Revenue by Payor' } } }
});
};
const renderCustomization = () => { /* Logic to render customization UI would be here */ };
// --- EVENT LISTENERS ---
generateBtn.addEventListener('click', buildDashboard);
window.ascSwitchTab = (evt, tabName) => {
if (evt.currentTarget.classList.contains('disabled')) return;
document.querySelectorAll('#asc-dashboard-container .asc-tab-content').forEach(tc => tc.style.display = 'none');
document.querySelectorAll('#asc-dashboard-container .asc-tab-button').forEach(tl => tl.classList.remove('active'));
document.getElementById(tabName).style.display = 'block';
evt.currentTarget.classList.add('active');
};
// --- INITIALIZATION ---
loadSampleData();
});