Skip to content

Commit 3378eac

Browse files
wip
1 parent 3ecd49b commit 3378eac

File tree

6 files changed

+267
-33
lines changed

6 files changed

+267
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static function getRecordRouteBindingEloquentQuery(): Builder
7676
'antecedents',
7777
'specialistsTeam.user',
7878
'specialistsTeam.roleForDisplay',
79-
'evaluateDetails',
79+
'evaluateDetails.specialist',
8080
'children',
8181
'detailedEvaluationSpecialists',
8282
'meetings',

app/Filament/Organizations/Resources/Cases/Resources/InitialEvaluation/InitialEvaluationResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function getRecordTitle(?Model $record): ?string
5050

5151
public static function getRecordRouteBindingEloquentQuery(): Builder
5252
{
53-
return parent::getRecordRouteBindingEloquentQuery()->with(['beneficiary']);
53+
return parent::getRecordRouteBindingEloquentQuery()->with(['beneficiary', 'specialist']);
5454
}
5555

5656
public static function form(Schema $schema): Schema

app/Filament/Organizations/Resources/Cases/Resources/InitialEvaluation/Pages/ViewInitialEvaluation.php

Lines changed: 138 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77
use App\Actions\BackAction;
88
use App\Filament\Organizations\Resources\Cases\CaseResource;
99
use App\Filament\Organizations\Resources\Cases\Resources\InitialEvaluation\InitialEvaluationResource;
10+
use App\Filament\Organizations\Resources\Cases\Schemas\IdentityInfolist;
1011
use App\Filament\Organizations\Schemas\BeneficiaryResource\InitialEvaluationSchema;
12+
use App\Infolists\Components\Notice;
1113
use App\Models\Beneficiary;
1214
use App\Models\EvaluateDetails;
1315
use Filament\Actions\EditAction;
16+
use Filament\Infolists\Components\RepeatableEntry;
17+
use Filament\Infolists\Components\RepeatableEntry\TableColumn;
18+
use Filament\Infolists\Components\TextEntry;
1419
use Filament\Resources\Pages\ViewRecord;
15-
use Filament\Schemas\Components\Group;
20+
use Filament\Schemas\Components\Grid;
1621
use Filament\Schemas\Components\Section;
22+
use Filament\Schemas\Components\Tabs;
23+
use Filament\Schemas\Components\Tabs\Tab;
1724
use Filament\Schemas\Schema;
1825
use Illuminate\Contracts\Support\Htmlable;
26+
use Illuminate\Support\Str;
1927

