From d14e38fde34372031e9c4d8fdd1cb138b0bbb367 Mon Sep 17 00:00:00 2001 From: Alex Popa Date: Mon, 16 Dec 2024 14:01:20 +0200 Subject: [PATCH] Change beneficiary id from url with ulid and display organization beneficary id --- app/Concerns/RedirectToDetailedEvaluation.php | 2 +- app/Concerns/RedirectToIdentity.php | 2 +- app/Concerns/RedirectToInitialEvaluation.php | 2 +- app/Concerns/RedirectToMonitoring.php | 2 +- .../RedirectToPersonalInformation.php | 2 +- .../Resources/BeneficiaryResource.php | 103 +++++++++--------- .../EditBeneficiaryPersonalInformation.php | 1 - .../Pages/ViewBeneficiary.php | 2 +- .../Resources/UserResource/Pages/EditUser.php | 4 +- app/Models/Beneficiary.php | 14 ++- .../Breadcrumb/BeneficiaryBreadcrumb.php | 6 +- ...beneficiary_id_column_in_beneficiaries.php | 30 +++++ ...initialize_organization_beneficiary_id.php | 38 +++++++ 13 files changed, 146 insertions(+), 62 deletions(-) create mode 100644 database/migrations/2024_12_16_095535_add_organization_beneficiary_id_column_in_beneficiaries.php create mode 100644 database/migrations/2024_12_16_100215_initialize_organization_beneficiary_id.php diff --git a/app/Concerns/RedirectToDetailedEvaluation.php b/app/Concerns/RedirectToDetailedEvaluation.php index e9168bd9..2cd7fe9d 100644 --- a/app/Concerns/RedirectToDetailedEvaluation.php +++ b/app/Concerns/RedirectToDetailedEvaluation.php @@ -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()), ]); } diff --git a/app/Concerns/RedirectToIdentity.php b/app/Concerns/RedirectToIdentity.php index 2660916e..d734669f 100644 --- a/app/Concerns/RedirectToIdentity.php +++ b/app/Concerns/RedirectToIdentity.php @@ -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()), ]); } diff --git a/app/Concerns/RedirectToInitialEvaluation.php b/app/Concerns/RedirectToInitialEvaluation.php index 39da1321..123c1dad 100644 --- a/app/Concerns/RedirectToInitialEvaluation.php +++ b/app/Concerns/RedirectToInitialEvaluation.php @@ -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()), ]); } diff --git a/app/Concerns/RedirectToMonitoring.php b/app/Concerns/RedirectToMonitoring.php index fd98fa28..a6d5d448 100644 --- a/app/Concerns/RedirectToMonitoring.php +++ b/app/Concerns/RedirectToMonitoring.php @@ -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()), ]); diff --git a/app/Concerns/RedirectToPersonalInformation.php b/app/Concerns/RedirectToPersonalInformation.php index c03f3676..2f08edb8 100644 --- a/app/Concerns/RedirectToPersonalInformation.php +++ b/app/Concerns/RedirectToPersonalInformation.php @@ -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()), ]); } diff --git a/app/Filament/Organizations/Resources/BeneficiaryResource.php b/app/Filament/Organizations/Resources/BeneficiaryResource.php index c0659fbb..44ffb1a7 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryResource.php +++ b/app/Filament/Organizations/Resources/BeneficiaryResource.php @@ -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 . '%')), @@ -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}'), ]; } } diff --git a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/EditBeneficiaryPersonalInformation.php b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/EditBeneficiaryPersonalInformation.php index 98282954..912e9891 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/EditBeneficiaryPersonalInformation.php +++ b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/EditBeneficiaryPersonalInformation.php @@ -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, ]); } diff --git a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php index c604fe0b..cab340cb 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php +++ b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php @@ -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, ])); } diff --git a/app/Filament/Organizations/Resources/UserResource/Pages/EditUser.php b/app/Filament/Organizations/Resources/UserResource/Pages/EditUser.php index fcf433ce..daed309e 100644 --- a/app/Filament/Organizations/Resources/UserResource/Pages/EditUser.php +++ b/app/Filament/Organizations/Resources/UserResource/Pages/EditUser.php @@ -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(), ]; } @@ -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]); } } diff --git a/app/Models/Beneficiary.php b/app/Models/Beneficiary.php index fdba5122..d918b5e2 100644 --- a/app/Models/Beneficiary.php +++ b/app/Models/Beneficiary.php @@ -41,6 +41,7 @@ class Beneficiary extends Model protected $fillable = [ 'initial_id', + 'organization_beneficiary_id', 'first_name', 'last_name', 'prior_name', @@ -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(); @@ -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 diff --git a/app/Services/Breadcrumb/BeneficiaryBreadcrumb.php b/app/Services/Breadcrumb/BeneficiaryBreadcrumb.php index 3cff0d55..48ef4228 100644 --- a/app/Services/Breadcrumb/BeneficiaryBreadcrumb.php +++ b/app/Services/Breadcrumb/BeneficiaryBreadcrumb.php @@ -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()], ); } @@ -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( diff --git a/database/migrations/2024_12_16_095535_add_organization_beneficiary_id_column_in_beneficiaries.php b/database/migrations/2024_12_16_095535_add_organization_beneficiary_id_column_in_beneficiaries.php new file mode 100644 index 00000000..3a57c3a9 --- /dev/null +++ b/database/migrations/2024_12_16_095535_add_organization_beneficiary_id_column_in_beneficiaries.php @@ -0,0 +1,30 @@ +bigInteger('organization_beneficiary_id')->nullable()->unsigned(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('beneficiaries', function (Blueprint $table) { + // + }); + } +}; diff --git a/database/migrations/2024_12_16_100215_initialize_organization_beneficiary_id.php b/database/migrations/2024_12_16_100215_initialize_organization_beneficiary_id.php new file mode 100644 index 00000000..a1c5f0b4 --- /dev/null +++ b/database/migrations/2024_12_16_100215_initialize_organization_beneficiary_id.php @@ -0,0 +1,38 @@ +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 + { + // + } +};