feat: add lab tests, patient file management, and prescription improvements
This commit is contained in:
+54
-26
@@ -5,6 +5,7 @@
|
||||
namespace App\Filament\Resources\SurgeryAppointmentResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SurgeryAppointmentResource;
|
||||
use App\Models\Patient;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Filament\Support\Enums\Width;
|
||||
@@ -29,53 +30,80 @@ protected function mutateFormDataBeforeCreate(array $data): array
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
protected function beforeCreate(): 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');
|
||||
$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 = Patient::find($data['patient_id'] ?? null);
|
||||
|
||||
$apiKey = \App\Models\OsurgInitial::val('sms_api_key', config('sms.api_key'));
|
||||
$apiUrl = \App\Models\OsurgInitial::val('sms_api_url', config('sms.api_url'));
|
||||
$smsPayload = [
|
||||
'phoneNumber' => $patient?->hand_phone ?? '',
|
||||
'patientName' => $patient?->full_name ?? '',
|
||||
'surgeryDate' => $jalaliDate,
|
||||
'patientId' => $patient?->id,
|
||||
'surgeryDateFull' => $surgeryDateTime->toDateTimeString(),
|
||||
];
|
||||
|
||||
try {
|
||||
$response = Http::timeout(30)
|
||||
->withHeader('X-API-Key', \App\Models\OsurgInitial::val('sms_api_key', config('sms.api_key')))
|
||||
->withHeader('X-API-Key', $apiKey)
|
||||
->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(),
|
||||
]);
|
||||
->post($apiUrl . '/surgery-reminder', $smsPayload);
|
||||
|
||||
if (! ($response->json('success') ?? false)) {
|
||||
Notification::make()
|
||||
->title(__('patients.actions.appointment_saved'))
|
||||
->body(__('patients.actions.api_failed') . ': ' . ($response->json('message') ?? ''))
|
||||
->warning()
|
||||
->title(__('patients.actions.api_failed'))
|
||||
->body($response->json('message') ?? '')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->halt();
|
||||
return;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Surgery appointment API failed', [
|
||||
'appointment_id' => $record->id,
|
||||
'patient_id' => $patient->id,
|
||||
'error' => $e->getMessage(),
|
||||
Log::warning('Surgery appointment SMS failed', [
|
||||
'patient_id' => $patient?->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
Notification::make()
|
||||
->title(__('patients.actions.appointment_saved'))
|
||||
->body(__('patients.actions.api_failed') . ': ' . $e->getMessage())
|
||||
->warning()
|
||||
->title(__('patients.actions.api_failed'))
|
||||
->body($e->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
$this->halt();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->smsApiKey = $apiKey;
|
||||
$this->smsApiUrl = $apiUrl;
|
||||
$this->smsSentPayload = $smsPayload;
|
||||
}
|
||||
|
||||
public string $smsApiKey = '';
|
||||
public string $smsApiUrl = '';
|
||||
public array $smsSentPayload = [];
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
if (! empty($this->smsSentPayload) && $this->record) {
|
||||
try {
|
||||
Http::timeout(30)
|
||||
->withHeader('X-API-Key', $this->smsApiKey)
|
||||
->asJson()
|
||||
->post($this->smsApiUrl . '/surgery-reminder', array_merge($this->smsSentPayload, [
|
||||
'appointmentId' => $this->record->id,
|
||||
]));
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('patients.actions.appointment_saved'))
|
||||
->body(__('patients.actions.sms_sent'))
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
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;
|
||||
|
||||
@@ -22,7 +21,14 @@ class EditSurgeryAppointment extends EditRecord
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
DeleteAction::make()
|
||||
->before(function () {
|
||||
$record = $this->getRecord();
|
||||
\App\Filament\Pages\SmsLogsPage::cancelAppointmentMessages(
|
||||
$record->patient->hand_phone ?? '',
|
||||
$record->surgery_date->toDateTimeString(),
|
||||
);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user