fix(turnero): corregir 6 hallazgos de auditoría en tomas previas
- cancelar_toma_pendiente: añade JOIN por paciente_id para prevenir IDOR - cancelar_toma_pendiente: requiere turno_id para validar propiedad - get_tomas_pendientes: porta filtros condicionales y _tomas_config de guardar_toma.php para mostrar conteo de firmas correcto - lugar.php: refresca sección tomas previas al completar via turneroFirmado - lugar.php: muestra error en catch de cargarTomasPrevias en vez de silenciar - lugar.php: limpia _tomaAlertados al cancelar toma previa - lugar.php: pasa turno_id en POST de cancelar para ownership check Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
814bd2ce5c
commit
49a622e05f
@@ -1496,7 +1496,7 @@ async function cargarTomasPrevias(turnoId) {
|
||||
const fecha = t.turno_fecha ? escHtml(t.turno_fecha.slice(0,10)) : '';
|
||||
const prog = t.tomas_total > 0
|
||||
? `<span class="toma-progreso">${t.tomas_firmadas}/${t.tomas_total}</span>` : '';
|
||||
return `<div class="toma-prev-row" data-consent-id="${t.id}">
|
||||
return `<div class="toma-prev-row" data-consent-id="${t.id}" data-turno-id="${t.turno_id}">
|
||||
<i class="fas fa-hourglass-half"></i>
|
||||
<span class="nom-form">${fNom}</span>
|
||||
${prog}
|
||||
@@ -1513,22 +1513,23 @@ async function cargarTomasPrevias(turnoId) {
|
||||
</div>`;
|
||||
}).join('');
|
||||
sec.style.display = '';
|
||||
} catch (_) {}
|
||||
} catch (e) { mostrarError('No se pudieron cargar tomas previas: ' + e.message); }
|
||||
}
|
||||
|
||||
async function cancelarTomaPrevia(consentId, btn) {
|
||||
if (!confirm('¿El paciente no quiere continuar la toma? Se marcará como cancelada.')) return;
|
||||
btn.disabled = true;
|
||||
const row = document.querySelector(`.toma-prev-row[data-consent-id="${consentId}"]`);
|
||||
const oldTId = row ? parseInt(row.dataset.turnoId) : 0;
|
||||
try {
|
||||
const res = await fetch(`${API}cancelar_toma_pendiente.php`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ consentimiento_id: consentId }),
|
||||
body: JSON.stringify({ consentimiento_id: consentId, turno_id: turnoActivo?.id }),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.ok) { mostrarError(json.error); btn.disabled = false; return; }
|
||||
// Quitar fila
|
||||
const row = document.querySelector(`.toma-prev-row[data-consent-id="${consentId}"]`);
|
||||
if (oldTId) _tomaAlertados.delete(oldTId);
|
||||
if (row) row.remove();
|
||||
const list = document.getElementById('lista-tomas-prev');
|
||||
if (list && !list.children.length) document.getElementById('sec-tomas-prev').style.display = 'none';
|
||||
@@ -1660,7 +1661,10 @@ window.addEventListener('message', function(e) {
|
||||
cerrarBannerToma();
|
||||
_tomaAlertados.clear();
|
||||
mostrarToast('Tomas completadas ✓', 'success', 3000);
|
||||
if (turnoActivo) actualizarConsentimientos(turnoActivo.id);
|
||||
if (turnoActivo) {
|
||||
actualizarConsentimientos(turnoActivo.id);
|
||||
cargarTomasPrevias(turnoActivo.id); // limpia fila completada del turno anterior
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user