Skip to content

Commit

Permalink
Merge pull request #294 from code4romania/move-protection-order-and-m…
Browse files Browse the repository at this point in the history
…onitored-fields-in-aggressors

move protection order and monitored in aggressors
  • Loading branch information
gheorghelupu17 authored Nov 13, 2024
2 parents a021c24 + da4c157 commit 25e06db
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Enums\Drug;
use App\Enums\Gender;
use App\Enums\Occupation;
use App\Enums\ProtectionOrder;
use App\Enums\Studies;
use App\Enums\Ternary;
use App\Enums\Violence;
Expand Down Expand Up @@ -69,8 +70,8 @@ public static function getPersonalInformationFormSchema(): array
public static function aggressorSection(): array
{
return [
Repeater::make('aggressor')
->relationship('aggressor')
Repeater::make('aggressors')
->relationship('aggressors')
->maxWidth('3xl')
->hiddenLabel()
->columns()
Expand All @@ -93,7 +94,7 @@ public static function aggressorSection(): array
->modalSubmitActionLabel(__('general.action.delete'))
)
->itemLabel(function (Get $get) {
if (\count($get('aggressor')) <= 1) {
if (\count($get('aggressors')) <= 1) {
return null;
}

Expand Down Expand Up @@ -210,6 +211,34 @@ public static function aggressorSection(): array
->multiple()
->live(),
]),

Grid::make()
->schema([
Select::make('has_protection_order')
->label(__('field.has_protection_order'))
->placeholder(__('placeholder.select_one'))
->options(ProtectionOrder::options())
->enum(ProtectionOrder::class)
->live(),

Select::make('electronically_monitored')
->label(__('field.electronically_monitored'))
->placeholder(__('placeholder.select_one'))
->options(Ternary::options())
->enum(Ternary::class)
->visible(
fn (Get $get) => ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::ISSUED_BY_COURT) ||
ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::TEMPORARY)
),

TextInput::make('protection_order_notes')
->label(__('field.protection_order_notes'))
->visible(
fn (Get $get) => ! ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::NO) &&
! ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::UNKNOWN)
)
->maxLength(100),
]),
]),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Filament\Organizations\Resources\BeneficiaryResource\Pages;

use App\Concerns\RedirectToPersonalInformation;
use App\Enums\ProtectionOrder;
use App\Enums\Ternary;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use App\Forms\Components\Select;
Expand Down Expand Up @@ -98,34 +97,6 @@ public static function antecedentsSection(): array
->minValue(0)
->maxValue(999),
]),

Grid::make()
->schema([
Select::make('has_protection_order')
->label(__('field.has_protection_order'))
->placeholder(__('placeholder.select_one'))
->options(ProtectionOrder::options())
->enum(ProtectionOrder::class)
->live(),

// Select::make('electronically_monitored')
// ->label(__('field.electronically_monitored'))
// ->placeholder(__('placeholder.select_one'))
// ->options(Ternary::options())
// ->enum(Ternary::class)
// ->visible(
// fn (Get $get) => ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::ISSUED_BY_COURT) ||
// ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::TEMPORARY)
// ),

TextInput::make('protection_order_notes')
->label(__('field.protection_order_notes'))
->visible(
fn (Get $get) => ! ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::NO) &&
! ProtectionOrder::isValue($get('has_protection_order'), ProtectionOrder::UNKNOWN)
)
->maxLength(100),
]),
]),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Enums\CaseStatus;
use App\Enums\Ternary;
use App\Filament\Organizations\Resources\BeneficiaryResource;
use App\Filament\Organizations\Resources\BeneficiaryResource\Actions\EditExtraLarge;
use App\Filament\Organizations\Resources\BeneficiaryResource\Actions\ViewDetailsAction;
use App\Filament\Organizations\Resources\BeneficiaryResource\Widgets\CaseTeamListWidget;
use App\Filament\Organizations\Resources\BeneficiaryResource\Widgets\CloseFileWidget;
Expand Down Expand Up @@ -231,7 +230,7 @@ protected function personalInformationSection(): Section
->icon('heroicon-o-phone')
->url(fn ($state) => "tel:{$state}"),

RepeatableEntry::make('aggressor')
RepeatableEntry::make('aggressors')
->label(__('beneficiary.section.personal_information.section.aggressor'))
->columns()
->columnSpanFull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ protected static function aggressorSection(): array
'class' => 'h-full',
])
->schema([
RepeatableEntry::make('aggressor')
RepeatableEntry::make('aggressors')
->columns()
->columnSpanFull()
->hiddenLabel()
Expand Down Expand Up @@ -282,6 +282,18 @@ protected static function aggressorSection(): array
TextEntry::make('drugs')
->label(__('field.aggressor_drugs')),
]),

Grid::make()
->schema([
TextEntry::make('has_protection_order')
->label(__('field.has_protection_order')),

TextEntry::make('electronically_monitored')
->label(__('field.electronically_monitored')),

TextEntry::make('protection_order_notes')
->label(__('field.protection_order_notes')),
]),
]),
]),
];
Expand Down Expand Up @@ -323,19 +335,6 @@ protected static function antecedentsSection(): array
->placeholder(__('placeholder.number'))
->numeric(),
]),

