feat: initialize Dr-Panel project with patient file number support
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\PrescriptionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PrescriptionResource;
|
||||
use App\Models\LabTest;
|
||||
use App\Models\Medication;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Filament\Support\Enums\Width;
|
||||
|
||||
class CreatePrescription extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PrescriptionResource::class;
|
||||
|
||||
protected Width|string|null $maxContentWidth = Width::SevenExtraLarge;
|
||||
|
||||
public string $printType = '';
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['doctor'] = auth()->user()?->name;
|
||||
$data['issue_datetime'] = now();
|
||||
$data['medication_ids'] = $data['medication_order'] ?? $data['medication_ids'] ?? [];
|
||||
|
||||
$content = $data['content'] ?? '';
|
||||
if (empty($content) && ! empty($data['medication_ids'])) {
|
||||
$medications = Medication::whereIn('id', $data['medication_ids'])->get()->keyBy('id');
|
||||
$data['content'] = '<ul>' . collect($data['medication_ids'])->map(fn ($id) => isset($medications[$id])
|
||||
? '<li>' . implode(' ', array_filter([
|
||||
$medications[$id]->dosage_form,
|
||||
$medications[$id]->name,
|
||||
$medications[$id]->strength,
|
||||
$medications[$id]->quantity ? '#' . $medications[$id]->quantity : null,
|
||||
$medications[$id]->timing,
|
||||
])) . '</li>'
|
||||
: ''
|
||||
)->filter()->implode('') . '</ul>';
|
||||
}
|
||||
|
||||
$labTestIds = $data['lab_test_ids'] ?? [];
|
||||
$labContent = $data['lab_content'] ?? '';
|
||||
if (empty($labContent) && ! empty($labTestIds)) {
|
||||
$tests = LabTest::whereIn('id', $labTestIds)->orderBy('name')->get();
|
||||
$data['lab_content'] = '<ul>' . $tests->map(fn ($t) => '<li>' . $t->name . '</li>')->implode('') . '</ul>';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getFormActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
$record = $this->getRecord();
|
||||
|
||||
if ($this->printType === 'prescription') {
|
||||
return route('prescription.print', $record);
|
||||
}
|
||||
|
||||
if ($this->printType === 'lab') {
|
||||
return route('prescription.print', ['prescription' => $record, 'type' => 'lab']);
|
||||
}
|
||||
|
||||
if ($this->printType === 'both') {
|
||||
return route('prescription.print', ['prescription' => $record, 'type' => 'both']);
|
||||
}
|
||||
|
||||
if ($this->printType === 'admission') {
|
||||
return route('prescription.print.admission', $record);
|
||||
}
|
||||
|
||||
return static::getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\PrescriptionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PrescriptionResource;
|
||||
use App\Models\LabTest;
|
||||
use App\Models\Medication;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class EditPrescription extends EditRecord
|
||||
{
|
||||
protected static string $resource = PrescriptionResource::class;
|
||||
|
||||
protected Width|string|null $maxContentWidth = Width::SevenExtraLarge;
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$data['medication_order'] = $data['medication_ids'] ?? [];
|
||||
$data['lab_test_order'] = $data['lab_test_ids'] ?? [];
|
||||
|
||||
$medicationIds = $data['medication_ids'] ?? [];
|
||||
if (empty($data['content']) && ! empty($medicationIds)) {
|
||||
$meds = Medication::whereIn('id', $medicationIds)->get()->keyBy('id');
|
||||
$data['content'] = '<ul>' . collect($medicationIds)->map(fn ($id) => isset($meds[$id])
|
||||
? '<li>' . implode(' ', array_filter([
|
||||
$meds[$id]->dosage_form,
|
||||
$meds[$id]->name,
|
||||
$meds[$id]->strength,
|
||||
$meds[$id]->quantity ? '#' . $meds[$id]->quantity : null,
|
||||
$meds[$id]->timing,
|
||||
])) . '</li>'
|
||||
: ''
|
||||
)->filter()->implode('') . '</ul>';
|
||||
}
|
||||
|
||||
$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()
|
||||
? '<ul>' . $tests->map(fn ($t) => '<li>' . $t->name . '</li>')->implode('') . '</ul>'
|
||||
: '';
|
||||
}
|
||||
|
||||
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'] = '<ul>' . collect($data['medication_ids'])->map(fn ($id) => isset($medications[$id])
|
||||
? '<li>' . implode(' ', array_filter([
|
||||
$medications[$id]->dosage_form,
|
||||
$medications[$id]->name,
|
||||
$medications[$id]->strength,
|
||||
$medications[$id]->quantity ? '#' . $medications[$id]->quantity : null,
|
||||
$medications[$id]->timing,
|
||||
])) . '</li>'
|
||||
: ''
|
||||
)->filter()->implode('') . '</ul>';
|
||||
}
|
||||
|
||||
$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'] = '<ul>' . $tests->map(fn ($t) => '<li>' . $t->name . '</li>')->implode('') . '</ul>';
|
||||
}
|
||||
|
||||
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 [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\PrescriptionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PrescriptionResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPrescriptions extends ListRecords
|
||||
{
|
||||
protected static string $resource = PrescriptionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make()
|
||||
->icon('heroicon-o-plus'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user