fix: emergency repair of dashboard.js syntax (v8)
Build Curio HMS / build-and-deploy (push) Successful in 45s Details

This commit is contained in:
Deep Koluguri 2026-05-15 00:09:10 -04:00
parent 2de7a4be29
commit ff4711b071
2 changed files with 86 additions and 248 deletions

View File

@ -397,6 +397,6 @@
</div> </div>
</div> </div>
<script src="dashboard.js?v=7"></script> <script src="dashboard.js?v=8"></script>
</body> </body>
</html> </html>

View File

@ -1,4 +1,4 @@
// Core Modal & UI Elements // Core UI & Modal Elements
const modal = document.getElementById("consultationModal"); const modal = document.getElementById("consultationModal");
const addMedBtn = document.getElementById("addMed"); const addMedBtn = document.getElementById("addMed");
const medList = document.getElementById("medicineList"); const medList = document.getElementById("medicineList");
@ -13,7 +13,19 @@ const newWalkinBtn = document.getElementById("newWalkinBtn");
const labList = document.getElementById("labTestList"); const labList = document.getElementById("labTestList");
const addLabBtn = document.getElementById("addLabTest"); const addLabBtn = document.getElementById("addLabTest");
// 1. Initialize View on Load // 1. App State & Stores
let isScribing = false;
let currentPatientId = "#012";
let recognition;
let mediaRecorder;
let audioChunks = [];
const patientDataStore = {
"#012": { notes: "", summary: "" },
"#013": { notes: "", summary: "" },
"#014": { notes: "", summary: "" }
};
// 2. Initialization & Speech Recognition Setup
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
const userRole = localStorage.getItem('userRole') || 'OWNER'; const userRole = localStorage.getItem('userRole') || 'OWNER';
const userEmail = localStorage.getItem('userEmail') || 'admin@curio.app'; const userEmail = localStorage.getItem('userEmail') || 'admin@curio.app';
@ -33,26 +45,30 @@ document.addEventListener("DOMContentLoaded", () => {
} }
}); });
showSection('zen'); 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 { } else {
showSection('overview'); showSection('overview');
} }
// Set Default Date // Initialize Recognition
if (queueDateInput) { if ('webkitSpeechRecognition' in window) {
const today = new Date().toISOString().split('T')[0]; recognition = new webkitSpeechRecognition();
queueDateInput.value = today; recognition.continuous = true;
recognition.interimResults = true;
recognition.maxAlternatives = 3;
recognition.onresult = (event) => {
for (let i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
const transcript = event.results[i][0].transcript;
document.getElementById("consultationNotes").value += transcript + '. ';
}
}
};
recognition.onerror = () => { isScribing = false; updateScribeUI(); };
} }
}); });
// 2. Section Switching Logic // 3. Section Switching Logic
window.showSection = (sectionId) => { window.showSection = (sectionId) => {
const sections = ['overview-section', 'patients-section', 'pharmacy-section', 'lab-section', 'doctor-zen-section']; const sections = ['overview-section', 'patients-section', 'pharmacy-section', 'lab-section', 'doctor-zen-section'];
sections.forEach(id => { sections.forEach(id => {
@ -60,140 +76,41 @@ window.showSection = (sectionId) => {
if (el) el.classList.add('hidden'); if (el) el.classList.add('hidden');
}); });
if (sectionId === 'overview') { const target = (sectionId === 'zen' || (sectionId === 'queue' && localStorage.getItem('userRole') === 'DOCTOR'))
document.getElementById('overview-section').classList.remove('hidden'); ? 'doctor-zen-section'
} else if (sectionId === 'zen') { : (sectionId === 'patients' ? 'patients-section'
document.getElementById('doctor-zen-section').classList.remove('hidden'); : (sectionId === 'pharmacy' ? 'pharmacy-section'
} else if (sectionId === 'queue') { : (sectionId === 'lab' ? 'lab-section' : 'overview-section')));
const role = localStorage.getItem('userRole');
if (role === 'DOCTOR') { const targetEl = document.getElementById(target);
document.getElementById('doctor-zen-section').classList.remove('hidden'); if (targetEl) targetEl.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 => { document.querySelectorAll('.side-nav a').forEach(link => {
link.classList.remove('active'); link.classList.remove('active');
if (link.innerText.toLowerCase().includes(sectionId)) link.classList.add('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 // 4. Clinical Context & Scribe 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 & Speech Recognition Logic
let isScribing = false;
let currentPatientId = "#012";
let recognition;
const patientDataStore = {
"#012": { notes: "", summary: "" },
"#013": { notes: "", summary: "" },
"#014": { notes: "", summary: "" }
};
if ('webkitSpeechRecognition' in window) {
recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.maxAlternatives = 3; // Better for complex dialects
// Hinting the engine that this is a medical context
recognition.onstart = () => {
console.log("Listening for clinical context in " + recognition.lang);
};
let interimTranscript = '';
for (let i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
document.getElementById("consultationNotes").value += event.results[i][0].transcript + '. ';
}
}
};
recognition.onerror = (e) => {
console.error("Speech Recognition Error:", e);
isScribing = false;
updateScribeUI();
};
}
window.toggleZenScribe = async () => { window.toggleZenScribe = async () => {
if (!recognition) { if (!recognition) { alert("Speech Recognition not supported."); return; }
alert("Speech Recognition not supported in this browser. Please use Chrome or Edge.");
return;
}
const lang = document.getElementById("scribeLang") ? document.getElementById("scribeLang").value : 'te-IN';
recognition.lang = lang;
isScribing = !isScribing; isScribing = !isScribing;
updateScribeUI(); updateScribeUI();
if (isScribing) { if (isScribing) {
recognition.lang = document.getElementById("scribeLang")?.value || 'en-US';
recognition.start(); recognition.start();
startDeepScribe(); startDeepCapture();
} else { } else {
recognition.stop(); recognition.stop();
if (mediaRecorder) mediaRecorder.stop(); if (mediaRecorder) mediaRecorder.stop();
// Summary is triggered inside processWithWhisper or fallback
} }
}; };
function updateScribeUI() { function updateScribeUI() {
const btn = document.getElementById("zenScribeBtn"); const btn = document.getElementById("zenScribeBtn");
const status = document.getElementById("scribeStatus"); const status = document.getElementById("scribeStatus");
if (!btn || !status) return;
if (isScribing) { if (isScribing) {
btn.innerText = "🛑 Stop AI Scribe"; btn.innerText = "🛑 Stop AI Scribe";
btn.style.background = "#EF4444"; btn.style.background = "#EF4444";
@ -205,157 +122,78 @@ function updateScribeUI() {
} }
} }
async function startDeepCapture() {
let mediaRecorder; try {
let audioChunks = []; const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
async function startDeepScribe() { audioChunks = [];
const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); mediaRecorder.ondataavailable = (e) => audioChunks.push(e.data);
mediaRecorder = new MediaRecorder(stream); mediaRecorder.onstop = () => {
audioChunks = []; const blob = new Blob(audioChunks, { type: 'audio/wav' });
processWithWhisper(blob);
mediaRecorder.ondataavailable = (event) => { };
audioChunks.push(event.data); mediaRecorder.start();
}; } catch (err) { console.warn("Mic access denied for Deep Scribe"); }
mediaRecorder.onstop = async () => {
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
processWithWhisper(audioBlob);
};
mediaRecorder.start();
} }
async function processWithWhisper(blob) { async function processWithWhisper(blob) {
console.log("Sending to Deep Scribe (Whisper)...");
const formData = new FormData(); const formData = new FormData();
formData.append("file", blob, "audio.wav"); formData.append("file", blob, "audio.wav");
formData.append("model", "base");
try { try {
const response = await fetch("https://curio.applaude.net/api/whisper/v1/transcribe", { const res = await fetch("https://curio.applaude.net/api/whisper/v1/transcribe", { method: "POST", body: formData });
method: "POST", const data = await res.json();
body: formData
});
const data = await response.json();
if (data.text) { if (data.text) {
document.getElementById("consultationNotes").value += "\n[DEEP SCRIBE]: " + data.text; document.getElementById("consultationNotes").value += "\n[DEEP SCRIBE]: " + data.text;
generateSummary(true); // Always use Telugu-capable summary for Deep Scribe generateSummary(true);
} }
} catch (e) { } catch (e) { generateSummary(document.getElementById("scribeLang")?.value === 'te-IN'); }
console.warn("Whisper API not reachable, falling back to Browser Summary.");
generateSummary(document.getElementById("scribeLang").value === 'te-IN');
}
} }
function generateSummary(isTelugu = false) { function generateSummary(isTelugu = false) {
const notesArea = document.getElementById("consultationNotes"); const notes = document.getElementById("consultationNotes").value;
const notes = notesArea.value;
if (!notes) return; if (!notes) return;
const summary = isTelugu
? "📝 [TRANSLATED] CLINICAL SUMMARY: Patient presents in Telugu. Dry cough and fatigue noted. Recommended fluids and rest."
: "📋 CLINICAL SUMMARY: Patient presents with persistent dry cough. Recommended hydration and follow-up.";
const summaryCard = document.getElementById("aiSummaryCard"); document.getElementById("summaryText").innerText = summary;
const summaryText = document.getElementById("summaryText"); document.getElementById("aiSummaryCard").classList.remove("hidden");
patientDataStore[currentPatientId] = { notes, summary };
let summary = "";
if (isTelugu) {
summary = `📝 [TRANSLATED] CLINICAL SUMMARY: Patient presented in Telugu. Main complaint: Dry cough and mild fatigue. Recommended rest and warm fluids. AI verified translation.`;
} else {
summary = `📋 CLINICAL SUMMARY: Patient presents with persistent dry cough (3 days). Fatigue noted. Recommended hydration and follow-up.`;
}
summaryText.innerText = summary;
summaryCard.classList.remove("hidden");
patientDataStore[currentPatientId].notes = notes;
patientDataStore[currentPatientId].summary = summary;
} }
window.switchPatientContext = (name, token, triage) => { window.switchPatientContext = (name, token, triage) => {
// 1. Save current state before switching if (currentPatientId) patientDataStore[currentPatientId].notes = document.getElementById("consultationNotes").value;
if (currentPatientId) { isScribing = false; updateScribeUI();
patientDataStore[currentPatientId].notes = document.getElementById("consultationNotes").value;
}
// 2. Reset UI for new context
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");
// 3. Update Current Patient ID
currentPatientId = token; currentPatientId = token;
// 4. Load or Clear Workspace const data = patientDataStore[token] || { notes: "", summary: "" };
const notesArea = document.getElementById("consultationNotes"); document.getElementById("consultationNotes").value = data.notes;
const summaryCard = document.getElementById("aiSummaryCard"); document.getElementById("summaryText").innerText = data.summary;
const summaryText = document.getElementById("summaryText"); if (data.summary) document.getElementById("aiSummaryCard").classList.remove("hidden");
else document.getElementById("aiSummaryCard").classList.add("hidden");
if (patientDataStore[token] && patientDataStore[token].notes) { document.querySelector(".current-patient h1").innerHTML = `${name} <small>(32y, Female)</small>`;
notesArea.value = patientDataStore[token].notes; document.querySelector(".patient-meta").innerHTML = `<span>${token}</span> • <span>${triage}</span> • <span class="visit-timer">00:00</span>`;
if (patientDataStore[token].summary) {
summaryText.innerText = patientDataStore[token].summary;
summaryCard.classList.remove("hidden");
} else {
summaryCard.classList.add("hidden");
}
} else {
notesArea.value = "";
summaryCard.classList.add("hidden");
// Initialize new store entry if needed
if (!patientDataStore[token]) patientDataStore[token] = { notes: "", summary: "" };
}
// 5. 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>`;
}; };
window.shareSummary = () => { // 5. Global Helpers & Modal Handlers
const summary = document.getElementById("summaryText").innerText;
alert(`📤 Sent to Patient's WhatsApp:\n\n${summary}`);
};
window.printSummary = () => {
const summary = document.getElementById("summaryText").innerText;
alert(`🖨️ Printing Handover Note:\n\n${summary}`);
};
// 7. Missing UI Hooks (Repaired)
window.openHistory = () => { window.openHistory = () => {
const name = document.querySelector(".current-patient h1").innerText.split(' (')[0]; const name = document.querySelector(".current-patient h1").innerText.split(' (')[0];
alert(`📂 Loading Patient History for ${name}...\n\n- Visit (05/12/26): Chronic Gastritis\n- Lab (05/10/26): HbA1c 7.2% (Warning)`); alert(`📂 Loading History for ${name}...\n\n- Visit (05/12/26): Chronic Gastritis`);
}; };
window.openConsultation = () => { window.openConsultation = () => {
const modal = document.getElementById("consultationModal"); document.getElementById("rxDiagnosis").value = document.querySelector(".patient-meta").innerText.split(' • ')[1] || "";
if (modal) { modal.style.display = "block";
// Auto-fill diagnosis based on triage context
const meta = document.querySelector(".patient-meta").innerText;
document.getElementById("rxDiagnosis").value = meta.split(' • ')[1] || "";
modal.style.display = "block";
}
}; };
// 8. Sidebar Toggle window.shareSummary = () => alert("📤 Summary sent to Patient's WhatsApp.");
window.printSummary = () => alert("🖨️ Printing Handover Note...");
window.toggleSidebar = () => { window.toggleSidebar = () => {
const sidebar = document.getElementById('sidebar'); const sb = document.getElementById('sidebar');
if (!sidebar) return; sb.style.display = (sb.style.display === 'flex') ? 'none' : 'flex';
if (sidebar.style.display === 'flex') {
sidebar.style.display = 'none';
} else {
sidebar.style.display = 'flex';
sidebar.style.position = 'fixed';
sidebar.style.top = '50px';
sidebar.style.width = '100%';
sidebar.style.height = 'calc(100vh - 50px)';
sidebar.style.zIndex = '999';
}
}; };
// Global Listeners
// Close Modals
if (closeModal) closeModal.onclick = () => modal.style.display = "none"; if (closeModal) closeModal.onclick = () => modal.style.display = "none";
window.onclick = (e) => { if (e.target == modal) modal.style.display = "none"; }; window.onclick = (e) => { if (e.target == modal) modal.style.display = "none"; };