up
This commit is contained in:
+87
-1
@@ -520,6 +520,41 @@ $domIdParam = (int)($_GET['id'] ?? 0);
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ═══════════════ MODAL: Reprogramar Domicilio ═══════════════ -->
|
||||
<div class="modal fade" id="modalReprogramar" tabindex="-1">
|
||||
<div class="modal-dialog modal-sm">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header py-2" style="background:#6f42c1;color:#fff">
|
||||
<h6 class="modal-title mb-0"><i class="fas fa-calendar-alt me-1"></i>Reprogramar domicilio</h6>
|
||||
<button class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input type="hidden" id="repr-dom-id">
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Nueva fecha <span class="text-danger">*</span></label>
|
||||
<input type="date" class="form-control form-control-sm" id="repr-fecha">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label small fw-semibold">Nueva hora</label>
|
||||
<input type="time" class="form-control form-control-sm" id="repr-hora">
|
||||
</div>
|
||||
<div class="mb-2">
|
||||
<label class="form-label small fw-semibold">Motivo / nota</label>
|
||||
<textarea class="form-control form-control-sm" id="repr-motivo" rows="2"
|
||||
placeholder="Ej: Paciente solicitó cambio…"></textarea>
|
||||
</div>
|
||||
<div id="repr-error" class="text-danger small d-none">Debes ingresar la nueva fecha.</div>
|
||||
</div>
|
||||
<div class="modal-footer py-2">
|
||||
<button class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Cancelar</button>
|
||||
<button class="btn btn-sm text-white" style="background:#6f42c1" onclick="confirmarReprogramar()">
|
||||
<i class="fas fa-calendar-check me-1"></i>Reprogramar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal Asignar / Reasignar Enfermero -->
|
||||
<div class="modal fade" id="modalAsignarEnf" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
@@ -768,6 +803,13 @@ async function verDomicilio(id) {
|
||||
en_camino: [['en_domicilio','En domicilio','warning']],
|
||||
en_domicilio:[['completado','Completar','success']],
|
||||
};
|
||||
// Reprogramar disponible en estados abiertos (excepto en camino / en domicilio)
|
||||
const puedeReprogramar = ['programado','confirmado'].includes(dom.estado);
|
||||
const btnRepr = puedeReprogramar
|
||||
? `<button class="btn btn-sm" style="background:#6f42c1;color:#fff" onclick="abrirReprogramar(${dom.id})">
|
||||
<i class="fas fa-calendar-alt me-1"></i>Reprogramar
|
||||
</button>`
|
||||
: '';
|
||||
const btns = (SIGUIENTES[dom.estado]||[]).map(([e,lbl,col]) =>
|
||||
`<button class="btn btn-sm btn-${col}" onclick="cambiarEstado(${dom.id},'${e}')">
|
||||
<i class="fas fa-arrow-right me-1"></i>${lbl}
|
||||
@@ -824,7 +866,23 @@ async function verDomicilio(id) {
|
||||
<!-- Orden médica -->
|
||||
${renderOrdenesDetail(dom)}
|
||||
<!-- Botones de flujo -->
|
||||
<div class="d-flex gap-2 flex-wrap">${btns}</div>
|
||||
<div class="d-flex gap-2 flex-wrap">${btns}${btnRepr}</div>
|
||||
<!-- Vínculos reprogramación -->
|
||||
${dom.domicilio_origen_id ? `
|
||||
<div class="alert alert-warning py-2 small mt-2 mb-0">
|
||||
<i class="fas fa-history me-1"></i>
|
||||
Reprogramado desde domicilio
|
||||
<a href="#" onclick="event.preventDefault();verDomicilio(${dom.domicilio_origen_id})" class="fw-semibold">#${dom.domicilio_origen_id}</a>
|
||||
${dom.origen_info ? `(${esc(dom.origen_info.fecha_programada)})` : ''}
|
||||
</div>` : ''}
|
||||
${dom.reprogramaciones && dom.reprogramaciones.length ? `
|
||||
<div class="alert alert-info py-2 small mt-2 mb-0">
|
||||
<i class="fas fa-calendar-check me-1"></i>
|
||||
Reprogramado a:
|
||||
${dom.reprogramaciones.map(r =>
|
||||
`<a href="#" onclick="event.preventDefault();verDomicilio(${r.id})" class="fw-semibold">#${r.id}</a> (${esc(r.fecha_programada)})`
|
||||
).join(', ')}
|
||||
</div>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-3">
|
||||
@@ -1106,6 +1164,34 @@ async function confirmarAsignacion() {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Reprogramar domicilio ───────────────────────────────────
|
||||
let _reprModal = null;
|
||||
function abrirReprogramar(id) {
|
||||
document.getElementById('repr-dom-id').value = id;
|
||||
document.getElementById('repr-fecha').value = '';
|
||||
document.getElementById('repr-hora').value = _domActual?.hora_programada?.slice(0,5) || '';
|
||||
document.getElementById('repr-motivo').value = '';
|
||||
document.getElementById('repr-error').classList.add('d-none');
|
||||
if (!_reprModal) _reprModal = new bootstrap.Modal('#modalReprogramar');
|
||||
_reprModal.show();
|
||||
}
|
||||
async function confirmarReprogramar() {
|
||||
const id = +document.getElementById('repr-dom-id').value;
|
||||
const fecha = document.getElementById('repr-fecha').value;
|
||||
const hora = document.getElementById('repr-hora').value;
|
||||
const motivo = document.getElementById('repr-motivo').value.trim();
|
||||
if (!fecha) { document.getElementById('repr-error').classList.remove('d-none'); return; }
|
||||
_reprModal.hide();
|
||||
const r = await fetch('api/lab/save_domicilio.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id, reprogramar: true, nueva_fecha: fecha, nueva_hora: hora, motivo }),
|
||||
});
|
||||
const d = await r.json();
|
||||
mostrarToast(d.success ? d.message : (d.error || 'Error'), d.success ? 'success' : 'danger');
|
||||
if (d.success) { cargarLista(paginaActual); verDomicilio(id); }
|
||||
}
|
||||
|
||||
// ── Cambio de estado ───────────────────────────────────────────────────────
|
||||
async function cambiarEstado(id, estado) {
|
||||
if (!confirm(`¿Cambiar estado a "${estado}"?`)) return;
|
||||
|
||||
Reference in New Issue
Block a user