diff --git a/app/controllers/concerns/authentication_concern.rb b/app/controllers/concerns/authentication_concern.rb index ffff28bc18..9e67bb530c 100644 --- a/app/controllers/concerns/authentication_concern.rb +++ b/app/controllers/concerns/authentication_concern.rb @@ -50,7 +50,8 @@ def selected_cis2_workgroup_is_valid? def selected_cis2_role_is_valid? cis2_info.is_admin? || cis2_info.is_nurse? || - cis2_info.is_healthcare_assistant? || cis2_info.is_superuser? + cis2_info.is_healthcare_assistant? || cis2_info.is_superuser? || + cis2_info.is_prescriber? end def storable_location? diff --git a/app/models/cis2_info.rb b/app/models/cis2_info.rb index 4d6e620c0c..c3052ba68e 100644 --- a/app/models/cis2_info.rb +++ b/app/models/cis2_info.rb @@ -8,6 +8,7 @@ class CIS2Info SUPERUSER_WORKGROUP = "mavissuperusers" + INDEPENDENT_PRESCRIBING_ACTIVITY_CODE = "B0420" PERSONAL_MEDICATION_ADMINISTRATION_ACTIVITY_CODE = "B0428" attribute :organisation_name @@ -50,6 +51,10 @@ def is_healthcare_assistant? activity_codes.include?(PERSONAL_MEDICATION_ADMINISTRATION_ACTIVITY_CODE) end + def is_prescriber? + activity_codes.include?(INDEPENDENT_PRESCRIBING_ACTIVITY_CODE) + end + def is_superuser? workgroups.include?(SUPERUSER_WORKGROUP) end diff --git a/app/models/user.rb b/app/models/user.rb index 75dad8c76e..ce86d95667 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -126,6 +126,8 @@ def role_description role = if is_healthcare_assistant? "Healthcare Assistant" + elsif is_prescriber? + "Prescriber" elsif is_nurse? "Nurse" else @@ -151,6 +153,10 @@ def is_healthcare_assistant? end end + def is_prescriber? + cis2_enabled? ? cis2_info.is_prescriber? : fallback_role_prescriber? + end + def is_superuser? cis2_enabled? ? cis2_info.is_superuser? : fallback_role_superuser? end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 07f7b46942..dc57218e5c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -100,6 +100,13 @@ fallback_role { :healthcare_assistant } end + trait :prescriber do + sequence(:email) { |n| "prescriber-#{n}@example.com" } + role_code { nil } + activity_codes { [CIS2Info::INDEPENDENT_PRESCRIBING_ACTIVITY_CODE] } + fallback_role { :prescriber } + end + trait :signed_in do current_sign_in_at { Time.current } current_sign_in_ip { "127.0.0.1" } @@ -108,5 +115,6 @@ factory :admin, parent: :user, traits: %i[admin] factory :healthcare_assistant, parent: :user, traits: %i[healthcare_assistant] + factory :prescriber, parent: :user, traits: %i[prescriber] factory :superuser, parent: :user, traits: %i[superuser] end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ecf02f3694..9ecfe871a3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -196,6 +196,50 @@ end end + describe "#is_prescriber?" do + subject { user.is_prescriber? } + + context "cis2 is enabled", cis2: :enabled do + context "when the user is a nurse" do + let(:user) { build(:nurse) } + + it { should be(false) } + end + + context "when the user is admin staff" do + let(:user) { build(:admin) } + + it { should be(false) } + end + + context "when the user is a prescriber" do + let(:user) { build(:prescriber) } + + it { should be(true) } + end + end + + context "cis2 is disabled", cis2: :disabled do + context "when the user is a nurse" do + let(:user) { build(:nurse) } + + it { should be(false) } + end + + context "when the user is admin staff" do + let(:user) { build(:admin) } + + it { should be(false) } + end + + context "when the user is a prescriber" do + let(:user) { build(:prescriber) } + + it { should be(true) } + end + end + end + describe "#is_superuser?" do subject { user.is_superuser? }