Skip to content

Commit

Permalink
update reason removed
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 1, 2024
1 parent 5daf982 commit c9add66
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 5 deletions.
25 changes: 25 additions & 0 deletions app/Enums/Beneficiary/ReasonRemoved.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Enums\Beneficiary;

use App\Concerns;

enum ReasonRemoved: string
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
use Concerns\Enums\HasLabel;

case DECEASED_HOME = 'deceased_home';
case DECEASED_HOSPITAL = 'deceased_hospital';
case RELOCATED_CITY = 'relocated_city';
case RELOCATED_ABROAD = 'relocated_abroad';
case OTHER = 'other';

protected function labelKeyPrefix(): ?string
{
return 'beneficiary.reason_removed';
}
}
38 changes: 34 additions & 4 deletions app/Filament/Forms/Components/BeneficiaryProgram.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace App\Filament\Forms\Components;

use App\Enums\Beneficiary\ReasonRemoved;
use App\Enums\Beneficiary\Status;
use App\Models\Beneficiary;
use App\Models\User;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Illuminate\Contracts\Database\Eloquent\Builder;
Expand Down Expand Up @@ -42,6 +44,23 @@ protected function getViewComponents(): array
Value::make('status')
->label(__('field.current_status')),

Value::make('reason_removed')
->visible(fn (callable $get) => Status::REMOVED->is($get('status')))
->label(__('field.reason_removed'))
->content(function (Beneficiary $record) {
$parts = [];

if ($record->reason_removed instanceof ReasonRemoved) {
$parts[] = $record->reason_removed->label();
}

if (filled($record->reason_removed_notes)) {
$parts[] = "({$record->reason_removed_notes})";
}

return implode(' ', $parts);
}),

Value::make('nurse')
->label(__('field.allocated_nurse'))
->content(fn (Beneficiary $record) => "#{$record->nurse->id} {$record->nurse->full_name}"),
Expand Down Expand Up @@ -87,11 +106,22 @@ protected function getEditComponents(): array
->reactive()
->required(),

TextInput::make('reason_removed')
->label(__('field.reason_removed'))
Grid::make('status_reason')
->columns()
->visible(fn (callable $get) => Status::REMOVED->is($get('status')))
->maxLength(200)
->required(),
->schema([
Select::make('reason_removed')
->label(__('field.reason_removed'))
->placeholder(__('placeholder.choose'))
->options(ReasonRemoved::options())
->reactive()
->required(),

TextInput::make('reason_removed_notes')
->label(__('field.reason_removed_notes'))
->maxLength(200)
->required(fn (callable $get) => ReasonRemoved::OTHER->is($get('reason_removed'))),
]),

];
}
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Concerns\HasLocation;
use App\Enums\Beneficiary\Ethnicity;
use App\Enums\Beneficiary\IDType;
use App\Enums\Beneficiary\ReasonRemoved;
use App\Enums\Beneficiary\Type;
use App\Enums\Beneficiary\WorkStatus;
use App\Enums\Gender;
Expand Down Expand Up @@ -57,6 +58,7 @@ class Beneficiary extends Model
'phone',
'notes',
'reason_removed',
'reason_removed_notes',

'nurse_id',
'family_id',
Expand All @@ -71,6 +73,7 @@ class Beneficiary extends Model
'gender' => Gender::class,
'ethnicity' => Ethnicity::class,
'work_status' => WorkStatus::class,
'reason_removed' => ReasonRemoved::class,
'integrated' => 'boolean',
'date_of_birth' => 'date',
'does_not_have_cnp' => 'boolean',
Expand Down
4 changes: 3 additions & 1 deletion database/factories/BeneficiaryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Enums\Beneficiary\Ethnicity;
use App\Enums\Beneficiary\IDType;
use App\Enums\Beneficiary\ReasonRemoved;
use App\Enums\Beneficiary\Status;
use App\Enums\Beneficiary\Type;
use App\Enums\Beneficiary\WorkStatus;
Expand Down Expand Up @@ -66,7 +67,8 @@ public function configure(): static

return [
'status' => $status,
'reason_removed' => Status::REMOVED->is($status) ? fake()->sentence() : null,
'reason_removed' => Status::REMOVED->is($status) ? fake()->randomElement(ReasonRemoved::values()) : null,
'reason_removed_notes' => Status::REMOVED->is($status) ? fake()->sentence() : null,
];
})
->afterCreating(function (Beneficiary $beneficiary) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

use App\Enums\Beneficiary\ReasonRemoved;
use App\Models\Beneficiary;
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('beneficiaries', function (Blueprint $table) {
$table->renameColumn('reason_removed', 'reason_removed_notes');
});

Schema::table('beneficiaries', function (Blueprint $table) {
$table->string('reason_removed')
->nullable()
->after('family_id');
});

Beneficiary::query()
->whereNotNull('reason_removed_notes')
->whereNull('reason_removed')
->update([
'reason_removed' => ReasonRemoved::OTHER,
]);
}
};
8 changes: 8 additions & 0 deletions lang/ro/beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
'other' => 'Altă situație',
],

'reason_removed' => [
'deceased_home' => 'Deces la domiciliu',
'deceased_hospital' => 'Deces la spital',
'relocated_city' => 'Relocare în altă localitate',
'relocated_abroad' => 'Relocare în străinătate',
'other' => 'Alt motiv',
],

'id_type' => [
'birth_certificate' => 'Certificat de naștere',
'id_card' => 'Carte de identitate',
Expand Down
1 change: 1 addition & 0 deletions lang/ro/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
'performed_interventions_count' => 'Servicii efectuate',
'phone' => 'Telefon',
'reason_removed' => 'Motiv scoatere din evidență',
'reason_removed_notes' => 'Observații scoatere din evidență',
'role' => 'Rol',
'section_details' => ':section - detalii',
'service_name' => 'Nume serviciu',
Expand Down

0 comments on commit c9add66

Please sign in to comment.