feat(diarization): Sub-Phase 3B.2 - intent-based turn attribution, 1-click role picker menu, and high-contrast color palette

This commit is contained in:
Ayush
2026-11-18 17:16:55 +05:30
parent 3c79b91fb1
commit 7d008ed738
3 changed files with 358 additions and 17 deletions
+114 -1
View File
@@ -757,7 +757,10 @@
<div class="utterance-avatar">${icon}</div>
<div class="utterance-content">
<div class="utterance-meta">
<span class="utterance-speaker ${colorCls}">${escapeHtml(utt.speaker)}</span>
<button type="button" class="speaker-role-btn ${colorCls}" onclick="event.stopPropagation(); window.app.openRolePicker('${utt.id}', this, event)" title="Click to choose speaker role">
<span class="speaker-role-text">${escapeHtml(utt.speaker)}</span>
<span class="role-switch-icon" aria-hidden="true">▾</span>
</button>
<span class="utterance-time">[${fmtTime(utt.startSec)} - ${fmtTime(utt.endSec)}]</span>
<span class="utterance-lang-badge">English</span>
</div>
@@ -1311,9 +1314,119 @@ ${Array.isArray(currentSummaryData.plan) ? currentSummaryData.plan.join('\n- ')
};
const caseId = caseMap[type] || 'case-cardiology';
this.loadSpecificCase(caseId);
},
cycleRole: function(uttId) {
const utt = liveUtterances.find(u => u.id === uttId);
if (!utt) return;
const roleOrder = ['doctor', 'patient', 'relative', 'nurse'];
const currentIdx = roleOrder.indexOf((utt.role || 'patient').toLowerCase());
const nextIdx = (currentIdx + 1) % roleOrder.length;
this.setRole(uttId, roleOrder[nextIdx]);
},
openRolePicker: function(uttId, btnEl, event) {
if (event) event.stopPropagation();
if (window._activeRolePicker && window._activeRolePicker._btnEl === btnEl) {
window.app.closeRolePicker();
return;
}
window.app.closeRolePicker();
const utt = liveUtterances.find(u => u.id === uttId);
if (!utt) return;
const roles = [
{ key: 'doctor', label: 'Doctor (डॉक्टर)', icon: '🩺', cls: 'opt-doctor' },
{ key: 'patient', label: 'Patient (रुग्ण / पेशंट)', icon: '🧑', cls: 'opt-patient' },
{ key: 'relative', label: 'Relative (नातेवाईक)', icon: '👨‍👩‍👧', cls: 'opt-relative' },
{ key: 'nurse', label: 'Nurse (परिचारिका)', icon: '👩‍⚕️', cls: 'opt-nurse' }
];
const popover = document.createElement('div');
popover.className = 'role-picker-popover';
popover._btnEl = btnEl;
const currentRole = (utt.role || 'patient').toLowerCase();
popover.innerHTML = `
<div class="role-picker-header">Assign Speaker</div>
${roles.map(r => `
<button type="button" class="role-picker-option ${r.cls} ${currentRole === r.key ? 'active' : ''}" data-role="${r.key}">
<span class="opt-icon">${r.icon}</span>
<span class="opt-label">${r.label}</span>
<span class="opt-check">${currentRole === r.key ? '✓' : ''}</span>
</button>
`).join('')}
`;
popover.querySelectorAll('.role-picker-option').forEach(opt => {
opt.addEventListener('click', (e) => {
e.stopPropagation();
const selectedRole = opt.getAttribute('data-role');
window.app.setRole(uttId, selectedRole);
window.app.closeRolePicker();
});
});
document.body.appendChild(popover);
window._activeRolePicker = popover;
const rect = btnEl.getBoundingClientRect();
const popoverHeight = 185;
let top = rect.bottom + window.scrollY + 5;
let left = rect.left + window.scrollX;
if (left + 210 > window.innerWidth) {
left = Math.max(10, window.innerWidth - 220);
}
if (rect.bottom + popoverHeight > window.innerHeight && rect.top > popoverHeight) {
top = rect.top + window.scrollY - popoverHeight - 5;
}
popover.style.top = `${top}px`;
popover.style.left = `${left}px`;
},
closeRolePicker: function() {
if (window._activeRolePicker) {
window._activeRolePicker.remove();
window._activeRolePicker = null;
}
},
setRole: function(uttId, newRole) {
const utt = liveUtterances.find(u => u.id === uttId);
if (!utt) return;
utt.role = newRole;
if (newRole === 'doctor') {
utt.speaker = 'Doctor (डॉक्टर)';
} else if (newRole === 'patient') {
utt.speaker = 'Patient (रुग्ण / पेशंट)';
} else if (newRole === 'relative') {
utt.speaker = 'Relative (नातेवाईक)';
} else if (newRole === 'nurse') {
utt.speaker = 'Nurse (परिचारिका)';
}
currentTranscript = liveUtterances.map(u => `[${u.speaker}] ${u.text}`).join('\n\n');
renderAllUtterances();
showToast(`Speaker assigned: ${utt.speaker}`);
}
};
// Close role picker popover on outside click or Esc
document.addEventListener('click', (e) => {
if (window._activeRolePicker && !window._activeRolePicker.contains(e.target)) {
window.app.closeRolePicker();
}
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
window.app.closeRolePicker();
}
});
})();
// End of application logic.