Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions app/components/app_patient_session_consent_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<h3 class="nhsuk-heading-m">Consent</h3>

<%= render AppCardComponent.new(feature: true) do |card| %>
<% card.with_heading(level: 4, colour:) { heading } %>
<%= render AppCardComponent.new(section: true) do |card| %>
<% card.with_heading(level: 2) { heading } %>

<% unless programme_status.vaccinated? %>
<% if consent_status_value == :no_response %>
Expand All @@ -27,21 +25,21 @@
<p>A consent request will be sent on <%= session.send_consent_requests_at.to_fs(:long) %>.</p>
<% end %>

<div class="nhsuk-button-group">
<% if can_send_consent_request? %>
<%= render AppActionLinkComponent.new(
text: "Record a new consent response",
href: new_session_patient_programme_consent_path(session, patient, programme),
) %>

<% if can_send_consent_request? %>
<div>
<%= govuk_button_to "Send consent request",
send_request_session_patient_programme_consents_path(
session, patient, programme
),
secondary: true %>
<% end %>
</div>
<% end %>

<%= govuk_button_to "Record a new consent response",
session_patient_programme_consents_path(
session, patient, programme
),
secondary: true %>
</div>
<% end %>

<% if consents.any? %>
Expand All @@ -52,11 +50,4 @@
<% end %>
<% end %>

<% if show_health_answers? %>
<hr class="nhsuk-section-break nhsuk-section-break--visible nhsuk-section-break--l">

<h5 class="nhsuk-heading-s nhsuk-u-margin-bottom-2">All answers to health questions</h5>

<%= render AppHealthAnswersSummaryComponent.new(grouped_consents) %>
<% end %>
<% end %>
11 changes: 1 addition & 10 deletions app/components/app_patient_session_consent_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ def initialize(patient:, session:, programme:)

def programme_type = programme.type

def colour
I18n.t(consent_status_value, scope: %i[status consent colour])
end

def heading
status_text = I18n.t(consent_status_value, scope: %i[status consent label])
"#{consent_status_generator.programme.name}: #{status_text}"
"Consent for #{consent_status_generator.programme.name} vaccination"
end

def consent_status_value
Expand Down Expand Up @@ -134,10 +129,6 @@ def who_refused
grouped_consents.find(&:response_refused?)&.who_responded
end

def show_health_answers?
grouped_consents.any?(&:response_given?)
end

def consent_notifications
patient
.consent_notifications
Expand Down
65 changes: 65 additions & 0 deletions app/components/app_patient_session_health_answers_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

class AppPatientSessionHealthAnswersComponent < ViewComponent::Base
erb_template <<~ERB
<% if any_yes_health_answers? %>
<%= render AppWarningCalloutComponent.new(heading:, level: 2) do %>
<%= render AppHealthAnswersSummaryComponent.new(grouped_consents) %>
<% end %>
<% else %>
<%= render AppCardComponent.new(section: true) do |card| %>
<% card.with_heading(level: 2) { heading } %>
<%= render AppHealthAnswersSummaryComponent.new(grouped_consents) %>
<% end %>
<% end %>
ERB

def render? = grouped_consents.any?(&:response_given?)

def initialize(patient:, session:, programme:)
@patient = patient
@session = session
@programme = programme
end

private

attr_reader :patient, :session, :programme

delegate :academic_year, to: :session

def heading
count = yes_health_answers_count
if count.positive?
"All answers to health questions, including #{count} #{"Yes response".pluralize(count)}"
else
"All answers to health questions"
end
end

def yes_health_answers_count
grouped_consents.sum do |consent|
consent.health_answers.count(&:response_yes?)
end
end

def any_yes_health_answers?
grouped_consents.any? do |consent|
consent.health_answers.any?(&:response_yes?)
end
end

def grouped_consents
@grouped_consents ||=
ConsentGrouper.call(
patient
.consents
.for_programme(programme)
.where(academic_year:)
.includes(:consent_form, :parent)
.order(created_at: :desc),
programme_type: programme.type,
academic_year:
)
end
end
30 changes: 11 additions & 19 deletions app/components/app_patient_session_triage_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<h3 class="nhsuk-heading-m">Triage</h3>

