Skip to content

Commit 6727c48

Browse files
feat: add ViewCaseInterventionService page and update routing for intervention services
1 parent 0806599 commit 6727c48

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

app/Filament/Organizations/Resources/Cases/CaseResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\CreateCaseInterventionPlan;
2121
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\CreateCaseMonthlyPlan;
2222
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseInterventionPlan;
23+
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseInterventionService;
2324
use App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\ViewCaseMonthlyPlan;
2425
use App\Filament\Organizations\Resources\Cases\Pages\ListCases;
2526
use App\Filament\Organizations\Resources\Cases\Pages\ViewCase;
@@ -155,6 +156,7 @@ public static function getPages(): array
155156
'edit_detailed_evaluation' => CreateCaseDetailedEvaluation::route('/{record}/detailed-evaluation/edit'),
156157
'create_intervention_plan' => CreateCaseInterventionPlan::route('/{record}/intervention-plan/create'),
157158
'view_intervention_plan' => ViewCaseInterventionPlan::route('/{record}/intervention-plan'),
159+
'view_intervention_service' => ViewCaseInterventionService::route('/{record}/intervention-plan/services/{interventionService}'),
158160
'create_monthly_plan' => CreateCaseMonthlyPlan::route('/{case}/intervention-plan/monthly-plans/create'),
159161
'view_monthly_plan' => ViewCaseMonthlyPlan::route('/{record}/intervention-plan/monthly-plans/{monthlyPlan}'),
160162
];
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan;
6+
7+
use App\Actions\BackAction;
8+
use App\Filament\Organizations\Resources\Cases\CaseResource;
9+
use App\Models\Beneficiary;
10+
use App\Models\InterventionService;
11+
use Carbon\Carbon;
12+
use Filament\Infolists\Components\TextEntry;
13+
use Filament\Resources\Pages\ViewRecord;
14+
use Filament\Schemas\Components\Section;
15+
use Filament\Schemas\Schema;
16+
use Illuminate\Contracts\Support\Htmlable;
17+
18+
class ViewCaseInterventionService extends ViewRecord
19+
{
20+
protected static string $resource = CaseResource::class;
21+
22+
public ?InterventionService $interventionService = null;
23+
24+
public function mount(int|string $record): void
25+
{
26+
$this->record = $this->resolveRecord($record);
27+
28+
if (! $this->record instanceof Beneficiary) {
29+
abort(404);
30+
}
31+
32+
$plan = $this->record->interventionPlan;
33+
if (! $plan) {
34+
$this->redirect(CaseResource::getUrl('view_intervention_plan', ['record' => $this->record]));
35+
36+
return;
37+
}
38+
39+
$interventionServiceId = request()->route('interventionService');
40+
$this->interventionService = InterventionService::query()
41+
->where('intervention_plan_id', $plan->id)
42+
->where('id', $interventionServiceId)
43+
->with([
44+
'organizationServiceWithoutStatusCondition.serviceWithoutStatusCondition',
45+
'specialist.user',
46+
'specialist.role',
47+
])
48+
->firstOrFail();
49+
50+
$this->authorizeAccess();
51+
}
52+
53+
protected function authorizeAccess(): void
54+
{
55+
abort_unless(CaseResource::canView($this->record), 403);
56+
}
57+
58+
public function getTitle(): string|Htmlable
59+
{
60+
return $this->interventionService?->organizationServiceWithoutStatusCondition?->serviceWithoutStatusCondition?->name ?? __('intervention_plan.headings.services');
61+
}
62+
63+
public function getBreadcrumbs(): array
64+
{
65+
$record = $this->getRecord();
66+
67+
return [
68+
CaseResource::getUrl('index') => __('case.view.breadcrumb_all'),
69+
CaseResource::getUrl('view', ['record' => $record]) => $record instanceof Beneficiary ? $record->getBreadcrumb() : '',
70+
CaseResource::getUrl('view_intervention_plan', ['record' => $record]) => __('intervention_plan.headings.view_page'),
71+
'' => $this->interventionService?->organizationServiceWithoutStatusCondition?->serviceWithoutStatusCondition?->name ?? __('intervention_plan.headings.services'),
72+
];
73+
}
74+
75+
protected function getHeaderActions(): array
76+
{
77+
return [
78+
BackAction::make()
79+
->url(CaseResource::getUrl('view_intervention_plan', ['record' => $this->getRecord()])),
80+
];
81+
}
82+
83+
public function infolist(Schema $schema): Schema
84+
{
85+
$service = $this->interventionService;
86+
87+
return $schema
88+
->record($service)
89+
->components([
90+
Section::make(__('intervention_plan.headings.services'))
91+
->schema([
92+
TextEntry::make('organizationServiceWithoutStatusCondition.serviceWithoutStatusCondition.name')
93+
->label(__('intervention_plan.labels.service'))
94+
->placeholder(''),
95+
TextEntry::make('specialist.name_role')
96+
->label(__('intervention_plan.labels.specialist'))
97+
->placeholder(''),
98+
TextEntry::make('institution')
99+
->label(__('intervention_plan.labels.responsible_institution'))
100+
->placeholder(''),
101+
TextEntry::make('start_date_interval')
102+
->label(__('intervention_plan.labels.start_date_interval'))
103+
->formatStateUsing(fn ($state) => self::formatDate($state))
104+
->placeholder(''),
105+
TextEntry::make('end_date_interval')
106+
->label(__('intervention_plan.labels.end_date_interval'))
107+
->formatStateUsing(fn ($state) => self::formatDate($state))
108+
->placeholder(''),
109+
TextEntry::make('interventions_count')
110+
->label(__('intervention_plan.labels.interventions_count'))
111+
->state((string) $service->beneficiaryInterventions()->count())
112+
->placeholder('0'),
113+
TextEntry::make('meetings_count')
114+
->label(__('intervention_plan.labels.meetings_count'))
115+
->state((string) $service->meetings()->count())
116+
->placeholder('0'),
117+
])
118+
->columns(2),
119+
]);
120+
}
121+
122+
private static function formatDate(?string $state): string
123+
{
124+
if ($state === null || $state === '') {
125+
return '';
126+
}
127+
128+
try {
129+
return Carbon::parse($state)->translatedFormat('d.m.Y');
130+
} catch (\Throwable) {
131+
return '';
132+
}
133+
}
134+
}

