Browse Source

feat: show correct headers in csv

pull/2083/head
natdeanlewissoftwire 2 years ago
parent
commit
d25fa8ded3
  1. 35
      app/services/csv/scheme_csv_service.rb

35
app/services/csv/scheme_csv_service.rb

@ -19,6 +19,21 @@ module Csv
private private
FIELD_FROM_ATTRIBUTE = {
"scheme_code" => %w[id_to_display],
"scheme_service_name" => %w[service_name],
"scheme_status" => %w[status],
"scheme_sensitive" => %w[sensitive],
"scheme_registered_under_care_act" => %w[registered_under_care_act],
"scheme_support_services_provided_by" => %w[arrangement_type],
"scheme_primary_client_group" => %w[primary_client_group],
"scheme_has_other_client_group" => %w[has_other_client_group],
"scheme_secondary_client_group" => %w[secondary_client_group],
"scheme_support_type" => %w[support_type],
"scheme_intended_stay" => %w[intended_stay],
"scheme_created_at" => %w[created_at],
}.freeze
CUSTOM_CALL_CHAINS = { CUSTOM_CALL_CHAINS = {
scheme_owning_organisation_name: %i[owning_organisation name], scheme_owning_organisation_name: %i[owning_organisation name],
}.freeze }.freeze
@ -28,6 +43,7 @@ module Csv
].freeze ].freeze
def value(attribute, scheme) def value(attribute, scheme)
attribute = FIELD_FROM_ATTRIBUTE.fetch(attribute, attribute)
if attribute == "scheme_active_dates" if attribute == "scheme_active_dates"
scheme_availability(scheme) scheme_availability(scheme)
elsif CUSTOM_CALL_CHAINS.key? attribute.to_sym elsif CUSTOM_CALL_CHAINS.key? attribute.to_sym
@ -40,26 +56,9 @@ module Csv
end end
end end
ATTRIBUTE_MAPPINGS = {
"scheme_code" => %w[id_to_display],
"scheme_service_name" => %w[service_name],
"scheme_status" => %w[status],
"scheme_sensitive" => %w[sensitive],
"scheme_registered_under_care_act" => %w[registered_under_care_act],
"scheme_support_services_provided_by" => %w[arrangement_type],
"scheme_primary_client_group" => %w[primary_client_group],
"scheme_has_other_client_group" => %w[has_other_client_group],
"scheme_secondary_client_group" => %w[secondary_client_group],
"scheme_support_type" => %w[support_type],
"scheme_intended_stay" => %w[intended_stay],
"scheme_created_at" => %w[created_at],
}.freeze
def scheme_attributes def scheme_attributes
attributes = %w[scheme_code scheme_service_name scheme_status scheme_sensitive scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates] %w[scheme_code scheme_service_name scheme_status scheme_sensitive scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates]
attributes.flat_map do |attribute|
ATTRIBUTE_MAPPINGS.fetch(attribute, attribute)
end
end end
end end
end end

Loading…
Cancel
Save