Grid::make()
->schema([
TextEntry::make('has_protection_order')
->label(__('field.has_protection_order')),

// TextEntry::make('electronically_monitored')
// ->label(__('field.electronically_monitored')),

TextEntry::make('protection_order_notes')
->label(__('field.protection_order_notes')),
]),

]),
];
}
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Aggressor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Enums\Drug;
use App\Enums\Gender;
use App\Enums\Occupation;
use App\Enums\ProtectionOrder;
use App\Enums\Studies;
use App\Enums\Ternary;
use App\Enums\Violence;
Expand Down Expand Up @@ -42,6 +43,9 @@ class Aggressor extends Model
'relationship',
'studies',
'violence_types',
'has_protection_order',
'electronically_monitored',
'protection_order_notes',
];

protected $casts = [
Expand All @@ -57,5 +61,7 @@ class Aggressor extends Model
'relationship' => AggressorRelationship::class,
'studies' => Studies::class,
'violence_types' => AsEnumCollection::class . ':' . Violence::class,
'has_protection_order' => ProtectionOrder::class,
'electronically_monitored' => Ternary::class,
];
}
2 changes: 1 addition & 1 deletion app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function children(): HasMany
return $this->hasMany(Children::class);
}

public function aggressor(): HasMany
public function aggressors(): HasMany
{
return $this->hasMany(Aggressor::class);
}
Expand Down
6 changes: 0 additions & 6 deletions app/Models/BeneficiaryAntecedents.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Models;

use App\Concerns\BelongsToBeneficiary;
use App\Enums\ProtectionOrder;
use App\Enums\Ternary;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -20,15 +19,10 @@ class BeneficiaryAntecedents extends Model
'police_report_count',
'has_medical_reports',
'medical_report_count',
'has_protection_order',
'electronically_monitored',
'protection_order_notes',
];

protected $casts = [
'has_medical_reports' => Ternary::class,
'has_police_reports' => Ternary::class,
'has_protection_order' => ProtectionOrder::class,
'electronically_monitored' => Ternary::class,
];
}
4 changes: 4 additions & 0 deletions database/factories/AggressorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Enums\Drug;
use App\Enums\Gender;
use App\Enums\Occupation;
use App\Enums\ProtectionOrder;
use App\Enums\Studies;
use App\Enums\Ternary;
use App\Enums\Violence;
Expand Down Expand Up @@ -39,6 +40,9 @@ public function definition(): array
'has_psychiatric_history' => fake()->randomElement(Ternary::values()),
'has_drug_history' => fake()->randomElement(Ternary::values()),
'legal_history' => fake()->randomElements(AggressorLegalHistory::values()),
'has_protection_order' => fake()->randomElement(ProtectionOrder::values()),
'electronically_monitored' => fake()->randomElement(Ternary::values()),
'protection_order_notes' => fake()->text(100),
];
}

Expand Down
4 changes: 0 additions & 4 deletions database/factories/BeneficiaryAntecedentsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Database\Factories;

use App\Enums\ProtectionOrder;
use App\Enums\Ternary;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand All @@ -25,9 +24,6 @@ public function definition(): array
'police_report_count' => fake()->numberBetween(0, 300),
'has_medical_reports' => fake()->randomElement(Ternary::values()),
'medical_report_count' => fake()->numberBetween(0, 300),
'has_protection_order' => fake()->randomElement(ProtectionOrder::values()),
'electronically_monitored' => fake()->randomElement(Ternary::values()),
'protection_order_notes' => fake()->text(100),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('aggressors', function (Blueprint $table) {
$table->string('has_protection_order')->nullable();
$table->string('electronically_monitored')->nullable();
$table->string('protection_order_notes')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('aggressors', function (Blueprint $table) {
//
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

use App\Models\Aggressor;
use App\Models\BeneficiaryAntecedents;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
BeneficiaryAntecedents::query()
->with(['beneficiary.aggressors'])
->whereNotNull(['has_protection_order',
'electronically_monitored',
'protection_order_notes'])
->each(
fn (BeneficiaryAntecedents $beneficiaryAntecedents) => $beneficiaryAntecedents
->beneficiary
->aggressors
->each(
fn (Aggressor $aggressor) => $aggressor->update([
'has_protection_order' => $beneficiaryAntecedents->has_protection_order,
'electronically_monitored' => $beneficiaryAntecedents->electronically_monitored,
'protection_order_notes' => $beneficiaryAntecedents->protection_order_notes,
])
),
);
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('aggressors', function (Blueprint $table) {
//
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('beneficiary_antecedents', function (Blueprint $table) {
$table->dropColumn('has_protection_order');
$table->dropColumn('electronically_monitored');
$table->dropColumn('protection_order_notes');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('antecedents', function (Blueprint $table) {
//
});
}
};

0 comments on commit 25e06db

Please sign in to comment.