From 3410976b219970e3b6a64ab3eddcb5357ef29b14 Mon Sep 17 00:00:00 2001 From: Deep Koluguri Date: Wed, 3 Jun 2026 01:33:00 -0400 Subject: [PATCH] refactor: integrate prescription builder seamlessly into doctor workspace --- backend/server.js | 1 - dashboard.css | 22 ++++ dashboard.html | 29 +++++- dashboard.js | 99 ++++++++++++++++++ doctor-dashboard.html | 228 ------------------------------------------ 5 files changed, 149 insertions(+), 230 deletions(-) delete mode 100644 doctor-dashboard.html diff --git a/backend/server.js b/backend/server.js index 31d801f..e85087c 100644 --- a/backend/server.js +++ b/backend/server.js @@ -85,7 +85,6 @@ app.get('/admin', (req, res) => sendHtmlPage(res, 'admin.html')); app.get('/dashboard', (req, res) => sendHtmlPage(res, 'dashboard.html')); app.get('/register', (req, res) => sendHtmlPage(res, 'register.html')); app.get('/super-admin', (req, res) => sendHtmlPage(res, 'super-admin.html')); -app.get('/doctor-dashboard', (req, res) => sendHtmlPage(res, 'doctor-dashboard.html')); // ── Multi-tenant Config API (DB-first, fallback to in-memory) ───────────────── diff --git a/dashboard.css b/dashboard.css index 040ef44..da1eaa3 100644 --- a/dashboard.css +++ b/dashboard.css @@ -1867,3 +1867,25 @@ body.zen-mode-active .dash-header { gap: 1.5rem; } } + +/* --- Prescription Builder & Print Styles --- */ +.medicines-list { display: flex; flex-direction: column; gap: 0.5rem; } +.medicine-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 0.5rem; align-items: center; background: #f8fafc; padding: 0.75rem; border-radius: 6px; border: 1px solid var(--border-color); } +.medicine-row input { padding: 0.5rem; border: 1px solid #ccc; border-radius: 4px; font-size: 0.9rem; } +.print-only { display: none; } + +@media print { + body * { visibility: hidden; } + .sidebar, .dash-header, .header-actions, .actions-row, .sidebar-backdrop, .sidebar-mobile-toggle, .zen-sidebar-right, #aiSummaryCard { display: none !important; } + #prescription-print-area, #prescription-print-area * { visibility: visible; } + #prescription-print-area { position: absolute; left: 0; top: 0; width: 100%; padding: 2rem; border: none !important; background: transparent !important; } + .print-only { display: block; text-align: center; margin-bottom: 2rem; } + .medicine-row { border: none; background: none; border-bottom: 1px dashed #ccc; grid-template-columns: 2fr 1fr 1fr 1fr; padding: 0.5rem 0; } + .medicine-row button { display: none; } + .medicine-row input { border: none; padding: 0; background: transparent; font-weight: 500; color: #000; } + textarea { border: none; resize: none; overflow: hidden; background: transparent; color: #000; height: auto; min-height: unset; } + .soap-field { border: none !important; padding: 0 !important; background: transparent !important; margin-bottom: 1rem; } + .soap-field label { font-size: 1.1rem; color: #000; font-weight: bold; border-bottom: 1px solid #000; display: inline-block; padding-bottom: 2px; margin-bottom: 0.5rem; } + .btn-sync { display: none; } +} + diff --git a/dashboard.html b/dashboard.html index 77b1c88..399f2e0 100644 --- a/dashboard.html +++ b/dashboard.html @@ -184,14 +184,41 @@ + +
+ + +
+ +
+ +
+ +
+ +
+ + +
+
+ diff --git a/dashboard.js b/dashboard.js index c8a0098..abc5357 100644 --- a/dashboard.js +++ b/dashboard.js @@ -886,3 +886,102 @@ window.saveSettings = async () => { }, 3000); } }; +// --- Prescription Builder Logic --- +function addMedicineRow() { + const container = document.getElementById('medicines-container'); + if (!container) return; + const row = document.createElement('div'); + row.className = 'medicine-row'; + row.innerHTML = ` + + + + + + `; + container.appendChild(row); +} + +// Initial setup when opening a patient +const originalOpenPatient = window.openPatient; +window.openPatient = function(name, id) { + if (originalOpenPatient) originalOpenPatient(name, id); + + // Fill print details + const printName = document.getElementById('print-patient-name'); + const printId = document.getElementById('print-patient-id'); + const printDate = document.getElementById('print-date'); + if (printName) printName.innerText = name; + if (printId) printId.innerText = id; + if (printDate) printDate.innerText = new Date().toLocaleDateString(); + + // Reset medicines + const medContainer = document.getElementById('medicines-container'); + if (medContainer) { + medContainer.innerHTML = ''; + addMedicineRow(); + } +}; + +// If there was no original openPatient (it was inline or something), let's hook into the global DOM elements instead: +document.addEventListener('DOMContentLoaded', () => { + // If medicines container exists, add the first row + const medContainer = document.getElementById('medicines-container'); + if (medContainer && medContainer.children.length === 0) { + addMedicineRow(); + } +}); + +async function submitPrescription() { + // Attempt to pull patient name from the main dashboard header (if openPatient didn't set it) + let patientName = document.getElementById('print-patient-name').innerText; + let patientId = document.getElementById('print-patient-id').innerText; + + // Fallback: pull from the h1 element in the clinical workspace if it exists + const titleEl = document.querySelector('.patient-title-bar h1'); + if (titleEl && (!patientName || patientName === 'Rahul Verma')) { // 'Rahul Verma' is the default template + patientName = titleEl.childNodes[0].textContent.trim(); + patientId = 'N/A'; // We might not have it displayed easily + } + + const diagnosis = document.getElementById('soap-a').value; + + const medicines = []; + document.querySelectorAll('.medicine-row').forEach(row => { + const name = row.querySelector('.med-name').value; + if (name) { + medicines.push({ + name: name, + dosage: row.querySelector('.med-dosage').value, + frequency: row.querySelector('.med-freq').value, + duration: row.querySelector('.med-dur').value + }); + } + }); + + if (!patientName || medicines.length === 0) { + alert("Please fill in at least one medicine and ensure patient name is loaded."); + return; + } + + try { + const res = await apiCall('/api/prescriptions', 'POST', { + patientId, + patientName, + diagnosis, + medicines, + labTests: [] + }); + + if (res.success) { + alert('Prescription created and sent to pharmacy! ID: ' + res.prescriptionId); + // Optionally print right away + // window.print(); + } else { + alert('Failed to create prescription.'); + } + } catch (err) { + console.error(err); + alert('An error occurred while creating the prescription.'); + } +} diff --git a/doctor-dashboard.html b/doctor-dashboard.html deleted file mode 100644 index 39ea145..0000000 --- a/doctor-dashboard.html +++ /dev/null @@ -1,228 +0,0 @@ - - - - - - Doctor Dashboard | Curio HMS - - - - - - - - - - - - -
-
-
-

Doctor Dashboard

-

Record details, prescribe medicines, and send to pharmacy.

-
-
- - -
-
- -
- - -
-
-
- - -
-
- - -
-
- -
- - -
- -
- -
- -
- -
-
-
-
- - - -