up
This commit is contained in:
@@ -17,6 +17,7 @@ $datos = inputJson();
|
||||
$area = $datos['area'] ?? '';
|
||||
$lugarId = isset($datos['lugar_id']) ? (int) $datos['lugar_id'] : null;
|
||||
$deskId = isset($datos['desk_id']) ? (int) $datos['desk_id'] : null;
|
||||
$turnoId = isset($datos['turno_id']) ? (int) $datos['turno_id'] : null; // llamar uno específico
|
||||
|
||||
// ── Validación ────────────────────────────────────────────────
|
||||
if (!in_array($area, ['recepcion', 'lugar'], true)) {
|
||||
@@ -59,11 +60,26 @@ try {
|
||||
|
||||
} else {
|
||||
// Cola de un Lugar específico: turnos 'en_espera_lugar' asignados a ese lugar
|
||||
$turno = siguienteTurnoEnCola('en_espera_lugar', $lugarId);
|
||||
|
||||
if (!$turno) {
|
||||
$pdo->rollBack();
|
||||
jsonOk(['turno' => null], 'Cola del lugar vacía');
|
||||
if ($turnoId) {
|
||||
// Llamar uno específico por id
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT t.*, p.codigo AS prioridad_codigo, p.nombre AS prioridad_nombre, p.color AS prioridad_color
|
||||
FROM turnero_turnos t
|
||||
JOIN turnero_prioridades p ON p.id = t.prioridad_id
|
||||
WHERE t.id = ? AND t.estado = "en_espera_lugar"'
|
||||
);
|
||||
$stmt->execute([$turnoId]);
|
||||
$turno = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$turno) {
|
||||
$pdo->rollBack();
|
||||
jsonError('El turno no está en espera o no existe.', 404);
|
||||
}
|
||||
} else {
|
||||
$turno = siguienteTurnoEnCola('en_espera_lugar', $lugarId);
|
||||
if (!$turno) {
|
||||
$pdo->rollBack();
|
||||
jsonOk(['turno' => null], 'Cola del lugar vacía');
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
|
||||
@@ -413,17 +413,29 @@ function renderCola(snap) {
|
||||
return;
|
||||
}
|
||||
lista.innerHTML = espera.map(t => `
|
||||
<div class="cola-card ${turnoActivo?.id === t.id ? 'activo' : ''}">
|
||||
<div class="cola-card ${turnoActivo?.id === t.id ? 'activo' : ''}"
|
||||
style="cursor:pointer" onclick="llamarTurnoEspecifico(${t.id})"
|
||||
title="Llamar turno ${escHtml(t.codigo)}">
|
||||
<div class="prio-dot" style="background:${t.prioridad_color}">${t.prioridad_codigo}</div>
|
||||
<div class="turno-info">
|
||||
<div class="cod">${escHtml(t.codigo)}</div>
|
||||
<div class="pac">${escHtml(t.paciente_nombre || 'Paciente')}</div>
|
||||
</div>
|
||||
<i class="fas fa-chevron-right text-muted ms-auto" style="font-size:.7rem"></i>
|
||||
</div>`).join('');
|
||||
}
|
||||
|
||||
// ── Llamar siguiente ──────────────────────────────────────────
|
||||
async function llamarSiguiente() {
|
||||
await _llamar({});
|
||||
}
|
||||
|
||||
async function llamarTurnoEspecifico(turnoId) {
|
||||
if (turnoActivo?.id === turnoId) return; // ya está abierto
|
||||
await _llamar({ turno_id: turnoId });
|
||||
}
|
||||
|
||||
async function _llamar(extra) {
|
||||
if (!lugarId) { alert('Primero seleccione un lugar.'); return; }
|
||||
const btn = document.getElementById('btn-llamar');
|
||||
btn.disabled = true;
|
||||
@@ -431,15 +443,11 @@ async function llamarSiguiente() {
|
||||
const res = await fetch(API + 'llamar_turno.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ area: 'lugar', lugar_id: lugarId }),
|
||||
body: JSON.stringify({ area: 'lugar', lugar_id: lugarId, ...extra }),
|
||||
});
|
||||
const json = await res.json();
|
||||
if (!json.ok) { alert('Error: ' + json.error); return; }
|
||||
|
||||
if (!json.turno) {
|
||||
alert('Cola del lugar vacía.');
|
||||
return;
|
||||
}
|
||||
if (!json.turno) { alert('Cola del lugar vacía.'); return; }
|
||||
await abrirFicha(json.turno);
|
||||
cargarCola();
|
||||
} catch (err) {
|
||||
@@ -494,11 +502,11 @@ async function cargarFichaSolicitud(turnoId) {
|
||||
document.getElementById('bloque-pac-info').style.display = '';
|
||||
document.getElementById('bloque-pac-sin').classList.add('d-none');
|
||||
document.getElementById('pac-nombre').textContent =
|
||||
(pac.full_name || (pac.nombre||'') + ' ' + (pac.apellido||'')).trim() || '—';
|
||||
pac.nombre_completo || pac.full_name || '—';
|
||||
document.getElementById('pac-doc').textContent =
|
||||
(pac.tipo_documento||'') + ' ' + (pac.documento||'') || '—';
|
||||
((pac.tipo_documento||'') + ' ' + (pac.numero_documento||pac.documento||'')).trim() || '—';
|
||||
document.getElementById('pac-fec').textContent = pac.fecha_nacimiento || '—';
|
||||
document.getElementById('pac-cel').textContent = pac.celular || pac.telefono || '—';
|
||||
document.getElementById('pac-cel').textContent = pac.telefono || pac.celular || '—';
|
||||
} else {
|
||||
document.getElementById('bloque-pac-info').style.display = 'none';
|
||||
document.getElementById('bloque-pac-sin').classList.remove('d-none');
|
||||
@@ -569,10 +577,10 @@ function renderConsentimientos(lista) {
|
||||
|
||||
// WA / Ver: según estado
|
||||
const btnWa = ya
|
||||
? (c.token ? `<button class="btn btn-outline-secondary" title="Ver firmado"
|
||||
onclick="window.open(BASE_WA+'ver_formulario_enviado.php?token='+encodeURIComponent('${token}'),'_blank')">
|
||||
? (c.token ? `<a href="${BASE_WA}ver_formulario_enviado.php?token=${token}" target="_blank"
|
||||
class="btn btn-outline-secondary" title="Ver firmado">
|
||||
<i class="fas fa-eye"></i> Ver
|
||||
</button>` : '')
|
||||
</a>` : '')
|
||||
: `<button class="btn btn-outline-success" title="Reenviar por WhatsApp"
|
||||
onclick="reenviarConsentimiento(${tId})">
|
||||
<i class="fab fa-whatsapp"></i> WA
|
||||
|
||||
@@ -992,7 +992,7 @@ function abrirFirmaEnfermero(formularioId, nombre) {
|
||||
document.getElementById('fe-nombre-consentimiento').textContent = nombre;
|
||||
if (!feCanvas._el) feCanvas.init();
|
||||
feCanvas.limpiar();
|
||||
const modal = bootstrap.Modal.getOrCreate(document.getElementById('modalFirmaEnfermero'));
|
||||
const modal = bootstrap.Modal.getOrCreateInstance(document.getElementById('modalFirmaEnfermero'));
|
||||
modal.show();
|
||||
}
|
||||
|
||||
@@ -1011,7 +1011,7 @@ async function feGuardarFirma() {
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.ok) {
|
||||
bootstrap.Modal.getInstance(document.getElementById('modalFirmaEnfermero')).hide();
|
||||
bootstrap.Modal.getOrCreateInstance(document.getElementById('modalFirmaEnfermero')).hide();
|
||||
mostrarToast('Firma del enfermero guardada', 'success');
|
||||
await refrescarConsentimientosLugar();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user