Toma progresiva: auto-scroll, cierre automático, countdown en cola y fix filtro por examen
- guardar_toma.php: filtrar firmas por condición del examen seleccionado; corrige countdown espurio y detección de 'completado' cuando hay múltiples tipos de examen. También descarta siguiente_toma_at si ya es pasado (minuto 0). - ver_formulario_enviado.php: auto-scroll a primera firma pendiente al cargar el modal; si el examen se selecciona y la firma no está en DOM, guarda y recarga el iframe. Al completar tomas, cierra el modal directamente sin botón "Finalizar". - get_cola.php: incluye siguiente_toma_at y en_toma_progresiva por turno desde turnero_consentimientos para mostrar cuenta regresiva en tarjetas. - lugar.php: muestra chip de cuenta regresiva en tarjetas de cola para pacientes en toma progresiva; color cambia a warn (<2 min) y crit (¡Ahora!). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
c2605fb274
commit
848dd8e4d0
+51
-10
@@ -1073,6 +1073,13 @@ function esc2(mixed $v): string {
|
||||
<?php if (!empty($_mpMap)): ?>
|
||||
window._muestrasMap = <?= json_encode($_mpMap, JSON_UNESCAPED_UNICODE) ?>;
|
||||
window._mpSavedFirmas = {};
|
||||
// Auto-scroll a la primera firma pendiente al cargar (examen ya seleccionado)
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
setTimeout(function() {
|
||||
var fw = document.querySelector('.firma-pro-widget:not([style*="display:none"])');
|
||||
if (fw) fw.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}, 350);
|
||||
});
|
||||
<?php endif; ?>
|
||||
/* ── Firma del profesional: función compartida canvas/1-clic ────── */
|
||||
function _guardarFirmaPro(widget, svg, msgEl) {
|
||||
@@ -1183,24 +1190,34 @@ function _guardarFirmaMP(widget, svg, msgEl, entry, campoId) {
|
||||
widget.replaceWith(box);
|
||||
|
||||
if (data.completado) {
|
||||
_mpMostrarFinalizar(entry.exam_type);
|
||||
// Cerrar modal en lugar.php y refrescar la lista
|
||||
// Toma completada: mostrar mensaje y cerrar modal automáticamente
|
||||
var ok = document.createElement('div');
|
||||
ok.className = 'alert alert-success mt-4 d-flex align-items-center gap-2';
|
||||
ok.innerHTML = '<i class="fas fa-check-circle fs-5"></i><div><strong>Toma ' + (entry.exam_type || '') + ' completada.</strong><br><small>Cerrando...</small></div>';
|
||||
document.querySelector('.doc-body').appendChild(ok);
|
||||
setTimeout(function() {
|
||||
try { window.parent.postMessage({ type: 'turneroFirmado' }, '*'); } catch(e) {}
|
||||
}, 1200);
|
||||
} else if (data.siguiente_toma_at) {
|
||||
// Countdown usando tiempo absoluto del servidor
|
||||
var targetMs = new Date(data.siguiente_toma_at.replace(' ', 'T')).getTime();
|
||||
var minsLeft = Math.max(1, Math.round((targetMs - Date.now()) / 60000));
|
||||
_mpIniciarCountdown(minsLeft, entry.next_label, entry.next_firma_id);
|
||||
} else if (!entry.is_last) {
|
||||
var nw = entry.next_firma_id ? document.getElementById('fpw-' + entry.next_firma_id) : document.querySelector('.firma-pro-widget');
|
||||
if (nw) nw.scrollIntoView({ behavior:'smooth', block:'center' });
|
||||
var nw = entry.next_firma_id ? document.getElementById('fpw-' + entry.next_firma_id) : null;
|
||||
if (!nw) nw = document.querySelector('.firma-pro-widget:not([style*="display:none"])');
|
||||
if (nw) { nw.style.display = ''; nw.scrollIntoView({ behavior:'smooth', block:'center' }); }
|
||||
} else {
|
||||
_mpMostrarFinalizar(entry.exam_type);
|
||||
setTimeout(function() {
|
||||
try { window.parent.postMessage({ type: 'turneroFirmado' }, '*'); } catch(e) {}
|
||||
}, 1200);
|
||||
// Último firma del grupo pero hay más exámenes pendientes; desbloquear siguiente
|
||||
var nw = document.querySelector('.firma-pro-widget[style*="display:none"]');
|
||||
if (nw) {
|
||||
nw.style.display = '';
|
||||
nw.scrollIntoView({ behavior:'smooth', block:'center' });
|
||||
} else {
|
||||
// Sin más firmas pendientes → cerrar
|
||||
setTimeout(function() {
|
||||
try { window.parent.postMessage({ type: 'turneroFirmado' }, '*'); } catch(e) {}
|
||||
}, 1200);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
@@ -1681,7 +1698,7 @@ const topaz = (() => {
|
||||
var condicionales = secciones.filter(function(s) { return s.condicion; });
|
||||
if (!condicionales.length) return;
|
||||
|
||||
function evaluar() {
|
||||
function evaluar(evt) {
|
||||
condicionales.forEach(function(sec) {
|
||||
var cond = sec.condicion;
|
||||
var valoresCond = cond.valores ? cond.valores : (cond.valor ? [cond.valor] : []);
|
||||
@@ -1708,6 +1725,30 @@ const topaz = (() => {
|
||||
el.style.pointerEvents = activo ? '' : 'none';
|
||||
});
|
||||
});
|
||||
|
||||
// Toma progresiva: scroll a la primera firma pendiente
|
||||
if (window._muestrasMap) {
|
||||
setTimeout(function() {
|
||||
var fw = document.querySelector('.firma-pro-widget:not([style*="display:none"])');
|
||||
if (fw) {
|
||||
fw.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
} else if (evt) {
|
||||
// Firma no está en el DOM (examen recién seleccionado) → guardar y recargar
|
||||
var dr = {};
|
||||
document.querySelectorAll('[name]').forEach(function(el) {
|
||||
var n = el.name.endsWith('[]') ? el.name.slice(0,-2) : el.name;
|
||||
if (el.type==='checkbox'){ if(el.checked){ if(!Array.isArray(dr[n]))dr[n]=[]; dr[n].push(el.value); } }
|
||||
else if (el.type==='radio'){ if(el.checked) dr[n]=el.value; }
|
||||
else if (el.value!=='') dr[n]=el.value;
|
||||
});
|
||||
fetch(window.location.href, {
|
||||
method:'POST', headers:{'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ datos_respuestas: dr })
|
||||
}).then(function() { window.location.reload(); })
|
||||
.catch(function() { window.location.reload(); });
|
||||
}
|
||||
}, 400);
|
||||
}
|
||||
}
|
||||
|
||||
var ctrlIds = [...new Set(condicionales.map(function(s) { return s.condicion.campo_id; }))];
|
||||
|
||||
Reference in New Issue
Block a user