def cast_element_ids_to_s(hash_element_ids, elements):
    """
    Cast a hash of element ids to a string of element ids.

    :param hash_element_ids: node/relation/way ids
    :type hash_element_ids: hash

    :param elements: OSM element to search
    :type elements: array

    :returns: a string of node/relation/way ids
    :rtype: str
    """
    elements_to_s = str()
    for el in elements:
        if len(hash_element_ids[el]) > 0:
            el_to_s = '{}(id:{});'.format(
                el,
                ','.join(str(element)
                         for element in hash_element_ids[el]))
            elements_to_s += el_to_s
    return elements_to_s