feat: add lab tests, patient file management, and prescription improvements
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -101,32 +102,42 @@ public static 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
@@ -154,7 +165,7 @@ public static function form(Schema $schema): Schema
|
||||
fn ($p) => [$p->id => $p->payment_type]
|
||||
)->toArray())
|
||||
->searchable()
|
||||
->nullable(),
|
||||
->required(),
|
||||
])
|
||||
->columns(3)
|
||||
->columnSpanFull(),
|
||||
@@ -207,6 +218,7 @@ public static function table(Table $table): Table
|
||||
->label(__('visits.fields.visit_date'))
|
||||
->sortable()
|
||||
->searchable()
|
||||
->wrap(false)
|
||||
->formatStateUsing(function ($state) {
|
||||
if (! $state) {
|
||||
return '-';
|
||||
@@ -224,12 +236,14 @@ public static function table(Table $table): Table
|
||||
->label(__('visits.fields.patient'))
|
||||
->formatStateUsing(fn ($record) => $record->patientRecord?->full_name ?? '-')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->wrap(false),
|
||||
|
||||
TextColumn::make('doctorRecord.first_name')
|
||||
->label(__('visits.fields.doctor'))
|
||||
->formatStateUsing(fn ($record) => $record->doctorRecord?->full_name ?? '-')
|
||||
->sortable()
|
||||
->wrap(false)
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('treatmentRecord.treatment_name')
|
||||
@@ -238,18 +252,21 @@ public static function table(Table $table): Table
|
||||
? ($record->treatmentRecord->treatment_name ?: $record->treatmentRecord->treatment_type)
|
||||
: '-')
|
||||
->sortable()
|
||||
->wrap(false)
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('treatment_cost')
|
||||
->label(__('visits.fields.treatment_cost'))
|
||||
->formatStateUsing(fn ($state) => $state !== null ? number_format((int) $state) : '-')
|
||||
->sortable()
|
||||
->wrap(false)
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('paid_amount')
|
||||
->label(__('visits.fields.paid_amount'))
|
||||
->formatStateUsing(fn ($state) => $state !== null ? number_format((int) $state) : '-')
|
||||
->sortable()
|
||||
->wrap(false)
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('remained_amount')
|
||||
@@ -257,15 +274,18 @@ public static function table(Table $table): Table
|
||||
->state(fn ($record) => $record->remained_amount)
|
||||
->formatStateUsing(fn ($state) => number_format((int) $state))
|
||||
->color(fn ($record) => $record->remained_amount > 0 ? 'danger' : 'success')
|
||||
->wrap(false)
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('paymentTypeRecord.payment_type')
|
||||
->label(__('visits.fields.payment_type'))
|
||||
->wrap(false)
|
||||
->placeholder('-'),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label(__('visits.fields.created_at'))
|
||||
->sortable()
|
||||
->wrap(false)
|
||||
->formatStateUsing(function ($state) {
|
||||
if (! $state) {
|
||||
return '-';
|
||||
@@ -281,6 +301,31 @@ public static function table(Table $table): Table
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
Filter::make('visit_date_range')
|
||||
->label(__('visits.filters.date_range'))
|
||||
->form([
|
||||
DatePicker::make('from_date')
|
||||
->label(__('visits.filters.from_date'))
|
||||
->jalali(),
|
||||
DatePicker::make('to_date')
|
||||
->label(__('visits.filters.to_date'))
|
||||
->jalali(),
|
||||
])
|
||||
->query(fn ($query, array $data) => $query
|
||||
->when($data['from_date'], fn ($q) => $q->whereDate('visit_date', '>=', $data['from_date']))
|
||||
->when($data['to_date'], fn ($q) => $q->whereDate('visit_date', '<=', $data['to_date']))
|
||||
)
|
||||
->indicateUsing(function (array $data): array {
|
||||
$indicators = [];
|
||||
if (! empty($data['from_date'])) {
|
||||
$indicators[] = __('visits.filters.from_date') . ': ' . $data['from_date'];
|
||||
}
|
||||
if (! empty($data['to_date'])) {
|
||||
$indicators[] = __('visits.filters.to_date') . ': ' . $data['to_date'];
|
||||
}
|
||||
return $indicators;
|
||||
}),
|
||||
|
||||
SelectFilter::make('doctor')
|
||||
->label(__('visits.fields.doctor'))
|
||||
->options(fn () => Doctor::all()->mapWithKeys(
|
||||
|
||||
Reference in New Issue
Block a user