<%= render AppCardComponent.new(feature: true) do |card| %>
<% card.with_heading(level: 4, colour:) { heading } %>
<%= render AppCardComponent.new(section: true) do |card| %>
<% card.with_heading(level: 2) { heading } %>

<% if triage_status_value == :not_required %>
<p>No triage is needed for <%= patient.full_name %>.</p>

<div class="nhsuk-button-group">
<% if helpers.policy(Triage).new? %>
<%= govuk_button_link_to "Update triage outcome",
new_session_patient_programme_triages_path(session, patient, programme),
secondary: true %>
<% end %>
</div>
<% if helpers.policy(Triage).new? %>
<%= render AppActionLinkComponent.new(text: "Update triage outcome",
href: new_session_patient_programme_triages_path(session, patient, programme)) %>
<% end %>
<% elsif latest_triage.nil? || latest_triage.keep_in_triage? %>
<% if helpers.policy(Triage).new? %>
<p>You need to decide if <%= patient.full_name %> is safe to vaccinate.</p>
<p>You need to decide if <%= patient.given_name %> is safe to vaccinate.</p>

<% if triage_status_generator.vaccination_history_requires_triage? %>
<p>Incomplete vaccination history for <%= programme.name_in_sentence %>. Check if the child needs another dose.</p>
Expand All @@ -33,13 +28,10 @@
<p><%= summary %></p>
<% end %>

<div class="nhsuk-button-group">
<% if helpers.policy(Triage).new? %>
<%= govuk_button_link_to "Update triage outcome",
new_session_patient_programme_triages_path(session, patient, programme),
secondary: true %>
<% end %>
</div>
<% if helpers.policy(Triage).new? %>
<%= render AppActionLinkComponent.new(text: "Update triage outcome",
href: new_session_patient_programme_triages_path(session, patient, programme)) %>
<% end %>
<% end %>

<%= render AppTriageTableComponent.new(patient:, session:, programme:) %>
Expand Down
7 changes: 1 addition & 6 deletions app/components/app_patient_session_triage_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@ def render?

def programme_type = programme.type

def colour
I18n.t(triage_status_value, scope: %i[status triage colour])
end

def heading
status_text = I18n.t(triage_status_value, scope: %i[status triage label])
"#{triage_status_generator.programme.name}: #{status_text}"
"Triage for #{triage_status_generator.programme.name} vaccination"
end

def triage_status_value
Expand Down
6 changes: 4 additions & 2 deletions app/components/app_triage_form_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def fieldset_options
end
end

legend = { text:, size: "m", classes: "nhsuk-u-font-size-22" }

if heading
{ legend: { text:, tag: :h2 }, hint: { text: hint } }
{ legend: legend.merge(tag: :h2), hint: { text: hint } }
else
{ legend: { text: }, hint: { text: hint } }
{ legend:, hint: { text: hint } }
end
end

Expand Down
14 changes: 13 additions & 1 deletion app/controllers/patient_sessions/consents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class PatientSessions::ConsentsController < PatientSessions::BaseController
before_action :set_consent, except: %i[create send_request]
before_action :set_consent, except: %i[new create send_request]
before_action :set_consent_follow_up_form,
only: %i[edit_follow_up update_follow_up]
before_action :set_consent_confirm_refusal_form,
Expand All @@ -17,6 +17,18 @@ class PatientSessions::ConsentsController < PatientSessions::BaseController
before_action :ensure_can_invalidate,
only: %i[edit_invalidate update_invalidate]

def new
authorize Consent

@draft_consent = DraftConsent.new(request_session: session, current_user:)

@draft_consent.clear_attributes
@draft_consent.assign_attributes(create_params)
@draft_consent.save!

redirect_to draft_consent_path(Wicked::FIRST_STEP)
end

def create
authorize Consent

Expand Down
2 changes: 2 additions & 0 deletions app/views/patient_sessions/programmes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

