Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flags to child records #2709

Merged
merged 5 commits into from
Dec 13, 2024
Merged
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
4 changes: 4 additions & 0 deletions app/assets/stylesheets/_status.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
color: $color_nhsuk-aqua-green;
}

&--blue {
color: $color_nhsuk-blue;
}

&--dark-orange {
color: $color_app-dark-orange;
}
Expand Down
30 changes: 30 additions & 0 deletions app/components/app_notice_status_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

class AppNoticeStatusComponent < ViewComponent::Base
def call
icon_warning @text, "blue"
end

def initialize(text:)
super

@text = text
end

private

def icon_warning(content, color)
template = <<-ERB
<p class="app-status app-status--#{color}">
<svg class="nhsuk-icon app-icon__warning"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
aria-hidden="true">
<path d="M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20Zm0 14a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Zm-1.5-9.5V13a1.5 1.5 0 0 0 3 0V6.5a1.5 1.5 0 0 0-3 0Z" fill="currentColor"></path>
</svg>
#{content}
</p>
ERB
template.html_safe
end
end
46 changes: 46 additions & 0 deletions app/components/app_patient_card_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

class AppPatientCardComponent < ViewComponent::Base
erb_template <<-ERB
<%= render AppCardComponent.new do |card| %>
<% card.with_heading { "Child record" } %>

<% if Flipper.enabled?(:"v1.2.0") %>
<% if @patient.date_of_death.present? %>
<%= render AppNoticeStatusComponent.new(
text: "Record updated with child’s date of death"
) %>
<% end %>

<% if @patient.invalidated? %>
<%= render AppNoticeStatusComponent.new(
text: "Record flagged as invalid"
) %>
<% end %>

<% if @patient.restricted? %>
<%= render AppNoticeStatusComponent.new(
text: "Record flagged as sensitive"
) %>
<% end %>
<% end %>

<%= render AppPatientSummaryComponent.new(
patient,
show_parent_or_guardians: true
) %>

<%= content %>
<% end %>
ERB

def initialize(patient)
super

@patient = patient
end

private

attr_reader :patient
end
5 changes: 1 addition & 4 deletions app/components/app_patient_page_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
render AppSimpleStatusBannerComponent.new(patient_session:)
end %>

<%= render AppCardComponent.new do |c| %>
<% c.with_heading { "Child details" } %>
<%= render AppPatientSummaryComponent.new(patient, show_parent_or_guardians: true) %>
<% end %>
<%= render AppPatientCardComponent.new(patient) %>

<% if display_gillick_assessment_card? %>
<%= render AppCardComponent.new do |c| %>
Expand Down
15 changes: 3 additions & 12 deletions app/components/app_patient_summary_component.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# frozen_string_literal: true

class AppPatientSummaryComponent < ViewComponent::Base
def initialize(
patient,
show_parent_or_guardians: false,
change_links: {},
highlight: true
)
def initialize(patient, change_links: {}, show_parent_or_guardians: false)
super

@patient = patient

@show_parent_or_guardians = show_parent_or_guardians
@change_links = change_links
@highlight = highlight
@show_parent_or_guardians = show_parent_or_guardians
end

def call
Expand Down Expand Up @@ -171,8 +164,6 @@ def format_parent_or_guardians
end

def highlight_if(value, condition)
return value unless @highlight && condition

tag.span value, class: "app-highlight"
condition ? tag.span(value, class: "app-highlight") : value
end
end
3 changes: 2 additions & 1 deletion app/controllers/consent_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def update_match
end

def new_patient
@patient = Patient.from_consent_form(@consent_form)
@patient =
Patient.from_consent_form(@consent_form).tap(&:clear_changes_information)

render layout: "two_thirds"
end
Expand Down
7 changes: 1 addition & 6 deletions app/views/consent_forms/new_patient.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
<%= page_title %>
<% end %>

<%= render AppCardComponent.new do |c| %>
<% c.with_heading { "Child record" } %>
<%= render AppPatientSummaryComponent.new(@patient,
show_parent_or_guardians: true,
highlight: false) %>
<% end %>
<%= render AppPatientCardComponent.new(@patient) %>

<%= render AppCardComponent.new do |c|
c.with_heading { "Consent response" }
Expand Down
8 changes: 3 additions & 5 deletions app/views/patients/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
<%= page_title %>
<% end %>

<% change_links = { nhs_number: edit_nhs_number_patient_path(@patient) } %>

