feat: initial project setup with Laravel 12 and Filament v4
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\SurgeryAppointmentResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SurgeryAppointmentResource;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
|
||||
class CreateSurgeryAppointment extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SurgeryAppointmentResource::class;
|
||||
|
||||
protected Width|string|null $maxContentWidth = Width::SevenExtraLarge;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$dateStr = $data['surgery_date_date'] ?? '';
|
||||
$timeStr = $data['surgery_date_time'] ?? '09:00';
|
||||
$data['surgery_date'] = \Carbon\Carbon::parse($dateStr . ' ' . $timeStr);
|
||||
|
||||
unset($data['surgery_date_date'], $data['surgery_date_time']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$record = $this->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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\SurgeryAppointmentResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SurgeryAppointmentResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Morilog\Jalali\Jalalian;
|
||||
|
||||
class EditSurgeryAppointment extends EditRecord
|
||||
{
|
||||
protected static string $resource = SurgeryAppointmentResource::class;
|
||||
|
||||
protected Width|string|null $maxContentWidth = Width::SevenExtraLarge;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
if (! empty($data['surgery_date'])) {
|
||||
$date = \Carbon\Carbon::parse($data['surgery_date']);
|
||||
$data['surgery_date_date'] = $date->format('Y-m-d');
|
||||
$data['surgery_date_time'] = $date->format('H:i');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$dateStr = $data['surgery_date_date'] ?? '';
|
||||
$timeStr = $data['surgery_date_time'] ?? '09:00';
|
||||
$data['surgery_date'] = \Carbon\Carbon::parse($dateStr . ' ' . $timeStr);
|
||||
|
||||
unset($data['surgery_date_date'], $data['surgery_date_time']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function beforeSave(): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$dateStr = $data['surgery_date_date'] ?? '';
|
||||
$timeStr = $data['surgery_date_time'] ?? '09:00';
|
||||
$surgeryDateTime = \Carbon\Carbon::parse($dateStr . ' ' . $timeStr);
|
||||
$jalaliDate = Jalalian::fromCarbon($surgeryDateTime)->format('Y/m/d');
|
||||
|
||||
$patient = $this->getRecord()->patient;
|
||||
|
||||
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' => $this->getRecord()->id,
|
||||
'patientId' => $patient->id,
|
||||
'surgeryDateFull' => $surgeryDateTime->toDateTimeString(),
|
||||
]);
|
||||
|
||||
if (! ($response->json('success') ?? false)) {
|
||||
Notification::make()
|
||||
->title(__('patients.actions.api_failed'))
|
||||
->body($response->json('message') ?? '')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->halt();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Surgery appointment API failed', [
|
||||
'patient_id' => $patient->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title(__('patients.actions.api_failed'))
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->halt();
|
||||
}
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
Notification::make()
|
||||
->title(__('patients.actions.appointment_saved'))
|
||||
->body(__('patients.actions.sms_sent'))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
protected function getFormActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\SurgeryAppointmentResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SurgeryAppointmentResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSurgeryAppointments extends ListRecords
|
||||
{
|
||||
protected static string $resource = SurgeryAppointmentResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->icon('heroicon-o-plus'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user