Skip to content

Commit fe7a3ff

Browse files
authored
Merge pull request #6576 from NHSDigital/gillick-assessment-valid-on-day
Only consider today’s Gillick assessments as valid
2 parents cbf6672 + e935ac1 commit fe7a3ff

4 files changed

Lines changed: 186 additions & 57 deletions

File tree

app/controllers/draft_consents_controller.rb

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class DraftConsentsController < ApplicationController
1212

1313
include WizardControllerConcern
1414

15-
before_action :set_triage_form, if: :includes_triage_step?
16-
before_action :set_parent_options, if: -> { current_step == :who }
1715
before_action :set_back_link_path
16+
before_action :set_new_or_existing_contact_options, if: :is_who_step?
17+
before_action :set_triage_form, if: :includes_triage_step?
1818

1919
def show
2020
authorize Consent, :edit?
@@ -213,6 +213,58 @@ def set_steps
213213
self.steps = @draft_consent.wizard_steps
214214
end
215215

216+
def set_back_link_path
217+
@back_link_path =
218+
if @draft_consent.editing?
219+
wizard_path("confirm")
220+
elsif current_step == @draft_consent.wizard_steps.first
221+
session_patient_programme_path(@session, @patient, @programme)
222+
else
223+
previous_wizard_path
224+
end
225+
end
226+
227+
def is_who_step? = current_step == :who
228+
229+
NewOrExistingContactOption = Struct.new(:value, :label, :hint)
230+
231+
def set_new_or_existing_contact_options
232+
@new_or_existing_contact_options = []
233+
234+
if @patient.can_self_consent_after_gillick_assessment?(
235+
location: @session.location,
236+
programme_type: @programme.type
237+
)
238+
@new_or_existing_contact_options << NewOrExistingContactOption.new(
239+
value: "patient",
240+
label: "Child (Gillick competent)"
241+
)
242+
end
243+
244+
parent_relationships =
245+
(
246+
@patient.parent_relationships.includes(:parent) +
247+
@patient
248+
.consents
249+
.where(programme_type: @programme.type)
250+
.filter_map(&:parent_relationship)
251+
).compact.uniq.sort_by(&:label)
252+
253+
@new_or_existing_contact_options +=
254+
parent_relationships.map do |parent_relationship|
255+
NewOrExistingContactOption.new(
256+
value: parent_relationship.parent.id,
257+
label: parent_relationship.label_with_parent,
258+
hint: parent_relationship.parent.contact_label
259+
)
260+
end
261+
262+
@new_or_existing_contact_options << NewOrExistingContactOption.new(
263+
value: "new",
264+
label: "Add a new parental contact"
265+
)
266+
end
267+
216268
def includes_triage_step?
217269
current_step.in?(%i[triage confirm]) && steps.include?("triage")
218270
end
@@ -235,28 +287,6 @@ def set_triage_form
235287
end
236288
end
237289

238-
def set_parent_options
239-
@parent_options =
240-
(
241-
@patient.parent_relationships.includes(:parent) +
242-
@patient
243-
.consents
244-
.select { it.programme_type == @programme.type }
245-
.filter_map(&:parent_relationship)
246-
).compact.uniq.sort_by(&:label)
247-
end
248-
249-
def set_back_link_path
250-
@back_link_path =
251-
if @draft_consent.editing?
252-
wizard_path("confirm")
253-
elsif current_step == @draft_consent.wizard_steps.first
254-
session_patient_programme_path(@session, @patient, @programme)
255-
else
256-
previous_wizard_path
257-
end
258-
end
259-
260290
# Returns:
261291
# {
262292
# question_0: %i[notes response],

app/models/patient.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ def show_year_group?(team:)
547547
end
548548
end
549549

550+
def can_self_consent_after_gillick_assessment?(location:, programme_type:)
551+
gillick_assessments
552+
.where(location:, programme_type:, date: Date.current)
553+
.order(created_at: :desc)
554+
&.first
555+
&.gillick_competent? || false
556+
end
557+
550558
def programme_status(programme, academic_year:)
551559
# TODO: Update this method to accept the `programme_type` so that we can
552560
# then determine the right programme variant from the `disease_types` on

app/views/draft_consents/who.html.erb

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,19 @@
22
<%= govuk_back_link(href: @back_link_path) %>
33
<% end %>
44

5-
<% page_title = "Who are you trying to get consent from?" %>
6-
7-
<%= h1 page_title: do %>
8-
<span class="nhsuk-caption-l">
9-
<%= @patient.full_name %>
10-
</span>
11-
<%= page_title %>
12-
<% end %>
13-
14-
<% gillick_competent = @patient.gillick_assessments.order(created_at: :desc).for_session(@session).for_programme(@programme)&.first&.gillick_competent? %>
5+
<% legend = "Who are you trying to get consent from?" %>
6+
<% content_for :page_title, legend %>
157

