def get_orgs_to_process(all_orgs, existing_orgs):
    """Extracts organisations and addresses, flattens addresses and returns just records
    that have not prevously been processed.

    Args:
        all_orgs(:obj:`list` of :obj:`tuple`): organisation id and addresses
        existing_orgs(:obj:`list` of :obj:`tuple`): organisation ids

    Returns:
        (:obj: `list` of :obj:`dict`): organisations to process
    """
    # convert list of 1-tuples to a set
    existing_ids = {org_id for (org_id,) in existing_orgs}

    orgs_to_process = []
    for org in all_orgs:
        org_id, address = org

        if org_id not in existing_ids:
            org_details = {'id': org_id}
            if address is not None:
                org_details = {**address['address'], **org_details}  # address also contains an 'id' which we overwrite with the id in org_details

            orgs_to_process.append(org_details)

    return orgs_to_process