2028
class ViewInitialEvaluation extends ViewRecord
2129
{
@@ -60,13 +68,40 @@ public function getBreadcrumbs(): array
6068
public function infolist(Schema $schema): Schema
6169
{
6270
return $schema
71+
->columns(1)
6372
->components([
64-
Group::make()
65-
->schema(InitialEvaluationSchema::getEvaluationDetailsInfolistComponents()),
66-
Section::make(__('beneficiary.wizard.violence.label'))
67-
->schema(InitialEvaluationSchema::getViolenceInfolistComponents()),
68-
Section::make(__('beneficiary.wizard.beneficiary_situation.label'))
69-
->schema(InitialEvaluationSchema::getBeneficiarySituationInfolistComponents()),
73+
Tabs::make()
74+
->persistTabInQueryString()
75+
->columnSpanFull()
76+
->tabs([
77+
Tab::make(__('beneficiary.wizard.details.label'))
78+
->maxWidth('3xl')
79+
->schema(InitialEvaluationSchema::getEvaluationDetailsInfolistComponents()),
80+
81+
Tab::make(__('beneficiary.section.identity.tab.beneficiary'))
82+
->maxWidth('3xl')
83+
->schema($this->getIdentitateBeneficiarSchema()),
84+
85+
Tab::make(__('beneficiary.section.identity.tab.children'))
86+
->maxWidth('3xl')
87+
->schema($this->getIdentitateCopiiSchema()),
88+
89+
Tab::make(__('beneficiary.wizard.violence.label'))
90+
->maxWidth('3xl')
91+
->schema(InitialEvaluationSchema::getViolenceInfolistComponents()),
92+
93+
Tab::make(__('beneficiary.wizard.risk_factors.label'))
94+
->maxWidth('3xl')
95+
->schema(InitialEvaluationSchema::getRiskFactorsInfolistComponents()),
96+
97+
Tab::make(__('beneficiary.wizard.requested_services.label'))
98+
->maxWidth('3xl')
99+
->schema(InitialEvaluationSchema::getRequestedServicesInfolistComponents()),
100+
101+
Tab::make(__('beneficiary.wizard.beneficiary_situation.label'))
102+
->maxWidth('3xl')
103+
->schema(InitialEvaluationSchema::getBeneficiarySituationInfolistComponents()),
104+
]),
70105
]);
71106
}
72107

@@ -77,4 +112,100 @@ public function defaultInfolist(Schema $schema): Schema
77112

78113
return parent::defaultInfolist($schema)->record($beneficiary ?? $record);
79114
}
115+
116+
/**
117+
* @return array<int, Notice|Section>
118+
*/
119+
protected function getIdentitateBeneficiarSchema(): array
120+
{
121+
$beneficiary = $this->getParentRecord();
122+
123+
return [
124+
Notice::make('identity_redirect')
125+
->state(__('beneficiary.section.identity.heading_description'))
126+
->registerActions([
127+
\Filament\Actions\Action::make('go_identity')
128+
->label(__('case.view.identity'))
129+
->record($beneficiary instanceof Beneficiary ? $beneficiary : null)
130+
->url(fn (): string => $beneficiary instanceof Beneficiary
131+
? CaseResource::getUrl('identity', ['record' => $beneficiary])
132+
: '#')
133+
->link(),
134+
]),
135+
Section::make(__('beneficiary.section.identity.tab.beneficiary'))
136+
->schema(IdentityInfolist::getIdentityFieldsSchemaForEmbedding()),
137+
];
138+
}
139+
140+
/**
141+
* @return array<int, Notice|Section|TextEntry|RepeatableEntry>
142+
*/
143+
protected function getIdentitateCopiiSchema(): array
144+
{
145+
$beneficiary = $this->getParentRecord();
146+
147+
return [
148+
Notice::make('children_redirect')
149+
->state(__('beneficiary.section.identity.heading_description'))
150+
->registerActions([
151+
\Filament\Actions\Action::make('go_identity')
152+
->label(__('case.view.identity'))
153+
->record($beneficiary instanceof Beneficiary ? $beneficiary : null)
154+
->url(fn (): string => $beneficiary instanceof Beneficiary
155+
? CaseResource::getUrl('identity', ['record' => $beneficiary])
156+
: '#')
157+
->link(),
158+
]),
159+
Section::make(__('beneficiary.section.identity.tab.children'))
160+
->schema([
161+
Grid::make(2)
162+
->schema([
163+
TextEntry::make('children_total_count')
164+
->label(__('field.children_total_count'))
165+
->placeholder('')
166+
->numeric(),
167+
TextEntry::make('children_accompanying_count')
168+
->label(__('field.children_accompanying_count'))
169+
->placeholder('')
170+
->numeric(),
171+
]),
172+
Section::make(__('enum.notifier.child'))
173+
->compact()
174+
->hidden(fn (Beneficiary $record): bool => (bool) $record->doesnt_have_children)
175+
->schema([
176+
RepeatableEntry::make('children')
177+
->hiddenLabel()
178+
->table([
179+
TableColumn::make(__('nomenclature.labels.nr')),
180+
TableColumn::make(__('field.child_name')),
181+
TableColumn::make(__('field.age')),
182+
TableColumn::make(__('field.current_address')),
183+
TableColumn::make(__('field.child_status')),
184+
])
185+
->schema([
186+
TextEntry::make('nr_crt')
187+
->state(fn (TextEntry $entry): int => $this->getRepeatableItemIndex($entry) + 1),
188+
TextEntry::make('name'),
189+
TextEntry::make('age'),
190+
TextEntry::make('current_address'),
191+
TextEntry::make('status'),
192+
]),
193+
]),
194+
TextEntry::make('children_notes')
195+
->label(__('field.children_notes'))
196+
->placeholder('')
197+
->columnSpanFull()
198+
->hidden(fn (Beneficiary $record): bool => (bool) $record->doesnt_have_children),
199+
]),
200+
];
201+
}
202+
203+
private function getRepeatableItemIndex(TextEntry $entry): int
204+
{
205+
$container = $entry->getContainer();
206+
$path = $container->getStatePath();
207+
$key = Str::afterLast($path, '.');
208+
209+
return is_numeric($key) ? (int) $key : 0;
210+
}
80211
}

app/Filament/Organizations/Schemas/BeneficiaryResource/InitialEvaluationSchema.php