168
<%= form_with model: @draft_consent, url: wizard_path, method: :put do |f| %>
179
<%= f.mavis_error_summary %>
1810

19-
<%= f.govuk_radio_buttons_fieldset(:new_or_existing_contact, legend: nil) do %>
20-
<% if gillick_competent %>
21-
<%= f.govuk_radio_button :new_or_existing_contact, "patient",
22-
label: { text: "Child (Gillick competent)" },
23-
link_errors: true %>
24-
<% end %>
25-
26-
<% if @parent_options.present? %>
27-
<% @parent_options.each.with_index do |parent_relationship, i| %>
28-
<% parent = parent_relationship.parent %>
29-
<%= f.govuk_radio_button :new_or_existing_contact, parent.id,
30-
label: { text: parent_relationship.label_with_parent },
31-
hint: { text: parent.contact_label },
32-
link_errors: !gillick_competent && i == 0 %>
33-
<% end %>
34-
35-
<%= f.govuk_radio_divider %>
36-
<% end %>
37-
38-
<%= f.govuk_radio_button :new_or_existing_contact, "new",
39-
label: { text: "Add a new parental contact" },
40-
link_errors: !gillick_competent && @parent_options.empty? %>
41-
<% end %>
11+
<%= f.govuk_collection_radio_buttons :new_or_existing_contact,
12+
@new_or_existing_contact_options,
13+
:value,
14+
:label,
15+
:hint,
16+
legend: { text: legend, tag: "h1", size: "l" },
17+
caption: { text: @patient.full_name, size: "l" } %>
4218

4319
<%= f.govuk_submit "Continue" %>
4420
<% end %>

spec/models/patient_spec.rb

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,121 @@
908908
it { should eq("JD") }
909909
end
910910

911+
describe "#can_self_consent_after_gillick_assessment?" do
912+
subject(:can_self_consent_after_gillick_assessment) do
913+
patient.can_self_consent_after_gillick_assessment?(
914+
location: session.location,
915+
programme_type: programme.type
916+
)
917+
end
918+
919+
let(:programme) { Programme.sample }
920+
let(:session) { create(:session, programmes: [programme]) }
921+
let(:patient) { create(:patient) }
922+
923+
context "when patient has no Gillick assessments" do
924+
it { should be(false) }
925+
end
926+
927+
context "when patient has a Gillick assessment for a different programme" do
928+
before do
929+
create(
930+
:gillick_assessment,
931+
:competent,
932+
patient:,
933+
programme_type: "hpv",
934+
session:
935+
)
936+
end
937+
938+
let(:programme) { Programme.flu }
939+
940+
it { should be(false) }
941+
end
942+
943+
context "when patient has a Gillick assessment for a different session" do
944+
let(:other_session) { create(:session, programmes: [programme]) }
945+
946+
before do
947+
create(
948+
:gillick_assessment,
949+
:competent,
950+
patient:,
951+
programme_type: programme.type,
952+
session: other_session
953+
)
954+
end
955+
956+
it { should be(false) }
957+
end
958+
959+
context "when patient has a Gillick assessment on a different date" do
960+
before do
961+
create(
962+
:gillick_assessment,
963+
:competent,
964+
patient:,
965+
programme_type: programme.type,
966+
session:,
967+
date: Date.yesterday
968+
)
969+
end
970+
971+
it { should be(false) }
972+
end
973+
974+
context "when patient has a not competent Gillick assessment" do
975+
before do
976+
create(
977+
:gillick_assessment,
978+
:not_competent,
979+
patient:,
980+
programme_type: programme.type,
981+
session:
982+
)
983+
end
984+
985+
it { should be(false) }
986+
end
987+
988+
context "when patient has a competent Gillick assessment" do
989+
before do
990+
create(
991+
:gillick_assessment,
992+
:competent,
993+
patient:,
994+
programme_type: programme.type,
995+
session:
996+
)
997+
end
998+
999+
it { should be(true) }
1000+
end
1001+
1002+
context "when patient has multiple Gillick assessments" do
1003+
before do
1004+
create(
1005+
:gillick_assessment,
1006+
:not_competent,
1007+
patient:,
1008+
programme_type: programme.type,
1009+
session:
1010+
)
1011+
create(
1012+
:gillick_assessment,
1013+
:competent,
1014+
patient:,
1015+
programme_type: programme.type,
1016+
session:
1017+
)
1018+
end
1019+
1020+
it "returns the result of the most recent assessment" do
1021+
expect(can_self_consent_after_gillick_assessment).to be(true)
1022+
end
1023+
end
1024+
end
1025+
9111026
describe "#has_patient_specific_direction?" do
9121027
subject { patient.has_patient_specific_direction?(team:) }
9131028

0 commit comments

Comments
 (0)