diff --git a/backend/audit/intakelib/transforms/runners.py b/backend/audit/intakelib/transforms/runners.py index c69983a420..32441ffb25 100644 --- a/backend/audit/intakelib/transforms/runners.py +++ b/backend/audit/intakelib/transforms/runners.py @@ -38,6 +38,7 @@ rename_additional_notes_sheet_to_form_sheet, ) +from .xform_add_transform_for_cfda_key import generate_cfda_keys from .xform_uniform_cluster_names import regenerate_uniform_cluster_names from .xform_reformat_prior_references import reformat_prior_references @@ -103,6 +104,7 @@ def run_all_secondary_auditors_transforms(ir): convert_number_of_findings_to_integers, convert_loan_balance_to_integers_or_na, regenerate_uniform_cluster_names, + generate_cfda_keys, ] audit_findings_transforms = general_transforms + [ diff --git a/backend/audit/intakelib/transforms/xform_add_transform_for_cfda_key.py b/backend/audit/intakelib/transforms/xform_add_transform_for_cfda_key.py new file mode 100644 index 0000000000..1439aaa7fd --- /dev/null +++ b/backend/audit/intakelib/transforms/xform_add_transform_for_cfda_key.py @@ -0,0 +1,21 @@ +import logging +from audit.intakelib.intermediate_representation import ( + get_range_by_name, + replace_range_by_name, +) + +logger = logging.getLogger(__name__) + + +def generate_cfda_keys(ir): + cfda_keys = [] + federal_agency_prefixes = get_range_by_name(ir, "federal_agency_prefix") + three_digit_extensions = get_range_by_name(ir, "three_digit_extension") + for prefix, extension in zip( + federal_agency_prefixes["values"], three_digit_extensions["values"] + ): + cfda_keys.append(f"{prefix}.{extension}" if prefix and extension else "") + + xform_ir = replace_range_by_name(ir, "cfda_key", cfda_keys) + + return xform_ir