Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fields for risk factors #473

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading