WIP: create backend for socio-economic-status

This commit is contained in:
rebuilt 2025-06-25 11:08:12 -07:00
parent 61c5b0b087
commit a258b32b39
23 changed files with 346 additions and 23 deletions

View file

@ -10,6 +10,9 @@ class DemographicLoader
create_from_column(column: "Special Ed Status", row:, model: Sped)
create_from_column(column: "Housing", row:, model: Housing)
create_from_column(column: "Language", row:, model: Language)
create_from_column(column: "Employment", row:, model: Employment)
create_from_column(column: "Education", row:, model: Education)
create_from_column(column: "Benefits", row:, model: Benefit)
end
end

View file

@ -102,6 +102,24 @@ class SurveyItemValues
@response_id ||= value_from(pattern: /Response\s*ID/i)
end
def employments
e = value_from(pattern: /^Employment$/i)
return [] if e.nil? || e.empty?
e.split(",").map do |item|
Employment.to_designation(item.strip)
end
end
def education
Education.to_designation(value_from(pattern: /^Education$/i)&.strip)
end
def benefits
Benefit.to_designation(value_from(pattern: /^Benefits$/i)&.strip)
end
def dese_id
@dese_id ||= begin
dese_id = value_from(pattern: /Dese\s*ID/i)

View file

@ -78,6 +78,18 @@ class SurveyResponsesDataLoader
@speds ||= Sped.by_designation
end
def employments
@employments ||= Employment.by_designation
end
def educations
@educations ||= Education.by_designation
end
def benefits
@benefits ||= Benefit.by_designation
end
def academic_years
@academic_years ||= AcademicYear.all
end
@ -110,6 +122,9 @@ class SurveyResponsesDataLoader
if row.respondent_type == :parent
parent = Parent.find_or_create_by(response_id: row.response_id)
parent.number_of_children = row.number_of_children
parent.education = educations[row.education] if row.education.present?
parent.benefits_id = benefits[row.benefits].id if row.benefits.present?
tmp_languages = row.languages.map { |language| languages[language] }.reject(&:nil?)
parent.languages.delete_all
parent.languages.concat(tmp_languages)
@ -122,6 +137,10 @@ class SurveyResponsesDataLoader
tmp_genders = row.genders_of_children.map { |race| genders[race] }.reject(&:nil?)
parent.genders.concat(tmp_genders)
parent.employments.delete_all
tmp_employments = row.employments.map { |employment| employments[employment] }.reject(&:nil?)
parent.employments.concat(tmp_employments)
parent.housing = housings[row.housing] if row.housing.present?
parent.save
end