<%= render AppPatientSessionConsentComponent.new(patient: @patient, session: @session, programme: @programme) %>

<%= render AppPatientSessionHealthAnswersComponent.new(patient: @patient, session: @session, programme: @programme) %>

<%= render AppPatientSessionTriageComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, triage_form: @triage_form) %>

<%= render AppPatientSessionRecordComponent.new(patient: @patient, session: @session, programme: @programme, current_user:, vaccinate_form: @vaccinate_form) %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
resources :programmes, path: "", param: :type, only: :show do
get "record-already-vaccinated"

resources :consents, only: %i[index create show] do
resources :consents, only: %i[index new create show] do
post "send-request", on: :collection, action: :send_request

member do
Expand Down
17 changes: 6 additions & 11 deletions spec/components/app_patient_session_consent_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
it { should_not have_css("details", text: /Consent (given|refused) by/) }
it { should_not have_css("details", text: "Responses to health questions") }
it { should have_css("p", text: "No consent request is scheduled") }
it { should have_css("button", text: "Record a new consent response") }
it { should have_link("Record a new consent response") }
end

context "when vaccinated" do
Expand All @@ -25,7 +25,7 @@
end

it { should_not have_css("p", text: "No requests have been sent.") }
it { should_not have_css("button", text: "Record a new consent response") }
it { should_not have_link("Record a new consent response") }
end

context "with refused consent" do
Expand All @@ -34,7 +34,7 @@
create(:consent, :refused, patient: patient.reload, parent:, programme:)
end

it { should have_css(".app-card__heading--red", text: "Consent refused") }
it { should have_content("refused to give consent") }
it { should have_content(consent.parent.full_name) }
it { should have_content(consent.parent_relationship.label) }
it { should have_content("Consent refused") }
Expand All @@ -48,12 +48,7 @@

let(:consent) { patient.consents.first }

it do
expect(rendered).to have_css(
".app-card__heading--green",
text: "Consent given"
)
end
it { should have_text("is ready for the vaccinator") }

it { should_not have_css("a", text: "Contact #{consent.parent.full_name}") }

Expand All @@ -64,7 +59,7 @@
create(:patient, :consent_given_nasal_only_triage_not_needed, session:)
end

it { should have_text("Consent given for nasal spray") }
it { should have_text("Nasal spray only") }

context "and the vaccine method is overridden by triage" do
let(:patient) do
Expand All @@ -75,7 +70,7 @@
)
end

it { should have_text("Consent given for injection") }
it { should have_text("is ready for the vaccinator") }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

describe AppPatientSessionHealthAnswersComponent do
subject(:rendered) { render_inline(component) }

let(:component) { described_class.new(patient:, session:, programme:) }

let(:programme) { Programme.hpv }
let(:session) { create(:session, programmes: [programme]) }
let(:patient) { create(:patient, session:) }

context "without any given consent" do
it { expect(rendered.to_html).to be_blank }
end

context "with refused consent" do
before { create(:consent, :refused, patient:, programme:) }

it { expect(rendered.to_html).to be_blank }
end

context "with given consent, all no health answers" do
before do
create(:consent, :given, :no_contraindications, patient:, programme:)
end

it { should have_css("section", text: "All answers to health questions") }
it { should_not have_css(".nhsuk-card--warning") }
it { should_not have_text("Yes response") }
end

context "with given consent with 1 yes health answer" do
before do
create(:consent, :given, :health_question_notes, patient:, programme:)
end

it { should have_css(".nhsuk-card--warning") }
it { should have_text("including 1 Yes response") }
end

context "with given consent with multiple yes health answers" do
before do
create(
:consent,
:given,
patient:,
programme:,
health_answers: [
HealthAnswer.new(question: "Question 1", response: "yes"),
HealthAnswer.new(question: "Question 2", response: "yes"),
HealthAnswer.new(question: "Question 3", response: "no")
]
)
end

it { should have_css(".nhsuk-card--warning") }
it { should have_text("including 2 Yes responses") }
end
end
Loading