record; $patient = $record->patient; $surgeryDateTime = $record->getRawOriginal('surgery_date') ? \Carbon\Carbon::parse($record->getRawOriginal('surgery_date')) : \Carbon\Carbon::parse($record->surgery_date); $jalaliDate = Jalalian::fromCarbon($surgeryDateTime)->format('Y/m/d'); try { $response = Http::timeout(30) ->withHeader('X-API-Key', \App\Models\OsurgInitial::val('sms_api_key', config('sms.api_key'))) ->asJson() ->post(\App\Models\OsurgInitial::val('sms_api_url', config('sms.api_url')) . '/surgery-reminder', [ 'phoneNumber' => $patient->hand_phone ?? '', 'patientName' => $patient->full_name, 'surgeryDate' => $jalaliDate, 'appointmentId' => $record->id, 'patientId' => $patient->id, 'surgeryDateFull' => $surgeryDateTime->toDateTimeString(), ]); if (! ($response->json('success') ?? false)) { Notification::make() ->title(__('patients.actions.appointment_saved')) ->body(__('patients.actions.api_failed') . ': ' . ($response->json('message') ?? '')) ->warning() ->send(); return; } } catch (\Throwable $e) { Log::warning('Surgery appointment API failed', [ 'appointment_id' => $record->id, 'patient_id' => $patient->id, 'error' => $e->getMessage(), ]); Notification::make() ->title(__('patients.actions.appointment_saved')) ->body(__('patients.actions.api_failed') . ': ' . $e->getMessage()) ->warning() ->send(); return; } Notification::make() ->title(__('patients.actions.appointment_saved')) ->body(__('patients.actions.sms_sent')) ->success() ->send(); } protected function getFormActions(): array { return []; } }