get()->keyBy('id'); $data['content'] = ''; } $labTestIds = $data['lab_test_ids'] ?? []; if (empty($data['lab_content']) && ! empty($labTestIds)) { $tests = LabTest::whereIn('id', $labTestIds)->orderBy('name')->get(); $data['lab_content'] = $tests->isNotEmpty() ? '' : ''; } return $data; } protected function mutateFormDataBeforeSave(array $data): array { $data['doctor'] = auth()->user()?->name; $data['issue_datetime'] = now(); $data['medication_ids'] = $data['medication_order'] ?? $data['medication_ids'] ?? []; $data['lab_test_ids'] = $data['lab_test_order'] ?? $data['lab_test_ids'] ?? []; $content = $data['content'] ?? ''; if (empty($content) && ! empty($data['medication_ids'])) { $medications = Medication::whereIn('id', $data['medication_ids'])->get()->keyBy('id'); $data['content'] = ''; } $labContent = $data['lab_content'] ?? ''; if (empty($labContent) && ! empty($data['lab_test_ids'])) { $tests = LabTest::whereIn('id', $data['lab_test_ids'])->orderBy('name')->get(); $data['lab_content'] = ''; } return $data; } protected function getRedirectUrl(): string { $return = request()->query('return'); if ($return && str_starts_with($return, url('/'))) { return $return; } return static::getResource()::getUrl('index'); } protected function getHeaderActions(): array { return [ Action::make('printPrescription') ->label(__('prescriptions.actions.print_prescription')) ->icon('heroicon-o-printer') ->color('info') ->url(fn () => route('prescription.print', $this->getRecord())) ->openUrlInNewTab(), Action::make('printAdmission') ->label(__('prescriptions.actions.print_admission')) ->icon('heroicon-o-printer') ->color('warning') ->visible(fn () => $this->getRecord()->patientRecord?->surgeryAppointment !== null) ->url(fn () => route('prescription.print.admission', $this->getRecord())) ->openUrlInNewTab(), Action::make('printLab') ->label(__('prescriptions.actions.print_lab')) ->icon('heroicon-o-beaker') ->color('gray') ->url(fn () => route('prescription.print', ['prescription' => $this->getRecord(), 'type' => 'lab'])) ->openUrlInNewTab(), DeleteAction::make(), ]; } protected function getFormActions(): array { return []; } }