feat: encuesta de satisfacción post-finalizar toma de muestras
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
4a4cbc31b8
commit
2455417bb4
@@ -994,6 +994,26 @@ require_once __DIR__ . '/../../../shared/components/sidebar.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ── Bar encuesta post-finalizar ─────────────────────────────── -->
|
||||
<div id="bar-encuesta" style="
|
||||
display:none;position:fixed;bottom:0;left:0;right:0;z-index:9100;
|
||||
background:#0f4c81;color:#fff;padding:14px 20px;
|
||||
display:none;align-items:center;gap:14px;flex-wrap:wrap;
|
||||
box-shadow:0 -4px 20px rgba(0,0,0,.25)">
|
||||
<i class="fas fa-star" style="font-size:1.2rem;color:#fbbf24;flex-shrink:0"></i>
|
||||
<span id="bar-encuesta-txt" style="flex:1;font-size:.95rem;font-weight:500"></span>
|
||||
<button onclick="_enviarEncuesta()" id="btn-enc-enviar"
|
||||
style="background:#22c55e;color:#fff;border:none;border-radius:8px;
|
||||
padding:8px 18px;font-weight:600;cursor:pointer;white-space:nowrap">
|
||||
<i class="fas fa-paper-plane me-1"></i>Enviar encuesta
|
||||
</button>
|
||||
<button onclick="_cerrarEncuestaBar()"
|
||||
style="background:rgba(255,255,255,.15);color:#fff;border:none;border-radius:8px;
|
||||
padding:8px 14px;cursor:pointer;white-space:nowrap">
|
||||
Omitir
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ── Modal de consentimiento embebido (modo embebido) ────────── -->
|
||||
<div id="modal-consentimiento" style="
|
||||
display:none;position:fixed;inset:0;z-index:9000;
|
||||
@@ -1961,7 +1981,9 @@ async function finalizarAtencion() {
|
||||
if (hayPendientes) { mostrarError('Debe firmar todos los consentimientos antes de finalizar.'); return; }
|
||||
if (hayMuestrasPendientes) { mostrarError('Debe marcar cada muestra como recibida o pendiente antes de finalizar.'); return; }
|
||||
if (!confirm(`¿Finalizar atención del turno ${turnoActivo.codigo}?`)) return;
|
||||
await cambiarEstadoTurno('finalizado');
|
||||
const _t = { id: turnoActivo.id, paciente_nombre: turnoActivo.paciente_nombre };
|
||||
const ok = await cambiarEstadoTurno('finalizado');
|
||||
if (ok) _ofrecerEncuesta(_t);
|
||||
}
|
||||
|
||||
async function marcarAusente() {
|
||||
@@ -2024,15 +2046,58 @@ async function cambiarEstadoTurno(nuevoEstado) {
|
||||
} else {
|
||||
mostrarError(json.error);
|
||||
}
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
resetFicha();
|
||||
cargarCola();
|
||||
return true;
|
||||
} catch (err) {
|
||||
mostrarError(err.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Encuesta post-finalizar ───────────────────────────────────
|
||||
let _encuestaTurnoId = null, _encuestaTimer = null;
|
||||
|
||||
function _ofrecerEncuesta(turno) {
|
||||
_encuestaTurnoId = turno.id;
|
||||
const bar = document.getElementById('bar-encuesta');
|
||||
document.getElementById('bar-encuesta-txt').textContent =
|
||||
`¿Enviar encuesta de satisfacción a ${turno.paciente_nombre || 'el paciente'}?`;
|
||||
document.getElementById('btn-enc-enviar').disabled = false;
|
||||
document.getElementById('btn-enc-enviar').innerHTML = '<i class="fas fa-paper-plane me-1"></i>Enviar encuesta';
|
||||
bar.style.display = 'flex';
|
||||
clearTimeout(_encuestaTimer);
|
||||
_encuestaTimer = setTimeout(_cerrarEncuestaBar, 12000);
|
||||
}
|
||||
|
||||
async function _enviarEncuesta() {
|
||||
if (!_encuestaTurnoId) return;
|
||||
const btn = document.getElementById('btn-enc-enviar');
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Enviando…';
|
||||
try {
|
||||
const res = await fetch(API + 'enviar_encuesta.php', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ turno_id: _encuestaTurnoId }),
|
||||
});
|
||||
const json = await res.json();
|
||||
_cerrarEncuestaBar();
|
||||
if (json.ok) mostrarToast('Encuesta enviada ✓', 'success', 3000);
|
||||
else mostrarToast('No se pudo enviar: ' + (json.error || 'error'), 'warning', 4000);
|
||||
} catch (e) {
|
||||
_cerrarEncuestaBar();
|
||||
mostrarToast('Error al enviar encuesta', 'warning', 3000);
|
||||
}
|
||||
}
|
||||
|
||||
function _cerrarEncuestaBar() {
|
||||
clearTimeout(_encuestaTimer);
|
||||
document.getElementById('bar-encuesta').style.display = 'none';
|
||||
_encuestaTurnoId = null;
|
||||
}
|
||||
|
||||
// ── Reset ficha ───────────────────────────────────────────────
|
||||
function resetFicha() {
|
||||
clearInterval(pollingConsentId);
|
||||
|
||||
Reference in New Issue
Block a user