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