Initial commit: Doctor-Patient clinical transcription and structured summary pipeline
This commit is contained in:
@@ -0,0 +1,341 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>AI Clinical Assistant — Doctor-Patient Consultation</title>
|
||||
<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=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Noto+Sans+Devanagari:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="layout-container">
|
||||
|
||||
<!-- SIDEBAR NAVIGATION -->
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-brand">
|
||||
<div class="brand-icon-box">
|
||||
<svg class="brand-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7Z"/>
|
||||
<path d="M12 5v14M5 12h14" stroke="#ffffff" stroke-width="1.5" stroke-linecap="round"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="brand-text">
|
||||
<h1 class="brand-title">AI Clinical Assistant</h1>
|
||||
<span class="brand-subtitle">Doctor-Patient Conversation</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav">
|
||||
<a href="#dashboard" class="nav-item" data-tab="dashboard">
|
||||
<span class="nav-icon">📊</span>
|
||||
<span class="nav-label">Dashboard</span>
|
||||
</a>
|
||||
<a href="#new-consultation" class="nav-item active" data-tab="new-consultation">
|
||||
<span class="nav-icon">🎙️</span>
|
||||
<span class="nav-label">New Consultation</span>
|
||||
</a>
|
||||
<a href="#past-recordings" class="nav-item" data-tab="past-recordings">
|
||||
<span class="nav-icon">📁</span>
|
||||
<span class="nav-label">Past Recordings</span>
|
||||
</a>
|
||||
<a href="#patients" class="nav-item" data-tab="patients">
|
||||
<span class="nav-icon">👥</span>
|
||||
<span class="nav-label">Patients</span>
|
||||
</a>
|
||||
<a href="#doctors" class="nav-item" data-tab="doctors">
|
||||
<span class="nav-icon">🩺</span>
|
||||
<span class="nav-label">Doctors</span>
|
||||
</a>
|
||||
<a href="#transcripts" class="nav-item" data-tab="transcripts">
|
||||
<span class="nav-icon">📄</span>
|
||||
<span class="nav-label">Transcripts</span>
|
||||
</a>
|
||||
<a href="#clinical-summaries" class="nav-item" data-tab="clinical-summaries">
|
||||
<span class="nav-icon">📋</span>
|
||||
<span class="nav-label">Clinical Summaries</span>
|
||||
</a>
|
||||
<a href="#settings" class="nav-item" data-tab="settings">
|
||||
<span class="nav-icon">⚙️</span>
|
||||
<span class="nav-label">Settings</span>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<div class="sidebar-footer">
|
||||
<div class="system-status-card">
|
||||
<div class="status-indicator-row">
|
||||
<span class="status-pulse-dot"></span>
|
||||
<span class="status-title">System Online</span>
|
||||
</div>
|
||||
<div class="status-meta">Sarvam AI Cloud (v3 STT)</div>
|
||||
<div class="status-tag">Online Mode • Ready</div>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- MAIN APP WRAPPER -->
|
||||
<div class="main-wrapper">
|
||||
<header class="top-header">
|
||||
<div class="header-left">
|
||||
<button class="menu-toggle-btn" id="menuToggle" aria-label="Toggle Navigation">
|
||||
<svg viewBox="0 0 24 24" width="20" height="20" stroke="currentColor" stroke-width="2.2" fill="none">
|
||||
<line x1="3" y1="12" x2="21" y2="12"></line>
|
||||
<line x1="3" y1="6" x2="21" y2="6"></line>
|
||||
<line x1="3" y1="18" x2="21" y2="18"></line>
|
||||
</svg>
|
||||
</button>
|
||||
<h2 class="page-title" id="pageHeading">New Consultation</h2>
|
||||
</div>
|
||||
|
||||
<div class="header-right">
|
||||
<div class="lang-selector-wrapper">
|
||||
<span class="lang-globe-icon">🌐</span>
|
||||
<select id="langSelect" class="lang-dropdown">
|
||||
<option value="auto" selected>Auto (मराठी / Hindi / English)</option>
|
||||
<option value="mr-IN">मराठी (mr-IN)</option>
|
||||
<option value="hi-IN">हिंदी (hi-IN)</option>
|
||||
<option value="en-IN">English (en-IN)</option>
|
||||
</select>
|
||||
<span class="dropdown-arrow">▾</span>
|
||||
</div>
|
||||
|
||||
<button class="notif-btn" id="notifBtn" title="Notifications">
|
||||
<span class="notif-icon">🔔</span>
|
||||
<span class="notif-badge">3</span>
|
||||
</button>
|
||||
|
||||
<div class="doctor-profile-card">
|
||||
<img class="doctor-avatar" src="https://images.unsplash.com/photo-1622253692010-333f2da6031d?w=100&auto=format&fit=crop&q=80" alt="Dr. Sharma">
|
||||
<div class="doctor-meta">
|
||||
<span class="doctor-name">Dr. Sharma</span>
|
||||
<span class="doctor-spec">Cardiologist</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="content-area">
|
||||
<section class="tab-view active" id="view-new-consultation">
|
||||
<!-- CARD 1: CONSULTATION DETAILS -->
|
||||
<div class="card details-card">
|
||||
<div class="card-header-row">
|
||||
<div class="card-title-group">
|
||||
<span class="card-header-icon">📋</span>
|
||||
<h3 class="card-title">Consultation Details</h3>
|
||||
</div>
|
||||
<button class="btn-link-action" id="openAddPatientBtn">
|
||||
<span>+ Add New Patient</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="details-form-grid">
|
||||
<div class="form-group">
|
||||
<label for="patientName" class="form-label">Patient Name</label>
|
||||
<div class="input-icon-box">
|
||||
<span class="input-icon">👤</span>
|
||||
<input type="text" id="patientName" placeholder="Select or type patient name..." value="Ramesh Patil" autocomplete="off">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="patientId" class="form-label">Patient ID</label>
|
||||
<div class="input-icon-box">
|
||||
<span class="input-icon">🪪</span>
|
||||
<input type="text" id="patientId" value="PT-2026-00124" readonly>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="doctorName" class="form-label">Doctor Name</label>
|
||||
<div class="input-icon-box select-box">
|
||||
<span class="input-icon">🩺</span>
|
||||
<select id="doctorName">
|
||||
<option value="Dr. Sharma" selected>Dr. Sharma</option>
|
||||
<option value="Dr. Kulkarni">Dr. Kulkarni</option>
|
||||
<option value="Dr. Joshi">Dr. Joshi</option>
|
||||
</select>
|
||||
<span class="select-chevron">▾</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="consultationDate" class="form-label">Date</label>
|
||||
<div class="input-icon-box">
|
||||
<span class="input-icon">📅</span>
|
||||
<input type="text" id="consultationDate" value="09-09-2026">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CARD 2: LIVE RECORDING & CONTROLS -->
|
||||
<div class="card recording-card">
|
||||
<div class="rec-status-line">
|
||||
<span class="rec-pulse-bubble" id="recPulse"></span>
|
||||
<div class="timer-display" id="timer">00:00:00</div>
|
||||
</div>
|
||||
|
||||
<div class="rec-substatus" id="recSubStatus">
|
||||
<span class="mic-glyph">🎙️</span>
|
||||
<span id="recStatusText">Ready to record consultation...</span>
|
||||
</div>
|
||||
|
||||
<div class="visualizer-container" id="visualizerContainer">
|
||||
<canvas id="waveformCanvas" width="560" height="42"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="rec-error-banner" id="recError" style="display:none;"></div>
|
||||
|
||||
<div class="action-buttons-row">
|
||||
<button class="btn btn-record" id="startBtn">
|
||||
<span class="btn-icon">▶</span>
|
||||
<span class="btn-text">START RECORDING</span>
|
||||
</button>
|
||||
|
||||
<button class="btn btn-stop" id="stopBtn" disabled>
|
||||
<span class="btn-icon">⏹</span>
|
||||
<span class="btn-text">STOP & AUTO-SUMMARIZE</span>
|
||||
</button>
|
||||
|
||||
<button class="btn btn-upload" id="uploadAudioBtn">
|
||||
<span class="btn-icon">📁</span>
|
||||
<span class="btn-text">UPLOAD AUDIO</span>
|
||||
</button>
|
||||
<input type="file" id="audioFileInput" accept="audio/*,.wav,.mp3,.m4a,.ogg,.webm" style="display:none;">
|
||||
|
||||
<button class="btn btn-demo" id="demoBtn">
|
||||
<span class="btn-icon">⚡</span>
|
||||
<span class="btn-text">DEMO</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CARD 3: TRANSCRIPT (FULL & REAL-TIME AUDIO SYNCHRONIZED) -->
|
||||
<div class="card transcript-card">
|
||||
<div class="card-header-row">
|
||||
<div class="card-title-group">
|
||||
<h3 class="card-title-section">TRANSCRIPT</h3>
|
||||
<span class="live-realtime-badge" id="liveRealtimeBadge" style="display:none;">
|
||||
<span class="live-blink-dot"></span> LIVE SYNC
|
||||
</span>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<div class="transcript-search-box">
|
||||
<span class="search-icon">🔍</span>
|
||||
<input type="text" id="transcriptSearch" placeholder="Search dialogue..." autocomplete="off">
|
||||
</div>
|
||||
<button class="btn-sm-action" id="copyTranscriptBtn">
|
||||
<span class="sm-icon">📋</span> Copy
|
||||
</button>
|
||||
<button class="btn-sm-action" id="clearTranscriptBtn">
|
||||
<span class="sm-icon">↺</span> Reset
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="audio-playback-bar" id="audioPlaybackBar" style="display:none;">
|
||||
<button class="btn-play-pause" id="playAudioBtn" title="Play / Pause Audio">
|
||||
<span id="playIcon">▶</span>
|
||||
</button>
|
||||
<div class="audio-progress-container">
|
||||
<input type="range" class="audio-scrubber" id="audioScrubber" min="0" max="100" value="0" step="0.1">
|
||||
<div class="audio-time-row">
|
||||
<span id="audioCurrentTime">00:00</span>
|
||||
<span class="sync-hint">💡 Click any dialogue line to jump audio</span>
|
||||
<span id="audioTotalDuration">00:00</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="transcript-filter-bar">
|
||||
<button class="filter-pill active" data-filter="all">All Dialogue</button>
|
||||
<button class="filter-pill" data-filter="doctor">🧑⚕️ Doctor</button>
|
||||
<button class="filter-pill" data-filter="patient">🧑 Patient</button>
|
||||
</div>
|
||||
|
||||
<div class="transcript-viewport" id="transcriptBody">
|
||||
<div class="transcript-placeholder" id="transcriptPlaceholder">
|
||||
<div class="placeholder-icon">🎙️</div>
|
||||
<p>Recording in progress… Transcript will appear here in real time.</p>
|
||||
<span class="placeholder-sub">Speak into the microphone or click DEMO to see full real-time audio synchronization.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CARD 4: AI CLINICAL SUMMARY -->
|
||||
<div class="card summary-card" id="summaryCard">
|
||||
<div class="card-header-row">
|
||||
<div class="card-title-group">
|
||||
<span class="card-header-icon">📋</span>
|
||||
<h3 class="card-title-section">AI CLINICAL SUMMARY</h3>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button class="btn-sm-action" id="copySummaryBtn">
|
||||
<span class="sm-icon">📋</span> Copy Summary
|
||||
</button>
|
||||
<button class="btn-sm-action" id="printSummaryBtn">
|
||||
<span class="sm-icon">🖨️</span> Print / PDF
|
||||
</button>
|
||||
<button class="btn-sm-action" id="exportJsonBtn">
|
||||
<span class="sm-icon">📥</span> Export JSON
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="summary-content-grid" id="summaryBody">
|
||||
<div class="summary-col-card">
|
||||
<div class="col-card-header">Chief Complaint</div>
|
||||
<div class="col-card-body" id="sumChiefComplaint"><p class="empty-field">—</p></div>
|
||||
</div>
|
||||
|
||||
<div class="summary-col-card">
|
||||
<div class="col-card-header">Symptoms Discussed</div>
|
||||
<div class="col-card-body" id="sumSymptoms"><p class="empty-field">—</p></div>
|
||||
</div>
|
||||
|
||||
<div class="summary-col-card">
|
||||
<div class="col-card-header">Doctor's Recommendation / Diagnosis</div>
|
||||
<div class="col-card-body" id="sumAssessment"><p class="empty-field">—</p></div>
|
||||
</div>
|
||||
|
||||
<div class="summary-col-card full-span">
|
||||
<div class="col-card-header">Patient History & Comorbidities</div>
|
||||
<div class="col-card-body" id="sumHistory"><p class="empty-field">—</p></div>
|
||||
</div>
|
||||
|
||||
<div class="summary-col-card full-span highlight-plan">
|
||||
<div class="col-card-header">Prescription, Tests & Treatment Plan (Rx)</div>
|
||||
<div class="col-card-body" id="sumPlan"><p class="empty-field">—</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-overlay" id="patientModal">
|
||||
<div class="modal-card">
|
||||
<div class="modal-header">
|
||||
<h3>Add New Patient</h3>
|
||||
<button class="modal-close-btn" id="closePatientModal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group mb-3">
|
||||
<label class="form-label">Full Name</label>
|
||||
<input type="text" id="newPatientName" placeholder="e.g. Ramesh Patil">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn-cancel" id="cancelPatientModal">Cancel</button>
|
||||
<button class="btn-save-patient" id="savePatientBtn">Save Patient</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toast-notification" id="toastBox">Notification</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,367 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
// ── Config ─────────────────────────────────────────────────────────────────
|
||||
// Point this to wherever your FastAPI backend is running
|
||||
const BACKEND = 'http://127.0.0.1:8080';
|
||||
|
||||
// ── DOM refs (matching existing HTML IDs exactly) ──────────────────────────
|
||||
const startBtn = document.getElementById('startBtn');
|
||||
const stopBtn = document.getElementById('stopBtn');
|
||||
const timerEl = document.getElementById('timer');
|
||||
const liveBadge = document.getElementById('liveBadge');
|
||||
const serverStatus = document.getElementById('serverStatus');
|
||||
const recError = document.getElementById('recError');
|
||||
const transcriptBody = document.getElementById('transcriptBody');
|
||||
const summaryBtn = document.getElementById('summaryBtn');
|
||||
const clearBtn = document.getElementById('clearBtn');
|
||||
const summaryCard = document.getElementById('summaryCard');
|
||||
const summaryBody = document.getElementById('summaryBody');
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
let mediaRecorder = null;
|
||||
let recordedChunks = [];
|
||||
let timerInterval = null;
|
||||
let secondsElapsed = 0;
|
||||
let lastTranscript = '';
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────────────
|
||||
function fmtTime(s) {
|
||||
const h = String(Math.floor(s / 3600)).padStart(2, '0');
|
||||
const m = String(Math.floor((s % 3600) / 60)).padStart(2, '0');
|
||||
const sec = String(s % 60).padStart(2, '0');
|
||||
return `${h}:${m}:${sec}`;
|
||||
}
|
||||
|
||||
function escHtml(str) {
|
||||
const d = document.createElement('div');
|
||||
d.innerText = str;
|
||||
return d.innerHTML;
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
recError.textContent = msg;
|
||||
recError.style.display = 'block';
|
||||
}
|
||||
|
||||
function clearError() {
|
||||
recError.textContent = '';
|
||||
recError.style.display = 'none';
|
||||
}
|
||||
|
||||
function setStatus(msg, type = '') {
|
||||
serverStatus.textContent = msg;
|
||||
serverStatus.className = 'status-text' + (type ? ` ${type}` : '');
|
||||
}
|
||||
|
||||
// ── Health check on load ───────────────────────────────────────────────────
|
||||
async function checkHealth() {
|
||||
try {
|
||||
const res = await fetch(`${BACKEND}/api/health`);
|
||||
const data = await res.json();
|
||||
if (data.sarvam_key_configured) {
|
||||
setStatus('✔ Backend ready — Sarvam API key configured', 'ok');
|
||||
} else {
|
||||
setStatus('✘ Backend running but SARVAM_API_KEY is not set', 'bad');
|
||||
startBtn.disabled = true;
|
||||
}
|
||||
} catch {
|
||||
setStatus('✘ Cannot reach backend at ' + BACKEND, 'bad');
|
||||
startBtn.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Choose best supported MIME type ───────────────────────────────────────
|
||||
function getSupportedMimeType() {
|
||||
const types = [
|
||||
'audio/webm;codecs=opus',
|
||||
'audio/webm',
|
||||
'audio/ogg;codecs=opus',
|
||||
'audio/ogg',
|
||||
'audio/mp4',
|
||||
];
|
||||
return types.find(t => MediaRecorder.isTypeSupported(t)) || '';
|
||||
}
|
||||
|
||||
// ── Start recording ────────────────────────────────────────────────────────
|
||||
async function startRecording() {
|
||||
clearError();
|
||||
recordedChunks = [];
|
||||
|
||||
// Request microphone
|
||||
let stream;
|
||||
try {
|
||||
stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: false });
|
||||
} catch (err) {
|
||||
if (err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError') {
|
||||
showError('Microphone permission denied. Please allow microphone access in your browser settings.');
|
||||
} else if (err.name === 'NotFoundError') {
|
||||
showError('No microphone found. Please connect a microphone and try again.');
|
||||
} else {
|
||||
showError(`Microphone error: ${err.message}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Create MediaRecorder
|
||||
const mimeType = getSupportedMimeType();
|
||||
try {
|
||||
mediaRecorder = new MediaRecorder(stream, mimeType ? { mimeType } : {});
|
||||
} catch (err) {
|
||||
showError(`Could not start MediaRecorder: ${err.message}`);
|
||||
stream.getTracks().forEach(t => t.stop());
|
||||
return;
|
||||
}
|
||||
|
||||
mediaRecorder.ondataavailable = (e) => {
|
||||
if (e.data && e.data.size > 0) recordedChunks.push(e.data);
|
||||
};
|
||||
|
||||
mediaRecorder.onerror = (e) => {
|
||||
showError(`Recording error: ${e.error?.message || 'Unknown error'}`);
|
||||
};
|
||||
|
||||
mediaRecorder.start(250); // collect data every 250 ms
|
||||
|
||||
// Update UI → recording state
|
||||
startBtn.disabled = true;
|
||||
stopBtn.disabled = false;
|
||||
liveBadge.classList.add('on');
|
||||
summaryBtn.disabled = true;
|
||||
summaryCard.style.display = 'none';
|
||||
lastTranscript = '';
|
||||
|
||||
transcriptBody.innerHTML = '<p class="placeholder-text">Recording in progress… press ⏹ Stop & Transcribe when done.</p>';
|
||||
|
||||
// Start timer
|
||||
secondsElapsed = 0;
|
||||
timerEl.textContent = '🔴 ' + fmtTime(0);
|
||||
timerInterval = setInterval(() => {
|
||||
secondsElapsed++;
|
||||
timerEl.textContent = '🔴 ' + fmtTime(secondsElapsed);
|
||||
}, 1000);
|
||||
|
||||
setStatus('🎙️ Recording…');
|
||||
}
|
||||
|
||||
// ── Stop recording → send to backend ──────────────────────────────────────
|
||||
function stopRecording() {
|
||||
if (!mediaRecorder || mediaRecorder.state === 'inactive') return;
|
||||
|
||||
// Stop timer
|
||||
clearInterval(timerInterval);
|
||||
timerInterval = null;
|
||||
|
||||
// Stop all mic tracks
|
||||
mediaRecorder.stream.getTracks().forEach(t => t.stop());
|
||||
|
||||
// When recorder finishes flushing, send the audio
|
||||
mediaRecorder.onstop = async () => {
|
||||
await sendAudioToBackend();
|
||||
};
|
||||
|
||||
mediaRecorder.stop();
|
||||
|
||||
// Update UI → processing state
|
||||
startBtn.disabled = true;
|
||||
stopBtn.disabled = true;
|
||||
liveBadge.classList.remove('on');
|
||||
timerEl.textContent = '⏳ ' + fmtTime(secondsElapsed);
|
||||
setStatus('Processing transcript…');
|
||||
|
||||
transcriptBody.innerHTML = `
|
||||
<div class="processing-row">
|
||||
<span class="spinner"></span>
|
||||
Processing transcript, please wait…
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// ── Upload audio blob → /api/transcribe ────────────────────────────────────
|
||||
async function sendAudioToBackend() {
|
||||
if (recordedChunks.length === 0) {
|
||||
showError('No audio was recorded. Please try again.');
|
||||
resetButtons();
|
||||
return;
|
||||
}
|
||||
|
||||
const mimeType = recordedChunks[0].type || 'audio/webm';
|
||||
const extension = mimeType.includes('ogg') ? 'ogg' : mimeType.includes('mp4') ? 'mp4' : 'webm';
|
||||
const audioBlob = new Blob(recordedChunks, { type: mimeType });
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', audioBlob, `recording.${extension}`);
|
||||
|
||||
try {
|
||||
const res = await fetch(`${BACKEND}/api/transcribe`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
// Do NOT set Content-Type header — browser sets it automatically with boundary
|
||||
});
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = await res.json();
|
||||
} catch {
|
||||
throw new Error(`Server returned non-JSON response (HTTP ${res.status})`);
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(data.detail || data.error || `HTTP ${res.status}`);
|
||||
}
|
||||
|
||||
lastTranscript = (data.transcript || '').trim();
|
||||
renderTranscript(lastTranscript, data.language || '');
|
||||
timerEl.textContent = '✅ ' + fmtTime(secondsElapsed);
|
||||
setStatus('✔ Transcript ready', 'ok');
|
||||
|
||||
if (lastTranscript) summaryBtn.disabled = false;
|
||||
|
||||
} catch (err) {
|
||||
// Classify the error for the user
|
||||
let msg = err.message || 'Unknown error';
|
||||
if (err instanceof TypeError && msg.includes('fetch')) {
|
||||
msg = `Cannot reach backend at ${BACKEND}. Is the server running?`;
|
||||
}
|
||||
showError('Transcription failed: ' + msg);
|
||||
transcriptBody.innerHTML = '<p class="placeholder-text">Transcription failed. Please try again.</p>';
|
||||
timerEl.textContent = '🔴 ' + fmtTime(secondsElapsed);
|
||||
setStatus('Transcription failed', 'bad');
|
||||
}
|
||||
|
||||
resetButtons();
|
||||
}
|
||||
|
||||
function resetButtons() {
|
||||
startBtn.disabled = false;
|
||||
stopBtn.disabled = true;
|
||||
}
|
||||
|
||||
// ── Render transcript in existing #transcriptBody ─────────────────────────
|
||||
function renderTranscript(text, language) {
|
||||
if (!text) {
|
||||
transcriptBody.innerHTML = '<p class="placeholder-text">No speech detected in the recording.</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Split on sentence boundaries and render each as an utterance block
|
||||
// (Doctor / Patient alternating — best-effort without diarization)
|
||||
const sentences = text.match(/[^.!?।\n]+[.!?।\n]*/g) || [text];
|
||||
const langTag = language && language !== 'unknown'
|
||||
? `<span class="utt-ts">[${escHtml(language)}]</span>`
|
||||
: '';
|
||||
|
||||
let html = '';
|
||||
sentences.forEach((sentence, i) => {
|
||||
sentence = sentence.trim();
|
||||
if (!sentence) return;
|
||||
|
||||
const isDoc = i % 2 === 0;
|
||||
const icon = isDoc ? '🧑⚕️' : '🧑';
|
||||
const name = isDoc ? 'Doctor' : 'Patient';
|
||||
const cls = isDoc ? '' : 'patient';
|
||||
const ts = fmtTime(Math.round((i / sentences.length) * secondsElapsed));
|
||||
|
||||
html += `
|
||||
<div class="utt">
|
||||
<div class="utt-meta">
|
||||
<span class="utt-icon">${icon}</span>
|
||||
<span class="utt-name ${cls}">${name}</span>
|
||||
<span class="utt-ts">[${ts}]</span>
|
||||
${i === 0 ? langTag : ''}
|
||||
</div>
|
||||
<div class="utt-text">${escHtml(sentence)}</div>
|
||||
</div>`;
|
||||
});
|
||||
|
||||
transcriptBody.innerHTML = html;
|
||||
transcriptBody.scrollTop = transcriptBody.scrollHeight;
|
||||
}
|
||||
|
||||
// ── Reset / Clear ──────────────────────────────────────────────────────────
|
||||
function resetAll() {
|
||||
lastTranscript = '';
|
||||
recordedChunks = [];
|
||||
transcriptBody.innerHTML = '<p class="placeholder-text">Transcript will appear here once recording starts…</p>';
|
||||
summaryCard.style.display = 'none';
|
||||
summaryBtn.disabled = true;
|
||||
timerEl.textContent = '🔴 00:00:00';
|
||||
clearError();
|
||||
setStatus('');
|
||||
}
|
||||
|
||||
// ── Generate AI Summary ────────────────────────────────────────────────────
|
||||
async function generateSummary() {
|
||||
if (!lastTranscript.trim()) return;
|
||||
|
||||
summaryCard.style.display = 'block';
|
||||
summaryBody.innerHTML = `
|
||||
<div class="summary-loading">
|
||||
<span class="spinner"></span> Generating summary…
|
||||
</div>`;
|
||||
summaryBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${BACKEND}/api/summary`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ transcript: lastTranscript }),
|
||||
});
|
||||
|
||||
let data;
|
||||
try { data = await res.json(); } catch { throw new Error('Non-JSON response from backend'); }
|
||||
if (!res.ok) throw new Error(data.detail || data.error || `HTTP ${res.status}`);
|
||||
|
||||
const s = data.summary;
|
||||
if (s.raw_text) {
|
||||
summaryBody.innerHTML = `
|
||||
<div class="summary-row">
|
||||
<span class="s-key">Summary</span>
|
||||
<span class="s-val">${escHtml(s.raw_text)}</span>
|
||||
</div>`;
|
||||
} else {
|
||||
renderSummary(s);
|
||||
}
|
||||
} catch (err) {
|
||||
summaryBody.innerHTML = `
|
||||
<div class="summary-row">
|
||||
<span class="s-key">Error</span>
|
||||
<span class="s-val" style="color:var(--red)">${escHtml(err.message)}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
summaryBtn.disabled = false;
|
||||
}
|
||||
|
||||
function renderSummary(s) {
|
||||
function listHtml(arr) {
|
||||
if (!arr || !arr.length) return 'Not mentioned';
|
||||
return '<ul>' + arr.map(x => `<li>${escHtml(String(x))}</li>`).join('') + '</ul>';
|
||||
}
|
||||
summaryBody.innerHTML = `
|
||||
<div class="summary-row">
|
||||
<span class="s-key">Chief Complaint</span>
|
||||
<span class="s-val">${escHtml(s.chief_complaint || 'Not mentioned')}</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span class="s-key">Symptoms</span>
|
||||
<span class="s-val">${listHtml(s.symptoms)}</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span class="s-key">Diagnosis</span>
|
||||
<span class="s-val">${escHtml(s.assessment || 'Not mentioned')}</span>
|
||||
</div>
|
||||
<div class="summary-row">
|
||||
<span class="s-key">Prescription</span>
|
||||
<span class="s-val">${listHtml(s.plan)}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// ── Event listeners ────────────────────────────────────────────────────────
|
||||
startBtn.addEventListener('click', startRecording);
|
||||
stopBtn.addEventListener('click', stopRecording);
|
||||
clearBtn.addEventListener('click', resetAll);
|
||||
summaryBtn.addEventListener('click', generateSummary);
|
||||
|
||||
// ── Init ───────────────────────────────────────────────────────────────────
|
||||
checkHealth();
|
||||
})();
|
||||
@@ -0,0 +1,380 @@
|
||||
/* ─── Reset ──────────────────────────────────────────────── */
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
/* ─── Tokens ─────────────────────────────────────────────── */
|
||||
:root {
|
||||
--bg: #f0f2f5;
|
||||
--surface: #ffffff;
|
||||
--surface2: #f5f7fa;
|
||||
--border: #dde1ea;
|
||||
--border-hi: #c8cdd8;
|
||||
--text: #1a1d2e;
|
||||
--text-dim: #5a6080;
|
||||
--text-muted: #a0a8c0;
|
||||
--accent: #3b6ff0;
|
||||
--green: #1fad6a;
|
||||
--green-bg: #e6f9f1;
|
||||
--red: #e03c3c;
|
||||
--red-bg: #fdeaea;
|
||||
--yellow: #d4a000;
|
||||
--radius-lg: 12px;
|
||||
--radius-sm: 8px;
|
||||
--gap: 12px;
|
||||
}
|
||||
|
||||
/* ─── Base ───────────────────────────────────────────────── */
|
||||
html, body {
|
||||
min-height: 100vh;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: 'Inter', 'Noto Sans Devanagari', sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* ─── Container ──────────────────────────────────────────── */
|
||||
.container {
|
||||
max-width: 760px;
|
||||
margin: 0 auto;
|
||||
padding: 32px 16px 72px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--gap);
|
||||
}
|
||||
|
||||
/* ─── Panel (shared card shell) ──────────────────────────── */
|
||||
.panel {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-lg);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* ─── Header ─────────────────────────────────────────────── */
|
||||
.header {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 18px 22px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .01em;
|
||||
}
|
||||
.header-icon { font-size: 22px; }
|
||||
|
||||
/* ─── Names panel ────────────────────────────────────────── */
|
||||
.names-panel {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 0;
|
||||
}
|
||||
.name-group {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
.divider-v {
|
||||
width: 1px;
|
||||
background: var(--border);
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .08em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
input[type="text"],
|
||||
select {
|
||||
background: var(--surface2);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--text);
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
padding: 8px 11px;
|
||||
width: 100%;
|
||||
outline: none;
|
||||
transition: border-color .15s;
|
||||
}
|
||||
input[type="text"]::placeholder { color: var(--text-muted); }
|
||||
input[type="text"]:focus,
|
||||
select:focus { border-color: var(--accent); }
|
||||
select { cursor: pointer; }
|
||||
select option { background: var(--surface2); }
|
||||
|
||||
/* ─── Recording panel ────────────────────────────────────── */
|
||||
.rec-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 28px 24px 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Live badge */
|
||||
.live-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .1em;
|
||||
color: var(--red);
|
||||
opacity: 0;
|
||||
transition: opacity .3s;
|
||||
}
|
||||
.live-badge.on { opacity: 1; }
|
||||
|
||||
.live-dot {
|
||||
width: 9px; height: 9px;
|
||||
border-radius: 50%;
|
||||
background: var(--red);
|
||||
animation: blink 1s ease-in-out infinite;
|
||||
}
|
||||
@keyframes blink { 50% { opacity: .2; } }
|
||||
|
||||
/* Timer */
|
||||
.timer {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
font-variant-numeric: tabular-nums;
|
||||
letter-spacing: .03em;
|
||||
}
|
||||
|
||||
/* Status text */
|
||||
.status-text {
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
.status-text.ok { color: var(--green); }
|
||||
.status-text.bad { color: var(--red); }
|
||||
|
||||
/* Error box */
|
||||
.rec-error {
|
||||
width: 100%;
|
||||
background: var(--red-bg);
|
||||
border: 1px solid #5a1e1e;
|
||||
border-radius: var(--radius-sm);
|
||||
color: var(--red);
|
||||
font-size: 12.5px;
|
||||
padding: 9px 14px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
/* Rec buttons row */
|
||||
.rec-btns {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* ─── Buttons ────────────────────────────────────────────── */
|
||||
.btn {
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .05em;
|
||||
padding: 11px 24px;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
transition: filter .15s, transform .1s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.btn:active { transform: scale(.97); }
|
||||
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
|
||||
|
||||
.btn-start {
|
||||
background: var(--green);
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn-start:not(:disabled):hover { filter: brightness(1.1); }
|
||||
|
||||
.btn-stop {
|
||||
background: var(--red);
|
||||
color: #fff;
|
||||
}
|
||||
.btn-stop:not(:disabled):hover { filter: brightness(1.1); }
|
||||
|
||||
.btn-generate {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
padding: 13px 32px;
|
||||
flex: 1;
|
||||
}
|
||||
.btn-generate:not(:disabled):hover { filter: brightness(1.1); }
|
||||
|
||||
.btn-reset {
|
||||
background: transparent;
|
||||
color: var(--text-dim);
|
||||
border: 1px solid var(--border-hi);
|
||||
padding: 13px 20px;
|
||||
}
|
||||
.btn-reset:hover { color: var(--text); border-color: var(--text-dim); }
|
||||
|
||||
/* ─── Panel heading (TRANSCRIPT / MEDICAL SUMMARY) ───────── */
|
||||
.panel-heading {
|
||||
background: var(--surface2);
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding: 10px 20px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .12em;
|
||||
color: var(--text-dim);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
/* ─── Transcript panel ───────────────────────────────────── */
|
||||
.transcript-panel { /* uses .panel */ }
|
||||
|
||||
.transcript-scroll {
|
||||
padding: 18px 20px;
|
||||
min-height: 160px;
|
||||
max-height: 380px;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
}
|
||||
|
||||
.placeholder-text {
|
||||
color: var(--text-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Processing state */
|
||||
.processing-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Utterance block */
|
||||
.utt {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.utt-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.utt-icon { font-size: 16px; }
|
||||
.utt-name {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--accent);
|
||||
}
|
||||
.utt-name.patient { color: var(--green); }
|
||||
.utt-ts {
|
||||
font-size: 11px;
|
||||
color: var(--text-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.utt-text {
|
||||
font-size: 14.5px;
|
||||
line-height: 1.7;
|
||||
color: var(--text);
|
||||
padding-left: 22px;
|
||||
}
|
||||
|
||||
/* ─── Generate panel ─────────────────────────────────────── */
|
||||
.generate-panel {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-lg);
|
||||
}
|
||||
|
||||
/* ─── Summary panel ──────────────────────────────────────── */
|
||||
.summary-panel { /* uses .panel */ }
|
||||
|
||||
.summary-body {
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.summary-row {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.summary-row:last-child { border-bottom: none; }
|
||||
|
||||
.s-key {
|
||||
flex: 0 0 160px;
|
||||
padding: 13px 20px;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--accent);
|
||||
background: var(--surface2);
|
||||
border-right: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.s-val {
|
||||
flex: 1;
|
||||
padding: 13px 20px;
|
||||
font-size: 14px;
|
||||
color: var(--text);
|
||||
line-height: 1.65;
|
||||
}
|
||||
.s-val ul {
|
||||
padding-left: 18px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Loading spinner */
|
||||
.spinner {
|
||||
display: inline-block;
|
||||
width: 14px; height: 14px;
|
||||
border: 2px solid var(--border-hi);
|
||||
border-top-color: var(--accent);
|
||||
border-radius: 50%;
|
||||
animation: spin .7s linear infinite;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
|
||||
.summary-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 18px 20px;
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* ─── Scrollbar ──────────────────────────────────────────── */
|
||||
::-webkit-scrollbar { width: 4px; }
|
||||
::-webkit-scrollbar-track { background: var(--surface2); }
|
||||
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 99px; }
|
||||
|
||||
/* ─── Responsive ─────────────────────────────────────────── */
|
||||
@media (max-width: 520px) {
|
||||
.names-panel { flex-direction: column; }
|
||||
.divider-v { width: 100%; height: 1px; align-self: auto; }
|
||||
.header { font-size: 14px; }
|
||||
.timer { font-size: 22px; }
|
||||
.s-key { flex: 0 0 120px; }
|
||||
}
|
||||
Reference in New Issue
Block a user