Lines changed: 119 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
use App\Enums\VictimPerceptionOfTheRiskSchema;
1414
use App\Enums\Violence;
1515
use App\Enums\ViolenceHistorySchema;
16+
use App\Enums\ViolenceMeans;
1617
use App\Enums\ViolencesTypesSchema;
18+
use App\Filament\Organizations\Resources\Cases\CaseResource;
19+
use App\Filament\Schemas\Components\SectionWithRecordActions;
1720
use App\Forms\Components\DatePicker;
1821
use App\Forms\Components\Select;
22+
use App\Infolists\Components\Actions\EditAction;
1923
use App\Infolists\Components\DateEntry;
2024
use App\Infolists\Components\EnumEntry;
25+
use App\Models\Beneficiary;
2126
use App\Models\User;
2227
use Filament\Forms\Components\Checkbox;
2328
use Filament\Forms\Components\CheckboxList;
@@ -68,25 +73,33 @@ public static function getEvaluationDetailsFormComponents(): array
6873
public static function getEvaluationDetailsInfolistComponents(): array
6974
{
7075
return [
71-
Group::make()
72-
->columns()
73-
->relationship('evaluateDetails')
76+
SectionWithRecordActions::make(__('beneficiary.wizard.details.label'))
77+
->headerActions([
78+
EditAction::make()
79+
->url(fn (Beneficiary $record): string => CaseResource::getUrl('edit_initial_evaluation', ['record' => $record])),
80+
])
7481
->schema([
75-
DateEntry::make('registered_date')
76-
->label(__('beneficiary.section.initial_evaluation.labels.registered_date')),
77-
78-
TextEntry::make('file_number')
79-
->label(__('beneficiary.section.initial_evaluation.labels.file_number'))
80-
->placeholder(__('beneficiary.placeholder.file_number')),
81-
82-
TextEntry::make('specialist.full_name')
83-
->label(__('beneficiary.section.initial_evaluation.labels.specialist'))
84-
->placeholder(__('beneficiary.placeholder.specialist')),
85-
86-
TextEntry::make('method_of_identifying_the_service')
87-
->label(__('beneficiary.section.initial_evaluation.labels.method_of_identifying_the_service'))
88-
->placeholder(__('beneficiary.placeholder.method_of_identifying_the_service'))
89-
->columnSpanFull(),
82+
Group::make()
83+
->columns(2)
84+
->relationship('evaluateDetails')
85+
->schema([
86+
DateEntry::make('registered_date')
87+
->label(__('beneficiary.section.initial_evaluation.labels.registered_date')),
88+
89+
TextEntry::make('file_number')
90+
->label(__('beneficiary.section.initial_evaluation.labels.file_number'))
91+
->placeholder(__('beneficiary.placeholder.file_number')),
92+
93+
TextEntry::make('specialist.full_name')
94+
->label(__('beneficiary.section.initial_evaluation.labels.specialist'))
95+
->placeholder(__('beneficiary.placeholder.specialist'))
96+
->columnSpanFull(),
97+
98+
TextEntry::make('method_of_identifying_the_service')
99+
->label(__('beneficiary.section.initial_evaluation.labels.method_of_identifying_the_service'))
100+
->placeholder(__('beneficiary.placeholder.method_of_identifying_the_service'))
101+
->columnSpanFull(),
102+
]),
90103
]),
91104
];
92105
}
@@ -120,11 +133,11 @@ public static function getViolenceFormComponents(): array
120133
Section::make()
121134
->relationship('violence')
122135
->maxWidth('3xl')
123-
->columns()
136+
->columns(2)
124137
->schema([
125138
Select::make('violence_types')
126139
->label(__('beneficiary.section.initial_evaluation.labels.violence_type'))
127-
->placeholder(__('beneficiary.placeholder.violence_type'))
140+
->placeholder(__('beneficiary.section.initial_evaluation.placeholders.select_many'))
128141
->options(Violence::options())
129142
->multiple()
130143
->required(),
@@ -141,6 +154,18 @@ public static function getViolenceFormComponents(): array
141154
->options(Frequency::options())
142155
->required(),
143156

157+
Select::make('violence_means')
158+
->label(__('beneficiary.section.initial_evaluation.labels.violence_means'))
159+
->placeholder(__('beneficiary.section.initial_evaluation.placeholders.select_many'))
160+
->options(ViolenceMeans::options())
161+
->multiple(),
162+
163+
TextInput::make('violence_means_specify')
164+
->label(__('beneficiary.section.initial_evaluation.labels.violence_means_specify'))
165+
->placeholder(__('beneficiary.placeholder.violence_means_specify'))
166+
->maxLength(100)
167+
->columnSpanFull(),
168+
144169
RichEditor::make('description')
145170
->label(__('beneficiary.section.initial_evaluation.labels.description'))
146171
->placeholder(__('beneficiary.placeholder.description'))
@@ -156,7 +181,7 @@ public static function getViolenceInfolistComponents(): array
156181
return [
157182
Group::make()
158183
->relationship('violence')
159-
->columns()
184+
->columns(2)
160185
->schema([
161186
TextEntry::make('violence_types')
162187
->label(__('beneficiary.section.initial_evaluation.labels.violence_type')),
@@ -169,6 +194,15 @@ public static function getViolenceInfolistComponents(): array
169194
->label(__('beneficiary.section.initial_evaluation.labels.frequency_violence'))
170195
->placeholder(__('beneficiary.placeholder.frequency_violence')),
171196

197+
TextEntry::make('violence_means')
198+
->label(__('beneficiary.section.initial_evaluation.labels.violence_means'))
199+
->placeholder(__('beneficiary.placeholder.violence_means_specify')),
200+
201+
TextEntry::make('violence_means_specify')
202+
->label(__('beneficiary.section.initial_evaluation.labels.violence_means_specify'))
203+
->placeholder(__('beneficiary.placeholder.violence_means_specify'))
204+
->columnSpanFull(),
205+
172206
TextEntry::make('description')
173207
->label(__('beneficiary.section.initial_evaluation.labels.description'))
174208
->placeholder(__('beneficiary.placeholder.description'))
@@ -240,6 +274,69 @@ public static function getBeneficiarySituationInfolistComponents(): array
240274
];
241275
}
242276

277+
public static function getRiskFactorsInfolistComponents(): array
278+
{
279+
return [
280+
Group::make()
281+
->relationship('riskFactors')
282+
->schema([
283+
Section::make(__('beneficiary.section.initial_evaluation.heading.violence_history'))
284+
->schema(self::getInfolistSchemaFromEnum(ViolenceHistorySchema::options())),
285+
Section::make(__('beneficiary.section.initial_evaluation.heading.violences_types'))
286+
->schema(self::getInfolistSchemaFromEnum(ViolencesTypesSchema::options())),
287+
Section::make(__('beneficiary.section.initial_evaluation.heading.risk_factors'))
288+
->schema(self::getInfolistSchemaFromEnum(RiskFactorsSchema::options())),
289+
Section::make(__('beneficiary.section.initial_evaluation.heading.victim_perception_of_the_risk'))
290+
->schema(self::getInfolistSchemaFromEnum(VictimPerceptionOfTheRiskSchema::options())),
291+
Section::make(__('beneficiary.section.initial_evaluation.heading.aggravating_factors'))
292+
->schema(self::getInfolistSchemaFromEnum(AggravatingFactorsSchema::options())),
293+
Section::make(__('beneficiary.section.initial_evaluation.heading.social_support'))
294+
->columns()
295+
->schema(self::getSocialSupportInfolistSchema()),
296+
]),
297+
];
298+
}
299+
300+
public static function getSocialSupportInfolistSchema(): array
301+
{
302+
return [
303+
TextEntry::make('extended_family_can_provide')
304+
->label(__('beneficiary.section.initial_evaluation.labels.extended_family_can_provide'))
305+
->formatStateUsing(fn ($record) => $record?->extended_family_can_not_provide
306+
? $record->extended_family_can_not_provide->label()
307+
: ($record?->extended_family_can_provide
308+
? $record->extended_family_can_provide->map(fn ($v) => $v->label())->implode(', ')
309+
: null)),
310+
311+
TextEntry::make('friends_can_provide')
312+
->label(__('beneficiary.section.initial_evaluation.labels.friends_can_provide'))
313+
->formatStateUsing(fn ($record) => $record?->friends_can_not_provide
314+
? $record->friends_can_not_provide->label()
315+
: ($record?->friends_can_provide
316+
? $record->friends_can_provide->map(fn ($v) => $v->label())->implode(', ')
317+
: null)),
318+
];
319+
}
320+
321+
public static function getRequestedServicesInfolistComponents(): array
322+
{
323+
return [
324+
Group::make()
325+
->relationship('requestedServices')
326+
->schema([
327+
TextEntry::make('requested_services')
328+
->label(__('beneficiary.section.initial_evaluation.heading.types_of_requested_services'))
329+
->formatStateUsing(fn ($state) => filled($state)
330+
? collect($state)->map(fn ($v) => $v->label())->implode(', ')
331+
: null),
332+
333+
TextEntry::make('other_services_description')
334+
->label(__('beneficiary.section.initial_evaluation.labels.other_services_description'))
335+
->placeholder(__('beneficiary.placeholder.other_services')),
336+
]),
337+
];
338+
}
339+
243340
public static function getViolenceHistorySchema(): array
244341
{
245342
$enumOptions = ViolenceHistorySchema::options();
@@ -364,7 +461,7 @@ public static function getInfolistSchemaFromEnum(array $enumOptions): array
364461

365462
$result ??= '-';
366463

367-
$description = data_get($record->riskFactors->risk_factors, "{$key}.description");
464+
$description = data_get($record?->riskFactors?->risk_factors, "{$key}.description");
368465

369466
if (filled($description)) {
370467
$result .= " ({$description})";

0 commit comments

Comments
 (0)