@props(['vaccine', 'tipo', 'rut', 'program' => '']) @php $estadoDocumento = null; $iconoEstado = '❌'; $textoEstado = 'No subido'; $claseEstado = 'text-muted'; // 1. Detectar si aplica lógica de IA para Tecnología Médica $esTecnoMedica = str_contains(strtolower($program), 'tecnolog'); $auditoria = ($vaccine && isset($vaccine['auditoria_ia'])) ? $vaccine['auditoria_ia'] : null; // 2. Calcular Estado Tradicional (Fechas) if ($vaccine && $vaccine['preview'] !== null) { if (in_array($tipo, ['Influenza', 'Covid']) && isset($vaccine['date'])) { try { $fechaVacuna = \Carbon\Carbon::parse($vaccine['date']); $now = now(); if ($tipo === 'Influenza') { $currentMarch = \Carbon\Carbon::create($now->year, 3, 1)->startOfDay(); $lastMarch = \Carbon\Carbon::create($now->year - 1, 3, 1)->startOfDay(); $currentApril = \Carbon\Carbon::create($now->year, 4, 30)->endOfDay(); if ($fechaVacuna->greaterThanOrEqualTo($currentMarch)) { $estadoDocumento = 'valid'; } elseif ($fechaVacuna->greaterThanOrEqualTo($lastMarch) && $now->lessThanOrEqualTo($currentApril)) { $estadoDocumento = 'expiring'; } else { $estadoDocumento = 'expired'; } } elseif ($tipo === 'Covid') { $elevenMonthsAgo = $now->copy()->subMonths(11)->startOfDay(); $twelveMonthsAgo = $now->copy()->subMonths(12)->startOfDay(); if ($fechaVacuna->lessThanOrEqualTo($elevenMonthsAgo) && $fechaVacuna->greaterThan($twelveMonthsAgo)) { $estadoDocumento = 'expiring'; } elseif ($fechaVacuna->year === $now->year || $fechaVacuna->greaterThan($twelveMonthsAgo)) { $estadoDocumento = 'valid'; } else { $estadoDocumento = 'expired'; } } if ($estadoDocumento === 'expiring') { $iconoEstado = '⏰'; $textoEstado = 'Próx. a vencer'; $claseEstado = 'text-warning'; } elseif ($estadoDocumento === 'expired') { $iconoEstado = '⚠️'; $textoEstado = 'Vencido'; $claseEstado = 'text-danger'; } else { $iconoEstado = '✅'; $textoEstado = 'Vigente'; $claseEstado = 'text-success'; } } catch (\Exception $e) { $iconoEstado = '✅'; $textoEstado = 'Subido'; $claseEstado = 'text-success'; } } else { $iconoEstado = '✅'; $textoEstado = 'Subido'; $claseEstado = 'text-success'; } // --- NUEVA LÓGICA TEMPORAL MIGRACIÓN HEPATITIS B --- if ($tipo === 'Hepatitis B') { if (empty($vaccine['fecha_2']) || empty($vaccine['fecha_3'])) { $iconoEstado = '⚠️'; $textoEstado = 'Fechas Pdte.'; $claseEstado = 'text-warning fw-bold'; } } } // 3. Preparar Variables Visuales para la Capa de IA $iaIcono = ''; $iaTexto = ''; $iaClase = ''; $permitirAuditar = false; $resValidacion = ''; $veto = 0; $iaCorrecta = null; if ($esTecnoMedica && $vaccine && $vaccine['preview']) { if (!$auditoria) { $iaIcono = 'fas fa-hourglass-half'; $iaTexto = 'En cola IA'; $iaClase = 'bg-light text-secondary border'; } else { $resValidacion = $auditoria['resultado_validacion'] ?? ''; $veto = $auditoria['veto_humano'] ?? 0; $iaCorrecta = $auditoria['ia_fue_correcta'] ?? null; if (($resValidacion === 'OBSERVADO' && is_null($iaCorrecta)) || ($resValidacion === 'APROBADO' && $veto === 0 && is_null($iaCorrecta))) { $permitirAuditar = true; } if (!$permitirAuditar) { if ($resValidacion === 'APROBADO') { if ($veto === 1 && $iaCorrecta === 0) { $iaIcono = 'fas fa-user-check'; $iaTexto = 'Aprobado Usuario'; $iaClase = 'bg-info text-dark shadow-sm'; } else { $iaIcono = 'fas fa-check-double'; $iaTexto = 'Aprobado (Verificado)'; $iaClase = 'bg-success text-white shadow-sm'; } } elseif ($resValidacion === 'OBSERVADO') { if ($veto === 1 && $iaCorrecta === 0) { $iaIcono = 'fas fa-user-times'; $iaTexto = 'Rechazado Usuario'; $iaClase = 'bg-danger text-white shadow-sm cursor-pointer'; } else { $iaIcono = 'fas fa-check-double'; $iaTexto = 'Alerta Confirmada'; $iaClase = 'bg-secondary text-white shadow-sm'; } } elseif ($resValidacion === 'PENDIENTE_IA') { $iaIcono = 'fas fa-spinner fa-spin'; $iaTexto = 'Analizando...'; $iaClase = 'bg-warning text-dark shadow-sm'; } } } } @endphp @if (!$vaccine || $vaccine['preview'] === null)
No subido
S/I
@else
{{-- 1. Estado Base (Fechas) --}}
{{ $iconoEstado }} {{ $textoEstado }}
Ver @if(request('documents') === 'missing_doses' && $tipo === 'Hepatitis B') @php // Limpiamos y formateamos estrictamente con Try/Catch por seguridad $fecha3ra = ''; $fecha2da = ''; $fecha1ra = ''; try { $fecha3ra = !empty($vaccine['date']) ? \Carbon\Carbon::parse($vaccine['date'])->format('Y-m-d') : ''; } catch(\Exception $e) {} try { $fecha2da = !empty($vaccine['fecha_2']) ? \Carbon\Carbon::parse($vaccine['fecha_2'])->format('Y-m-d') : ''; } catch(\Exception $e) {} try { $fecha1ra = !empty($vaccine['fecha_3']) ? \Carbon\Carbon::parse($vaccine['fecha_3'])->format('Y-m-d') : ''; } catch(\Exception $e) {} @endphp @else @endif
{{-- 3. CAPA DE INTELIGENCIA ARTIFICIAL UNIFICADA --}} @if ($esTecnoMedica)
@if ($permitirAuditar) @php $esAprobado = ($resValidacion === 'APROBADO'); $btnClass = $esAprobado ? 'btn-success' : 'btn-danger'; $btnIcon = $esAprobado ? 'fas fa-robot' : 'fas fa-exclamation-triangle'; $btnText = $esAprobado ? 'Aprobado IA' : 'Alerta IA'; @endphp @else {{ $iaTexto }} @endif
@endif {{-- 4. Fechas Informativas --}} @if (isset($vaccine['date']))
{{-- LÓGICA DE HEPATITIS B --}} @if ($tipo === 'Hepatitis B') @if(!empty($vaccine['fecha_2']) && !empty($vaccine['fecha_3'])) {{-- CASO IDEAL: Tiene las 3 fechas --}}
{{ \Carbon\Carbon::parse($vaccine['date'])->format('d/m/Y') }}
(3 dosis completas)
@else {{-- CASO MIGRACIÓN: Faltan dosis --}}
{{ \Carbon\Carbon::parse($vaccine['date'])->format('d/m/Y') }} (Faltan dosis 1 o 2)
@endif {{-- LÓGICA DE OTRAS VACUNAS --}} @else
@php try { $fechaFormateada = \Carbon\Carbon::parse($vaccine['date'])->format('d/m/Y'); } catch (\Exception $e) { $fechaFormateada = 'Inválida'; } @endphp {{ $fechaFormateada }}
@endif
@endif
@endif @push('scripts') @endpush