from typing import List


def process_reverse_chain_params(resource: str, reverse_chains: List[dict]) -> str:
    """
    Creates a query string based on the given reverse chain parameters for the queried resource (querying based on
    other resources that refer to the resource.
    :param resource: the main resource on which to query references
    :param reverse_chains: list of reverse chain resources and parameters
    :return: query string to use in fhir search
    """

    resource_prop = resource.lower()
    reverse_chain_string = ""
    # add all the resources given as reverse chain parameters to the query url
    for i, chain_resource in enumerate(reverse_chains):
        reverse_chain_string += f"_has:{chain_resource['resource']}:{resource_prop}:{chain_resource['property']}="

        # Check if there are multiple conditions given and if so join them with commas
        if isinstance(chain_resource["params"], list):
            reverse_chain_string += ",".join(chain_resource["params"])
        else:
            reverse_chain_string += chain_resource["params"]

        if i < len(reverse_chains) - 1:
            reverse_chain_string += "&"
    return reverse_chain_string