File tree Expand file tree Collapse file tree 5 files changed +65
-1
lines changed Expand file tree Collapse file tree 5 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,8 @@ def selected_cis2_workgroup_is_valid?
50
50
51
51
def selected_cis2_role_is_valid?
52
52
cis2_info . is_admin? || cis2_info . is_nurse? ||
53
- cis2_info . is_healthcare_assistant? || cis2_info . is_superuser?
53
+ cis2_info . is_healthcare_assistant? || cis2_info . is_superuser? ||
54
+ cis2_info . is_prescriber?
54
55
end
55
56
56
57
def storable_location?
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class CIS2Info
8
8
9
9
SUPERUSER_WORKGROUP = "mavissuperusers"
10
10
11
+ INDEPENDENT_PRESCRIBING_ACTIVITY_CODE = "B0420"
11
12
PERSONAL_MEDICATION_ADMINISTRATION_ACTIVITY_CODE = "B0428"
12
13
13
14
attribute :organisation_name
@@ -50,6 +51,10 @@ def is_healthcare_assistant?
50
51
activity_codes . include? ( PERSONAL_MEDICATION_ADMINISTRATION_ACTIVITY_CODE )
51
52
end
52
53
54
+ def is_prescriber?
55
+ activity_codes . include? ( INDEPENDENT_PRESCRIBING_ACTIVITY_CODE )
56
+ end
57
+
53
58
def is_superuser?
54
59
workgroups . include? ( SUPERUSER_WORKGROUP )
55
60
end
Original file line number Diff line number Diff line change @@ -126,6 +126,8 @@ def role_description
126
126
role =
127
127
if is_healthcare_assistant?
128
128
"Healthcare Assistant"
129
+ elsif is_prescriber?
130
+ "Prescriber"
129
131
elsif is_nurse?
130
132
"Nurse"
131
133
else
@@ -151,6 +153,10 @@ def is_healthcare_assistant?
151
153
end
152
154
end
153
155
156
+ def is_prescriber?
157
+ cis2_enabled? ? cis2_info . is_prescriber? : fallback_role_prescriber?
158
+ end
159
+
154
160
def is_superuser?
155
161
cis2_enabled? ? cis2_info . is_superuser? : fallback_role_superuser?
156
162
end
Original file line number Diff line number Diff line change 100
100
fallback_role { :healthcare_assistant }
101
101
end
102
102
103
+ trait :prescriber do
104
+ sequence ( :email ) { |n | "prescriber-#{ n } @example.com" }
105
+ role_code { nil }
106
+ activity_codes { [ CIS2Info ::INDEPENDENT_PRESCRIBING_ACTIVITY_CODE ] }
107
+ fallback_role { :prescriber }
108
+ end
109
+
103
110
trait :signed_in do
104
111
current_sign_in_at { Time . current }
105
112
current_sign_in_ip { "127.0.0.1" }
108
115
109
116
factory :admin , parent : :user , traits : %i[ admin ]
110
117
factory :healthcare_assistant , parent : :user , traits : %i[ healthcare_assistant ]
118
+ factory :prescriber , parent : :user , traits : %i[ prescriber ]
111
119
factory :superuser , parent : :user , traits : %i[ superuser ]
112
120
end
Original file line number Diff line number Diff line change 196
196
end
197
197
end
198
198
199
+ describe "#is_prescriber?" do
200
+ subject { user . is_prescriber? }
201
+
202
+ context "cis2 is enabled" , cis2 : :enabled do
203
+ context "when the user is a nurse" do
204
+ let ( :user ) { build ( :nurse ) }
205
+
206
+ it { should be ( true ) }
207
+ end
208
+
209
+ context "when the user is admin staff" do
210
+ let ( :user ) { build ( :admin ) }
211
+
212
+ it { should be ( false ) }
213
+ end
214
+
215
+ context "when the user is a prescriber" do
216
+ let ( :user ) { build ( :prescriber ) }
217
+
218
+ it { should be ( true ) }
219
+ end
220
+ end
221
+
222
+ context "cis2 is disabled" , cis2 : :disabled do
223
+ context "when the user is a nurse" do
224
+ let ( :user ) { build ( :nurse ) }
225
+
226
+ it { should be ( true ) }
227
+ end
228
+
229
+ context "when the user is admin staff" do
230
+ let ( :user ) { build ( :admin ) }
231
+
232
+ it { should be ( false ) }
233
+ end
234
+
235
+ context "when the user is a prescriber" do
236
+ let ( :user ) { build ( :prescriber ) }
237
+
238
+ it { should be ( true ) }
239
+ end
240
+ end
241
+ end
242
+
199
243
describe "#is_superuser?" do
200
244
subject { user . is_superuser? }
201
245
You can’t perform that action at this time.
0 commit comments