From 6aeaf07bfc325ba37d461889e4e7f2927601baaa Mon Sep 17 00:00:00 2001 From: Theodor Vararu Date: Tue, 21 Nov 2023 15:28:13 +0100 Subject: [PATCH] Display basic tabs in consents index page This queries the list of patient_sessions and splits them into the respective categories that match the tabs in the design. --- app/controllers/consents_controller.rb | 17 ++++++++++++++ .../patient_session_state_machine_concern.rb | 6 +++++ app/views/consents/index.html.erb | 22 +++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/app/controllers/consents_controller.rb b/app/controllers/consents_controller.rb index cdd822ed7..cde9bee0e 100644 --- a/app/controllers/consents_controller.rb +++ b/app/controllers/consents_controller.rb @@ -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 @@ -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 diff --git a/app/models/concerns/patient_session_state_machine_concern.rb b/app/models/concerns/patient_session_state_machine_concern.rb index e9e255cae..da999bb60 100644 --- a/app/models/concerns/patient_session_state_machine_concern.rb +++ b/app/models/concerns/patient_session_state_machine_concern.rb @@ -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 diff --git a/app/views/consents/index.html.erb b/app/views/consents/index.html.erb index fb5177e35..79af5ee1f 100644 --- a/app/views/consents/index.html.erb +++ b/app/views/consents/index.html.erb @@ -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 %>