def __retrieve_all_contact_reservation_by_id(message):
        from gooutsafe.dao.reservation_manager import ReservationManager
        reservations = ReservationManager.retrieve_all_contact_reservation_by_id(
            message['customer_id'])
        reservations = [
            reservation.serialize() for reservation in reservations
        ]

        return reservations
def notify_customers_about_positive_contact_task(customer_id):
    reservations = ReservationManager.retrieve_by_customer_id_in_last_14_days(
        customer_id)
    for reservation in reservations:
        contact_reservations = ReservationManager.retrieve_all_contact_reservation_by_id(
            reservation.id)
        for contact_reservation in contact_reservations:
            restaurant = contact_reservation.restaurant
            notification = Notification(contact_reservation.user_id,
                                        customer_id, restaurant.id,
                                        reservation.start_time)
            NotificationManager.create_notification(notification=notification)
def contact_tracing(contact_id):
    """This method allows the health authority to retrieve the list of
    contacts, given a positive user

    Args:
        contact_id (id): univocal id of the user

    Returns:
        Redirects the view to the health authority's home page
    """
    if current_user is not None and current_user.type == 'authority':
        customer = CustomerManager.retrieve_by_id(id_=contact_id)
        if customer is not None:
            pos_reservations = ReservationManager.retrieve_by_customer_id(
                user_id=customer.id)
            cust_contacts = []
            restaurant_contacts = []
            date_contacts = []
            for res in pos_reservations:
                contacts = ReservationManager.retrieve_all_contact_reservation_by_id(
                    res.id)
                for c in contacts:
                    cust = CustomerManager.retrieve_by_id(c.user_id)
                    cust_contacts.append(cust)
                    restaurant_contacts.append(
                        RestaurantManager.retrieve_by_id(c.restaurant_id).name)
                    date_contacts.append(c.start_time.date())
            return render_template('contact_tracing_positive.html',
                                   customer=customer,
                                   pos_contact=cust_contacts,
                                   res_contact=restaurant_contacts,
                                   date_contact=date_contacts)
        else:
            return redirect(
                url_for('auth.authority', id=current_user.id, positive_id=0))
    else:
        return redirect(url_for('home.index'))