@extends('dashboard.admin.layouts.master') @php $bookings = $overview['bookings']; $stats = $overview['stats']; $money = fn ($amount) => number_format((float) $amount, 2); $na = trans('clinic.common.not_available'); $tabs = array_filter([ 'main' => ['bi-person-vcard', trans('clinic.patients.tab_main'), null], 'medical' => $canViewMedical ? ['bi-heart-pulse', trans('clinic.patient_profile.medical_history'), null] : null, 'bookings' => ['bi-calendar-check', trans('clinic.doctors.tab_bookings'), $bookings->count()], 'visits' => $canViewMedical ? ['bi-clipboard2-pulse', trans('clinic.patients.tab_visits'), $overview['visits']->count()] : null, 'files' => ['bi-folder2-open', trans('clinic.patient_files.title'), $attachments->count()], 'payments' => ['bi-credit-card', trans('clinic.patients.tab_payments'), $overview['payments']->count()], 'followups' => ['bi-arrow-repeat', trans('clinic.followups.title'), $overview['followups']->count()], 'offers' => ['bi-tags', trans('clinic.patients.tab_offers'), $overview['subscriptions']->count()], 'reviews' => ['bi-star', trans('clinic.patients.tab_reviews'), $overview['reviews']->count()], ]); $activeTab = $errors->hasAny(['files', 'files.*', 'category_id', 'label']) ? 'files' : 'main'; @endphp @section('toolbar')

{{ trans('clinic.patients.details') }}

{{ trans('clinic.common.back') }} @can('clinic.bookings.create') {{ trans('clinic.bookings.add') }} @endcan @can('clinic.medicine_orders.create') {{ trans('clinic.medicine_orders.add') }} @endcan @can('clinic.patients.edit') {{ trans('core.common.edit') }} @endcan
@endsection @section('content')
{{-- Header --}}
{{ mb_substr((string) $patient->name, 0, 1) }}
{{ $patient->name }}
{{ $patient->phone ?: $na }} {{ $patient->email ?: $na }} @if ($profile?->date_of_birth) {{ trans('clinic.patients.age', ['age' => \Illuminate\Support\Carbon::parse($profile->date_of_birth)->age]) }} @endif
@foreach (array_filter([ ['bi-calendar-check', 'primary', $stats['total'], trans('clinic.patients.stat_bookings')], ['bi-check2-circle', 'success', $stats['completed'], trans('clinic.patients.stat_completed')], ['bi-hourglass-split', 'warning', $stats['upcoming'], trans('clinic.patients.stat_upcoming')], ['bi-x-circle', 'danger', $stats['cancelled'], trans('clinic.patients.stat_cancelled')], auth('admin')->user()->can('clinic.reports.view') ? ['bi-cash-coin', 'info', $money($stats['spent']), trans('clinic.patients.stat_spent')] : null, ]) as [$icon, $color, $value, $label])
{{ $value }}
{{ $label }}
@endforeach
{{-- Main data --}}
@foreach ([ [trans('clinic.patients.phone'), $patient->phone, 'ltr'], [trans('clinic.patients.email'), $patient->email, 'ltr'], [trans('clinic.patients.address'), $patient->address, 'auto'], [trans('clinic.patients.date_of_birth'), $profile?->date_of_birth ? \Illuminate\Support\Carbon::parse($profile->date_of_birth)->format('Y-m-d') : null, 'ltr'], [trans('clinic.patients.gender'), $profile?->gender ? trans('clinic.patients.gender_' . $profile->gender) : null, 'auto'], [trans('clinic.patients.occupation'), $profile?->occupation, 'auto'], [trans('clinic.patients.registered'), $patient->created_at?->format('Y-m-d'), 'ltr'], [trans('clinic.patients.last_visit'), $stats['last_visit']?->format('Y-m-d'), 'ltr'], ] as [$label, $value, $dir])
{{ $label }}
{{ $value ?: $na }}
@endforeach
{{-- Medical history --}} @if ($canViewMedical)
@if (! $profile)
{{ trans('clinic.patients.no_medical_profile') }}
@else

{{ trans('clinic.patient_profile.medical_history') }}

@php($conditions = $conditionOptions->filter(fn ($option) => ! empty($profile->medical_history[$option->code] ?? false))) @forelse ($conditions as $option) {{ $option->name }} @empty {{ $na }} @endforelse @if (! empty($profile->medical_history['other'] ?? null))

{{ trans('clinic.patient_profile.other') }}: {{ $profile->medical_history['other'] }}

@endif

{{ trans('clinic.patient_profile.medication_history') }}

@php($medications = $medicationOptions->filter(fn ($option) => ! empty($profile->medication_history[$option->code] ?? false))) @forelse ($medications as $option) {{ $option->name }} @empty {{ $na }} @endforelse @foreach (['other', 'notes'] as $key) @if (! empty($profile->medication_history[$key] ?? null))

{{ trans('clinic.patient_profile.' . $key) }}: {{ $profile->medication_history[$key] }}

@endif @endforeach

{{ trans('clinic.patient_profile.surgical_history') }}

@if (! empty($profile->surgical_history['had_surgery'] ?? false))
{{ $profile->surgical_history['type'] ?? '' }}
{{ $profile->surgical_history['hospital'] ?? '' }} · {{ $profile->surgical_history['date'] ?? '' }}
@else {{ $na }} @endif

{{ trans('clinic.patient_profile.allergies') }}

