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})">
|
onclick="envio.abrir(${f.id})">
|
||||||
<i class="fas fa-paper-plane me-1"></i>Enviar
|
<i class="fas fa-paper-plane me-1"></i>Enviar
|
||||||
</button>
|
</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 ? `
|
${PUEDE_ESCRIBIR ? `
|
||||||
<button class="btn btn-sm btn-outline-secondary" onclick="clonarFormulario(${f.id},'${esc(f.nombre)}')"
|
<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>
|
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];
|
$_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): ?>
|
<?php if ($_showCfgPanel): ?>
|
||||||
<div class="mp-cfg-overlay" id="mp-cfg-overlay">
|
<div class="mp-cfg-overlay" id="mp-cfg-overlay">
|
||||||
<div class="mp-cfg-card">
|
<div class="mp-cfg-card">
|
||||||
<div class="mp-cfg-head">
|
<div class="mp-cfg-head d-flex align-items-center justify-content-between">
|
||||||
<i class="fas fa-sliders-h me-2"></i>Configurar protocolo de tomas
|
<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>
|
||||||
<div class="mp-cfg-body">
|
<div class="mp-cfg-body">
|
||||||
<p class="text-muted small mb-3">
|
<p class="text-muted small mb-3">
|
||||||
Seleccione las tomas a realizar para este paciente.
|
Seleccione las tomas a realizar. Desmárquelas si el médico indicó un protocolo reducido.
|
||||||
Puede desmarcar las tomas que no apliquen según la indicación médica.
|
|
||||||
</p>
|
</p>
|
||||||
<?php foreach ($_gruposConfig as $_cgk => $_cg): ?>
|
<?php foreach ($_gruposConfig as $_cgk => $_cg): ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -1207,53 +1222,79 @@ function esc2(mixed $v): string {
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
<?php if (!empty($_mpMap)): ?>
|
<?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): ?>
|
<?php if ($_showCfgPanel ?? false): ?>
|
||||||
/* ── Panel de configuración de ciclos ── */
|
|
||||||
(function() {
|
(function() {
|
||||||
var btn = document.getElementById('mp-cfg-iniciar');
|
function showMsg(msg) {
|
||||||
if (!btn) return;
|
var el = document.getElementById('mp-cfg-msg');
|
||||||
btn.addEventListener('click', function() {
|
if (el) el.innerHTML = '<span class="text-danger"><i class="fas fa-exclamation-circle me-1"></i>' + msg + '</span>';
|
||||||
var byGroup = {};
|
}
|
||||||
document.querySelectorAll('.mp-cfg-chk').forEach(function(chk) {
|
function setBtnLoading(btn) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
btn.disabled = true;
|
btn.disabled = true;
|
||||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin me-2"></i>Guardando...';
|
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' },
|
// Botón "Usar todas" → guarda config default y recarga
|
||||||
body: JSON.stringify({ token: <?= json_encode($tokenTurnero) ?>, tomas_config: config })
|
var btnTodas = document.getElementById('mp-cfg-todas');
|
||||||
})
|
if (btnTodas) {
|
||||||
.then(function(r) { return r.json(); })
|
btnTodas.addEventListener('click', function() {
|
||||||
.then(function(d) {
|
setBtnLoading(this);
|
||||||
if (d.ok) { location.reload(); }
|
_mpGuardarConfig(_mpCfgDefault, function() { location.reload(); }, function(e) {
|
||||||
else {
|
showMsg(e);
|
||||||
document.getElementById('mp-cfg-msg').innerHTML =
|
btnTodas.disabled = false;
|
||||||
'<span class="text-danger">Error: ' + (d.error || 'Error desconocido') + '</span>';
|
btnTodas.innerHTML = '<i class="fas fa-forward me-1"></i>Usar todas';
|
||||||
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 "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; ?>
|
||||||
|
<?php endif; ?>
|
||||||
window._muestrasMap = <?= json_encode($_mpMap, JSON_UNESCAPED_UNICODE) ?>;
|
window._muestrasMap = <?= json_encode($_mpMap, JSON_UNESCAPED_UNICODE) ?>;
|
||||||
window._mpSavedFirmas = {};
|
window._mpSavedFirmas = {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user