Skip to content

Commit

Permalink
Improve validation for clawback payer response upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie committed Jan 30, 2025
1 parent f86f3c1 commit b39d4da
Show file tree
Hide file tree
Showing 28 changed files with 467 additions and 266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def update
@wizard.upload_esfa_responses
@wizard.reset_state
redirect_to index_path, flash: {
heading: t(".success"),
heading: t(".heading"),
body: t(".body"),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def update
@wizard.upload_provider_responses
@wizard.reset_state
redirect_to index_path, flash: {
heading: t(".success"),
heading: t(".heading"),
body: t(".body"),
}
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
<% content_for(:page_title) { sanitize t(".page_title") } %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-grid-column-full">
<span class="govuk-caption-l"><%= t(".caption") %></span>
<h1 class="govuk-heading-l"><%= t(".title") %></h1>

<%= form_for(current_step, url: current_step_path, method: :put) do |f| %>
<%= f.govuk_error_summary %>

<p class="govuk-body">
<%= t(".claims_count", count: current_step.claims_count) %>
<h2 class="govuk-heading-m"><%= current_step.file_name %></h2>

<div class="horizontal-scrollable">
<%= govuk_table do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell text: 1 %>
<% current_step.csv_headers.each do |header| %>
<% row.with_cell text: header %>
<% end %>
<% end %>
<% end %>

<% table.with_body do |body| %>
<% current_step.csv.each_with_index do |csv_row, index| %>
<% if csv_row["claim_reference"].present? %>
<% body.with_row do |row| %>
<% row.with_cell text: index + 2 %>
<% current_step.csv_headers.each do |header| %>
<%= row.with_cell text: csv_row[header] %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
</div>

<p class="govuk_body govuk-!-text-align-centre">
<% if current_step.csv.count > 5 %>
<%= t(".only_showing_first_five_rows") %>
<% else %>
<%= t(".showing_all_rows") %>
<% end %>
</p>

<%= f.govuk_submit(t(".upload_data")) %>
<%= f.govuk_submit(t(".confirm_upload")) %>
<% end %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,75 +1,69 @@
<% content_for(:page_title) { sanitize t(".page_title") } %>
<% content_for(:page_title) { sanitize title_with_error_prefix(t(".page_title"), error: true) } %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<div class="govuk-grid-column-full">
<span class="govuk-caption-l"><%= t(".caption") %></span>
<h1 class="govuk-heading-l"><%= t(".title") %></h1>
<% if current_step.invalid_claim_references.present? %>
<h2 class="govuk-heading-m govuk-!-margin-top-0">
<%= t(".incorrect_claim_reference") %>
</h2>

<%= govuk_summary_list(actions: false) do |summary_list| %>
<% current_step.invalid_claim_references.each do |invalid_claim_references| %>
<% summary_list.with_row do |row| %>
<% row.with_key(
text: invalid_claim_references,
) %>
<% end %>
<% end %>
<% end %>
<% end %>
<div class="govuk-error-summary" data-module="govuk-error-summary">
<div role="alert">
<h2 class="govuk-error-summary__title">
<%= t(".error_summary.title") %>
</h2>
<div class="govuk-error-summary__body">
<div class="govuk-list govuk-error-summary__list">
<% if current_step.error_count > 0 %>
<p class="govuk-heading-s">
<%= t(".error_summary.errors_to_fix", count: current_step.error_count) %>
</p>
<% end %>
</div>
</div>
</div>
</div>

<% if current_step.invalid_status_claims.present? %>
<h2 class="govuk-heading-m govuk-!-margin-top-0">
<%= t(".incorrect_status") %>
</h2>
<h2 class="govuk-heading-m"><%= current_step.file_name %></h2>

<%= govuk_table do |table| %>
<% table.with_head do |head| %>
<% head.with_row do |row| %>
<% row.with_cell text: 1 %>
<% row.with_cell text: t(".csv_table.headers.claim_reference") %>
<% row.with_cell text: t(".csv_table.headers.claim_status") %>

<%= govuk_summary_list do |summary_list| %>
<% current_step.invalid_status_claims.each do |invalid_claim| %>
<% summary_list.with_row do |row| %>
<% row.with_key(
text: invalid_claim.reference,
) %>
<% row.with_action(
text: t(".view"),
href: claims_support_claim_path(invalid_claim),
visually_hidden_text: invalid_claim.reference,
html_attributes: {
class: "govuk-link--no-visited-state",
target: "_blank",
new_tab: true,
},
) %>
<% end %>
<% end %>
<% end %>
<% end %>

<% if current_step.invalid_updated_status_claims.present? %>
<h2 class="govuk-heading-m govuk-!-margin-top-0">
<%= t(".invalid_updated_status") %>
</h2>

<%= govuk_summary_list do |summary_list| %>
<% current_step.invalid_updated_status_claims.each do |invalid_claim| %>
<% summary_list.with_row do |row| %>
<% row.with_key(
text: invalid_claim.reference,
) %>
<% row.with_action(
text: t(".view"),
href: claims_support_claim_path(invalid_claim),
visually_hidden_text: invalid_claim.reference,
html_attributes: { class: "govuk-link--no-visited-state" },
) %>
<% table.with_body do |body| %>
<% current_step.row_indexes_with_errors.each do |csv_row_index| %>
<% csv_row = current_step.csv[csv_row_index] %>
<% body.with_row do |row| %>
<% row.with_cell(text: csv_row_index + 2) %>
<% row.with_cell do %>
<p>
<% if current_step.invalid_claim_rows.include?(csv_row_index) %>
<strong class="error-text"><%= t(".csv_table.errors.invalid_claim_reference") %></strong><br>
<% end %>
<%= csv_row["claim_reference"] %>
</p>
<% end %>
<% row.with_cell do %>
<p>
<% if current_step.invalid_claim_status_rows.include?(csv_row_index) %>
<strong class="error-text"><%= t(".csv_table.errors.invalid_claim_status") %></strong><br>
<% end %>
<%= csv_row["claim_status"] %>
</p>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>

<%= govuk_warning_text do %>
<%= t(".upload_warning_html") %>
<% end %>
<p class="govuk_body govuk-!-text-align-centre">
<%= t(".only_showing_rows_with_errors") %>
</p>

<%= govuk_button_link_to t(".upload_your_file_again"), step_path(:upload) %>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1 class="govuk-heading-l"><%= t(".title") %></h1>

<%= form_for(current_step, url: current_step_path, method: :put, multipart: true) do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_error_summary(presenter: DetailedErrorSummaryPresenter) %>
<%= f.govuk_file_field :csv_upload, label: { text: t(".upload_csv_file"), size: "s" } %>

<%= govuk_details(summary_text: t(".csv_help")) do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<p class="govuk_body govuk-!-text-align-centre">
<% if current_step.csv.count > 5 %>
<%= t(".only_showing_first_rows", row_count: current_step.csv.count) %>
<%= t(".only_showing_first_five_rows") %>
<% else %>
<%= t(".showing_all_rows") %>
<% end %>
Expand Down
7 changes: 1 addition & 6 deletions app/wizards/claims/upload_esfa_clawback_response_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def clawback_in_progress_claims
@clawback_in_progress_claims ||= Claims::Claim.clawback_in_progress
end

def claims_count
csv_rows.count
end

private

attr_reader :current_user
Expand All @@ -52,8 +48,7 @@ def csv_inputs_valid?
end

def csv_rows
csv = steps.fetch(:upload).csv_content
CSV.parse(csv, headers: true, skip_blanks: true).reject do |row|
steps.fetch(:upload).csv.reject do |row|
row["claim_reference"].blank?
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
class Claims::UploadESFAClawbackResponseWizard::ConfirmationStep < BaseStep
delegate :claims_count, to: :wizard
delegate :file_name, :csv, to: :upload_step

def csv_headers
@csv_headers ||= csv.headers
end

private

def upload_step
@upload_step ||= wizard.steps.fetch(:upload)
end
end
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
class Claims::UploadESFAClawbackResponseWizard::UploadErrorsStep < BaseStep
delegate :invalid_claim_references,
:invalid_status_claim_references,
:invalid_updated_status_claim_references,
delegate :invalid_claim_rows,
:invalid_claim_status_rows,
:file_name,
:csv,
to: :upload_step

def invalid_status_claims
return [] if invalid_status_claim_references.blank?

Claims::Claim.where(reference: invalid_status_claim_references)
def row_indexes_with_errors
combined_errors.uniq.sort
end

def invalid_updated_status_claims
return [] if invalid_updated_status_claim_references.blank?

Claims::Claim.where(reference: invalid_updated_status_claim_references)
def error_count
combined_errors.count
end

private

def combined_errors
invalid_claim_rows +
invalid_claim_status_rows
end

def upload_step
@upload_step ||= wizard.steps.fetch(:upload)
end
Expand Down
Loading

0 comments on commit b39d4da

Please sign in to comment.