@if ($profile->allergy_type) {{ trans('clinic.patient_profile.allergy_types.' . $profile->allergy_type) }} {{ $profile->allergy_substance }} @if ($profile->allergy_severity) ({{ trans('clinic.patient_profile.severities.' . $profile->allergy_severity) }}) @endif @if ($profile->allergy_notes)
{{ $profile->allergy_notes }}
@endif @else {{ $na }} @endif
@endif
@endif {{-- Bookings --}}
@foreach ($bookings as $booking) @endforeach
{{ trans('clinic.bookings.date') }} {{ trans('clinic.doctors.title') }} {{ trans('clinic.clinics.title') }} {{ trans('clinic.bookings.type') }} {{ trans('clinic.doctors.price') }} {{ trans('clinic.bookings.status') }}
{{ $booking->scheduled_at?->format('Y-m-d') }}
{{ $booking->scheduled_at?->format('h:i A') }}
{{ $booking->doctor?->name }}
{{ $booking->doctor?->specialty?->name }}
{{ $booking->clinicProfile?->name ?? $booking->branch?->name }} {{ trans('clinic.bookings.' . $booking->type) }} {{ $money($booking->price) }} {{ trans('clinic.bookings.statuses.' . $booking->status) }}
{{-- Visits and medical records --}} @if ($canViewMedical)
@forelse ($overview['visits'] as $booking)
{{ $booking->doctor?->name }} · {{ $booking->doctor?->specialty?->name }} {{ $booking->scheduled_at?->format('Y-m-d h:i A') }}
{{ trans('clinic.bookings.' . $booking->type) }}
@foreach (['diagnosis', 'prescription', 'report'] as $field)
{{ trans('clinic.medical_records.' . $field) }}
{!! nl2br(e($booking->medicalRecord->{$field} ?: $na)) !!}
@endforeach
@if ($booking->medicalRecord->attachment_path || $booking->attachments->isNotEmpty())
@if ($booking->medicalRecord->attachment_path) {{ trans('doctor.visits.view_file') }} @endif @foreach ($booking->attachments as $bookingAttachment) {{ $bookingAttachment->label ?: trans('clinic.patient_files.view_file') }} @endforeach
@endif
@empty
{{ trans('clinic.patients.no_visits') }}
@endforelse
@endif {{-- Files --}}
@can('clinic.patient_attachments.manage')
@csrf
@foreach (['category_id', 'label', 'files', 'files.*'] as $field) @error($field)
{{ $message }}
@enderror @endforeach
@endcan @if ($attachments->isEmpty())
{{ trans('clinic.patient_files.none') }}
@else
@foreach ($attachments as $attachment)
{{ $attachment->label ?: trans('clinic.patient_files.view_file') }}
{{ $attachment->category->name ?? $na }} · {{ $attachment->uploadedBy->name ?? $na }} · {{ $attachment->created_at?->format('Y-m-d') }}
@can('clinic.patient_attachments.manage')
@csrf @method('DELETE')
@endcan
@endforeach
@endif
{{-- Payments --}}
@if ($overview['payments']->isEmpty())
{{ trans('clinic.patients.no_payments') }}
@else
@foreach ($overview['payments'] as $payment) @endforeach
{{ trans('clinic.patients.payment_date') }} {{ trans('clinic.doctors.title') }} {{ trans('clinic.patients.payment_method') }} {{ trans('clinic.patients.payment_amount') }} {{ trans('clinic.bookings.status') }}
{{ ($payment->paid_at ?? $payment->created_at)?->format('Y-m-d H:i') }} {{ $payment->booking?->doctor?->name ?? $na }} {{ $payment->gateway_code ?: ($payment->method ?: $na) }} {{ $money($payment->amount) }} {{ $payment->currency }} {{ trans()->has('clinic.patients.payment_statuses.' . $payment->status) ? trans('clinic.patients.payment_statuses.' . $payment->status) : $payment->status }}
@endif
{{-- Follow-ups --}}
@forelse ($overview['followups'] as $followup)
{{ $followup->doctor?->name }} · {{ $followup->clinicProfile?->name }}
{{ trans('clinic.followups.due_date') }}: {{ $followup->due_date ? \Illuminate\Support\Carbon::parse($followup->due_date)->format('Y-m-d') : trans('clinic.followups.no_due_date') }}
@if ($followup->doctor_note)
{{ $followup->doctor_note }}
@endif
{{ trans('clinic.followups.statuses.' . $followup->status) }}
@empty
{{ trans('clinic.followups.empty') }}
@endforelse
{{-- Offer subscriptions --}}
{{ trans('clinic.patients.offers_matched_by_phone') }}
@forelse ($overview['subscriptions'] as $subscription)
{{ $subscription->offerLabel() ?? $na }}
{{ $subscription->created_at?->format('Y-m-d H:i') }}
@if ($subscription->message)
{{ $subscription->message }}
@endif
{{ trans($subscription->isContacted() ? 'dash_site.offer_sub_contacted' : 'dash_site.offer_sub_new') }}
@empty
{{ trans('clinic.patients.no_offers') }}
@endforelse
{{-- Reviews --}}
@forelse ($overview['reviews'] as $review)
{{ $review->booking?->doctor?->name }} {{ $review->created_at?->format('Y-m-d') }}
@if ($review->doctor_rating)
{{ trans('clinic.patients.doctor_rating') }}@include('dashboard.admin.Site.feedback.partials.stars', ['rating' => (int) $review->doctor_rating])
@if ($review->doctor_comment)

{{ $review->doctor_comment }}

@endif @endif @if ($review->clinic_rating)
{{ trans('clinic.patients.clinic_rating') }}@include('dashboard.admin.Site.feedback.partials.stars', ['rating' => (int) $review->clinic_rating])
@if ($review->clinic_comment)

{{ $review->clinic_comment }}

@endif @endif
@empty
{{ trans('clinic.patients.no_reviews') }}
@endforelse
@endsection @section('js') @endsection