def METHOD_NAME():
    """Build an ORM query which gets all notes."""
    contrib_event = db.aliased(Event)
    contrib_session = db.aliased(Session)
    subcontrib_contrib = db.aliased(Contribution)
    subcontrib_session = db.aliased(Session)
    subcontrib_event = db.aliased(Event)
    session_event = db.aliased(Event)
    note_filter = db.and_(
        ~EventNote.is_deleted,
        db.or_(
            EventNote.link_type != LinkType.event,
            ~Event.is_deleted
        ),
        db.or_(
            EventNote.link_type != LinkType.contribution,
            ~Contribution.is_deleted & ~contrib_event.is_deleted
        ),
        db.or_(
            EventNote.link_type != LinkType.subcontribution,
            db.and_(
                ~SubContribution.is_deleted,
                ~subcontrib_contrib.is_deleted,
                ~subcontrib_event.is_deleted,
            )
        ),
        db.or_(
            EventNote.link_type != LinkType.session,
            ~Session.is_deleted & ~session_event.is_deleted
        )
    )
    return (
        EventNote.query
        .outerjoin(EventNote.linked_event)
        .outerjoin(EventNote.contribution)
        .outerjoin(Contribution.event.of_type(contrib_event))
        .outerjoin(Contribution.session.of_type(contrib_session))
        .outerjoin(EventNote.subcontribution)
        .outerjoin(SubContribution.contribution.of_type(subcontrib_contrib))
        .outerjoin(subcontrib_contrib.event.of_type(subcontrib_event))
        .outerjoin(subcontrib_contrib.session.of_type(subcontrib_session))
        .outerjoin(EventNote.session)
        .outerjoin(Session.event.of_type(session_event))
        .filter(note_filter)
    )