Skip to content

Commit 41a9bc5

Browse files
committed
Refactor GillickAssessmentsController
Because we now don't really have the concept of editing a Gillick assessment (they're always created new) then we can reduce duplication and go down to one set of controller actions.
1 parent 87e4a7e commit 41a9bc5

File tree

8 files changed

+55
-90
lines changed

8 files changed

+55
-90
lines changed

app/components/app_patient_page_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<% elsif gillick_assessment_can_be_recorded? %>
5454
<p class="nhsuk-body">
5555
<%= govuk_button_link_to "Assess Gillick competence",
56-
new_session_patient_gillick_assessment_path(
56+
edit_session_patient_gillick_assessment_path(
5757
session,
5858
patient,
5959
section: @section,

app/controllers/gillick_assessments_controller.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@ class GillickAssessmentsController < ApplicationController
44
before_action :set_patient
55
before_action :set_session
66
before_action :set_patient_session
7+
before_action :set_is_first_assessment
78
before_action :set_gillick_assessment
89

9-
def new
10-
end
11-
12-
def create
13-
if @gillick_assessment.update(gillick_assessment_params)
14-
redirect_to session_patient_path(id: @patient.id)
15-
else
16-
render :new, status: :unprocessable_entity
17-
end
18-
end
19-
2010
def edit
2111
end
2212

@@ -45,6 +35,10 @@ def set_patient_session
4535
policy_scope(PatientSession).find_by(session: @session, patient: @patient)
4636
end
4737

38+
def set_is_first_assessment
39+
@is_first_assessment = @patient_session.gillick_assessments.empty?
40+
end
41+
4842
def set_gillick_assessment
4943
@gillick_assessment =
5044
authorize @patient_session.latest_gillick_assessment&.dup ||

app/controllers/patient_sessions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def set_patient_session
2424
policy_scope(PatientSession)
2525
.includes(:patient, :vaccination_records)
2626
.eager_load(:session)
27-
.preload(:consents, :triages)
27+
.preload(:consents, :gillick_assessments, :triages)
2828
.find_by!(
2929
session: {
3030
slug: params.fetch(:session_slug)

app/views/gillick_assessments/_form_fields.html.erb

Lines changed: 0 additions & 38 deletions
This file was deleted.

app/views/gillick_assessments/_guidance.html.erb

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/views/gillick_assessments/edit.html.erb

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
) %>
66
<% end %>
77

8-
<% page_title = "Edit Gillick competence" %>
8+
<% page_title = @is_first_assessment ? "Assess Gillick competence" : "Edit Gillick competence" %>
99

1010
<%= h1 page_title: do %>
1111
<span class="nhsuk-caption-l">
@@ -14,12 +14,54 @@
1414
<%= page_title %>
1515
<% end %>
1616

17-
<%= render "guidance" %>
17+
<%= govuk_inset_text do %>
18+
<p class="nhsuk-body">
19+
Before you make your assessment, you should give
20+
<%= @patient.given_name %> a chance to ask questions.
21+
</p>
22+
<% end %>
1823

19-
<%= form_with model: @gillick_assessment, url: session_patient_gillick_assessment_path do |f| %>
24+
<%= form_with model: @gillick_assessment, url: session_patient_gillick_assessment_path, method: :put do |f| %>
2025
<% content_for(:before_content) { f.govuk_error_summary } %>
2126

22-
<%= render "form_fields", f: %>
27+
<% options = [OpenStruct.new(value: true, label: "Yes"), OpenStruct.new(value: false, label: "No")] %>
28+
29+
<%= f.govuk_collection_radio_buttons :knows_vaccination,
30+
options,
31+
:value,
32+
:label,
33+
inline: true,
34+
legend: { text: "The child knows which vaccination they will have", size: "s" } %>
35+
36+
<%= f.govuk_collection_radio_buttons :knows_disease,
37+
options,
38+
:value,
39+
:label,
40+
inline: true,
41+
legend: { text: "The child knows which disease the vaccination protects against", size: "s" } %>
42+
43+
<%= f.govuk_collection_radio_buttons :knows_consequences,
44+
options,
45+
:value,
46+
:label,
47+
inline: true,
48+
legend: { text: "The child knows what could happen if they got the disease", size: "s" } %>
49+
50+
<%= f.govuk_collection_radio_buttons :knows_delivery,
51+
options,
52+
:value,
53+
:label,
54+
inline: true,
55+
legend: { text: "The child knows how the injection will be given", size: "s" } %>
56+
57+
<%= f.govuk_collection_radio_buttons :knows_side_effects,
58+
options,
59+
:value,
60+
:label,
61+
inline: true,
62+
legend: { text: "The child knows which side effects they might experience", size: "s" } %>
63+
64+
<%= f.govuk_text_area :notes, label: { text: "Assessment notes (optional)" } %>
2365

24-
<%= f.govuk_submit "Update your assessment" %>
66+
<%= f.govuk_submit @is_first_assessment ? "Complete your assessment" : "Update your assessment" %>
2567
<% end %>

app/views/gillick_assessments/new.html.erb

Lines changed: 0 additions & 25 deletions
This file was deleted.

config/routes.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@
312312
end
313313
end
314314

315-
resource :gillick_assessment,
316-
path: "gillick",
317-
only: %i[new create edit update]
315+
resource :gillick_assessment, path: "gillick", only: %i[edit update]
318316
resource :triages, only: %i[new create]
319317
resource :vaccinations, only: %i[create] do
320318
member do

0 commit comments

Comments
 (0)