@php
$number_history = null;
if ($data && $data->patient_id) {
// 1) Intentar expediente por paciente + especialidad (si existe)
$historyQuery = \App\Models\History::where('patient_id', $data->patient_id)
->whereNotNull('number_history');
if (!empty($data->specialty_id)) {
$historyQuery->where('specialty_id', $data->specialty_id);
}
$history = $historyQuery->latest('id')->first();
// 2) Fallback: último expediente del paciente, sin filtrar especialidad
if (!$history || !$history->number_history) {
$history = \App\Models\History::where('patient_id', $data->patient_id)
->whereNotNull('number_history')
->latest('id')
->first();
}
if ($history && $history->number_history) {
$number_history = $history->number_history;
}
}
$patient_name = ($data && $data->patient && $data->patient->name) ? strtoupper($data->patient->name) : '';
$doctor_name = ($data && $data->medic && $data->medic->name) ? strtoupper($data->medic->name) : '';
$fecha_formateada = '';
$hora_formateada = '';
if($data && $data->date_quotes) {
$fecha = \Carbon\Carbon::parse($data->date_quotes);
$dias = ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'];
$meses = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'];
$dia_semana = $dias[$fecha->dayOfWeek];
$dia = $fecha->day;
$mes = $meses[$fecha->month - 1];
$anio = $fecha->year;
$fecha_formateada = ucfirst($dia_semana) . ' ' . $dia . ' de ' . $mes . ' ' . $anio;
}
if($data && !empty($data->hour)) {
try {
$hora_formateada = \Carbon\Carbon::parse($data->hour)->format('g:i A');
} catch (\Throwable $e) {
$hora_formateada = (string) $data->hour;
}
}
@endphp
| N° Expediente: {{ $number_history ? str_pad($number_history, 7, "0", STR_PAD_LEFT) : '' }} |
| Paciente: {{ $patient_name }} |
| Doctor: {{ $doctor_name }} |
| Fecha: {{ $fecha_formateada }} |
| Hora: {{ $hora_formateada }} |
|
@php
$detail = ($data && $data->detail) ? $data->detail : 'No especificado';
@endphp
MOTIVO DE CONSULTA:
{{ $detail }}
|
|