Vincular turnos por muestra pendiente y precargar Datos Toma de Muestras
El turno original no se modifica (queda finalizado igual que antes) — solo se agrega trazabilidad: turnero_muestras.recibida_en_turno_id registra en qué turno se completó una muestra que había quedado pendiente en otra visita. Historial, bandeja y lugar.php ahora muestran un chip/botón "Turno vinculado" en ambos sentidos (origen ⇄ seguimiento) con acceso directo. Además, al abrir un formulario "Datos Toma de Muestras" pendiente para una visita de seguimiento, aparece un botón para cargar las respuestas del último formulario firmado de ese mismo paciente (sin firma ni identidad del profesional anterior) — evita reescribir la historia clínica; la firma y fecha siguen siendo las de hoy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
8e1f46904c
commit
538ee8ad25
@@ -34,6 +34,7 @@ if ($modoTurnero) {
|
||||
tc.siguiente_toma_at, tc.toma_inicio_at,
|
||||
f.nombre AS form_nombre, f.categoria, f.descripcion AS form_descripcion,
|
||||
f.esquema, f.es_toma_progresiva, f.solo_profesional, f.doc_encabezado, f.doc_subtitulo, f.doc_logo_base64, f.doc_color, f.doc_pie_pagina,
|
||||
p.id AS paciente_id,
|
||||
p.nombre_completo AS paciente_nombre,
|
||||
p.numero_documento, p.tipo_documento,
|
||||
p.fecha_nacimiento, p.telefono AS paciente_telefono, p.eps,
|
||||
@@ -986,6 +987,15 @@ function _addExamWizardHtml(string $cid): string {
|
||||
<i class="fas fa-wpforms me-1"></i>
|
||||
<?= $modoEditar ? 'Formulario de consentimiento' : 'Respuestas del formulario' ?>
|
||||
</div>
|
||||
<?php if ($modoTurnero && $modoEditar && !empty($tcRow['paciente_id'])): ?>
|
||||
<button type="button" id="btnCargarAnterior" class="btn btn-outline-primary btn-sm no-print mb-3"
|
||||
data-paciente="<?= (int)$tcRow['paciente_id'] ?>"
|
||||
data-formulario="<?= (int)$tcRow['formulario_id'] ?>"
|
||||
data-turno="<?= (int)$tcRow['turno_id'] ?>">
|
||||
<i class="fas fa-history me-1"></i>Cargar datos de la visita anterior
|
||||
</button>
|
||||
<div id="cargarAnteriorMsg" class="small text-muted mb-2" style="display:none"></div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
$paciente = $datosPrefilled['__paciente'] ?? [];
|
||||
|
||||
@@ -2193,6 +2203,56 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
window._fpwPreFirma = <?= json_encode($firmaProfPreguardada) ?>;
|
||||
window._profNombre = <?= json_encode($profNombre) ?>;
|
||||
window._profDocumento = <?= json_encode($profDocumento) ?>;
|
||||
|
||||
// ── Cargar datos de la visita anterior (mismo formulario, mismo paciente) ──
|
||||
(function() {
|
||||
var btn = document.getElementById('btnCargarAnterior');
|
||||
if (!btn) return;
|
||||
btn.addEventListener('click', function() {
|
||||
var base = window.location.href.split('/ver_formulario_enviado.php')[0];
|
||||
var msg = document.getElementById('cargarAnteriorMsg');
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Buscando…';
|
||||
var params = new URLSearchParams({
|
||||
paciente_id: btn.dataset.paciente,
|
||||
formulario_id: btn.dataset.formulario,
|
||||
exclude_turno_id: btn.dataset.turno,
|
||||
});
|
||||
fetch(base + '/modules/turnero/api/get_formulario_anterior.php?' + params)
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(json) {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fas fa-history me-1"></i>Cargar datos de la visita anterior';
|
||||
if (!json.ok || !json.encontrado) {
|
||||
msg.style.display = '';
|
||||
msg.textContent = 'No hay una visita anterior con este formulario firmado.';
|
||||
return;
|
||||
}
|
||||
var datos = json.datos_respuestas || {};
|
||||
document.querySelectorAll('[name]').forEach(function(el) {
|
||||
var raw = el.name, isArr = raw.slice(-2) === '[]', name = isArr ? raw.slice(0, -2) : raw;
|
||||
if (!(name in datos)) return;
|
||||
var val = datos[name];
|
||||
if (el.type === 'checkbox') {
|
||||
var arr = Array.isArray(val) ? val : [val];
|
||||
el.checked = arr.includes(el.value);
|
||||
} else if (el.type === 'radio') {
|
||||
el.checked = (el.value === val);
|
||||
} else {
|
||||
el.value = val;
|
||||
}
|
||||
});
|
||||
msg.style.display = '';
|
||||
msg.textContent = 'Datos cargados de la visita ' + (json.turno_codigo || '') + '. Revise y firme.';
|
||||
})
|
||||
.catch(function() {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<i class="fas fa-history me-1"></i>Cargar datos de la visita anterior';
|
||||
msg.style.display = '';
|
||||
msg.textContent = 'Error de conexión.';
|
||||
});
|
||||
});
|
||||
})();
|
||||
<?php if (!empty($_mpSiguienteTomAt)): ?>
|
||||
// Fix 1: recuperar countdown si el modal fue cerrado y reabierto mientras una toma estaba en curso
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user