def METHOD_NAME(codes, coding_system, csv_data_codes_to_terms=None):
    csv_data_codes_to_terms = csv_data_codes_to_terms or {}
    code_to_term = coding_system.code_to_term(codes)
    def get_term(code):
        term = code_to_term[code]
        if term == "Unknown" and csv_data_codes_to_terms.get(code) is not None:
            term = f"[Unknown] {csv_data_codes_to_terms[code]}"
        return term
    if coding_system.id == "dmd":
        # dm+d has no hierarchy to look up, just return the codes themselves with their
        # terms
        summary = [{"code": code, "term": get_term(code)} for code in codes]
    else:
        summary = []
        hierarchy = Hierarchy.from_codes(coding_system, codes)
        ancestor_codes = hierarchy.filter_to_ultimate_ancestors(codes)
        for ancestor_code in ancestor_codes:
            descendants = sorted(
                (
                    {"code": code, "term": get_term(code)}
                    for code in (
                        hierarchy.descendants(ancestor_code) & codes - {ancestor_code}
                    )
                ),
                key=lambda d: d["term"],
            )
            summary.append(
                {
                    "code": ancestor_code,
                    "term": get_term(ancestor_code),
                    "descendants": descendants,
                }
            )
    summary.sort(key=lambda d: d["term"])
    return summary