refactor: integrate prescription builder seamlessly into doctor workspace
Build Curio HMS / build-and-deploy (push) Successful in 1m5s Details

This commit is contained in:
Deep Koluguri 2026-06-03 01:33:00 -04:00
parent 4a5ea663b6
commit 3410976b21
5 changed files with 149 additions and 230 deletions

View File

@ -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) ─────────────────

View File

@ -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; }
}

View File

@ -184,14 +184,41 @@
<label for="soap-p">Plan</label>
<textarea id="soap-p" class="zen-textarea-small" placeholder="Treatment, Rx, follow-up..." tabindex="4"></textarea>
</div>
</div>
</div>
<div id="prescription-print-area" class="prescription-builder" style="margin-top: 1.5rem; background: #fff; padding: 1.5rem; border-radius: 8px; border: 1px solid var(--border-color);">
<div class="print-only">
<h2 style="margin-bottom:0.5rem; color:#0F172A;">Curio Clinic</h2>
<p style="margin-bottom:0.25rem;"><strong><span class="doctor-name-print">Dr. Sharma</span></strong> | <span class="doctor-spec-print">Cardiologist</span></p>
<p style="margin-bottom:1rem; border-bottom: 2px solid #000; padding-bottom: 1rem;">Date: <span id="print-date"></span></p>
<div style="display:flex; justify-content:space-between; margin-bottom: 1.5rem; text-align:left;">
<div><strong>Patient:</strong> <span id="print-patient-name">Rahul Verma</span></div>
<div><strong>ID/Phone:</strong> <span id="print-patient-id">P1</span></div>
</div>
</div>
<div class="form-group" style="margin-bottom: 1rem;">
<label style="font-weight: 600; display: block; margin-bottom: 0.5rem;">Medicines (Rx)</label>
<div id="medicines-container" class="medicines-list">
<!-- Medicine rows injected here -->
</div>
<button class="btn btn-sm btn-secondary actions-row" style="width:fit-content; margin-top: 1rem;" onclick="addMedicineRow()">+ Add Medicine</button>
</div>
<div class="actions-row" style="display: flex; gap: 1rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border-color);">
<button class="btn btn-primary" onclick="submitPrescription()">✅ Prescribe & Send to Pharmacy</button>
<button class="btn btn-secondary" onclick="window.print()">🖨️ Print Prescription</button>
</div>
</div>
<div id="aiSummaryCard" class="summary-card hidden">
<div class="card-header">✨ AI Clinical Summary</div>
<div id="summaryText" class="summary-content"></div>
<div class="summary-actions">
<button class="btn-small secondary" onclick="shareSummary()">📤 Send</button>
<button class="btn-small secondary" onclick="printSummary()">🖨️ Print</button>
<button class="btn-small secondary" onclick="window.print()">🖨️ Print</button>
</div>
</div>
</main>

View File

@ -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 = `
<input type="text" class="form-control med-name" placeholder="Medicine Name">
<input type="text" class="form-control med-dosage" placeholder="Dosage (e.g. 500mg)">
<input type="text" class="form-control med-freq" placeholder="Frequency (e.g. 1-0-1)">
<input type="text" class="form-control med-dur" placeholder="Duration (e.g. 5 days)">
<button class="btn btn-sm btn-secondary actions-row" onclick="this.parentElement.remove()"></button>
`;
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.');
}
}

View File

