curaflow/dashboard.js

209 lines
7.6 KiB
JavaScript

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");
// Initialize Date Picker to Today
if (queueDateInput) {
const today = new Date().toISOString().split('T')[0];
queueDateInput.value = today;
queueDateInput.min = today; // Prevent past dates
queueDateInput.addEventListener("change", (e) => {
console.log(`Switching view to date: ${e.target.value}`);
// In a real app, this would fetch the queue for that specific date
alert(`Now viewing appointments for: ${e.target.value}`);
});
}
// Handle New Walk-in for selected date
if (newWalkinBtn) {
newWalkinBtn.addEventListener("click", () => {
const selectedDate = queueDateInput.value;
const name = prompt("Enter Patient Name:");
if (name) {
console.log(`Booking walk-in for ${name} on ${selectedDate}`);
alert(`Token generated for ${name} on ${selectedDate}. \n\nPlease print the token and hand it to the patient.`);
}
});
}
// Open modal when clicking 'Prescribe'
document.querySelectorAll(".btn-small").forEach(btn => {
if (btn.innerText === "Prescribe") {
btn.addEventListener("click", () => {
modal.style.display = "block";
});
}
});
closeModal.onclick = () => modal.style.display = "none";
window.onclick = (event) => {
if (event.target == modal) modal.style.display = "none";
};
const labList = document.getElementById("labTestList");
const addLabBtn = document.getElementById("addLabTest");
// Add new medicine row
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);
};
// Add new lab test row
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 (e.g. CBC, Lipid)" class="lab-test-name" style="flex: 1; padding: 0.6rem; border-radius: 8px; border: 1px solid var(--border);">
`;
labList.appendChild(row);
};
// Handle sending prescription
sendRxBtn.onclick = () => {
const diagnosis = document.getElementById("rxDiagnosis").value;
const meds = [];
document.querySelectorAll(".med-row").forEach(row => {
const name = row.querySelector(".med-name").value;
if (name) {
meds.push({
name,
dosage: row.querySelector(".med-dosage").value,
duration: row.querySelector(".med-duration").value
});
}
});
if (!diagnosis || meds.length === 0) {
alert("Please enter diagnosis and at least one medicine.");
return;
}
// Simulate sending to backend
console.log("Sending Rx:", { diagnosis, meds });
// UI Feedback
sendRxBtn.innerText = "Sent! ✅";
sendRxBtn.style.background = "#10B981";
setTimeout(() => {
modal.style.display = "none";
sendRxBtn.innerText = "Send to WhatsApp";
sendRxBtn.style.background = "";
const note = document.getElementById("deptNote").value;
if (note) {
console.log("Dept Note:", note);
alert("Prescription sent. Note forwarded to Pharmacy/Lab.");
} else {
alert("Prescription has been sent to the patient's WhatsApp.");
}
}, 1500);
};
window.shareTip = (type) => {
const tips = {
diabetes: "🥗 Healthy Diet Tip: Reduce white rice, add more greens.",
hypertension: "🧘 BP Control: Limit salt intake to 5g/day.",
viral: "💧 Hydration: Drink 3L of warm water daily."
};
alert(`📤 Sent to Patient's WhatsApp:\n\n${tips[type]}`);
};
window.printTips = () => {
alert("🖨️ Printing General Health Guidelines for this patient...");
};
// Voice AI Logic
startRecordBtn.onclick = () => {
startRecordBtn.classList.add("hidden");
recordingStatus.classList.remove("hidden");
// Simulate recording for 3 seconds
setTimeout(() => {
recordingStatus.classList.add("hidden");
aiInsightsBox.classList.remove("hidden");
// Mock data filtering simulation
const mockTranscript = "Hello Rahul, how is your family? The weather is very hot today. Regarding your cough, it seems like a viral infection. You should avoid cold drinks for 3 days. Take the paracetamol after meals. I'll see you in a week.";
// Filter out small talk (AI simulation)
const insights = "Viral infection detected. Avoid cold drinks for 3 days. Take paracetamol after meals. Follow-up in 1 week.";
insightText.innerText = insights;
// Auto-fill diagnosis if empty
if (!document.getElementById("rxDiagnosis").value) {
document.getElementById("rxDiagnosis").value = "Viral Infection";
}
}, 3000);
};
// Section Switching Logic
window.showSection = (sectionId) => {
// Hide all sections
const sections = ['overview-section', 'patients-section', 'pharmacy-section', 'lab-section'];
sections.forEach(id => {
const el = document.getElementById(id);
if (el) el.classList.add('hidden');
});
// Show target section
if (sectionId === 'overview') {
document.getElementById('overview-section').classList.remove('hidden');
} else if (sectionId === 'queue') {
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');
}
// Update active state in nav
document.querySelectorAll('.side-nav a').forEach(link => {
link.classList.remove('active');
if (link.innerText.toLowerCase().includes(sectionId)) {
link.classList.add('active');
}
});
// Auto-hide sidebar on mobile after clicking
if (window.innerWidth <= 768) {
document.getElementById('sidebar').style.display = 'none';
}
};
window.toggleSidebar = () => {
const sidebar = document.getElementById('sidebar');
if (sidebar.style.display === 'flex') {
sidebar.style.display = 'none';
} else {
sidebar.style.display = 'flex';
sidebar.style.position = 'fixed';
sidebar.style.top = '50px';
sidebar.style.left = '0';
sidebar.style.width = '100%';
sidebar.style.height = 'calc(100vh - 50px)';
sidebar.style.zIndex = '999';
}
};