diff --git a/CHANGELOG.md b/CHANGELOG.md index 13897ccd..0aec9987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased ## New features +- Add `bld_ef3__student__other_names` and conditional code in `dim_student` to pull into columns, if configured in dbt var `'edu:stu_demos:other_names'`. ## Under the hood ## Fixes diff --git a/models/build/edfi_3/students/bld_ef3__student__other_names.sql b/models/build/edfi_3/students/bld_ef3__student__other_names.sql new file mode 100644 index 00000000..6bd3719c --- /dev/null +++ b/models/build/edfi_3/students/bld_ef3__student__other_names.sql @@ -0,0 +1,31 @@ +{# otherName properties pulled from Ed-Fi Data Handbook (v5.0.0) +https://edfidocs.blob.core.windows.net/$web/handbook/v5.0/index.html#/OtherName82adcecf-8e39-4f24-a5a6-3c32964693c3 #} +{%- set name_type_list = ['personal_title_prefix', 'first_name', 'middle_name', 'last_surname', 'generation_code_suffix']-%} + +with stg_other_names as ( + select * from {{ ref('stg_ef3__students__other_names') }} +), +widened as ( + select + tenant_code, + api_year, + k_student, + k_student_xyear + {%- if not is_empty_model('stg_ef3__students__other_names') -%}, + {%- for name_type in name_type_list -%} + {{ ea_pivot( + column='other_name_type', + values=dbt_utils.get_column_values(ref('stg_ef3__students__other_names'),'other_name_type'), + agg='min', + suffix='_' ~ name_type, + then_value=name_type, + else_value='null', + )}} + {%- if not loop.last -%},{%- endif-%} + {%- endfor-%} + {%- endif %} + from stg_other_names + group by all + +) +select * from widened diff --git a/models/core_warehouse/dim_student.sql b/models/core_warehouse/dim_student.sql index 510244f3..001fed20 100644 --- a/models/core_warehouse/dim_student.sql +++ b/models/core_warehouse/dim_student.sql @@ -24,7 +24,8 @@ {% set custom_homeless_program_agg_indicators = var('edu:homeless:custom_program_agg_indicators', None) %} {% set custom_language_instruction_program_agg_indicators = var('edu:language_instruction:custom_program_agg_indicators', None) %} {% set custom_title_i_program_agg_indicators = var('edu:title_i:custom_program_agg_indicators', None) %} - +{% set other_name_types = var('edu:stu_demos:other_names', None) %} +{%- set name_type_list = ['personal_title_prefix', 'first_name', 'middle_name', 'last_surname', 'generation_code_suffix']-%} with stg_student as ( select * from {{ ref('stg_ef3__students') }} @@ -53,6 +54,9 @@ stu_grade as ( stu_cohort_year as ( select * from {{ ref('bld_ef3__student_cohort_years')}} ), +stu_other_names as ( + select * from {{ ref('bld_ef3__student__other_names') }} +), -- student programs {% if var('src:program:special_ed:enabled', True) %} @@ -191,6 +195,14 @@ formatted as ( {%- endfor -%} {%- endif %} + -- other name types + {% if other_name_types is not none and other_name_types | length -%} + {%- for type in other_name_types -%} + {%- for name_type in name_type_list -%} + stu_other_names.{{dbt_utils.slugify(type)}}_{{name_type}}, + {%- endfor -%} + {%- endfor -%} + {%- endif -%} -- add indicator of most recent demographic entry stg_student.api_year = max(stg_student.api_year) over(partition by stg_student.k_student_xyear) as is_latest_record, @@ -222,6 +234,8 @@ formatted as ( and stg_student.api_year = stu_grade.school_year left join stu_cohort_year on stu_demos.k_student = stu_cohort_year.k_student + left join stu_other_names + on stu_demos.k_student = stu_other_names.k_student -- student programs {% if var('src:program:special_ed:enabled', True) %}