@php $history = $patient->clinicalHistory; $hasAlerts = $history && ($history->allergies || $history->contraindications || $history->special_conditions); $initials = collect(explode(' ', $patient->fullName()))->take(2)->map(fn($w) => strtoupper(substr($w,0,1)))->implode(''); $stats = [ ['n' => $history?->evolutions->count() ?? 0, 'label' => 'Evoluciones', 'color' => 'indigo', 'path' => 'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01'], ['n' => $history?->prescriptions->count() ?? 0, 'label' => 'Recetas', 'color' => 'emerald','path' => 'M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z'], ['n' => $history?->orders->count() ?? 0, 'label' => 'Órdenes', 'color' => 'amber', 'path' => 'M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414A1 1 0 0119 9.414V19a2 2 0 01-2 2z'], ['n' => $history?->consents->count() ?? 0, 'label' => 'Consentimientos', 'color' => 'violet', 'path' => 'M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z'], ]; @endphp {{-- Flash --}} @if(session('success'))
{{ session('success') }}
@endif {{-- ── HERO CARD ── --}}
{{-- Avatar --}}
{{ $initials }}
{{-- Datos --}}

{{ $patient->fullName() }}

@if($patient->is_active) Activo @else Inactivo @endif @if($patient->blood_type) 🩸 {{ $patient->blood_type }} @endif @if($history?->history_number) {{ $history->history_number }} @endif
@if($patient->birthdate) {{ $patient->birthdate->format('d/m/Y') }} · {{ $patient->age() }} años @endif @if($patient->gender) {{ ['male'=>'Masculino','female'=>'Femenino','other'=>'Otro'][$patient->gender] ?? $patient->gender }} @endif @if($patient->document_number) {{ strtoupper($patient->document_type ?? 'DOC') }} {{ $patient->document_number }} @endif {{ $patient->phone }} @if($patient->email) {{ $patient->email }} @endif
{{-- Acciones --}}
{{-- Alerta clínica --}} @if($hasAlerts)

Alertas clínicas

@if($history->allergies)

Alergias: {{ $history->allergies }}

@endif @if($history->contraindications)

Contraindicaciones: {{ $history->contraindications }}

@endif @if($history->special_conditions)

Condiciones especiales: {{ $history->special_conditions }}

@endif
@endif {{-- Stats strip --}} @php $statColors = [ 'indigo' => 'bg-indigo-50 text-indigo-600 border-indigo-100', 'emerald' => 'bg-emerald-50 text-emerald-600 border-emerald-100', 'amber' => 'bg-amber-50 text-amber-600 border-amber-100', 'violet' => 'bg-violet-50 text-violet-600 border-violet-100', ]; @endphp
@foreach($stats as $s)

{{ $s['n'] }}

{{ $s['label'] }}

@endforeach
{{-- ── BODY ── --}}
{{-- Sidebar --}}

Información

Editar
@if($patient->insurance_company)

EPS / Aseguradora

{{ $patient->insurance_company }}

@endif @if($patient->address)

Dirección

{{ $patient->address }}{{ $patient->city ? ', '.$patient->city : '' }}{{ $patient->country ? ', '.$patient->country : '' }}

@endif @if($patient->emergency_contact_name)

Emergencias

{{ $patient->emergency_contact_name }}

{{ $patient->emergency_contact_phone }}

@endif @if($patient->notes)

Notas

{{ $patient->notes }}

@endif @if(!$patient->insurance_company && !$patient->address && !$patient->emergency_contact_name && !$patient->notes)

Sin información adicional.

@endif
@if($history && $history->backgrounds->count())

Antecedentes

@foreach($history->backgrounds->groupBy('type') as $type => $items)

{{ \App\Models\ClinicalBackground::$types[$type] ?? $type }}

@foreach($items as $bg)

{{ $bg->description }}

