Skip to content

Commit

Permalink
Display basic tabs in consents index page
Browse files Browse the repository at this point in the history
This queries the list of patient_sessions and splits them into the
respective categories that match the tabs in the design.
  • Loading branch information
tvararu committed Nov 24, 2023
1 parent 5c5d03d commit 6aeaf07
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/controllers/consents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
class ConsentsController < ApplicationController
before_action :set_session
before_action :set_patient_sessions, only: %i[index]

def index
methods = %i[consent_given? consent_refused? consent_conflicts? no_consent?]

@tabs =
@patient_sessions.group_by do |patient_session|
methods.find { |m| patient_session.send(m) }
end

methods.each { |m| @tabs[m] ||= [] }
end

private
Expand All @@ -12,4 +21,12 @@ def set_session
params.fetch(:session_id) { params.fetch(:id) }
)
end

def set_patient_sessions
@patient_sessions =
@session
.patient_sessions
.includes(patient: :consents)
.order("patients.first_name", "patients.last_name")
end
end
6 changes: 6 additions & 0 deletions app/models/concerns/patient_session_state_machine_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def consent_refused?
consents.any?(&:response_refused?)
end

def consent_conflicts?
return false if no_consent?

consents.any?(&:response_given?) && consents.any?(&:response_refused?)
end

def no_consent?
consents.empty?
end
Expand Down
22 changes: 22 additions & 0 deletions app/views/consents/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,25 @@
<% end %>
<%= h1 "Check consent responses", class: "govuk-heading-l" %>
<%= govuk_tabs title: "Vaccinations", classes: 'nhsuk-tabs' do |c|
c.with_tab(label: "Consent given (#{ @tabs[:consent_given?].size })",
classes: 'nhsuk-tabs__panel') do
@tabs[:consent_given?].size.to_s
end

c.with_tab(label: "Consent refused (#{ @tabs[:consent_refused?].size })",
classes: 'nhsuk-tabs__panel') do
@tabs[:consent_refused?].size.to_s
end

c.with_tab(label: "Consent conflicts (#{ @tabs[:consent_conflicts?].size })",
classes: 'nhsuk-tabs__panel') do
@tabs[:consent_conflicts?].size.to_s
end

c.with_tab(label: "No response (#{ @tabs[:no_consent?].size })",
classes: 'nhsuk-tabs__panel') do
@tabs[:no_consent?].size.to_s
end
end %>

0 comments on commit 6aeaf07

Please sign in to comment.