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

CREATE FUNCTION public.i_val_protocoldata_condition_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 || '(val:protocolData_condition_meta_data)(';
      FOR current_row IN SELECT * FROM val_protocolData_condition_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_val_protocoldata_condition_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_val_protocoldata_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 || '(val:protocolData_history)(';
      FOR current_row IN SELECT * FROM val_protocolData_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_imageAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_condition_history WHERE check_conditions_condition_val__id=current_row.id AND xft_version=current_row.xft_version ORDER BY val_protocoldata_condition_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_condition_history( parent_row.val_protocoldata_condition_id, child_count,$3,false,false);
              fullText := fullText || '(check_conditions_condition_protocoldata_condition' || 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 val_protocolData_comment_history WHERE check_comments_comment_val_prot_id=current_row.id AND xft_version=current_row.xft_version ORDER BY val_protocoldata_comment_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_comment_history( parent_row.val_protocoldata_comment_id, child_count,$3,false,false);
              fullText := fullText || '(check_comments_comment_protocoldata_comment' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.check_additionalval_val_additionalval_id IS NOT NULL)) THEN
            fullText := fullText || '(check_additionalval_val_additionalval_id:integer)=(' || current_row.check_additionalval_val_additionalval_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM val_additionalVal_history WHERE  val_additionalval_id=current_row.check_additionalval_val_additionalval_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_additionalVal_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(check_additionalval_additionalval:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.check_status IS NOT NULL) THEN 
              fullText := fullText || '(check_status:string)=(' || REPLACE(REPLACE(current_row.check_status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_scan_check_history WHERE scans_scan_check_val_protocolDa_id=current_row.id AND xft_version=current_row.xft_version ORDER BY val_protocoldata_scan_check_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_history( parent_row.val_protocoldata_scan_check_id, child_count,$3,false,false);
              fullText := fullText || '(scans_scan_check_protocoldata_scan_check' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.protocolData_info IS NOT NULL)) THEN
            fullText := fullText || '(protocoldata_info:integer)=(' || current_row.protocoldata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_meta_data(current_row.protocolData_info, child_count,$3,false,false);
              fullText := fullText || '(protocoldata_info_protocoldata_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_imageAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_val_protocoldata_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 || '(val:protocolData_meta_data)(';
      FOR current_row IN SELECT * FROM val_protocolData_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_val_protocoldata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_val_protocoldata_scan_check(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 || '(val:protocolData_scan_check)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check WHERE  val_protocoldata_scan_check_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 val_protocolData_scan_check_condition WHERE conditions_condition_val_protoc_val_protocoldata_scan_check_id=current_row.val_protocoldata_scan_check_id ORDER BY val_protocoldata_scan_check_condition_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_condition( parent_row.val_protocoldata_scan_check_condition_id, child_count,$3,false,false);
              fullText := fullText || '(conditions_condition_protocoldata_scan_check_condition' || 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 val_protocolData_scan_check_comment WHERE comments_comment_val_protocolDa_val_protocoldata_scan_check_id=current_row.val_protocoldata_scan_check_id ORDER BY val_protocoldata_scan_check_comment_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_comment( parent_row.val_protocoldata_scan_check_comment_id, child_count,$3,false,false);
              fullText := fullText || '(comments_comment_protocoldata_scan_check_comment' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.additionalval_val_additionalval_id IS NOT NULL)) THEN
            fullText := fullText || '(additionalval_val_additionalval_id:integer)=(' || current_row.additionalval_val_additionalval_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_additionalVal(current_row.additionalval_val_additionalval_id, child_count,$3,false,false);
              fullText := fullText || '(additionalval_additionalval:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.scan_id IS NOT NULL) THEN 
              fullText := fullText || '(scan_id:string)=(' || REPLACE(REPLACE(current_row.scan_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.protocolData_scan_check_info IS NOT NULL)) THEN
            fullText := fullText || '(protocoldata_scan_check_info:integer)=(' || current_row.protocoldata_scan_check_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_meta_data(current_row.protocolData_scan_check_info, child_count,$3,false,false);
              fullText := fullText || '(protocoldata_scan_check_info_protocoldata_scan_check_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.scans_scan_check_val_protocolDa_id IS NOT NULL)) THEN
            fullText := fullText || '(scans_scan_check_val_protocolda_id:string)=(' || current_row.scans_scan_check_val_protocolda_id || ')';
        END IF;
          IF (current_row.val_protocoldata_scan_check_id IS NOT NULL) THEN 
              fullText := fullText || '(val_protocoldata_scan_check_id:integer)=(' || current_row.val_protocoldata_scan_check_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_comment(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 || '(val:protocolData_scan_check_comment)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_comment WHERE  val_protocoldata_scan_check_comment_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.comment IS NOT NULL) THEN 
              fullText := fullText || '(comment:string)=(' || REPLACE(REPLACE(current_row.comment,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.username IS NOT NULL) THEN 
              fullText := fullText || '(username:string)=(' || REPLACE(REPLACE(current_row.username,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.datetime IS NOT NULL) THEN 
              fullText := fullText || '(datetime:dateTime)=(' || current_row.datetime || ')';
          END IF;
        IF ((current_row.protocolData_scan_check_comment_info IS NOT NULL)) THEN
            fullText := fullText || '(protocoldata_scan_check_comment_info:integer)=(' || current_row.protocoldata_scan_check_comment_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_comment_meta_data(current_row.protocolData_scan_check_comment_info, child_count,$3,false,false);
              fullText := fullText || '(protocoldata_scan_check_comment_info_protocoldata_scan_check_comment_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.comments_comment_val_protocolDa_val_protocoldata_scan_check_id IS NOT NULL)) THEN
            fullText := fullText || '(comments_comment_val_protocolda_val_protocoldata_scan_check_id:integer)=(' || current_row.comments_comment_val_protocolda_val_protocoldata_scan_check_id || ')';
        END IF;
          IF (current_row.val_protocoldata_scan_check_comment_id IS NOT NULL) THEN 
              fullText := fullText || '(val_protocoldata_scan_check_comment_id:integer)=(' || current_row.val_protocoldata_scan_check_comment_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_comment_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 || '(val:protocolData_scan_check_comment_history)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_comment_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.comment IS NOT NULL) THEN 
              fullText := fullText || '(comment:string)=(' || REPLACE(REPLACE(current_row.comment,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.username IS NOT NULL) THEN 
              fullText := fullText || '(username:string)=(' || REPLACE(REPLACE(current_row.username,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.datetime IS NOT NULL) THEN 
              fullText := fullText || '(datetime:dateTime)=(' || current_row.datetime || ')';
          END IF;
        IF ((current_row.protocolData_scan_check_comment_info IS NOT NULL)) THEN
            fullText := fullText || '(protocoldata_scan_check_comment_info:integer)=(' || current_row.protocoldata_scan_check_comment_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_comment_meta_data(current_row.protocolData_scan_check_comment_info, child_count,$3,false,false);
              fullText := fullText || '(protocoldata_scan_check_comment_info_protocoldata_scan_check_comment_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.comments_comment_val_protocolDa_val_protocoldata_scan_check_id IS NOT NULL)) THEN
            fullText := fullText || '(comments_comment_val_protocolda_val_protocoldata_scan_check_id:integer)=(' || current_row.comments_comment_val_protocolda_val_protocoldata_scan_check_id || ')';
        END IF;
          IF (current_row.val_protocoldata_scan_check_comment_id IS NOT NULL) THEN 
              fullText := fullText || '(val_protocoldata_scan_check_comment_id:integer)=(' || current_row.val_protocoldata_scan_check_comment_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_val_protocoldata_scan_check_comment_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_comment_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 || '(val:protocolData_scan_check_comment_meta_data)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_comment_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_val_protocoldata_scan_check_comment_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_condition(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 || '(val:protocolData_scan_check_condition)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_condition WHERE  val_protocoldata_scan_check_condition_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.verified IS NOT NULL) THEN 
              fullText := fullText || '(verified:string)=(' || REPLACE(REPLACE(current_row.verified,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.diagnosis IS NOT NULL) THEN 
              fullText := fullText || '(diagnosis:string)=(' || REPLACE(REPLACE(current_row.diagnosis,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.xmlpath IS NOT NULL) THEN 
              fullText := fullText || '(xmlpath:string)=(' || REPLACE(REPLACE(current_row.xmlpath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.protocolData_scan_check_condition_info IS NOT NULL)) THEN
            fullText := fullText || '(protocoldata_scan_check_condition_info:integer)=(' || current_row.protocoldata_scan_check_condition_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_condition_meta_data(current_row.protocolData_scan_check_condition_info, child_count,$3,false,false);
              fullText := fullText || '(protocoldata_scan_check_condition_info_protocoldata_scan_check_condition_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.conditions_condition_val_protoc_val_protocoldata_scan_check_id IS NOT NULL)) THEN
            fullText := fullText || '(conditions_condition_val_protoc_val_protocoldata_scan_check_id:integer)=(' || current_row.conditions_condition_val_protoc_val_protocoldata_scan_check_id || ')';
        END IF;
          IF (current_row.val_protocoldata_scan_check_condition_id IS NOT NULL) THEN 
              fullText := fullText || '(val_protocoldata_scan_check_condition_id:integer)=(' || current_row.val_protocoldata_scan_check_condition_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_condition_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 || '(val:protocolData_scan_check_condition_history)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_condition_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.verified IS NOT NULL) THEN 
              fullText := fullText || '(verified:string)=(' || REPLACE(REPLACE(current_row.verified,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.diagnosis IS NOT NULL) THEN 
              fullText := fullText || '(diagnosis:string)=(' || REPLACE(REPLACE(current_row.diagnosis,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.status IS NOT NULL) THEN 
              fullText := fullText || '(status:string)=(' || REPLACE(REPLACE(current_row.status,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.xmlpath IS NOT NULL) THEN 
              fullText := fullText || '(xmlpath:string)=(' || REPLACE(REPLACE(current_row.xmlpath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.protocolData_scan_check_condition_info IS NOT NULL)) THEN
            fullText := fullText || '(protocoldata_scan_check_condition_info:integer)=(' || current_row.protocoldata_scan_check_condition_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_condition_meta_data(current_row.protocolData_scan_check_condition_info, child_count,$3,false,false);
              fullText := fullText || '(protocoldata_scan_check_condition_info_protocoldata_scan_check_condition_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.conditions_condition_val_protoc_val_protocoldata_scan_check_id IS NOT NULL)) THEN
            fullText := fullText || '(conditions_condition_val_protoc_val_protocoldata_scan_check_id:integer)=(' || current_row.conditions_condition_val_protoc_val_protocoldata_scan_check_id || ')';
        END IF;
          IF (current_row.val_protocoldata_scan_check_condition_id IS NOT NULL) THEN 
              fullText := fullText || '(val_protocoldata_scan_check_condition_id:integer)=(' || current_row.val_protocoldata_scan_check_condition_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_val_protocoldata_scan_check_condition_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_condition_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 || '(val:protocolData_scan_check_condition_meta_data)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_condition_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_val_protocoldata_scan_check_condition_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_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 || '(val:protocolData_scan_check_history)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_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 val_protocolData_scan_check_condition_history WHERE conditions_condition_val_protoc_val_protocoldata_scan_check_id=current_row.val_protocoldata_scan_check_id AND xft_version=current_row.xft_version ORDER BY val_protocoldata_scan_check_condition_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_condition_history( parent_row.val_protocoldata_scan_check_condition_id, child_count,$3,false,false);
              fullText := fullText || '(conditions_condition_protocoldata_scan_check_condition' || 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 val_protocolData_scan_check_comment_history WHERE comments_comment_val_protocolDa_val_protocoldata_scan_check_id=current_row.val_protocoldata_scan_check_id AND xft_version=current_row.xft_version ORDER BY val_protocoldata_scan_check_comment_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_comment_history( parent_row.val_protocoldata_scan_check_comment_id, child_count,$3,false,false);
              fullText := fullText || '(comments_comment_protocoldata_scan_check_comment' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.additionalval_val_additionalval_id IS NOT NULL)) THEN
            fullText := fullText || '(additionalval_val_additionalval_id:integer)=(' || current_row.additionalval_val_additionalval_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM val_additionalVal_history WHERE  val_additionalval_id=current_row.additionalval_val_additionalval_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_additionalVal_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(additionalval_additionalval:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.scan_id IS NOT NULL) THEN 
              fullText := fullText || '(scan_id:string)=(' || REPLACE(REPLACE(current_row.scan_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.protocolData_scan_check_info IS NOT NULL)) THEN
            fullText := fullText || '(protocoldata_scan_check_info:integer)=(' || current_row.protocoldata_scan_check_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_val_protocolData_scan_check_meta_data(current_row.protocolData_scan_check_info, child_count,$3,false,false);
              fullText := fullText || '(protocoldata_scan_check_info_protocoldata_scan_check_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.scans_scan_check_val_protocolDa_id IS NOT NULL)) THEN
            fullText := fullText || '(scans_scan_check_val_protocolda_id:string)=(' || current_row.scans_scan_check_val_protocolda_id || ')';
        END IF;
          IF (current_row.val_protocoldata_scan_check_id IS NOT NULL) THEN 
              fullText := fullText || '(val_protocoldata_scan_check_id:integer)=(' || current_row.val_protocoldata_scan_check_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_val_protocoldata_scan_check_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_val_protocoldata_scan_check_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 || '(val:protocolData_scan_check_meta_data)(';
      FOR current_row IN SELECT * FROM val_protocolData_scan_check_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_val_protocoldata_scan_check_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_abstractexecutionenvironment(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT wrk_abstractExecutionEnvironment.wrk_abstractexecutionenvironment_id AS wrk_abstractExecutionEnvironment2, table1.element_name AS xdat_meta_element3, table2.insert_date AS wrk_abstractExecutionEnvironment_meta_data10 FROM wrk_abstractExecutionEnvironment wrk_abstractExecutionEnvironment   LEFT JOIN xdat_meta_element table1 ON wrk_abstractExecutionEnvironment.extension=table1.xdat_meta_element_id   LEFT JOIN wrk_abstractExecutionEnvironment_meta_data table2 ON wrk_abstractExecutionEnvironment.abstractExecutionEnvironment_info=table2.meta_data_id) SEARCH  WHERE 
 ( (wrk_abstractExecutionEnvironment2=$1))
      LOOP
         IF (current_row.xdat_meta_element3 IS NULL) THEN 
             fullText:= ie_wrk_abstractExecutionEnvironment( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='wrk:xnatExecutionEnvironment') THEN
                fullText:= i_wrk_xnatExecutionEnvironment( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_wrk_abstractExecutionEnvironment( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_wrk_abstractexecutionenvironment_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 wrk_abstractExecutionEnvironment_history.history_id AS wrk_abstractExecutionEnvironment_history4, table1.element_name AS xdat_meta_element9, wrk_abstractExecutionEnvironment_history.xft_version AS wrk_abstractExecutionEnvironment_history_xft_version, wrk_abstractExecutionEnvironment_history.wrk_abstractexecutionenvironment_id AS wrk_abstractExecutionEnvironment_history0 FROM wrk_abstractExecutionEnvironment_history wrk_abstractExecutionEnvironment_history   LEFT JOIN xdat_meta_element table1 ON wrk_abstractExecutionEnvironment_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (wrk_abstractExecutionEnvironment_history4=$1))
      LOOP
         IF (current_row.xdat_meta_element9 IS NULL) THEN 
             fullText:= ie_wrk_abstractExecutionEnvironment( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element9='wrk:xnatExecutionEnvironment') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM wrk_xnatExecutionEnvironment_history WHERE wrk_abstractexecutionenvironment_id=current_row.wrk_abstractExecutionEnvironment_history0 AND xft_version=current_row.wrk_abstractExecutionEnvironment_history_xft_version
           	LOOP
                fullText:= i_wrk_xnatExecutionEnvironment_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_wrk_abstractExecutionEnvironment_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_wrk_abstractexecutionenvironment_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 || '(wrk:abstractExecutionEnvironment_meta_data)(';
      FOR current_row IN SELECT * FROM wrk_abstractExecutionEnvironment_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_wrk_abstractexecutionenvironment_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_workflowdata(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 || '(wrk:workflowData)(';
      FOR current_row IN SELECT * FROM wrk_workflowData WHERE  wrk_workflowdata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.executionenvironment_wrk_abstractexecutionenvironment_id IS NOT NULL)) THEN
            fullText := fullText || '(executionenvironment_wrk_abstractexecutionenvironment_id:integer)=(' || current_row.executionenvironment_wrk_abstractexecutionenvironment_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_abstractExecutionEnvironment(current_row.executionenvironment_wrk_abstractexecutionenvironment_id, child_count,$3,false,false);
              fullText := fullText || '(executionenvironment_abstractexecutionenvironment:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.comments IS NOT NULL) THEN 
              fullText := fullText || '(comments:string)=(' || REPLACE(REPLACE(current_row.comments,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.details IS NOT NULL) THEN 
              fullText := fullText || '(details:string)=(' || REPLACE(REPLACE(current_row.details,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.justification IS NOT NULL) THEN 
              fullText := fullText || '(justification:string)=(' || REPLACE(REPLACE(current_row.justification,'(','*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.src IS NOT NULL) THEN 
              fullText := fullText || '(src:string)=(' || REPLACE(REPLACE(current_row.src,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.category IS NOT NULL) THEN 
              fullText := fullText || '(category:string)=(' || REPLACE(REPLACE(current_row.category,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.data_type IS NOT NULL) THEN 
              fullText := fullText || '(data_type:string)=(' || REPLACE(REPLACE(current_row.data_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.externalid IS NOT NULL) THEN 
              fullText := fullText || '(externalid:string)=(' || REPLACE(REPLACE(current_row.externalid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.current_step_launch_time IS NOT NULL) THEN 
              fullText := fullText || '(current_step_launch_time:dateTime)=(' || current_row.current_step_launch_time || ')';
          END IF;
          IF (current_row.current_step_id IS NOT NULL) THEN 
              fullText := fullText || '(current_step_id:string)=(' || REPLACE(REPLACE(current_row.current_step_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.create_user IS NOT NULL) THEN 
              fullText := fullText || '(create_user:string)=(' || REPLACE(REPLACE(current_row.create_user,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pipeline_name IS NOT NULL) THEN 
              fullText := fullText || '(pipeline_name:string)=(' || REPLACE(REPLACE(current_row.pipeline_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.next_step_id IS NOT NULL) THEN 
              fullText := fullText || '(next_step_id:string)=(' || REPLACE(REPLACE(current_row.next_step_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.step_description IS NOT NULL) THEN 
              fullText := fullText || '(step_description:string)=(' || REPLACE(REPLACE(current_row.step_description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.launch_time IS NOT NULL) THEN 
              fullText := fullText || '(launch_time:dateTime)=(' || current_row.launch_time || ')';
          END IF;
          IF (current_row.percentagecomplete IS NOT NULL) THEN 
              fullText := fullText || '(percentagecomplete:string)=(' || REPLACE(REPLACE(current_row.percentagecomplete,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.jobid IS NOT NULL) THEN 
              fullText := fullText || '(jobid:string)=(' || REPLACE(REPLACE(current_row.jobid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.workflowData_info IS NOT NULL)) THEN
            fullText := fullText || '(workflowdata_info:integer)=(' || current_row.workflowdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_workflowData_meta_data(current_row.workflowData_info, child_count,$3,false,false);
              fullText := fullText || '(workflowdata_info_workflowdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.wrk_workflowdata_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_workflowdata_id:integer)=(' || current_row.wrk_workflowdata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_wrk_workflowdata_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 || '(wrk:workflowData_history)(';
      FOR current_row IN SELECT * FROM wrk_workflowData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.executionenvironment_wrk_abstractexecutionenvironment_id IS NOT NULL)) THEN
            fullText := fullText || '(executionenvironment_wrk_abstractexecutionenvironment_id:integer)=(' || current_row.executionenvironment_wrk_abstractexecutionenvironment_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM wrk_abstractExecutionEnvironment_history WHERE  wrk_abstractexecutionenvironment_id=current_row.executionenvironment_wrk_abstractexecutionenvironment_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_abstractExecutionEnvironment_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(executionenvironment_abstractexecutionenvironment:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.comments IS NOT NULL) THEN 
              fullText := fullText || '(comments:string)=(' || REPLACE(REPLACE(current_row.comments,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.details IS NOT NULL) THEN 
              fullText := fullText || '(details:string)=(' || REPLACE(REPLACE(current_row.details,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.justification IS NOT NULL) THEN 
              fullText := fullText || '(justification:string)=(' || REPLACE(REPLACE(current_row.justification,'(','*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.src IS NOT NULL) THEN 
              fullText := fullText || '(src:string)=(' || REPLACE(REPLACE(current_row.src,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.category IS NOT NULL) THEN 
              fullText := fullText || '(category:string)=(' || REPLACE(REPLACE(current_row.category,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.data_type IS NOT NULL) THEN 
              fullText := fullText || '(data_type:string)=(' || REPLACE(REPLACE(current_row.data_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.externalid IS NOT NULL) THEN 
              fullText := fullText || '(externalid:string)=(' || REPLACE(REPLACE(current_row.externalid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.current_step_launch_time IS NOT NULL) THEN 
              fullText := fullText || '(current_step_launch_time:dateTime)=(' || current_row.current_step_launch_time || ')';
          END IF;
          IF (current_row.current_step_id IS NOT NULL) THEN 
              fullText := fullText || '(current_step_id:string)=(' || REPLACE(REPLACE(current_row.current_step_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.create_user IS NOT NULL) THEN 
              fullText := fullText || '(create_user:string)=(' || REPLACE(REPLACE(current_row.create_user,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pipeline_name IS NOT NULL) THEN 
              fullText := fullText || '(pipeline_name:string)=(' || REPLACE(REPLACE(current_row.pipeline_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.next_step_id IS NOT NULL) THEN 
              fullText := fullText || '(next_step_id:string)=(' || REPLACE(REPLACE(current_row.next_step_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.step_description IS NOT NULL) THEN 
              fullText := fullText || '(step_description:string)=(' || REPLACE(REPLACE(current_row.step_description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.launch_time IS NOT NULL) THEN 
              fullText := fullText || '(launch_time:dateTime)=(' || current_row.launch_time || ')';
          END IF;
          IF (current_row.percentagecomplete IS NOT NULL) THEN 
              fullText := fullText || '(percentagecomplete:string)=(' || REPLACE(REPLACE(current_row.percentagecomplete,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.jobid IS NOT NULL) THEN 
              fullText := fullText || '(jobid:string)=(' || REPLACE(REPLACE(current_row.jobid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.workflowData_info IS NOT NULL)) THEN
            fullText := fullText || '(workflowdata_info:integer)=(' || current_row.workflowdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_workflowData_meta_data(current_row.workflowData_info, child_count,$3,false,false);
              fullText := fullText || '(workflowdata_info_workflowdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.wrk_workflowdata_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_workflowdata_id:integer)=(' || current_row.wrk_workflowdata_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_wrk_workflowdata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_workflowdata_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 || '(wrk:workflowData_meta_data)(';
      FOR current_row IN SELECT * FROM wrk_workflowData_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_wrk_workflowdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment(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 || '(wrk:xnatExecutionEnvironment)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment WHERE  wrk_abstractexecutionenvironment_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.wrk_abstractexecutionenvironment_id IS NOT NULL)) THEN
            fullText := fullText || '(wrk_abstractexecutionenvironment_id:integer)=(' || current_row.wrk_abstractexecutionenvironment_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_wrk_abstractExecutionEnvironment(current_row.wrk_abstractexecutionenvironment_id, child_count,$3,false,false);
              fullText := fullText || '(abstractexecutionenvironment_abstractexecutionenvironment:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.pipeline IS NOT NULL) THEN 
              fullText := fullText || '(pipeline:string)=(' || REPLACE(REPLACE(current_row.pipeline,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.xnatuser IS NOT NULL) THEN 
              fullText := fullText || '(xnatuser:string)=(' || REPLACE(REPLACE(current_row.xnatuser,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.host IS NOT NULL) THEN 
              fullText := fullText || '(host:string)=(' || REPLACE(REPLACE(current_row.host,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.startat IS NOT NULL) THEN 
              fullText := fullText || '(startat:string)=(' || REPLACE(REPLACE(current_row.startat,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM wrk_xnatExecutionEnvironment_parameter WHERE parameters_parameter_wrk_xnatEx_wrk_abstractexecutionenvironmen=current_row.wrk_abstractexecutionenvironment_id ORDER BY wrk_xnatexecutionenvironment_parameter_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_parameter( parent_row.wrk_xnatexecutionenvironment_parameter_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_parameter_xnatexecutionenvironment_parameter' || 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 wrk_xnatExecutionEnvironment_notify WHERE wrk_xnatExecutionEnvironment_wrk_abstractexecutionenvironmen=current_row.wrk_abstractexecutionenvironment_id ORDER BY wrk_xnatexecutionenvironment_notify_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_notify( parent_row.wrk_xnatexecutionenvironment_notify_id, child_count,$3,false,false);
              fullText := fullText || '(notify_xnatexecutionenvironment_notify' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.datatype IS NOT NULL) THEN 
              fullText := fullText || '(datatype:string)=(' || REPLACE(REPLACE(current_row.datatype,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.supressnotification IS NOT NULL) THEN 
              fullText := fullText || '(supressnotification:integer)=(' || current_row.supressnotification || ')';
          END IF;
          IF (current_row.log IS NOT NULL) THEN 
              fullText := fullText || '(log:string)=(' || REPLACE(REPLACE(current_row.log,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.catalogpath IS NOT NULL) THEN 
              fullText := fullText || '(catalogpath:string)=(' || REPLACE(REPLACE(current_row.catalogpath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterfile_xml IS NOT NULL) THEN 
              fullText := fullText || '(parameterfile_xml:string)=(' || REPLACE(REPLACE(current_row.parameterfile_xml,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterfile_path IS NOT NULL) THEN 
              fullText := fullText || '(parameterfile_path:string)=(' || REPLACE(REPLACE(current_row.parameterfile_path,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.xnatExecutionEnvironment_info IS NOT NULL)) THEN
            fullText := fullText || '(xnatexecutionenvironment_info:integer)=(' || current_row.xnatexecutionenvironment_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_meta_data(current_row.xnatExecutionEnvironment_info, child_count,$3,false,false);
              fullText := fullText || '(xnatexecutionenvironment_info_xnatexecutionenvironment_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_wrk_abstractExecutionEnvironment( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractexecutionenvironment_abstractexecutionenvironment:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_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 || '(wrk:xnatExecutionEnvironment_history)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.wrk_abstractexecutionenvironment_id IS NOT NULL)) THEN
            fullText := fullText || '(wrk_abstractexecutionenvironment_id:integer)=(' || current_row.wrk_abstractexecutionenvironment_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM wrk_abstractExecutionEnvironment_history WHERE wrk_abstractexecutionenvironment_id=current_row.wrk_abstractexecutionenvironment_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_wrk_abstractExecutionEnvironment_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(abstractexecutionenvironment_abstractexecutionenvironment:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.pipeline IS NOT NULL) THEN 
              fullText := fullText || '(pipeline:string)=(' || REPLACE(REPLACE(current_row.pipeline,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.xnatuser IS NOT NULL) THEN 
              fullText := fullText || '(xnatuser:string)=(' || REPLACE(REPLACE(current_row.xnatuser,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.host IS NOT NULL) THEN 
              fullText := fullText || '(host:string)=(' || REPLACE(REPLACE(current_row.host,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.startat IS NOT NULL) THEN 
              fullText := fullText || '(startat:string)=(' || REPLACE(REPLACE(current_row.startat,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM wrk_xnatExecutionEnvironment_parameter_history WHERE parameters_parameter_wrk_xnatEx_wrk_abstractexecutionenvironmen=current_row.wrk_abstractexecutionenvironment_id AND xft_version=current_row.xft_version ORDER BY wrk_xnatexecutionenvironment_parameter_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_parameter_history( parent_row.wrk_xnatexecutionenvironment_parameter_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_parameter_xnatexecutionenvironment_parameter' || 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 wrk_xnatExecutionEnvironment_notify_history WHERE wrk_xnatExecutionEnvironment_wrk_abstractexecutionenvironmen=current_row.wrk_abstractexecutionenvironment_id AND xft_version=current_row.xft_version ORDER BY wrk_xnatexecutionenvironment_notify_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_notify_history( parent_row.wrk_xnatexecutionenvironment_notify_id, child_count,$3,false,false);
              fullText := fullText || '(notify_xnatexecutionenvironment_notify' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.datatype IS NOT NULL) THEN 
              fullText := fullText || '(datatype:string)=(' || REPLACE(REPLACE(current_row.datatype,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.supressnotification IS NOT NULL) THEN 
              fullText := fullText || '(supressnotification:integer)=(' || current_row.supressnotification || ')';
          END IF;
          IF (current_row.log IS NOT NULL) THEN 
              fullText := fullText || '(log:string)=(' || REPLACE(REPLACE(current_row.log,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.catalogpath IS NOT NULL) THEN 
              fullText := fullText || '(catalogpath:string)=(' || REPLACE(REPLACE(current_row.catalogpath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterfile_xml IS NOT NULL) THEN 
              fullText := fullText || '(parameterfile_xml:string)=(' || REPLACE(REPLACE(current_row.parameterfile_xml,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterfile_path IS NOT NULL) THEN 
              fullText := fullText || '(parameterfile_path:string)=(' || REPLACE(REPLACE(current_row.parameterfile_path,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.xnatExecutionEnvironment_info IS NOT NULL)) THEN
            fullText := fullText || '(xnatexecutionenvironment_info:integer)=(' || current_row.xnatexecutionenvironment_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_meta_data(current_row.xnatExecutionEnvironment_info, child_count,$3,false,false);
              fullText := fullText || '(xnatexecutionenvironment_info_xnatexecutionenvironment_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_wrk_abstractExecutionEnvironment_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractexecutionenvironment_abstractexecutionenvironment:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_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 || '(wrk:xnatExecutionEnvironment_meta_data)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_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_wrk_xnatexecutionenvironment_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_notify(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 || '(wrk:xnatExecutionEnvironment_notify)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_notify WHERE  wrk_xnatexecutionenvironment_notify_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.notify IS NOT NULL) THEN 
              fullText := fullText || '(notify:string)=(' || REPLACE(REPLACE(current_row.notify,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.xnatExecutionEnvironment_notify_info IS NOT NULL)) THEN
            fullText := fullText || '(xnatexecutionenvironment_notify_info:integer)=(' || current_row.xnatexecutionenvironment_notify_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_notify_meta_data(current_row.xnatExecutionEnvironment_notify_info, child_count,$3,false,false);
              fullText := fullText || '(xnatexecutionenvironment_notify_info_xnatexecutionenvironment_notify_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.wrk_xnatExecutionEnvironment_wrk_abstractexecutionenvironmen IS NOT NULL)) THEN
            fullText := fullText || '(wrk_xnatexecutionenvironment_wrk_abstractexecutionenvironmen:integer)=(' || current_row.wrk_xnatexecutionenvironment_wrk_abstractexecutionenvironmen || ')';
        END IF;
          IF (current_row.wrk_xnatexecutionenvironment_notify_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_xnatexecutionenvironment_notify_id:integer)=(' || current_row.wrk_xnatexecutionenvironment_notify_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_notify_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 || '(wrk:xnatExecutionEnvironment_notify_history)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_notify_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.notify IS NOT NULL) THEN 
              fullText := fullText || '(notify:string)=(' || REPLACE(REPLACE(current_row.notify,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.xnatExecutionEnvironment_notify_info IS NOT NULL)) THEN
            fullText := fullText || '(xnatexecutionenvironment_notify_info:integer)=(' || current_row.xnatexecutionenvironment_notify_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_notify_meta_data(current_row.xnatExecutionEnvironment_notify_info, child_count,$3,false,false);
              fullText := fullText || '(xnatexecutionenvironment_notify_info_xnatexecutionenvironment_notify_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.wrk_xnatExecutionEnvironment_wrk_abstractexecutionenvironmen IS NOT NULL)) THEN
            fullText := fullText || '(wrk_xnatexecutionenvironment_wrk_abstractexecutionenvironmen:integer)=(' || current_row.wrk_xnatexecutionenvironment_wrk_abstractexecutionenvironmen || ')';
        END IF;
          IF (current_row.wrk_xnatexecutionenvironment_notify_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_xnatexecutionenvironment_notify_id:integer)=(' || current_row.wrk_xnatexecutionenvironment_notify_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_wrk_xnatexecutionenvironment_notify_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_notify_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 || '(wrk:xnatExecutionEnvironment_notify_meta_data)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_notify_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_wrk_xnatexecutionenvironment_notify_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_parameter(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 || '(wrk:xnatExecutionEnvironment_parameter)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_parameter WHERE  wrk_xnatexecutionenvironment_parameter_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.parameter IS NOT NULL) THEN 
              fullText := fullText || '(parameter:string)=(' || REPLACE(REPLACE(current_row.parameter,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.xnatExecutionEnvironment_parameter_info IS NOT NULL)) THEN
            fullText := fullText || '(xnatexecutionenvironment_parameter_info:integer)=(' || current_row.xnatexecutionenvironment_parameter_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_parameter_meta_data(current_row.xnatExecutionEnvironment_parameter_info, child_count,$3,false,false);
              fullText := fullText || '(xnatexecutionenvironment_parameter_info_xnatexecutionenvironment_parameter_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_parameter_wrk_xnatEx_wrk_abstractexecutionenvironmen IS NOT NULL)) THEN
            fullText := fullText || '(parameters_parameter_wrk_xnatex_wrk_abstractexecutionenvironmen:integer)=(' || current_row.parameters_parameter_wrk_xnatex_wrk_abstractexecutionenvironmen || ')';
        END IF;
          IF (current_row.wrk_xnatexecutionenvironment_parameter_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_xnatexecutionenvironment_parameter_id:integer)=(' || current_row.wrk_xnatexecutionenvironment_parameter_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_parameter_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 || '(wrk:xnatExecutionEnvironment_parameter_history)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_parameter_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.parameter IS NOT NULL) THEN 
              fullText := fullText || '(parameter:string)=(' || REPLACE(REPLACE(current_row.parameter,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.xnatExecutionEnvironment_parameter_info IS NOT NULL)) THEN
            fullText := fullText || '(xnatexecutionenvironment_parameter_info:integer)=(' || current_row.xnatexecutionenvironment_parameter_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_xnatExecutionEnvironment_parameter_meta_data(current_row.xnatExecutionEnvironment_parameter_info, child_count,$3,false,false);
              fullText := fullText || '(xnatexecutionenvironment_parameter_info_xnatexecutionenvironment_parameter_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_parameter_wrk_xnatEx_wrk_abstractexecutionenvironmen IS NOT NULL)) THEN
            fullText := fullText || '(parameters_parameter_wrk_xnatex_wrk_abstractexecutionenvironmen:integer)=(' || current_row.parameters_parameter_wrk_xnatex_wrk_abstractexecutionenvironmen || ')';
        END IF;
          IF (current_row.wrk_xnatexecutionenvironment_parameter_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_xnatexecutionenvironment_parameter_id:integer)=(' || current_row.wrk_xnatexecutionenvironment_parameter_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_wrk_xnatexecutionenvironment_parameter_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_wrk_xnatexecutionenvironment_parameter_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 || '(wrk:xnatExecutionEnvironment_parameter_meta_data)(';
      FOR current_row IN SELECT * FROM wrk_xnatExecutionEnvironment_parameter_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_wrk_xnatexecutionenvironment_parameter_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_access_log(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:access_log)(';
      FOR current_row IN SELECT * FROM xdat_access_log WHERE  xdat_access_log_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.access_date IS NOT NULL) THEN 
              fullText := fullText || '(access_date:dateTime)=(' || current_row.access_date || ')';
          END IF;
          IF (current_row.ip IS NOT NULL) THEN 
              fullText := fullText || '(ip:string)=(' || REPLACE(REPLACE(current_row.ip,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.method IS NOT NULL) THEN 
              fullText := fullText || '(method:string)=(' || REPLACE(REPLACE(current_row.method,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.access_log_info IS NOT NULL)) THEN
            fullText := fullText || '(access_log_info:integer)=(' || current_row.access_log_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_access_log_meta_data(current_row.access_log_info, child_count,$3,false,false);
              fullText := fullText || '(access_log_info_access_log_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_access_log_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_access_log_id:integer)=(' || current_row.xdat_access_log_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_access_log_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:access_log_history)(';
      FOR current_row IN SELECT * FROM xdat_access_log_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.access_date IS NOT NULL) THEN 
              fullText := fullText || '(access_date:dateTime)=(' || current_row.access_date || ')';
          END IF;
          IF (current_row.ip IS NOT NULL) THEN 
              fullText := fullText || '(ip:string)=(' || REPLACE(REPLACE(current_row.ip,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.method IS NOT NULL) THEN 
              fullText := fullText || '(method:string)=(' || REPLACE(REPLACE(current_row.method,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.access_log_info IS NOT NULL)) THEN
            fullText := fullText || '(access_log_info:integer)=(' || current_row.access_log_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_access_log_meta_data(current_row.access_log_info, child_count,$3,false,false);
              fullText := fullText || '(access_log_info_access_log_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_access_log_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_access_log_id:integer)=(' || current_row.xdat_access_log_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_access_log_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_access_log_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:access_log_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_access_log_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_access_log_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_action_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:action_type)(';
      FOR current_row IN SELECT * FROM xdat_action_type WHERE  action_name=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.action_name IS NOT NULL) THEN 
              fullText := fullText || '(action_name:string)=(' || REPLACE(REPLACE(current_row.action_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display_name IS NOT NULL) THEN 
              fullText := fullText || '(display_name:string)=(' || REPLACE(REPLACE(current_row.display_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
        IF ((current_row.action_type_info IS NOT NULL)) THEN
            fullText := fullText || '(action_type_info:integer)=(' || current_row.action_type_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_action_type_meta_data(current_row.action_type_info, child_count,$3,false,false);
              fullText := fullText || '(action_type_info_action_type_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.actions_action_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(actions_action_xdat_security_xdat_security_id:integer)=(' || current_row.actions_action_xdat_security_xdat_security_id || ')';
        END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_action_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:action_type_history)(';
      FOR current_row IN SELECT * FROM xdat_action_type_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.action_name IS NOT NULL) THEN 
              fullText := fullText || '(action_name:string)=(' || REPLACE(REPLACE(current_row.action_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display_name IS NOT NULL) THEN 
              fullText := fullText || '(display_name:string)=(' || REPLACE(REPLACE(current_row.display_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
        IF ((current_row.action_type_info IS NOT NULL)) THEN
            fullText := fullText || '(action_type_info:integer)=(' || current_row.action_type_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_action_type_meta_data(current_row.action_type_info, child_count,$3,false,false);
              fullText := fullText || '(action_type_info_action_type_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.actions_action_xdat_security_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(actions_action_xdat_security_xdat_security_id:integer)=(' || current_row.actions_action_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_action_type_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_action_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:action_type_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_action_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_action_type_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_change_info(bigint, 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:change_info)(';
      FOR current_row IN SELECT * FROM xdat_change_info WHERE  xdat_change_info_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.change_user IS NOT NULL)) THEN
            fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user(current_row.change_user, child_count,$3,false,false);
              fullText := fullText || '(change_user_user:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.comment IS NOT NULL) THEN 
              fullText := fullText || '(comment:string)=(' || REPLACE(REPLACE(current_row.comment,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.event_id IS NOT NULL) THEN 
              fullText := fullText || '(event_id:integer)=(' || current_row.event_id || ')';
          END IF;
          IF (current_row.xdat_change_info_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_change_info_id:long)=(' || current_row.xdat_change_info_id || ')';
          END IF;
        IF ((current_row.change_info_info IS NOT NULL)) THEN
            fullText := fullText || '(change_info_info:integer)=(' || current_row.change_info_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_change_info_meta_data(current_row.change_info_info, child_count,$3,false,false);
              fullText := fullText || '(change_info_info_change_info_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_change_info_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:change_info_history)(';
      FOR current_row IN SELECT * FROM xdat_change_info_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.change_user IS NOT NULL)) THEN
            fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
 -- 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.change_user 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 || '(change_user_user:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.comment IS NOT NULL) THEN 
              fullText := fullText || '(comment:string)=(' || REPLACE(REPLACE(current_row.comment,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.event_id IS NOT NULL) THEN 
              fullText := fullText || '(event_id:integer)=(' || current_row.event_id || ')';
          END IF;
          IF (current_row.xdat_change_info_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_change_info_id:long)=(' || current_row.xdat_change_info_id || ')';
          END IF;
        IF ((current_row.change_info_info IS NOT NULL)) THEN
            fullText := fullText || '(change_info_info:integer)=(' || current_row.change_info_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_change_info_meta_data(current_row.change_info_info, child_count,$3,false,false);
              fullText := fullText || '(change_info_info_change_info_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;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_change_info_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:change_info_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_change_info_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_change_info_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_criteria(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:criteria)(';
      FOR current_row IN SELECT * FROM xdat_criteria WHERE  xdat_criteria_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.schema_field IS NOT NULL) THEN 
              fullText := fullText || '(schema_field:string)=(' || REPLACE(REPLACE(current_row.schema_field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.comparison_type IS NOT NULL) THEN 
              fullText := fullText || '(comparison_type:string)=(' || REPLACE(REPLACE(current_row.comparison_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.custom_search IS NOT NULL) THEN 
              fullText := fullText || '(custom_search:string)=(' || REPLACE(REPLACE(current_row.custom_search,'(','*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.override_value_formatting IS NOT NULL) THEN 
              fullText := fullText || '(override_value_formatting:integer)=(' || current_row.override_value_formatting || ')';
          END IF;
        IF ((current_row.criteria_info IS NOT NULL)) THEN
            fullText := fullText || '(criteria_info:integer)=(' || current_row.criteria_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria_meta_data(current_row.criteria_info, child_count,$3,false,false);
              fullText := fullText || '(criteria_info_criteria_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_criteria_set_xdat_criteria_set_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_criteria_set_xdat_criteria_set_id:integer)=(' || current_row.xdat_criteria_set_xdat_criteria_set_id || ')';
        END IF;
          IF (current_row.xdat_criteria_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_criteria_id:integer)=(' || current_row.xdat_criteria_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_criteria_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:criteria_history)(';
      FOR current_row IN SELECT * FROM xdat_criteria_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.schema_field IS NOT NULL) THEN 
              fullText := fullText || '(schema_field:string)=(' || REPLACE(REPLACE(current_row.schema_field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.comparison_type IS NOT NULL) THEN 
              fullText := fullText || '(comparison_type:string)=(' || REPLACE(REPLACE(current_row.comparison_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.custom_search IS NOT NULL) THEN 
              fullText := fullText || '(custom_search:string)=(' || REPLACE(REPLACE(current_row.custom_search,'(','*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.override_value_formatting IS NOT NULL) THEN 
              fullText := fullText || '(override_value_formatting:integer)=(' || current_row.override_value_formatting || ')';
          END IF;
        IF ((current_row.criteria_info IS NOT NULL)) THEN
            fullText := fullText || '(criteria_info:integer)=(' || current_row.criteria_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria_meta_data(current_row.criteria_info, child_count,$3,false,false);
              fullText := fullText || '(criteria_info_criteria_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_criteria_set_xdat_criteria_set_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_criteria_set_xdat_criteria_set_id:integer)=(' || current_row.xdat_criteria_set_xdat_criteria_set_id || ')';
        END IF;
          IF (current_row.xdat_criteria_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_criteria_id:integer)=(' || current_row.xdat_criteria_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_criteria_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_criteria_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:criteria_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_criteria_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_criteria_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_criteria_set(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:criteria_set)(';
      FOR current_row IN SELECT * FROM xdat_criteria_set WHERE  xdat_criteria_set_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_criteria WHERE xdat_criteria_set_xdat_criteria_set_id=current_row.xdat_criteria_set_id ORDER BY xdat_criteria_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria( parent_row.xdat_criteria_id, child_count,$3,false,false);
              fullText := fullText || '(criteria_criteria' || 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_criteria_set WHERE child_set_xdat_criteria_set_id=current_row.xdat_criteria_set_id ORDER BY xdat_criteria_set_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria_set( parent_row.xdat_criteria_set_id, child_count,$3,false,false);
              fullText := fullText || '(child_set_criteria_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.method IS NOT NULL) THEN 
              fullText := fullText || '(method:string)=(' || REPLACE(REPLACE(current_row.method,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.criteria_set_info IS NOT NULL)) THEN
            fullText := fullText || '(criteria_set_info:integer)=(' || current_row.criteria_set_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria_set_meta_data(current_row.criteria_set_info, child_count,$3,false,false);
              fullText := fullText || '(criteria_set_info_criteria_set_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_criteria_set_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_criteria_set_id:integer)=(' || current_row.xdat_criteria_set_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_criteria_set_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:criteria_set_history)(';
      FOR current_row IN SELECT * FROM xdat_criteria_set_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_criteria_history WHERE xdat_criteria_set_xdat_criteria_set_id=current_row.xdat_criteria_set_id AND xft_version=current_row.xft_version ORDER BY xdat_criteria_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria_history( parent_row.xdat_criteria_id, child_count,$3,false,false);
              fullText := fullText || '(criteria_criteria' || 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_criteria_set_history WHERE child_set_xdat_criteria_set_id=current_row.xdat_criteria_set_id AND xft_version=current_row.xft_version ORDER BY xdat_criteria_set_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria_set_history( parent_row.xdat_criteria_set_id, child_count,$3,false,false);
              fullText := fullText || '(child_set_criteria_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.method IS NOT NULL) THEN 
              fullText := fullText || '(method:string)=(' || REPLACE(REPLACE(current_row.method,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.criteria_set_info IS NOT NULL)) THEN
            fullText := fullText || '(criteria_set_info:integer)=(' || current_row.criteria_set_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_criteria_set_meta_data(current_row.criteria_set_info, child_count,$3,false,false);
              fullText := fullText || '(criteria_set_info_criteria_set_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_criteria_set_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_criteria_set_id:integer)=(' || current_row.xdat_criteria_set_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_criteria_set_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_criteria_set_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:criteria_set_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_criteria_set_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_criteria_set_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_access(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:element_access)(';
      FOR current_row IN SELECT * FROM xdat_element_access WHERE  xdat_element_access_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.secondary_password IS NOT NULL) THEN 
              fullText := fullText || '(secondary_password:string)=(' || REPLACE(REPLACE(current_row.secondary_password,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secondary_password_encrypt IS NOT NULL) THEN 
              fullText := fullText || '(secondary_password_encrypt:integer)=(' || current_row.secondary_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_secure_ip WHERE xdat_element_access_xdat_element_access_id=current_row.xdat_element_access_id ORDER BY xdat_element_access_secure_ip_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_secure_ip( parent_row.xdat_element_access_secure_ip_id, child_count,$3,false,false);
              fullText := fullText || '(secure_ip_element_access_secure_ip' || 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_field_mapping_set WHERE permissions_allow_set_xdat_elem_xdat_element_access_id=current_row.xdat_element_access_id ORDER BY xdat_field_mapping_set_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_set( parent_row.xdat_field_mapping_set_id, child_count,$3,false,false);
              fullText := fullText || '(permissions_allow_set_field_mapping_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          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.element_access_info IS NOT NULL)) THEN
            fullText := fullText || '(element_access_info:integer)=(' || current_row.element_access_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_meta_data(current_row.element_access_info, child_count,$3,false,false);
              fullText := fullText || '(element_access_info_element_access_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_user_xdat_user_id:integer)=(' || current_row.xdat_user_xdat_user_id || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_userGroup_xdat_usergroup_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_usergroup_xdat_usergroup_id:integer)=(' || current_row.xdat_usergroup_xdat_usergroup_id || ')';
        END IF;
          IF (current_row.xdat_element_access_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_access_id:integer)=(' || current_row.xdat_element_access_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_element_access_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:element_access_history)(';
      FOR current_row IN SELECT * FROM xdat_element_access_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.secondary_password IS NOT NULL) THEN 
              fullText := fullText || '(secondary_password:string)=(' || REPLACE(REPLACE(current_row.secondary_password,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secondary_password_encrypt IS NOT NULL) THEN 
              fullText := fullText || '(secondary_password_encrypt:integer)=(' || current_row.secondary_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_secure_ip_history WHERE xdat_element_access_xdat_element_access_id=current_row.xdat_element_access_id AND xft_version=current_row.xft_version ORDER BY xdat_element_access_secure_ip_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_secure_ip_history( parent_row.xdat_element_access_secure_ip_id, child_count,$3,false,false);
              fullText := fullText || '(secure_ip_element_access_secure_ip' || 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_field_mapping_set_history WHERE permissions_allow_set_xdat_elem_xdat_element_access_id=current_row.xdat_element_access_id AND xft_version=current_row.xft_version ORDER BY xdat_field_mapping_set_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_set_history( parent_row.xdat_field_mapping_set_id, child_count,$3,false,false);
              fullText := fullText || '(permissions_allow_set_field_mapping_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          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.element_access_info IS NOT NULL)) THEN
            fullText := fullText || '(element_access_info:integer)=(' || current_row.element_access_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_meta_data(current_row.element_access_info, child_count,$3,false,false);
              fullText := fullText || '(element_access_info_element_access_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_user_xdat_user_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_user_xdat_user_id:integer)=(' || current_row.xdat_user_xdat_user_id || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_userGroup_xdat_usergroup_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_usergroup_xdat_usergroup_id:integer)=(' || current_row.xdat_usergroup_xdat_usergroup_id || ')';
        END IF;
          IF (current_row.xdat_element_access_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_access_id:integer)=(' || current_row.xdat_element_access_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_element_access_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_access_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:element_access_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_element_access_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_element_access_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_access_secure_ip(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:element_access_secure_ip)(';
      FOR current_row IN SELECT * FROM xdat_element_access_secure_ip WHERE  xdat_element_access_secure_ip_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.secure_ip IS NOT NULL) THEN 
              fullText := fullText || '(secure_ip:string)=(' || REPLACE(REPLACE(current_row.secure_ip,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_access_secure_ip_info IS NOT NULL)) THEN
            fullText := fullText || '(element_access_secure_ip_info:integer)=(' || current_row.element_access_secure_ip_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_secure_ip_meta_data(current_row.element_access_secure_ip_info, child_count,$3,false,false);
              fullText := fullText || '(element_access_secure_ip_info_element_access_secure_ip_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_element_access_xdat_element_access_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_element_access_xdat_element_access_id:integer)=(' || current_row.xdat_element_access_xdat_element_access_id || ')';
        END IF;
          IF (current_row.xdat_element_access_secure_ip_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_access_secure_ip_id:integer)=(' || current_row.xdat_element_access_secure_ip_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_element_access_secure_ip_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:element_access_secure_ip_history)(';
      FOR current_row IN SELECT * FROM xdat_element_access_secure_ip_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.secure_ip IS NOT NULL) THEN 
              fullText := fullText || '(secure_ip:string)=(' || REPLACE(REPLACE(current_row.secure_ip,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_access_secure_ip_info IS NOT NULL)) THEN
            fullText := fullText || '(element_access_secure_ip_info:integer)=(' || current_row.element_access_secure_ip_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_access_secure_ip_meta_data(current_row.element_access_secure_ip_info, child_count,$3,false,false);
              fullText := fullText || '(element_access_secure_ip_info_element_access_secure_ip_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_element_access_xdat_element_access_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_element_access_xdat_element_access_id:integer)=(' || current_row.xdat_element_access_xdat_element_access_id || ')';
        END IF;
          IF (current_row.xdat_element_access_secure_ip_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_access_secure_ip_id:integer)=(' || current_row.xdat_element_access_secure_ip_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_element_access_secure_ip_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_access_secure_ip_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:element_access_secure_ip_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_element_access_secure_ip_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_element_access_secure_ip_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_action_type(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:element_action_type)(';
      FOR current_row IN SELECT * FROM xdat_element_action_type WHERE  xdat_element_action_type_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.element_action_name IS NOT NULL) THEN 
              fullText := fullText || '(element_action_name:string)=(' || REPLACE(REPLACE(current_row.element_action_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display_name IS NOT NULL) THEN 
              fullText := fullText || '(display_name:string)=(' || REPLACE(REPLACE(current_row.display_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.image IS NOT NULL) THEN 
              fullText := fullText || '(image:string)=(' || REPLACE(REPLACE(current_row.image,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.popup IS NOT NULL) THEN 
              fullText := fullText || '(popup:string)=(' || REPLACE(REPLACE(current_row.popup,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secureaccess IS NOT NULL) THEN 
              fullText := fullText || '(secureaccess:string)=(' || REPLACE(REPLACE(current_row.secureaccess,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.securefeature IS NOT NULL) THEN 
              fullText := fullText || '(securefeature:string)=(' || REPLACE(REPLACE(current_row.securefeature,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterstring IS NOT NULL) THEN 
              fullText := fullText || '(parameterstring:string)=(' || REPLACE(REPLACE(current_row.parameterstring,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.grouping IS NOT NULL) THEN 
              fullText := fullText || '(grouping:string)=(' || REPLACE(REPLACE(current_row.grouping,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_action_type_info IS NOT NULL)) THEN
            fullText := fullText || '(element_action_type_info:integer)=(' || current_row.element_action_type_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_action_type_meta_data(current_row.element_action_type_info, child_count,$3,false,false);
              fullText := fullText || '(element_action_type_info_element_action_type_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.element_actions_element_action__element_name IS NOT NULL)) THEN
            fullText := fullText || '(element_actions_element_action__element_name:string)=(' || current_row.element_actions_element_action__element_name || ')';
        END IF;
          IF (current_row.xdat_element_action_type_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_action_type_id:integer)=(' || current_row.xdat_element_action_type_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_element_action_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:element_action_type_history)(';
      FOR current_row IN SELECT * FROM xdat_element_action_type_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.element_action_name IS NOT NULL) THEN 
              fullText := fullText || '(element_action_name:string)=(' || REPLACE(REPLACE(current_row.element_action_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display_name IS NOT NULL) THEN 
              fullText := fullText || '(display_name:string)=(' || REPLACE(REPLACE(current_row.display_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.image IS NOT NULL) THEN 
              fullText := fullText || '(image:string)=(' || REPLACE(REPLACE(current_row.image,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.popup IS NOT NULL) THEN 
              fullText := fullText || '(popup:string)=(' || REPLACE(REPLACE(current_row.popup,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secureaccess IS NOT NULL) THEN 
              fullText := fullText || '(secureaccess:string)=(' || REPLACE(REPLACE(current_row.secureaccess,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.securefeature IS NOT NULL) THEN 
              fullText := fullText || '(securefeature:string)=(' || REPLACE(REPLACE(current_row.securefeature,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterstring IS NOT NULL) THEN 
              fullText := fullText || '(parameterstring:string)=(' || REPLACE(REPLACE(current_row.parameterstring,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.grouping IS NOT NULL) THEN 
              fullText := fullText || '(grouping:string)=(' || REPLACE(REPLACE(current_row.grouping,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_action_type_info IS NOT NULL)) THEN
            fullText := fullText || '(element_action_type_info:integer)=(' || current_row.element_action_type_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_action_type_meta_data(current_row.element_action_type_info, child_count,$3,false,false);
              fullText := fullText || '(element_action_type_info_element_action_type_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.element_actions_element_action__element_name IS NOT NULL)) THEN
            fullText := fullText || '(element_actions_element_action__element_name:string)=(' || current_row.element_actions_element_action__element_name || ')';
        END IF;
          IF (current_row.xdat_element_action_type_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_action_type_id:integer)=(' || current_row.xdat_element_action_type_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_element_action_type_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_action_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:element_action_type_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_element_action_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_element_action_type_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_security(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:element_security)(';
      FOR current_row IN SELECT * FROM xdat_element_security WHERE  element_name=$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_primary_security_field WHERE primary_security_fields_primary_element_name=current_row.element_name ORDER BY xdat_primary_security_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_primary_security_field( parent_row.xdat_primary_security_field_id, child_count,$3,false,false);
              fullText := fullText || '(primary_security_fields_primary_security_field_primary_security_field' || 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_action_type WHERE element_actions_element_action__element_name=current_row.element_name ORDER BY xdat_element_action_type_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_action_type( parent_row.xdat_element_action_type_id, child_count,$3,false,false);
              fullText := fullText || '(element_actions_element_action_element_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_listing_action WHERE listing_actions_listing_action__element_name=current_row.element_name ORDER BY xdat_element_security_listing_action_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security_listing_action( parent_row.xdat_element_security_listing_action_id, child_count,$3,false,false);
              fullText := fullText || '(listing_actions_listing_action_element_security_listing_action' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          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.secondary_password IS NOT NULL) THEN 
              fullText := fullText || '(secondary_password:integer)=(' || current_row.secondary_password || ')';
          END IF;
          IF (current_row.secure_ip IS NOT NULL) THEN 
              fullText := fullText || '(secure_ip:integer)=(' || current_row.secure_ip || ')';
          END IF;
          IF (current_row.secure IS NOT NULL) THEN 
              fullText := fullText || '(secure:integer)=(' || current_row.secure || ')';
          END IF;
          IF (current_row.browse IS NOT NULL) THEN 
              fullText := fullText || '(browse:integer)=(' || current_row.browse || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.quarantine IS NOT NULL) THEN 
              fullText := fullText || '(quarantine:integer)=(' || current_row.quarantine || ')';
          END IF;
          IF (current_row.pre_load IS NOT NULL) THEN 
              fullText := fullText || '(pre_load:integer)=(' || current_row.pre_load || ')';
          END IF;
          IF (current_row.searchable IS NOT NULL) THEN 
              fullText := fullText || '(searchable:integer)=(' || current_row.searchable || ')';
          END IF;
          IF (current_row.secure_read IS NOT NULL) THEN 
              fullText := fullText || '(secure_read:integer)=(' || current_row.secure_read || ')';
          END IF;
          IF (current_row.secure_edit IS NOT NULL) THEN 
              fullText := fullText || '(secure_edit:integer)=(' || current_row.secure_edit || ')';
          END IF;
          IF (current_row.secure_create IS NOT NULL) THEN 
              fullText := fullText || '(secure_create:integer)=(' || current_row.secure_create || ')';
          END IF;
          IF (current_row.secure_delete IS NOT NULL) THEN 
              fullText := fullText || '(secure_delete:integer)=(' || current_row.secure_delete || ')';
          END IF;
          IF (current_row.accessible IS NOT NULL) THEN 
              fullText := fullText || '(accessible:integer)=(' || current_row.accessible || ')';
          END IF;
          IF (current_row.usage IS NOT NULL) THEN 
              fullText := fullText || '(usage:string)=(' || REPLACE(REPLACE(current_row.usage,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.singular IS NOT NULL) THEN 
              fullText := fullText || '(singular:string)=(' || REPLACE(REPLACE(current_row.singular,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.plural IS NOT NULL) THEN 
              fullText := fullText || '(plural:string)=(' || REPLACE(REPLACE(current_row.plural,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.category IS NOT NULL) THEN 
              fullText := fullText || '(category:string)=(' || REPLACE(REPLACE(current_row.category,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.code IS NOT NULL) THEN 
              fullText := fullText || '(code:string)=(' || REPLACE(REPLACE(current_row.code,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_security_info IS NOT NULL)) THEN
            fullText := fullText || '(element_security_info:integer)=(' || current_row.element_security_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security_meta_data(current_row.element_security_info, child_count,$3,false,false);
              fullText := fullText || '(element_security_info_element_security_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.element_security_set_element_se_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(element_security_set_element_se_xdat_security_id:integer)=(' || current_row.element_security_set_element_se_xdat_security_id || ')';
        END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_element_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:element_security_history)(';
      FOR current_row IN SELECT * FROM xdat_element_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_primary_security_field_history WHERE primary_security_fields_primary_element_name=current_row.element_name AND xft_version=current_row.xft_version ORDER BY xdat_primary_security_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_primary_security_field_history( parent_row.xdat_primary_security_field_id, child_count,$3,false,false);
              fullText := fullText || '(primary_security_fields_primary_security_field_primary_security_field' || 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_action_type_history WHERE element_actions_element_action__element_name=current_row.element_name AND xft_version=current_row.xft_version ORDER BY xdat_element_action_type_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_action_type_history( parent_row.xdat_element_action_type_id, child_count,$3,false,false);
              fullText := fullText || '(element_actions_element_action_element_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_listing_action_history WHERE listing_actions_listing_action__element_name=current_row.element_name AND xft_version=current_row.xft_version ORDER BY xdat_element_security_listing_action_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security_listing_action_history( parent_row.xdat_element_security_listing_action_id, child_count,$3,false,false);
              fullText := fullText || '(listing_actions_listing_action_element_security_listing_action' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          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.secondary_password IS NOT NULL) THEN 
              fullText := fullText || '(secondary_password:integer)=(' || current_row.secondary_password || ')';
          END IF;
          IF (current_row.secure_ip IS NOT NULL) THEN 
              fullText := fullText || '(secure_ip:integer)=(' || current_row.secure_ip || ')';
          END IF;
          IF (current_row.secure IS NOT NULL) THEN 
              fullText := fullText || '(secure:integer)=(' || current_row.secure || ')';
          END IF;
          IF (current_row.browse IS NOT NULL) THEN 
              fullText := fullText || '(browse:integer)=(' || current_row.browse || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.quarantine IS NOT NULL) THEN 
              fullText := fullText || '(quarantine:integer)=(' || current_row.quarantine || ')';
          END IF;
          IF (current_row.pre_load IS NOT NULL) THEN 
              fullText := fullText || '(pre_load:integer)=(' || current_row.pre_load || ')';
          END IF;
          IF (current_row.searchable IS NOT NULL) THEN 
              fullText := fullText || '(searchable:integer)=(' || current_row.searchable || ')';
          END IF;
          IF (current_row.secure_read IS NOT NULL) THEN 
              fullText := fullText || '(secure_read:integer)=(' || current_row.secure_read || ')';
          END IF;
          IF (current_row.secure_edit IS NOT NULL) THEN 
              fullText := fullText || '(secure_edit:integer)=(' || current_row.secure_edit || ')';
          END IF;
          IF (current_row.secure_create IS NOT NULL) THEN 
              fullText := fullText || '(secure_create:integer)=(' || current_row.secure_create || ')';
          END IF;
          IF (current_row.secure_delete IS NOT NULL) THEN 
              fullText := fullText || '(secure_delete:integer)=(' || current_row.secure_delete || ')';
          END IF;
          IF (current_row.accessible IS NOT NULL) THEN 
              fullText := fullText || '(accessible:integer)=(' || current_row.accessible || ')';
          END IF;
          IF (current_row.usage IS NOT NULL) THEN 
              fullText := fullText || '(usage:string)=(' || REPLACE(REPLACE(current_row.usage,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.singular IS NOT NULL) THEN 
              fullText := fullText || '(singular:string)=(' || REPLACE(REPLACE(current_row.singular,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.plural IS NOT NULL) THEN 
              fullText := fullText || '(plural:string)=(' || REPLACE(REPLACE(current_row.plural,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.category IS NOT NULL) THEN 
              fullText := fullText || '(category:string)=(' || REPLACE(REPLACE(current_row.category,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.code IS NOT NULL) THEN 
              fullText := fullText || '(code:string)=(' || REPLACE(REPLACE(current_row.code,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_security_info IS NOT NULL)) THEN
            fullText := fullText || '(element_security_info:integer)=(' || current_row.element_security_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security_meta_data(current_row.element_security_info, child_count,$3,false,false);
              fullText := fullText || '(element_security_info_element_security_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.element_security_set_element_se_xdat_security_id IS NOT NULL)) THEN
            fullText := fullText || '(element_security_set_element_se_xdat_security_id:integer)=(' || current_row.element_security_set_element_se_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_element_security_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_security_listing_action(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:element_security_listing_action)(';
      FOR current_row IN SELECT * FROM xdat_element_security_listing_action WHERE  xdat_element_security_listing_action_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.element_action_name IS NOT NULL) THEN 
              fullText := fullText || '(element_action_name:string)=(' || REPLACE(REPLACE(current_row.element_action_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display_name IS NOT NULL) THEN 
              fullText := fullText || '(display_name:string)=(' || REPLACE(REPLACE(current_row.display_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.image IS NOT NULL) THEN 
              fullText := fullText || '(image:string)=(' || REPLACE(REPLACE(current_row.image,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.popup IS NOT NULL) THEN 
              fullText := fullText || '(popup:string)=(' || REPLACE(REPLACE(current_row.popup,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secureaccess IS NOT NULL) THEN 
              fullText := fullText || '(secureaccess:string)=(' || REPLACE(REPLACE(current_row.secureaccess,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.securefeature IS NOT NULL) THEN 
              fullText := fullText || '(securefeature:string)=(' || REPLACE(REPLACE(current_row.securefeature,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterstring IS NOT NULL) THEN 
              fullText := fullText || '(parameterstring:string)=(' || REPLACE(REPLACE(current_row.parameterstring,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_security_listing_action_info IS NOT NULL)) THEN
            fullText := fullText || '(element_security_listing_action_info:integer)=(' || current_row.element_security_listing_action_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security_listing_action_meta_data(current_row.element_security_listing_action_info, child_count,$3,false,false);
              fullText := fullText || '(element_security_listing_action_info_element_security_listing_action_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.listing_actions_listing_action__element_name IS NOT NULL)) THEN
            fullText := fullText || '(listing_actions_listing_action__element_name:string)=(' || current_row.listing_actions_listing_action__element_name || ')';
        END IF;
          IF (current_row.xdat_element_security_listing_action_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_security_listing_action_id:integer)=(' || current_row.xdat_element_security_listing_action_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_element_security_listing_action_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:element_security_listing_action_history)(';
      FOR current_row IN SELECT * FROM xdat_element_security_listing_action_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.element_action_name IS NOT NULL) THEN 
              fullText := fullText || '(element_action_name:string)=(' || REPLACE(REPLACE(current_row.element_action_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display_name IS NOT NULL) THEN 
              fullText := fullText || '(display_name:string)=(' || REPLACE(REPLACE(current_row.display_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.image IS NOT NULL) THEN 
              fullText := fullText || '(image:string)=(' || REPLACE(REPLACE(current_row.image,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.popup IS NOT NULL) THEN 
              fullText := fullText || '(popup:string)=(' || REPLACE(REPLACE(current_row.popup,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secureaccess IS NOT NULL) THEN 
              fullText := fullText || '(secureaccess:string)=(' || REPLACE(REPLACE(current_row.secureaccess,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.securefeature IS NOT NULL) THEN 
              fullText := fullText || '(securefeature:string)=(' || REPLACE(REPLACE(current_row.securefeature,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameterstring IS NOT NULL) THEN 
              fullText := fullText || '(parameterstring:string)=(' || REPLACE(REPLACE(current_row.parameterstring,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.element_security_listing_action_info IS NOT NULL)) THEN
            fullText := fullText || '(element_security_listing_action_info:integer)=(' || current_row.element_security_listing_action_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_element_security_listing_action_meta_data(current_row.element_security_listing_action_info, child_count,$3,false,false);
              fullText := fullText || '(element_security_listing_action_info_element_security_listing_action_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.listing_actions_listing_action__element_name IS NOT NULL)) THEN
            fullText := fullText || '(listing_actions_listing_action__element_name:string)=(' || current_row.listing_actions_listing_action__element_name || ')';
        END IF;
          IF (current_row.xdat_element_security_listing_action_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_element_security_listing_action_id:integer)=(' || current_row.xdat_element_security_listing_action_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_element_security_listing_action_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_security_listing_action_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:element_security_listing_action_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_element_security_listing_action_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_element_security_listing_action_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_element_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:element_security_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_element_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_element_security_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_field_mapping(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:field_mapping)(';
      FOR current_row IN SELECT * FROM xdat_field_mapping WHERE  xdat_field_mapping_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.field IS NOT NULL) THEN 
              fullText := fullText || '(field:string)=(' || REPLACE(REPLACE(current_row.field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.field_value IS NOT NULL) THEN 
              fullText := fullText || '(field_value:string)=(' || REPLACE(REPLACE(current_row.field_value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.create_element IS NOT NULL) THEN 
              fullText := fullText || '(create_element:integer)=(' || current_row.create_element || ')';
          END IF;
          IF (current_row.read_element IS NOT NULL) THEN 
              fullText := fullText || '(read_element:integer)=(' || current_row.read_element || ')';
          END IF;
          IF (current_row.edit_element IS NOT NULL) THEN 
              fullText := fullText || '(edit_element:integer)=(' || current_row.edit_element || ')';
          END IF;
          IF (current_row.delete_element IS NOT NULL) THEN 
              fullText := fullText || '(delete_element:integer)=(' || current_row.delete_element || ')';
          END IF;
          IF (current_row.active_element IS NOT NULL) THEN 
              fullText := fullText || '(active_element:integer)=(' || current_row.active_element || ')';
          END IF;
          IF (current_row.comparison_type IS NOT NULL) THEN 
              fullText := fullText || '(comparison_type:string)=(' || REPLACE(REPLACE(current_row.comparison_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.field_mapping_info IS NOT NULL)) THEN
            fullText := fullText || '(field_mapping_info:integer)=(' || current_row.field_mapping_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_meta_data(current_row.field_mapping_info, child_count,$3,false,false);
              fullText := fullText || '(field_mapping_info_field_mapping_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_field_mapping_set_xdat_field_mapping_set_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_field_mapping_set_xdat_field_mapping_set_id:integer)=(' || current_row.xdat_field_mapping_set_xdat_field_mapping_set_id || ')';
        END IF;
          IF (current_row.xdat_field_mapping_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_field_mapping_id:integer)=(' || current_row.xdat_field_mapping_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_field_mapping_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:field_mapping_history)(';
      FOR current_row IN SELECT * FROM xdat_field_mapping_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.field IS NOT NULL) THEN 
              fullText := fullText || '(field:string)=(' || REPLACE(REPLACE(current_row.field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.field_value IS NOT NULL) THEN 
              fullText := fullText || '(field_value:string)=(' || REPLACE(REPLACE(current_row.field_value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.create_element IS NOT NULL) THEN 
              fullText := fullText || '(create_element:integer)=(' || current_row.create_element || ')';
          END IF;
          IF (current_row.read_element IS NOT NULL) THEN 
              fullText := fullText || '(read_element:integer)=(' || current_row.read_element || ')';
          END IF;
          IF (current_row.edit_element IS NOT NULL) THEN 
              fullText := fullText || '(edit_element:integer)=(' || current_row.edit_element || ')';
          END IF;
          IF (current_row.delete_element IS NOT NULL) THEN 
              fullText := fullText || '(delete_element:integer)=(' || current_row.delete_element || ')';
          END IF;
          IF (current_row.active_element IS NOT NULL) THEN 
              fullText := fullText || '(active_element:integer)=(' || current_row.active_element || ')';
          END IF;
          IF (current_row.comparison_type IS NOT NULL) THEN 
              fullText := fullText || '(comparison_type:string)=(' || REPLACE(REPLACE(current_row.comparison_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.field_mapping_info IS NOT NULL)) THEN
            fullText := fullText || '(field_mapping_info:integer)=(' || current_row.field_mapping_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_meta_data(current_row.field_mapping_info, child_count,$3,false,false);
              fullText := fullText || '(field_mapping_info_field_mapping_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xdat_field_mapping_set_xdat_field_mapping_set_id IS NOT NULL)) THEN
            fullText := fullText || '(xdat_field_mapping_set_xdat_field_mapping_set_id:integer)=(' || current_row.xdat_field_mapping_set_xdat_field_mapping_set_id || ')';
        END IF;
          IF (current_row.xdat_field_mapping_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_field_mapping_id:integer)=(' || current_row.xdat_field_mapping_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_field_mapping_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_field_mapping_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:field_mapping_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_field_mapping_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_field_mapping_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_field_mapping_set(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:field_mapping_set)(';
      FOR current_row IN SELECT * FROM xdat_field_mapping_set WHERE  xdat_field_mapping_set_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_field_mapping WHERE xdat_field_mapping_set_xdat_field_mapping_set_id=current_row.xdat_field_mapping_set_id ORDER BY xdat_field_mapping_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping( parent_row.xdat_field_mapping_id, child_count,$3,false,false);
              fullText := fullText || '(allow_field_mapping' || 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_field_mapping_set WHERE sub_set_xdat_field_mapping_set_id=current_row.xdat_field_mapping_set_id ORDER BY xdat_field_mapping_set_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_set( parent_row.xdat_field_mapping_set_id, child_count,$3,false,false);
              fullText := fullText || '(sub_set_field_mapping_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.method IS NOT NULL) THEN 
              fullText := fullText || '(method:string)=(' || REPLACE(REPLACE(current_row.method,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.field_mapping_set_info IS NOT NULL)) THEN
            fullText := fullText || '(field_mapping_set_info:integer)=(' || current_row.field_mapping_set_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_set_meta_data(current_row.field_mapping_set_info, child_count,$3,false,false);
              fullText := fullText || '(field_mapping_set_info_field_mapping_set_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.permissions_allow_set_xdat_elem_xdat_element_access_id IS NOT NULL)) THEN
            fullText := fullText || '(permissions_allow_set_xdat_elem_xdat_element_access_id:integer)=(' || current_row.permissions_allow_set_xdat_elem_xdat_element_access_id || ')';
        END IF;
          IF (current_row.xdat_field_mapping_set_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_field_mapping_set_id:integer)=(' || current_row.xdat_field_mapping_set_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_field_mapping_set_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:field_mapping_set_history)(';
      FOR current_row IN SELECT * FROM xdat_field_mapping_set_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_field_mapping_history WHERE xdat_field_mapping_set_xdat_field_mapping_set_id=current_row.xdat_field_mapping_set_id AND xft_version=current_row.xft_version ORDER BY xdat_field_mapping_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_history( parent_row.xdat_field_mapping_id, child_count,$3,false,false);
              fullText := fullText || '(allow_field_mapping' || 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_field_mapping_set_history WHERE sub_set_xdat_field_mapping_set_id=current_row.xdat_field_mapping_set_id AND xft_version=current_row.xft_version ORDER BY xdat_field_mapping_set_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_set_history( parent_row.xdat_field_mapping_set_id, child_count,$3,false,false);
              fullText := fullText || '(sub_set_field_mapping_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.method IS NOT NULL) THEN 
              fullText := fullText || '(method:string)=(' || REPLACE(REPLACE(current_row.method,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.field_mapping_set_info IS NOT NULL)) THEN
            fullText := fullText || '(field_mapping_set_info:integer)=(' || current_row.field_mapping_set_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_field_mapping_set_meta_data(current_row.field_mapping_set_info, child_count,$3,false,false);
              fullText := fullText || '(field_mapping_set_info_field_mapping_set_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.permissions_allow_set_xdat_elem_xdat_element_access_id IS NOT NULL)) THEN
            fullText := fullText || '(permissions_allow_set_xdat_elem_xdat_element_access_id:integer)=(' || current_row.permissions_allow_set_xdat_elem_xdat_element_access_id || ')';
        END IF;
          IF (current_row.xdat_field_mapping_set_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_field_mapping_set_id:integer)=(' || current_row.xdat_field_mapping_set_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_field_mapping_set_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_field_mapping_set_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:field_mapping_set_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_field_mapping_set_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_field_mapping_set_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_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:history)(';
      FOR current_row IN SELECT * FROM xdat_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.new_row IS NOT NULL) THEN 
              fullText := fullText || '(new_row:string)=(' || current_row.new_row || ')';
          END IF;
        IF ((current_row.change_user IS NOT NULL)) THEN
            fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_user(current_row.change_user, child_count,$3,false,false);
              fullText := fullText || '(change_user_user:XFTItem)=(' || tempText || ')';
        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_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_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_infoentry(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:infoEntry)(';
      FOR current_row IN SELECT * FROM xdat_infoEntry WHERE  xdat_infoentry_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.infoEntry_info IS NOT NULL)) THEN
            fullText := fullText || '(infoentry_info:integer)=(' || current_row.infoentry_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_infoEntry_meta_data(current_row.infoEntry_info, child_count,$3,false,false);
              fullText := fullText || '(infoentry_info_infoentry_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_infoentry_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_infoentry_id:integer)=(' || current_row.xdat_infoentry_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_infoentry_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:infoEntry_history)(';
      FOR current_row IN SELECT * FROM xdat_infoEntry_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.infoEntry_info IS NOT NULL)) THEN
            fullText := fullText || '(infoentry_info:integer)=(' || current_row.infoentry_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_infoEntry_meta_data(current_row.infoEntry_info, child_count,$3,false,false);
              fullText := fullText || '(infoentry_info_infoentry_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xdat_infoentry_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_infoentry_id:integer)=(' || current_row.xdat_infoentry_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_infoentry_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_infoentry_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:infoEntry_meta_data)(';
      FOR current_row IN SELECT * FROM xdat_infoEntry_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_infoentry_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xdat_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:meta_data)(';
      FOR current_row IN SELECT * FROM xdat_meta_data WHERE  meta_data_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.insert_date IS NOT NULL) THEN 
              fullText := fullText || '(insert_date:dateTime)=(' || current_row.insert_date || ')';
          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.activation_date IS NOT NULL) THEN 
              fullText := fullText || '(activation_date:dateTime)=(' || current_row.activation_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.last_modified IS NOT NULL) THEN 
              fullText := fullText || '(last_modified:dateTime)=(' || current_row.last_modified || ')';
          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.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:string)=(' || REPLACE(REPLACE(current_row.xft_version,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.meta_data_id IS NOT NULL) THEN 
              fullText := fullText || '(meta_data_id:integer)=(' || current_row.meta_data_id || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          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.modified IS NOT NULL) THEN 
              fullText := fullText || '(modified:integer)=(' || current_row.modified || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xdat_meta_element(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:meta_element)(';
      FOR current_row IN SELECT * FROM xdat_meta_element WHERE  xdat_meta_element_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.xdat_meta_element_id IS NOT NULL) THEN 
              fullText := fullText || '(xdat_meta_element_id:integer)=(' || current_row.xdat_meta_element_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

--
