4271 lines
142 KiB
HTML
4271 lines
142 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="hi">
|
||
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>KEM Hospital — Diabetes Dost 🩺</title>
|
||
<link rel="icon" type="image/png" sizes="32x32" href="/static/kem_hospital_logo.png?v=kem">
|
||
<link rel="icon" type="image/png" sizes="16x16" href="/static/kem_hospital_logo.png?v=kem">
|
||
<link rel="shortcut icon" href="/static/kem_hospital_logo.png?v=kem">
|
||
<link rel="apple-touch-icon" href="/static/kem_hospital_logo.png?v=kem">
|
||
<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=Outfit:wght@300;400;500;600;700;800&family=Inter:wght@300;400;500;600;700;800&family=Noto+Sans+Devanagari:wght@400;500;600;700;800&family=Caveat:wght@600;700&display=swap"
|
||
rel="stylesheet">
|
||
<style>
|
||
:root {
|
||
--bg-page: #f2f7fb;
|
||
--card-bg: #ffffff;
|
||
--card-border: #e2eaf2;
|
||
--card-shadow: 0 4px 20px rgba(15, 45, 80, 0.05);
|
||
|
||
--primary-teal: #0ea5a8;
|
||
--primary-teal-dark: #0b8082;
|
||
--primary-teal-light: #e6f7f7;
|
||
|
||
--blue-accent: #0284c7;
|
||
--blue-accent-light: #e0f2fe;
|
||
--blue-navy: #0f294a;
|
||
|
||
--patient-bubble-bg: #e6f7f2;
|
||
--patient-bubble-text: #065f46;
|
||
--bot-bubble-bg: #eaf3ff;
|
||
--bot-bubble-text: #1e3a8a;
|
||
|
||
--text-dark: #1e293b;
|
||
--text-muted: #64748b;
|
||
--text-light: #94a3b8;
|
||
|
||
--success-green: #10b981;
|
||
--success-green-light: #d1fae5;
|
||
--warning-amber: #f59e0b;
|
||
--warning-amber-light: #fef3c7;
|
||
--danger-red: #ef4444;
|
||
--danger-red-light: #fee2e2;
|
||
--purple-light: #f3e8ff;
|
||
|
||
--radius-sm: 8px;
|
||
--radius-md: 14px;
|
||
--radius-lg: 20px;
|
||
--radius-full: 9999px;
|
||
}
|
||
|
||
* {
|
||
box-sizing: border-box;
|
||
margin: 0;
|
||
padding: 0;
|
||
}
|
||
|
||
body {
|
||
font-family: 'Inter', 'Noto Sans Devanagari', -apple-system, BlinkMacSystemFont, sans-serif;
|
||
background-color: var(--bg-page);
|
||
color: var(--text-dark);
|
||
min-height: 100vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow-x: hidden;
|
||
-webkit-font-smoothing: antialiased;
|
||
}
|
||
|
||
/* ========================================================
|
||
TOP NAVIGATION HEADER
|
||
======================================================== */
|
||
header.main-header {
|
||
background: #ffffff;
|
||
border-bottom: 1px solid var(--card-border);
|
||
padding: 10px 24px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 100;
|
||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
|
||
}
|
||
|
||
.header-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
|
||
.brand-logo-img {
|
||
width: 48px;
|
||
height: 48px;
|
||
border-radius: 12px;
|
||
object-fit: contain;
|
||
box-shadow: 0 4px 12px rgba(14, 165, 168, 0.25);
|
||
border: 1px solid rgba(14, 165, 168, 0.2);
|
||
flex-shrink: 0;
|
||
background: #ffffff;
|
||
padding: 2px;
|
||
}
|
||
|
||
.brand-logo-icon {
|
||
width: 44px;
|
||
height: 44px;
|
||
border-radius: 14px;
|
||
background: linear-gradient(135deg, #0ea5a8 0%, #0284c7 100%);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: white;
|
||
box-shadow: 0 4px 12px rgba(14, 165, 168, 0.3);
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.brand-titles h1 {
|
||
font-family: 'Outfit', sans-serif;
|
||
font-size: 1.28rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
line-height: 1.15;
|
||
letter-spacing: -0.3px;
|
||
}
|
||
|
||
.brand-titles p {
|
||
font-size: 0.76rem;
|
||
color: #527993;
|
||
font-weight: 600;
|
||
letter-spacing: 0.2px;
|
||
}
|
||
|
||
.header-center {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.status-pill-banner {
|
||
background: #e8f8f5;
|
||
border: 1px solid #c7f2e5;
|
||
padding: 6px 16px;
|
||
border-radius: var(--radius-full);
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.status-pill-icon {
|
||
width: 28px;
|
||
height: 28px;
|
||
border-radius: 50%;
|
||
background: #10b981;
|
||
color: #ffffff;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.85rem;
|
||
}
|
||
|
||
.status-pill-text h4 {
|
||
font-size: 0.82rem;
|
||
font-weight: 700;
|
||
color: #065f46;
|
||
line-height: 1.15;
|
||
}
|
||
|
||
.status-pill-text p {
|
||
font-size: 0.72rem;
|
||
color: #047857;
|
||
font-weight: 500;
|
||
}
|
||
|
||
.header-right {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
}
|
||
|
||
.btn-notification {
|
||
position: relative;
|
||
background: #f8fafc;
|
||
border: 1px solid var(--card-border);
|
||
width: 38px;
|
||
height: 38px;
|
||
border-radius: 50%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
cursor: pointer;
|
||
color: var(--text-muted);
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.btn-notification:hover {
|
||
background: #f1f5f9;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.notification-badge {
|
||
position: absolute;
|
||
top: -2px;
|
||
right: -2px;
|
||
background: #ef4444;
|
||
color: white;
|
||
font-size: 0.65rem;
|
||
font-weight: 800;
|
||
width: 16px;
|
||
height: 16px;
|
||
border-radius: 50%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border: 2px solid #ffffff;
|
||
}
|
||
|
||
.doctor-profile-wrap {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.doctor-avatar-circle {
|
||
width: 38px;
|
||
height: 38px;
|
||
border-radius: 50%;
|
||
background: #dbeafe;
|
||
color: #1d4ed8;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-weight: 700;
|
||
font-size: 0.9rem;
|
||
border: 2px solid #ffffff;
|
||
box-shadow: 0 2px 8px rgba(30, 64, 175, 0.15);
|
||
}
|
||
|
||
.doctor-info h4 {
|
||
font-size: 0.85rem;
|
||
font-weight: 700;
|
||
color: var(--blue-navy);
|
||
line-height: 1.1;
|
||
}
|
||
|
||
.doctor-info p {
|
||
font-size: 0.72rem;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.security-badge-btn {
|
||
background: #059669;
|
||
color: white;
|
||
border: none;
|
||
padding: 6px 14px;
|
||
border-radius: var(--radius-full);
|
||
font-size: 0.76rem;
|
||
font-weight: 700;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
|
||
}
|
||
|
||
/* ========================================================
|
||
MAIN DASHBOARD GRID LAYOUT
|
||
======================================================== */
|
||
.dashboard-layout {
|
||
display: grid;
|
||
grid-template-columns: 300px 1fr;
|
||
gap: 24px;
|
||
padding: 20px 24px;
|
||
flex: 1;
|
||
max-width: 1720px;
|
||
margin: 0 auto;
|
||
width: 100%;
|
||
}
|
||
|
||
/* Common Card Styling */
|
||
.app-card {
|
||
background: var(--card-bg);
|
||
border: 1px solid var(--card-border);
|
||
border-radius: var(--radius-lg);
|
||
padding: 16px;
|
||
box-shadow: var(--card-shadow);
|
||
transition: box-shadow 0.2s ease;
|
||
}
|
||
|
||
/* ========================================================
|
||
LEFT SIDEBAR COLUMN
|
||
======================================================== */
|
||
.left-sidebar {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 16px;
|
||
}
|
||
|
||
/* Navigation List */
|
||
.sidebar-nav-box {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 8px 10px;
|
||
box-shadow: var(--card-shadow);
|
||
}
|
||
|
||
.sidebar-nav-item {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
padding: 10px 14px;
|
||
border-radius: 12px;
|
||
font-size: 0.88rem;
|
||
font-weight: 600;
|
||
color: var(--text-muted);
|
||
cursor: pointer;
|
||
border: none;
|
||
background: transparent;
|
||
width: 100%;
|
||
text-align: left;
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.sidebar-nav-item:hover {
|
||
background: #f8fafc;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.sidebar-nav-item.active {
|
||
background: #e0f2fe;
|
||
color: #0284c7;
|
||
font-weight: 700;
|
||
position: relative;
|
||
}
|
||
|
||
.sidebar-nav-item.active::before {
|
||
content: '';
|
||
position: absolute;
|
||
left: 0;
|
||
top: 6px;
|
||
bottom: 6px;
|
||
width: 4px;
|
||
background: #0284c7;
|
||
border-radius: 0 4px 4px 0;
|
||
}
|
||
|
||
.sidebar-nav-item svg {
|
||
width: 18px;
|
||
height: 18px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
/* Patient Profile Card */
|
||
.patient-profile-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 18px;
|
||
box-shadow: var(--card-shadow);
|
||
display: flex;
|
||
flex-direction: column;
|
||
flex: 1;
|
||
}
|
||
|
||
.patient-card-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-bottom: 16px;
|
||
padding-bottom: 14px;
|
||
border-bottom: 1px solid #f1f5f9;
|
||
}
|
||
|
||
.patient-avatar-img {
|
||
width: 46px;
|
||
height: 46px;
|
||
border-radius: 50%;
|
||
background: #e0f2fe;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.4rem;
|
||
border: 2px solid #bae6fd;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.patient-header-info {
|
||
flex: 1;
|
||
}
|
||
|
||
.patient-header-top {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.patient-name-title {
|
||
font-size: 0.98rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.status-badge-active {
|
||
background: #dcfce7;
|
||
color: #15803d;
|
||
font-size: 0.68rem;
|
||
font-weight: 700;
|
||
padding: 2px 8px;
|
||
border-radius: var(--radius-full);
|
||
border: 1px solid #bbf7d0;
|
||
}
|
||
|
||
.patient-id-sub {
|
||
font-size: 0.74rem;
|
||
color: var(--text-muted);
|
||
margin-top: 2px;
|
||
}
|
||
|
||
.patient-meta-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 10px;
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.patient-meta-item {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
background: #f8fafc;
|
||
border: 1px solid #f1f5f9;
|
||
border-radius: 12px;
|
||
padding: 10px 12px;
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.patient-meta-item:hover {
|
||
background: #f1f5f9;
|
||
border-color: #e2e8f0;
|
||
}
|
||
|
||
.patient-meta-item svg {
|
||
width: 17px;
|
||
height: 17px;
|
||
color: #0284c7;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.meta-content {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 2px;
|
||
}
|
||
|
||
.meta-label {
|
||
font-size: 0.68rem;
|
||
color: var(--text-light);
|
||
font-weight: 700;
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.3px;
|
||
}
|
||
|
||
.meta-value {
|
||
font-size: 0.86rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.patient-card-footer-box {
|
||
margin-top: auto;
|
||
padding-top: 16px;
|
||
border-top: 1px solid #f1f5f9;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.sidebar-status-banner {
|
||
background: #f0fdf4;
|
||
border: 1px solid #bbf7d0;
|
||
border-radius: 12px;
|
||
padding: 10px 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
font-size: 0.76rem;
|
||
color: #15803d;
|
||
font-weight: 700;
|
||
}
|
||
|
||
/* Quick Overview Card */
|
||
.quick-overview-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 16px;
|
||
box-shadow: var(--card-shadow);
|
||
}
|
||
|
||
.section-mini-header {
|
||
font-size: 0.88rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.quick-overview-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 10px;
|
||
}
|
||
|
||
.mini-metric-box {
|
||
border-radius: 12px;
|
||
padding: 10px 12px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 4px;
|
||
transition: transform 0.2s ease;
|
||
}
|
||
|
||
.mini-metric-box:hover {
|
||
transform: translateY(-2px);
|
||
}
|
||
|
||
.mini-metric-box.pink {
|
||
background: #fef2f2;
|
||
border: 1px solid #fee2e2;
|
||
}
|
||
|
||
.mini-metric-box.pink .metric-icon-wrap {
|
||
background: #fee2e2;
|
||
color: #dc2626;
|
||
}
|
||
|
||
.mini-metric-box.blue {
|
||
background: #eff6ff;
|
||
border: 1px solid #dbeafe;
|
||
}
|
||
|
||
.mini-metric-box.blue .metric-icon-wrap {
|
||
background: #dbeafe;
|
||
color: #2563eb;
|
||
}
|
||
|
||
.mini-metric-box.green {
|
||
background: #f0fdf4;
|
||
border: 1px solid #dcfce7;
|
||
}
|
||
|
||
.mini-metric-box.green .metric-icon-wrap {
|
||
background: #dcfce7;
|
||
color: #16a34a;
|
||
}
|
||
|
||
.mini-metric-box.purple {
|
||
background: #faf5ff;
|
||
border: 1px solid #f3e8ff;
|
||
}
|
||
|
||
.mini-metric-box.purple .metric-icon-wrap {
|
||
background: #f3e8ff;
|
||
color: #9333ea;
|
||
}
|
||
|
||
.metric-icon-wrap {
|
||
width: 24px;
|
||
height: 24px;
|
||
border-radius: 8px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.8rem;
|
||
margin-bottom: 2px;
|
||
}
|
||
|
||
.metric-title {
|
||
font-size: 0.72rem;
|
||
color: var(--text-muted);
|
||
font-weight: 600;
|
||
}
|
||
|
||
.metric-val {
|
||
font-size: 0.86rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
/* Patient Memory Card */
|
||
.patient-memory-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 14px 16px;
|
||
box-shadow: var(--card-shadow);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
cursor: pointer;
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.patient-memory-card:hover {
|
||
border-color: #cbd5e1;
|
||
background: #fcfdfe;
|
||
}
|
||
|
||
.memory-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.memory-icon {
|
||
width: 32px;
|
||
height: 32px;
|
||
border-radius: 10px;
|
||
background: #eff6ff;
|
||
color: #2563eb;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.1rem;
|
||
}
|
||
|
||
.memory-details h4 {
|
||
font-size: 0.84rem;
|
||
font-weight: 700;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.memory-details p {
|
||
font-size: 0.74rem;
|
||
color: var(--text-muted);
|
||
font-weight: 600;
|
||
}
|
||
|
||
.memory-details p span {
|
||
color: #10b981;
|
||
font-weight: 700;
|
||
}
|
||
|
||
/* Bottom Promo Banner Card */
|
||
.better-health-promo {
|
||
background: linear-gradient(135deg, #e6f7f2 0%, #d5f2ea 100%);
|
||
border: 1px solid #bbf7d0;
|
||
border-radius: var(--radius-lg);
|
||
padding: 16px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
position: relative;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.promo-icon-wrap {
|
||
width: 36px;
|
||
height: 36px;
|
||
border-radius: 50%;
|
||
background: #ffffff;
|
||
color: #059669;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.1rem;
|
||
box-shadow: 0 2px 8px rgba(5, 150, 105, 0.15);
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.promo-text h5 {
|
||
font-size: 0.85rem;
|
||
font-weight: 800;
|
||
color: #065f46;
|
||
line-height: 1.15;
|
||
}
|
||
|
||
.promo-text p {
|
||
font-size: 0.72rem;
|
||
color: #047857;
|
||
font-weight: 500;
|
||
}
|
||
|
||
/* ========================================================
|
||
CENTER STAGE (VOICE CONVERSATION & CONTROLS)
|
||
======================================================== */
|
||
.center-stage {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 16px;
|
||
min-width: 0;
|
||
}
|
||
|
||
/* Top Conversation Header */
|
||
.conversation-header-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 16px 20px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
box-shadow: var(--card-shadow);
|
||
}
|
||
|
||
.conv-header-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
|
||
.conv-wave-icon {
|
||
width: 40px;
|
||
height: 40px;
|
||
border-radius: 50%;
|
||
background: #e0f2fe;
|
||
color: #0284c7;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.2rem;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.conv-titles h3 {
|
||
font-family: 'Outfit', sans-serif;
|
||
font-size: 1.12rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
letter-spacing: -0.2px;
|
||
}
|
||
|
||
.conv-titles p {
|
||
font-size: 0.78rem;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.conv-header-right {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: flex-end;
|
||
gap: 6px;
|
||
}
|
||
|
||
.question-progress-pill {
|
||
background: #f1f5f9;
|
||
border: 1px solid var(--card-border);
|
||
font-size: 0.74rem;
|
||
font-weight: 700;
|
||
color: var(--blue-navy);
|
||
padding: 3px 10px;
|
||
border-radius: var(--radius-full);
|
||
}
|
||
|
||
.progress-bar-track {
|
||
width: 140px;
|
||
height: 7px;
|
||
background: #e2e8f0;
|
||
border-radius: 99px;
|
||
overflow: hidden;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.progress-bar-fill {
|
||
height: 100%;
|
||
background: linear-gradient(90deg, #0ea5a8, #0284c7);
|
||
width: 58%;
|
||
border-radius: 99px;
|
||
transition: width 0.4s ease;
|
||
}
|
||
|
||
.progress-percent-label {
|
||
font-size: 0.72rem;
|
||
font-weight: 700;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
/* Chat Messages Container */
|
||
.chat-scroll-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
box-shadow: var(--card-shadow);
|
||
padding: 18px 20px;
|
||
flex: 1;
|
||
min-height: 280px;
|
||
max-height: 420px;
|
||
overflow-y: auto;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 16px;
|
||
}
|
||
|
||
.chat-row {
|
||
display: flex;
|
||
gap: 12px;
|
||
max-width: 85%;
|
||
animation: fadeIn 0.3s ease;
|
||
}
|
||
|
||
.chat-row.bot {
|
||
align-self: flex-start;
|
||
}
|
||
|
||
.chat-row.patient {
|
||
align-self: flex-end;
|
||
flex-direction: row-reverse;
|
||
}
|
||
|
||
.chat-avatar {
|
||
width: 36px;
|
||
height: 36px;
|
||
border-radius: 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.1rem;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.chat-avatar.bot {
|
||
background: #e0f2fe;
|
||
color: #0284c7;
|
||
border: 1px solid #bae6fd;
|
||
}
|
||
|
||
.chat-avatar.patient {
|
||
background: #dcfce7;
|
||
color: #10b981;
|
||
border: 1px solid #bbf7d0;
|
||
border-radius: 50%;
|
||
}
|
||
|
||
.chat-bubble-wrap {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 4px;
|
||
}
|
||
|
||
.chat-sender-name {
|
||
font-size: 0.72rem;
|
||
font-weight: 700;
|
||
color: var(--text-muted);
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
|
||
.chat-sender-badge {
|
||
font-size: 0.65rem;
|
||
font-weight: 600;
|
||
background: #f1f5f9;
|
||
color: #475569;
|
||
padding: 1px 6px;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
.chat-bubble {
|
||
padding: 12px 18px;
|
||
border-radius: 18px;
|
||
font-size: 0.94rem;
|
||
line-height: 1.55;
|
||
position: relative;
|
||
}
|
||
|
||
.chat-bubble.bot {
|
||
background: var(--bot-bubble-bg);
|
||
color: var(--bot-bubble-text);
|
||
border-top-left-radius: 4px;
|
||
border: 1px solid #dbeafe;
|
||
}
|
||
|
||
.chat-bubble.patient {
|
||
background: var(--patient-bubble-bg);
|
||
color: var(--patient-bubble-text);
|
||
border-top-right-radius: 4px;
|
||
border: 1px solid #bbf7d0;
|
||
}
|
||
|
||
.chat-bubble-footer {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
gap: 8px;
|
||
margin-top: 4px;
|
||
font-size: 0.72rem;
|
||
color: #64748b;
|
||
}
|
||
|
||
.btn-audio-replay {
|
||
background: none;
|
||
border: none;
|
||
color: #0284c7;
|
||
cursor: pointer;
|
||
font-size: 0.85rem;
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 2px;
|
||
border-radius: 4px;
|
||
transition: transform 0.15s ease;
|
||
}
|
||
|
||
.btn-audio-replay:hover {
|
||
transform: scale(1.15);
|
||
}
|
||
|
||
/* Live Interaction Stage & Mic Box */
|
||
.live-mic-stage-card {
|
||
background: linear-gradient(180deg, #f4fafe 0%, #edf6fc 100%);
|
||
border: 1px solid #d8e8f5;
|
||
border-radius: var(--radius-lg);
|
||
padding: 22px 20px;
|
||
box-shadow: var(--card-shadow);
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 12px;
|
||
position: relative;
|
||
}
|
||
|
||
.mic-waveform-center {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 24px;
|
||
width: 100%;
|
||
}
|
||
|
||
.sound-bars-cluster {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 3px;
|
||
height: 36px;
|
||
}
|
||
|
||
.sound-bar {
|
||
width: 3px;
|
||
background: #0ea5a8;
|
||
border-radius: 4px;
|
||
height: 12px;
|
||
transition: height 0.1s ease;
|
||
animation: soundDance 1.2s infinite ease-in-out;
|
||
}
|
||
|
||
.sound-bar:nth-child(2) {
|
||
height: 22px;
|
||
animation-delay: 0.15s;
|
||
}
|
||
|
||
.sound-bar:nth-child(3) {
|
||
height: 32px;
|
||
animation-delay: 0.3s;
|
||
}
|
||
|
||
.sound-bar:nth-child(4) {
|
||
height: 18px;
|
||
animation-delay: 0.45s;
|
||
}
|
||
|
||
.sound-bar:nth-child(5) {
|
||
height: 26px;
|
||
animation-delay: 0.6s;
|
||
}
|
||
|
||
@keyframes soundDance {
|
||
|
||
0%,
|
||
100% {
|
||
transform: scaleY(0.4);
|
||
}
|
||
|
||
50% {
|
||
transform: scaleY(1.1);
|
||
}
|
||
}
|
||
|
||
.central-mic-orb {
|
||
width: 64px;
|
||
height: 64px;
|
||
border-radius: 50%;
|
||
background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
|
||
color: white;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.5rem;
|
||
cursor: pointer;
|
||
box-shadow: 0 0 24px rgba(2, 132, 199, 0.4), inset 0 0 10px rgba(255, 255, 255, 0.4);
|
||
border: 3px solid #ffffff;
|
||
transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||
}
|
||
|
||
.central-mic-orb:hover {
|
||
transform: scale(1.08);
|
||
box-shadow: 0 0 32px rgba(2, 132, 199, 0.6);
|
||
}
|
||
|
||
.central-mic-orb.listening {
|
||
background: linear-gradient(135deg, #34d399 0%, #059669 100%);
|
||
box-shadow: 0 0 30px rgba(16, 185, 129, 0.6);
|
||
animation: micPulse 1.2s infinite alternate;
|
||
}
|
||
|
||
.central-mic-orb.speaking {
|
||
background: linear-gradient(135deg, #60a5fa 0%, #2563eb 100%);
|
||
box-shadow: 0 0 30px rgba(37, 99, 235, 0.6);
|
||
animation: micPulse 1.4s infinite alternate;
|
||
}
|
||
|
||
.central-mic-orb.paused {
|
||
background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
|
||
box-shadow: 0 0 20px rgba(217, 119, 6, 0.4);
|
||
}
|
||
|
||
.central-mic-orb.stopped {
|
||
background: linear-gradient(135deg, #94a3b8 0%, #475569 100%);
|
||
box-shadow: 0 0 15px rgba(71, 85, 105, 0.3);
|
||
}
|
||
|
||
@keyframes micPulse {
|
||
0% {
|
||
transform: scale(1);
|
||
}
|
||
|
||
100% {
|
||
transform: scale(1.1);
|
||
}
|
||
}
|
||
|
||
.mic-status-label {
|
||
font-size: 0.94rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
text-align: center;
|
||
}
|
||
|
||
.mic-status-sub {
|
||
font-size: 0.76rem;
|
||
color: var(--text-muted);
|
||
font-weight: 500;
|
||
}
|
||
|
||
/* Actions Bar */
|
||
.controls-action-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 12px;
|
||
width: 100%;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.btn-pill-action {
|
||
background: #ffffff;
|
||
border: 1px solid var(--card-border);
|
||
border-radius: var(--radius-full);
|
||
padding: 7px 16px;
|
||
font-size: 0.82rem;
|
||
font-weight: 700;
|
||
color: var(--text-dark);
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
cursor: pointer;
|
||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.btn-pill-action:hover {
|
||
background: #f8fafc;
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.btn-pill-action.end-session {
|
||
background: #fee2e2;
|
||
border-color: #fecaca;
|
||
color: #dc2626;
|
||
}
|
||
|
||
.btn-pill-action.end-session:hover {
|
||
background: #fca5a5;
|
||
color: #991b1b;
|
||
}
|
||
|
||
.btn-pill-action.listening-active,
|
||
.btn-pill-action.resume-active {
|
||
background: #dcfce7;
|
||
border-color: #bbf7d0;
|
||
color: #16a34a;
|
||
}
|
||
|
||
.btn-pill-action.resume-active:hover {
|
||
background: #bbf7d0;
|
||
color: #15803d;
|
||
}
|
||
|
||
.btn-pill-action.pause-active {
|
||
background: #fef3c7;
|
||
border-color: #fde68a;
|
||
color: #b45309;
|
||
}
|
||
|
||
.btn-pill-action.pause-active:hover {
|
||
background: #fde68a;
|
||
color: #92400e;
|
||
}
|
||
|
||
.btn-pill-action.status-disabled {
|
||
background: #f1f5f9;
|
||
color: #94a3b8;
|
||
border-color: #e2e8f0;
|
||
cursor: default;
|
||
}
|
||
|
||
/* Bottom 3 Feature Cards & Tagline */
|
||
.bottom-features-section {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 10px;
|
||
}
|
||
|
||
.three-features-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr 1fr;
|
||
gap: 12px;
|
||
}
|
||
|
||
.feature-box-card {
|
||
background: #ffffff;
|
||
border-radius: 14px;
|
||
border: 1px solid var(--card-border);
|
||
padding: 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
box-shadow: var(--card-shadow);
|
||
}
|
||
|
||
.feature-box-icon {
|
||
width: 32px;
|
||
height: 32px;
|
||
border-radius: 10px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1rem;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.feature-box-icon.purple {
|
||
background: #f3e8ff;
|
||
color: #9333ea;
|
||
}
|
||
|
||
.feature-box-icon.green {
|
||
background: #dcfce7;
|
||
color: #16a34a;
|
||
}
|
||
|
||
.feature-box-icon.blue {
|
||
background: #e0f2fe;
|
||
color: #0284c7;
|
||
}
|
||
|
||
.feature-box-text h5 {
|
||
font-size: 0.8rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
line-height: 1.15;
|
||
}
|
||
|
||
.feature-box-text p {
|
||
font-size: 0.68rem;
|
||
color: var(--text-muted);
|
||
margin-top: 1px;
|
||
}
|
||
|
||
.tagline-cursive {
|
||
font-family: 'Caveat', cursive, sans-serif;
|
||
font-size: 1.15rem;
|
||
color: #0284c7;
|
||
font-weight: 700;
|
||
text-align: right;
|
||
padding-right: 8px;
|
||
}
|
||
|
||
/* ========================================================
|
||
RIGHT SIDEBAR (AI CONTEXT, STATUS, SUMMARY)
|
||
======================================================== */
|
||
.right-sidebar {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 16px;
|
||
}
|
||
|
||
/* AI Context Card */
|
||
.ai-context-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 16px;
|
||
box-shadow: var(--card-shadow);
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 14px;
|
||
}
|
||
|
||
.context-card-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.context-header-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.context-brain-icon {
|
||
width: 30px;
|
||
height: 30px;
|
||
border-radius: 8px;
|
||
background: #e0f2fe;
|
||
color: #0284c7;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.1rem;
|
||
}
|
||
|
||
.context-header-left h3 {
|
||
font-size: 0.94rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.link-full-history {
|
||
font-size: 0.74rem;
|
||
font-weight: 700;
|
||
color: #0284c7;
|
||
text-decoration: none;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.link-full-history:hover {
|
||
text-decoration: underline;
|
||
}
|
||
|
||
/* Previous Visit Pill Box */
|
||
.previous-visit-box {
|
||
background: #f0fdf4;
|
||
border: 1px solid #dcfce7;
|
||
border-radius: 12px;
|
||
padding: 10px 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.prev-visit-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.prev-visit-icon {
|
||
width: 24px;
|
||
height: 24px;
|
||
border-radius: 6px;
|
||
background: #dcfce7;
|
||
color: #15803d;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.8rem;
|
||
}
|
||
|
||
.prev-visit-text h5 {
|
||
font-size: 0.78rem;
|
||
font-weight: 800;
|
||
color: #14532d;
|
||
}
|
||
|
||
.prev-visit-text p {
|
||
font-size: 0.68rem;
|
||
color: #166534;
|
||
}
|
||
|
||
.badge-completed-green {
|
||
background: #dcfce7;
|
||
color: #15803d;
|
||
font-size: 0.65rem;
|
||
font-weight: 700;
|
||
padding: 2px 8px;
|
||
border-radius: var(--radius-full);
|
||
border: 1px solid #bbf7d0;
|
||
}
|
||
|
||
/* Known Information List */
|
||
.known-info-section {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.known-info-title {
|
||
font-size: 0.78rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
|
||
.checklist-container {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
}
|
||
|
||
.check-item {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-size: 0.78rem;
|
||
font-weight: 600;
|
||
color: var(--text-dark);
|
||
}
|
||
|
||
.check-bullet {
|
||
width: 16px;
|
||
height: 16px;
|
||
border-radius: 50%;
|
||
background: #10b981;
|
||
color: white;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.65rem;
|
||
font-weight: 800;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.view-all-link {
|
||
font-size: 0.72rem;
|
||
font-weight: 700;
|
||
color: #0284c7;
|
||
text-align: right;
|
||
cursor: pointer;
|
||
text-decoration: none;
|
||
margin-top: 2px;
|
||
}
|
||
|
||
/* Today's Changes Box (Amber) */
|
||
.today-changes-box {
|
||
background: #fefce8;
|
||
border: 1px solid #fef08a;
|
||
border-radius: 12px;
|
||
padding: 12px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.today-changes-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.today-changes-title {
|
||
font-size: 0.78rem;
|
||
font-weight: 800;
|
||
color: #854d0e;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
|
||
.badge-new-amber {
|
||
background: #0f172a;
|
||
color: #fef08a;
|
||
font-size: 0.62rem;
|
||
font-weight: 800;
|
||
padding: 2px 6px;
|
||
border-radius: var(--radius-full);
|
||
letter-spacing: 0.5px;
|
||
}
|
||
|
||
.changes-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
}
|
||
|
||
.change-point {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-size: 0.76rem;
|
||
font-weight: 600;
|
||
color: #713f12;
|
||
}
|
||
|
||
.change-bullet {
|
||
width: 16px;
|
||
height: 16px;
|
||
border-radius: 50%;
|
||
background: #ca8a04;
|
||
color: white;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.65rem;
|
||
font-weight: 800;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
/* Questions Status Card */
|
||
.questions-status-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 16px;
|
||
box-shadow: var(--card-shadow);
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12px;
|
||
}
|
||
|
||
.questions-status-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
|
||
.donut-status-icon {
|
||
width: 28px;
|
||
height: 28px;
|
||
border-radius: 50%;
|
||
border: 3px solid #0ea5a8;
|
||
border-top-color: #e2e8f0;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.questions-status-header h4 {
|
||
font-size: 0.88rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.questions-metrics-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.q-metric-item {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
font-size: 0.78rem;
|
||
}
|
||
|
||
.q-metric-label {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-weight: 600;
|
||
color: var(--text-dark);
|
||
}
|
||
|
||
.q-metric-val {
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.q-dot-icon {
|
||
width: 16px;
|
||
height: 16px;
|
||
border-radius: 50%;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 0.65rem;
|
||
font-weight: 800;
|
||
color: white;
|
||
}
|
||
|
||
.q-dot-icon.green {
|
||
background: #10b981;
|
||
}
|
||
|
||
.q-dot-icon.blue {
|
||
background: #0284c7;
|
||
}
|
||
|
||
.q-dot-icon.gray {
|
||
background: #94a3b8;
|
||
}
|
||
|
||
/* Visit Summary (Live) Card */
|
||
.visit-summary-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
border: 1px solid var(--card-border);
|
||
padding: 16px;
|
||
box-shadow: var(--card-shadow);
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 10px;
|
||
}
|
||
|
||
.summary-card-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.summary-card-header svg {
|
||
width: 18px;
|
||
height: 18px;
|
||
color: #0284c7;
|
||
}
|
||
|
||
.summary-card-header h4 {
|
||
font-size: 0.88rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.summary-card-header h4 span {
|
||
color: #10b981;
|
||
}
|
||
|
||
.summary-card-desc {
|
||
font-size: 0.74rem;
|
||
color: var(--text-muted);
|
||
line-height: 1.45;
|
||
}
|
||
|
||
.btn-view-summary {
|
||
background: #e0f2fe;
|
||
border: 1px solid #bae6fd;
|
||
color: #0369a1;
|
||
padding: 9px 14px;
|
||
border-radius: var(--radius-full);
|
||
font-size: 0.82rem;
|
||
font-weight: 700;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 6px;
|
||
cursor: pointer;
|
||
transition: all 0.2s ease;
|
||
width: 100%;
|
||
}
|
||
|
||
.btn-view-summary:hover {
|
||
background: #bae6fd;
|
||
color: #0c4a6e;
|
||
}
|
||
|
||
/* ========================================================
|
||
START CONSULTATION OVERLAY
|
||
======================================================== */
|
||
.start-session-overlay {
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: 0;
|
||
background: rgba(15, 23, 42, 0.65);
|
||
backdrop-filter: blur(8px);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
z-index: 500;
|
||
padding: 20px;
|
||
transition: opacity 0.3s ease, visibility 0.3s ease;
|
||
}
|
||
|
||
.start-session-overlay.hidden {
|
||
opacity: 0;
|
||
visibility: hidden;
|
||
pointer-events: none;
|
||
}
|
||
|
||
.start-overlay-card {
|
||
background: #ffffff;
|
||
border-radius: 24px;
|
||
padding: 32px 28px;
|
||
text-align: center;
|
||
max-width: 480px;
|
||
width: 100%;
|
||
box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 16px;
|
||
border: 1px solid var(--card-border);
|
||
animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||
}
|
||
|
||
@keyframes popIn {
|
||
0% {
|
||
transform: scale(0.9);
|
||
opacity: 0;
|
||
}
|
||
|
||
100% {
|
||
transform: scale(1);
|
||
opacity: 1;
|
||
}
|
||
}
|
||
|
||
.start-icon-pulse {
|
||
width: 64px;
|
||
height: 64px;
|
||
border-radius: 50%;
|
||
background: linear-gradient(135deg, #0ea5a8, #0284c7);
|
||
color: white;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 2rem;
|
||
box-shadow: 0 0 24px rgba(14, 165, 168, 0.4);
|
||
animation: micPulse 1.2s infinite alternate;
|
||
}
|
||
|
||
.start-overlay-card h3 {
|
||
font-family: 'Outfit', sans-serif;
|
||
font-size: 1.35rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.start-overlay-card p {
|
||
font-size: 0.88rem;
|
||
color: var(--text-muted);
|
||
line-height: 1.5;
|
||
}
|
||
|
||
.btn-start-consultation {
|
||
background: linear-gradient(135deg, #0ea5a8, #0284c7);
|
||
border: none;
|
||
color: white;
|
||
font-size: 1rem;
|
||
font-weight: 700;
|
||
padding: 12px 24px;
|
||
border-radius: var(--radius-full);
|
||
cursor: pointer;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
box-shadow: 0 4px 14px rgba(14, 165, 168, 0.35);
|
||
transition: all 0.2s ease;
|
||
width: 100%;
|
||
justify-content: center;
|
||
}
|
||
|
||
.btn-start-consultation:hover {
|
||
transform: translateY(-2px);
|
||
box-shadow: 0 6px 20px rgba(14, 165, 168, 0.5);
|
||
}
|
||
|
||
/* ========================================================
|
||
MODAL STYLES (DOCTOR SUMMARY)
|
||
======================================================== */
|
||
.modal-overlay {
|
||
display: none;
|
||
position: fixed;
|
||
top: 0;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: 0;
|
||
background: rgba(15, 23, 42, 0.7);
|
||
backdrop-filter: blur(6px);
|
||
z-index: 1000;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 20px;
|
||
}
|
||
|
||
.modal-overlay.active {
|
||
display: flex;
|
||
}
|
||
|
||
.modal-content-card {
|
||
background: #ffffff;
|
||
border-radius: var(--radius-lg);
|
||
max-width: 960px;
|
||
width: 100%;
|
||
max-height: 90vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
|
||
overflow: hidden;
|
||
border: 1px solid var(--card-border);
|
||
}
|
||
|
||
.modal-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 16px 24px;
|
||
background: #f8fafc;
|
||
border-bottom: 1px solid var(--card-border);
|
||
}
|
||
|
||
.modal-header h3 {
|
||
font-family: 'Outfit', sans-serif;
|
||
font-size: 1.15rem;
|
||
color: var(--blue-navy);
|
||
font-weight: 800;
|
||
}
|
||
|
||
.modal-body {
|
||
padding: 24px;
|
||
overflow-y: auto;
|
||
flex: 1;
|
||
}
|
||
|
||
.bilingual-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 18px;
|
||
}
|
||
|
||
.summary-column {
|
||
background: #f8fafc;
|
||
border: 1px solid var(--card-border);
|
||
border-radius: 12px;
|
||
padding: 16px;
|
||
}
|
||
|
||
.summary-column h4 {
|
||
font-size: 0.88rem;
|
||
color: var(--blue-navy);
|
||
margin-bottom: 10px;
|
||
font-weight: 700;
|
||
border-bottom: 1px solid var(--card-border);
|
||
padding-bottom: 6px;
|
||
}
|
||
|
||
.summary-text {
|
||
white-space: pre-wrap;
|
||
line-height: 1.6;
|
||
font-size: 0.88rem;
|
||
color: var(--text-dark);
|
||
}
|
||
|
||
.modal-footer {
|
||
padding: 14px 24px;
|
||
background: #f8fafc;
|
||
border-top: 1px solid var(--card-border);
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 10px;
|
||
}
|
||
|
||
/* Responsive Media Queries */
|
||
@media (max-width: 1200px) {
|
||
.dashboard-layout {
|
||
grid-template-columns: 260px 1fr;
|
||
}
|
||
|
||
.right-sidebar {
|
||
grid-column: span 2;
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
}
|
||
}
|
||
|
||
@media (max-width: 900px) {
|
||
.dashboard-layout {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.right-sidebar {
|
||
grid-column: auto;
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.three-features-grid {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.header-center {
|
||
display: none;
|
||
}
|
||
}
|
||
|
||
/* ========================================================
|
||
INLINE ADMIN CONSULTATIONS DASHBOARD STYLES
|
||
======================================================== */
|
||
.admin-stats-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||
gap: 14px;
|
||
margin-bottom: 4px;
|
||
}
|
||
|
||
.admin-stat-card {
|
||
background: #ffffff;
|
||
border: 1px solid var(--card-border);
|
||
border-radius: var(--radius-lg);
|
||
padding: 16px;
|
||
box-shadow: var(--card-shadow);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
transition: transform 0.2s ease;
|
||
}
|
||
|
||
.admin-stat-card:hover {
|
||
transform: translateY(-2px);
|
||
}
|
||
|
||
.admin-stat-details span {
|
||
font-size: 0.74rem;
|
||
font-weight: 700;
|
||
color: var(--text-muted);
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.4px;
|
||
}
|
||
|
||
.admin-stat-details h3 {
|
||
font-family: 'Outfit', sans-serif;
|
||
font-size: 1.5rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
margin-top: 2px;
|
||
}
|
||
|
||
.admin-stat-icon {
|
||
width: 42px;
|
||
height: 42px;
|
||
border-radius: 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 1.25rem;
|
||
}
|
||
|
||
.admin-stat-icon.teal {
|
||
background: #e0f2fe;
|
||
color: #0284c7;
|
||
}
|
||
|
||
.admin-stat-icon.red {
|
||
background: #fef2f2;
|
||
color: #dc2626;
|
||
}
|
||
|
||
.admin-stat-icon.green {
|
||
background: #ecfdf5;
|
||
color: #059669;
|
||
}
|
||
|
||
.admin-stat-icon.purple {
|
||
background: #faf5ff;
|
||
color: #9333ea;
|
||
}
|
||
|
||
.admin-controls-card {
|
||
background: #ffffff;
|
||
border: 1px solid var(--card-border);
|
||
border-radius: var(--radius-lg);
|
||
padding: 14px 18px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
box-shadow: var(--card-shadow);
|
||
}
|
||
|
||
.admin-search-wrap {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
background: #f8fafc;
|
||
border: 1px solid var(--gray-200);
|
||
padding: 6px 12px;
|
||
border-radius: var(--radius-md);
|
||
flex: 1;
|
||
max-width: 360px;
|
||
}
|
||
|
||
.admin-search-wrap input {
|
||
border: none;
|
||
background: transparent;
|
||
outline: none;
|
||
font-family: inherit;
|
||
font-size: 0.84rem;
|
||
width: 100%;
|
||
color: var(--navy-900);
|
||
}
|
||
|
||
.admin-filter-select {
|
||
background: #f8fafc;
|
||
border: 1px solid var(--card-border);
|
||
padding: 6px 12px;
|
||
border-radius: var(--radius-md);
|
||
font-family: inherit;
|
||
font-size: 0.82rem;
|
||
font-weight: 600;
|
||
color: var(--blue-navy);
|
||
outline: none;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.admin-table-container {
|
||
background: #ffffff;
|
||
border: 1px solid var(--card-border);
|
||
border-radius: var(--radius-lg);
|
||
box-shadow: var(--card-shadow);
|
||
overflow: hidden;
|
||
}
|
||
|
||
.admin-table-header {
|
||
padding: 14px 20px;
|
||
border-bottom: 1px solid #f1f5f9;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
.admin-table-header h3 {
|
||
font-family: 'Outfit', sans-serif;
|
||
font-size: 1.05rem;
|
||
font-weight: 800;
|
||
color: var(--blue-navy);
|
||
}
|
||
|
||
.admin-table-responsive {
|
||
overflow-x: auto;
|
||
max-height: 480px;
|
||
}
|
||
|
||
.admin-data-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
text-align: left;
|
||
}
|
||
|
||
.admin-data-table th {
|
||
background: #f8fafc;
|
||
padding: 10px 16px;
|
||
font-size: 0.74rem;
|
||
font-weight: 800;
|
||
color: var(--text-muted);
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.4px;
|
||
border-bottom: 1px solid #e2e8f0;
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 2;
|
||
}
|
||
|
||
.admin-data-table td {
|
||
padding: 12px 16px;
|
||
font-size: 0.84rem;
|
||
color: var(--blue-navy);
|
||
border-bottom: 1px solid #f1f5f9;
|
||
vertical-align: middle;
|
||
}
|
||
|
||
.admin-data-table tr:hover td {
|
||
background: #f8fafc;
|
||
}
|
||
|
||
.urgency-badge {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
padding: 3px 8px;
|
||
border-radius: 999px;
|
||
font-size: 0.72rem;
|
||
font-weight: 700;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.urgency-badge.routine {
|
||
background: #ecfdf5;
|
||
color: #047857;
|
||
border: 1px solid #a7f3d0;
|
||
}
|
||
|
||
.urgency-badge.urgent {
|
||
background: #fffbeb;
|
||
color: #b45309;
|
||
border: 1px solid #fde68a;
|
||
}
|
||
|
||
.urgency-badge.emergency {
|
||
background: #fef2f2;
|
||
color: #b91c1c;
|
||
border: 1px solid #fecaca;
|
||
font-weight: 800;
|
||
}
|
||
|
||
.btn-action-view {
|
||
background: #eff6ff;
|
||
border: 1px solid #bfdbfe;
|
||
color: #1d4ed8;
|
||
padding: 4px 10px;
|
||
border-radius: 6px;
|
||
font-size: 0.76rem;
|
||
font-weight: 700;
|
||
cursor: pointer;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
transition: all 0.2s ease;
|
||
}
|
||
|
||
.btn-action-view:hover {
|
||
background: #dbeafe;
|
||
}
|
||
|
||
.btn-action-del {
|
||
background: #fef2f2;
|
||
border: 1px solid #fecaca;
|
||
color: #dc2626;
|
||
padding: 4px 8px;
|
||
border-radius: 6px;
|
||
font-size: 0.76rem;
|
||
cursor: pointer;
|
||
margin-left: 4px;
|
||
}
|
||
|
||
.btn-action-del:hover {
|
||
background: #fee2e2;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
|
||
<!-- ========================================================
|
||
TOP NAVIGATION HEADER
|
||
======================================================== -->
|
||
<header class="main-header">
|
||
<div class="header-left">
|
||
<img src="/static/kem_hospital_logo.png?v=kem" alt="KEM Hospital Logo" class="brand-logo-img">
|
||
<div class="brand-titles">
|
||
<h1>KEM Hospital</h1>
|
||
<p>Diabetes Dost — Care Companion</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="header-right" style="position: relative; display: flex; align-items: center; gap: 10px;">
|
||
<!-- Language Switcher Pill (Hindi / Marathi) -->
|
||
<div class="lang-switch-box"
|
||
style="display: flex; align-items: center; background: #f1f5f9; border-radius: 999px; padding: 3px; border: 1px solid var(--card-border); gap: 2px;">
|
||
<button id="lang-btn-hi" onclick="setLanguageMode('hi-IN')"
|
||
style="background: #ffffff; color: var(--blue-navy); border: none; padding: 4px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.08); transition: all 0.2s;">
|
||
🇮🇳 हिंदी
|
||
</button>
|
||
<button id="lang-btn-mr" onclick="setLanguageMode('mr-IN')"
|
||
style="background: transparent; color: var(--text-muted); border: none; padding: 4px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; cursor: pointer; transition: all 0.2s;">
|
||
🚩 मराठी
|
||
</button>
|
||
</div>
|
||
|
||
<!-- Single Top-Right Admin Icon Button (When not logged in) -->
|
||
<button id="btn-header-login-icon" class="btn-top-admin-icon" onclick="openAdminLoginModal()" title="Admin Login"
|
||
style="width: 40px; height: 40px; border-radius: 50%; background: #ffffff; border: 1px solid var(--card-border); color: #0f172a; font-size: 1.15rem; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.06); transition: all 0.2s ease;">
|
||
👤
|
||
</button>
|
||
|
||
<!-- Top-Right Admin Controls (When logged in) -->
|
||
<div id="header-admin-user" style="display: none; align-items: center; gap: 8px;">
|
||
<button id="btn-toggle-view-action" onclick="toggleMainView()"
|
||
style="background: #e0f2fe; color: #0284c7; border: 1px solid #bae6fd; padding: 6px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 4px;">
|
||
<span id="view-toggle-icon">📋</span> <span id="view-toggle-text">Consultations DB</span>
|
||
</button>
|
||
|
||
<span
|
||
style="font-size: 0.78rem; font-weight: 700; color: #059669; background: #ecfdf5; border: 1px solid #a7f3d0; padding: 5px 10px; border-radius: 999px; display: flex; align-items: center; gap: 4px;">
|
||
👨⚕️ <span id="header-admin-name">Admin</span>
|
||
</span>
|
||
|
||
<button onclick="handleMainLogout()" title="Logout"
|
||
style="background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; width: 32px; height: 32px; border-radius: 50%; font-size: 0.85rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center;">
|
||
🚪
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</header>
|
||
|
||
<!-- ========================================================
|
||
MAIN DASHBOARD GRID LAYOUT
|
||
======================================================== -->
|
||
<main class="dashboard-layout">
|
||
|
||
<!-- ========================================================
|
||
LEFT SIDEBAR COLUMN
|
||
======================================================== -->
|
||
<aside class="left-sidebar">
|
||
|
||
<!-- Navigation Menu -->
|
||
<div class="sidebar-nav-box">
|
||
<button class="sidebar-nav-item active" id="nav-btn-voice" onclick="switchMainTab('voice')">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path>
|
||
<path d="M19 10v2a7 7 0 0 1-14 0v-2"></path>
|
||
<line x1="12" y1="19" x2="12" y2="23"></line>
|
||
<line x1="8" y1="23" x2="16" y2="23"></line>
|
||
</svg>
|
||
Voice Screener
|
||
</button>
|
||
|
||
<button class="sidebar-nav-item" id="nav-btn-consultations" onclick="switchMainTab('consultations')">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
|
||
<polyline points="14 2 14 8 20 8"></polyline>
|
||
<line x1="16" y1="13" x2="8" y2="13"></line>
|
||
<line x1="16" y1="17" x2="8" y2="17"></line>
|
||
</svg>
|
||
Consultations DB
|
||
</button>
|
||
|
||
<button class="sidebar-nav-item" onclick="restartNewSession()">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<polyline points="1 4 1 10 7 10"></polyline>
|
||
<path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path>
|
||
</svg>
|
||
New Session
|
||
</button>
|
||
|
||
<button class="sidebar-nav-item" onclick="openDoctorSummaryModal()">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<line x1="18" y1="20" x2="18" y2="10"></line>
|
||
<line x1="12" y1="20" x2="12" y2="4"></line>
|
||
<line x1="6" y1="20" x2="6" y2="14"></line>
|
||
</svg>
|
||
Live Summary Report
|
||
</button>
|
||
</div>
|
||
|
||
<!-- Patient Profile Card -->
|
||
<div class="patient-profile-card">
|
||
<div class="patient-card-header">
|
||
<div class="patient-avatar-img">👤</div>
|
||
<div class="patient-header-info">
|
||
<div class="patient-header-top">
|
||
<h3 class="patient-name-title" id="side-patient-name">—</h3>
|
||
<span class="status-badge-active" id="side-patient-status" style="display: none;">Active</span>
|
||
</div>
|
||
<p class="patient-id-sub" id="side-patient-id">Patient ID: —</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="patient-meta-grid">
|
||
<div class="patient-meta-item">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
|
||
<circle cx="12" cy="7" r="4"></circle>
|
||
</svg>
|
||
<div class="meta-content">
|
||
<span class="meta-label">Age</span>
|
||
<span class="meta-value" id="side-patient-age">—</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="patient-meta-item">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<circle cx="12" cy="12" r="5"></circle>
|
||
<line x1="12" y1="1" x2="12" y2="3"></line>
|
||
<line x1="12" y1="21" x2="12" y2="23"></line>
|
||
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
|
||
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
|
||
<line x1="1" y1="12" x2="3" y2="12"></line>
|
||
<line x1="21" y1="12" x2="23" y2="12"></line>
|
||
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
|
||
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
|
||
</svg>
|
||
<div class="meta-content">
|
||
<span class="meta-label">Gender</span>
|
||
<span class="meta-value" id="side-patient-gender">—</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="patient-meta-item">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<path d="M12 2.69l5.66 5.66a8 8 0 1 1-11.31 0z"></path>
|
||
</svg>
|
||
<div class="meta-content">
|
||
<span class="meta-label">Diabetes</span>
|
||
<span class="meta-value" id="side-patient-type">—</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="patient-meta-item">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
|
||
<line x1="16" y1="2" x2="16" y2="6"></line>
|
||
<line x1="8" y1="2" x2="8" y2="6"></line>
|
||
<line x1="3" y1="10" x2="21" y2="10"></line>
|
||
</svg>
|
||
<div class="meta-content">
|
||
<span class="meta-label">Registered</span>
|
||
<span class="meta-value" id="side-patient-reg">—</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="patient-meta-item" style="grid-column: span 2;">
|
||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
||
stroke-linejoin="round">
|
||
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"></path>
|
||
<circle cx="12" cy="10" r="3"></circle>
|
||
</svg>
|
||
<div class="meta-content">
|
||
<span class="meta-label">Location</span>
|
||
<span class="meta-value" id="side-patient-loc">—</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="patient-card-footer-box">
|
||
<div class="sidebar-status-banner">
|
||
<span>🎙️ AI Voice Pre-Screening</span>
|
||
<span>● Ready</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
<!-- ========================================================
|
||
CENTER STAGE 1: LIVE VOICE CONSULTATION & CONTROLS
|
||
======================================================== -->
|
||
<section class="center-stage" id="voice-consultation-stage">
|
||
|
||
<!-- Live Mic & Acoustic Waveform Stage -->
|
||
<div class="live-mic-stage-card">
|
||
<div class="mic-waveform-center">
|
||
<div class="sound-bars-cluster">
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
</div>
|
||
|
||
<div class="central-mic-orb listening" id="central-sehat-orb" onclick="handleOrbClick()"
|
||
title="Tap to Pause / Speak">
|
||
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3"
|
||
stroke-linecap="round" stroke-linejoin="round">
|
||
<path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path>
|
||
<path d="M19 10v2a7 7 0 0 1-14 0v-2"></path>
|
||
<line x1="12" y1="19" x2="12" y2="23"></line>
|
||
<line x1="8" y1="23" x2="16" y2="23"></line>
|
||
</svg>
|
||
</div>
|
||
|
||
<div class="sound-bars-cluster">
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
<div class="sound-bar wave-bar"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="text-align: center; margin-top: 6px;">
|
||
<h4 class="mic-status-label" id="orb-dock-status">Ready</h4>
|
||
<p class="mic-status-sub" id="orb-dock-subtext">Tap orb or button below to begin voice consultation</p>
|
||
<button class="btn-start-consultation" id="btn-central-start-session"
|
||
onclick="initiateVoiceSessionWithUserGesture()"
|
||
style="max-width: 290px; margin: 12px auto 0 auto; padding: 10px 22px; font-size: 0.95rem;">
|
||
<span>🎙️</span> Start Voice Consultation
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Action Buttons Row -->
|
||
<div class="controls-action-bar">
|
||
<button class="btn-pill-action end-session" id="btn-end-conversation" onclick="handleEndOrRestartClick()">
|
||
<span>📞</span> End Session
|
||
</button>
|
||
|
||
<button class="btn-pill-action pause-active" id="btn-pause-resume" onclick="togglePauseMic()">
|
||
<span>⏸️</span> Pause
|
||
</button>
|
||
</div>
|
||
|
||
<!-- Chat Messages Scroll Container -->
|
||
<div class="chat-scroll-card" id="chat-messages-container">
|
||
</div>
|
||
</section>
|
||
|
||
<!-- ========================================================
|
||
CENTER STAGE 2: INLINE ADMIN CONSULTATIONS DASHBOARD (SQLITE)
|
||
======================================================== -->
|
||
<section class="center-stage" id="admin-consultations-stage" style="display: none;">
|
||
|
||
<!-- 4 Stat Metrics Cards -->
|
||
<div class="admin-stats-grid">
|
||
<div class="admin-stat-card">
|
||
<div class="admin-stat-details">
|
||
<span>Total Consultations</span>
|
||
<h3 id="inline-stat-total">0</h3>
|
||
</div>
|
||
<div class="admin-stat-icon teal">📋</div>
|
||
</div>
|
||
|
||
<div class="admin-stat-card">
|
||
<div class="admin-stat-details">
|
||
<span>Emergency Alerts</span>
|
||
<h3 id="inline-stat-emergencies" style="color: #dc2626;">0</h3>
|
||
</div>
|
||
<div class="admin-stat-icon red">🚨</div>
|
||
</div>
|
||
|
||
<div class="admin-stat-card">
|
||
<div class="admin-stat-details">
|
||
<span>Routine Reviews</span>
|
||
<h3 id="inline-stat-routine" style="color: #059669;">0</h3>
|
||
</div>
|
||
<div class="admin-stat-icon green">✅</div>
|
||
</div>
|
||
|
||
<div class="admin-stat-card">
|
||
<div class="admin-stat-details">
|
||
<span>Total Patients</span>
|
||
<h3 id="inline-stat-patients">0</h3>
|
||
</div>
|
||
<div class="admin-stat-icon purple">👥</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Search & Filters -->
|
||
<div class="admin-controls-card">
|
||
<div class="admin-search-wrap">
|
||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#94a3b8" stroke-width="2.2"
|
||
stroke-linecap="round" stroke-linejoin="round">
|
||
<circle cx="11" cy="11" r="8"></circle>
|
||
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
|
||
</svg>
|
||
<input type="text" id="inline-search-input" placeholder="Search by patient name, ID, or session..."
|
||
oninput="debounceInlineSearch()">
|
||
</div>
|
||
|
||
<div style="display: flex; align-items: center; gap: 8px;">
|
||
<select id="inline-urgency-select" class="admin-filter-select" onchange="fetchInlineConsultations()">
|
||
<option value="all">All Urgencies</option>
|
||
<option value="routine">Routine</option>
|
||
<option value="urgent">Urgent</option>
|
||
<option value="emergency">Emergency</option>
|
||
</select>
|
||
|
||
<button onclick="fetchInlineAdminData()"
|
||
style="background: #ffffff; border: 1px solid var(--card-border); padding: 6px 12px; border-radius: var(--radius-md); font-size: 0.8rem; font-weight: 700; color: var(--blue-navy); cursor: pointer; display: flex; align-items: center; gap: 4px;">
|
||
<span>🔄</span> Refresh
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Consultations Table -->
|
||
<div class="admin-table-container">
|
||
<div class="admin-table-header">
|
||
<h3>Consultation Records (SQLite)</h3>
|
||
<span id="inline-table-count" style="font-size: 0.78rem; font-weight: 700; color: var(--text-muted);">0
|
||
Records</span>
|
||
</div>
|
||
|
||
<div class="admin-table-responsive">
|
||
<table class="admin-data-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Date & Time</th>
|
||
<th>Patient Details</th>
|
||
<th>Diabetes Profile</th>
|
||
<th>Branch</th>
|
||
<th>Urgency</th>
|
||
<th>Actions</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="inline-consultations-tbody">
|
||
<tr>
|
||
<td colspan="6" style="text-align: center; padding: 28px; color: var(--text-muted);">
|
||
Loading consultations...
|
||
</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
|
||
|
||
</main>
|
||
|
||
<!-- ========================================================
|
||
DOCTOR CLINICAL SUMMARY MODAL
|
||
======================================================== -->
|
||
<div id="doctor-summary-modal" class="modal-overlay">
|
||
<div class="modal-content-card">
|
||
<div class="modal-header">
|
||
<div>
|
||
<h3 id="modal-summary-title">Clinical Summary & Doctor Handover</h3>
|
||
<div id="modal-summary-filepath" style="font-size: 0.75rem; color: var(--text-muted); margin-top: 3px;"></div>
|
||
</div>
|
||
<button style="background: none; border: none; color: #64748b; font-size: 1.5rem; cursor: pointer;"
|
||
onclick="closeDoctorSummaryModal()">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<!-- Indian Diabetes Risk Score (IDRS) Clinical Banner -->
|
||
<div id="modal-idrs-banner"
|
||
style="display: flex; align-items: center; justify-content: space-between; background: linear-gradient(135deg, #eff6ff 0%, #e0f2fe 100%); border: 1px solid #bae6fd; border-radius: 12px; padding: 12px 18px; margin-bottom: 16px;">
|
||
<div>
|
||
<div
|
||
style="font-size: 0.74rem; font-weight: 800; color: #0369a1; text-transform: uppercase; letter-spacing: 0.5px;">
|
||
INDIAN DIABETES RISK SCORE (IDRS)</div>
|
||
<div style="font-size: 0.8rem; color: #334155; margin-top: 2px;">Validated MDRF Clinical Screening Algorithm
|
||
</div>
|
||
</div>
|
||
<div style="display: flex; align-items: center; gap: 10px;">
|
||
<div id="modal-idrs-score-text"
|
||
style="font-family: 'Outfit', sans-serif; font-size: 1.5rem; font-weight: 800; color: #0284c7;">—/100
|
||
</div>
|
||
<span id="modal-idrs-badge" class="urgency-badge routine" style="font-size: 0.78rem; padding: 4px 10px;">Low
|
||
Risk</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="bilingual-grid" style="grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));">
|
||
<div class="summary-column">
|
||
<h4>🚩 Consultation Summary (Marathi / मराठी)</h4>
|
||
<div id="modal-summary-mr" class="summary-text">परामर्श सारांश उपलब्ध आहे.</div>
|
||
</div>
|
||
<div class="summary-column">
|
||
<h4>🇮🇳 Consultation Summary (Hindi)</h4>
|
||
<div id="modal-summary-hi" class="summary-text">Loading summary...</div>
|
||
</div>
|
||
<div class="summary-column">
|
||
<h4>🇬🇧 Clinical Summary (English for Physician)</h4>
|
||
<div id="modal-summary-en" class="summary-text">Loading clinical record...</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="margin-top: 20px; border-top: 1px solid var(--card-border); padding-top: 14px;">
|
||
<h4 style="color: var(--blue-navy); margin-bottom: 10px; font-size: 0.9rem;">📝 Complete Q&A Transcript</h4>
|
||
<div id="modal-qa-history"></div>
|
||
</div>
|
||
</div>
|
||
<div class="modal-footer">
|
||
<span style="font-size: 0.78rem; color: var(--text-muted);">⚕️ Pre-screening summary stored to EHR
|
||
record.</span>
|
||
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||
<button class="btn-pill-action" onclick="downloadCurrentSummaryTxt()">💾 Download (.txt)</button>
|
||
<button class="btn-pill-action" onclick="downloadCurrentSummaryJson()">📦 Download JSON</button>
|
||
<button class="btn-pill-action"
|
||
style="background: linear-gradient(135deg,#0ea5a8,#0284c7); color:white; border:none;"
|
||
onclick="downloadPDF(currentSessionId)">📄 PDF Download</button>
|
||
<button class="btn-pill-action"
|
||
style="background: linear-gradient(135deg,#25d366,#128c7e); color:white; border:none;"
|
||
onclick="openWhatsAppShareModal()">📲 Send to Doctor (WhatsApp)</button>
|
||
<button class="btn-pill-action" onclick="copyCurrentSummaryToClipboard()">📋 Copy</button>
|
||
<button class="btn-pill-action" onclick="window.print()">🖨️ Print</button>
|
||
<button class="btn-pill-action" onclick="closeDoctorSummaryModal()">Close</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ========================================================
|
||
CLIENT ENGINE & VOICE SCRIPT
|
||
======================================================== -->
|
||
<script>
|
||
let currentSessionId = null;
|
||
let questionsAskedCount = 7;
|
||
let maxBudget = 12;
|
||
let isListeningActive = false;
|
||
let isMicPaused = false;
|
||
let isConversationStopped = false;
|
||
let recognition = null;
|
||
let currentSttLang = 'hi-IN';
|
||
let silenceTimer = null;
|
||
let speechWatchdogInterval = null;
|
||
let speechSafetyTimeout = null;
|
||
let currentAccumulatedSpeech = '';
|
||
let currentLivePatientRow = null;
|
||
let lastBotPromptText = 'ही तहान तुम्हाला किती दिवसांपासून जाणवते?';
|
||
let lastBotAudioUrl = null;
|
||
let maleHindiVoice = null;
|
||
let isMaleVoice = false;
|
||
let isBotSpeaking = false;
|
||
let currentAudioPlayer = null;
|
||
let currentSpeechTurnSeq = 0;
|
||
let sessionStarted = false;
|
||
|
||
function escapeHtml(text) {
|
||
if (!text) return '';
|
||
const div = document.createElement('div');
|
||
div.textContent = text;
|
||
return div.innerHTML;
|
||
}
|
||
|
||
function setLanguageMode(lang) {
|
||
currentSttLang = lang;
|
||
const btnHi = document.getElementById('lang-btn-hi');
|
||
const btnMr = document.getElementById('lang-btn-mr');
|
||
if (lang === 'mr-IN') {
|
||
if (btnMr) {
|
||
btnMr.style.background = '#ffffff';
|
||
btnMr.style.color = 'var(--blue-navy)';
|
||
btnMr.style.boxShadow = '0 1px 3px rgba(0,0,0,0.08)';
|
||
}
|
||
if (btnHi) {
|
||
btnHi.style.background = 'transparent';
|
||
btnHi.style.color = 'var(--text-muted)';
|
||
btnHi.style.boxShadow = 'none';
|
||
}
|
||
lastBotPromptText = 'तुम्हाला मधुमेह (शुगर) चा त्रास आधीपासून आहे का, की काही नवीन लक्षणे जाणवत आहेत?';
|
||
} else {
|
||
if (btnHi) {
|
||
btnHi.style.background = '#ffffff';
|
||
btnHi.style.color = 'var(--blue-navy)';
|
||
btnHi.style.boxShadow = '0 1px 3px rgba(0,0,0,0.08)';
|
||
}
|
||
if (btnMr) {
|
||
btnMr.style.background = 'transparent';
|
||
btnMr.style.color = 'var(--text-muted)';
|
||
btnMr.style.boxShadow = 'none';
|
||
}
|
||
lastBotPromptText = 'क्या आपको पहले से Diabetes है, या आपको कुछ Symptoms feel हो रहे हैं?';
|
||
}
|
||
if (recognition) {
|
||
recognition.lang = currentSttLang;
|
||
}
|
||
setupVoices();
|
||
}
|
||
|
||
function setupVoices() {
|
||
if ('speechSynthesis' in window) {
|
||
const voices = window.speechSynthesis.getVoices();
|
||
if (!voices || voices.length === 0) return;
|
||
const targetLang = currentSttLang.toLowerCase();
|
||
|
||
let found = null;
|
||
if (targetLang.includes('mr')) {
|
||
// Marathi voice search
|
||
found = voices.find(v => {
|
||
const name = (v.name || '').toLowerCase();
|
||
const lang = (v.lang || '').toLowerCase();
|
||
return (lang.includes('mr') || lang.startsWith('mr_')) && (name.includes('aarohi') || name.includes('manohar') || name.includes('natural') || name.includes('google') || name.includes('marathi'));
|
||
}) || voices.find(v => (v.lang || '').toLowerCase().includes('mr'));
|
||
} else {
|
||
// Hindi voice search
|
||
found = voices.find(v => {
|
||
const name = (v.name || '').toLowerCase();
|
||
const lang = (v.lang || '').toLowerCase();
|
||
return (lang.includes('hi') || lang === 'hi-in') && (name.includes('google') || name.includes('natural') || name.includes('swara') || name.includes('madhur') || name.includes('hemant') || name.includes('kalpana') || name.includes('aditya') || name.includes('rahul'));
|
||
}) || voices.find(v => {
|
||
const lang = (v.lang || '').toLowerCase();
|
||
return lang.includes('hi') || lang === 'hi-in' || lang.startsWith('hi_');
|
||
});
|
||
}
|
||
|
||
// Fallback to Indian English or standard
|
||
if (!found) {
|
||
found = voices.find(v => {
|
||
const lang = (v.lang || '').toLowerCase();
|
||
return lang.includes('en-in') || lang.includes('en_in');
|
||
});
|
||
}
|
||
|
||
if (found) {
|
||
maleHindiVoice = found;
|
||
isMaleVoice = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
if ('speechSynthesis' in window) {
|
||
if (window.speechSynthesis.getVoices().length > 0) setupVoices();
|
||
else window.speechSynthesis.onvoiceschanged = setupVoices;
|
||
}
|
||
|
||
let micAudioContext = null;
|
||
let micAnalyser = null;
|
||
let micMediaStream = null;
|
||
|
||
async function requestMicPermission() {
|
||
try {
|
||
if (micMediaStream) return micMediaStream;
|
||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) return null;
|
||
const stream = await navigator.mediaDevices.getUserMedia({
|
||
audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true }
|
||
});
|
||
micMediaStream = stream;
|
||
setupWebAudioAnalyser(stream);
|
||
return stream;
|
||
} catch (err) {
|
||
console.warn('Microphone permission request note:', err);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
function setupWebAudioAnalyser(stream) {
|
||
try {
|
||
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
||
if (!AudioCtx) return;
|
||
if (!micAudioContext) micAudioContext = new AudioCtx();
|
||
if (micAudioContext.state === 'suspended') micAudioContext.resume();
|
||
const source = micAudioContext.createMediaStreamSource(stream);
|
||
micAnalyser = micAudioContext.createAnalyser();
|
||
micAnalyser.fftSize = 256;
|
||
source.connect(micAnalyser);
|
||
startVuMeterLoop();
|
||
} catch (e) { }
|
||
}
|
||
|
||
function startVuMeterLoop() {
|
||
const dataArray = new Uint8Array(micAnalyser ? micAnalyser.frequencyBinCount : 0);
|
||
const waveBars = document.querySelectorAll('.wave-bar');
|
||
|
||
function renderFrame() {
|
||
if (micAnalyser && !isMicPaused && !isConversationStopped) {
|
||
micAnalyser.getByteFrequencyData(dataArray);
|
||
let sum = 0;
|
||
for (let i = 0; i < dataArray.length; i++) sum += dataArray[i];
|
||
const avg = sum / dataArray.length;
|
||
|
||
if (waveBars.length > 0) {
|
||
waveBars.forEach((bar, idx) => {
|
||
const binVal = dataArray[(idx * 3) % dataArray.length] || avg;
|
||
const scale = Math.max(0.35, Math.min(1.8, binVal / 50));
|
||
bar.style.transform = `scaleY(${scale})`;
|
||
});
|
||
}
|
||
}
|
||
requestAnimationFrame(renderFrame);
|
||
}
|
||
renderFrame();
|
||
}
|
||
|
||
function cleanSpokenTranscript(raw) {
|
||
if (!raw) return '';
|
||
return raw
|
||
.replace(/[।,;:\.\?!()\"'/\-_।॥\u0964\u0965`~*#&^%$@+=><\[\]\{\}\\|\n\r]/g, ' ')
|
||
.replace(/\s+/g, ' ')
|
||
.trim();
|
||
}
|
||
|
||
function initSpeechRecognition() {
|
||
if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) return;
|
||
const SpeechRec = window.SpeechRecognition || window.webkitSpeechRecognition;
|
||
try {
|
||
if (recognition) {
|
||
try { recognition.abort(); } catch (e) { }
|
||
}
|
||
recognition = new SpeechRec();
|
||
recognition.lang = currentSttLang || 'hi-IN';
|
||
recognition.continuous = true;
|
||
recognition.interimResults = true;
|
||
|
||
recognition.onstart = function () {
|
||
if (isMicPaused || isConversationStopped) {
|
||
try { recognition.stop(); } catch (e) { }
|
||
return;
|
||
}
|
||
isListeningActive = true;
|
||
if (!isBotSpeaking) updateOrbUI('listening');
|
||
};
|
||
|
||
recognition.onresult = function (event) {
|
||
if (isMicPaused || isConversationStopped) return;
|
||
|
||
// If patient starts speaking, immediately stop any active bot speech (Barge-In)
|
||
if (isBotSpeaking) {
|
||
stopAnyBotSpeech();
|
||
}
|
||
|
||
let sessionTranscript = '';
|
||
for (let i = 0; i < event.results.length; ++i) {
|
||
if (event.results[i] && event.results[i][0]) {
|
||
sessionTranscript += event.results[i][0].transcript + ' ';
|
||
}
|
||
}
|
||
|
||
const rawCombined = (currentAccumulatedSpeech + ' ' + sessionTranscript).trim();
|
||
const cleanDisplay = cleanSpokenTranscript(rawCombined);
|
||
|
||
if (cleanDisplay) {
|
||
updatePatientLiveBubble(cleanDisplay);
|
||
const lbl = document.getElementById('orb-dock-status');
|
||
const sub = document.getElementById('orb-dock-subtext');
|
||
if (lbl) lbl.textContent = '👂 Listening carefully...';
|
||
if (sub) {
|
||
sub.textContent = '🗣️ "' + cleanDisplay + '" (Speak at your own pace...)';
|
||
sub.style.color = '#38bdf8';
|
||
sub.style.fontWeight = '600';
|
||
}
|
||
if (silenceTimer) clearTimeout(silenceTimer);
|
||
|
||
// Generous natural pause (2500ms): ensures patient finishes full multi-phrase sentence without punctuation truncation
|
||
silenceTimer = setTimeout(() => {
|
||
if (isBotSpeaking || isMicPaused || isConversationStopped) return;
|
||
if (cleanDisplay) {
|
||
currentAccumulatedSpeech = '';
|
||
stopListening();
|
||
sendVoiceTurn(cleanDisplay);
|
||
}
|
||
}, 2500);
|
||
}
|
||
};
|
||
|
||
recognition.onerror = function (event) {
|
||
if (event.error === 'no-speech') {
|
||
return; // Normal silence, keep listening
|
||
}
|
||
console.log('Speech error notice:', event.error);
|
||
};
|
||
|
||
recognition.onend = function () {
|
||
if (isListeningActive && !isMicPaused && !isConversationStopped && !isBotSpeaking) {
|
||
setTimeout(() => {
|
||
try { recognition.start(); } catch (e) { }
|
||
}, 100);
|
||
}
|
||
};
|
||
} catch (e) { }
|
||
}
|
||
|
||
initSpeechRecognition();
|
||
|
||
async function startListening() {
|
||
if (isBotSpeaking || isMicPaused || isConversationStopped) return;
|
||
if (silenceTimer) clearTimeout(silenceTimer);
|
||
currentAccumulatedSpeech = '';
|
||
currentLivePatientRow = null;
|
||
|
||
await requestMicPermission();
|
||
|
||
if (!recognition) initSpeechRecognition();
|
||
if (recognition) {
|
||
try { recognition.abort(); } catch (e) { }
|
||
setTimeout(() => {
|
||
if (isBotSpeaking || isMicPaused || isConversationStopped) return;
|
||
try {
|
||
isListeningActive = true;
|
||
recognition.start();
|
||
} catch (e) { }
|
||
updateOrbUI('listening');
|
||
}, 60);
|
||
} else {
|
||
isListeningActive = true;
|
||
updateOrbUI('listening');
|
||
}
|
||
}
|
||
|
||
function stopListening() {
|
||
isListeningActive = false;
|
||
if (silenceTimer) clearTimeout(silenceTimer);
|
||
if (recognition) {
|
||
try { recognition.abort(); } catch (e) { }
|
||
}
|
||
updateOrbUI(isMicPaused ? 'paused' : 'idle');
|
||
}
|
||
|
||
function handleOrbClick() {
|
||
if (isConversationStopped) {
|
||
restartNewSession();
|
||
return;
|
||
}
|
||
if (!sessionStarted) {
|
||
initiateVoiceSessionWithUserGesture();
|
||
return;
|
||
}
|
||
if (isListeningActive && currentAccumulatedSpeech.trim()) {
|
||
const fullText = currentAccumulatedSpeech.trim();
|
||
currentAccumulatedSpeech = '';
|
||
stopListening();
|
||
sendVoiceTurn(fullText);
|
||
return;
|
||
}
|
||
togglePauseMic();
|
||
}
|
||
|
||
function togglePauseMic() {
|
||
if (isConversationStopped) {
|
||
restartNewSession();
|
||
return;
|
||
}
|
||
if (!sessionStarted) {
|
||
initiateVoiceSessionWithUserGesture();
|
||
return;
|
||
}
|
||
|
||
const btn = document.getElementById('btn-pause-resume');
|
||
if (!isMicPaused) {
|
||
isMicPaused = true;
|
||
stopListening();
|
||
updateOrbUI('paused');
|
||
if (btn) {
|
||
btn.innerHTML = '<span>▶️</span> Resume';
|
||
btn.className = 'btn-pill-action resume-active';
|
||
}
|
||
} else {
|
||
isMicPaused = false;
|
||
if (btn) {
|
||
btn.innerHTML = '<span>⏸️</span> Pause';
|
||
btn.className = 'btn-pill-action pause-active';
|
||
}
|
||
if (!isBotSpeaking) startListening();
|
||
else updateOrbUI('speaking');
|
||
}
|
||
}
|
||
|
||
function handleEndOrRestartClick() {
|
||
if (isConversationStopped) {
|
||
restartNewSession();
|
||
return;
|
||
}
|
||
stopEntireConversation();
|
||
}
|
||
|
||
function stopAnyBotSpeech() {
|
||
currentSpeechTurnSeq++;
|
||
if (currentAudioPlayer) {
|
||
try {
|
||
currentAudioPlayer.pause();
|
||
currentAudioPlayer.currentTime = 0;
|
||
} catch (e) { }
|
||
currentAudioPlayer = null;
|
||
}
|
||
if ('speechSynthesis' in window) {
|
||
try { window.speechSynthesis.cancel(); } catch (e) { }
|
||
}
|
||
if (speechWatchdogInterval) clearInterval(speechWatchdogInterval);
|
||
if (speechSafetyTimeout) clearTimeout(speechSafetyTimeout);
|
||
isBotSpeaking = false;
|
||
}
|
||
|
||
function stopEntireConversation() {
|
||
isConversationStopped = true;
|
||
isMicPaused = true;
|
||
isListeningActive = false;
|
||
|
||
stopAnyBotSpeech();
|
||
stopListening();
|
||
|
||
updateOrbUI('stopped');
|
||
|
||
const startBtn = document.getElementById('btn-central-start-session');
|
||
if (startBtn) {
|
||
startBtn.innerHTML = '<span>🎙️</span> Start New Consultation';
|
||
startBtn.style.display = 'flex';
|
||
}
|
||
|
||
const endBtn = document.getElementById('btn-end-conversation');
|
||
if (endBtn) {
|
||
endBtn.innerHTML = '<span>🔄</span> Start New';
|
||
endBtn.className = 'btn-pill-action listening-active';
|
||
}
|
||
|
||
const pauseBtn = document.getElementById('btn-pause-resume');
|
||
if (pauseBtn) {
|
||
pauseBtn.innerHTML = '<span>▶️</span> Resume';
|
||
pauseBtn.className = 'btn-pill-action resume-active';
|
||
}
|
||
}
|
||
|
||
function restartNewSession() {
|
||
isConversationStopped = false;
|
||
isMicPaused = false;
|
||
isBotSpeaking = false;
|
||
isListeningActive = false;
|
||
currentSessionId = null;
|
||
currentAccumulatedSpeech = '';
|
||
|
||
const startBtn = document.getElementById('btn-central-start-session');
|
||
if (startBtn) startBtn.style.display = 'none';
|
||
|
||
const endBtn = document.getElementById('btn-end-conversation');
|
||
if (endBtn) {
|
||
endBtn.innerHTML = '<span>📞</span> End Session';
|
||
endBtn.className = 'btn-pill-action end-session';
|
||
}
|
||
|
||
const pauseBtn = document.getElementById('btn-pause-resume');
|
||
if (pauseBtn) {
|
||
pauseBtn.innerHTML = '<span>⏸️</span> Pause';
|
||
pauseBtn.className = 'btn-pill-action pause-active';
|
||
}
|
||
|
||
const container = document.getElementById('chat-messages-container');
|
||
if (container) container.innerHTML = '';
|
||
|
||
updateProgress(1, 12);
|
||
startSehatSession();
|
||
}
|
||
|
||
function updateOrbUI(state) {
|
||
const orb = document.getElementById('central-sehat-orb');
|
||
const lbl = document.getElementById('orb-dock-status');
|
||
const sub = document.getElementById('orb-dock-subtext');
|
||
const pauseBtn = document.getElementById('btn-pause-resume');
|
||
|
||
if (orb) orb.className = 'central-mic-orb';
|
||
if (sub) {
|
||
sub.style.color = '';
|
||
sub.style.fontWeight = '';
|
||
}
|
||
|
||
if (state === 'speaking') {
|
||
if (orb) orb.classList.add('speaking');
|
||
if (lbl) lbl.textContent = 'Assistant Speaking...';
|
||
if (sub) sub.textContent = 'Listening to response...';
|
||
if (pauseBtn && !isMicPaused) {
|
||
pauseBtn.innerHTML = '<span>⏸️</span> Pause';
|
||
pauseBtn.className = 'btn-pill-action pause-active';
|
||
}
|
||
} else if (state === 'listening') {
|
||
if (orb) orb.classList.add('listening');
|
||
if (lbl) lbl.textContent = 'Listening...';
|
||
if (sub) sub.textContent = 'Please speak...';
|
||
if (pauseBtn && !isMicPaused) {
|
||
pauseBtn.innerHTML = '<span>⏸️</span> Pause';
|
||
pauseBtn.className = 'btn-pill-action pause-active';
|
||
}
|
||
} else if (state === 'thinking') {
|
||
if (lbl) lbl.textContent = 'Processing...';
|
||
if (sub) sub.textContent = 'Analyzing response...';
|
||
} else if (state === 'paused') {
|
||
if (orb) orb.classList.add('paused');
|
||
if (lbl) lbl.textContent = 'Microphone Paused';
|
||
if (sub) sub.textContent = 'Tap to resume...';
|
||
if (pauseBtn) {
|
||
pauseBtn.innerHTML = '<span>▶️</span> Resume';
|
||
pauseBtn.className = 'btn-pill-action resume-active';
|
||
}
|
||
} else if (state === 'stopped') {
|
||
if (orb) orb.classList.add('stopped');
|
||
if (lbl) lbl.textContent = 'Conversation Ended';
|
||
if (sub) sub.textContent = 'Review summary or start new';
|
||
} else {
|
||
if (lbl) lbl.textContent = 'Ready';
|
||
if (sub) sub.textContent = 'Tap orb or speak';
|
||
}
|
||
}
|
||
|
||
function playSehatMaleSpeech(text, onComplete, audioUrl = null) {
|
||
if (isConversationStopped || !text || !text.trim()) {
|
||
if (onComplete) onComplete();
|
||
return;
|
||
}
|
||
|
||
stopAnyBotSpeech();
|
||
const thisTurnSeq = currentSpeechTurnSeq;
|
||
isBotSpeaking = true;
|
||
lastBotPromptText = text;
|
||
lastBotAudioUrl = audioUrl;
|
||
|
||
stopListening();
|
||
|
||
let speechFinished = false;
|
||
const finishSpeech = () => {
|
||
if (thisTurnSeq !== currentSpeechTurnSeq || speechFinished) return;
|
||
speechFinished = true;
|
||
if (speechWatchdogInterval) clearInterval(speechWatchdogInterval);
|
||
if (speechSafetyTimeout) clearTimeout(speechSafetyTimeout);
|
||
isBotSpeaking = false;
|
||
if (!isConversationStopped && !isMicPaused) updateOrbUI('idle');
|
||
if (onComplete) onComplete();
|
||
};
|
||
|
||
if (audioUrl) {
|
||
try {
|
||
const freshAudioUrl = audioUrl + (audioUrl.includes('?') ? '&' : '?') + 't=' + Date.now();
|
||
const audio = new Audio(freshAudioUrl);
|
||
audio.playbackRate = 1.05;
|
||
currentAudioPlayer = audio;
|
||
audio.onplay = () => {
|
||
if (thisTurnSeq === currentSpeechTurnSeq) updateOrbUI('speaking');
|
||
};
|
||
audio.onended = finishSpeech;
|
||
audio.onerror = () => playWithBrowserSpeechSynthesis(text, finishSpeech, thisTurnSeq);
|
||
audio.play().catch(() => playWithBrowserSpeechSynthesis(text, finishSpeech, thisTurnSeq));
|
||
return;
|
||
} catch (e) { }
|
||
}
|
||
|
||
playWithBrowserSpeechSynthesis(text, finishSpeech, thisTurnSeq);
|
||
}
|
||
|
||
let cachedVoice = null;
|
||
function findPoliteIndianVoice() {
|
||
if (!('speechSynthesis' in window)) return null;
|
||
if (cachedVoice) return cachedVoice;
|
||
const voices = window.speechSynthesis.getVoices() || [];
|
||
if (!voices.length) return null;
|
||
|
||
// 1. Natural / Neural Hindi voices
|
||
let v = voices.find(v => (v.lang === 'hi-IN' || v.lang.startsWith('hi')) && (v.name.includes('Natural') || v.name.includes('Google') || v.name.includes('Online') || v.name.includes('Madhav') || v.name.includes('Hemant')));
|
||
if (v) { cachedVoice = v; return v; }
|
||
|
||
// 2. Any Hindi voice
|
||
v = voices.find(v => v.lang === 'hi-IN' || v.lang.startsWith('hi'));
|
||
if (v) { cachedVoice = v; return v; }
|
||
|
||
// 3. Indian English / Marathi natural voice
|
||
v = voices.find(v => (v.lang === 'mr-IN' || v.lang === 'en-IN') && (v.name.includes('Natural') || v.name.includes('Google') || v.name.includes('Prabhat') || v.name.includes('Neerja')));
|
||
if (v) { cachedVoice = v; return v; }
|
||
|
||
v = voices.find(v => v.lang === 'en-IN' || v.lang === 'mr-IN');
|
||
if (v) { cachedVoice = v; return v; }
|
||
|
||
cachedVoice = voices[0] || null;
|
||
return cachedVoice;
|
||
}
|
||
|
||
if ('speechSynthesis' in window) {
|
||
window.speechSynthesis.onvoiceschanged = () => {
|
||
cachedVoice = null;
|
||
findPoliteIndianVoice();
|
||
};
|
||
setTimeout(findPoliteIndianVoice, 100);
|
||
}
|
||
|
||
function cleanTextForSpeechPlayback(raw) {
|
||
if (!raw) return '';
|
||
return raw
|
||
.replace(/Male\s*\/\s*Female/gi, 'Male या Female')
|
||
.replace(/112\s*\/\s*108/g, '112 या 108')
|
||
.replace(/हाँ\s*\/\s*नहीं/g, 'हाँ या नहीं')
|
||
.replace(/(\w+)\s*\/\s*(\w+)/g, '$1 या $2')
|
||
.replace(/\bmg\/dL\b/gi, ' मिलीग्राम ')
|
||
.replace(/\bHbA1c\b/gi, ' HbA1c ')
|
||
.replace(/\bBP\b/gi, ' BP ')
|
||
.replace(/[\(\)\[\]\{\}\<\>\"\'`*#~_—–|:;/\\]/g, ' ')
|
||
.replace(/\s+/g, ' ')
|
||
.trim();
|
||
}
|
||
|
||
function playWithBrowserSpeechSynthesis(text, finishSpeech, turnSeq) {
|
||
if (isConversationStopped || ('speechSynthesis' in window === false)) {
|
||
finishSpeech();
|
||
return;
|
||
}
|
||
window.speechSynthesis.cancel();
|
||
window.speechSynthesis.resume();
|
||
|
||
const spokenText = cleanTextForSpeechPlayback(text);
|
||
const utterance = new SpeechSynthesisUtterance(spokenText);
|
||
utterance.lang = 'hi-IN';
|
||
utterance.volume = 1.0;
|
||
utterance.pitch = 1.0; // Natural human pitch
|
||
utterance.rate = 1.15; // Snappy, fluent conversational pacing
|
||
|
||
const politeVoice = findPoliteIndianVoice();
|
||
if (politeVoice) utterance.voice = politeVoice;
|
||
|
||
utterance.onstart = () => {
|
||
if (turnSeq === currentSpeechTurnSeq) updateOrbUI('speaking');
|
||
};
|
||
utterance.onend = finishSpeech;
|
||
utterance.onerror = finishSpeech;
|
||
|
||
const maxDuration = Math.max(3500, spokenText.length * 120 + 2000);
|
||
speechSafetyTimeout = setTimeout(() => {
|
||
window.speechSynthesis.cancel();
|
||
finishSpeech();
|
||
}, maxDuration);
|
||
|
||
try {
|
||
window.speechSynthesis.speak(utterance);
|
||
} catch (err) {
|
||
finishSpeech();
|
||
}
|
||
}
|
||
|
||
function appendBotBubble(text, audioUrl = null) {
|
||
finalizePatientBubble();
|
||
const cleanText = cleanSpokenTranscript(text);
|
||
const timeStr = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||
const container = document.getElementById('chat-messages-container');
|
||
const div = document.createElement('div');
|
||
div.className = 'chat-row bot';
|
||
div.innerHTML = `
|
||
<div class="chat-avatar bot">🤖</div>
|
||
<div class="chat-bubble-wrap">
|
||
<div class="chat-sender-name">
|
||
<span>Diabetic Dost</span>
|
||
<span class="chat-sender-badge">AI Assistant</span>
|
||
</div>
|
||
<div class="chat-bubble bot">
|
||
${escapeHtml(cleanText)}
|
||
<div class="chat-bubble-footer">
|
||
<span>${timeStr}</span>
|
||
<button class="btn-audio-replay" title="Replay Audio">🔊</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
const btn = div.querySelector('.btn-audio-replay');
|
||
if (btn) {
|
||
btn.onclick = () => playSehatMaleSpeech(cleanText, () => startListening(), audioUrl);
|
||
}
|
||
container.appendChild(div);
|
||
container.scrollTop = container.scrollHeight;
|
||
}
|
||
|
||
function updatePatientLiveBubble(text) {
|
||
if (!text || !text.trim()) return;
|
||
const cleanSpokenText = cleanSpokenTranscript(text);
|
||
if (!cleanSpokenText) return;
|
||
|
||
const container = document.getElementById('chat-messages-container');
|
||
const timeStr = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||
|
||
if (!currentLivePatientRow || !container.contains(currentLivePatientRow)) {
|
||
const row = document.createElement('div');
|
||
row.className = 'chat-row patient';
|
||
row.innerHTML = `
|
||
<div class="chat-avatar patient">👤</div>
|
||
<div class="chat-bubble-wrap">
|
||
<div class="chat-sender-name" style="justify-content: flex-end;">
|
||
<span>Patient</span>
|
||
</div>
|
||
<div class="chat-bubble patient">
|
||
<span class="patient-text-content">${escapeHtml(cleanSpokenText)}</span>
|
||
<div class="chat-bubble-footer">
|
||
<span class="patient-time">${timeStr}</span>
|
||
<span style="color: #10b981;">📶</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
`;
|
||
container.appendChild(row);
|
||
currentLivePatientRow = row;
|
||
} else {
|
||
const el = currentLivePatientRow.querySelector('.patient-text-content');
|
||
if (el) el.textContent = cleanSpokenText;
|
||
}
|
||
container.scrollTop = container.scrollHeight;
|
||
}
|
||
|
||
function finalizePatientBubble() {
|
||
currentLivePatientRow = null;
|
||
}
|
||
|
||
async function initiateVoiceSessionWithUserGesture() {
|
||
if (sessionStarted) return;
|
||
sessionStarted = true;
|
||
|
||
const startBtn = document.getElementById('btn-central-start-session');
|
||
if (startBtn) startBtn.style.display = 'none';
|
||
|
||
if ('speechSynthesis' in window) {
|
||
try {
|
||
const unlock = new SpeechSynthesisUtterance(' ');
|
||
unlock.volume = 0.01;
|
||
window.speechSynthesis.speak(unlock);
|
||
} catch (e) { }
|
||
}
|
||
|
||
await Promise.all([
|
||
requestMicPermission(),
|
||
startSehatSession()
|
||
]);
|
||
}
|
||
|
||
async function startSehatFollowupSession(patientName) {
|
||
sessionStarted = true;
|
||
stopListening();
|
||
try {
|
||
const formData = new FormData();
|
||
formData.append('patient_name', patientName);
|
||
const res = await fetch('/api/sehat/session/start_followup', { method: 'POST', body: formData });
|
||
const data = await res.json();
|
||
if (data.status === 'success') {
|
||
currentSessionId = data.session_id;
|
||
updateProgress(data.questions_asked_count, data.total_budget || 8);
|
||
updateProfileSidebar(data.state);
|
||
appendBotBubble(data.bot_speech_hi, data.audio_url);
|
||
playSehatMaleSpeech(data.bot_speech_hi, () => {
|
||
setTimeout(() => { if (!isMicPaused && !isConversationStopped) startListening(); }, 40);
|
||
}, data.audio_url);
|
||
}
|
||
} catch (err) {
|
||
console.error(err);
|
||
}
|
||
}
|
||
|
||
async function startSehatSession() {
|
||
sessionStarted = true;
|
||
stopListening();
|
||
try {
|
||
const res = await fetch('/api/sehat/session/start', { method: 'POST' });
|
||
const data = await res.json();
|
||
if (data.status === 'success') {
|
||
currentSessionId = data.session_id;
|
||
updateProgress(data.questions_asked_count, data.total_budget || 12);
|
||
updateProfileSidebar(data.state);
|
||
appendBotBubble(data.bot_speech_hi, data.audio_url);
|
||
playSehatMaleSpeech(data.bot_speech_hi, () => {
|
||
setTimeout(() => { if (!isMicPaused && !isConversationStopped) startListening(); }, 40);
|
||
}, data.audio_url);
|
||
}
|
||
} catch (err) {
|
||
console.error(err);
|
||
}
|
||
}
|
||
|
||
async function sendVoiceTurn(transcriptText, audioBlob = null) {
|
||
if (!transcriptText && !audioBlob) {
|
||
startListening();
|
||
return;
|
||
}
|
||
stopAnyBotSpeech();
|
||
const spokenText = transcriptText ? transcriptText.trim() : '';
|
||
if (spokenText) updatePatientLiveBubble(spokenText);
|
||
finalizePatientBubble();
|
||
stopListening();
|
||
updateOrbUI('thinking');
|
||
|
||
const formData = new FormData();
|
||
formData.append('session_id', currentSessionId || '');
|
||
if (spokenText) formData.append('transcript', spokenText);
|
||
if (audioBlob) formData.append('file', audioBlob, 'patient_voice.wav');
|
||
// Send active language to backend for correct ASR language code
|
||
formData.append('language', currentSttLang === 'mr-IN' ? 'mr' : 'hi');
|
||
|
||
try {
|
||
const res = await fetch('/api/sehat/session/turn', { method: 'POST', body: formData });
|
||
const data = await res.json();
|
||
if (isConversationStopped) return;
|
||
|
||
if (data.status === 'success' || data.status === 'emergency_interrupted') {
|
||
// Immediately update patient message with accurate Hinglish / English-formatted transcript
|
||
if (data.patient_transcript) {
|
||
const allPatientRows = document.querySelectorAll('.chat-row.patient');
|
||
if (allPatientRows.length > 0) {
|
||
const lastPatientEl = allPatientRows[allPatientRows.length - 1].querySelector('.patient-text-content');
|
||
if (lastPatientEl) lastPatientEl.textContent = data.patient_transcript;
|
||
}
|
||
}
|
||
|
||
appendBotBubble(data.bot_speech_hi, data.audio_url);
|
||
updateProgress(data.questions_asked_count, data.total_budget || 12);
|
||
updateProfileSidebar(data.state);
|
||
|
||
playSehatMaleSpeech(data.bot_speech_hi, () => {
|
||
if (!data.is_completed && !isMicPaused && !isConversationStopped) {
|
||
setTimeout(() => { if (!isMicPaused && !isConversationStopped) startListening(); }, 40);
|
||
} else if (data.is_completed) {
|
||
updateOrbUI('idle');
|
||
// 🎉 Show IDRS risk card + WhatsApp share button after completion
|
||
setTimeout(() => showCompletionCard(data.state), 600);
|
||
}
|
||
}, data.audio_url);
|
||
}
|
||
} catch (err) {
|
||
console.error(err);
|
||
if (!isMicPaused && !isConversationStopped) startListening();
|
||
}
|
||
}
|
||
|
||
function updateProgress(count, total) {
|
||
questionsAskedCount = count || 1;
|
||
maxBudget = total || 12;
|
||
const badge = document.getElementById('question-progress-badge');
|
||
if (badge) badge.textContent = `Question ${questionsAskedCount} of ${maxBudget}`;
|
||
|
||
const pct = Math.min(100, Math.round((questionsAskedCount / maxBudget) * 100));
|
||
const fillBar = document.getElementById('progress-fill-bar');
|
||
if (fillBar) fillBar.style.width = pct + '%';
|
||
const pctText = document.getElementById('progress-percent-text');
|
||
if (pctText) pctText.textContent = pct + '%';
|
||
|
||
// Update right column questions status counts
|
||
const qCompleted = document.getElementById('q-stat-completed');
|
||
if (qCompleted) qCompleted.textContent = Math.max(1, questionsAskedCount);
|
||
const qRemaining = document.getElementById('q-stat-remaining');
|
||
if (qRemaining) qRemaining.textContent = Math.max(0, maxBudget - questionsAskedCount);
|
||
}
|
||
|
||
function updateProfileSidebar(state) {
|
||
if (!state) return;
|
||
const patient = state.patient || state.demographics || {};
|
||
|
||
const nameEl = document.getElementById('side-patient-name');
|
||
if (nameEl) nameEl.textContent = patient.name || (state.session_id ? 'Active Patient' : '—');
|
||
|
||
const statusEl = document.getElementById('side-patient-status');
|
||
if (statusEl) {
|
||
statusEl.textContent = 'Active';
|
||
statusEl.style.display = 'inline-block';
|
||
}
|
||
|
||
const idEl = document.getElementById('side-patient-id');
|
||
if (idEl) {
|
||
idEl.textContent = patient.patient_id ? `Patient ID: ${patient.patient_id}` : (state.session_id ? `Session: ${state.session_id.substring(0, 8)}` : 'Patient ID: —');
|
||
}
|
||
|
||
const ageEl = document.getElementById('side-patient-age');
|
||
if (ageEl) ageEl.textContent = patient.age ? `${patient.age} Years` : '—';
|
||
|
||
const genderEl = document.getElementById('side-patient-gender');
|
||
if (genderEl) genderEl.textContent = patient.gender || patient.sex || '—';
|
||
|
||
const typeEl = document.getElementById('side-patient-type');
|
||
if (typeEl) {
|
||
typeEl.textContent = state.diabetes_type || patient.diabetes_type || (state.branch === 'known_diabetic' ? 'Type 2 Diabetes' : (state.branch === 'not_diabetic' ? 'Non-Diabetic' : 'Screening'));
|
||
}
|
||
|
||
const regEl = document.getElementById('side-patient-reg');
|
||
if (regEl) {
|
||
regEl.textContent = patient.registered_date || (state.created_at ? new Date(state.created_at).toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }) : 'Today');
|
||
}
|
||
|
||
const locEl = document.getElementById('side-patient-loc');
|
||
if (locEl) locEl.textContent = patient.location || patient.city || 'Kolhapur';
|
||
}
|
||
|
||
function replaySehatPrompt() {
|
||
playSehatMaleSpeech(lastBotPromptText, () => startListening(), lastBotAudioUrl);
|
||
}
|
||
|
||
let currentLoadedSummary = null;
|
||
|
||
// ── IDRS Risk Score Visual Card (shown after consultation completes) ──────
|
||
function showCompletionCard(state) {
|
||
// Try to fetch full summary for IDRS data
|
||
if (!currentSessionId) return;
|
||
fetch(`/api/sehat/session/${currentSessionId}/summary`)
|
||
.then(r => r.json())
|
||
.then(data => {
|
||
if (data.status !== 'success') return;
|
||
const s = data.summary;
|
||
const idrsScore = s.idrs_risk_score || 0;
|
||
const idrsCategory = s.idrs_risk_category || 'Low Risk';
|
||
const breakdown = s.idrs_breakdown || {};
|
||
const medications = s.medications || [];
|
||
|
||
// Colour by category
|
||
const color = idrsCategory.toLowerCase().includes('high') ? '#ef4444'
|
||
: idrsCategory.toLowerCase().includes('moderate') ? '#f59e0b'
|
||
: '#10b981';
|
||
const bgColor = idrsCategory.toLowerCase().includes('high') ? '#fef2f2'
|
||
: idrsCategory.toLowerCase().includes('moderate') ? '#fffbeb'
|
||
: '#f0fdf4';
|
||
|
||
// Diet tips by risk
|
||
const dietTips = [
|
||
'🌿 मेथी दाण्यांचे पाणी सकाळी रिकाम्या पोटी प्या.',
|
||
'🌾 ज्वारी / बाजरी भाकरी वापरा — पांढऱ्या तांदळाऐवजी.',
|
||
'🥦 मूग डाळ, पालेभाज्या, काकडी — कमी GI पदार्थ.',
|
||
'🚶 रोज ३०–४५ मिनिटे चाला किंवा व्यायाम करा.',
|
||
...(idrsCategory.toLowerCase().includes('high') ? [
|
||
'🚫 गोड पेये, कोल्ड ड्रिंक्स पूर्णपणे टाळा.',
|
||
'🩺 HbA1c तपासणी दर ३ महिन्यांनी करा.'
|
||
] : [])
|
||
];
|
||
|
||
// Build SVG arc for score meter
|
||
const radius = 54;
|
||
const circumference = 2 * Math.PI * radius;
|
||
const offset = circumference * (1 - idrsScore / 100);
|
||
|
||
const card = document.createElement('div');
|
||
card.id = 'idrs-completion-card';
|
||
card.style.cssText = `
|
||
background: linear-gradient(135deg, ${bgColor} 0%, #ffffff 100%);
|
||
border: 2px solid ${color}30;
|
||
border-radius: 18px;
|
||
padding: 20px;
|
||
margin: 14px 0;
|
||
animation: slideInUp 0.5s ease;
|
||
`;
|
||
card.innerHTML = `
|
||
<div style="display: flex; align-items: center; gap: 16px; margin-bottom: 14px;">
|
||
<!-- SVG Score Meter -->
|
||
<div style="flex-shrink: 0; position: relative; width: 120px; height: 120px;">
|
||
<svg width="120" height="120" viewBox="0 0 120 120">
|
||
<circle cx="60" cy="60" r="54" fill="none" stroke="#e2e8f0" stroke-width="10"/>
|
||
<circle cx="60" cy="60" r="54" fill="none" stroke="${color}" stroke-width="10"
|
||
stroke-dasharray="${circumference.toFixed(1)}"
|
||
stroke-dashoffset="${offset.toFixed(1)}"
|
||
stroke-linecap="round"
|
||
transform="rotate(-90 60 60)"
|
||
style="transition: stroke-dashoffset 1.2s ease;"/>
|
||
<text x="60" y="56" text-anchor="middle" font-family="Outfit,sans-serif" font-size="20" font-weight="800" fill="${color}">${idrsScore}</text>
|
||
<text x="60" y="72" text-anchor="middle" font-family="Inter,sans-serif" font-size="9" fill="#64748b">/100 IDRS</text>
|
||
</svg>
|
||
</div>
|
||
<!-- Score Info -->
|
||
<div style="flex: 1;">
|
||
<div style="font-family: 'Outfit',sans-serif; font-size: 1rem; font-weight: 800; color: #0f2949;">📊 Indian Diabetes Risk Score</div>
|
||
<div style="font-size: 0.78rem; color: #64748b; margin-bottom: 8px;">IDRS — MDRF Validated Algorithm</div>
|
||
<span style="background: ${color}; color: white; padding: 3px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 700;">${idrsCategory}</span>
|
||
<!-- Breakdown bars -->
|
||
<div style="margin-top: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 0.74rem;">
|
||
${[['वय (Age)', breakdown.age_score || 0, 30], ['कौटुंबिक इतिहास', breakdown.family_history_score || 0, 20], ['व्यायाम (Activity)', breakdown.physical_activity_score || 0, 30], ['लक्षणे (Symptoms)', breakdown.symptoms_score || 0, 20]].map(([label, val, max]) => `
|
||
<div style="display: flex; align-items: center; gap: 6px;">
|
||
<span style="width: 110px; color: #475569; font-weight: 600;">${label}</span>
|
||
<div style="flex: 1; background: #e2e8f0; border-radius: 999px; height: 6px;">
|
||
<div style="background: ${color}; height: 6px; border-radius: 999px; width: ${Math.min(100, Math.round(val / max * 100))}%; transition: width 1s ease;"></div>
|
||
</div>
|
||
<span style="color: #64748b; font-weight: 700; width: 32px; text-align: right;">${val}/${max}</span>
|
||
</div>`).join('')}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
${medications.length > 0 ? `
|
||
<div style="background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px; padding: 10px 14px; margin-bottom: 12px;">
|
||
<div style="font-size: 0.8rem; font-weight: 800; color: #1e40af; margin-bottom: 4px;">💊 नोंदवलेली औषधे (Medications)</div>
|
||
<div style="font-size: 0.8rem; color: #1e3a8a;">${medications.map(m => `<span style="background: #dbeafe; padding: 2px 8px; border-radius: 999px; margin: 2px; display: inline-block;">${escapeHtml(String(m))}</span>`).join('')}</div>
|
||
</div>` : ''}
|
||
|
||
<!-- Diet Tips -->
|
||
<div style="background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 10px; padding: 10px 14px; margin-bottom: 14px;">
|
||
<div style="font-size: 0.8rem; font-weight: 800; color: #065f46; margin-bottom: 6px;">🥗 आहार व जीवनशैली सल्ला (Diet & Lifestyle Tips)</div>
|
||
${dietTips.map(t => `<div style="font-size: 0.78rem; color: #064e3b; padding: 2px 0; line-height: 1.4;">${escapeHtml(t)}</div>`).join('')}
|
||
</div>
|
||
|
||
<!-- Action Buttons -->
|
||
<div style="display: flex; flex-wrap: wrap; gap: 8px;">
|
||
<button onclick="openDoctorSummaryModal()" style="flex: 1; min-width: 140px; background: linear-gradient(135deg, #0ea5a8, #0284c7); color: white; border: none; padding: 9px 14px; border-radius: 10px; font-size: 0.82rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;">
|
||
📋 पूर्ण अहवाल पहा
|
||
</button>
|
||
<button onclick="openWhatsAppShareModal()" style="flex: 1; min-width: 140px; background: linear-gradient(135deg, #25d366, #128c7e); color: white; border: none; padding: 9px 14px; border-radius: 10px; font-size: 0.82rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;">
|
||
📲 WhatsApp वर पाठवा
|
||
</button>
|
||
<button onclick="window.location.href='/api/admin/consultations/${currentSessionId}/pdf'" style="flex: 1; min-width: 120px; background: #f1f5f9; color: #0f2949; border: 1px solid #e2e8f0; padding: 9px 14px; border-radius: 10px; font-size: 0.82rem; font-weight: 700; cursor: pointer;">
|
||
📄 PDF डाउनलोड
|
||
</button>
|
||
</div>
|
||
`;
|
||
|
||
// Insert card into chat after last bot bubble
|
||
const chatArea = document.getElementById('chat-messages-area');
|
||
if (chatArea) {
|
||
const existingCard = document.getElementById('idrs-completion-card');
|
||
if (existingCard) existingCard.remove();
|
||
chatArea.appendChild(card);
|
||
card.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
|
||
}
|
||
})
|
||
.catch(err => console.warn('IDRS card fetch failed:', err));
|
||
}
|
||
|
||
// ── Reimplemented Medical-Grade WhatsApp Share Suite ─────────────────────
|
||
let currentWhatsAppPreview = null;
|
||
let currentWhatsAppText = '';
|
||
let currentWhatsAppDirectUrl = '';
|
||
let currentWhatsAppPdfUrl = '';
|
||
|
||
async function openWhatsAppShareModal() {
|
||
const modal = document.getElementById('whatsapp-share-modal');
|
||
if (!modal) return;
|
||
modal.classList.add('active');
|
||
|
||
const phoneInput = document.getElementById('wa-phone-input');
|
||
const statusEl = document.getElementById('wa-send-status');
|
||
const previewTextEl = document.getElementById('wa-preview-text');
|
||
const patientChipEl = document.getElementById('wa-patient-chip');
|
||
|
||
if (phoneInput && !phoneInput.value.trim()) {
|
||
phoneInput.value = '+918830578295';
|
||
}
|
||
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '<span style="color:#0284c7;">🔄 वैद्यकीय सारांश तयार करत आहे... (Preparing summary...)</span>';
|
||
}
|
||
|
||
const sid = currentSessionId || '';
|
||
const phone = phoneInput ? phoneInput.value.trim() : '+918830578295';
|
||
|
||
try {
|
||
const res = await fetch(`/api/doctor/summary-preview?session_id=${encodeURIComponent(sid)}&doctor_phone=${encodeURIComponent(phone)}`);
|
||
const data = await res.json();
|
||
if (data.status === 'success' && data.preview) {
|
||
currentWhatsAppPreview = data.preview;
|
||
currentWhatsAppText = data.preview.message_text || '';
|
||
currentWhatsAppDirectUrl = data.preview.whatsapp_url || '';
|
||
currentWhatsAppPdfUrl = data.preview.pdf_url || '';
|
||
|
||
if (previewTextEl) {
|
||
previewTextEl.textContent = currentWhatsAppText;
|
||
}
|
||
if (patientChipEl) {
|
||
const urgency = (data.preview.urgency || 'routine').toUpperCase();
|
||
const urgColor = urgency.includes('EMERG') ? '#ef4444' : (urgency.includes('URGENT') ? '#f59e0b' : '#10b981');
|
||
patientChipEl.innerHTML = `
|
||
<div style="display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px;">
|
||
<div>
|
||
<strong style="color:#0f172a; font-size:0.92rem;">👤 ${data.preview.patient_name || 'रुग्ण'}</strong>
|
||
<span style="color:#64748b; font-size:0.75rem; margin-left:6px;">IDRS: ${data.preview.idrs_score || 'N/A'}/100</span>
|
||
</div>
|
||
<span style="background:${urgColor}; color:#fff; font-size:0.7rem; font-weight:800; padding:2px 8px; border-radius:12px; text-transform:uppercase;">
|
||
${urgency}
|
||
</span>
|
||
</div>
|
||
`;
|
||
}
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '<span style="color:#059669;">✅ सारांश तयार आहे! 1-Click WhatsApp किंवा Twilio Cloud द्वारे पाठवा.</span>';
|
||
}
|
||
} else {
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '<span style="color:#64748b;">माहिती लोड झाली. फोन नंबर तपासा आणि पाठवा.</span>';
|
||
}
|
||
}
|
||
} catch (e) {
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '<span style="color:#94a3b8;">थेट नंबर प्रविष्ट करून पाठवू शकता.</span>';
|
||
}
|
||
}
|
||
}
|
||
|
||
function closeWhatsAppModal() {
|
||
const modal = document.getElementById('whatsapp-share-modal');
|
||
if (modal) modal.classList.remove('active');
|
||
}
|
||
|
||
function toggleWhatsAppPreview() {
|
||
const box = document.getElementById('wa-preview-box');
|
||
const btn = document.getElementById('wa-preview-toggle-btn');
|
||
if (!box) return;
|
||
if (box.style.display === 'none' || !box.style.display) {
|
||
box.style.display = 'block';
|
||
if (btn) btn.textContent = '🔼 सारांश लपवा (Hide Preview)';
|
||
} else {
|
||
box.style.display = 'none';
|
||
if (btn) btn.textContent = '👁️ सारांश पूर्वावलोकन (Preview Message)';
|
||
}
|
||
}
|
||
|
||
function openWhatsAppDirectly() {
|
||
const phoneInput = document.getElementById('wa-phone-input');
|
||
const phone = phoneInput ? phoneInput.value.trim() : '+918830578295';
|
||
const cleanPhone = phone.replace(/[^0-9]/g, '');
|
||
const digits = cleanPhone.length === 10 ? '91' + cleanPhone : cleanPhone;
|
||
|
||
let msg = currentWhatsAppText;
|
||
if (!msg) {
|
||
msg = `🏥 *दीनानाथ मंगेशकर रुग्णालय — Diabetes Dost Pre-Screening Summary*\nSession ID: ${currentSessionId}\nDoctor: ${phone}`;
|
||
}
|
||
|
||
const waUrl = `https://wa.me/${digits}?text=${encodeURIComponent(msg)}`;
|
||
window.open(waUrl, '_blank');
|
||
|
||
const statusEl = document.getElementById('wa-send-status');
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '🚀 <strong style="color:#059669;">WhatsApp विंडो उघडली आहे!</strong> कृपया WhatsApp मध्ये Send बटण दाबा.';
|
||
}
|
||
}
|
||
|
||
async function copyWhatsAppSummary() {
|
||
const statusEl = document.getElementById('wa-send-status');
|
||
if (!currentWhatsAppText) {
|
||
if (statusEl) statusEl.innerHTML = '<span style="color:#dc2626;">कॉपी करण्यासाठी मजकूर उपलब्ध नाही.</span>';
|
||
return;
|
||
}
|
||
try {
|
||
await navigator.clipboard.writeText(currentWhatsAppText);
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '📋 <strong style="color:#059669;">संपूर्ण क्लिनिकल सारांश क्लिपबोर्डवर कॉपी झाला!</strong>';
|
||
}
|
||
} catch (e) {
|
||
const ta = document.createElement('textarea');
|
||
ta.value = currentWhatsAppText;
|
||
document.body.appendChild(ta);
|
||
ta.select();
|
||
document.execCommand('copy');
|
||
document.body.removeChild(ta);
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '📋 <strong style="color:#059669;">संपूर्ण क्लिनिकल सारांश क्लिपबोर्डवर कॉपी झाला!</strong>';
|
||
}
|
||
}
|
||
}
|
||
|
||
function openWhatsAppReportPdf() {
|
||
if (currentWhatsAppPdfUrl) {
|
||
window.open(currentWhatsAppPdfUrl, '_blank');
|
||
} else if (currentSessionId) {
|
||
window.open(`/api/admin/consultations/${currentSessionId}/pdf`, '_blank');
|
||
}
|
||
}
|
||
|
||
async function submitWhatsAppShare() {
|
||
const phoneInput = document.getElementById('wa-phone-input');
|
||
const statusEl = document.getElementById('wa-send-status');
|
||
const phone = (phoneInput ? phoneInput.value : '').trim();
|
||
|
||
if (!phone || phone.length < 10) {
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '<span style="color:#dc2626;">⚠️ कृपया वैध 10-अंकी फोन नंबर प्रविष्ट करा.</span>';
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (statusEl) {
|
||
statusEl.innerHTML = '<span style="color:#0284c7;">📤 Twilio Cloud द्वारे डॉक्टरांना WhatsApp पाठवत आहे...</span>';
|
||
}
|
||
|
||
try {
|
||
const res = await fetch(`/api/doctor/send-summary`, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ session_id: currentSessionId, doctor_phone: phone, include_pdf: true })
|
||
});
|
||
const data = await res.json();
|
||
|
||
if (data.status === 'success') {
|
||
const delivery = data.delivery || {};
|
||
currentWhatsAppDirectUrl = data.whatsapp_url || currentWhatsAppDirectUrl;
|
||
currentWhatsAppText = data.message_text || currentWhatsAppText;
|
||
currentWhatsAppPdfUrl = data.pdf_url || currentWhatsAppPdfUrl;
|
||
|
||
if (delivery.status === 'sent') {
|
||
const sid = delivery.message_sid ? ` (SID: ${delivery.message_sid.slice(0, 10)}...)` : '';
|
||
if (statusEl) {
|
||
statusEl.innerHTML = `<span style="color:#059669; font-weight:700;">✅ Twilio Cloud द्वारे संदेश थेट डॉक्टरांच्या WhatsApp वर पाठवला गेला!${sid}</span>`;
|
||
}
|
||
setTimeout(() => closeWhatsAppModal(), 4000);
|
||
} else {
|
||
// Graceful fallback to 1-Click WhatsApp Direct
|
||
const reason = delivery.twilio_error || 'Twilio Sandbox चाचणी मर्यादा';
|
||
if (statusEl) {
|
||
statusEl.innerHTML = `
|
||
<div style="background:#fef3c7; border:1px solid #fcd34d; border-radius:10px; padding:10px; text-align:left; margin-bottom:6px;">
|
||
<div style="font-weight:700; color:#92400e; font-size:0.8rem; margin-bottom:3px;">
|
||
ℹ️ Twilio Cloud सूचना: ${reason.slice(0, 70)}...
|
||
</div>
|
||
<div style="font-size:0.75rem; color:#78350f;">
|
||
👉 काळजी करू नका! <strong>1-Click WhatsApp</strong> बटनावर क्लिक करून त्वरित डॉक्टरांना पाठवा:
|
||
</div>
|
||
<div style="margin-top:8px;">
|
||
<button onclick="openWhatsAppDirectly()" style="background:#25d366; color:#fff; border:none; padding:8px 14px; border-radius:8px; font-size:0.8rem; font-weight:800; cursor:pointer; display:inline-flex; align-items:center; gap:6px;">
|
||
📲 त्वरित WhatsApp मध्ये उघडा (Open in WhatsApp)
|
||
</button>
|
||
</div>
|
||
</div>
|
||
`;
|
||
}
|
||
}
|
||
} else {
|
||
const errMsg = data.detail || 'पाठवण्यात अडचण आली.';
|
||
if (statusEl) {
|
||
statusEl.innerHTML = `
|
||
<div style="color:#dc2626; font-size:0.8rem; margin-bottom:6px;">❌ ${errMsg}</div>
|
||
<button onclick="openWhatsAppDirectly()" style="background:#25d366; color:#fff; border:none; padding:8px 14px; border-radius:8px; font-size:0.8rem; font-weight:800; cursor:pointer;">
|
||
📲 1-Click WhatsApp ने पाठवा
|
||
</button>
|
||
`;
|
||
}
|
||
}
|
||
} catch (e) {
|
||
if (statusEl) {
|
||
statusEl.innerHTML = `
|
||
<div style="color:#dc2626; font-size:0.8rem; margin-bottom:6px;">❌ नेटवर्क समस्या: ${e.message}</div>
|
||
<button onclick="openWhatsAppDirectly()" style="background:#25d366; color:#fff; border:none; padding:8px 14px; border-radius:8px; font-size:0.8rem; font-weight:800; cursor:pointer;">
|
||
📲 थेट WhatsApp ने पाठवा
|
||
</button>
|
||
`;
|
||
}
|
||
}
|
||
}
|
||
|
||
// ── PDF Download ─────────────────────────────────────────────────────────
|
||
function downloadPDF(sessionId) {
|
||
if (!sessionId) return;
|
||
window.open(`/api/admin/consultations/${sessionId}/pdf`, '_blank');
|
||
}
|
||
|
||
async function openDoctorSummaryModal() {
|
||
if (!currentSessionId) {
|
||
alert('Please start a consultation first.');
|
||
return;
|
||
}
|
||
try {
|
||
const res = await fetch(`/api/sehat/session/${currentSessionId}/summary`);
|
||
const data = await res.json();
|
||
if (data.status === 'success') {
|
||
const s = data.summary;
|
||
currentLoadedSummary = s;
|
||
const p = s.patient || {};
|
||
document.getElementById('modal-summary-title').textContent = `Clinical Summary: ${p.name || 'Patient'} (${p.age ? p.age + ' Yrs' : '—'} / ${p.sex || p.gender || '—'})`;
|
||
|
||
const filePathEl = document.getElementById('modal-summary-filepath');
|
||
if (filePathEl) {
|
||
filePathEl.innerHTML = `💾 <strong>Saved:</strong> <span style="font-family: monospace; color: #0284c7;">${s.summary_file_txt || 'outputs/reports/summaries/'}</span>`;
|
||
}
|
||
|
||
// Populate IDRS banner
|
||
const idrsScore = s.idrs_risk_score || 0;
|
||
const idrsCategory = s.idrs_risk_category || 'Low Risk';
|
||
const idrsScoreEl = document.getElementById('modal-idrs-score-text');
|
||
const idrsBadgeEl = document.getElementById('modal-idrs-badge');
|
||
if (idrsScoreEl) idrsScoreEl.textContent = `${idrsScore}/100`;
|
||
if (idrsBadgeEl) {
|
||
idrsBadgeEl.textContent = idrsCategory;
|
||
idrsBadgeEl.className = 'urgency-badge ' + (
|
||
idrsCategory.toLowerCase().includes('high') ? 'emergency' :
|
||
idrsCategory.toLowerCase().includes('moderate') ? 'urgent' : 'routine'
|
||
);
|
||
}
|
||
|
||
// Summaries (Marathi, Hindi, English)
|
||
const mrEl = document.getElementById('modal-summary-mr');
|
||
if (mrEl) mrEl.textContent = s.clinical_summary_mr || s.summary_narrative || 'मराठी सारांश उपलब्ध नाही.';
|
||
document.getElementById('modal-summary-hi').textContent = s.clinical_summary_hi || s.summary_narrative || 'परामर्श सारांश उपलब्ध आहे.';
|
||
document.getElementById('modal-summary-en').textContent = s.clinical_summary_en || s.summary_narrative || 'Clinical pre-screening notes generated.';
|
||
|
||
const qaDiv = document.getElementById('modal-qa-history');
|
||
qaDiv.innerHTML = (s.qa_transcript || []).map((q, idx) => `
|
||
<div style="background: #f8fafc; padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; border-left: 3px solid #0ea5a8;">
|
||
<div style="color: #0b8082; font-weight:700;">Q${idx + 1}: ${escapeHtml(q.question_asked_hi || q.question || '')}</div>
|
||
<div style="color: #1e293b; margin-top: 2px;">🗣️ ${escapeHtml(q.patient_answer_hi || q.answer || '—')}</div>
|
||
</div>
|
||
`).join('');
|
||
|
||
document.getElementById('doctor-summary-modal').classList.add('active');
|
||
}
|
||
} catch (e) {
|
||
console.error(e);
|
||
}
|
||
}
|
||
|
||
function closeDoctorSummaryModal() {
|
||
document.getElementById('doctor-summary-modal').classList.remove('active');
|
||
}
|
||
|
||
function downloadCurrentSummaryTxt() {
|
||
if (!currentSessionId) return;
|
||
window.location.href = `/api/sehat/session/${currentSessionId}/download`;
|
||
}
|
||
|
||
function downloadCurrentSummaryJson() {
|
||
if (!currentSessionId) return;
|
||
window.location.href = `/api/sehat/session/${currentSessionId}/download/json`;
|
||
}
|
||
|
||
function copyCurrentSummaryToClipboard() {
|
||
if (!currentLoadedSummary) return;
|
||
const text = (currentLoadedSummary.clinical_summary_en || '') + '\n\n' + (currentLoadedSummary.clinical_summary_hi || '');
|
||
navigator.clipboard.writeText(text).then(() => alert('Summary copied to clipboard!'));
|
||
}
|
||
|
||
function switchNav(event, tab) {
|
||
document.querySelectorAll('.sidebar-nav-item').forEach(b => b.classList.remove('active'));
|
||
if (event && event.currentTarget) event.currentTarget.classList.add('active');
|
||
}
|
||
|
||
/* ========================================================
|
||
INLINE ADMIN PORTAL & TAB SWITCHING LOGIC
|
||
======================================================== */
|
||
let inlineAdminToken = localStorage.getItem('diabetes_dost_admin_token') || null;
|
||
let inlineSearchTimer = null;
|
||
let currentMainTab = 'voice';
|
||
|
||
async function authFetchInline(url, options = {}) {
|
||
if (!options.headers) {
|
||
options.headers = {};
|
||
}
|
||
if (inlineAdminToken) {
|
||
if (options.headers instanceof Headers) {
|
||
options.headers.set('Authorization', `Bearer ${inlineAdminToken}`);
|
||
} else {
|
||
options.headers['Authorization'] = `Bearer ${inlineAdminToken}`;
|
||
}
|
||
}
|
||
const res = await fetch(url, options);
|
||
if (res.status === 401) {
|
||
inlineAdminToken = null;
|
||
localStorage.removeItem('diabetes_dost_admin_token');
|
||
setAdminHeaderUI(false);
|
||
openAdminLoginModal();
|
||
throw new Error('Unauthorized');
|
||
}
|
||
return res;
|
||
}
|
||
|
||
async function checkAdminAuthStatus() {
|
||
if (!inlineAdminToken) {
|
||
setAdminHeaderUI(false);
|
||
return;
|
||
}
|
||
try {
|
||
const res = await authFetchInline('/api/admin/check-auth');
|
||
const data = await res.json();
|
||
if (data.status === 'success') {
|
||
setAdminHeaderUI(true, data.user.full_name || data.user.username);
|
||
} else {
|
||
setAdminHeaderUI(false);
|
||
inlineAdminToken = null;
|
||
localStorage.removeItem('diabetes_dost_admin_token');
|
||
}
|
||
} catch (e) {
|
||
setAdminHeaderUI(false);
|
||
}
|
||
}
|
||
|
||
function setAdminHeaderUI(isLoggedIn, name = 'Admin') {
|
||
const loginIcon = document.getElementById('btn-header-login-icon');
|
||
const userDiv = document.getElementById('header-admin-user');
|
||
const nameEl = document.getElementById('header-admin-name');
|
||
|
||
if (isLoggedIn) {
|
||
if (loginIcon) loginIcon.style.display = 'none';
|
||
if (userDiv) userDiv.style.display = 'flex';
|
||
if (nameEl) nameEl.textContent = name;
|
||
} else {
|
||
if (loginIcon) loginIcon.style.display = 'flex';
|
||
if (userDiv) userDiv.style.display = 'none';
|
||
}
|
||
}
|
||
|
||
function toggleMainView() {
|
||
if (currentMainTab === 'voice') {
|
||
switchMainTab('consultations');
|
||
} else {
|
||
switchMainTab('voice');
|
||
}
|
||
}
|
||
|
||
function switchMainTab(tab) {
|
||
currentMainTab = tab;
|
||
const voiceStage = document.getElementById('voice-consultation-stage');
|
||
const adminStage = document.getElementById('admin-consultations-stage');
|
||
const navVoice = document.getElementById('nav-btn-voice');
|
||
const navAdmin = document.getElementById('nav-btn-consultations');
|
||
const toggleIcon = document.getElementById('view-toggle-icon');
|
||
const toggleText = document.getElementById('view-toggle-text');
|
||
|
||
if (tab === 'consultations') {
|
||
if (!inlineAdminToken) {
|
||
openAdminLoginModal();
|
||
return;
|
||
}
|
||
if (voiceStage) voiceStage.style.display = 'none';
|
||
if (adminStage) adminStage.style.display = 'flex';
|
||
|
||
if (toggleIcon) toggleIcon.textContent = '🎙️';
|
||
if (toggleText) toggleText.textContent = 'Voice Screener';
|
||
|
||
if (navVoice) navVoice.classList.remove('active');
|
||
if (navAdmin) navAdmin.classList.add('active');
|
||
|
||
fetchInlineAdminData();
|
||
} else {
|
||
if (voiceStage) voiceStage.style.display = 'flex';
|
||
if (adminStage) adminStage.style.display = 'none';
|
||
|
||
if (toggleIcon) toggleIcon.textContent = '📋';
|
||
if (toggleText) toggleText.textContent = 'Consultations DB';
|
||
|
||
if (navVoice) navVoice.classList.add('active');
|
||
if (navAdmin) navAdmin.classList.remove('active');
|
||
}
|
||
}
|
||
|
||
function openAdminLoginModal() {
|
||
const modal = document.getElementById('admin-login-modal');
|
||
const errorDiv = document.getElementById('inline-login-error');
|
||
if (errorDiv) errorDiv.style.display = 'none';
|
||
if (modal) modal.classList.add('active');
|
||
}
|
||
|
||
function closeAdminLoginModal() {
|
||
const modal = document.getElementById('admin-login-modal');
|
||
if (modal) modal.classList.remove('active');
|
||
}
|
||
|
||
async function handleInlineLoginSubmit(e) {
|
||
e.preventDefault();
|
||
const u = document.getElementById('inline-admin-username').value.trim();
|
||
const p = document.getElementById('inline-admin-password').value;
|
||
const err = document.getElementById('inline-login-error');
|
||
const btn = document.getElementById('btn-inline-login');
|
||
|
||
err.style.display = 'none';
|
||
btn.textContent = 'Verifying...';
|
||
|
||
try {
|
||
const res = await fetch('/api/admin/login', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ username: u, password: p })
|
||
});
|
||
const data = await res.json();
|
||
if (res.ok && data.status === 'success') {
|
||
inlineAdminToken = data.token;
|
||
localStorage.setItem('diabetes_dost_admin_token', inlineAdminToken);
|
||
setAdminHeaderUI(true, data.user.full_name || data.user.username);
|
||
closeAdminLoginModal();
|
||
switchMainTab('consultations');
|
||
} else {
|
||
err.textContent = data.detail || 'Invalid credentials.';
|
||
err.style.display = 'block';
|
||
}
|
||
} catch (e) {
|
||
err.textContent = 'Network or server error during login.';
|
||
err.style.display = 'block';
|
||
} finally {
|
||
btn.textContent = 'Login to Consultations DB 🔐';
|
||
}
|
||
}
|
||
|
||
async function handleMainLogout() {
|
||
if (inlineAdminToken) {
|
||
const formData = new FormData();
|
||
formData.append('token', inlineAdminToken);
|
||
try {
|
||
await fetch('/api/admin/logout', {
|
||
method: 'POST',
|
||
headers: { 'Authorization': `Bearer ${inlineAdminToken}` },
|
||
body: formData
|
||
});
|
||
} catch (e) { }
|
||
}
|
||
inlineAdminToken = null;
|
||
localStorage.removeItem('diabetes_dost_admin_token');
|
||
setAdminHeaderUI(false);
|
||
switchMainTab('voice');
|
||
}
|
||
|
||
async function fetchInlineAdminData() {
|
||
await Promise.all([
|
||
fetchInlineMetrics(),
|
||
fetchInlineConsultations()
|
||
]);
|
||
}
|
||
|
||
async function fetchInlineMetrics() {
|
||
try {
|
||
const res = await authFetchInline('/api/admin/metrics');
|
||
const data = await res.json();
|
||
if (data.status === 'success') {
|
||
const m = data.metrics;
|
||
document.getElementById('inline-stat-total').textContent = m.total_consultations;
|
||
document.getElementById('inline-stat-emergencies').textContent = m.emergency_cases;
|
||
document.getElementById('inline-stat-routine').textContent = m.routine_reviews;
|
||
document.getElementById('inline-stat-patients').textContent = m.total_patients;
|
||
}
|
||
} catch (e) { }
|
||
}
|
||
|
||
function debounceInlineSearch() {
|
||
clearTimeout(inlineSearchTimer);
|
||
inlineSearchTimer = setTimeout(() => {
|
||
fetchInlineConsultations();
|
||
}, 250);
|
||
}
|
||
|
||
async function fetchInlineConsultations() {
|
||
const search = document.getElementById('inline-search-input').value.trim();
|
||
const urgency = document.getElementById('inline-urgency-select').value;
|
||
const tbody = document.getElementById('inline-consultations-tbody');
|
||
|
||
let url = `/api/admin/consultations?limit=50`;
|
||
if (search) url += `&search=${encodeURIComponent(search)}`;
|
||
if (urgency && urgency !== 'all') url += `&urgency=${encodeURIComponent(urgency)}`;
|
||
|
||
try {
|
||
const res = await authFetchInline(url);
|
||
const data = await res.json();
|
||
if (data.status === 'success') {
|
||
const list = data.data.consultations || [];
|
||
document.getElementById('inline-table-count').textContent = `Showing ${list.length} of ${data.data.total} records`;
|
||
|
||
if (list.length === 0) {
|
||
tbody.innerHTML = `
|
||
<tr>
|
||
<td colspan="6" style="text-align: center; padding: 32px; color: var(--text-muted);">
|
||
No consultations found matching your filters.
|
||
</td>
|
||
</tr>
|
||
`;
|
||
return;
|
||
}
|
||
|
||
tbody.innerHTML = list.map(c => {
|
||
const dateStr = c.created_at ? new Date(c.created_at).toLocaleString([], {
|
||
day: '2-digit', month: 'short', year: 'numeric',
|
||
hour: '2-digit', minute: '2-digit'
|
||
}) : '—';
|
||
|
||
const patientName = c.patient_name || 'Patient';
|
||
const ageGender = (c.age ? `${c.age}Y` : '') + (c.gender ? ` • ${c.gender}` : '');
|
||
const initial = patientName.charAt(0).toUpperCase();
|
||
const urg = (c.recommended_urgency || 'routine').toLowerCase();
|
||
|
||
return `
|
||
<tr>
|
||
<td style="font-weight: 600; color: #475569; white-space: nowrap;">${dateStr}</td>
|
||
<td>
|
||
<div style="display: flex; align-items: center; gap: 8px;">
|
||
<div style="width: 30px; height: 30px; border-radius: 50%; background: #e0f2fe; color: #0369a1; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.78rem;">${initial}</div>
|
||
<div>
|
||
<div style="font-weight: 700; color: var(--blue-navy);">${escapeHtml(patientName)}</div>
|
||
<div style="font-size: 0.72rem; color: var(--text-muted);">${ageGender} ${c.patient_id ? '• ' + escapeHtml(c.patient_id) : ''}</div>
|
||
</div>
|
||
</div>
|
||
</td>
|
||
<td>
|
||
<span style="font-weight: 700; color: #0284c7;">${escapeHtml(c.diabetes_type || 'Type 2')}</span>
|
||
</td>
|
||
<td>
|
||
<span style="font-size: 0.78rem; background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-weight: 600;">
|
||
${escapeHtml(c.branch || 'common')}
|
||
</span>
|
||
</td>
|
||
<td>
|
||
<span class="urgency-badge ${urg}">
|
||
${urg === 'emergency' ? '🚨 Emergency' : (urg === 'urgent' ? '⚠️ Urgent' : '✅ Routine')}
|
||
</span>
|
||
</td>
|
||
<td>
|
||
<button class="btn-action-view" onclick="viewInlineConsultationDetail('${c.session_id}')">
|
||
<span>👁️</span> View
|
||
</button>
|
||
<button class="btn-action-del" onclick="deleteInlineConsultationRecord('${c.session_id}')" title="Delete">
|
||
🗑️
|
||
</button>
|
||
</td>
|
||
</tr>
|
||
`;
|
||
}).join('');
|
||
}
|
||
} catch (e) {
|
||
tbody.innerHTML = `
|
||
<tr>
|
||
<td colspan="6" style="text-align: center; padding: 28px; color: #dc2626;">
|
||
Failed to load records from SQLite database.
|
||
</td>
|
||
</tr>
|
||
`;
|
||
}
|
||
}
|
||
|
||
async function viewInlineConsultationDetail(sessionId) {
|
||
currentSessionId = sessionId;
|
||
try {
|
||
const res = await authFetchInline(`/api/admin/consultations/${sessionId}`);
|
||
const data = await res.json();
|
||
if (data.status === 'success') {
|
||
const c = data.consultation;
|
||
currentLoadedSummary = c;
|
||
const p = c.patient_name || 'Patient';
|
||
document.getElementById('modal-summary-title').textContent = `Clinical Summary: ${p} (${c.age || '—'}Y / ${c.gender || '—'})`;
|
||
|
||
const filePathEl = document.getElementById('modal-summary-filepath');
|
||
if (filePathEl) {
|
||
filePathEl.innerHTML = `💾 <strong>Session ID:</strong> <span style="font-family: monospace; color: #0284c7;">${c.session_id}</span>`;
|
||
}
|
||
|
||
document.getElementById('modal-summary-hi').textContent = c.summary_hi || 'परामर्श सारांश उपलब्ध आहे.';
|
||
document.getElementById('modal-summary-en').textContent = c.summary_en || 'Clinical pre-screening notes generated.';
|
||
|
||
const qaDiv = document.getElementById('modal-qa-history');
|
||
if (c.qa_transcript && c.qa_transcript.length > 0) {
|
||
qaDiv.innerHTML = c.qa_transcript.map((q, idx) => `
|
||
<div style="background: #f8fafc; padding: 8px 12px; border-radius: 8px; margin-bottom: 8px; border-left: 3px solid #0ea5a8;">
|
||
<div style="color: #0b8082; font-weight:700;">Q${idx + 1}: ${escapeHtml(q.question_asked_hi || q.question || '')}</div>
|
||
<div style="color: #1e293b; margin-top: 2px;">🗣️ ${escapeHtml(q.patient_answer_hi || q.answer || '—')}</div>
|
||
</div>
|
||
`).join('');
|
||
} else {
|
||
qaDiv.innerHTML = '<p style="color: var(--text-muted); font-size: 0.82rem;">No Q&A recorded.</p>';
|
||
}
|
||
|
||
document.getElementById('doctor-summary-modal').classList.add('active');
|
||
}
|
||
} catch (e) {
|
||
alert('Failed to load consultation details.');
|
||
}
|
||
}
|
||
|
||
async function deleteInlineConsultationRecord(sessionId) {
|
||
if (!confirm(`Are you sure you want to delete consultation record ${sessionId}?`)) return;
|
||
try {
|
||
const res = await authFetchInline(`/api/admin/consultations/${sessionId}`, { method: 'DELETE' });
|
||
if (res.ok) {
|
||
fetchInlineAdminData();
|
||
} else {
|
||
alert('Failed to delete consultation.');
|
||
}
|
||
} catch (e) {
|
||
alert('Network error deleting record.');
|
||
}
|
||
}
|
||
|
||
window.addEventListener('DOMContentLoaded', () => {
|
||
checkAdminAuthStatus();
|
||
if ('speechSynthesis' in window) setupVoices();
|
||
});
|
||
</script>
|
||
|
||
<!-- ==============================================
|
||
REIMPLEMENTED WHATSAPP SHARE MODAL (DOCTOR HANDOVER)
|
||
============================================== -->
|
||
<div id="whatsapp-share-modal" class="modal-overlay"
|
||
onclick="if(event.target.id==='whatsapp-share-modal') closeWhatsAppModal()">
|
||
<div
|
||
style="background:#fff; border-radius:20px; padding:26px 24px; max-width:520px; width:92%; box-shadow:0 25px 70px rgba(0,0,0,0.22); border:1px solid #e2e8f0; max-height:92vh; overflow-y:auto; text-align:left; font-family:'Inter',sans-serif;">
|
||
|
||
<!-- Hospital & Title Header -->
|
||
<div style="display:flex; align-items:center; gap:12px; margin-bottom:14px; border-bottom:1px solid #f1f5f9; padding-bottom:12px;">
|
||
<div
|
||
style="width:50px; height:50px; background:linear-gradient(135deg,#25d366,#128c7e); border-radius:14px; display:flex; align-items:center; justify-content:center; font-size:1.6rem; color:#fff; box-shadow:0 6px 18px rgba(37,211,102,0.35); flex-shrink:0;">
|
||
📲
|
||
</div>
|
||
<div>
|
||
<div style="font-size:0.68rem; font-weight:800; color:#0b8082; text-transform:uppercase; letter-spacing:0.5px;">
|
||
🏥 KEM Hospital
|
||
</div>
|
||
<h3 style="font-family:'Outfit',sans-serif; font-size:1.18rem; font-weight:800; color:#0f172a; margin:2px 0 0 0;">
|
||
डॉक्टरांना WhatsApp सारांश पाठवा
|
||
</h3>
|
||
</div>
|
||
<button onclick="closeWhatsAppModal()" style="margin-left:auto; background:transparent; border:none; color:#94a3b8; font-size:1.4rem; cursor:pointer; padding:4px;">
|
||
✕
|
||
</button>
|
||
</div>
|
||
|
||
<!-- Patient Vitals Chip -->
|
||
<div id="wa-patient-chip" style="background:#f8fafc; border:1px solid #e2e8f0; border-radius:12px; padding:10px 14px; margin-bottom:14px;">
|
||
<div style="display:flex; justify-content:space-between; align-items:center;">
|
||
<span style="font-weight:700; color:#334155; font-size:0.85rem;">👤 रुग्ण पूर्व-तपासणी माहिती लोड होत आहे...</span>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Doctor Phone Input -->
|
||
<div style="margin-bottom:14px;">
|
||
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:5px;">
|
||
<label style="font-size:0.75rem; font-weight:700; color:#1e293b; text-transform:uppercase;">
|
||
📞 डॉक्टरांचा WhatsApp नंबर (Physician Number)
|
||
</label>
|
||
<span style="font-size:0.72rem; color:#0ea5a8; font-weight:600; cursor:pointer;" onclick="document.getElementById('wa-phone-input').value='+918830578295'">
|
||
+918830578295 (Default)
|
||
</span>
|
||
</div>
|
||
<input type="tel" id="wa-phone-input" placeholder="+918830578295 किंवा 9876543210"
|
||
value="+918830578295"
|
||
style="width:100%; padding:10px 14px; border:1.5px solid #cbd5e1; border-radius:10px; font-size:0.92rem; outline:none; font-family:'Inter',sans-serif; font-weight:600; color:#0f172a;"
|
||
onfocus="this.style.borderColor='#25d366'">
|
||
<div style="font-size:0.7rem; color:#64748b; margin-top:4px;">
|
||
✓ भारत (+91) आपोआप फॉरमॅट केला जाईल. 1-Click WhatsApp द्वारे कोणत्याही नंबरवर त्वरित संदेश पाठवता येतो.
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Preview Accordion -->
|
||
<div style="margin-bottom:14px;">
|
||
<button id="wa-preview-toggle-btn" type="button" onclick="toggleWhatsAppPreview()"
|
||
style="background:#f1f5f9; border:1px solid #e2e8f0; color:#334155; font-size:0.78rem; font-weight:700; padding:6px 12px; border-radius:8px; cursor:pointer; width:100%; text-align:left; display:flex; justify-content:space-between; align-items:center;">
|
||
<span>👁️ संपूर्ण क्लिनिकल सारांश पूर्वावलोकन (Preview Message)</span>
|
||
<span style="font-size:0.7rem;">▼</span>
|
||
</button>
|
||
<div id="wa-preview-box" style="display:none; margin-top:8px; background:#0f172a; color:#f8fafc; padding:14px; border-radius:12px; font-family:'Courier New', monospace; font-size:0.76rem; max-height:160px; overflow-y:auto; white-space:pre-wrap; line-height:1.45; border:1px solid #334155;">
|
||
<div id="wa-preview-text">लोड होत आहे...</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Status Feedback Area -->
|
||
<div id="wa-send-status" style="min-height:24px; font-size:0.82rem; font-weight:600; margin-bottom:14px; line-height:1.4;"></div>
|
||
|
||
<!-- Primary Action Buttons -->
|
||
<div style="display:flex; flex-direction:column; gap:8px;">
|
||
<!-- 1-Click WhatsApp Direct (Guaranteed Success) -->
|
||
<button type="button" onclick="openWhatsAppDirectly()"
|
||
style="background:linear-gradient(135deg,#25d366 0%,#128c7e 100%); color:#ffffff; border:none; padding:12px 18px; border-radius:12px; font-size:0.92rem; font-weight:800; cursor:pointer; box-shadow:0 6px 18px rgba(37,211,102,0.35); display:flex; align-items:center; justify-content:center; gap:8px;">
|
||
<span>📲</span> 1-Click WhatsApp वर उघडा (Instant Send)
|
||
</button>
|
||
|
||
<div style="display:flex; gap:8px;">
|
||
<!-- Twilio Cloud Auto-Dispatch -->
|
||
<button type="button" onclick="submitWhatsAppShare()"
|
||
style="flex:1; background:linear-gradient(135deg,#0284c7 0%,#0369a1 100%); color:#ffffff; border:none; padding:10px 14px; border-radius:10px; font-size:0.82rem; font-weight:700; cursor:pointer; box-shadow:0 4px 12px rgba(2,132,199,0.25); display:flex; align-items:center; justify-content:center; gap:6px;">
|
||
<span>☁️</span> Twilio द्वारे पाठवा
|
||
</button>
|
||
|
||
<!-- Copy to Clipboard -->
|
||
<button type="button" onclick="copyWhatsAppSummary()"
|
||
style="background:#f8fafc; border:1px solid #cbd5e1; color:#1e293b; padding:10px 14px; border-radius:10px; font-size:0.82rem; font-weight:700; cursor:pointer; display:flex; align-items:center; gap:6px;">
|
||
<span>📋</span> कॉपी करा
|
||
</button>
|
||
|
||
<!-- View PDF Report -->
|
||
<button type="button" onclick="openWhatsAppReportPdf()"
|
||
style="background:#f8fafc; border:1px solid #cbd5e1; color:#0284c7; padding:10px 14px; border-radius:10px; font-size:0.82rem; font-weight:700; cursor:pointer; display:flex; align-items:center; gap:6px;" title="View PDF">
|
||
<span>📄</span> PDF
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<div style="text-align:center; margin-top:12px;">
|
||
<button type="button" onclick="closeWhatsAppModal()"
|
||
style="background:transparent; border:none; color:#64748b; font-size:0.78rem; font-weight:600; cursor:pointer;">
|
||
बंद करा (Close)
|
||
</button>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ==========================================
|
||
ADMIN LOGIN POPUP MODAL
|
||
========================================== -->
|
||
<div id="admin-login-modal" class="modal-overlay"
|
||
onclick="if(event.target.id === 'admin-login-modal') closeAdminLoginModal()">
|
||
<div
|
||
style="background: #ffffff; border-radius: 16px; padding: 28px 24px; max-width: 400px; width: 100%; box-shadow: var(--shadow-lg); text-align: center; border: 1px solid var(--card-border);">
|
||
<img src="/static/kem_hospital_logo.png?v=kem" alt="KEM Hospital"
|
||
style="width: 58px; height: 58px; border-radius: 14px; object-fit: contain; margin: 0 auto 12px auto; display: block; box-shadow: 0 4px 12px rgba(14, 165, 168, 0.25); border: 1px solid rgba(14, 165, 168, 0.2); background: #ffffff; padding: 3px;">
|
||
<h3 style="font-family: 'Outfit', sans-serif; font-size: 1.25rem; font-weight: 800; color: var(--blue-navy);">
|
||
KEM Hospital Admin
|
||
</h3>
|
||
<p style="font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; margin-bottom: 18px;">
|
||
Sign in to view all patient consultations & SQLite records
|
||
</p>
|
||
|
||
<div id="inline-login-error"
|
||
style="background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; padding: 8px 12px; border-radius: 8px; font-size: 0.8rem; margin-bottom: 12px; display: none;">
|
||
</div>
|
||
|
||
<form onsubmit="handleInlineLoginSubmit(event)">
|
||
<div style="text-align: left; margin-bottom: 12px;">
|
||
<label
|
||
style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--navy-800); margin-bottom: 4px; text-transform: uppercase;">Username</label>
|
||
<input type="text" id="inline-admin-username"
|
||
style="width: 100%; padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 0.85rem; outline: none;"
|
||
placeholder="Enter Username" required autocomplete="username">
|
||
</div>
|
||
|
||
<div style="text-align: left; margin-bottom: 16px;">
|
||
<label
|
||
style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--navy-800); margin-bottom: 4px; text-transform: uppercase;">Password</label>
|
||
<input type="password" id="inline-admin-password"
|
||
style="width: 100%; padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 0.85rem; outline: none;"
|
||
placeholder="••••••••" required autocomplete="current-password">
|
||
</div>
|
||
|
||
<button type="submit" id="btn-inline-login"
|
||
style="width: 100%; background: linear-gradient(135deg, #0ea5a8 0%, #0284c7 100%); color: white; border: none; padding: 10px; border-radius: 8px; font-size: 0.88rem; font-weight: 800; cursor: pointer; box-shadow: 0 4px 12px rgba(14, 165, 168, 0.25);">
|
||
Login to Consultations DB 🔐
|
||
</button>
|
||
|
||
|
||
<button type="button" onclick="closeAdminLoginModal()"
|
||
style="margin-top: 10px; background: transparent; border: none; color: #64748b; font-size: 0.78rem; font-weight: 600; cursor: pointer;">
|
||
Cancel
|
||
</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</body>
|
||
|
||
</html> |