@ -1,228 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Doctor Dashboard | Curio HMS</title>
<link rel="stylesheet" href="globals.css">
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="dashboard.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@500;600;700&display=swap" rel="stylesheet">
<script src="globals.js"></script>
<style>
.prescription-builder {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.form-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.form-group label {
font-weight: 600;
color: var(--text-dark);
}
.form-control {
padding: 0.75rem;
border: 1px solid var(--border-color);
border-radius: 6px;
font-family: inherit;
}
.medicines-list {
display: flex;
flex-direction: column;
gap: 1rem;
}
.medicine-row {
display: grid;
grid-template-columns: 2fr 1fr 1fr 1fr auto;
gap: 1rem;
align-items: center;
background: #f8fafc;
padding: 1rem;
border-radius: 6px;
border: 1px solid var(--border-color);
}
.print-only {
display: none;
}
/* Print Styles */
@media print {
body * {
visibility: hidden;
}
.sidebar, .dash-header, .header-actions, .actions-row {
display: none !important;
}
#prescription-print-area, #prescription-print-area * {
visibility: visible;
}
#prescription-print-area {
position: absolute;
left: 0;
top: 0;
width: 100%;
padding: 2rem;
}
.print-only {
display: block;
text-align: center;
margin-bottom: 2rem;
border-bottom: 2px solid #000;
padding-bottom: 1rem;
}
.medicine-row {
border: none;
background: none;
border-bottom: 1px dashed #ccc;
grid-template-columns: 2fr 1fr 1fr 1fr;
}
.medicine-row button {
display: none;
}
.form-control {
border: none;
padding: 0;
appearance: none;
background: transparent;
}
}
</style>
</head>
<body class="dashboard-body">
<aside class="sidebar">
<div class="logo">
<div class="logo-icon">C</div>
<span class="logo-text">Curio</span>
</div>
<nav class="side-nav">
<a href="doctor-dashboard.html" class="active"><span>🩺</span> Consultations</a>
<a href="dashboard.html"><span>📂</span> Patients</a>
<a href="login.html" class="logout-btn" style="margin-top:auto;"><span>🚪</span> Logout</a>
</nav>
</aside>
<main class="dashboard-main">
<header class="dash-header">
<div class="header-title">
<h1>Doctor Dashboard</h1>
<p>Record details, prescribe medicines, and send to pharmacy.</p>
</div>
<div class="header-actions">
<button class="btn btn-secondary" onclick="window.print()">🖨️ Print Prescription</button>
<button class="btn btn-primary" onclick="submitPrescription()">✅ Prescribe & Send</button>
</div>
</header>
<section class="section-card" id="prescription-print-area">
<div class="print-only">
<h2>Curio Clinic</h2>
<p>Dr. Sharma | MBBS, MD</p>
<p>Date: <span id="print-date"></span></p>
</div>
<div class="prescription-builder">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
<div class="form-group">
<label>Patient ID / Phone</label>
<input type="text" id="patient-id" class="form-control" placeholder="e.g., 9876543210">
</div>
<div class="form-group">
<label>Patient Name</label>
<input type="text" id="patient-name" class="form-control" placeholder="Patient Full Name">
</div>
</div>
<div class="form-group">
<label>Symptoms & Diagnosis</label>
<textarea id="diagnosis" class="form-control" rows="3" placeholder="Enter diagnosis..."></textarea>
</div>
<div class="form-group">
<label>Medicines</label>
<div id="medicines-container" class="medicines-list">
<!-- Medicine rows injected here -->
</div>
<button class="btn btn-secondary actions-row" style="width:fit-content; margin-top: 1rem;" onclick="addMedicineRow()">+ Add Medicine</button>
</div>
</div>
</section>
</main>
<script>
document.getElementById('print-date').innerText = new Date().toLocaleDateString();
function addMedicineRow() {
const container = document.getElementById('medicines-container');
const row = document.createElement('div');
row.className = 'medicine-row';
row.innerHTML = `
<input type="text" class="form-control med-name" placeholder="Medicine Name">
<input type="text" class="form-control med-dosage" placeholder="Dosage (e.g. 500mg)">
<input type="text" class="form-control med-freq" placeholder="Frequency (e.g. 1-0-1)">
<input type="text" class="form-control med-dur" placeholder="Duration (e.g. 5 days)">
<button class="btn btn-sm btn-secondary actions-row" onclick="this.parentElement.remove()"></button>
`;
container.appendChild(row);
}
// Add initial row
addMedicineRow();
async function submitPrescription() {
const patientId = document.getElementById('patient-id').value;
const patientName = document.getElementById('patient-name').value;
const diagnosis = document.getElementById('diagnosis').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 patient name and at least one medicine.");
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);
window.print();
// Clear form
document.getElementById('patient-id').value = '';
document.getElementById('patient-name').value = '';
document.getElementById('diagnosis').value = '';
document.getElementById('medicines-container').innerHTML = '';
addMedicineRow();
} else {
alert('Failed to create prescription.');
}
} catch (err) {
console.error(err);
alert('An error occurred.');
}
}
</script>
</body>
</html>