190 lines
7.1 KiB
JavaScript
190 lines
7.1 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) {
|
|
} 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';
|
|
}
|
|
};
|
|
|
|
// Role-Based UI Filtering (Run on Load)
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const userRole = localStorage.getItem('userRole') || 'OWNER';
|
|
const userEmail = localStorage.getItem('userEmail') || 'admin@curio.app';
|
|
|
|
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;
|
|
|
|
if (userRole === 'DOCTOR') {
|
|
document.querySelectorAll('.side-nav a').forEach(link => {
|
|
if (link.innerText.includes('Billing') || link.innerText.includes('Staff') || link.innerText.includes('Overview')) {
|
|
link.style.display = 'none';
|
|
}
|
|
});
|
|
showSection('zen'); // Primary view for doctors
|
|
} else if (userRole === 'RECEPTIONIST') {
|
|
document.querySelectorAll('.side-nav a').forEach(link => {
|
|
if (link.innerText.includes('Lab') || link.innerText.includes('Staff')) {
|
|
link.style.display = 'none';
|
|
}
|
|
});
|
|
showSection('overview');
|
|
}
|
|
});
|