fix: no mostrar consentimientos de toma de muestras al guardar en recepción

create_solicitud.php: cambia de crear consents por lugar (toma de muestras)
a crear consents por examen (exam_tipo_consentimientos). Los de lugar se
crean cuando el paciente llega a la estación vía get_consentimientos.php.

get_consentimientos.php: cuando lugar_destino_id es NULL (turno en recepción),
busca TODOS los formularios de turnero_lugar_consentimientos y los marca con
origen_lugar_id = -1 (truthy), para que el filtro !c.origen_lugar_id de
recepcion.php los excluya correctamente aunque no haya destino asignado aún.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-08 09:23:54 -05:00
co-authored by Claude Sonnet 4.6
parent 7b4827f70f
commit 3062cd7e95
2 changed files with 43 additions and 29 deletions
+12 -2
View File
@@ -26,7 +26,11 @@ $stmt->execute([$turnoId]);
$turno = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$turno) jsonError('Turno no encontrado.', 404);
// ── Formularios asignados al lugar destino (calculado al vuelo, sin depender de origen_lugar_id) ──
// ── Formularios de lugar ──────────────────────────────────────────────────────
// Si el turno ya tiene lugar destino asignado, usar solo ese lugar.
// Si aún está en recepción (lugar_destino_id NULL), marcar como "de lugar" todos
// los formularios configurados en cualquier lugar para que recepcion.php los filtre
// con !c.origen_lugar_id aunque todavía no exista destino.
$lugarDestinoId = (int)($turno['lugar_destino_id'] ?? 0);
$fidsDeLugar = [];
if ($lugarDestinoId) {
@@ -35,6 +39,12 @@ if ($lugarDestinoId) {
);
$stmtL->execute([$lugarDestinoId]);
$fidsDeLugar = array_map('intval', $stmtL->fetchAll(PDO::FETCH_COLUMN));
} else {
$stmtL = $pdo->prepare(
"SELECT DISTINCT formulario_id FROM turnero_lugar_consentimientos"
);
$stmtL->execute();
$fidsDeLugar = array_map('intval', $stmtL->fetchAll(PDO::FETCH_COLUMN));
}
// ── Consentimientos ───────────────────────────────────────────
@@ -87,7 +97,7 @@ foreach ($consentimientos as &$c) {
$c['requiere_firma_profesional'] = $tieneFirmaPro;
$c['requiere_firma_paciente'] = !($tieneFirmaPro && !$tieneFirmaPac);
$c['origen_lugar_id'] = in_array((int)$c['formulario_id'], $fidsDeLugar, true)
? $lugarDestinoId : null;
? ($lugarDestinoId ?: -1) : null;
$c['es_toma_progresiva'] = $esTomaProg;
$c['tomas_total'] = $tomasTotal;
$c['tomas_firmadas'] = $tomasFirm;