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

[Update] added the radio button fix #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions migration/v1_to_v2/data/exporters/record_data_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
class RecordDataExporter < DataExporter
private

def initialize(options = {})
super(options)
@radio_fields = get_radio_fields
end

def parse_object(object)
super(object).merge(ownership_fields(object))
end
Expand All @@ -17,6 +22,46 @@ def migrate_notes(notes)
end
end

def get_radio_fields
primero_module = PrimeroModule.find_by_name("CP") #hardcoded for now. need to change it to accomodate either one. Cannot use all since there comflicting fields in both modules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to change this to accommodate GBV migrations. There are shared fields between the two modules but they shouldn't conflict.

formsections = primero_module.associated_forms(true)
radio_fields = []
formsections.each do |form|
radio_fields << form.fields.map{ |s| s.name if s.visible == true && s.type == "radio_button" && s.option_strings_source == "lookup lookup-yes-no" }.compact
end
return radio_fields.flatten.compact
end

def value_to_ruby_string(value, include_blank = false)
return 'nil' if include_blank && value.nil?

puts value

if value.is_a?(Hash)
ruby_string = "{\n"
_i
ruby_string += i
# TODO: was using .compact instead of .reject but it was throwing away false values. We want to keep those
ruby_string += (include_blank ? value : value.reject { |_, v| v.nil? || v == [] }).map do |k,v|
if @radio_fields.include?(k)
"#{key_to_ruby(k)}: \"#{v}\""
else
"#{key_to_ruby(k)}: #{value_to_ruby_string(v, include_blank)}"
end
end.join(",\n#{i}")
i_
ruby_string + "\n#{i}}"
elsif value.is_a?(Array)
array_value_to_ruby_string(value, include_blank)
elsif value.is_a?(Range)
value
elsif value.is_a?(String) && (value.include?('.parse(') || value.include?('.find_by('))
value
else
value.to_json
end
end

def data_hash_case(data_hash)
keys = data_hash.keys
data_hash['notes_section'] = migrate_notes(data_hash['notes_section']) if data_hash['notes_section'].present?
Expand Down