CREATE OR REPLACE VIEW view_search_user AS
    SELECT
        a.id,
        a.organization_id as organizationId,
        p.id AS personId,
        p.username,
        p.name,
        p.givenName,
        CASE
            WHEN p.givenName IS NOT NULL AND p.name IS NOT NULL
                AND p.givenName <> '' AND p.name <> ''
                THEN CONCAT(p.name, ' ', p.givenName)
            WHEN p.givenName IS NOT NULL AND p.givenName <> ''
                THEN p.givenName
            WHEN p.name IS NOT NULL AND p.name <> ''
                THEN p.name
            ELSE ''
        END AS fullName
    FROM
        opentalent.Access a
            INNER JOIN
        opentalent.Person p
        ON
            a.person_id = p.id
    WHERE a.adminAccess IS FALSE
      AND a.isPseudonymised IS FALSE
      AND a.newAccess IS FALSE;

