Skip to content

Commit 6f748c5

Browse files
authored
Only show attendance buttons if allowed (#3205)
This ensures that we're not showing the buttons when the attendance cannot be changed, for example if a vaccination record has been created against that patient and session for the particular date.
2 parents 2915c0a + 59606c5 commit 6f748c5

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

app/components/app_patient_session_search_result_card_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AppPatientSessionSearchResultCardComponent < ViewComponent::Base
3131
end
3232
end %>
3333
34-
<% if context == :register %>
34+
<% if context == :register && helpers.policy(patient_session.register_outcome.latest).new? %>
3535
<div class="app-button-group">
3636
<%= helpers.govuk_button_to "Attending", create_session_register_path(session, patient, "present", search_form: params[:search_form]&.permit!), class: "app-button--secondary app-button--small" %>
3737
<%= helpers.govuk_button_to "Absent", create_session_register_path(session, patient, "absent", search_form: params[:search_form]&.permit!), class: "app-button--secondary-warning app-button--small" %>

app/models/patient_session.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class PatientSession < ApplicationRecord
6464
scope :preload_for_status,
6565
-> do
6666
eager_load(:patient).preload(
67-
:session_attendances,
67+
session_attendances: :session_date,
6868
patient: [:triages, { consents: :parent }, :vaccination_records],
6969
session: :programmes
7070
)

app/policies/session_attendance_policy.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def update?
1111

1212
private
1313

14-
delegate :patient, :session_date, to: :record
14+
delegate :patient_session, :session_date, to: :record
15+
delegate :patient, to: :patient_session
1516

1617
def was_seen_by_nurse?
17-
patient
18-
.vaccination_records
19-
.where(performed_at: session_date.value.all_day)
20-
.exists?
18+
patient.vaccination_records.any? do
19+
it.performed_at.to_date == session_date.value
20+
end
2121
end
2222
end

spec/components/app_patient_session_search_result_card_component_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,21 @@
3232
context "when context is register" do
3333
let(:context) { :register }
3434

35-
it { should have_text("Action required\nGet consent for HPV") }
35+
context "when allowed to record attendance" do
36+
before { stub_authorization(allowed: true) }
37+
38+
it { should have_text("Action required\nGet consent for HPV") }
39+
it { should have_button("Attending") }
40+
it { should have_button("Absent") }
41+
end
42+
43+
context "when not allowed to record attendance" do
44+
before { stub_authorization(allowed: false) }
45+
46+
it { should have_text("Action required\nGet consent for HPV") }
47+
it { should_not have_button("Attending") }
48+
it { should_not have_button("Absent") }
49+
end
3650
end
3751

3852
context "when context is record" do

0 commit comments

Comments
 (0)