File tree Expand file tree Collapse file tree 5 files changed +70
-2
lines changed Expand file tree Collapse file tree 5 files changed +70
-2
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 . can_view? || cis2_info . can_supply_using_pgd? ||
53
- cis2_info . can_perform_local_admin_tasks? ||
53
+ cis2_info . can_prescribe?
54
+ cis2_info . can_perform_local_admin_tasks? ||
54
55
cis2_info . can_access_sensitive_records?
55
56
end
56
57
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ class CIS2Info
8
8
9
9
SUPERUSER_WORKGROUP = "mavissuperusers"
10
10
11
+ INDEPENDENT_PRESCRIBING_ACTIVITY_CODE = "B0420"
12
+
11
13
attribute :organisation_name
12
14
attribute :organisation_code
13
15
attribute :role_name
@@ -44,6 +46,11 @@ def can_supply_using_pgd?
44
46
role_code == NURSE_ROLE
45
47
end
46
48
49
+ def can_prescribe?
50
+ role_code == NURSE_ROLE ||
51
+ activity_codes . include? ( INDEPENDENT_PRESCRIBING_ACTIVITY_CODE )
52
+ end
53
+
47
54
def can_perform_local_admin_tasks?
48
55
in_superuser_workgroup?
49
56
end
Original file line number Diff line number Diff line change @@ -139,6 +139,14 @@ def can_supply_using_pgd?
139
139
cis2_enabled? ? cis2_info . can_supply_using_pgd? : fallback_role_nurse?
140
140
end
141
141
142
+ def can_prescribe?
143
+ if cis2_enabled?
144
+ cis2_info . can_prescribe?
145
+ else
146
+ fallback_role_nurse? || fallback_role_prescriber?
147
+ end
148
+ end
149
+
142
150
def can_perform_local_admin_tasks?
143
151
if cis2_enabled?
144
152
cis2_info . can_perform_local_admin_tasks?
Original file line number Diff line number Diff line change 93
93
fallback_role { :healthcare_assistant }
94
94
end
95
95
96
+ trait :prescriber do
97
+ sequence ( :email ) { |n | "prescriber-#{ n } @example.com" }
98
+ role_code { nil }
99
+ activity_codes { [ CIS2Info ::INDEPENDENT_PRESCRIBING_ACTIVITY_CODE ] }
100
+ fallback_role { :prescriber }
101
+ end
102
+
96
103
trait :signed_in do
97
104
current_sign_in_at { Time . current }
98
105
current_sign_in_ip { "127.0.0.1" }
99
106
end
100
107
end
101
108
102
109
factory :admin , parent : :user , traits : %i[ admin ]
110
+ factory :prescriber , parent : :user , traits : %i[ prescriber ]
103
111
end
Original file line number Diff line number Diff line change 119
119
end
120
120
end
121
121
122
- describe "#can_supply_using_pgd?? " do
122
+ describe "#can_supply_using_pgd?" do
123
123
subject { user . can_supply_using_pgd? }
124
124
125
125
context "cis2 is enabled" , cis2 : :enabled do
151
151
end
152
152
end
153
153
154
+ describe "#can_prescribe?" do
155
+ subject { user . can_prescribe? }
156
+
157
+ context "cis2 is enabled" , cis2 : :enabled do
158
+ context "when the user is a nurse" do
159
+ let ( :user ) { build ( :nurse ) }
160
+
161
+ it { should be ( true ) }
162
+ end
163
+
164
+ context "when the user is admin staff" do
165
+ let ( :user ) { build ( :admin ) }
166
+
167
+ it { should be ( false ) }
168
+ end
169
+
170
+ context "when the user is a prescriber" do
171
+ let ( :user ) { build ( :prescriber ) }
172
+
173
+ it { should be ( true ) }
174
+ end
175
+ end
176
+
177
+ context "cis2 is disabled" , cis2 : :disabled do
178
+ context "when the user is a nurse" do
179
+ let ( :user ) { build ( :nurse ) }
180
+
181
+ it { should be ( true ) }
182
+ end
183
+
184
+ context "when the user is admin staff" do
185
+ let ( :user ) { build ( :admin ) }
186
+
187
+ it { should be ( false ) }
188
+ end
189
+
190
+ context "when the user is a prescriber" do
191
+ let ( :user ) { build ( :prescriber ) }
192
+
193
+ it { should be ( true ) }
194
+ end
195
+ end
196
+ end
197
+
154
198
describe "#can_perform_local_admin_tasks?" do
155
199
subject { user . can_perform_local_admin_tasks? }
156
200
You can’t perform that action at this time.
0 commit comments