From 56a34673a4b8f13a5f89b3d34c3a2e325edda50e Mon Sep 17 00:00:00 2001 From: Alex Popa Date: Mon, 30 Dec 2024 22:52:01 +0200 Subject: [PATCH 1/2] add fields for risk factors --- .../InitialEvaluation/EditRiskFactors.php | 48 +++++++++++++++---- app/Models/RiskFactors.php | 23 ++++++++- lang/ro/beneficiary.php | 2 + 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/InitialEvaluation/EditRiskFactors.php b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/InitialEvaluation/EditRiskFactors.php index b41b034c..66fb953e 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/InitialEvaluation/EditRiskFactors.php +++ b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/InitialEvaluation/EditRiskFactors.php @@ -17,11 +17,13 @@ use App\Infolists\Components\EnumEntry; use App\Models\Beneficiary; use App\Services\Breadcrumb\BeneficiaryBreadcrumb; +use Filament\Forms\Components\Checkbox; use Filament\Forms\Components\Group; use Filament\Forms\Components\Radio; use Filament\Forms\Components\Section; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; +use Filament\Forms\Get; use Filament\Infolists\Components\Group as InfolistGroup; use Filament\Infolists\Components\Section as InfolistSection; use Filament\Infolists\Components\TextEntry; @@ -117,14 +119,32 @@ public static function getAggravatingFactorsSchema(): array public static function getSocialSupportSchema(): array { return [ - Select::make('extended_family_can_provide') - ->label(__('beneficiary.section.initial_evaluation.labels.extended_family_can_provide')) - ->multiple() - ->options(Helps::options()), - Select::make('friends_can_provide') - ->label(__('beneficiary.section.initial_evaluation.labels.friends_can_provide')) - ->multiple() - ->options(Helps::options()), + Group::make() + ->schema([ + Select::make('extended_family_can_provide') + ->label(__('beneficiary.section.initial_evaluation.labels.extended_family_can_provide')) + ->multiple() + ->options(Helps::options()) + ->disabled(fn (Get $get) => $get('extended_family_can_not_provide')), + + Checkbox::make('extended_family_can_not_provide') + ->label(__('beneficiary.section.initial_evaluation.labels.extended_family_can_not_provide')) + ->live(), + ]), + + Group::make() + ->schema([ + Select::make('friends_can_provide') + ->label(__('beneficiary.section.initial_evaluation.labels.friends_can_provide')) + ->multiple() + ->options(Helps::options()) + ->disabled(fn (Get $get) => $get('friends_can_not_provide')), + + Checkbox::make('friends_can_not_provide') + ->label(__('beneficiary.section.initial_evaluation.labels.friends_can_not_provide')) + ->live(), + ]), + ]; } @@ -197,10 +217,22 @@ public static function getSocialSupportInfolistSchema(): array return [ EnumEntry::make('extended_family_can_provide') ->label(__('beneficiary.section.initial_evaluation.labels.extended_family_can_provide')) + ->formatStateUsing( + fn (Beneficiary $record, $state) => $record->riskFactors->extended_family_can_not_provide ? + __('beneficiary.section.initial_evaluation.labels.extended_family_can_not_provide') : + $state + ) ->badge(), + EnumEntry::make('friends_can_provide') ->label(__('beneficiary.section.initial_evaluation.labels.friends_can_provide')) + ->formatStateUsing( + fn (Beneficiary $record, $state) => $record->riskFactors->friends_can_not_provide ? + __('beneficiary.section.initial_evaluation.labels.friends_can_not_provide') : + $state + ) ->badge(), + ]; } diff --git a/app/Models/RiskFactors.php b/app/Models/RiskFactors.php index f487d478..44d1bc89 100644 --- a/app/Models/RiskFactors.php +++ b/app/Models/RiskFactors.php @@ -24,7 +24,9 @@ class RiskFactors extends Model protected $fillable = [ 'risk_factors', 'extended_family_can_provide', + 'extended_family_can_not_provide', 'friends_can_provide', + 'friends_can_not_provide', 'risk_level', ]; @@ -38,9 +40,26 @@ class RiskFactors extends Model protected static function boot() { parent::boot(); - self::creating(fn (RiskFactors $model) => self::calculateRiskLevel($model)); + self::creating(function (RiskFactors $model) { + self::formatSocialSupport($model); + self::calculateRiskLevel($model); + }); + + self::updating(function (RiskFactors $model) { + self::formatSocialSupport($model); + self::calculateRiskLevel($model); + }); + } - self::updating(fn (RiskFactors $model) => self::calculateRiskLevel($model)); + public static function formatSocialSupport(self $model): void + { + if ($model->extended_family_can_not_provide) { + $model->extended_family_can_provide = []; + } + + if ($model->friends_can_not_provide) { + $model->friends_can_provide = []; + } } public static function calculateRiskLevel(self $model): void diff --git a/lang/ro/beneficiary.php b/lang/ro/beneficiary.php index 67d468eb..5aad5f8a 100644 --- a/lang/ro/beneficiary.php +++ b/lang/ro/beneficiary.php @@ -240,7 +240,9 @@ 'domestic_violence_during_pregnancy' => '23. Au existat acte de violență domestică în timpul sarcinii?', 'extended_family_can_provide' => '24. Familia extinsă poate oferi', + 'extended_family_can_not_provide' => 'Familia extinsă nu poate oferi suport social', 'friends_can_provide' => '25. Vecinii/ prietenii pot oferi', + 'friends_can_not_provide' => 'Vecinii/ prietenii nu pot oferi suport social', 'moment_of_evaluation' => 'Momentul evaluării situației', 'description_of_situation' => 'A se include și situația juridică - acțiuni în instanță, situația socio-familială, situația medicală actuală):', From e484f5e9ecf63527c2df3e1e2c11d05b1e292a47 Mon Sep 17 00:00:00 2001 From: Alex Popa Date: Mon, 30 Dec 2024 22:52:45 +0200 Subject: [PATCH 2/2] migration --- ...195954_add_fields_in_risk_factors_table.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 database/migrations/2024_12_30_195954_add_fields_in_risk_factors_table.php diff --git a/database/migrations/2024_12_30_195954_add_fields_in_risk_factors_table.php b/database/migrations/2024_12_30_195954_add_fields_in_risk_factors_table.php new file mode 100644 index 00000000..050383c6 --- /dev/null +++ b/database/migrations/2024_12_30_195954_add_fields_in_risk_factors_table.php @@ -0,0 +1,18 @@ +boolean('extended_family_can_not_provide')->nullable(); + $table->boolean('friends_can_not_provide')->nullable(); + }); + } +};