feat(subphase-3a): chronological transcript sequencing and role-based labels
This commit is contained in:
+18
-11
@@ -433,9 +433,7 @@
|
|||||||
// BUG: doctorSelect हा DOM ID नाही — 'doctorName' हा actual ID आहे
|
// BUG: doctorSelect हा DOM ID नाही — 'doctorName' हा actual ID आहे
|
||||||
const doctorEl = document.getElementById('doctorName');
|
const doctorEl = document.getElementById('doctorName');
|
||||||
const patientEl = document.getElementById('patientName');
|
const patientEl = document.getElementById('patientName');
|
||||||
utt.speaker = isDoc
|
utt.speaker = isDoc ? 'Doctor (डॉक्टर)' : 'Patient (रुग्ण / पेशंट)';
|
||||||
? (doctorEl ? doctorEl.value || 'Dr. Sharma' : 'Dr. Sharma').split('(')[0].trim()
|
|
||||||
: (patientEl ? patientEl.value.trim() || 'Patient' : 'Patient');
|
|
||||||
renderAllUtterances();
|
renderAllUtterances();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -606,11 +604,21 @@
|
|||||||
|
|
||||||
// Case 1: Use true acoustic timestamps returned directly by Sarvam Diarization
|
// Case 1: Use true acoustic timestamps returned directly by Sarvam Diarization
|
||||||
if (entries && Array.isArray(entries) && entries.length > 0) {
|
if (entries && Array.isArray(entries) && entries.length > 0) {
|
||||||
liveUtterances = entries.map((entry, idx) => {
|
// Defensive sort: Ensure strictly chronological sequence by spoken start time
|
||||||
|
const sortedEntries = [...entries].sort((a, b) => {
|
||||||
|
const aStart = typeof a.startSec === 'number' ? a.startSec : (parseFloat(a.startSec) || 0);
|
||||||
|
const bStart = typeof b.startSec === 'number' ? b.startSec : (parseFloat(b.startSec) || 0);
|
||||||
|
if (aStart !== bStart) return aStart - bStart;
|
||||||
|
const aEnd = typeof a.endSec === 'number' ? a.endSec : (parseFloat(a.endSec) || 0);
|
||||||
|
const bEnd = typeof b.endSec === 'number' ? b.endSec : (parseFloat(b.endSec) || 0);
|
||||||
|
return aEnd - bEnd;
|
||||||
|
});
|
||||||
|
|
||||||
|
liveUtterances = sortedEntries.map((entry, idx) => {
|
||||||
const role = (entry.role || 'patient').toLowerCase();
|
const role = (entry.role || 'patient').toLowerCase();
|
||||||
let speaker = doctorName;
|
let speaker = 'Doctor (डॉक्टर)';
|
||||||
if (role === 'patient') {
|
if (role === 'patient') {
|
||||||
speaker = patientName;
|
speaker = 'Patient (रुग्ण / पेशंट)';
|
||||||
} else if (role === 'relative') {
|
} else if (role === 'relative') {
|
||||||
speaker = 'Relative (नातेवाईक)';
|
speaker = 'Relative (नातेवाईक)';
|
||||||
} else if (role === 'nurse') {
|
} else if (role === 'nurse') {
|
||||||
@@ -661,11 +669,11 @@
|
|||||||
const isNurse = /^(?:\[Speaker_\d+\s*\|\s*Nurse\])|(?:(?:nurse|परिचारिका|नर्स)\s*[::\-])/i.test(segment);
|
const isNurse = /^(?:\[Speaker_\d+\s*\|\s*Nurse\])|(?:(?:nurse|परिचारिका|नर्स)\s*[::\-])/i.test(segment);
|
||||||
|
|
||||||
let role = 'doctor';
|
let role = 'doctor';
|
||||||
let speaker = doctorName;
|
let speaker = 'Doctor (डॉक्टर)';
|
||||||
|
|
||||||
if (isPatient) {
|
if (isPatient) {
|
||||||
role = 'patient';
|
role = 'patient';
|
||||||
speaker = patientName;
|
speaker = 'Patient (रुग्ण / पेशंट)';
|
||||||
} else if (isRelative) {
|
} else if (isRelative) {
|
||||||
role = 'relative';
|
role = 'relative';
|
||||||
speaker = 'Relative (नातेवाईक)';
|
speaker = 'Relative (नातेवाईक)';
|
||||||
@@ -712,9 +720,8 @@
|
|||||||
let html = '';
|
let html = '';
|
||||||
|
|
||||||
liveUtterances.forEach((utt) => {
|
liveUtterances.forEach((utt) => {
|
||||||
// Filter by speaker
|
// Filter by speaker (All, Doctor, Patient, Relative, Nurse)
|
||||||
if (activeFilter === 'doctor' && utt.role !== 'doctor') return;
|
if (activeFilter !== 'all' && utt.role !== activeFilter) return;
|
||||||
if (activeFilter === 'patient' && utt.role !== 'patient') return;
|
|
||||||
|
|
||||||
// Filter by search
|
// Filter by search
|
||||||
if (searchTerm && !utt.text.toLowerCase().includes(searchTerm) && !utt.speaker.toLowerCase().includes(searchTerm)) {
|
if (searchTerm && !utt.text.toLowerCase().includes(searchTerm) && !utt.speaker.toLowerCase().includes(searchTerm)) {
|
||||||
|
|||||||
@@ -288,6 +288,8 @@
|
|||||||
<button class="filter-pill active" data-filter="all">All Dialogue</button>
|
<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="doctor">🧑⚕️ Doctor</button>
|
||||||
<button class="filter-pill" data-filter="patient">🧑 Patient</button>
|
<button class="filter-pill" data-filter="patient">🧑 Patient</button>
|
||||||
|
<button class="filter-pill" data-filter="relative">👨👩👧 Relative</button>
|
||||||
|
<button class="filter-pill" data-filter="nurse">👩⚕️ Nurse</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Full Transcript Scroll Viewport -->
|
<!-- Full Transcript Scroll Viewport -->
|
||||||
|
|||||||
@@ -760,8 +760,14 @@ app.post('/api/transcribe', async (req, res) => {
|
|||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Strict Chronological Sort: Order utterances strictly by spoken timeline
|
||||||
|
normalizedEntries.sort((a, b) => {
|
||||||
|
if (a.startSec !== b.startSec) return a.startSec - b.startSec;
|
||||||
|
return a.endSec - b.endSec;
|
||||||
|
});
|
||||||
|
|
||||||
const plainConversation = normalizedEntries.map(entry => `${entry.speakerId}: ${entry.textContent}`).join('\n');
|
const plainConversation = normalizedEntries.map(entry => `${entry.speakerId}: ${entry.textContent}`).join('\n');
|
||||||
const firstSpeakerId = normalizedEntries[0].speakerId;
|
const firstSpeakerId = normalizedEntries[0]?.speakerId || 'Speaker_0';
|
||||||
|
|
||||||
// Step 2: Role Classifier using LLM
|
// Step 2: Role Classifier using LLM
|
||||||
console.log("8. Running NLP Role Classifier (LLM Context Analysis)...");
|
console.log("8. Running NLP Role Classifier (LLM Context Analysis)...");
|
||||||
@@ -815,6 +821,12 @@ ${plainConversation.slice(0, 3000)}`;
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Strict Chronological Sort for Structured UI Entries & Final Transcript
|
||||||
|
structuredEntries.sort((a, b) => {
|
||||||
|
if (a.startSec !== b.startSec) return a.startSec - b.startSec;
|
||||||
|
return a.endSec - b.endSec;
|
||||||
|
});
|
||||||
|
|
||||||
finalTranscript = structuredEntries.map(entry => {
|
finalTranscript = structuredEntries.map(entry => {
|
||||||
return `[${entry.speakerId} | ${entry.role}] ${entry.text}`;
|
return `[${entry.speakerId} | ${entry.role}] ${entry.text}`;
|
||||||
}).join('\n\n');
|
}).join('\n\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user