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

Change beneficiary id from url with ulid and display organization ben… #415

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/Concerns/RedirectToDetailedEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait RedirectToDetailedEvaluation
protected function getRedirectUrl(): string
{
return self::$resource::getUrl('view_detailed_evaluation', [
'record' => $this->record->id,
'record' => $this->record,
'tab' => \sprintf('-%s-tab', $this->getTabSlug()),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Concerns/RedirectToIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait RedirectToIdentity
protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('view_identity', [
'record' => $this->record->id,
'record' => $this->record,
'tab' => \sprintf('-%s-tab', $this->getTabSlug()),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Concerns/RedirectToInitialEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait RedirectToInitialEvaluation
protected function getRedirectUrl(): string
{
return self::$resource::getUrl('view_initial_evaluation', [
'record' => $this->record->id,
'record' => $this->record,
'tab' => \sprintf('-%s-tab', $this->getTabSlug()),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Concerns/RedirectToMonitoring.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait RedirectToMonitoring
protected function getRedirectUrl(): ?string
{
return self::getParentResource()::getUrl('monitorings.view', [
'parent' => $this->getRecord()->beneficiary_id,
'parent' => $this->getRecord()->beneficiary,
'record' => $this->getRecord(),
'tab' => \sprintf('-%s-tab', $this->getTabSlug()),
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Concerns/RedirectToPersonalInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait RedirectToPersonalInformation
protected function getRedirectUrl(): string
{
return static::getResource()::getUrl('view_personal_information', [
'record' => $this->record->id,
'record' => $this->record,
'tab' => \sprintf('-%s-tab', $this->getTabSlug()),
]);
}
Expand Down
103 changes: 54 additions & 49 deletions app/Filament/Organizations/Resources/BeneficiaryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function table(Table $table): Table
->whereUserHasAccess()
)
->columns([
TextColumn::make('id')
TextColumn::make('organization_beneficiary_id')
->label(__('field.case_id'))
->sortable()
->searchable(true, fn (Builder $query, $search) => $query->where('beneficiaries.id', 'LIKE', '%' . $search . '%')),
Expand Down Expand Up @@ -161,59 +161,64 @@ public static function getRelations(): array
];
}

public static function getRecordRouteKeyName(): ?string
{
return 'ulid';
}

public static function getPages(): array
{
return [
'index' => Pages\ListBeneficiaries::route('/'),
'create' => Pages\CreateBeneficiary::route('/create/{parent?}'),
'view' => Pages\ViewBeneficiary::route('/{record}'),

'view_identity' => Pages\ViewBeneficiaryIdentity::route('/{record}/identity'),
'edit_identity' => Pages\EditBeneficiaryIdentity::route('/{record}/identity/edit'),
'edit_children' => Pages\EditChildrenIdentity::route('{record}/children/edit'),
'view_personal_information' => Pages\ViewBeneficiaryPersonalInformation::route('/{record}/personal'),
'edit_personal_information' => Pages\EditBeneficiaryPersonalInformation::route('/{record}/personal/edit'),
'edit_aggressor' => Pages\EditAggressor::route('/{record}/aggressor/edit'),
'edit_antecedents' => Pages\EditAntecedents::route('{record}/antecedents/edit'),
'edit_flow_presentation' => Pages\EditFlowPresentation::route('{record}/flowPresentation/edit'),

'view_initial_evaluation' => InitialEvaluation\ViewInitialEvaluation::route('/{record}/initialEvaluation'),
'create_initial_evaluation' => InitialEvaluation\CreateInitialEvaluation::route('/{record}/initialEvaluation/create'),
'edit_initial_evaluation_details' => InitialEvaluation\EditEvaluationDetails::route('/{record}/initialEvaluation/details/edit'),
'edit_initial_evaluation_violence' => InitialEvaluation\EditViolence::route('/{record}/initialEvaluation/violence/edit'),
'edit_initial_evaluation_risk_factors' => InitialEvaluation\EditRiskFactors::route('/{record}/initialEvaluation/riskFactors/edit'),
'edit_initial_evaluation_requested_services' => InitialEvaluation\EditRequestedServices::route('/{record}/initialEvaluation/requestedServices/edit'),
'edit_initial_evaluation_beneficiary_situation' => InitialEvaluation\EditBeneficiarySituation::route('/{record}/initialEvaluation/beneficiarySituation/edit'),

'view_detailed_evaluation' => DetailedEvaluation\ViewDetailedEvaluation::route('/{record}/detailedEvaluation'),
'create_detailed_evaluation' => DetailedEvaluation\CreateDetailedEvaluation::route('/{record}/detailedEvaluation/create'),
'edit_detailed_evaluation' => DetailedEvaluation\EditDetailedEvaluation::route('/{record}/detailedEvaluation/edit'),
'edit_beneficiary_partner' => DetailedEvaluation\EditBeneficiaryPartner::route('/{record}/beneficiaryPartner/edit'),
'edit_multidisciplinary_evaluation' => DetailedEvaluation\EditMultidisciplinaryEvaluation::route('/{record}/multidisciplinaryEvaluation/edit'),
'edit_detailed_evaluation_result' => DetailedEvaluation\EditDetailedEvaluationResult::route('/{record}/detailedEvaluationResult/edit'),

'view_specialists' => ListSpecialists::route('/{record}/specialists'),

'documents.index' => ListDocuments::route('/{parent}/documents'),
'documents.view' => ViewDocument::route('/{parent}/documents/{record}'),

'monitorings.create' => MonitoringResourcePages\CreateMonitoring::route('/{parent}/monitoring/create/{copyLastFile?}'),
'monitorings.index' => MonitoringResourcePages\ListMonitoring::route('/{parent}/monitoring'),
'monitorings.view' => MonitoringResourcePages\ViewMonitoring::route('/{parent}/monitoring/{record}'),
'monitoring.edit_details' => MonitoringResourcePages\EditDetails::route('/{parent}/monitoring/{record}/editDetails'),
'monitoring.edit_children' => MonitoringResourcePages\EditChildren::route('/{parent}/monitoring/{record}/editChildren'),
'monitoring.edit_general' => MonitoringResourcePages\EditGeneral::route('/{parent}/monitoring/{record}/editGeneral'),

'beneficiary-histories.index' => ListBeneficiaryHistories::route('{parent}/history'),
'beneficiary-histories.view' => ViewBeneficiaryHistories::route('{parent}/history/{record}'),

'create_close_file' => CloseFile\CreateCloseFile::route('/{record}/createCloseFile'),
'view_close_file' => CloseFile\ViewCloseFile::route('/{record}/closeFile'),
'edit_close_file_details' => CloseFile\EditCloseFileDetails::route('{record}/closeFile/editDetails'),
'edit_close_file_general_details' => CloseFile\EditCloseFileGeneralDetails::route('{record}/closeFile/editGeneralDetails'),

'create_intervention_plan' => CreateInterventionPlan::route('/{parent}/createInterventionPlan'),
'view_intervention_plan' => ViewInterventionPlan::route('/{parent}/interventionPlan/{record}'),
'view' => Pages\ViewBeneficiary::route('/{record:ulid}'),

'view_identity' => Pages\ViewBeneficiaryIdentity::route('/{record:ulid}/identity'),
'edit_identity' => Pages\EditBeneficiaryIdentity::route('/{record:ulid}/identity/edit'),
'edit_children' => Pages\EditChildrenIdentity::route('{record:ulid}/children/edit'),
'view_personal_information' => Pages\ViewBeneficiaryPersonalInformation::route('/{record:ulid}/personal'),
'edit_personal_information' => Pages\EditBeneficiaryPersonalInformation::route('/{record:ulid}/personal/edit'),
'edit_aggressor' => Pages\EditAggressor::route('/{record:ulid}/aggressor/edit'),
'edit_antecedents' => Pages\EditAntecedents::route('{record:ulid}/antecedents/edit'),
'edit_flow_presentation' => Pages\EditFlowPresentation::route('{record:ulid}/flowPresentation/edit'),

'view_initial_evaluation' => InitialEvaluation\ViewInitialEvaluation::route('/{record:ulid}/initialEvaluation'),
'create_initial_evaluation' => InitialEvaluation\CreateInitialEvaluation::route('/{record:ulid}/initialEvaluation/create'),
'edit_initial_evaluation_details' => InitialEvaluation\EditEvaluationDetails::route('/{record:ulid}/initialEvaluation/details/edit'),
'edit_initial_evaluation_violence' => InitialEvaluation\EditViolence::route('/{record:ulid}/initialEvaluation/violence/edit'),
'edit_initial_evaluation_risk_factors' => InitialEvaluation\EditRiskFactors::route('/{record:ulid}/initialEvaluation/riskFactors/edit'),
'edit_initial_evaluation_requested_services' => InitialEvaluation\EditRequestedServices::route('/{record:ulid}/initialEvaluation/requestedServices/edit'),
'edit_initial_evaluation_beneficiary_situation' => InitialEvaluation\EditBeneficiarySituation::route('/{record:ulid}/initialEvaluation/beneficiarySituation/edit'),

'view_detailed_evaluation' => DetailedEvaluation\ViewDetailedEvaluation::route('/{record:ulid}/detailedEvaluation'),
'create_detailed_evaluation' => DetailedEvaluation\CreateDetailedEvaluation::route('/{record:ulid}/detailedEvaluation/create'),
'edit_detailed_evaluation' => DetailedEvaluation\EditDetailedEvaluation::route('/{record:ulid}/detailedEvaluation/edit'),
'edit_beneficiary_partner' => DetailedEvaluation\EditBeneficiaryPartner::route('/{record:ulid}/beneficiaryPartner/edit'),
'edit_multidisciplinary_evaluation' => DetailedEvaluation\EditMultidisciplinaryEvaluation::route('/{record:ulid}/multidisciplinaryEvaluation/edit'),
'edit_detailed_evaluation_result' => DetailedEvaluation\EditDetailedEvaluationResult::route('/{record:ulid}/detailedEvaluationResult/edit'),

'view_specialists' => ListSpecialists::route('/{record:ulid}/specialists'),

'documents.index' => ListDocuments::route('/{parent:ulid}/documents'),
'documents.view' => ViewDocument::route('/{parent:ulid}/documents/{record}'),

'monitorings.create' => MonitoringResourcePages\CreateMonitoring::route('/{parent:ulid}/monitoring/create/{copyLastFile?}'),
'monitorings.index' => MonitoringResourcePages\ListMonitoring::route('/{parent:ulid}/monitoring'),
'monitorings.view' => MonitoringResourcePages\ViewMonitoring::route('/{parent:ulid}/monitoring/{record}'),
'monitoring.edit_details' => MonitoringResourcePages\EditDetails::route('/{parent:ulid}/monitoring/{record}/editDetails'),
'monitoring.edit_children' => MonitoringResourcePages\EditChildren::route('/{parent:ulid}/monitoring/{record}/editChildren'),
'monitoring.edit_general' => MonitoringResourcePages\EditGeneral::route('/{parent:ulid}/monitoring/{record}/editGeneral'),

'beneficiary-histories.index' => ListBeneficiaryHistories::route('{parent:ulid}/history'),
'beneficiary-histories.view' => ViewBeneficiaryHistories::route('{parent:ulid}/history/{record}'),

'create_close_file' => CloseFile\CreateCloseFile::route('/{record:ulid}/createCloseFile'),
'view_close_file' => CloseFile\ViewCloseFile::route('/{record:ulid}/closeFile'),
'edit_close_file_details' => CloseFile\EditCloseFileDetails::route('{record:ulid}/closeFile/editDetails'),
'edit_close_file_general_details' => CloseFile\EditCloseFileGeneralDetails::route('{record:ulid}/closeFile/editGeneralDetails'),

'create_intervention_plan' => CreateInterventionPlan::route('/{parent:ulid}/createInterventionPlan'),
'view_intervention_plan' => ViewInterventionPlan::route('/{parent:ulid}/interventionPlan/{record}'),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function getTitle(): string|Htmlable
{
return __('beneficiary.page.edit_personal_information.title', [
'name' => $this->record->full_name,
'id' => $this->record->id,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getTitle(): string|Htmlable

return new HtmlString(__('beneficiary.page.view.title', [
'name' => $this->record->full_name,
'id' => $this->record->id,
'id' => $this->record->organization_beneficiary_id,
'badge' => $statusBadge,
]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getBreadcrumbs(): array
{
return [
self::$resource::getUrl() => self::$resource::getBreadcrumb(),
self::$resource::getUrl('view', ['record' => $this->record->id]) => $this->record->getFilamentName(),
self::$resource::getUrl('view', ['record' => $this->record]) => $this->record->getFilamentName(),
];
}

Expand All @@ -27,6 +27,6 @@ public function getTitle(): string|Htmlable

protected function getRedirectUrl(): string
{
return self::$resource::getUrl('view', ['record' => $this->record->id]);
return self::$resource::getUrl('view', ['record' => $this->record]);
}
}
14 changes: 13 additions & 1 deletion app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Beneficiary extends Model

protected $fillable = [
'initial_id',
'organization_beneficiary_id',
'first_name',
'last_name',
'prior_name',
Expand Down Expand Up @@ -93,6 +94,17 @@ class Beneficiary extends Model
'status' => CaseStatus::class,
];

protected static function boot()
{
parent::boot();

static::creating(function (self $beneficiary) {
$beneficiary->organization_beneficiary_id = 1 + (int) Beneficiary::query()
->where('organization_id', $beneficiary->organization_id)
->max('organization_beneficiary_id');
});
}

public function scopeWhereUserHasAccess(Builder $query): Builder
{
$user = auth()->user();
Expand All @@ -107,7 +119,7 @@ public function scopeWhereUserHasAccess(Builder $query): Builder

public function getBreadcrumb(): string
{
return \sprintf('#%d %s', $this->id, $this->full_name);
return \sprintf('#%d %s', $this->organization_beneficiary_id, $this->full_name);
}

public function children(): HasMany
Expand Down
6 changes: 3 additions & 3 deletions app/Services/Breadcrumb/BeneficiaryBreadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getBaseBreadcrumbs(): array
{
return array_merge(
[self::$resourcePath::getUrl() => self::$resourcePath::getBreadcrumb()],
[self::$resourcePath::getUrl('view', ['record' => $this->record->id]) => $this->record->getBreadcrumb()],
[self::$resourcePath::getUrl('view', ['record' => $this->record]) => $this->record->getBreadcrumb()],
);
}

Expand All @@ -48,9 +48,9 @@ public function getBreadcrumbs(string $page): array
};

$params = match ($page) {
'documents.index', 'monitorings.index', 'beneficiary-histories.index' => ['parent' => $this->record->id],
'documents.index', 'monitorings.index', 'beneficiary-histories.index' => ['parent' => $this->record],

default => ['record' => $this->record->id],
default => ['record' => $this->record],
};

return array_merge(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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('beneficiaries', function (Blueprint $table) {
$table->bigInteger('organization_beneficiary_id')->nullable()->unsigned();
});
}

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

declare(strict_types=1);

use App\Models\Beneficiary;
use App\Models\Organization;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Organization::all()->each(function (Organization $organization) {
$beneficiaryID = 1;
$organization->beneficiaries()
->orderBy('id')
->with(['legal_residence', 'effective_residence'])
->get()
->each(
function (Beneficiary $beneficiary) {
static $beneficiaryID = 1;
$beneficiary->update(['organization_beneficiary_id' => $beneficiaryID++]);
}
);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};
Loading