Skip to content

Commit

Permalink
Add FullNameConcern
Browse files Browse the repository at this point in the history
This is a concern which handles the displaying of a full name combined
from a given name and a family name.
  • Loading branch information
thomasleese committed Oct 15, 2024
1 parent bdf2276 commit 1394580
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
8 changes: 1 addition & 7 deletions app/controllers/cohorts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ def index
def show
@cohort = policy_scope(Cohort).find(params[:id])
@pagy, @patients =
pagy(
@cohort
.patients
.recorded
.includes(:school)
.order(:given_name, :family_name)
)
pagy(@cohort.patients.recorded.includes(:school).order_by_name)
end

private
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/concerns/full_name_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module FullNameConcern
extend ActiveSupport::Concern

included { scope :order_by_name, -> { order(:given_name, :family_name) } }

def full_name
"#{given_name} #{family_name}"
end
end
5 changes: 1 addition & 4 deletions app/models/consent_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
class ConsentForm < ApplicationRecord
include AddressConcern
include AgeConcern
include FullNameConcern
include WizardStepConcern

before_save :reset_unused_fields
Expand Down Expand Up @@ -240,10 +241,6 @@ class ConsentForm < ApplicationRecord

delegate :vaccines, to: :programme

def full_name
[given_name, family_name].join(" ")
end

def wizard_steps
[
:name,
Expand Down
5 changes: 1 addition & 4 deletions app/models/patient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
class Patient < ApplicationRecord
include AddressConcern
include AgeConcern
include FullNameConcern
include PendingChangesConcern
include Recordable

Expand Down Expand Up @@ -128,10 +129,6 @@ def relationship_to(parent:)
parent_relationships.find { _1.parent == parent }
end

def full_name
"#{given_name} #{family_name}"
end

def year_group
cohort&.year_group || date_of_birth.year_group
end
Expand Down
6 changes: 2 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
# index_users_on_provider_and_uid (provider,uid) UNIQUE
#
class User < ApplicationRecord
include FullNameConcern

devise :database_authenticatable,
:trackable,
:timeoutable,
Expand Down Expand Up @@ -60,10 +62,6 @@ class User < ApplicationRecord
scope :recently_active,
-> { where(last_sign_in_at: 1.week.ago..Time.current) }

def full_name
[given_name, family_name].join(" ")
end

def team
# TODO: Update the app to properly support multiple teams per user
teams.first
Expand Down

0 comments on commit 1394580

Please sign in to comment.