Tomas prolongadas: panel configurable + link acceso directo
- Panel de protocolo ahora tiene botón "Usar todas" para cerrar sin configurar - Si todos los grupos ya tienen una sola toma, se guarda config silenciosamente y se recarga sin mostrar panel - Lógica de guardado extraída a _mpGuardarConfig() compartida entre ambos botones - Botón de acceso a lab_tomas_config.php en tarjeta del formulario es_toma_progresiva Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2eefe3f5c8
commit
578873a10f
@@ -444,6 +444,11 @@ function renderFormularios() {
|
||||
onclick="envio.abrir(${f.id})">
|
||||
<i class="fas fa-paper-plane me-1"></i>Enviar
|
||||
</button>
|
||||
${f.es_toma_progresiva && PUEDE_ESCRIBIR ? `
|
||||
<a class="btn btn-sm btn-outline-info" href="lab_tomas_config.php"
|
||||
title="Configurar tipos de examen de tomas prolongadas">
|
||||
<i class="fas fa-vials"></i>
|
||||
</a>` : ''}
|
||||
${PUEDE_ESCRIBIR ? `
|
||||
<button class="btn btn-sm btn-outline-secondary" onclick="clonarFormulario(${f.id},'${esc(f.nombre)}')"
|
||||
title="Clonar formulario"><i class="fas fa-copy"></i></button>
|
||||
|
||||
+86
-45
@@ -664,18 +664,33 @@ function esc2(mixed $v): string {
|
||||
$_gruposConfig[$_gk] = ['title' => $__title, 'secs' => $_gsecs];
|
||||
}
|
||||
}
|
||||
$_showCfgPanel = $modoTurnero && $embebido && !empty($_gruposConfig) && $_tomasConfig === null;
|
||||
<?php
|
||||
// Mostrar panel solo si al menos un grupo tiene >= 2 tomas (hay algo que configurar).
|
||||
// Si todos los grupos tienen 1 sola toma, el JS auto-guarda la config sin preguntar.
|
||||
$_hasMulTomas = array_reduce($_gruposConfig, fn($c, $g) => $c || count($g['secs']) >= 2, false);
|
||||
$_showCfgPanel = $modoTurnero && $embebido && !empty($_gruposConfig) && $_tomasConfig === null && $_hasMulTomas;
|
||||
$_autoSaveCfg = $modoTurnero && $embebido && !empty($_gruposConfig) && $_tomasConfig === null && !$_hasMulTomas;
|
||||
// Config por defecto (todas las tomas) — usada tanto por auto-save como por "Usar todas"
|
||||
$_cfgDefault = [];
|
||||
foreach ($_gruposConfig as $_cgk => $_cg) {
|
||||
$_cfgDefault[$_cgk] = array_column($_cg['secs'], 'firma');
|
||||
}
|
||||
?>
|
||||
<?php if ($_showCfgPanel): ?>
|
||||
<div class="mp-cfg-overlay" id="mp-cfg-overlay">
|
||||
<div class="mp-cfg-card">
|
||||
<div class="mp-cfg-head">
|
||||
<i class="fas fa-sliders-h me-2"></i>Configurar protocolo de tomas
|
||||
<div class="mp-cfg-head d-flex align-items-center justify-content-between">
|
||||
<span><i class="fas fa-sliders-h me-2"></i>Configurar protocolo de tomas</span>
|
||||
<button id="mp-cfg-todas" type="button"
|
||||
title="Usar todas las tomas sin configurar"
|
||||
style="background:rgba(255,255,255,.2);border:none;color:#fff;border-radius:6px;
|
||||
padding:3px 10px;font-size:.8rem;cursor:pointer;white-space:nowrap">
|
||||
<i class="fas fa-forward me-1"></i>Usar todas
|
||||
</button>
|
||||
</div>
|
||||
<div class="mp-cfg-body">
|
||||
<p class="text-muted small mb-3">
|
||||
Seleccione las tomas a realizar para este paciente.
|
||||
Puede desmarcar las tomas que no apliquen según la indicación médica.
|
||||
Seleccione las tomas a realizar. Desmárquelas si el médico indicó un protocolo reducido.
|
||||
</p>
|
||||
<?php foreach ($_gruposConfig as $_cgk => $_cg): ?>
|
||||
<div class="mb-3">
|
||||
@@ -1207,53 +1222,79 @@ function esc2(mixed $v): string {
|
||||
|
||||
<script>
|
||||
<?php if (!empty($_mpMap)): ?>
|
||||
/* ── Panel configuración de ciclos + auto-save ── */
|
||||
<?php if (($_showCfgPanel || $_autoSaveCfg) ?? false): ?>
|
||||
var _mpCfgDefault = <?= json_encode($_cfgDefault, JSON_UNESCAPED_UNICODE) ?>;
|
||||
var _mpCfgToken = <?= json_encode($tokenTurnero) ?>;
|
||||
|
||||
function _mpGuardarConfig(config, onOk, onErr) {
|
||||
var base = window.location.href.split('/ver_formulario_enviado.php')[0];
|
||||
fetch(base + '/modules/turnero/api/configurar_tomas.php', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token: _mpCfgToken, tomas_config: config })
|
||||
})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(d) { d.ok ? onOk() : onErr(d.error || 'Error desconocido'); })
|
||||
.catch(function() { onErr('Error de conexión.'); });
|
||||
}
|
||||
|
||||
<?php if ($_autoSaveCfg ?? false): ?>
|
||||
// Todos los grupos tienen una sola toma → guardar config default sin mostrar panel
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
_mpGuardarConfig(_mpCfgDefault, function() { location.reload(); }, function(e) {
|
||||
console.warn('mp-cfg auto-save:', e);
|
||||
});
|
||||
});
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($_showCfgPanel ?? false): ?>
|
||||
/* ── Panel de configuración de ciclos ── */
|
||||
(function() {
|
||||
var btn = document.getElementById('mp-cfg-iniciar');
|
||||
if (!btn) return;
|
||||
btn.addEventListener('click', function() {
|
||||
var byGroup = {};
|
||||
document.querySelectorAll('.mp-cfg-chk').forEach(function(chk) {
|
||||
var g = chk.dataset.group;
|
||||
if (!byGroup[g]) byGroup[g] = { total: 0, sel: [] };
|
||||
byGroup[g].total++;
|
||||
if (chk.checked) byGroup[g].sel.push(chk.value);
|
||||
});
|
||||
var config = {};
|
||||
for (var g in byGroup) {
|
||||
if (byGroup[g].sel.length === 0) {
|
||||
document.getElementById('mp-cfg-msg').innerHTML =
|
||||
'<span class="text-danger"><i class="fas fa-exclamation-circle me-1"></i>Seleccione al menos una toma por protocolo.</span>';
|
||||
return;
|
||||
}
|
||||
config[g] = byGroup[g].sel;
|
||||
}
|
||||
function showMsg(msg) {
|
||||
var el = document.getElementById('mp-cfg-msg');
|
||||
if (el) el.innerHTML = '<span class="text-danger"><i class="fas fa-exclamation-circle me-1"></i>' + msg + '</span>';
|
||||
}
|
||||
function setBtnLoading(btn) {
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Guardando...';
|
||||
var base = window.location.href.split('/ver_formulario_enviado.php')[0];
|
||||
fetch(base + '/modules/turnero/api/configurar_tomas.php', {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ token: <?= json_encode($tokenTurnero) ?>, tomas_config: config })
|
||||
})
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(d) {
|
||||
if (d.ok) { location.reload(); }
|
||||
else {
|
||||
document.getElementById('mp-cfg-msg').innerHTML =
|
||||
'<span class="text-danger">Error: ' + (d.error || 'Error desconocido') + '</span>';
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fas fa-play-circle me-2"></i>Iniciar protocolo';
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
document.getElementById('mp-cfg-msg').innerHTML = '<span class="text-danger">Error de conexión.</span>';
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fas fa-play-circle me-2"></i>Iniciar protocolo';
|
||||
}
|
||||
|
||||
// Botón "Usar todas" → guarda config default y recarga
|
||||
var btnTodas = document.getElementById('mp-cfg-todas');
|
||||
if (btnTodas) {
|
||||
btnTodas.addEventListener('click', function() {
|
||||
setBtnLoading(this);
|
||||
_mpGuardarConfig(_mpCfgDefault, function() { location.reload(); }, function(e) {
|
||||
showMsg(e);
|
||||
btnTodas.disabled = false;
|
||||
btnTodas.innerHTML = '<i class="fas fa-forward me-1"></i>Usar todas';
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Botón "Iniciar protocolo" → lee selección actual
|
||||
var btnIniciar = document.getElementById('mp-cfg-iniciar');
|
||||
if (btnIniciar) {
|
||||
btnIniciar.addEventListener('click', function() {
|
||||
var byGroup = {};
|
||||
document.querySelectorAll('.mp-cfg-chk').forEach(function(chk) {
|
||||
var g = chk.dataset.group;
|
||||
if (!byGroup[g]) byGroup[g] = [];
|
||||
if (chk.checked) byGroup[g].push(chk.value);
|
||||
});
|
||||
for (var g in byGroup) {
|
||||
if (!byGroup[g].length) { showMsg('Seleccione al menos una toma por protocolo.'); return; }
|
||||
}
|
||||
setBtnLoading(this);
|
||||
_mpGuardarConfig(byGroup, function() { location.reload(); }, function(e) {
|
||||
showMsg(e);
|
||||
btnIniciar.disabled = false;
|
||||
btnIniciar.innerHTML = '<i class="fas fa-play-circle me-2"></i>Iniciar protocolo';
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
window._muestrasMap = <?= json_encode($_mpMap, JSON_UNESCAPED_UNICODE) ?>;
|
||||
window._mpSavedFirmas = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user