@php $patient = $patient ?? null; $encounter = $encounter ?? null; $openEncounters = $openEncounters ?? collect(); $types = $types ?? []; $doseUnits = $doseUnits ?? []; $routes = $routes ?? []; $frequencies = $frequencies ?? []; $defaults = $defaults ?? []; $submitLabel = $submitLabel ?? 'Send to pharmacy'; $action = $action ?? route('prescriptions.store'); $method = $method ?? 'POST'; $backRoute = $backRoute ?? route('prescriptions.index'); $encounterOptions = $openEncounters ->mapWithKeys(fn ($row) => [ $row->id => $row->encounter_no .' · '.lookup_label('encounter_type', $row->encounter_type, $row->encounter_type) .' · '.($row->doctor?->name ?? 'Unassigned') .' · '.($row->started_at?->format('d M Y') ?? ''), ])->all(); // A bounced submission comes back with the rows the prescriber had already // filled in. The display-only columns of each row travel in a `snapshot` // field the browser writes, so the line can be rebuilt exactly as it looked. $lineErrors = function (int $index): array { if (! isset($errors)) { return []; } return collect($errors->getMessages()) ->filter(fn ($messages, $key) => str_starts_with($key, "items.{$index}.")) ->mapWithKeys(fn ($messages, $key) => [Str::afterLast($key, '.') => $messages]) ->all(); }; $seedLines = collect(is_array(old('items')) ? array_values(old('items')) : []) ->map(function ($row, $index) use ($lineErrors) { $row = is_array($row) ? $row : []; $snapshot = is_string($row['snapshot'] ?? null) ? json_decode($row['snapshot'], true) : []; return array_merge(is_array($snapshot) ? $snapshot : [], [ 'drug_id' => $row['drug_id'] ?? '', 'dose' => $row['dose'] ?? '', 'dose_unit' => $row['dose_unit'] ?? 'mg', 'route' => $row['route'] ?? 'oral', 'frequency' => $row['frequency'] ?? 'bd', 'duration_days' => $row['duration_days'] ?? '', 'quantity' => $row['quantity'] ?? '', 'quantity_unit' => $row['quantity_unit'] ?? 'tablet', 'is_stat' => ! empty($row['is_stat']), 'is_prn' => ! empty($row['is_prn']), 'prn_indication' => $row['prn_indication'] ?? '', 'instructions' => $row['instructions'] ?? '', 'substitution_allowed' => ! empty($row['substitution_allowed']), 'errors' => $lineErrors($index), ]); }) ->values() ->all(); @endphp
{{ $patient->full_name }}
{{ $patient->medical_record_number }}
{{ $patient->age_display }} · {{ $patient->gender_label }} @if ($patient->phone) · {{ $patient->phone }} @endif
No patient chosen.
@endifAn estimate only — the charge is raised when the pharmacy dispenses, at the price of the batch that actually leaves the shelf.