-- Name: i_xdat_newsentry(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_newsentry(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:newsEntry)(';
      FOR current_row IN SELECT * FROM xdat_newsEntry WHERE  xdat_newsentry_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.date IS NOT NULL) THEN 
              fullText := fullText || '(date:dateTime)=(' || current_row.date || ')';
          END IF;
          IF (current_row.title IS NOT NULL) THEN 
              fullText := fullText || '(title:string)=(' || REPLACE(REPLACE(current_row.title,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.link IS NOT NULL) THEN 
              fullText := fullText || '(link:string)=(' || REPLACE(REPLACE(current_row.link,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.newsEntry_info IS NOT NULL)) THEN
            fullText := fullText || '(newsentry_info:integer)=(' || current_row.newsentry_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_newsEntry_meta_data(current_row.newsEntry_info, child_count,$3,false,false);
              fullText := fullText || '(newsentry_info_newsentry_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_newsentry_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_newsentry_id:integer)=(' || current_row.xdat_newsentry_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_newsentry(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_newsentry_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_newsentry_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:newsEntry_history)(';
      FOR current_row IN SELECT * FROM xdat_newsEntry_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.date IS NOT NULL) THEN 
              fullText := fullText || '(date:dateTime)=(' || current_row.date || ')';
          END IF;
          IF (current_row.title IS NOT NULL) THEN 
              fullText := fullText || '(title:string)=(' || REPLACE(REPLACE(current_row.title,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.link IS NOT NULL) THEN 
              fullText := fullText || '(link:string)=(' || REPLACE(REPLACE(current_row.link,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.newsEntry_info IS NOT NULL)) THEN
            fullText := fullText || '(newsentry_info:integer)=(' || current_row.newsentry_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_newsEntry_meta_data(current_row.newsEntry_info, child_count,$3,false,false);
              fullText := fullText || '(newsentry_info_newsentry_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_newsentry_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_newsentry_id:integer)=(' || current_row.xdat_newsentry_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_newsentry_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_newsentry_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_newsentry_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:newsEntry_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_newsEntry_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_newsentry_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_primary_security_field(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_primary_security_field(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:primary_security_field)(';
      FOR current_row IN SELECT * FROM xdat_primary_security_field WHERE  xdat_primary_security_field_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.primary_security_field IS NOT NULL) THEN 
              fullText := fullText || '(primary_security_field:string)=(' || REPLACE(REPLACE(current_row.primary_security_field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.primary_security_field_info IS NOT NULL)) THEN
            fullText := fullText || '(primary_security_field_info:integer)=(' || current_row.primary_security_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_primary_security_field_meta_data(current_row.primary_security_field_info, child_count,$3,false,false);
              fullText := fullText || '(primary_security_field_info_primary_security_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.primary_security_fields_primary_element_name IS NOT NULL)) THEN
            fullText := fullText || '(primary_security_fields_primary_element_name:string)=(' || current_row.primary_security_fields_primary_element_name || ')';
        END IF;
          IF (current_row.xdat_primary_security_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_primary_security_field_id:integer)=(' || current_row.xdat_primary_security_field_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_primary_security_field(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_primary_security_field_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_primary_security_field_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:primary_security_field_history)(';
      FOR current_row IN SELECT * FROM xdat_primary_security_field_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.primary_security_field IS NOT NULL) THEN 
              fullText := fullText || '(primary_security_field:string)=(' || REPLACE(REPLACE(current_row.primary_security_field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.primary_security_field_info IS NOT NULL)) THEN
            fullText := fullText || '(primary_security_field_info:integer)=(' || current_row.primary_security_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_primary_security_field_meta_data(current_row.primary_security_field_info, child_count,$3,false,false);
              fullText := fullText || '(primary_security_field_info_primary_security_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.primary_security_fields_primary_element_name IS NOT NULL)) THEN
            fullText := fullText || '(primary_security_fields_primary_element_name:string)=(' || current_row.primary_security_fields_primary_element_name || ')';
        END IF;
          IF (current_row.xdat_primary_security_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_primary_security_field_id:integer)=(' || current_row.xdat_primary_security_field_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_primary_security_field_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_primary_security_field_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_primary_security_field_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:primary_security_field_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_primary_security_field_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_primary_security_field_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_role_type(character varying, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_role_type(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:role_type)(';
      FOR current_row IN SELECT * FROM xdat_role_type WHERE  role_name=$1
      LOOP
           row_ct := row_ct+1;
          
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_a_xdat_action_type_allowe_xdat_role_type WHERE  xdat_role_type_role_name=current_row.role_name
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_action_type( mapping_row.xdat_action_type_action_name, child_count,$3,false,false);
              fullText := fullText || '(allowed_actions_allowed_action_action_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
          IF (current_row.role_name IS NOT NULL) THEN 
              fullText := fullText || '(role_name:string)=(' || REPLACE(REPLACE(current_row.role_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
        IF ((current_row.role_type_info IS NOT NULL)) THEN
            fullText := fullText || '(role_type_info:integer)=(' || current_row.role_type_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_role_type_meta_data(current_row.role_type_info, child_count,$3,false,false);
              fullText := fullText || '(role_type_info_role_type_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.roles_role_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(roles_role_xdat_security_xdat_security_id:integer)=(' || current_row.roles_role_xdat_security_xdat_security_id || ')';
        END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_role_type(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_role_type_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_role_type_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:role_type_history)(';
      FOR current_row IN SELECT * FROM xdat_role_type_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_a_xdat_action_type_allowe_xdat_role_type_history WHERE  xdat_role_type_role_name=current_row.role_name AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_action_type_history( mapping_row.xdat_action_type_action_name, child_count,$3,false,false);
              fullText := fullText || '(allowed_actions_allowed_action_action_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
          IF (current_row.role_name IS NOT NULL) THEN 
              fullText := fullText || '(role_name:string)=(' || REPLACE(REPLACE(current_row.role_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
        IF ((current_row.role_type_info IS NOT NULL)) THEN
            fullText := fullText || '(role_type_info:integer)=(' || current_row.role_type_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_role_type_meta_data(current_row.role_type_info, child_count,$3,false,false);
              fullText := fullText || '(role_type_info_role_type_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.roles_role_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(roles_role_xdat_security_xdat_security_id:integer)=(' || current_row.roles_role_xdat_security_xdat_security_id || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_role_type_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_role_type_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_role_type_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:role_type_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_role_type_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_role_type_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_search(character varying, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_search(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:Search)(';
      FOR current_row IN SELECT * FROM xdat_Search WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xdat_stored_search(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(stored_search_stored_search:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.page IS NOT NULL) THEN 
              fullText := fullText || '(page:integer)=(' || current_row.page || ')';
          END IF;
        IF ((current_row.Search_info IS NOT NULL)) THEN
            fullText := fullText || '(search_info:integer)=(' || current_row.search_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_Search_meta_data(current_row.Search_info, child_count,$3,false,false);
              fullText := fullText || '(search_info_search_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xdat_stored_search( $1, child_count,$3,$4,false);
              fullText := fullText || '(stored_search_stored_search:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_search(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_search_field(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_search_field(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:search_field)(';
      FOR current_row IN SELECT * FROM xdat_search_field WHERE  xdat_search_field_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.element_name IS NOT NULL) THEN 
              fullText := fullText || '(element_name:string)=(' || REPLACE(REPLACE(current_row.element_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.field_id IS NOT NULL) THEN 
              fullText := fullText || '(field_id:string)=(' || REPLACE(REPLACE(current_row.field_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.header IS NOT NULL) THEN 
              fullText := fullText || '(header:string)=(' || REPLACE(REPLACE(current_row.header,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visible IS NOT NULL) THEN 
              fullText := fullText || '(visible:integer)=(' || current_row.visible || ')';
          END IF;
        IF ((current_row.search_field_info IS NOT NULL)) THEN
            fullText := fullText || '(search_field_info:integer)=(' || current_row.search_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_search_field_meta_data(current_row.search_field_info, child_count,$3,false,false);
              fullText := fullText || '(search_field_info_search_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_stored_search_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_stored_search_id:string)=(' || current_row.xdat_stored_search_id || ')';
        END IF;
          IF (current_row.xdat_search_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_search_field_id:integer)=(' || current_row.xdat_search_field_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_search_field(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_search_field_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_search_field_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:search_field_history)(';
      FOR current_row IN SELECT * FROM xdat_search_field_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.element_name IS NOT NULL) THEN 
              fullText := fullText || '(element_name:string)=(' || REPLACE(REPLACE(current_row.element_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.field_id IS NOT NULL) THEN 
              fullText := fullText || '(field_id:string)=(' || REPLACE(REPLACE(current_row.field_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.header IS NOT NULL) THEN 
              fullText := fullText || '(header:string)=(' || REPLACE(REPLACE(current_row.header,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visible IS NOT NULL) THEN 
              fullText := fullText || '(visible:integer)=(' || current_row.visible || ')';
          END IF;
        IF ((current_row.search_field_info IS NOT NULL)) THEN
            fullText := fullText || '(search_field_info:integer)=(' || current_row.search_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_search_field_meta_data(current_row.search_field_info, child_count,$3,false,false);
              fullText := fullText || '(search_field_info_search_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_stored_search_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_stored_search_id:string)=(' || current_row.xdat_stored_search_id || ')';
        END IF;
          IF (current_row.xdat_search_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_search_field_id:integer)=(' || current_row.xdat_search_field_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_search_field_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_search_field_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_search_field_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:search_field_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_search_field_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_search_field_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_search_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_search_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:Search_history)(';
      FOR current_row IN SELECT * FROM xdat_Search_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xdat_stored_search_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xdat_stored_search_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(stored_search_stored_search:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.page IS NOT NULL) THEN 
              fullText := fullText || '(page:integer)=(' || current_row.page || ')';
          END IF;
        IF ((current_row.Search_info IS NOT NULL)) THEN
            fullText := fullText || '(search_info:integer)=(' || current_row.search_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_Search_meta_data(current_row.Search_info, child_count,$3,false,false);
              fullText := fullText || '(search_info_search_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xdat_stored_search_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(stored_search_stored_search:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_search_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_search_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_search_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:Search_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_Search_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_search_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_security(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_security(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:security)(';
      FOR current_row IN SELECT * FROM xdat_security WHERE  xdat_security_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_userGroup WHERE groups_group_xdat_security_xdat_security_id=current_row.xdat_security_id ORDER BY xdat_usergroup_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_userGroup( parent_row.xdat_usergroup_id, child_count,$3,false,false);
              fullText := fullText || '(groups_group_usergroup' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_user WHERE users_user_xdat_security_xdat_security_id=current_row.xdat_security_id ORDER BY xdat_user_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user( parent_row.xdat_user_id, child_count,$3,false,false);
              fullText := fullText || '(users_user_user' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_role_type WHERE roles_role_xdat_security_xdat_security_id=current_row.xdat_security_id ORDER BY role_name
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_role_type( parent_row.role_name, child_count,$3,false,false);
              fullText := fullText || '(roles_role_role_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_action_type WHERE actions_action_xdat_security_xdat_security_id=current_row.xdat_security_id ORDER BY action_name
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_action_type( parent_row.action_name, child_count,$3,false,false);
              fullText := fullText || '(actions_action_action_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_security WHERE element_security_set_element_se_xdat_security_id=current_row.xdat_security_id ORDER BY element_name
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security( parent_row.element_name, child_count,$3,false,false);
              fullText := fullText || '(element_security_set_element_security_element_security' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.newslist_news_xdat_newsentry_id IS NOT NULL)) THEN
            fullText := fullText || '(newslist_news_xdat_newsentry_id:integer)=(' || current_row.newslist_news_xdat_newsentry_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_newsEntry(current_row.newslist_news_xdat_newsentry_id, child_count,$3,false,false);
              fullText := fullText || '(newslist_news_newsentry:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.infolist_info_xdat_infoentry_id IS NOT NULL)) THEN
            fullText := fullText || '(infolist_info_xdat_infoentry_id:integer)=(' || current_row.infolist_info_xdat_infoentry_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_infoEntry(current_row.infolist_info_xdat_infoentry_id, child_count,$3,false,false);
              fullText := fullText || '(infolist_info_infoentry:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.system IS NOT NULL) THEN 
              fullText := fullText || '(system:string)=(' || REPLACE(REPLACE(current_row.system,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.require_login IS NOT NULL) THEN 
              fullText := fullText || '(require_login:integer)=(' || current_row.require_login || ')';
          END IF;
        IF ((current_row.security_info IS NOT NULL)) THEN
            fullText := fullText || '(security_info:integer)=(' || current_row.security_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_security_meta_data(current_row.security_info, child_count,$3,false,false);
              fullText := fullText || '(security_info_security_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_security_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_security_id:integer)=(' || current_row.xdat_security_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_security(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_security_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_security_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:security_history)(';
      FOR current_row IN SELECT * FROM xdat_security_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_userGroup_history WHERE groups_group_xdat_security_xdat_security_id=current_row.xdat_security_id AND xft_version=current_row.xft_version ORDER BY xdat_usergroup_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_userGroup_history( parent_row.xdat_usergroup_id, child_count,$3,false,false);
              fullText := fullText || '(groups_group_usergroup' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_user_history WHERE users_user_xdat_security_xdat_security_id=current_row.xdat_security_id AND xft_version=current_row.xft_version ORDER BY xdat_user_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_history( parent_row.xdat_user_id, child_count,$3,false,false);
              fullText := fullText || '(users_user_user' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_role_type_history WHERE roles_role_xdat_security_xdat_security_id=current_row.xdat_security_id AND xft_version=current_row.xft_version ORDER BY role_name
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_role_type_history( parent_row.role_name, child_count,$3,false,false);
              fullText := fullText || '(roles_role_role_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_action_type_history WHERE actions_action_xdat_security_xdat_security_id=current_row.xdat_security_id AND xft_version=current_row.xft_version ORDER BY action_name
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_action_type_history( parent_row.action_name, child_count,$3,false,false);
              fullText := fullText || '(actions_action_action_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_security_history WHERE element_security_set_element_se_xdat_security_id=current_row.xdat_security_id AND xft_version=current_row.xft_version ORDER BY element_name
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security_history( parent_row.element_name, child_count,$3,false,false);
              fullText := fullText || '(element_security_set_element_security_element_security' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.newslist_news_xdat_newsentry_id IS NOT NULL)) THEN
            fullText := fullText || '(newslist_news_xdat_newsentry_id:integer)=(' || current_row.newslist_news_xdat_newsentry_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xdat_newsEntry_history WHERE  xdat_newsentry_id=current_row.newslist_news_xdat_newsentry_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_newsEntry_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(newslist_news_newsentry:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF ((current_row.infolist_info_xdat_infoentry_id IS NOT NULL)) THEN
            fullText := fullText || '(infolist_info_xdat_infoentry_id:integer)=(' || current_row.infolist_info_xdat_infoentry_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xdat_infoEntry_history WHERE  xdat_infoentry_id=current_row.infolist_info_xdat_infoentry_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_infoEntry_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(infolist_info_infoentry:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.system IS NOT NULL) THEN 
              fullText := fullText || '(system:string)=(' || REPLACE(REPLACE(current_row.system,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.require_login IS NOT NULL) THEN 
              fullText := fullText || '(require_login:integer)=(' || current_row.require_login || ')';
          END IF;
        IF ((current_row.security_info IS NOT NULL)) THEN
            fullText := fullText || '(security_info:integer)=(' || current_row.security_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_security_meta_data(current_row.security_info, child_count,$3,false,false);
              fullText := fullText || '(security_info_security_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_security_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_security_id:integer)=(' || current_row.xdat_security_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_security_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_security_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_security_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:security_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_security_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_security_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search(character varying, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xdat_stored_search.id AS xdat_stored_search3, table1.element_name AS xdat_meta_element103, table2.insert_date AS xdat_stored_search_meta_data110 FROM xdat_stored_search xdat_stored_search   LEFT JOIN xdat_meta_element table1 ON xdat_stored_search.extension=table1.xdat_meta_element_id   LEFT JOIN xdat_stored_search_meta_data table2 ON xdat_stored_search.stored_search_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xdat_stored_search3=$1))
      LOOP
         IF (current_row.xdat_meta_element103 IS NULL) THEN 
             fullText:= ie_xdat_stored_search( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element103='xdat:Search') THEN
                fullText:= i_xdat_Search( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xdat_stored_search( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_allowed_user(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_allowed_user(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_allowed_user)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_allowed_user WHERE  xdat_stored_search_allowed_user_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.login IS NOT NULL) THEN 
              fullText := fullText || '(login:string)=(' || REPLACE(REPLACE(current_row.login,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.stored_search_allowed_user_info IS NOT NULL)) THEN
            fullText := fullText || '(stored_search_allowed_user_info:integer)=(' || current_row.stored_search_allowed_user_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_allowed_user_meta_data(current_row.stored_search_allowed_user_info, child_count,$3,false,false);
              fullText := fullText || '(stored_search_allowed_user_info_stored_search_allowed_user_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_stored_search_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_stored_search_id:string)=(' || current_row.xdat_stored_search_id || ')';
        END IF;
          IF (current_row.xdat_stored_search_allowed_user_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_stored_search_allowed_user_id:integer)=(' || current_row.xdat_stored_search_allowed_user_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_allowed_user(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_allowed_user_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_allowed_user_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_allowed_user_history)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_allowed_user_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.login IS NOT NULL) THEN 
              fullText := fullText || '(login:string)=(' || REPLACE(REPLACE(current_row.login,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.stored_search_allowed_user_info IS NOT NULL)) THEN
            fullText := fullText || '(stored_search_allowed_user_info:integer)=(' || current_row.stored_search_allowed_user_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_allowed_user_meta_data(current_row.stored_search_allowed_user_info, child_count,$3,false,false);
              fullText := fullText || '(stored_search_allowed_user_info_stored_search_allowed_user_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_stored_search_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_stored_search_id:string)=(' || current_row.xdat_stored_search_id || ')';
        END IF;
          IF (current_row.xdat_stored_search_allowed_user_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_stored_search_allowed_user_id:integer)=(' || current_row.xdat_stored_search_allowed_user_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_allowed_user_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_allowed_user_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_allowed_user_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_allowed_user_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_allowed_user_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_allowed_user_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_groupid(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_groupid(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_groupID)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_groupID WHERE  xdat_stored_search_groupid_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.groupid IS NOT NULL) THEN 
              fullText := fullText || '(groupid:string)=(' || REPLACE(REPLACE(current_row.groupid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.stored_search_groupID_info IS NOT NULL)) THEN
            fullText := fullText || '(stored_search_groupid_info:integer)=(' || current_row.stored_search_groupid_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_groupID_meta_data(current_row.stored_search_groupID_info, child_count,$3,false,false);
              fullText := fullText || '(stored_search_groupid_info_stored_search_groupid_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.allowed_groups_groupid_xdat_sto_id IS NOT NULL)) THEN
            fullText := fullText || '(allowed_groups_groupid_xdat_sto_id:string)=(' || current_row.allowed_groups_groupid_xdat_sto_id || ')';
        END IF;
          IF (current_row.xdat_stored_search_groupid_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_stored_search_groupid_id:integer)=(' || current_row.xdat_stored_search_groupid_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_groupid(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_groupid_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_groupid_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_groupID_history)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_groupID_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.groupid IS NOT NULL) THEN 
              fullText := fullText || '(groupid:string)=(' || REPLACE(REPLACE(current_row.groupid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.stored_search_groupID_info IS NOT NULL)) THEN
            fullText := fullText || '(stored_search_groupid_info:integer)=(' || current_row.stored_search_groupid_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_groupID_meta_data(current_row.stored_search_groupID_info, child_count,$3,false,false);
              fullText := fullText || '(stored_search_groupid_info_stored_search_groupid_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.allowed_groups_groupid_xdat_sto_id IS NOT NULL)) THEN
            fullText := fullText || '(allowed_groups_groupid_xdat_sto_id:string)=(' || current_row.allowed_groups_groupid_xdat_sto_id || ')';
        END IF;
          IF (current_row.xdat_stored_search_groupid_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_stored_search_groupid_id:integer)=(' || current_row.xdat_stored_search_groupid_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_groupid_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_groupid_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_groupid_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_groupID_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_groupID_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_groupid_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xdat_stored_search_history.history_id AS xdat_stored_search_history7, table1.element_name AS xdat_meta_element18, xdat_stored_search_history.xft_version AS xdat_stored_search_history_xft_version, xdat_stored_search_history.id AS xdat_stored_search_history6 FROM xdat_stored_search_history xdat_stored_search_history   LEFT JOIN xdat_meta_element table1 ON xdat_stored_search_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xdat_stored_search_history7=$1))
      LOOP
         IF (current_row.xdat_meta_element18 IS NULL) THEN 
             fullText:= ie_xdat_stored_search( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element18='xdat:Search') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xdat_Search_history WHERE id=current_row.xdat_stored_search_history6 AND xft_version=current_row.xdat_stored_search_history_xft_version
           	LOOP
                fullText:= i_xdat_Search_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xdat_stored_search_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_stored_search_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_stored_search_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_stored_search_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user)(';
      FOR current_row IN SELECT * FROM xdat_user WHERE  xdat_user_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.login IS NOT NULL) THEN 
              fullText := fullText || '(login:string)=(' || REPLACE(REPLACE(current_row.login,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.firstname IS NOT NULL) THEN 
              fullText := fullText || '(firstname:string)=(' || REPLACE(REPLACE(current_row.firstname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.lastname IS NOT NULL) THEN 
              fullText := fullText || '(lastname:string)=(' || REPLACE(REPLACE(current_row.lastname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.email IS NOT NULL) THEN 
              fullText := fullText || '(email:string)=(' || REPLACE(REPLACE(current_row.email,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.primary_password IS NOT NULL) THEN 
              fullText := fullText || '(primary_password:string)=(' || REPLACE(REPLACE(current_row.primary_password,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.primary_password_encrypt IS NOT NULL) THEN 
              fullText := fullText || '(primary_password_encrypt:integer)=(' || current_row.primary_password_encrypt || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_access WHERE xdat_user_xdat_user_id=current_row.xdat_user_id ORDER BY xdat_element_access_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access( parent_row.xdat_element_access_id, child_count,$3,false,false);
              fullText := fullText || '(element_access_element_access' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_r_xdat_role_type_assign_xdat_user WHERE  xdat_user_xdat_user_id=current_row.xdat_user_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_role_type( mapping_row.xdat_role_type_role_name, child_count,$3,false,false);
              fullText := fullText || '(assigned_roles_assigned_role_role_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
          IF (current_row.quarantine_path IS NOT NULL) THEN 
              fullText := fullText || '(quarantine_path:string)=(' || REPLACE(REPLACE(current_row.quarantine_path,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_user_groupID WHERE groups_groupid_xdat_user_xdat_user_id=current_row.xdat_user_id ORDER BY xdat_user_groupid_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_groupID( parent_row.xdat_user_groupid_id, child_count,$3,false,false);
              fullText := fullText || '(groups_groupid_user_groupid' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.enabled IS NOT NULL) THEN 
              fullText := fullText || '(enabled:integer)=(' || current_row.enabled || ')';
          END IF;
          IF (current_row.verified IS NOT NULL) THEN 
              fullText := fullText || '(verified:integer)=(' || current_row.verified || ')';
          END IF;
          IF (current_row.salt IS NOT NULL) THEN 
              fullText := fullText || '(salt:string)=(' || REPLACE(REPLACE(current_row.salt,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.user_info IS NOT NULL)) THEN
            fullText := fullText || '(user_info:integer)=(' || current_row.user_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_meta_data(current_row.user_info, child_count,$3,false,false);
              fullText := fullText || '(user_info_user_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.users_user_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(users_user_xdat_security_xdat_security_id:integer)=(' || current_row.users_user_xdat_security_xdat_security_id || ')';
        END IF;
          IF (current_row.xdat_user_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_user_id:integer)=(' || current_row.xdat_user_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_groupid(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_groupid(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_groupID)(';
      FOR current_row IN SELECT * FROM xdat_user_groupID WHERE  xdat_user_groupid_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.groupid IS NOT NULL) THEN 
              fullText := fullText || '(groupid:string)=(' || REPLACE(REPLACE(current_row.groupid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.user_groupID_info IS NOT NULL)) THEN
            fullText := fullText || '(user_groupid_info:integer)=(' || current_row.user_groupid_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_groupID_meta_data(current_row.user_groupID_info, child_count,$3,false,false);
              fullText := fullText || '(user_groupid_info_user_groupid_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.groups_groupid_xdat_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(groups_groupid_xdat_user_xdat_user_id:integer)=(' || current_row.groups_groupid_xdat_user_xdat_user_id || ')';
        END IF;
          IF (current_row.xdat_user_groupid_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_user_groupid_id:integer)=(' || current_row.xdat_user_groupid_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_groupid(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_groupid_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_groupid_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_groupID_history)(';
      FOR current_row IN SELECT * FROM xdat_user_groupID_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.groupid IS NOT NULL) THEN 
              fullText := fullText || '(groupid:string)=(' || REPLACE(REPLACE(current_row.groupid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.user_groupID_info IS NOT NULL)) THEN
            fullText := fullText || '(user_groupid_info:integer)=(' || current_row.user_groupid_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_groupID_meta_data(current_row.user_groupID_info, child_count,$3,false,false);
              fullText := fullText || '(user_groupid_info_user_groupid_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.groups_groupid_xdat_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(groups_groupid_xdat_user_xdat_user_id:integer)=(' || current_row.groups_groupid_xdat_user_xdat_user_id || ')';
        END IF;
          IF (current_row.xdat_user_groupid_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_user_groupid_id:integer)=(' || current_row.xdat_user_groupid_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_groupid_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_groupid_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_groupid_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_groupID_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_user_groupID_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_groupid_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_history)(';
      FOR current_row IN SELECT * FROM xdat_user_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.login IS NOT NULL) THEN 
              fullText := fullText || '(login:string)=(' || REPLACE(REPLACE(current_row.login,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.firstname IS NOT NULL) THEN 
              fullText := fullText || '(firstname:string)=(' || REPLACE(REPLACE(current_row.firstname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.lastname IS NOT NULL) THEN 
              fullText := fullText || '(lastname:string)=(' || REPLACE(REPLACE(current_row.lastname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.email IS NOT NULL) THEN 
              fullText := fullText || '(email:string)=(' || REPLACE(REPLACE(current_row.email,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.primary_password IS NOT NULL) THEN 
              fullText := fullText || '(primary_password:string)=(' || REPLACE(REPLACE(current_row.primary_password,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.primary_password_encrypt IS NOT NULL) THEN 
              fullText := fullText || '(primary_password_encrypt:integer)=(' || current_row.primary_password_encrypt || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_access_history WHERE xdat_user_xdat_user_id=current_row.xdat_user_id AND xft_version=current_row.xft_version ORDER BY xdat_element_access_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_history( parent_row.xdat_element_access_id, child_count,$3,false,false);
              fullText := fullText || '(element_access_element_access' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_r_xdat_role_type_assign_xdat_user_history WHERE  xdat_user_xdat_user_id=current_row.xdat_user_id AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_role_type_history( mapping_row.xdat_role_type_role_name, child_count,$3,false,false);
              fullText := fullText || '(assigned_roles_assigned_role_role_type' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
          IF (current_row.quarantine_path IS NOT NULL) THEN 
              fullText := fullText || '(quarantine_path:string)=(' || REPLACE(REPLACE(current_row.quarantine_path,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_user_groupID_history WHERE groups_groupid_xdat_user_xdat_user_id=current_row.xdat_user_id AND xft_version=current_row.xft_version ORDER BY xdat_user_groupid_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_groupID_history( parent_row.xdat_user_groupid_id, child_count,$3,false,false);
              fullText := fullText || '(groups_groupid_user_groupid' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.enabled IS NOT NULL) THEN 
              fullText := fullText || '(enabled:integer)=(' || current_row.enabled || ')';
          END IF;
          IF (current_row.verified IS NOT NULL) THEN 
              fullText := fullText || '(verified:integer)=(' || current_row.verified || ')';
          END IF;
          IF (current_row.salt IS NOT NULL) THEN 
              fullText := fullText || '(salt:string)=(' || REPLACE(REPLACE(current_row.salt,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.user_info IS NOT NULL)) THEN
            fullText := fullText || '(user_info:integer)=(' || current_row.user_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_meta_data(current_row.user_info, child_count,$3,false,false);
              fullText := fullText || '(user_info_user_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.users_user_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(users_user_xdat_security_xdat_security_id:integer)=(' || current_row.users_user_xdat_security_xdat_security_id || ')';
        END IF;
          IF (current_row.xdat_user_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_user_id:integer)=(' || current_row.xdat_user_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_login(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_login(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_login)(';
      FOR current_row IN SELECT * FROM xdat_user_login WHERE  xdat_user_login_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.login_date IS NOT NULL) THEN 
              fullText := fullText || '(login_date:dateTime)=(' || current_row.login_date || ')';
          END IF;
          IF (current_row.logout_date IS NOT NULL) THEN 
              fullText := fullText || '(logout_date:dateTime)=(' || current_row.logout_date || ')';
          END IF;
          IF (current_row.session_id IS NOT NULL) THEN 
              fullText := fullText || '(session_id:string)=(' || REPLACE(REPLACE(current_row.session_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ip_address IS NOT NULL) THEN 
              fullText := fullText || '(ip_address:string)=(' || REPLACE(REPLACE(current_row.ip_address,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(user_xdat_user_id:integer)=(' || current_row.user_xdat_user_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user(current_row.user_xdat_user_id, child_count,$3,false,false);
              fullText := fullText || '(user_user:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.user_login_info IS NOT NULL)) THEN
            fullText := fullText || '(user_login_info:integer)=(' || current_row.user_login_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_login_meta_data(current_row.user_login_info, child_count,$3,false,false);
              fullText := fullText || '(user_login_info_user_login_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_user_login_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_user_login_id:integer)=(' || current_row.xdat_user_login_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_login(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_login_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_login_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_login_history)(';
      FOR current_row IN SELECT * FROM xdat_user_login_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.login_date IS NOT NULL) THEN 
              fullText := fullText || '(login_date:dateTime)=(' || current_row.login_date || ')';
          END IF;
          IF (current_row.logout_date IS NOT NULL) THEN 
              fullText := fullText || '(logout_date:dateTime)=(' || current_row.logout_date || ')';
          END IF;
          IF (current_row.session_id IS NOT NULL) THEN 
              fullText := fullText || '(session_id:string)=(' || REPLACE(REPLACE(current_row.session_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ip_address IS NOT NULL) THEN 
              fullText := fullText || '(ip_address:string)=(' || REPLACE(REPLACE(current_row.ip_address,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(user_xdat_user_id:integer)=(' || current_row.user_xdat_user_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xdat_user_history WHERE  xdat_user_id=current_row.user_xdat_user_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(user_user:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF ((current_row.user_login_info IS NOT NULL)) THEN
            fullText := fullText || '(user_login_info:integer)=(' || current_row.user_login_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user_login_meta_data(current_row.user_login_info, child_count,$3,false,false);
              fullText := fullText || '(user_login_info_user_login_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_user_login_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_user_login_id:integer)=(' || current_row.xdat_user_login_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_login_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_login_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_login_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_login_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_user_login_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_login_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_user_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_user_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:user_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_user_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_user_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_usergroup(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_usergroup(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:userGroup)(';
      FOR current_row IN SELECT * FROM xdat_userGroup WHERE  xdat_usergroup_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_access WHERE xdat_userGroup_xdat_usergroup_id=current_row.xdat_usergroup_id ORDER BY xdat_element_access_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access( parent_row.xdat_element_access_id, child_count,$3,false,false);
              fullText := fullText || '(element_access_element_access' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.displayname IS NOT NULL) THEN 
              fullText := fullText || '(displayname:string)=(' || REPLACE(REPLACE(current_row.displayname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tag IS NOT NULL) THEN 
              fullText := fullText || '(tag:string)=(' || REPLACE(REPLACE(current_row.tag,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.userGroup_info IS NOT NULL)) THEN
            fullText := fullText || '(usergroup_info:integer)=(' || current_row.usergroup_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_userGroup_meta_data(current_row.userGroup_info, child_count,$3,false,false);
              fullText := fullText || '(usergroup_info_usergroup_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.groups_group_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(groups_group_xdat_security_xdat_security_id:integer)=(' || current_row.groups_group_xdat_security_xdat_security_id || ')';
        END IF;
          IF (current_row.xdat_usergroup_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_usergroup_id:integer)=(' || current_row.xdat_usergroup_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_usergroup(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_usergroup_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_usergroup_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:userGroup_history)(';
      FOR current_row IN SELECT * FROM xdat_userGroup_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_access_history WHERE xdat_userGroup_xdat_usergroup_id=current_row.xdat_usergroup_id AND xft_version=current_row.xft_version ORDER BY xdat_element_access_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_history( parent_row.xdat_element_access_id, child_count,$3,false,false);
              fullText := fullText || '(element_access_element_access' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.displayname IS NOT NULL) THEN 
              fullText := fullText || '(displayname:string)=(' || REPLACE(REPLACE(current_row.displayname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tag IS NOT NULL) THEN 
              fullText := fullText || '(tag:string)=(' || REPLACE(REPLACE(current_row.tag,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.userGroup_info IS NOT NULL)) THEN
            fullText := fullText || '(usergroup_info:integer)=(' || current_row.usergroup_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_userGroup_meta_data(current_row.userGroup_info, child_count,$3,false,false);
              fullText := fullText || '(usergroup_info_usergroup_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.groups_group_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(groups_group_xdat_security_xdat_security_id:integer)=(' || current_row.groups_group_xdat_security_xdat_security_id || ')';
        END IF;
          IF (current_row.xdat_usergroup_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_usergroup_id:integer)=(' || current_row.xdat_usergroup_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_usergroup_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xdat_usergroup_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xdat_usergroup_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:userGroup_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_userGroup_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xdat_usergroup_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_scidresearchdata(character varying, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_scidresearchdata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:scidResearchData)(';
      FOR current_row IN SELECT * FROM xnat_a_scidResearchData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.administrator IS NOT NULL) THEN 
              fullText := fullText || '(administrator:string)=(' || REPLACE(REPLACE(current_row.administrator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.moodepisodes_currentmajordepressiveepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentmajordepressiveepisode:integer)=(' || current_row.moodepisodes_currentmajordepressiveepisode || ')';
          END IF;
          IF (current_row.moodepisodes_pastmajordepressiveepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastmajordepressiveepisode:integer)=(' || current_row.moodepisodes_pastmajordepressiveepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currentmanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentmanicepisode:integer)=(' || current_row.moodepisodes_currentmanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_pastmanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastmanicepisode:integer)=(' || current_row.moodepisodes_pastmanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currenthypomanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currenthypomanicepisode:integer)=(' || current_row.moodepisodes_currenthypomanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_pasthypomanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pasthypomanicepisode:integer)=(' || current_row.moodepisodes_pasthypomanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currentdysthmicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentdysthmicepisode:integer)=(' || current_row.moodepisodes_currentdysthmicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currentmooddisorderduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentmooddisorderduetomedicalcondition:integer)=(' || current_row.moodepisodes_currentmooddisorderduetomedicalcondition || ')';
          END IF;
          IF (current_row.moodepisodes_pastmooddisorderduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastmooddisorderduetomedicalcondition:integer)=(' || current_row.moodepisodes_pastmooddisorderduetomedicalcondition || ')';
          END IF;
          IF (current_row.moodepisodes_currentsubstanceinducedmooddisorder IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentsubstanceinducedmooddisorder:integer)=(' || current_row.moodepisodes_currentsubstanceinducedmooddisorder || ')';
          END IF;
          IF (current_row.moodepisodes_pastsubstanceinducedmooddisorder IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastsubstanceinducedmooddisorder:integer)=(' || current_row.moodepisodes_pastsubstanceinducedmooddisorder || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentdelusions IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentdelusions:integer)=(' || current_row.psychoticsymptoms_currentdelusions || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastdelusions IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastdelusions:integer)=(' || current_row.psychoticsymptoms_pastdelusions || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currenthallucinations IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currenthallucinations:integer)=(' || current_row.psychoticsymptoms_currenthallucinations || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pasthallucinations IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pasthallucinations:integer)=(' || current_row.psychoticsymptoms_pasthallucinations || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentdisorganizedspeechbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentdisorganizedspeechbehavior:integer)=(' || current_row.psychoticsymptoms_currentdisorganizedspeechbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastdisorganizedspeechbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastdisorganizedspeechbehavior:integer)=(' || current_row.psychoticsymptoms_pastdisorganizedspeechbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentcatatonicbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentcatatonicbehavior:integer)=(' || current_row.psychoticsymptoms_currentcatatonicbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastcatatonicbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastcatatonicbehavior:integer)=(' || current_row.psychoticsymptoms_pastcatatonicbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentnegativesymptoms IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentnegativesymptoms:integer)=(' || current_row.psychoticsymptoms_currentnegativesymptoms || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastnegativesymptoms IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastnegativesymptoms:integer)=(' || current_row.psychoticsymptoms_pastnegativesymptoms || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentschizophrenia IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentschizophrenia:integer)=(' || current_row.psychoticdisorders_currentschizophrenia || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastschizophrenia IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastschizophrenia:integer)=(' || current_row.psychoticdisorders_pastschizophrenia || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentparanoidtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentparanoidtype:integer)=(' || current_row.psychoticdisorders_currentparanoidtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastparanoidtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastparanoidtype:integer)=(' || current_row.psychoticdisorders_pastparanoidtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentcatatonictype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentcatatonictype:integer)=(' || current_row.psychoticdisorders_currentcatatonictype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastcatatonictype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastcatatonictype:integer)=(' || current_row.psychoticdisorders_pastcatatonictype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentdisorganizedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentdisorganizedtype:integer)=(' || current_row.psychoticdisorders_currentdisorganizedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastdisorganizedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastdisorganizedtype:integer)=(' || current_row.psychoticdisorders_pastdisorganizedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentundifferentiatedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentundifferentiatedtype:integer)=(' || current_row.psychoticdisorders_currentundifferentiatedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastundifferentiatedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastundifferentiatedtype:integer)=(' || current_row.psychoticdisorders_pastundifferentiatedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentresidualtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentresidualtype:integer)=(' || current_row.psychoticdisorders_currentresidualtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastresidualtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastresidualtype:integer)=(' || current_row.psychoticdisorders_pastresidualtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentschizophreniformdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentschizophreniformdisorder:integer)=(' || current_row.psychoticdisorders_currentschizophreniformdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastschizophreniformdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastschizophreniformdisorder:integer)=(' || current_row.psychoticdisorders_pastschizophreniformdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentschizoaffectivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentschizoaffectivedisorder:integer)=(' || current_row.psychoticdisorders_currentschizoaffectivedisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastschizoaffectivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastschizoaffectivedisorder:integer)=(' || current_row.psychoticdisorders_pastschizoaffectivedisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentdelusionaldisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentdelusionaldisorder:integer)=(' || current_row.psychoticdisorders_currentdelusionaldisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastdelusionaldisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastdelusionaldisorder:integer)=(' || current_row.psychoticdisorders_pastdelusionaldisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentbriefpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentbriefpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_currentbriefpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastbriefpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastbriefpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_pastbriefpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentpsychoticdisorderduetomedicalconditio IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentpsychoticdisorderduetomedicalconditio:integer)=(' || current_row.psychoticdisorders_currentpsychoticdisorderduetomedicalconditio || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastpsychoticdisorderduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastpsychoticdisorderduetomedicalcondition:integer)=(' || current_row.psychoticdisorders_pastpsychoticdisorderduetomedicalcondition || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentsubstanceinducedpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentsubstanceinducedpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_currentsubstanceinducedpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastsubstanceinducedpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastsubstanceinducedpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_pastsubstanceinducedpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentpsychoticdisordernos IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentpsychoticdisordernos:integer)=(' || current_row.psychoticdisorders_currentpsychoticdisordernos || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastpsychoticdisordernos IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastpsychoticdisordernos:integer)=(' || current_row.psychoticdisorders_pastpsychoticdisordernos || ')';
          END IF;
          IF (current_row.mooddisorders_currentbipolar1disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentbipolar1disorder:integer)=(' || current_row.mooddisorders_currentbipolar1disorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastbipolar1disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastbipolar1disorder:integer)=(' || current_row.mooddisorders_pastbipolar1disorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentbipolar2disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentbipolar2disorder:integer)=(' || current_row.mooddisorders_currentbipolar2disorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastbipolar2disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastbipolar2disorder:integer)=(' || current_row.mooddisorders_pastbipolar2disorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentotherbipolardisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentotherbipolardisorder:integer)=(' || current_row.mooddisorders_currentotherbipolardisorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastotherbipolardisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastotherbipolardisorder:integer)=(' || current_row.mooddisorders_pastotherbipolardisorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentmajordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentmajordepressivedisorder:integer)=(' || current_row.mooddisorders_currentmajordepressivedisorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastmajordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastmajordepressivedisorder:integer)=(' || current_row.mooddisorders_pastmajordepressivedisorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentdepressivedisordernos IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentdepressivedisordernos:integer)=(' || current_row.mooddisorders_currentdepressivedisordernos || ')';
          END IF;
          IF (current_row.mooddisorders_pastdepressivedisordernos IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastdepressivedisordernos:integer)=(' || current_row.mooddisorders_pastdepressivedisordernos || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentalcoholdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentalcoholdependence:integer)=(' || current_row.substanceusedisorders_currentalcoholdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastalcoholdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastalcoholdependence:integer)=(' || current_row.substanceusedisorders_pastalcoholdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentalcoholabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentalcoholabuse:integer)=(' || current_row.substanceusedisorders_currentalcoholabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastalcoholabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastalcoholabuse:integer)=(' || current_row.substanceusedisorders_pastalcoholabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentamphetaminedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentamphetaminedependence:integer)=(' || current_row.substanceusedisorders_currentamphetaminedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastamphetaminedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastamphetaminedependence:integer)=(' || current_row.substanceusedisorders_pastamphetaminedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentamphetamineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentamphetamineabuse:integer)=(' || current_row.substanceusedisorders_currentamphetamineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastamphetamineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastamphetamineabuse:integer)=(' || current_row.substanceusedisorders_pastamphetamineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcannabisdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcannabisdependence:integer)=(' || current_row.substanceusedisorders_currentcannabisdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcannabisdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcannabisdependence:integer)=(' || current_row.substanceusedisorders_pastcannabisdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcannabisabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcannabisabuse:integer)=(' || current_row.substanceusedisorders_currentcannabisabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcannabisabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcannabisabuse:integer)=(' || current_row.substanceusedisorders_pastcannabisabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcocainedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcocainedependence:integer)=(' || current_row.substanceusedisorders_currentcocainedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcocainedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcocainedependence:integer)=(' || current_row.substanceusedisorders_pastcocainedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcocaineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcocaineabuse:integer)=(' || current_row.substanceusedisorders_currentcocaineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcocaineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcocaineabuse:integer)=(' || current_row.substanceusedisorders_pastcocaineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currenthallucinogendependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currenthallucinogendependence:integer)=(' || current_row.substanceusedisorders_currenthallucinogendependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pasthallucinogendependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pasthallucinogendependence:integer)=(' || current_row.substanceusedisorders_pasthallucinogendependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currenthallucinogenabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currenthallucinogenabuse:integer)=(' || current_row.substanceusedisorders_currenthallucinogenabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pasthallucinogenabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pasthallucinogenabuse:integer)=(' || current_row.substanceusedisorders_pasthallucinogenabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentopioiddependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentopioiddependence:integer)=(' || current_row.substanceusedisorders_currentopioiddependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastopioiddependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastopioiddependence:integer)=(' || current_row.substanceusedisorders_pastopioiddependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentopioidabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentopioidabuse:integer)=(' || current_row.substanceusedisorders_currentopioidabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastopioidabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastopioidabuse:integer)=(' || current_row.substanceusedisorders_pastopioidabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentphencyclidinedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentphencyclidinedependence:integer)=(' || current_row.substanceusedisorders_currentphencyclidinedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastphencyclidinedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastphencyclidinedependence:integer)=(' || current_row.substanceusedisorders_pastphencyclidinedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentphencyclidineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentphencyclidineabuse:integer)=(' || current_row.substanceusedisorders_currentphencyclidineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastphencyclidineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastphencyclidineabuse:integer)=(' || current_row.substanceusedisorders_pastphencyclidineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentsedativehypnoticanxiolyticdependen IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentsedativehypnoticanxiolyticdependen:integer)=(' || current_row.substanceusedisorders_currentsedativehypnoticanxiolyticdependen || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastsedativehypnoticanxiolyticdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastsedativehypnoticanxiolyticdependence:integer)=(' || current_row.substanceusedisorders_pastsedativehypnoticanxiolyticdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentsedativehypnoticanxiolyticabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentsedativehypnoticanxiolyticabuse:integer)=(' || current_row.substanceusedisorders_currentsedativehypnoticanxiolyticabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastsedativehypnoticanxiolyticabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastsedativehypnoticanxiolyticabuse:integer)=(' || current_row.substanceusedisorders_pastsedativehypnoticanxiolyticabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentpolysubstancedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentpolysubstancedependence:integer)=(' || current_row.substanceusedisorders_currentpolysubstancedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastpolysubstancedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastpolysubstancedependence:integer)=(' || current_row.substanceusedisorders_pastpolysubstancedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentotherorunknowndependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentotherorunknowndependence:integer)=(' || current_row.substanceusedisorders_currentotherorunknowndependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastotherorunknowndependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastotherorunknowndependence:integer)=(' || current_row.substanceusedisorders_pastotherorunknowndependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentotherorunknownabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentotherorunknownabuse:integer)=(' || current_row.substanceusedisorders_currentotherorunknownabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastotherorunknownabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastotherorunknownabuse:integer)=(' || current_row.substanceusedisorders_pastotherorunknownabuse || ')';
          END IF;
          IF (current_row.anxietydisorders_currentpanicwithagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentpanicwithagoraphobia:integer)=(' || current_row.anxietydisorders_currentpanicwithagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastpanicwithagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastpanicwithagoraphobia:integer)=(' || current_row.anxietydisorders_pastpanicwithagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentpanicwithoutagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentpanicwithoutagoraphobia:integer)=(' || current_row.anxietydisorders_currentpanicwithoutagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastpanicwithoutagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastpanicwithoutagoraphobia:integer)=(' || current_row.anxietydisorders_pastpanicwithoutagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentagoraphobiawithoutpanichx IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentagoraphobiawithoutpanichx:integer)=(' || current_row.anxietydisorders_currentagoraphobiawithoutpanichx || ')';
          END IF;
          IF (current_row.anxietydisorders_pastagoraphobiawithoutpanichx IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastagoraphobiawithoutpanichx:integer)=(' || current_row.anxietydisorders_pastagoraphobiawithoutpanichx || ')';
          END IF;
          IF (current_row.anxietydisorders_currentsocialphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentsocialphobia:integer)=(' || current_row.anxietydisorders_currentsocialphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastsocialphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastsocialphobia:integer)=(' || current_row.anxietydisorders_pastsocialphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentspecificphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentspecificphobia:integer)=(' || current_row.anxietydisorders_currentspecificphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastspecificphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastspecificphobia:integer)=(' || current_row.anxietydisorders_pastspecificphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentocd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentocd:integer)=(' || current_row.anxietydisorders_currentocd || ')';
          END IF;
          IF (current_row.anxietydisorders_pastocd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastocd:integer)=(' || current_row.anxietydisorders_pastocd || ')';
          END IF;
          IF (current_row.anxietydisorders_currentptsd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentptsd:integer)=(' || current_row.anxietydisorders_currentptsd || ')';
          END IF;
          IF (current_row.anxietydisorders_pastptsd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastptsd:integer)=(' || current_row.anxietydisorders_pastptsd || ')';
          END IF;
          IF (current_row.anxietydisorders_currentgeneralizedanxietydisorder IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentgeneralizedanxietydisorder:integer)=(' || current_row.anxietydisorders_currentgeneralizedanxietydisorder || ')';
          END IF;
          IF (current_row.anxietydisorders_currentanxietyduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentanxietyduetomedicalcondition:integer)=(' || current_row.anxietydisorders_currentanxietyduetomedicalcondition || ')';
          END IF;
          IF (current_row.anxietydisorders_pastanxietyduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastanxietyduetomedicalcondition:integer)=(' || current_row.anxietydisorders_pastanxietyduetomedicalcondition || ')';
          END IF;
          IF (current_row.anxietydisorders_currentsubstanceinducedanxietydisorder IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentsubstanceinducedanxietydisorder:integer)=(' || current_row.anxietydisorders_currentsubstanceinducedanxietydisorder || ')';
          END IF;
          IF (current_row.anxietydisorders_pastsubstanceinducedanxietydisorder IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastsubstanceinducedanxietydisorder:integer)=(' || current_row.anxietydisorders_pastsubstanceinducedanxietydisorder || ')';
          END IF;
          IF (current_row.anxietydisorders_currentanxietydisordernos IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentanxietydisordernos:integer)=(' || current_row.anxietydisorders_currentanxietydisordernos || ')';
          END IF;
          IF (current_row.anxietydisorders_pastanxietydisordernos IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastanxietydisordernos:integer)=(' || current_row.anxietydisorders_pastanxietydisordernos || ')';
          END IF;
          IF (current_row.somatoformdisorders_somatizationdisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_somatizationdisorder:integer)=(' || current_row.somatoformdisorders_somatizationdisorder || ')';
          END IF;
          IF (current_row.somatoformdisorders_undifferentiatedsomatformdisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_undifferentiatedsomatformdisorder:integer)=(' || current_row.somatoformdisorders_undifferentiatedsomatformdisorder || ')';
          END IF;
          IF (current_row.somatoformdisorders_paindisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_paindisorder:integer)=(' || current_row.somatoformdisorders_paindisorder || ')';
          END IF;
          IF (current_row.somatoformdisorders_hypochondriasis IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_hypochondriasis:integer)=(' || current_row.somatoformdisorders_hypochondriasis || ')';
          END IF;
          IF (current_row.somatoformdisorders_bodydysmorphicdisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_bodydysmorphicdisorder:integer)=(' || current_row.somatoformdisorders_bodydysmorphicdisorder || ')';
          END IF;
          IF (current_row.eatingdisorders_currentanorexianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_currentanorexianervosa:integer)=(' || current_row.eatingdisorders_currentanorexianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_pastanorexianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_pastanorexianervosa:integer)=(' || current_row.eatingdisorders_pastanorexianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_currentbulimianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_currentbulimianervosa:integer)=(' || current_row.eatingdisorders_currentbulimianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_pastbulimianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_pastbulimianervosa:integer)=(' || current_row.eatingdisorders_pastbulimianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_currentbingeeatingdisorder IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_currentbingeeatingdisorder:integer)=(' || current_row.eatingdisorders_currentbingeeatingdisorder || ')';
          END IF;
          IF (current_row.eatingdisorders_pastbingeeatingdisorder IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_pastbingeeatingdisorder:integer)=(' || current_row.eatingdisorders_pastbingeeatingdisorder || ')';
          END IF;
          IF (current_row.adjustmentdisorder IS NOT NULL) THEN 
              fullText := fullText || '(adjustmentdisorder:integer)=(' || current_row.adjustmentdisorder || ')';
          END IF;
          IF (current_row.optional_currentacutestressdisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_currentacutestressdisorder:integer)=(' || current_row.optional_currentacutestressdisorder || ')';
          END IF;
          IF (current_row.optional_pastacutestressdisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastacutestressdisorder:integer)=(' || current_row.optional_pastacutestressdisorder || ')';
          END IF;
          IF (current_row.optional_currentminordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_currentminordepressivedisorder:integer)=(' || current_row.optional_currentminordepressivedisorder || ')';
          END IF;
          IF (current_row.optional_pastminordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastminordepressivedisorder:integer)=(' || current_row.optional_pastminordepressivedisorder || ')';
          END IF;
          IF (current_row.optional_currentmixedanxietydepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_currentmixedanxietydepressivedisorder:integer)=(' || current_row.optional_currentmixedanxietydepressivedisorder || ')';
          END IF;
          IF (current_row.optional_pastmixedanxietydepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastmixedanxietydepressivedisorder:integer)=(' || current_row.optional_pastmixedanxietydepressivedisorder || ')';
          END IF;
          IF (current_row.optional_pastsympomaticdetails IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastsympomaticdetails:string)=(' || REPLACE(REPLACE(current_row.optional_pastsympomaticdetails,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.scidResearchData_info IS NOT NULL)) THEN
            fullText := fullText || '(scidresearchdata_info:integer)=(' || current_row.scidresearchdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_scidResearchData_meta_data(current_row.scidResearchData_info, child_count,$3,false,false);
              fullText := fullText || '(scidresearchdata_info_scidresearchdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_scidresearchdata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_scidresearchdata_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_scidresearchdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:scidResearchData_history)(';
      FOR current_row IN SELECT * FROM xnat_a_scidResearchData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_subjectAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_subjectAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.administrator IS NOT NULL) THEN 
              fullText := fullText || '(administrator:string)=(' || REPLACE(REPLACE(current_row.administrator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.moodepisodes_currentmajordepressiveepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentmajordepressiveepisode:integer)=(' || current_row.moodepisodes_currentmajordepressiveepisode || ')';
          END IF;
          IF (current_row.moodepisodes_pastmajordepressiveepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastmajordepressiveepisode:integer)=(' || current_row.moodepisodes_pastmajordepressiveepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currentmanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentmanicepisode:integer)=(' || current_row.moodepisodes_currentmanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_pastmanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastmanicepisode:integer)=(' || current_row.moodepisodes_pastmanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currenthypomanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currenthypomanicepisode:integer)=(' || current_row.moodepisodes_currenthypomanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_pasthypomanicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pasthypomanicepisode:integer)=(' || current_row.moodepisodes_pasthypomanicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currentdysthmicepisode IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentdysthmicepisode:integer)=(' || current_row.moodepisodes_currentdysthmicepisode || ')';
          END IF;
          IF (current_row.moodepisodes_currentmooddisorderduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentmooddisorderduetomedicalcondition:integer)=(' || current_row.moodepisodes_currentmooddisorderduetomedicalcondition || ')';
          END IF;
          IF (current_row.moodepisodes_pastmooddisorderduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastmooddisorderduetomedicalcondition:integer)=(' || current_row.moodepisodes_pastmooddisorderduetomedicalcondition || ')';
          END IF;
          IF (current_row.moodepisodes_currentsubstanceinducedmooddisorder IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_currentsubstanceinducedmooddisorder:integer)=(' || current_row.moodepisodes_currentsubstanceinducedmooddisorder || ')';
          END IF;
          IF (current_row.moodepisodes_pastsubstanceinducedmooddisorder IS NOT NULL) THEN 
              fullText := fullText || '(moodepisodes_pastsubstanceinducedmooddisorder:integer)=(' || current_row.moodepisodes_pastsubstanceinducedmooddisorder || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentdelusions IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentdelusions:integer)=(' || current_row.psychoticsymptoms_currentdelusions || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastdelusions IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastdelusions:integer)=(' || current_row.psychoticsymptoms_pastdelusions || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currenthallucinations IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currenthallucinations:integer)=(' || current_row.psychoticsymptoms_currenthallucinations || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pasthallucinations IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pasthallucinations:integer)=(' || current_row.psychoticsymptoms_pasthallucinations || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentdisorganizedspeechbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentdisorganizedspeechbehavior:integer)=(' || current_row.psychoticsymptoms_currentdisorganizedspeechbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastdisorganizedspeechbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastdisorganizedspeechbehavior:integer)=(' || current_row.psychoticsymptoms_pastdisorganizedspeechbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentcatatonicbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentcatatonicbehavior:integer)=(' || current_row.psychoticsymptoms_currentcatatonicbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastcatatonicbehavior IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastcatatonicbehavior:integer)=(' || current_row.psychoticsymptoms_pastcatatonicbehavior || ')';
          END IF;
          IF (current_row.psychoticsymptoms_currentnegativesymptoms IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_currentnegativesymptoms:integer)=(' || current_row.psychoticsymptoms_currentnegativesymptoms || ')';
          END IF;
          IF (current_row.psychoticsymptoms_pastnegativesymptoms IS NOT NULL) THEN 
              fullText := fullText || '(psychoticsymptoms_pastnegativesymptoms:integer)=(' || current_row.psychoticsymptoms_pastnegativesymptoms || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentschizophrenia IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentschizophrenia:integer)=(' || current_row.psychoticdisorders_currentschizophrenia || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastschizophrenia IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastschizophrenia:integer)=(' || current_row.psychoticdisorders_pastschizophrenia || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentparanoidtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentparanoidtype:integer)=(' || current_row.psychoticdisorders_currentparanoidtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastparanoidtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastparanoidtype:integer)=(' || current_row.psychoticdisorders_pastparanoidtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentcatatonictype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentcatatonictype:integer)=(' || current_row.psychoticdisorders_currentcatatonictype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastcatatonictype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastcatatonictype:integer)=(' || current_row.psychoticdisorders_pastcatatonictype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentdisorganizedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentdisorganizedtype:integer)=(' || current_row.psychoticdisorders_currentdisorganizedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastdisorganizedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastdisorganizedtype:integer)=(' || current_row.psychoticdisorders_pastdisorganizedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentundifferentiatedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentundifferentiatedtype:integer)=(' || current_row.psychoticdisorders_currentundifferentiatedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastundifferentiatedtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastundifferentiatedtype:integer)=(' || current_row.psychoticdisorders_pastundifferentiatedtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentresidualtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentresidualtype:integer)=(' || current_row.psychoticdisorders_currentresidualtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastresidualtype IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastresidualtype:integer)=(' || current_row.psychoticdisorders_pastresidualtype || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentschizophreniformdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentschizophreniformdisorder:integer)=(' || current_row.psychoticdisorders_currentschizophreniformdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastschizophreniformdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastschizophreniformdisorder:integer)=(' || current_row.psychoticdisorders_pastschizophreniformdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentschizoaffectivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentschizoaffectivedisorder:integer)=(' || current_row.psychoticdisorders_currentschizoaffectivedisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastschizoaffectivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastschizoaffectivedisorder:integer)=(' || current_row.psychoticdisorders_pastschizoaffectivedisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentdelusionaldisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentdelusionaldisorder:integer)=(' || current_row.psychoticdisorders_currentdelusionaldisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastdelusionaldisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastdelusionaldisorder:integer)=(' || current_row.psychoticdisorders_pastdelusionaldisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentbriefpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentbriefpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_currentbriefpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastbriefpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastbriefpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_pastbriefpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentpsychoticdisorderduetomedicalconditio IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentpsychoticdisorderduetomedicalconditio:integer)=(' || current_row.psychoticdisorders_currentpsychoticdisorderduetomedicalconditio || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastpsychoticdisorderduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastpsychoticdisorderduetomedicalcondition:integer)=(' || current_row.psychoticdisorders_pastpsychoticdisorderduetomedicalcondition || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentsubstanceinducedpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentsubstanceinducedpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_currentsubstanceinducedpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastsubstanceinducedpsychoticdisorder IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastsubstanceinducedpsychoticdisorder:integer)=(' || current_row.psychoticdisorders_pastsubstanceinducedpsychoticdisorder || ')';
          END IF;
          IF (current_row.psychoticdisorders_currentpsychoticdisordernos IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_currentpsychoticdisordernos:integer)=(' || current_row.psychoticdisorders_currentpsychoticdisordernos || ')';
          END IF;
          IF (current_row.psychoticdisorders_pastpsychoticdisordernos IS NOT NULL) THEN 
              fullText := fullText || '(psychoticdisorders_pastpsychoticdisordernos:integer)=(' || current_row.psychoticdisorders_pastpsychoticdisordernos || ')';
          END IF;
          IF (current_row.mooddisorders_currentbipolar1disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentbipolar1disorder:integer)=(' || current_row.mooddisorders_currentbipolar1disorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastbipolar1disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastbipolar1disorder:integer)=(' || current_row.mooddisorders_pastbipolar1disorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentbipolar2disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentbipolar2disorder:integer)=(' || current_row.mooddisorders_currentbipolar2disorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastbipolar2disorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastbipolar2disorder:integer)=(' || current_row.mooddisorders_pastbipolar2disorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentotherbipolardisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentotherbipolardisorder:integer)=(' || current_row.mooddisorders_currentotherbipolardisorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastotherbipolardisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastotherbipolardisorder:integer)=(' || current_row.mooddisorders_pastotherbipolardisorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentmajordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentmajordepressivedisorder:integer)=(' || current_row.mooddisorders_currentmajordepressivedisorder || ')';
          END IF;
          IF (current_row.mooddisorders_pastmajordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastmajordepressivedisorder:integer)=(' || current_row.mooddisorders_pastmajordepressivedisorder || ')';
          END IF;
          IF (current_row.mooddisorders_currentdepressivedisordernos IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_currentdepressivedisordernos:integer)=(' || current_row.mooddisorders_currentdepressivedisordernos || ')';
          END IF;
          IF (current_row.mooddisorders_pastdepressivedisordernos IS NOT NULL) THEN 
              fullText := fullText || '(mooddisorders_pastdepressivedisordernos:integer)=(' || current_row.mooddisorders_pastdepressivedisordernos || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentalcoholdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentalcoholdependence:integer)=(' || current_row.substanceusedisorders_currentalcoholdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastalcoholdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastalcoholdependence:integer)=(' || current_row.substanceusedisorders_pastalcoholdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentalcoholabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentalcoholabuse:integer)=(' || current_row.substanceusedisorders_currentalcoholabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastalcoholabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastalcoholabuse:integer)=(' || current_row.substanceusedisorders_pastalcoholabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentamphetaminedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentamphetaminedependence:integer)=(' || current_row.substanceusedisorders_currentamphetaminedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastamphetaminedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastamphetaminedependence:integer)=(' || current_row.substanceusedisorders_pastamphetaminedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentamphetamineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentamphetamineabuse:integer)=(' || current_row.substanceusedisorders_currentamphetamineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastamphetamineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastamphetamineabuse:integer)=(' || current_row.substanceusedisorders_pastamphetamineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcannabisdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcannabisdependence:integer)=(' || current_row.substanceusedisorders_currentcannabisdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcannabisdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcannabisdependence:integer)=(' || current_row.substanceusedisorders_pastcannabisdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcannabisabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcannabisabuse:integer)=(' || current_row.substanceusedisorders_currentcannabisabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcannabisabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcannabisabuse:integer)=(' || current_row.substanceusedisorders_pastcannabisabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcocainedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcocainedependence:integer)=(' || current_row.substanceusedisorders_currentcocainedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcocainedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcocainedependence:integer)=(' || current_row.substanceusedisorders_pastcocainedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentcocaineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentcocaineabuse:integer)=(' || current_row.substanceusedisorders_currentcocaineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastcocaineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastcocaineabuse:integer)=(' || current_row.substanceusedisorders_pastcocaineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currenthallucinogendependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currenthallucinogendependence:integer)=(' || current_row.substanceusedisorders_currenthallucinogendependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pasthallucinogendependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pasthallucinogendependence:integer)=(' || current_row.substanceusedisorders_pasthallucinogendependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currenthallucinogenabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currenthallucinogenabuse:integer)=(' || current_row.substanceusedisorders_currenthallucinogenabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pasthallucinogenabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pasthallucinogenabuse:integer)=(' || current_row.substanceusedisorders_pasthallucinogenabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentopioiddependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentopioiddependence:integer)=(' || current_row.substanceusedisorders_currentopioiddependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastopioiddependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastopioiddependence:integer)=(' || current_row.substanceusedisorders_pastopioiddependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentopioidabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentopioidabuse:integer)=(' || current_row.substanceusedisorders_currentopioidabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastopioidabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastopioidabuse:integer)=(' || current_row.substanceusedisorders_pastopioidabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentphencyclidinedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentphencyclidinedependence:integer)=(' || current_row.substanceusedisorders_currentphencyclidinedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastphencyclidinedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastphencyclidinedependence:integer)=(' || current_row.substanceusedisorders_pastphencyclidinedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentphencyclidineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentphencyclidineabuse:integer)=(' || current_row.substanceusedisorders_currentphencyclidineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastphencyclidineabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastphencyclidineabuse:integer)=(' || current_row.substanceusedisorders_pastphencyclidineabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentsedativehypnoticanxiolyticdependen IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentsedativehypnoticanxiolyticdependen:integer)=(' || current_row.substanceusedisorders_currentsedativehypnoticanxiolyticdependen || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastsedativehypnoticanxiolyticdependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastsedativehypnoticanxiolyticdependence:integer)=(' || current_row.substanceusedisorders_pastsedativehypnoticanxiolyticdependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentsedativehypnoticanxiolyticabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentsedativehypnoticanxiolyticabuse:integer)=(' || current_row.substanceusedisorders_currentsedativehypnoticanxiolyticabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastsedativehypnoticanxiolyticabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastsedativehypnoticanxiolyticabuse:integer)=(' || current_row.substanceusedisorders_pastsedativehypnoticanxiolyticabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentpolysubstancedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentpolysubstancedependence:integer)=(' || current_row.substanceusedisorders_currentpolysubstancedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastpolysubstancedependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastpolysubstancedependence:integer)=(' || current_row.substanceusedisorders_pastpolysubstancedependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentotherorunknowndependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentotherorunknowndependence:integer)=(' || current_row.substanceusedisorders_currentotherorunknowndependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastotherorunknowndependence IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastotherorunknowndependence:integer)=(' || current_row.substanceusedisorders_pastotherorunknowndependence || ')';
          END IF;
          IF (current_row.substanceusedisorders_currentotherorunknownabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_currentotherorunknownabuse:integer)=(' || current_row.substanceusedisorders_currentotherorunknownabuse || ')';
          END IF;
          IF (current_row.substanceusedisorders_pastotherorunknownabuse IS NOT NULL) THEN 
              fullText := fullText || '(substanceusedisorders_pastotherorunknownabuse:integer)=(' || current_row.substanceusedisorders_pastotherorunknownabuse || ')';
          END IF;
          IF (current_row.anxietydisorders_currentpanicwithagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentpanicwithagoraphobia:integer)=(' || current_row.anxietydisorders_currentpanicwithagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastpanicwithagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastpanicwithagoraphobia:integer)=(' || current_row.anxietydisorders_pastpanicwithagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentpanicwithoutagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentpanicwithoutagoraphobia:integer)=(' || current_row.anxietydisorders_currentpanicwithoutagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastpanicwithoutagoraphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastpanicwithoutagoraphobia:integer)=(' || current_row.anxietydisorders_pastpanicwithoutagoraphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentagoraphobiawithoutpanichx IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentagoraphobiawithoutpanichx:integer)=(' || current_row.anxietydisorders_currentagoraphobiawithoutpanichx || ')';
          END IF;
          IF (current_row.anxietydisorders_pastagoraphobiawithoutpanichx IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastagoraphobiawithoutpanichx:integer)=(' || current_row.anxietydisorders_pastagoraphobiawithoutpanichx || ')';
          END IF;
          IF (current_row.anxietydisorders_currentsocialphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentsocialphobia:integer)=(' || current_row.anxietydisorders_currentsocialphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastsocialphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastsocialphobia:integer)=(' || current_row.anxietydisorders_pastsocialphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentspecificphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentspecificphobia:integer)=(' || current_row.anxietydisorders_currentspecificphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_pastspecificphobia IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastspecificphobia:integer)=(' || current_row.anxietydisorders_pastspecificphobia || ')';
          END IF;
          IF (current_row.anxietydisorders_currentocd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentocd:integer)=(' || current_row.anxietydisorders_currentocd || ')';
          END IF;
          IF (current_row.anxietydisorders_pastocd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastocd:integer)=(' || current_row.anxietydisorders_pastocd || ')';
          END IF;
          IF (current_row.anxietydisorders_currentptsd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentptsd:integer)=(' || current_row.anxietydisorders_currentptsd || ')';
          END IF;
          IF (current_row.anxietydisorders_pastptsd IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastptsd:integer)=(' || current_row.anxietydisorders_pastptsd || ')';
          END IF;
          IF (current_row.anxietydisorders_currentgeneralizedanxietydisorder IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentgeneralizedanxietydisorder:integer)=(' || current_row.anxietydisorders_currentgeneralizedanxietydisorder || ')';
          END IF;
          IF (current_row.anxietydisorders_currentanxietyduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentanxietyduetomedicalcondition:integer)=(' || current_row.anxietydisorders_currentanxietyduetomedicalcondition || ')';
          END IF;
          IF (current_row.anxietydisorders_pastanxietyduetomedicalcondition IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastanxietyduetomedicalcondition:integer)=(' || current_row.anxietydisorders_pastanxietyduetomedicalcondition || ')';
          END IF;
          IF (current_row.anxietydisorders_currentsubstanceinducedanxietydisorder IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentsubstanceinducedanxietydisorder:integer)=(' || current_row.anxietydisorders_currentsubstanceinducedanxietydisorder || ')';
          END IF;
          IF (current_row.anxietydisorders_pastsubstanceinducedanxietydisorder IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastsubstanceinducedanxietydisorder:integer)=(' || current_row.anxietydisorders_pastsubstanceinducedanxietydisorder || ')';
          END IF;
          IF (current_row.anxietydisorders_currentanxietydisordernos IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_currentanxietydisordernos:integer)=(' || current_row.anxietydisorders_currentanxietydisordernos || ')';
          END IF;
          IF (current_row.anxietydisorders_pastanxietydisordernos IS NOT NULL) THEN 
              fullText := fullText || '(anxietydisorders_pastanxietydisordernos:integer)=(' || current_row.anxietydisorders_pastanxietydisordernos || ')';
          END IF;
          IF (current_row.somatoformdisorders_somatizationdisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_somatizationdisorder:integer)=(' || current_row.somatoformdisorders_somatizationdisorder || ')';
          END IF;
          IF (current_row.somatoformdisorders_undifferentiatedsomatformdisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_undifferentiatedsomatformdisorder:integer)=(' || current_row.somatoformdisorders_undifferentiatedsomatformdisorder || ')';
          END IF;
          IF (current_row.somatoformdisorders_paindisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_paindisorder:integer)=(' || current_row.somatoformdisorders_paindisorder || ')';
          END IF;
          IF (current_row.somatoformdisorders_hypochondriasis IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_hypochondriasis:integer)=(' || current_row.somatoformdisorders_hypochondriasis || ')';
          END IF;
          IF (current_row.somatoformdisorders_bodydysmorphicdisorder IS NOT NULL) THEN 
              fullText := fullText || '(somatoformdisorders_bodydysmorphicdisorder:integer)=(' || current_row.somatoformdisorders_bodydysmorphicdisorder || ')';
          END IF;
          IF (current_row.eatingdisorders_currentanorexianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_currentanorexianervosa:integer)=(' || current_row.eatingdisorders_currentanorexianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_pastanorexianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_pastanorexianervosa:integer)=(' || current_row.eatingdisorders_pastanorexianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_currentbulimianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_currentbulimianervosa:integer)=(' || current_row.eatingdisorders_currentbulimianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_pastbulimianervosa IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_pastbulimianervosa:integer)=(' || current_row.eatingdisorders_pastbulimianervosa || ')';
          END IF;
          IF (current_row.eatingdisorders_currentbingeeatingdisorder IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_currentbingeeatingdisorder:integer)=(' || current_row.eatingdisorders_currentbingeeatingdisorder || ')';
          END IF;
          IF (current_row.eatingdisorders_pastbingeeatingdisorder IS NOT NULL) THEN 
              fullText := fullText || '(eatingdisorders_pastbingeeatingdisorder:integer)=(' || current_row.eatingdisorders_pastbingeeatingdisorder || ')';
          END IF;
          IF (current_row.adjustmentdisorder IS NOT NULL) THEN 
              fullText := fullText || '(adjustmentdisorder:integer)=(' || current_row.adjustmentdisorder || ')';
          END IF;
          IF (current_row.optional_currentacutestressdisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_currentacutestressdisorder:integer)=(' || current_row.optional_currentacutestressdisorder || ')';
          END IF;
          IF (current_row.optional_pastacutestressdisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastacutestressdisorder:integer)=(' || current_row.optional_pastacutestressdisorder || ')';
          END IF;
          IF (current_row.optional_currentminordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_currentminordepressivedisorder:integer)=(' || current_row.optional_currentminordepressivedisorder || ')';
          END IF;
          IF (current_row.optional_pastminordepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastminordepressivedisorder:integer)=(' || current_row.optional_pastminordepressivedisorder || ')';
          END IF;
          IF (current_row.optional_currentmixedanxietydepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_currentmixedanxietydepressivedisorder:integer)=(' || current_row.optional_currentmixedanxietydepressivedisorder || ')';
          END IF;
          IF (current_row.optional_pastmixedanxietydepressivedisorder IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastmixedanxietydepressivedisorder:integer)=(' || current_row.optional_pastmixedanxietydepressivedisorder || ')';
          END IF;
          IF (current_row.optional_pastsympomaticdetails IS NOT NULL) THEN 
              fullText := fullText || '(optional_pastsympomaticdetails:string)=(' || REPLACE(REPLACE(current_row.optional_pastsympomaticdetails,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.scidResearchData_info IS NOT NULL)) THEN
            fullText := fullText || '(scidresearchdata_info:integer)=(' || current_row.scidresearchdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_scidResearchData_meta_data(current_row.scidResearchData_info, child_count,$3,false,false);
              fullText := fullText || '(scidresearchdata_info_scidresearchdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_scidresearchdata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_scidresearchdata_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_scidresearchdata_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:scidResearchData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_a_scidResearchData_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_scidresearchdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_sideeffectspittsburghdata(character varying, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_sideeffectspittsburghdata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:sideEffectsPittsburghData)(';
      FOR current_row IN SELECT * FROM xnat_a_sideEffectsPittsburghData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.motortics IS NOT NULL) THEN 
              fullText := fullText || '(motortics:integer)=(' || current_row.motortics || ')';
          END IF;
          IF (current_row.buccal_lingualmovements IS NOT NULL) THEN 
              fullText := fullText || '(buccal_lingualmovements:integer)=(' || current_row.buccal_lingualmovements || ')';
          END IF;
          IF (current_row.picking_skin_fingers_nails_lip IS NOT NULL) THEN 
              fullText := fullText || '(picking_skin_fingers_nails_lip:integer)=(' || current_row.picking_skin_fingers_nails_lip || ')';
          END IF;
          IF (current_row.worried_anxious IS NOT NULL) THEN 
              fullText := fullText || '(worried_anxious:integer)=(' || current_row.worried_anxious || ')';
          END IF;
          IF (current_row.dull_tired_listless IS NOT NULL) THEN 
              fullText := fullText || '(dull_tired_listless:integer)=(' || current_row.dull_tired_listless || ')';
          END IF;
          IF (current_row.sedation IS NOT NULL) THEN 
              fullText := fullText || '(sedation:integer)=(' || current_row.sedation || ')';
          END IF;
          IF (current_row.stomachache IS NOT NULL) THEN 
              fullText := fullText || '(stomachache:integer)=(' || current_row.stomachache || ')';
          END IF;
          IF (current_row.nausea_vomiting IS NOT NULL) THEN 
              fullText := fullText || '(nausea_vomiting:integer)=(' || current_row.nausea_vomiting || ')';
          END IF;
          IF (current_row.crabby_irritable IS NOT NULL) THEN 
              fullText := fullText || '(crabby_irritable:integer)=(' || current_row.crabby_irritable || ')';
          END IF;
          IF (current_row.tearful_sad_depressed IS NOT NULL) THEN 
              fullText := fullText || '(tearful_sad_depressed:integer)=(' || current_row.tearful_sad_depressed || ')';
          END IF;
          IF (current_row.hallucinations IS NOT NULL) THEN 
              fullText := fullText || '(hallucinations:integer)=(' || current_row.hallucinations || ')';
          END IF;
          IF (current_row.troublesleeping IS NOT NULL) THEN 
              fullText := fullText || '(troublesleeping:integer)=(' || current_row.troublesleeping || ')';
          END IF;
          IF (current_row.lossofappetite IS NOT NULL) THEN 
              fullText := fullText || '(lossofappetite:integer)=(' || current_row.lossofappetite || ')';
          END IF;
          IF (current_row.troubleconcentrating_distractible IS NOT NULL) THEN 
              fullText := fullText || '(troubleconcentrating_distractible:integer)=(' || current_row.troubleconcentrating_distractible || ')';
          END IF;
          IF (current_row.dizziness_lightheadedness IS NOT NULL) THEN 
              fullText := fullText || '(dizziness_lightheadedness:integer)=(' || current_row.dizziness_lightheadedness || ')';
          END IF;
          IF (current_row.headaches IS NOT NULL) THEN 
              fullText := fullText || '(headaches:integer)=(' || current_row.headaches || ')';
          END IF;
          IF (current_row.socialwithdrawal IS NOT NULL) THEN 
              fullText := fullText || '(socialwithdrawal:integer)=(' || current_row.socialwithdrawal || ')';
          END IF;
          IF (current_row.drymouth IS NOT NULL) THEN 
              fullText := fullText || '(drymouth:integer)=(' || current_row.drymouth || ')';
          END IF;
          IF (current_row.palpitations IS NOT NULL) THEN 
              fullText := fullText || '(palpitations:integer)=(' || current_row.palpitations || ')';
          END IF;
        IF ((current_row.sideEffectsPittsburghData_info IS NOT NULL)) THEN
            fullText := fullText || '(sideeffectspittsburghdata_info:integer)=(' || current_row.sideeffectspittsburghdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_sideEffectsPittsburghData_meta_data(current_row.sideEffectsPittsburghData_info, child_count,$3,false,false);
              fullText := fullText || '(sideeffectspittsburghdata_info_sideeffectspittsburghdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_sideeffectspittsburghdata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_sideeffectspittsburghdata_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_sideeffectspittsburghdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:sideEffectsPittsburghData_history)(';
      FOR current_row IN SELECT * FROM xnat_a_sideEffectsPittsburghData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_subjectAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_subjectAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.motortics IS NOT NULL) THEN 
              fullText := fullText || '(motortics:integer)=(' || current_row.motortics || ')';
          END IF;
          IF (current_row.buccal_lingualmovements IS NOT NULL) THEN 
              fullText := fullText || '(buccal_lingualmovements:integer)=(' || current_row.buccal_lingualmovements || ')';
          END IF;
          IF (current_row.picking_skin_fingers_nails_lip IS NOT NULL) THEN 
              fullText := fullText || '(picking_skin_fingers_nails_lip:integer)=(' || current_row.picking_skin_fingers_nails_lip || ')';
          END IF;
          IF (current_row.worried_anxious IS NOT NULL) THEN 
              fullText := fullText || '(worried_anxious:integer)=(' || current_row.worried_anxious || ')';
          END IF;
          IF (current_row.dull_tired_listless IS NOT NULL) THEN 
              fullText := fullText || '(dull_tired_listless:integer)=(' || current_row.dull_tired_listless || ')';
          END IF;
          IF (current_row.sedation IS NOT NULL) THEN 
              fullText := fullText || '(sedation:integer)=(' || current_row.sedation || ')';
          END IF;
          IF (current_row.stomachache IS NOT NULL) THEN 
              fullText := fullText || '(stomachache:integer)=(' || current_row.stomachache || ')';
          END IF;
          IF (current_row.nausea_vomiting IS NOT NULL) THEN 
              fullText := fullText || '(nausea_vomiting:integer)=(' || current_row.nausea_vomiting || ')';
          END IF;
          IF (current_row.crabby_irritable IS NOT NULL) THEN 
              fullText := fullText || '(crabby_irritable:integer)=(' || current_row.crabby_irritable || ')';
          END IF;
          IF (current_row.tearful_sad_depressed IS NOT NULL) THEN 
              fullText := fullText || '(tearful_sad_depressed:integer)=(' || current_row.tearful_sad_depressed || ')';
          END IF;
          IF (current_row.hallucinations IS NOT NULL) THEN 
              fullText := fullText || '(hallucinations:integer)=(' || current_row.hallucinations || ')';
          END IF;
          IF (current_row.troublesleeping IS NOT NULL) THEN 
              fullText := fullText || '(troublesleeping:integer)=(' || current_row.troublesleeping || ')';
          END IF;
          IF (current_row.lossofappetite IS NOT NULL) THEN 
              fullText := fullText || '(lossofappetite:integer)=(' || current_row.lossofappetite || ')';
          END IF;
          IF (current_row.troubleconcentrating_distractible IS NOT NULL) THEN 
              fullText := fullText || '(troubleconcentrating_distractible:integer)=(' || current_row.troubleconcentrating_distractible || ')';
          END IF;
          IF (current_row.dizziness_lightheadedness IS NOT NULL) THEN 
              fullText := fullText || '(dizziness_lightheadedness:integer)=(' || current_row.dizziness_lightheadedness || ')';
          END IF;
          IF (current_row.headaches IS NOT NULL) THEN 
              fullText := fullText || '(headaches:integer)=(' || current_row.headaches || ')';
          END IF;
          IF (current_row.socialwithdrawal IS NOT NULL) THEN 
              fullText := fullText || '(socialwithdrawal:integer)=(' || current_row.socialwithdrawal || ')';
          END IF;
          IF (current_row.drymouth IS NOT NULL) THEN 
              fullText := fullText || '(drymouth:integer)=(' || current_row.drymouth || ')';
          END IF;
          IF (current_row.palpitations IS NOT NULL) THEN 
              fullText := fullText || '(palpitations:integer)=(' || current_row.palpitations || ')';
          END IF;
        IF ((current_row.sideEffectsPittsburghData_info IS NOT NULL)) THEN
            fullText := fullText || '(sideeffectspittsburghdata_info:integer)=(' || current_row.sideeffectspittsburghdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_sideEffectsPittsburghData_meta_data(current_row.sideEffectsPittsburghData_info, child_count,$3,false,false);
              fullText := fullText || '(sideeffectspittsburghdata_info_sideeffectspittsburghdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_sideeffectspittsburghdata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_sideeffectspittsburghdata_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_sideeffectspittsburghdata_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:sideEffectsPittsburghData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_a_sideEffectsPittsburghData_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_sideeffectspittsburghdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_updrs3data(character varying, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_updrs3data(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:updrs3Data)(';
      FOR current_row IN SELECT * FROM xnat_a_updrs3Data WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.inscanner IS NOT NULL) THEN 
              fullText := fullText || '(inscanner:integer)=(' || current_row.inscanner || ')';
          END IF;
          IF (current_row.clicker_right IS NOT NULL) THEN 
              fullText := fullText || '(clicker_right:integer)=(' || current_row.clicker_right || ')';
          END IF;
          IF (current_row.clicker_left IS NOT NULL) THEN 
              fullText := fullText || '(clicker_left:integer)=(' || current_row.clicker_left || ')';
          END IF;
          IF (current_row.clicker_interval IS NOT NULL) THEN 
              fullText := fullText || '(clicker_interval:integer)=(' || current_row.clicker_interval || ')';
          END IF;
          IF (current_row.tremorrest_face IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_face:string)=(' || REPLACE(REPLACE(current_row.tremorrest_face,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_rue IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_rue:string)=(' || REPLACE(REPLACE(current_row.tremorrest_rue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_lue IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_lue:string)=(' || REPLACE(REPLACE(current_row.tremorrest_lue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_rle IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_rle:string)=(' || REPLACE(REPLACE(current_row.tremorrest_rle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_lle IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_lle:string)=(' || REPLACE(REPLACE(current_row.tremorrest_lle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_neck IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_neck:string)=(' || REPLACE(REPLACE(current_row.rigidity_neck,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_rue IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_rue:string)=(' || REPLACE(REPLACE(current_row.rigidity_rue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_lue IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_lue:string)=(' || REPLACE(REPLACE(current_row.rigidity_lue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_rle IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_rle:string)=(' || REPLACE(REPLACE(current_row.rigidity_rle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_lle IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_lle:string)=(' || REPLACE(REPLACE(current_row.rigidity_lle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.handmovementsgrip_right IS NOT NULL) THEN 
              fullText := fullText || '(handmovementsgrip_right:integer)=(' || current_row.handmovementsgrip_right || ')';
          END IF;
          IF (current_row.handmovementsgrip_left IS NOT NULL) THEN 
              fullText := fullText || '(handmovementsgrip_left:integer)=(' || current_row.handmovementsgrip_left || ')';
          END IF;
          IF (current_row.facialexpression IS NOT NULL) THEN 
              fullText := fullText || '(facialexpression:integer)=(' || current_row.facialexpression || ')';
          END IF;
          IF (current_row.gait IS NOT NULL) THEN 
              fullText := fullText || '(gait:integer)=(' || current_row.gait || ')';
          END IF;
          IF (current_row.speech IS NOT NULL) THEN 
              fullText := fullText || '(speech:integer)=(' || current_row.speech || ')';
          END IF;
          IF (current_row.writing IS NOT NULL) THEN 
              fullText := fullText || '(writing:integer)=(' || current_row.writing || ')';
          END IF;
          IF (current_row.arisefromchair IS NOT NULL) THEN 
              fullText := fullText || '(arisefromchair:integer)=(' || current_row.arisefromchair || ')';
          END IF;
          IF (current_row.actionposturaltremor_right IS NOT NULL) THEN 
              fullText := fullText || '(actionposturaltremor_right:integer)=(' || current_row.actionposturaltremor_right || ')';
          END IF;
          IF (current_row.actionposturaltremor_left IS NOT NULL) THEN 
              fullText := fullText || '(actionposturaltremor_left:integer)=(' || current_row.actionposturaltremor_left || ')';
          END IF;
          IF (current_row.handsram_right IS NOT NULL) THEN 
              fullText := fullText || '(handsram_right:integer)=(' || current_row.handsram_right || ')';
          END IF;
          IF (current_row.handsram_left IS NOT NULL) THEN 
              fullText := fullText || '(handsram_left:integer)=(' || current_row.handsram_left || ')';
          END IF;
          IF (current_row.fingertaps_right IS NOT NULL) THEN 
              fullText := fullText || '(fingertaps_right:integer)=(' || current_row.fingertaps_right || ')';
          END IF;
          IF (current_row.fingertaps_left IS NOT NULL) THEN 
              fullText := fullText || '(fingertaps_left:integer)=(' || current_row.fingertaps_left || ')';
          END IF;
          IF (current_row.posture IS NOT NULL) THEN 
              fullText := fullText || '(posture:integer)=(' || current_row.posture || ')';
          END IF;
          IF (current_row.posturalstability IS NOT NULL) THEN 
              fullText := fullText || '(posturalstability:integer)=(' || current_row.posturalstability || ')';
          END IF;
          IF (current_row.foottaps_right IS NOT NULL) THEN 
              fullText := fullText || '(foottaps_right:integer)=(' || current_row.foottaps_right || ')';
          END IF;
          IF (current_row.foottaps_left IS NOT NULL) THEN 
              fullText := fullText || '(foottaps_left:integer)=(' || current_row.foottaps_left || ')';
          END IF;
          IF (current_row.bodybradykinesiahypokinesia IS NOT NULL) THEN 
              fullText := fullText || '(bodybradykinesiahypokinesia:integer)=(' || current_row.bodybradykinesiahypokinesia || ')';
          END IF;
          IF (current_row.problem IS NOT NULL) THEN 
              fullText := fullText || '(problem:integer)=(' || current_row.problem || ')';
          END IF;
        IF ((current_row.updrs3Data_info IS NOT NULL)) THEN
            fullText := fullText || '(updrs3data_info:integer)=(' || current_row.updrs3data_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_updrs3Data_meta_data(current_row.updrs3Data_info, child_count,$3,false,false);
              fullText := fullText || '(updrs3data_info_updrs3data_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_updrs3data(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_updrs3data_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_updrs3data_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:updrs3Data_history)(';
      FOR current_row IN SELECT * FROM xnat_a_updrs3Data_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_subjectAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_subjectAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.inscanner IS NOT NULL) THEN 
              fullText := fullText || '(inscanner:integer)=(' || current_row.inscanner || ')';
          END IF;
          IF (current_row.clicker_right IS NOT NULL) THEN 
              fullText := fullText || '(clicker_right:integer)=(' || current_row.clicker_right || ')';
          END IF;
          IF (current_row.clicker_left IS NOT NULL) THEN 
              fullText := fullText || '(clicker_left:integer)=(' || current_row.clicker_left || ')';
          END IF;
          IF (current_row.clicker_interval IS NOT NULL) THEN 
              fullText := fullText || '(clicker_interval:integer)=(' || current_row.clicker_interval || ')';
          END IF;
          IF (current_row.tremorrest_face IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_face:string)=(' || REPLACE(REPLACE(current_row.tremorrest_face,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_rue IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_rue:string)=(' || REPLACE(REPLACE(current_row.tremorrest_rue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_lue IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_lue:string)=(' || REPLACE(REPLACE(current_row.tremorrest_lue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_rle IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_rle:string)=(' || REPLACE(REPLACE(current_row.tremorrest_rle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tremorrest_lle IS NOT NULL) THEN 
              fullText := fullText || '(tremorrest_lle:string)=(' || REPLACE(REPLACE(current_row.tremorrest_lle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_neck IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_neck:string)=(' || REPLACE(REPLACE(current_row.rigidity_neck,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_rue IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_rue:string)=(' || REPLACE(REPLACE(current_row.rigidity_rue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_lue IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_lue:string)=(' || REPLACE(REPLACE(current_row.rigidity_lue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_rle IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_rle:string)=(' || REPLACE(REPLACE(current_row.rigidity_rle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rigidity_lle IS NOT NULL) THEN 
              fullText := fullText || '(rigidity_lle:string)=(' || REPLACE(REPLACE(current_row.rigidity_lle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.handmovementsgrip_right IS NOT NULL) THEN 
              fullText := fullText || '(handmovementsgrip_right:integer)=(' || current_row.handmovementsgrip_right || ')';
          END IF;
          IF (current_row.handmovementsgrip_left IS NOT NULL) THEN 
              fullText := fullText || '(handmovementsgrip_left:integer)=(' || current_row.handmovementsgrip_left || ')';
          END IF;
          IF (current_row.facialexpression IS NOT NULL) THEN 
              fullText := fullText || '(facialexpression:integer)=(' || current_row.facialexpression || ')';
          END IF;
          IF (current_row.gait IS NOT NULL) THEN 
              fullText := fullText || '(gait:integer)=(' || current_row.gait || ')';
          END IF;
          IF (current_row.speech IS NOT NULL) THEN 
              fullText := fullText || '(speech:integer)=(' || current_row.speech || ')';
          END IF;
          IF (current_row.writing IS NOT NULL) THEN 
              fullText := fullText || '(writing:integer)=(' || current_row.writing || ')';
          END IF;
          IF (current_row.arisefromchair IS NOT NULL) THEN 
              fullText := fullText || '(arisefromchair:integer)=(' || current_row.arisefromchair || ')';
          END IF;
          IF (current_row.actionposturaltremor_right IS NOT NULL) THEN 
              fullText := fullText || '(actionposturaltremor_right:integer)=(' || current_row.actionposturaltremor_right || ')';
          END IF;
          IF (current_row.actionposturaltremor_left IS NOT NULL) THEN 
              fullText := fullText || '(actionposturaltremor_left:integer)=(' || current_row.actionposturaltremor_left || ')';
          END IF;
          IF (current_row.handsram_right IS NOT NULL) THEN 
              fullText := fullText || '(handsram_right:integer)=(' || current_row.handsram_right || ')';
          END IF;
          IF (current_row.handsram_left IS NOT NULL) THEN 
              fullText := fullText || '(handsram_left:integer)=(' || current_row.handsram_left || ')';
          END IF;
          IF (current_row.fingertaps_right IS NOT NULL) THEN 
              fullText := fullText || '(fingertaps_right:integer)=(' || current_row.fingertaps_right || ')';
          END IF;
          IF (current_row.fingertaps_left IS NOT NULL) THEN 
              fullText := fullText || '(fingertaps_left:integer)=(' || current_row.fingertaps_left || ')';
          END IF;
          IF (current_row.posture IS NOT NULL) THEN 
              fullText := fullText || '(posture:integer)=(' || current_row.posture || ')';
          END IF;
          IF (current_row.posturalstability IS NOT NULL) THEN 
              fullText := fullText || '(posturalstability:integer)=(' || current_row.posturalstability || ')';
          END IF;
          IF (current_row.foottaps_right IS NOT NULL) THEN 
              fullText := fullText || '(foottaps_right:integer)=(' || current_row.foottaps_right || ')';
          END IF;
          IF (current_row.foottaps_left IS NOT NULL) THEN 
              fullText := fullText || '(foottaps_left:integer)=(' || current_row.foottaps_left || ')';
          END IF;
          IF (current_row.bodybradykinesiahypokinesia IS NOT NULL) THEN 
              fullText := fullText || '(bodybradykinesiahypokinesia:integer)=(' || current_row.bodybradykinesiahypokinesia || ')';
          END IF;
          IF (current_row.problem IS NOT NULL) THEN 
              fullText := fullText || '(problem:integer)=(' || current_row.problem || ')';
          END IF;
        IF ((current_row.updrs3Data_info IS NOT NULL)) THEN
            fullText := fullText || '(updrs3data_info:integer)=(' || current_row.updrs3data_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_updrs3Data_meta_data(current_row.updrs3Data_info, child_count,$3,false,false);
              fullText := fullText || '(updrs3data_info_updrs3data_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_updrs3data_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_updrs3data_meta_data(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_updrs3data_meta_data(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:updrs3Data_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_a_updrs3Data_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          END IF;
          IF (current_row.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_date || ')';
          END IF;
          IF (current_row.row_last_modified IS NOT NULL) THEN 
              fullText := fullText || '(row_last_modified:dateTime)=(' || current_row.row_last_modified || ')';
          END IF;
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          END IF;
        IF ((current_row.activation_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(activation_user_xdat_user_id:integer)=(' || current_row.activation_user_xdat_user_id || ')';
        END IF;
        IF ((current_row.insert_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(insert_user_xdat_user_id:integer)=(' || current_row.insert_user_xdat_user_id || ')';
        END IF;
          IF (current_row.origin IS NOT NULL) THEN 
              fullText := fullText || '(origin:string)=(' || REPLACE(REPLACE(current_row.origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_updrs3data_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_ybocsdata(character varying, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_ybocsdata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:ybocsData)(';
      FOR current_row IN SELECT * FROM xnat_a_ybocsData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.currentorworstever IS NOT NULL) THEN 
              fullText := fullText || '(currentorworstever:string)=(' || REPLACE(REPLACE(current_row.currentorworstever,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.timeoccupiedwiththoughts IS NOT NULL) THEN 
              fullText := fullText || '(timeoccupiedwiththoughts:integer)=(' || current_row.timeoccupiedwiththoughts || ')';
          END IF;
          IF (current_row.thoughtsinterferefunctioning IS NOT NULL) THEN 
              fullText := fullText || '(thoughtsinterferefunctioning:integer)=(' || current_row.thoughtsinterferefunctioning || ')';
          END IF;
          IF (current_row.distresscaused IS NOT NULL) THEN 
              fullText := fullText || '(distresscaused:integer)=(' || current_row.distresscaused || ')';
          END IF;
          IF (current_row.efforttoresistthoughts IS NOT NULL) THEN 
              fullText := fullText || '(efforttoresistthoughts:integer)=(' || current_row.efforttoresistthoughts || ')';
          END IF;
          IF (current_row.controloverthoughts IS NOT NULL) THEN 
              fullText := fullText || '(controloverthoughts:integer)=(' || current_row.controloverthoughts || ')';
          END IF;
          IF (current_row.timeperforming IS NOT NULL) THEN 
              fullText := fullText || '(timeperforming:integer)=(' || current_row.timeperforming || ')';
          END IF;
          IF (current_row.behaviorsinterferefunctioning IS NOT NULL) THEN 
              fullText := fullText || '(behaviorsinterferefunctioning:integer)=(' || current_row.behaviorsinterferefunctioning || ')';
          END IF;
          IF (current_row.feelingifprevented IS NOT NULL) THEN 
              fullText := fullText || '(feelingifprevented:integer)=(' || current_row.feelingifprevented || ')';
          END IF;
          IF (current_row.efforttoresistbehaviors IS NOT NULL) THEN 
              fullText := fullText || '(efforttoresistbehaviors:integer)=(' || current_row.efforttoresistbehaviors || ')';
          END IF;
          IF (current_row.behaviordrivestrength IS NOT NULL) THEN 
              fullText := fullText || '(behaviordrivestrength:integer)=(' || current_row.behaviordrivestrength || ')';
          END IF;
          IF (current_row.untiljustright IS NOT NULL) THEN 
              fullText := fullText || '(untiljustright:integer)=(' || current_row.untiljustright || ')';
          END IF;
          IF (current_row.untiljustrightawareness IS NOT NULL) THEN 
              fullText := fullText || '(untiljustrightawareness:string)=(' || REPLACE(REPLACE(current_row.untiljustrightawareness,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.untiljustrightperceptions IS NOT NULL) THEN 
              fullText := fullText || '(untiljustrightperceptions:string)=(' || REPLACE(REPLACE(current_row.untiljustrightperceptions,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.whenstartuntiljustright IS NOT NULL) THEN 
              fullText := fullText || '(whenstartuntiljustright:string)=(' || REPLACE(REPLACE(current_row.whenstartuntiljustright,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.frequencyuntiljustright IS NOT NULL) THEN 
              fullText := fullText || '(frequencyuntiljustright:string)=(' || REPLACE(REPLACE(current_row.frequencyuntiljustright,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.firstuntiljustrightage IS NOT NULL) THEN 
              fullText := fullText || '(firstuntiljustrightage:float)=(' || current_row.firstuntiljustrightage || ')';
          END IF;
        IF ((current_row.ybocsData_info IS NOT NULL)) THEN
            fullText := fullText || '(ybocsdata_info:integer)=(' || current_row.ybocsdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_ybocsData_meta_data(current_row.ybocsData_info, child_count,$3,false,false);
              fullText := fullText || '(ybocsdata_info_ybocsdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_ybocsdata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

--
-- Name: i_xnat_a_ybocsdata_history(integer, integer, boolean, boolean, boolean); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.i_xnat_a_ybocsdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat_a:ybocsData_history)(';
      FOR current_row IN SELECT * FROM xnat_a_ybocsData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_subjectAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_subjectAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.currentorworstever IS NOT NULL) THEN 
              fullText := fullText || '(currentorworstever:string)=(' || REPLACE(REPLACE(current_row.currentorworstever,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.timeoccupiedwiththoughts IS NOT NULL) THEN 
              fullText := fullText || '(timeoccupiedwiththoughts:integer)=(' || current_row.timeoccupiedwiththoughts || ')';
          END IF;
          IF (current_row.thoughtsinterferefunctioning IS NOT NULL) THEN 
              fullText := fullText || '(thoughtsinterferefunctioning:integer)=(' || current_row.thoughtsinterferefunctioning || ')';
          END IF;
          IF (current_row.distresscaused IS NOT NULL) THEN 
              fullText := fullText || '(distresscaused:integer)=(' || current_row.distresscaused || ')';
          END IF;
          IF (current_row.efforttoresistthoughts IS NOT NULL) THEN 
              fullText := fullText || '(efforttoresistthoughts:integer)=(' || current_row.efforttoresistthoughts || ')';
          END IF;
          IF (current_row.controloverthoughts IS NOT NULL) THEN 
              fullText := fullText || '(controloverthoughts:integer)=(' || current_row.controloverthoughts || ')';
          END IF;
          IF (current_row.timeperforming IS NOT NULL) THEN 
              fullText := fullText || '(timeperforming:integer)=(' || current_row.timeperforming || ')';
          END IF;
          IF (current_row.behaviorsinterferefunctioning IS NOT NULL) THEN 
              fullText := fullText || '(behaviorsinterferefunctioning:integer)=(' || current_row.behaviorsinterferefunctioning || ')';
          END IF;
          IF (current_row.feelingifprevented IS NOT NULL) THEN 
              fullText := fullText || '(feelingifprevented:integer)=(' || current_row.feelingifprevented || ')';
          END IF;
          IF (current_row.efforttoresistbehaviors IS NOT NULL) THEN 
              fullText := fullText || '(efforttoresistbehaviors:integer)=(' || current_row.efforttoresistbehaviors || ')';
          END IF;
          IF (current_row.behaviordrivestrength IS NOT NULL) THEN 
              fullText := fullText || '(behaviordrivestrength:integer)=(' || current_row.behaviordrivestrength || ')';
          END IF;
          IF (current_row.untiljustright IS NOT NULL) THEN 
              fullText := fullText || '(untiljustright:integer)=(' || current_row.untiljustright || ')';
          END IF;
          IF (current_row.untiljustrightawareness IS NOT NULL) THEN 
              fullText := fullText || '(untiljustrightawareness:string)=(' || REPLACE(REPLACE(current_row.untiljustrightawareness,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.untiljustrightperceptions IS NOT NULL) THEN 
              fullText := fullText || '(untiljustrightperceptions:string)=(' || REPLACE(REPLACE(current_row.untiljustrightperceptions,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.whenstartuntiljustright IS NOT NULL) THEN 
              fullText := fullText || '(whenstartuntiljustright:string)=(' || REPLACE(REPLACE(current_row.whenstartuntiljustright,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.frequencyuntiljustright IS NOT NULL) THEN 
              fullText := fullText || '(frequencyuntiljustright:string)=(' || REPLACE(REPLACE(current_row.frequencyuntiljustright,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.firstuntiljustrightage IS NOT NULL) THEN 
              fullText := fullText || '(firstuntiljustrightage:float)=(' || current_row.firstuntiljustrightage || ')';
          END IF;
        IF ((current_row.ybocsData_info IS NOT NULL)) THEN
            fullText := fullText || '(ybocsdata_info:integer)=(' || current_row.ybocsdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_ybocsData_meta_data(current_row.ybocsData_info, child_count,$3,false,false);
              fullText := fullText || '(ybocsdata_info_ybocsdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


ALTER FUNCTION public.i_xnat_a_ybocsdata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
