Historial turnero: usar el formulario real de tomas prolongadas (F-LAB-28)
El desglose anterior se basaba en turnero_muestras, que no representa el formulario "Control de Tomas de Muestras Prolongadas" que el laboratorio ya usa para tomas seriadas (curvas de glicemia, etc.). Ahora el doc-pill del historial muestra "X/Y tomas" usando es_toma_progresiva/tomas_firmadas que get_consentimientos.php ya calculaba, sin duplicar lógica. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0b8418ec76
commit
86aea30f62
@@ -144,7 +144,6 @@ $turnoIds = array_column($turnos, 'id');
|
||||
$examenes = [];
|
||||
$consentimientos = [];
|
||||
$comentarios = [];
|
||||
$tomas = [];
|
||||
|
||||
if ($turnoIds) {
|
||||
$ph = implode(',', array_fill(0, count($turnoIds), '?'));
|
||||
@@ -195,25 +194,6 @@ if ($turnoIds) {
|
||||
}
|
||||
}
|
||||
|
||||
// Tomas de muestra — batch (una solicitud por turno, varias tomas por solicitud)
|
||||
$stmtTom = $pdo->prepare(
|
||||
"SELECT ts.turno_id, tm.tipo_muestra, tm.estado, tm.creado_at, tm.recibida_at,
|
||||
ar.full_name AS recibida_por_nombre
|
||||
FROM turnero_muestras tm
|
||||
JOIN turnero_solicitudes ts ON ts.id = tm.solicitud_id
|
||||
LEFT JOIN admin_users ar ON ar.id = tm.recibida_por
|
||||
WHERE ts.turno_id IN ($ph)
|
||||
ORDER BY tm.creado_at ASC"
|
||||
);
|
||||
$stmtTom->execute($turnoIds);
|
||||
foreach ($stmtTom->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$tid = (int)$row['turno_id'];
|
||||
unset($row['turno_id']);
|
||||
$row['tiempo_min'] = ($row['creado_at'] && $row['recibida_at'])
|
||||
? round((strtotime($row['recibida_at']) - strtotime($row['creado_at'])) / 60, 1)
|
||||
: null;
|
||||
$tomas[$tid][] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($turnos as &$turno) {
|
||||
@@ -221,7 +201,6 @@ foreach ($turnos as &$turno) {
|
||||
$turno['examenes'] = $examenes[$tid] ?? [];
|
||||
$turno['consentimientos'] = $consentimientos[$tid] ?? [];
|
||||
$turno['comentarios'] = $comentarios[$tid] ?? [];
|
||||
$turno['tomas'] = $tomas[$tid] ?? [];
|
||||
}
|
||||
|
||||
// ── Resumen por estado (del rango filtrado) ───────────────────
|
||||
|
||||
@@ -533,25 +533,6 @@ function renderDetalle(t) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// Tomas de muestra (solo si hay más de una — turno prolongado por varias tomas)
|
||||
let tomasHtml = '';
|
||||
if (t.tomas && t.tomas.length > 1) {
|
||||
tomasHtml = `<div class="detail-extra">
|
||||
<div class="d-lbl"><i class="fas fa-tint me-1 text-danger"></i>Tomas de muestra (${t.tomas.length})</div>
|
||||
<table class="table table-sm mb-0" style="font-size:.78rem">
|
||||
<thead><tr><th>Muestra</th><th>Recibió</th><th>Recibida</th><th>Tiempo</th></tr></thead>
|
||||
<tbody>
|
||||
${t.tomas.map(m => `<tr>
|
||||
<td>${esc(m.tipo_muestra)}</td>
|
||||
<td>${esc(m.recibida_por_nombre || '—')}</td>
|
||||
<td>${m.recibida_at ? new Date(m.recibida_at.replace(' ','T')).toLocaleTimeString('es-CO',{hour:'2-digit',minute:'2-digit'}) : '—'}</td>
|
||||
<td>${m.tiempo_min != null ? m.tiempo_min + ' m' : '—'}</td>
|
||||
</tr>`).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// Comentarios
|
||||
let comHtml = '';
|
||||
if (t.comentarios && t.comentarios.length) {
|
||||
@@ -574,7 +555,7 @@ function renderDetalle(t) {
|
||||
<div class="d-val">${it.val}</div>
|
||||
</div>`).join('')}
|
||||
</div>
|
||||
${examHtml}${tomasHtml}${comHtml}
|
||||
${examHtml}${comHtml}
|
||||
<div class="docs-section" id="docs-${t.id}">
|
||||
<div class="docs-lbl"><i class="fas fa-file-signature me-1"></i>Documentos</div>
|
||||
<span class="text-muted small"><i class="fas fa-spinner fa-spin me-1"></i>Cargando…</span>
|
||||
@@ -615,15 +596,19 @@ async function cargarDocumentosTurno(turnoId, container) {
|
||||
const pills = list.map(c => {
|
||||
const est = c.estado || 'pendiente';
|
||||
const nombre = esc(c.formulario_nombre || 'Documento');
|
||||
// Formulario de tomas progresivas (ej. Control de Tomas de Muestras Prolongadas F-LAB-28)
|
||||
const tomas = c.es_toma_progresiva
|
||||
? ` <span class="badge bg-danger-subtle text-danger ms-1" style="font-size:.62rem">${c.tomas_firmadas||0}/${c.tomas_total||0} tomas</span>`
|
||||
: '';
|
||||
if (est === 'firmado' && c.token) {
|
||||
const url = BASE_URL_ROOT + 'ver_formulario_enviado.php?token=' + encodeURIComponent(c.token);
|
||||
return `<a class="doc-pill firmado" href="${url}" onclick="return abrirDocModal(event,'${url}','${nombre.replace(/'/g,"\\'")}')">
|
||||
<i class="fas fa-check-circle"></i>${nombre}
|
||||
<i class="fas fa-check-circle"></i>${nombre}${tomas}
|
||||
</a>`;
|
||||
}
|
||||
const cls = est === 'enviado' || est === 'visto' ? 'enviado' : 'pendiente';
|
||||
const ico = est === 'enviado' ? 'fa-paper-plane' : (est === 'visto' ? 'fa-eye' : 'fa-clock');
|
||||
return `<span class="doc-pill ${cls}"><i class="fas ${ico}"></i>${nombre}</span>`;
|
||||
return `<span class="doc-pill ${cls}"><i class="fas ${ico}"></i>${nombre}${tomas}</span>`;
|
||||
}).join('');
|
||||
container.innerHTML = '<div class="docs-lbl"><i class="fas fa-file-signature me-1"></i>Documentos</div>' + pills;
|
||||
} catch(_) {
|
||||
|
||||
Reference in New Issue
Block a user