diff --git a/app/components/app_activity_log_component.rb b/app/components/app_activity_log_component.rb index a25d3b581..0e8c94e9d 100644 --- a/app/components/app_activity_log_component.rb +++ b/app/components/app_activity_log_component.rb @@ -40,8 +40,7 @@ def triage_events def consent_events @patient_session.patient.consents.recorded.map do { - title: - "Consent #{_1.response} by #{_1.parent.full_name} (#{_1.who_responded})", + title: "Consent #{_1.response} by #{_1.name} (#{_1.who_responded})", time: _1.recorded_at } end diff --git a/spec/components/app_activity_log_component_spec.rb b/spec/components/app_activity_log_component_spec.rb index c7ef9784b..7173817cb 100644 --- a/spec/components/app_activity_log_component_spec.rb +++ b/spec/components/app_activity_log_component_spec.rb @@ -31,92 +31,115 @@ end let(:location) { create(:location, :school, name: "Hogwarts") } let(:session) { create(:session, programme:, location:) } - let(:patient) { create(:patient, school: location) } + let(:patient) do + create(:patient, school: location, given_name: "Sarah", family_name: "Doe") + end - let(:mum) { create(:parent, :recorded, full_name: "Jane Doe") } - let(:dad) { create(:parent, :recorded, full_name: "John Doe") } + describe "consent given by parents" do + let(:mum) { create(:parent, :recorded, full_name: "Jane Doe") } + let(:dad) { create(:parent, :recorded, full_name: "John Doe") } - before do - create(:parent_relationship, :mother, parent: mum, patient:) - create(:parent_relationship, :father, parent: dad, patient:) + before do + create(:parent_relationship, :mother, parent: mum, patient:) + create(:parent_relationship, :father, parent: dad, patient:) - create( - :consent, - :given, - programme:, - patient:, - parent: mum, - recorded_at: Time.zone.parse("2024-05-30 12:00") - ) - create( - :consent, - :refused, - programme:, - patient:, - parent: dad, - recorded_at: Time.zone.parse("2024-05-30 13:00") - ) - create( - :triage, - :needs_follow_up, - programme:, - patient_session:, - created_at: Time.zone.parse("2024-05-30 14:00"), - notes: "Some notes", - performed_by: user - ) - create( - :triage, - :ready_to_vaccinate, - programme:, - patient_session:, - created_at: Time.zone.parse("2024-05-30 14:30"), - performed_by: user - ) + create( + :consent, + :given, + programme:, + patient:, + parent: mum, + recorded_at: Time.zone.parse("2024-05-30 12:00") + ) + create( + :consent, + :refused, + programme:, + patient:, + parent: dad, + recorded_at: Time.zone.parse("2024-05-30 13:00") + ) + create( + :triage, + :needs_follow_up, + programme:, + patient_session:, + created_at: Time.zone.parse("2024-05-30 14:00"), + notes: "Some notes", + performed_by: user + ) + create( + :triage, + :ready_to_vaccinate, + programme:, + patient_session:, + created_at: Time.zone.parse("2024-05-30 14:30"), + performed_by: user + ) - create( - :vaccination_record, - programme:, - patient_session:, - created_at: Time.zone.parse("2024-05-31 12:00"), - performed_by: user, - notes: "Some notes" - ) - render_inline(component) - end + create( + :vaccination_record, + programme:, + patient_session:, + created_at: Time.zone.parse("2024-05-31 12:00"), + performed_by: user, + notes: "Some notes" + ) + render_inline(component) + end + + it "renders headings in correct order" do + expect(subject).to have_css("h2:nth-of-type(1)", text: "31 May 2024") + expect(subject).to have_css("h2:nth-of-type(2)", text: "30 May 2024") + expect(subject).to have_css("h2:nth-of-type(3)", text: "29 May 2024") + end + + include_examples "card", + title: "Vaccinated with Gardasil 9 (HPV)", + date: "31 May 2024 at 12:00pm", + notes: "Some notes", + by: "Nurse Joy" + + include_examples "card", + title: "Triaged decision: Safe to vaccinate", + date: "30 May 2024 at 2:30pm", + by: "Nurse Joy" - it "renders headings in correct order" do - expect(subject).to have_css("h2:nth-of-type(1)", text: "31 May 2024") - expect(subject).to have_css("h2:nth-of-type(2)", text: "30 May 2024") - expect(subject).to have_css("h2:nth-of-type(3)", text: "29 May 2024") + include_examples "card", + title: "Triaged decision: Keep in triage", + date: "30 May 2024 at 2:00pm", + notes: "Some notes", + by: "Nurse Joy" + + include_examples "card", + title: "Consent refused by John Doe (Dad)", + date: "30 May 2024 at 1:00pm" + + include_examples "card", + title: "Consent given by Jane Doe (Mum)", + date: "30 May 2024 at 12:00pm" + + include_examples "card", + title: "Added to session at Hogwarts", + date: "29 May 2024 at 12:00pm" end - include_examples "card", - title: "Vaccinated with Gardasil 9 (HPV)", - date: "31 May 2024 at 12:00pm", - notes: "Some notes", - by: "Nurse Joy" - - include_examples "card", - title: "Triaged decision: Safe to vaccinate", - date: "30 May 2024 at 2:30pm", - by: "Nurse Joy" - - include_examples "card", - title: "Triaged decision: Keep in triage", - date: "30 May 2024 at 2:00pm", - notes: "Some notes", - by: "Nurse Joy" - - include_examples "card", - title: "Consent refused by John Doe (Dad)", - date: "30 May 2024 at 1:00pm" - - include_examples "card", - title: "Consent given by Jane Doe (Mum)", - date: "30 May 2024 at 12:00pm" - - include_examples "card", - title: "Added to session at Hogwarts", - date: "29 May 2024 at 12:00pm" + describe "self-consent" do + before do + create( + :consent, + :given, + :self_consent, + programme:, + patient:, + recorded_at: Time.zone.parse("2024-05-30 12:00") + ) + render_inline(component) + end + + include_examples "card", + title: + "Consent given by Sarah Doe (Child (Gillick competent))", + date: "30 May 2024 at 12:00pm" + end end diff --git a/spec/factories/consents.rb b/spec/factories/consents.rb index e50dec380..a1eded76b 100644 --- a/spec/factories/consents.rb +++ b/spec/factories/consents.rb @@ -68,6 +68,11 @@ recorded_by { create(:user) } end + trait :self_consent do + route { "self_consent" } + parent { nil } + end + trait :refused do response { :refused } reason_for_refusal { :personal_choice }