app/Filament/Organizations/Resources/Cases/Pages/InterventionPlan/Widgets/InterventionPlanServicesWidget.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Filament\Organizations\Resources\Cases\Pages\InterventionPlan\Widgets;
66

7+
use App\Filament\Organizations\Resources\Cases\CaseResource;
78
use App\Forms\Components\DatePicker;
89
use App\Models\Beneficiary;
910
use App\Models\InterventionService;
@@ -50,7 +51,18 @@ public function table(Table $table): Table
5051
->label(__('intervention_plan.labels.interventions_count')),
5152
TextColumn::make('meetings_count')
5253
->label(__('intervention_plan.labels.meetings_count')),
54+
TextColumn::make('view_details')
55+
->label('')
56+
->state(__('intervention_plan.actions.view_details'))
57+
->url(fn (InterventionService $record): string => CaseResource::getUrl('view_intervention_service', [
58+
'record' => $this->record,
59+
'interventionService' => $record->id,
60+
])),
5361
])
62+
->recordUrl(fn (InterventionService $record): string => CaseResource::getUrl('view_intervention_service', [
63+
'record' => $this->record,
64+
'interventionService' => $record->id,
65+
]))
5466
->headerActions([
5567
\Filament\Actions\CreateAction::make()
5668
->label(__('intervention_plan.actions.add_service'))

0 commit comments

Comments
 (0)