Esempio n. 1
0
def _filter_query_on_degrees(degree_list: List[str],
                             query: BaseQuery) -> BaseQuery:
    regular_degree_filters = [
        degree for degree in degree_list
        if degree not in ["dmd / dds", "md / do"]
    ]

    # TODO replace this with alias tags
    md_do_filter = ([
        func.bool_or(func.lower(DegreeOption.value) == "md")
        | func.bool_or(func.lower(DegreeOption.value) == "do")
    ] if "md / do" in degree_list else [])

    dmd_dds_filter = ([
        func.bool_or(func.lower(DegreeOption.value) == "dmd")
        | func.bool_or(func.lower(DegreeOption.value) == "dds")
    ] if "dmd / dds" in degree_list else [])

    degree_filters = ([
        func.bool_or(func.lower(DegreeOption.value) == degree)
        for degree in regular_degree_filters
    ] + md_do_filter + dmd_dds_filter)

    degree_filter = reduce(operator.and_, degree_filters)
    return (
        query.outerjoin(FacultyProfileDegree).outerjoin(DegreeOption).group_by(
            FacultyProfile.id).having(degree_filter))
Esempio n. 2
0
def _filter_faculty_query_on_affiliations(affiliation_list: List[str],
                                          query: BaseQuery) -> BaseQuery:
    affiliations_filters = reduce(
        operator.and_,
        [
            func.bool_or(
                func.lower(HospitalAffiliationOption.value) == affilation)
            for affilation in affiliation_list
        ],
    )

    return (query.outerjoin(
        FacultyHospitalAffiliation,
        FacultyProfile.id == FacultyHospitalAffiliation.profile_id,
    ).outerjoin(HospitalAffiliationOption).group_by(
        FacultyProfile.id).having(affiliations_filters))