<%= render AppCardComponent.new do |card| %>
<% card.with_heading { "Record details" } %>
<%= render AppPatientSummaryComponent.new(
@patient,
show_parent_or_guardians: true,
change_links: { nhs_number: edit_nhs_number_patient_path(@patient) },
) %>
<%= render AppPatientSummaryComponent.new(@patient, change_links:) %>
<% end %>

<%= govuk_button_link_to "Continue", patient_path(@patient) %>
5 changes: 1 addition & 4 deletions app/views/patients/edit/nhs_number_merge.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
Updating the NHS number for <%= @patient.full_name %> will merge their record with an existing record:
</p>

<%= render AppCardComponent.new do |card| %>
<% card.with_heading { "Child record" } %>
<%= render AppPatientSummaryComponent.new(@existing_patient) %>
<% end %>
<%= render AppPatientCardComponent.new(@existing_patient) %>

<%= form_with model: @patient, url: edit_nhs_number_merge_patient_path(@patient), method: :put do |f| %>
<%= f.hidden_field :nhs_number, value: @existing_patient.nhs_number %>
Expand Down
4 changes: 1 addition & 3 deletions app/views/patients/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
nav.with_item(href: log_patient_path(@patient), text: "Activity log")
end %>

<%= render AppCardComponent.new do |c| %>
<% c.with_heading { "Child record" } %>
<%= render AppPatientSummaryComponent.new(@patient, show_parent_or_guardians: true) %>
<%= render AppPatientCardComponent.new(@patient) do %>
<%= govuk_button_link_to "Edit child record", edit_patient_path(@patient), class: "app-button--secondary" %>
<% end %>

Expand Down
5 changes: 1 addition & 4 deletions app/views/vaccination_records/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

<%= h1 @patient.full_name %>

<%= render AppCardComponent.new do |c| %>
<% c.with_heading { "Child record" } %>
<%= render AppPatientSummaryComponent.new(@patient, show_parent_or_guardians: true) %>
<% end %>
<%= render AppPatientCardComponent.new(@patient) %>

<%= render AppCardComponent.new do |c| %>
<% c.with_heading { "Vaccination details" } %>
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Faker::Config.locale = "en-GB"

def set_feature_flags
%i[dev_tools mesh_jobs cis2].each do |feature_flag|
%i[dev_tools mesh_jobs cis2 v1.2.0].each do |feature_flag|
Flipper.add(feature_flag) unless Flipper.exist?(feature_flag)
end
end
Expand Down
64 changes: 64 additions & 0 deletions spec/components/app_patient_card_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

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

let(:component) { described_class.new(patient) }

let(:patient) { create(:patient) }

it { should have_content("Child record") }

it { should have_content("Full name") }
it { should have_content("Date of birth") }
it { should have_content("Address") }

context "with a deceased patient" do
let(:patient) { create(:patient, :deceased) }

context "with feature flag enabled" do
before { Flipper.enable(:"v1.2.0") }
after { Flipper.enable(:"v1.2.0") }

it { should have_content("Record updated with child’s date of death") }
end

context "without feature flag enabled" do
it do
expect(rendered).not_to have_content(
"Record updated with child’s date of death"
)
end
end
end

context "with an invalidated patient" do
let(:patient) { create(:patient, :invalidated) }

context "with feature flag enabled" do
before { Flipper.enable(:"v1.2.0") }
after { Flipper.enable(:"v1.2.0") }

it { should have_content("Record flagged as invalid") }
end

context "without feature flag enabled" do
it { should_not have_content("Record flagged as invalid") }
end
end

context "with a restricted patient" do
let(:patient) { create(:patient, :restricted) }

context "with feature flag enabled" do
before { Flipper.enable(:"v1.2.0") }
after { Flipper.enable(:"v1.2.0") }

it { should have_content("Record flagged as sensitive") }
end

context "without feature flag enabled" do
it { should_not have_content("Record flagged as sensitive") }
end
end
end
4 changes: 2 additions & 2 deletions spec/components/app_patient_page_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
end

it { should have_css(".nhsuk-card__heading", text: "Child details") }
it { should have_css(".nhsuk-card__heading", text: "Child record") }
it { should have_css(".nhsuk-card__heading", text: "Consent") }
it { should_not have_css(".nhsuk-card__heading", text: "Triage notes") }

Expand Down Expand Up @@ -77,7 +77,7 @@
)
end

it { should have_css(".nhsuk-card__heading", text: "Child details") }
it { should have_css(".nhsuk-card__heading", text: "Child record") }
it { should have_css(".nhsuk-card__heading", text: "Consent") }
it { should have_css(".nhsuk-card__heading", text: "Triage notes") }

Expand Down
Loading