44
55namespace App \Filament \Organizations \Resources \Cases \Schemas ;
66
7+ use App \Enums \AggressorRelationship ;
78use App \Filament \Organizations \Resources \Cases \CaseResource ;
89use App \Filament \Organizations \Resources \Cases \Resources \CloseFile \CloseFileResource ;
910use App \Filament \Organizations \Resources \Cases \Resources \InitialEvaluation \InitialEvaluationResource ;
11+ use App \Infolists \Components \SectionHeader ;
12+ use App \Models \Aggressor ;
1013use App \Models \Beneficiary ;
1114use Carbon \Carbon ;
1215use Filament \Actions \Action ;
1316use Filament \Infolists \Components \RepeatableEntry ;
1417use Filament \Infolists \Components \TextEntry ;
18+ use Filament \Schemas \Components \EmptyState ;
1519use Filament \Schemas \Components \Grid ;
1620use Filament \Schemas \Components \Section ;
1721use Filament \Schemas \Schema ;
22+ use Filament \Support \Icons \Heroicon ;
23+ use Illuminate \Support \Collection ;
1824
1925class CaseInfolist
2026{
2127 public static function configure (Schema $ schema ): Schema
2228 {
2329 return $ schema
2430 ->columns (2 )
31+ ->extraAttributes ([
32+ 'class ' => 'h-full ' ,
33+ ])
2534 ->components ([
2635 Grid::make (2 )
2736 ->columnSpanFull ()
@@ -91,7 +100,88 @@ public static function configure(Schema $schema): Schema
91100 ->schema ([
92101 TextEntry::make ('flowPresentation.presentation_mode ' )
93102 ->label (__ ('field.presentation_mode ' ))
103+ ->formatStateUsing (fn ($ state ) => is_object ($ state ) && method_exists ($ state , 'getLabel ' ) ? $ state ->getLabel () : '— ' )
94104 ->placeholder ('— ' ),
105+ TextEntry::make ('flowPresentation.referringInstitution.name ' )
106+ ->label (__ ('field.referring_institution ' ))
107+ ->placeholder ('— ' ),
108+ TextEntry::make ('details.family_doctor_name ' )
109+ ->label (__ ('field.family_doctor_name ' ))
110+ ->placeholder ('— ' ),
111+ TextEntry::make ('details.family_doctor_contact ' )
112+ ->label (__ ('field.family_doctor_contact ' ))
113+ ->placeholder ('— ' ),
114+ RepeatableEntry::make ('aggressors ' )
115+ ->label (__ ('case.view.aggressor ' ))
116+ ->hiddenLabel ()
117+ ->columns (2 )
118+ ->schema ([
119+ SectionHeader::make ('header ' )
120+ ->state (function (SectionHeader $ component ): string {
121+ $ path = $ component ->getStatePath ();
122+ $ parts = explode ('. ' , $ path );
123+ $ index = (int ) ($ parts [1 ] ?? 0 );
124+ $ parentState = $ component ->getContainer ()?->getParentComponent()?->getState();
125+ $ total = $ parentState instanceof Collection ? $ parentState ->count () : (is_countable ($ parentState ) ? count ($ parentState ) : 0 );
126+
127+ return $ total > 1
128+ ? __ ('case.view.aggressor ' ).' ( ' .($ index + 1 ).' din ' .$ total .' ' .__ ('case.aggressors_documented ' ).') '
129+ : __ ('case.view.aggressor ' );
130+ })
131+ ->visible (fn (SectionHeader $ component ): bool => $ component ->getContainer ()?->getParentComponent()?->getState() instanceof Collection
132+ && $ component ->getContainer ()->getParentComponent ()->getState ()->count () > 0 ),
133+ TextEntry::make ('relationship ' )
134+ ->label (__ ('field.aggressor_relationship ' ))
135+ ->formatStateUsing (fn ($ state , Aggressor $ record ): string => $ record ->relationship !== null
136+ ? ($ record ->relationship === AggressorRelationship::OTHER && $ record ->relationship_other
137+ ? $ record ->relationship ->getLabel ().' ( ' .$ record ->relationship_other .') '
138+ : $ record ->relationship ->getLabel ())
139+ : '— ' )
140+ ->placeholder ('— ' ),
141+ TextEntry::make ('violence_types ' )
142+ ->label (__ ('field.aggressor_violence_types ' ))
143+ ->formatStateUsing (function ($ state ): string {
144+ if ($ state === null ) {
145+ return '— ' ;
146+ }
147+ if ($ state instanceof Collection) {
148+ return $ state ->map (fn ($ v ) => is_object ($ v ) && method_exists ($ v , 'getLabel ' ) ? $ v ->getLabel () : (string ) $ v )->join (', ' );
149+ }
150+ if (is_iterable ($ state )) {
151+ return collect ($ state )->map (fn ($ v ) => is_object ($ v ) && method_exists ($ v , 'getLabel ' ) ? $ v ->getLabel () : (string ) $ v )->join (', ' );
152+ }
153+
154+ return '— ' ;
155+ })
156+ ->placeholder ('— ' ),
157+ TextEntry::make ('has_protection_order ' )
158+ ->label (__ ('field.has_protection_order ' ))
159+ ->formatStateUsing (fn ($ state ) => is_object ($ state ) && method_exists ($ state , 'getLabel ' ) ? $ state ->getLabel () : '— ' )
160+ ->placeholder ('— ' ),
161+ TextEntry::make ('electronically_monitored ' )
162+ ->label (__ ('field.electronically_monitored ' ))
163+ ->formatStateUsing (fn ($ state ) => is_object ($ state ) && method_exists ($ state , 'getLabel ' ) ? $ state ->getLabel () : '— ' )
164+ ->placeholder ('— ' ),
165+ ])
166+ ->visible (fn (Beneficiary $ record ): bool => $ record ->aggressors ->isNotEmpty ()),
167+ Grid::make (2 )
168+ ->schema ([
169+ TextEntry::make ('antecedents.has_police_reports ' )
170+ ->label (__ ('field.has_police_reports ' ))
171+ ->formatStateUsing (fn ($ state ) => is_object ($ state ) && method_exists ($ state , 'getLabel ' ) ? $ state ->getLabel () : '— ' )
172+ ->placeholder ('— ' ),
173+ TextEntry::make ('antecedents.police_report_count ' )
174+ ->label (__ ('field.police_report_count ' ))
175+ ->placeholder ('— ' ),
176+ TextEntry::make ('antecedents.has_medical_reports ' )
177+ ->label (__ ('field.has_medical_reports ' ))
178+ ->formatStateUsing (fn ($ state ) => is_object ($ state ) && method_exists ($ state , 'getLabel ' ) ? $ state ->getLabel () : '— ' )
179+ ->placeholder ('— ' ),
180+ TextEntry::make ('antecedents.medical_report_count ' )
181+ ->label (__ ('field.medical_report_count ' ))
182+ ->placeholder ('— ' ),
183+ ])
184+ ->visible (fn (Beneficiary $ record ): bool => $ record ->antecedents !== null ),
95185 ]),
96186
97187 Section::make (__ ('case.view.initial_evaluation ' ))
@@ -111,6 +201,16 @@ public static function configure(Schema $schema): Schema
111201 ->link (),
112202 ])
113203 ->schema ([
204+ EmptyState::make (__ ('case.view.initial_evaluation ' ))
205+ ->description (__ ('case.view.empty_initial_eval ' ))
206+ ->icon (Heroicon::OutlinedClipboardDocumentList)
207+ ->visible (fn (Beneficiary $ record ): bool => $ record ->evaluateDetails === null )
208+ ->footer ([
209+ Action::make ('create_initial_evaluation_empty ' )
210+ ->label (__ ('case.view.start_evaluation ' ))
211+ ->url (fn (Beneficiary $ record ): string => CaseResource::getUrl ('create_initial_evaluation ' , ['record ' => $ record ]))
212+ ->button (),
213+ ]),
114214 TextEntry::make ('evaluateDetails.registered_date ' )
115215 ->label (__ ('beneficiary.labels.registered_date ' ))
116216 ->formatStateUsing (fn (mixed $ state ): string => self ::formatBirthdateState ($ state , 'd.m.Y ' ))
@@ -131,7 +231,18 @@ public static function configure(Schema $schema): Schema
131231 ->visible (fn (Beneficiary $ record ): bool => $ record ->multidisciplinaryEvaluation === null && $ record ->detailedEvaluationResult === null && ! $ record ->detailedEvaluationSpecialists ()->exists ())
132232 ->link (),
133233 ])
134- ->schema ([]),
234+ ->schema ([
235+ EmptyState::make (__ ('case.view.detailed_evaluation ' ))
236+ ->description (__ ('case.view.empty_detailed_eval ' ))
237+ ->icon (Heroicon::OutlinedChartBarSquare)
238+ ->visible (fn (Beneficiary $ record ): bool => $ record ->multidisciplinaryEvaluation === null && $ record ->detailedEvaluationResult === null && ! $ record ->detailedEvaluationSpecialists ()->exists ())
239+ ->footer ([
240+ Action::make ('start_detailed_evaluation_empty ' )
241+ ->label (__ ('case.view.start_evaluation ' ))
242+ ->url (fn (Beneficiary $ record ): string => CaseResource::getUrl ('create_detailed_evaluation ' , ['record ' => $ record ]))
243+ ->button (),
244+ ]),
245+ ]),
135246
136247 Section::make (__ ('case.view.intervention_plan ' ))
137248 ->headerActions ([
@@ -146,6 +257,16 @@ public static function configure(Schema $schema): Schema
146257 ->link (),
147258 ])
148259 ->schema ([
260+ EmptyState::make (__ ('case.view.intervention_plan ' ))
261+ ->description (__ ('case.view.empty_intervention_plan ' ))
262+ ->icon (Heroicon::OutlinedClipboardDocumentCheck)
263+ ->visible (fn (Beneficiary $ record ): bool => $ record ->interventionPlan === null )
264+ ->footer ([
265+ Action::make ('create_plan_empty ' )
266+ ->label (__ ('case.view.create_plan ' ))
267+ ->url (fn (Beneficiary $ record ): string => CaseResource::getUrl ('create_intervention_plan ' , ['record ' => $ record ]))
268+ ->button (),
269+ ]),
149270 TextEntry::make ('interventionPlan.plan_date ' )
150271 ->label (__ ('intervention_plan.labels.plan_date ' ))
151272 ->formatStateUsing (fn (mixed $ state ): string => self ::formatBirthdateState ($ state , 'd.m.Y ' ))
@@ -162,14 +283,26 @@ public static function configure(Schema $schema): Schema
162283 ->link (),
163284 ])
164285 ->schema ([
286+ EmptyState::make (__ ('case.view.case_monitoring ' ))
287+ ->description (__ ('case.view.empty_monitoring ' ))
288+ ->icon (Heroicon::OutlinedDocumentChartBar)
289+ ->visible (fn (Beneficiary $ record ): bool => $ record ->monitoring ()->count () === 0 )
290+ ->footer ([
291+ Action::make ('complete_monitoring_empty ' )
292+ ->label (__ ('case.view.complete_monitoring_sheet ' ))
293+ ->url (fn (Beneficiary $ record ): string => CaseResource::getUrl ('edit_case_monitoring ' , ['record ' => $ record ]))
294+ ->button (),
295+ ]),
165296 TextEntry::make ('lastMonitoring.date ' )
166297 ->label (__ ('case.view.last_monitoring ' ))
167298 ->formatStateUsing (fn (mixed $ state ): string => self ::formatBirthdateState ($ state , 'd.m.Y ' ))
168- ->placeholder ('— ' ),
299+ ->placeholder ('— ' )
300+ ->visible (fn (Beneficiary $ record ): bool => $ record ->monitoring ()->count () > 0 ),
169301 TextEntry::make ('monitoring_count ' )
170302 ->label (__ ('case.view.total_monitorings ' ))
171303 ->state (fn (Beneficiary $ record ): string => (string ) $ record ->monitoring ()->count ())
172- ->placeholder ('0 ' ),
304+ ->placeholder ('0 ' )
305+ ->visible (fn (Beneficiary $ record ): bool => $ record ->monitoring ()->count () > 0 ),
173306 ]),
174307
175308 Section::make (__ ('case.view.case_closure ' ))
@@ -186,14 +319,25 @@ public static function configure(Schema $schema): Schema
186319 ->link (),
187320 ])
188321 ->schema ([
322+ EmptyState::make (__ ('case.view.case_closure ' ))
323+ ->description (__ ('case.view.empty_closure ' ))
324+ ->icon (Heroicon::OutlinedDocumentCheck)
325+ ->visible (fn (Beneficiary $ record ): bool => $ record ->closeFile === null )
326+ ->footer ([
327+ Action::make ('complete_closure_empty ' )
328+ ->label (__ ('case.view.complete_closure_sheet ' ))
329+ ->url (fn (Beneficiary $ record ): string => CloseFileResource::getUrl ('create ' , ['beneficiary ' => $ record ]))
330+ ->button ()
331+ ->visible (fn (Beneficiary $ record ): bool => $ record ->status ?->value === 'closed ' ),
332+ ]),
189333 TextEntry::make ('closeFile.date ' )
190334 ->label (__ ('case.view.closed_at ' ))
191335 ->formatStateUsing (fn (mixed $ state ): string => self ::formatBirthdateState ($ state , 'd.m.Y ' ))
192336 ->placeholder ('— ' )
193337 ->visible (fn (Beneficiary $ record ): bool => $ record ->closeFile !== null ),
194338 TextEntry::make ('closeFile.close_method ' )
195339 ->label (__ ('case.view.closure_method ' ))
196- ->formatStateUsing (fn ($ state ) => $ state? ->getLabel() ?? '— ' )
340+ ->formatStateUsing (fn ($ state ) => is_object ( $ state) && method_exists ( $ state , ' getLabel ' ) ? $ state ->getLabel () : '— ' )
197341 ->placeholder ('— ' )
198342 ->visible (fn (Beneficiary $ record ): bool => $ record ->closeFile !== null ),
199343 ]),
@@ -225,11 +369,21 @@ public static function configure(Schema $schema): Schema
225369 ->link (),
226370 ])
227371 ->schema ([
372+ EmptyState::make (__ ('case.view.documents ' ))
373+ ->description (__ ('case.view.empty_documents ' ))
374+ ->icon (Heroicon::OutlinedDocument)
375+ ->visible (fn (Beneficiary $ record ): bool => $ record ->documents ()->count () === 0 )
376+ ->footer ([
377+ Action::make ('upload_document_empty ' )
378+ ->label (__ ('case.view.upload_document ' ))
379+ ->url (fn (Beneficiary $ record ): string => CaseResource::getUrl ('edit_case_documents ' , ['record ' => $ record ]))
380+ ->button (),
381+ ]),
228382 RepeatableEntry::make ('documents ' )
229383 ->schema ([
230384 TextEntry::make ('type ' )
231385 ->label (__ ('document.labels.type ' ))
232- ->formatStateUsing (fn ($ state ) => $ state? ->getLabel() ?? '— ' ),
386+ ->formatStateUsing (fn ($ state ) => is_object ( $ state) && method_exists ( $ state , ' getLabel ' ) ? $ state ->getLabel () : '— ' ),
233387 TextEntry::make ('name ' )
234388 ->label (__ ('document.labels.name ' )),
235389 ])
0 commit comments