lib/tasks/fix_nil_ethnicity_arrays.rake
# - find draft applications that were ingested via ATP (or using provided hbx_id)
# - check and update person ethnicity array
# - check and update applicant ethnicity array
find draft applications that were ingested via ATP (or using provided hbx_id)
check and update person ethnicity array
check and update applicant ethnicity array
find draft applications that were ingested via ATP ( or using provided hbx_id ) check and update person ethnicity array check and update applicant ethnicity array
def remove_ethnicity_nils
      application_hbx_id = ENV['application_hbx_id']
      applications = if application_hbx_id.present?
                       FinancialAssistance::Application.draft.where(hbx_id: application_hbx_id)
                     else
                       FinancialAssistance::Application.draft.not.where(transfer_id: nil)
                     end
      @primary_hbx_ids = []
      applications.no_timeout.each do |application|
        application.applicants.no_timeout.each do |applicant|
          person = find_person(applicant.person_hbx_id)
          next if person.nil?
          person_ethnicity = person.ethnicity
          next unless person_ethnicity && person_ethnicity.include?(nil)
          fix_person_ethnicity_array(person_ethnicity, application, person)
        end
      end
      applications.no_timeout.each do |application|
        application.applicants.no_timeout.each do |applicant|
          next if applicant.nil?
          applicant_ethnicity = applicant.ethnicity
          next unless applicant_ethnicity && applicant_ethnicity.include?(nil)
          fix_applicant_ethnicity_array(applicant_ethnicity, application, applicant)
        end
      end
    end
def remove_ethnicity_nils application_hbx_id = ENV [ 'application_hbx_id' ] applications = if application_hbx_id . present? FinancialAssistance :: Application . draft . where ( hbx_id : application_hbx_id ) else FinancialAssistance :: Application . draft . not . where ( transfer_id : nil ) end @primary_hbx_ids = [ ] applications . no_timeout . each do | application | application . applicants . no_timeout . each do | applicant | person = find_person ( applicant . person_hbx_id ) next if person . nil? person_ethnicity = person . ethnicity next unless person_ethnicity && person_ethnicity . include? ( nil ) fix_person_ethnicity_array ( person_ethnicity , application , person ) end end applications . no_timeout . each do | application | application . applicants . no_timeout . each do | applicant | next if applicant . nil? applicant_ethnicity = applicant . ethnicity next unless applicant_ethnicity && applicant_ethnicity . include? ( nil ) fix_applicant_ethnicity_array ( applicant_ethnicity , application , applicant ) end end end
find draft applications that were ingested via ATP (or using provided hbx_id)
 check and update person ethnicity array
 check and update applicant ethnicity array
find draft applications that were ingested via ATP ( or using provided hbx_id ) check and update person ethnicity array check and update applicant ethnicity array
# Run on application with provided hbx_id # Run on all ATP-ingested draft applications # Fix person ethnicity arrays # Fix applicant ethnicity arrays