Skip to content

Commit

Permalink
Merge pull request #473 from code4romania/450-ngo-admin-beneficiari-e…
Browse files Browse the repository at this point in the history
…valuare-initiala-factori-de-risc-suport-social-enhance-social-support-selectors-family-friends

add fields for risk factors
  • Loading branch information
gheorghelupu17 authored Jan 1, 2025
2 parents 06fda38 + e484f5e commit 2bb6096
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
]),

];
}

Expand Down Expand Up @@ -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(),

];
}

Expand Down
23 changes: 21 additions & 2 deletions app/Models/RiskFactors.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('risk_factors', function (Blueprint $table) {
$table->boolean('extended_family_can_not_provide')->nullable();
$table->boolean('friends_can_not_provide')->nullable();
});
}
};
2 changes: 2 additions & 0 deletions lang/ro/beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -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ă):',
Expand Down

0 comments on commit 2bb6096

Please sign in to comment.