curaflow/dashboard.js

96 lines
3.4 KiB
JavaScript

const modal = document.getElementById("prescriptionModal");
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");
// 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";
};
// 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" class="med-dosage">
<input type="text" placeholder="Freq" class="med-freq">
`;
medList.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,
frequency: row.querySelector(".med-freq").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 = "";
alert("Prescription has been sent to the patient's WhatsApp.");
}, 1500);
};
// 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);
};