@endforeach
@endforeach
@endif
{{-- Panel de tabs --}}
{{-- Tab bar --}} @php $tabs = [ 'timeline' => ['label'=>'Timeline', 'path'=>'M13 10V3L4 14h7v7l9-11h-7z'], 'evolutions' => ['label'=>'Evoluciones', 'path'=>'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01'], 'prescriptions' => ['label'=>'Recetas', 'path'=>'M19.428 15.428a2 2 0 00-1.022-.547l-2.387-.477a6 6 0 00-3.86.517l-.318.158a6 6 0 01-3.86.517L6.05 15.21a2 2 0 00-1.806.547M8 4h8l-1 1v5.172a2 2 0 00.586 1.414l5 5c1.26 1.26.367 3.414-1.415 3.414H4.828c-1.782 0-2.674-2.154-1.414-3.414l5-5A2 2 0 009 10.172V5L8 4z'], 'orders' => ['label'=>'Órdenes', 'path'=>'M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414A1 1 0 0119 9.414V19a2 2 0 01-2 2z'], 'consents' => ['label'=>'Consentimientos', 'path'=>'M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z'], 'files' => ['label'=>'Documentos', 'path'=>'M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13'], 'antecedentes' => ['label'=>'Antecedentes', 'path'=>'M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4'], ]; @endphp
{{-- ── TIMELINE ── --}}
@php $events = collect(); if ($history) { $events = $events ->merge($history->evolutions->map(fn($e) => ['type'=>'evolution', 'date'=>$e->created_at, 'model'=>$e])) ->merge($history->prescriptions->map(fn($p) => ['type'=>'prescription', 'date'=>$p->created_at, 'model'=>$p])) ->merge($history->orders->map(fn($o) => ['type'=>'order', 'date'=>$o->created_at, 'model'=>$o])) ->merge($history->consents->map(fn($c) => ['type'=>'consent', 'date'=>$c->created_at, 'model'=>$c])) ->merge($history->files->map(fn($f) => ['type'=>'file', 'date'=>$f->created_at, 'model'=>$f])) ->sortByDesc('date'); } $evCfg = [ 'evolution' => ['dot'=>'bg-indigo-500', 'ring'=>'ring-indigo-100', 'card'=>'border-indigo-100 hover:border-indigo-200 hover:bg-indigo-50/40', 'link'=>'text-indigo-600', 'badge'=>'bg-indigo-50 text-indigo-700', 'label'=>'Evolución clínica'], 'prescription' => ['dot'=>'bg-emerald-500', 'ring'=>'ring-emerald-100', 'card'=>'border-emerald-100 hover:border-emerald-200 hover:bg-emerald-50/40','link'=>'text-emerald-600','badge'=>'bg-emerald-50 text-emerald-700','label'=>'Prescripción'], 'order' => ['dot'=>'bg-amber-500', 'ring'=>'ring-amber-100', 'card'=>'border-amber-100 hover:border-amber-200 hover:bg-amber-50/40', 'link'=>'text-amber-600', 'badge'=>'bg-amber-50 text-amber-700', 'label'=>'Orden médica'], 'consent' => ['dot'=>'bg-violet-500', 'ring'=>'ring-violet-100', 'card'=>'border-violet-100 hover:border-violet-200 hover:bg-violet-50/40', 'link'=>'text-violet-600', 'badge'=>'bg-violet-50 text-violet-700', 'label'=>'Consentimiento'], 'file' => ['dot'=>'bg-gray-400', 'ring'=>'ring-gray-100', 'card'=>'border-gray-100', 'link'=>'text-gray-600', 'badge'=>'bg-gray-100 text-gray-600', 'label'=>'Documento'], ]; @endphp @if($events->isEmpty())

Sin eventos registrados

Crea la primera evolución clínica del paciente.

Nueva evolución
@else
@foreach($events as $ev) @php $cfg = $evCfg[$ev['type']] ?? $evCfg['file']; $m = $ev['model']; @endphp
{{ $cfg['label'] }} @if($ev['type']==='evolution')

{{ Str::limit($m->consultation_reason, 100) }}

@if($m->employee)

Por: {{ $m->employee->user?->name ?? '—' }}

@endif @elseif($ev['type']==='prescription')

{{ $m->prescription_number }}

{{ $m->items->count() }} medicamento(s)

@elseif($ev['type']==='order')

{{ $m->title }}

{{ $m->typeLabel() }}

@elseif($ev['type']==='consent')

{{ $m->title }}

@else

{{ $m->title ?? $m->original_name }}

@endif

{{ $ev['date']->format('d/m/Y') }}

{{ $ev['date']->format('H:i') }}

@if($ev['type']==='evolution') Ver evolución → PDF @elseif($ev['type']==='prescription') Ver receta → @if($m->isSigned())PDF@endif @elseif($ev['type']==='order') Ver orden → @if($m->isSigned())PDF@endif @endif
@endforeach
@endif
{{-- ── EVOLUCIONES ── --}} {{-- ── RECETAS ── --}} {{-- ── ÓRDENES ── --}}

Órdenes y recomendaciones

Nueva orden
@forelse($history?->orders ?? [] as $order)

{{ $order->title }}

{{ $order->typeLabel() }} · {{ $order->created_at->format('d/m/Y') }}

{{ $order->status==='signed' ? 'Firmada' : 'Borrador' }}
@empty

Sin órdenes aún.

@endforelse
{{-- ── CONSENTIMIENTOS ── --}}

Consentimientos informados

@forelse($history?->consents ?? [] as $consent)

{{ $consent->title }}

{{ $consent->created_at->format('d/m/Y') }}@if($consent->signer_name) · {{ $consent->signer_name }}@endif

{{ ucfirst($consent->status) }}
@empty

Sin consentimientos registrados.

@endforelse
{{-- ── DOCUMENTOS ── --}}

Documentos adjuntos

@forelse($history?->files ?? [] as $file)

{{ $file->title ?? $file->original_name }}

{{ $file->created_at->format('d/m/Y') }} · {{ number_format($file->size_bytes/1024,1) }} KB

Descargar
@empty

Sin documentos adjuntos.

@endforelse
{{-- ── ANTECEDENTES ── --}}

Antecedentes y datos médicos

@if($history)
@csrf @method('PUT')
@foreach([ 'allergies' => 'Alergias', 'diseases' => 'Enfermedades', 'current_medications' => 'Medicamentos actuales', 'previous_procedures' => 'Procedimientos previos', 'contraindications' => 'Contraindicaciones', 'special_conditions' => 'Condiciones especiales', 'medical_notes' => 'Notas médicas', ] as $field => $label)
@endforeach
@else

No hay historia clínica creada para este paciente.

@endif