feat: add lab tests, patient file management, and prescription improvements

This commit is contained in:
SajjadMahmoody
2026-04-17 20:15:38 +03:30
parent 6a301c5529
commit bf0ada051f
53 changed files with 3201 additions and 387 deletions
@@ -4,6 +4,8 @@
namespace App\Filament\Resources\PatientResource\RelationManagers;
use App\Filament\Resources\PatientResource\Pages\CreatePatient;
use App\Filament\Resources\PatientResource\Pages\EditPatient;
use App\Models\Doctor;
use App\Models\PaymentType;
use App\Models\Treatment;
@@ -28,6 +30,11 @@ class VisitsRelationManager extends RelationManager
{
protected static string $relationship = 'visits';
public static function canViewForRecord(\Illuminate\Database\Eloquent\Model $ownerRecord, string $pageClass): bool
{
return in_array($pageClass, [CreatePatient::class, EditPatient::class]);
}
public static function getTitle(\Illuminate\Database\Eloquent\Model $ownerRecord, string $pageClass): string
{
return __('navigation.visits.title');
@@ -49,32 +56,42 @@ public function form(Schema $schema): Schema
TimePicker::make('visit_time')
->label(__('visits.fields.visit_time'))
->nullable()
->native(false)
->seconds(false)
->minutesStep(15),
->minutesStep(15)
->afterStateHydrated(function ($component, $state) {
if (blank($state)) {
$component->state(now()->format('Y-m-d H:i:s'));
}
}),
Select::make('doctor')
->label(__('visits.fields.doctor'))
->options(fn () => Doctor::all()->mapWithKeys(
fn ($d) => [$d->id => $d->full_name]
)->toArray())
->searchable()
->default(fn () => Doctor::where('is_default', true)->first()?->id)
->nullable(),
Select::make('treatment')
->label(__('visits.fields.treatment'))
->options(fn () => Treatment::all()->mapWithKeys(
fn ($t) => [$t->id => ($t->treatment_name ?: $t->treatment_type)]
fn ($t) => [$t->id => ($t->descriptions ? '★ ' : '') . ($t->treatment_name ?: $t->treatment_type)]
)->toArray())
->searchable()
->nullable()
->required()
->live()
->afterStateUpdated(function ($state, callable $set) {
if ($state) {
$treatment = Treatment::find($state);
if ($treatment && $treatment->treatment_cost > 0) {
$set('treatment_cost', $treatment->treatment_cost);
if ($treatment) {
if ($treatment->treatment_cost > 0) {
$set('treatment_cost', $treatment->treatment_cost);
$set('paid_amount', $treatment->treatment_cost);
}
if ($treatment->descriptions) {
$set('treatment_description', $treatment->descriptions);
}
}
}
}),
@@ -102,7 +119,7 @@ public function form(Schema $schema): Schema
fn ($p) => [$p->id => $p->payment_type]
)->toArray())
->searchable()
->nullable(),
->required(),
])
->columns(3)
->columnSpanFull(),
@@ -124,10 +141,13 @@ public function table(Table $table): Table
{
return $table
->recordTitleAttribute('visit_date')
->modifyQueryUsing(fn ($query) => $query->with(['doctorRecord', 'treatmentRecord', 'paymentTypeRecord']))
->deferLoading()
->columns([
TextColumn::make('visit_date')
->label(__('visits.fields.visit_date'))
->sortable()
->wrap(false)
->formatStateUsing(function ($state) {
if (! $state) {
return '-';
@@ -144,6 +164,7 @@ public function table(Table $table): Table
TextColumn::make('doctorRecord.first_name')
->label(__('visits.fields.doctor'))
->formatStateUsing(fn ($record) => $record->doctorRecord?->full_name ?? '-')
->wrap(false)
->placeholder('-'),
TextColumn::make('treatmentRecord.treatment_name')
@@ -151,11 +172,13 @@ public function table(Table $table): Table
->formatStateUsing(fn ($record) => $record->treatmentRecord
? ($record->treatmentRecord->treatment_name ?: $record->treatmentRecord->treatment_type)
: '-')
->wrap(false)
->placeholder('-'),
TextColumn::make('treatment_cost')
->label(__('visits.fields.treatment_cost'))
->formatStateUsing(fn ($state) => $state !== null ? number_format((int) $state) : '-')
->wrap(false)
->placeholder('-')
->summarize(
Sum::make()
@@ -166,6 +189,7 @@ public function table(Table $table): Table
TextColumn::make('paid_amount')
->label(__('visits.fields.paid_amount'))
->formatStateUsing(fn ($state) => $state !== null ? number_format((int) $state) : '-')
->wrap(false)
->placeholder('-')
->summarize(
Sum::make()
@@ -177,10 +201,12 @@ public function table(Table $table): Table
->label(__('visits.fields.remained_amount'))
->state(fn ($record) => $record->remained_amount)
->formatStateUsing(fn ($state) => number_format((int) $state))
->color(fn ($record) => $record->remained_amount > 0 ? 'danger' : 'success'),
->color(fn ($record) => $record->remained_amount > 0 ? 'danger' : 'success')
->wrap(false),
TextColumn::make('paymentTypeRecord.payment_type')
->label(__('visits.fields.payment_type'))
->wrap(false)
->placeholder('-'),
])
->defaultSort('visit_date', 'desc')