fix(turnero): no mostrar consentimientos de toma de muestras en recepcion
Agrega origen_lugar_id a turnero_consentimientos para distinguir consents creados por examen (null) vs por estación (= lugar_id destino). Recepcion filtra los de origen_lugar_id != null; lugar.php muestra solo los suyos + los de examen. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
333e856f38
commit
229977785b
@@ -0,0 +1,5 @@
|
||||
-- Separar consentimientos por examen vs por lugar destino
|
||||
-- Los creados desde turnero_lugar_consentimientos llevan origen_lugar_id = lugar_id de la estación
|
||||
-- Los creados desde exam_tipo_consentimientos quedan con origen_lugar_id = NULL
|
||||
ALTER TABLE turnero_consentimientos
|
||||
ADD COLUMN IF NOT EXISTS origen_lugar_id INT NULL DEFAULT NULL;
|
||||
@@ -12,6 +12,7 @@ $pendientes = [
|
||||
'20260703_medicos.sql',
|
||||
'20260703_medicos_seed.sql',
|
||||
'20260703_solicitud_medico.sql',
|
||||
'20260707_turnero_consent_origen_lugar.sql',
|
||||
];
|
||||
|
||||
$pdo = Database::getInstance()->getConnection();
|
||||
|
||||
@@ -37,6 +37,7 @@ $stmt = $pdo->prepare(
|
||||
tc.firmado_at,
|
||||
(tc.firma_profesional_svg IS NOT NULL) AS tiene_firma_profesional,
|
||||
tc.firmado_profesional_at,
|
||||
tc.origen_lugar_id,
|
||||
f.nombre AS formulario_nombre,
|
||||
f.esquema AS formulario_esquema
|
||||
FROM turnero_consentimientos tc
|
||||
@@ -139,7 +140,7 @@ if ($incluirSolicitud) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fuente 2: lugar destino del turno
|
||||
// Fuente 2: lugar destino del turno (marcamos origen_lugar_id para filtrar en recepcion)
|
||||
$lugarDestinoId = (int)($turno['lugar_destino_id'] ?? 0);
|
||||
if ($lugarDestinoId) {
|
||||
$stmtL = $pdo->prepare(
|
||||
@@ -152,6 +153,7 @@ if ($incluirSolicitud) {
|
||||
foreach ($stmtL->fetchAll(PDO::FETCH_ASSOC) as $r) {
|
||||
$fid = (int)$r['formulario_id'];
|
||||
if (!in_array($fid, $vistosFIds, true)) {
|
||||
$r['origen_lugar_id'] = $lugarDestinoId;
|
||||
$requeridos[] = $r;
|
||||
$vistosFIds[] = $fid;
|
||||
}
|
||||
@@ -163,8 +165,8 @@ if ($incluirSolicitud) {
|
||||
$existFormIds = array_map('intval', array_column($consentimientos, 'formulario_id'));
|
||||
$stmtIns = $pdo->prepare(
|
||||
"INSERT IGNORE INTO turnero_consentimientos
|
||||
(turno_id, formulario_id, token, estado)
|
||||
VALUES (?, ?, ?, 'pendiente')"
|
||||
(turno_id, formulario_id, token, estado, origen_lugar_id)
|
||||
VALUES (?, ?, ?, 'pendiente', ?)"
|
||||
);
|
||||
$creados = 0;
|
||||
foreach ($requeridos as $r) {
|
||||
@@ -177,7 +179,7 @@ if ($incluirSolicitud) {
|
||||
mt_rand(0,0x3fff)|0x8000,
|
||||
mt_rand(0,0xffff), mt_rand(0,0xffff), mt_rand(0,0xffff)
|
||||
);
|
||||
$stmtIns->execute([$turnoId, (int)$r['formulario_id'], $token]);
|
||||
$stmtIns->execute([$turnoId, (int)$r['formulario_id'], $token, $r['origen_lugar_id'] ?? null]);
|
||||
$creados++;
|
||||
}
|
||||
}
|
||||
@@ -189,6 +191,7 @@ if ($incluirSolicitud) {
|
||||
tc.estado, tc.enviado_at, tc.firmado_at,
|
||||
(tc.firma_profesional_svg IS NOT NULL) AS tiene_firma_profesional,
|
||||
tc.firmado_profesional_at,
|
||||
tc.origen_lugar_id,
|
||||
f.nombre AS formulario_nombre,
|
||||
f.esquema AS formulario_esquema
|
||||
FROM turnero_consentimientos tc
|
||||
|
||||
@@ -1096,6 +1096,8 @@ const CONSENT_LBL = {
|
||||
};
|
||||
|
||||
function renderConsentimientos(lista) {
|
||||
// Mostrar consentimientos de examen (origen null) + los de esta estación
|
||||
lista = lista.filter(c => !c.origen_lugar_id || c.origen_lugar_id == lugarId);
|
||||
tieneConsent = lista.length > 0;
|
||||
hayPendientes = lista.some(c => !['firmado','rechazado'].includes(c.estado));
|
||||
const pendCount = lista.filter(c => !['firmado','rechazado'].includes(c.estado)).length;
|
||||
|
||||
@@ -1629,6 +1629,8 @@ const CONSENT_META = {
|
||||
|
||||
function renderConsentimientos(lista) {
|
||||
const el = document.getElementById('lista-consentimientos');
|
||||
// Solo mostrar consentimientos de examen (origen_lugar_id null); los de toma de muestras se gestionan en lugar.php
|
||||
lista = lista.filter(c => !c.origen_lugar_id);
|
||||
if (!lista.length) {
|
||||
el.innerHTML = '<div class="text-muted small"><i class="fas fa-check-circle text-success me-1"></i>Sin consentimientos requeridos</div>';
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user