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

CREATE FUNCTION public.ie_arc_pipelinedata(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 || '(arc:pipelineData)(';
      FOR current_row IN SELECT * FROM arc_pipelineData WHERE  arc_pipelinedata_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.displaytext IS NOT NULL) THEN 
              fullText := fullText || '(displaytext:string)=(' || REPLACE(REPLACE(current_row.displaytext,'(','*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.location IS NOT NULL) THEN 
              fullText := fullText || '(location:string)=(' || REPLACE(REPLACE(current_row.location,'(','*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($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_pipelineParameterData WHERE parameters_parameter_arc_pipeli_arc_pipelinedata_id=current_row.arc_pipelinedata_id ORDER BY arc_pipelineparameterdata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_arc_pipelineParameterData( parent_row.arc_pipelineparameterdata_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_parameter_pipelineparameterdata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.customwebpage IS NOT NULL) THEN 
              fullText := fullText || '(customwebpage:string)=(' || REPLACE(REPLACE(current_row.customwebpage,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.pipelineData_info IS NOT NULL)) THEN
            fullText := fullText || '(pipelinedata_info:integer)=(' || current_row.pipelinedata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_arc_pipelineData_meta_data(current_row.pipelineData_info, child_count,$3,false,false);
              fullText := fullText || '(pipelinedata_info_pipelinedata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.arc_pipelinedata_id IS NOT NULL) THEN 
              fullText := fullText || '(arc_pipelinedata_id:integer)=(' || current_row.arc_pipelinedata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_arc_pipelinedata_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 || '(arc:pipelineData_history)(';
      FOR current_row IN SELECT * FROM arc_pipelineData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.displaytext IS NOT NULL) THEN 
              fullText := fullText || '(displaytext:string)=(' || REPLACE(REPLACE(current_row.displaytext,'(','*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.location IS NOT NULL) THEN 
              fullText := fullText || '(location:string)=(' || REPLACE(REPLACE(current_row.location,'(','*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($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_pipelineParameterData_history WHERE parameters_parameter_arc_pipeli_arc_pipelinedata_id=current_row.arc_pipelinedata_id AND xft_version=current_row.xft_version ORDER BY arc_pipelineparameterdata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_arc_pipelineParameterData_history( parent_row.arc_pipelineparameterdata_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_parameter_pipelineparameterdata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.customwebpage IS NOT NULL) THEN 
              fullText := fullText || '(customwebpage:string)=(' || REPLACE(REPLACE(current_row.customwebpage,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.pipelineData_info IS NOT NULL)) THEN
            fullText := fullText || '(pipelinedata_info:integer)=(' || current_row.pipelinedata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_arc_pipelineData_meta_data(current_row.pipelineData_info, child_count,$3,false,false);
              fullText := fullText || '(pipelinedata_info_pipelinedata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.arc_pipelinedata_id IS NOT NULL) THEN 
              fullText := fullText || '(arc_pipelinedata_id:integer)=(' || current_row.arc_pipelinedata_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.ie_arc_pipelinedata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_cat_catalog(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 || '(cat:catalog)(';
      FOR current_row IN SELECT * FROM cat_catalog WHERE  cat_catalog_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 cat_catalog_metaField WHERE metafields_metafield_cat_catalo_cat_catalog_id=current_row.cat_catalog_id ORDER BY cat_catalog_metafield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog_metaField( parent_row.cat_catalog_metafield_id, child_count,$3,false,false);
              fullText := fullText || '(metafields_metafield_catalog_metafield' || 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 cat_catalog_tag WHERE tags_tag_cat_catalog_cat_catalog_id=current_row.cat_catalog_id ORDER BY cat_catalog_tag_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog_tag( parent_row.cat_catalog_tag_id, child_count,$3,false,false);
              fullText := fullText || '(tags_tag_catalog_tag' || 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 cat_catalog WHERE sets_entryset_cat_catalog_id=current_row.cat_catalog_id ORDER BY cat_catalog_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog( parent_row.cat_catalog_id, child_count,$3,false,false);
              fullText := fullText || '(sets_entryset_catalog' || 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 cat_entry WHERE entries_entry_cat_catalog_cat_catalog_id=current_row.cat_catalog_id ORDER BY cat_entry_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry( parent_row.cat_entry_id, child_count,$3,false,false);
              fullText := fullText || '(entries_entry_entry' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.catalog_info IS NOT NULL)) THEN
            fullText := fullText || '(catalog_info:integer)=(' || current_row.catalog_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog_meta_data(current_row.catalog_info, child_count,$3,false,false);
              fullText := fullText || '(catalog_info_catalog_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.cat_catalog_id IS NOT NULL) THEN 
              fullText := fullText || '(cat_catalog_id:integer)=(' || current_row.cat_catalog_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_cat_catalog_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 || '(cat:catalog_history)(';
      FOR current_row IN SELECT * FROM cat_catalog_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 cat_catalog_metaField_history WHERE metafields_metafield_cat_catalo_cat_catalog_id=current_row.cat_catalog_id AND xft_version=current_row.xft_version ORDER BY cat_catalog_metafield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog_metaField_history( parent_row.cat_catalog_metafield_id, child_count,$3,false,false);
              fullText := fullText || '(metafields_metafield_catalog_metafield' || 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 cat_catalog_tag_history WHERE tags_tag_cat_catalog_cat_catalog_id=current_row.cat_catalog_id AND xft_version=current_row.xft_version ORDER BY cat_catalog_tag_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog_tag_history( parent_row.cat_catalog_tag_id, child_count,$3,false,false);
              fullText := fullText || '(tags_tag_catalog_tag' || 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 cat_catalog_history WHERE sets_entryset_cat_catalog_id=current_row.cat_catalog_id AND xft_version=current_row.xft_version ORDER BY cat_catalog_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog_history( parent_row.cat_catalog_id, child_count,$3,false,false);
              fullText := fullText || '(sets_entryset_catalog' || 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 cat_entry_history WHERE entries_entry_cat_catalog_cat_catalog_id=current_row.cat_catalog_id AND xft_version=current_row.xft_version ORDER BY cat_entry_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry_history( parent_row.cat_entry_id, child_count,$3,false,false);
              fullText := fullText || '(entries_entry_entry' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.catalog_info IS NOT NULL)) THEN
            fullText := fullText || '(catalog_info:integer)=(' || current_row.catalog_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_catalog_meta_data(current_row.catalog_info, child_count,$3,false,false);
              fullText := fullText || '(catalog_info_catalog_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.cat_catalog_id IS NOT NULL) THEN 
              fullText := fullText || '(cat_catalog_id:integer)=(' || current_row.cat_catalog_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.ie_cat_catalog_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_cat_entry(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 || '(cat:entry)(';
      FOR current_row IN SELECT * FROM cat_entry WHERE  cat_entry_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 cat_entry_metaField WHERE metafields_metafield_cat_entry_cat_entry_id=current_row.cat_entry_id ORDER BY cat_entry_metafield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry_metaField( parent_row.cat_entry_metafield_id, child_count,$3,false,false);
              fullText := fullText || '(metafields_metafield_entry_metafield' || 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 cat_entry_tag WHERE tags_tag_cat_entry_cat_entry_id=current_row.cat_entry_id ORDER BY cat_entry_tag_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry_tag( parent_row.cat_entry_tag_id, child_count,$3,false,false);
              fullText := fullText || '(tags_tag_entry_tag' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*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.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.createdtime IS NOT NULL) THEN 
              fullText := fullText || '(createdtime:dateTime)=(' || current_row.createdtime || ')';
          END IF;
          IF (current_row.createdby IS NOT NULL) THEN 
              fullText := fullText || '(createdby:string)=(' || REPLACE(REPLACE(current_row.createdby,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.createdeventid IS NOT NULL) THEN 
              fullText := fullText || '(createdeventid:integer)=(' || current_row.createdeventid || ')';
          END IF;
          IF (current_row.modifiedtime IS NOT NULL) THEN 
              fullText := fullText || '(modifiedtime:dateTime)=(' || current_row.modifiedtime || ')';
          END IF;
          IF (current_row.modifiedby IS NOT NULL) THEN 
              fullText := fullText || '(modifiedby:string)=(' || REPLACE(REPLACE(current_row.modifiedby,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modifiedeventid IS NOT NULL) THEN 
              fullText := fullText || '(modifiedeventid:integer)=(' || current_row.modifiedeventid || ')';
          END IF;
          IF (current_row.digest IS NOT NULL) THEN 
              fullText := fullText || '(digest:string)=(' || REPLACE(REPLACE(current_row.digest,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.entry_info IS NOT NULL)) THEN
            fullText := fullText || '(entry_info:integer)=(' || current_row.entry_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry_meta_data(current_row.entry_info, child_count,$3,false,false);
              fullText := fullText || '(entry_info_entry_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.entries_entry_cat_catalog_cat_catalog_id IS NOT NULL)) THEN
            fullText := fullText || '(entries_entry_cat_catalog_cat_catalog_id:integer)=(' || current_row.entries_entry_cat_catalog_cat_catalog_id || ')';
        END IF;
          IF (current_row.cat_entry_id IS NOT NULL) THEN 
              fullText := fullText || '(cat_entry_id:integer)=(' || current_row.cat_entry_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_cat_entry_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 || '(cat:entry_history)(';
      FOR current_row IN SELECT * FROM cat_entry_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 cat_entry_metaField_history WHERE metafields_metafield_cat_entry_cat_entry_id=current_row.cat_entry_id AND xft_version=current_row.xft_version ORDER BY cat_entry_metafield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry_metaField_history( parent_row.cat_entry_metafield_id, child_count,$3,false,false);
              fullText := fullText || '(metafields_metafield_entry_metafield' || 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 cat_entry_tag_history WHERE tags_tag_cat_entry_cat_entry_id=current_row.cat_entry_id AND xft_version=current_row.xft_version ORDER BY cat_entry_tag_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry_tag_history( parent_row.cat_entry_tag_id, child_count,$3,false,false);
              fullText := fullText || '(tags_tag_entry_tag' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*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.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.createdtime IS NOT NULL) THEN 
              fullText := fullText || '(createdtime:dateTime)=(' || current_row.createdtime || ')';
          END IF;
          IF (current_row.createdby IS NOT NULL) THEN 
              fullText := fullText || '(createdby:string)=(' || REPLACE(REPLACE(current_row.createdby,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.createdeventid IS NOT NULL) THEN 
              fullText := fullText || '(createdeventid:integer)=(' || current_row.createdeventid || ')';
          END IF;
          IF (current_row.modifiedtime IS NOT NULL) THEN 
              fullText := fullText || '(modifiedtime:dateTime)=(' || current_row.modifiedtime || ')';
          END IF;
          IF (current_row.modifiedby IS NOT NULL) THEN 
              fullText := fullText || '(modifiedby:string)=(' || REPLACE(REPLACE(current_row.modifiedby,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modifiedeventid IS NOT NULL) THEN 
              fullText := fullText || '(modifiedeventid:integer)=(' || current_row.modifiedeventid || ')';
          END IF;
          IF (current_row.digest IS NOT NULL) THEN 
              fullText := fullText || '(digest:string)=(' || REPLACE(REPLACE(current_row.digest,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.entry_info IS NOT NULL)) THEN
            fullText := fullText || '(entry_info:integer)=(' || current_row.entry_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_cat_entry_meta_data(current_row.entry_info, child_count,$3,false,false);
              fullText := fullText || '(entry_info_entry_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.entries_entry_cat_catalog_cat_catalog_id IS NOT NULL)) THEN
            fullText := fullText || '(entries_entry_cat_catalog_cat_catalog_id:integer)=(' || current_row.entries_entry_cat_catalog_cat_catalog_id || ')';
        END IF;
          IF (current_row.cat_entry_id IS NOT NULL) THEN 
              fullText := fullText || '(cat_entry_id:integer)=(' || current_row.cat_entry_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.ie_cat_entry_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_wrk_abstractexecutionenvironment(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)(';
      FOR current_row IN SELECT * FROM wrk_abstractExecutionEnvironment WHERE  wrk_abstractexecutionenvironment_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractExecutionEnvironment_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractexecutionenvironment_info:integer)=(' || current_row.abstractexecutionenvironment_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_abstractExecutionEnvironment_meta_data(current_row.abstractExecutionEnvironment_info, child_count,$3,false,false);
              fullText := fullText || '(abstractexecutionenvironment_info_abstractexecutionenvironment_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.wrk_abstractexecutionenvironment_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_abstractexecutionenvironment_id:integer)=(' || current_row.wrk_abstractexecutionenvironment_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_wrk_abstractexecutionenvironment_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:abstractExecutionEnvironment_history)(';
      FOR current_row IN SELECT * FROM wrk_abstractExecutionEnvironment_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractExecutionEnvironment_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractexecutionenvironment_info:integer)=(' || current_row.abstractexecutionenvironment_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_wrk_abstractExecutionEnvironment_meta_data(current_row.abstractExecutionEnvironment_info, child_count,$3,false,false);
              fullText := fullText || '(abstractexecutionenvironment_info_abstractexecutionenvironment_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.wrk_abstractexecutionenvironment_id IS NOT NULL) THEN 
              fullText := fullText || '(wrk_abstractexecutionenvironment_id:integer)=(' || current_row.wrk_abstractexecutionenvironment_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.ie_wrk_abstractexecutionenvironment_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xdat_stored_search(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search)(';
      FOR current_row IN SELECT * FROM xdat_stored_search WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.root_element_name IS NOT NULL) THEN 
              fullText := fullText || '(root_element_name:string)=(' || REPLACE(REPLACE(current_row.root_element_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_search_field WHERE xdat_stored_search_id=current_row.id ORDER BY xdat_search_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_search_field( parent_row.xdat_search_field_id, child_count,$3,false,false);
              fullText := fullText || '(search_field_search_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_criteria_set WHERE xdat_stored_search_id=current_row.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 || '(search_where_criteria_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.sort_by_element_name IS NOT NULL) THEN 
              fullText := fullText || '(sort_by_element_name:string)=(' || REPLACE(REPLACE(current_row.sort_by_element_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sort_by_field_id IS NOT NULL) THEN 
              fullText := fullText || '(sort_by_field_id:string)=(' || REPLACE(REPLACE(current_row.sort_by_field_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_stored_search_allowed_user WHERE xdat_stored_search_id=current_row.id ORDER BY xdat_stored_search_allowed_user_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_allowed_user( parent_row.xdat_stored_search_allowed_user_id, child_count,$3,false,false);
              fullText := fullText || '(allowed_user_stored_search_allowed_user' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_stored_search_groupID WHERE allowed_groups_groupid_xdat_sto_id=current_row.id ORDER BY xdat_stored_search_groupid_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_groupID( parent_row.xdat_stored_search_groupid_id, child_count,$3,false,false);
              fullText := fullText || '(allowed_groups_groupid_stored_search_groupid' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.layeredsequence IS NOT NULL) THEN 
              fullText := fullText || '(layeredsequence:string)=(' || REPLACE(REPLACE(current_row.layeredsequence,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.allow_diff_columns IS NOT NULL) THEN 
              fullText := fullText || '(allow_diff_columns:integer)=(' || current_row.allow_diff_columns || ')';
          END IF;
          IF (current_row.secure IS NOT NULL) THEN 
              fullText := fullText || '(secure:integer)=(' || current_row.secure || ')';
          END IF;
          IF (current_row.brief_description IS NOT NULL) THEN 
              fullText := fullText || '(brief_description:string)=(' || REPLACE(REPLACE(current_row.brief_description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tag IS NOT NULL) THEN 
              fullText := fullText || '(tag:string)=(' || REPLACE(REPLACE(current_row.tag,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.stored_search_info IS NOT NULL)) THEN
            fullText := fullText || '(stored_search_info:integer)=(' || current_row.stored_search_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_meta_data(current_row.stored_search_info, child_count,$3,false,false);
              fullText := fullText || '(stored_search_info_stored_search_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xdat_stored_search_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xdat:stored_search_history)(';
      FOR current_row IN SELECT * FROM xdat_stored_search_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.root_element_name IS NOT NULL) THEN 
              fullText := fullText || '(root_element_name:string)=(' || REPLACE(REPLACE(current_row.root_element_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_search_field_history WHERE xdat_stored_search_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xdat_search_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_search_field_history( parent_row.xdat_search_field_id, child_count,$3,false,false);
              fullText := fullText || '(search_field_search_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_criteria_set_history WHERE xdat_stored_search_id=current_row.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 || '(search_where_criteria_set' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.sort_by_element_name IS NOT NULL) THEN 
              fullText := fullText || '(sort_by_element_name:string)=(' || REPLACE(REPLACE(current_row.sort_by_element_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sort_by_field_id IS NOT NULL) THEN 
              fullText := fullText || '(sort_by_field_id:string)=(' || REPLACE(REPLACE(current_row.sort_by_field_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_stored_search_allowed_user_history WHERE xdat_stored_search_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xdat_stored_search_allowed_user_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_allowed_user_history( parent_row.xdat_stored_search_allowed_user_id, child_count,$3,false,false);
              fullText := fullText || '(allowed_user_stored_search_allowed_user' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_stored_search_groupID_history WHERE allowed_groups_groupid_xdat_sto_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xdat_stored_search_groupid_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_groupID_history( parent_row.xdat_stored_search_groupid_id, child_count,$3,false,false);
              fullText := fullText || '(allowed_groups_groupid_stored_search_groupid' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.layeredsequence IS NOT NULL) THEN 
              fullText := fullText || '(layeredsequence:string)=(' || REPLACE(REPLACE(current_row.layeredsequence,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.allow_diff_columns IS NOT NULL) THEN 
              fullText := fullText || '(allow_diff_columns:integer)=(' || current_row.allow_diff_columns || ')';
          END IF;
          IF (current_row.secure IS NOT NULL) THEN 
              fullText := fullText || '(secure:integer)=(' || current_row.secure || ')';
          END IF;
          IF (current_row.brief_description IS NOT NULL) THEN 
              fullText := fullText || '(brief_description:string)=(' || REPLACE(REPLACE(current_row.brief_description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tag IS NOT NULL) THEN 
              fullText := fullText || '(tag:string)=(' || REPLACE(REPLACE(current_row.tag,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.stored_search_info IS NOT NULL)) THEN
            fullText := fullText || '(stored_search_info:integer)=(' || current_row.stored_search_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_stored_search_meta_data(current_row.stored_search_info, child_count,$3,false,false);
              fullText := fullText || '(stored_search_info_stored_search_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_abstractdemographicdata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractDemographicData)(';
      FOR current_row IN SELECT * FROM xnat_abstractDemographicData WHERE  xnat_abstractdemographicdata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractDemographicData_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractdemographicdata_info:integer)=(' || current_row.abstractdemographicdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractDemographicData_meta_data(current_row.abstractDemographicData_info, child_count,$3,false,false);
              fullText := fullText || '(abstractdemographicdata_info_abstractdemographicdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_abstractdemographicdata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractdemographicdata_id:integer)=(' || current_row.xnat_abstractdemographicdata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_abstractdemographicdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractDemographicData_history)(';
      FOR current_row IN SELECT * FROM xnat_abstractDemographicData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractDemographicData_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractdemographicdata_info:integer)=(' || current_row.abstractdemographicdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractDemographicData_meta_data(current_row.abstractDemographicData_info, child_count,$3,false,false);
              fullText := fullText || '(abstractdemographicdata_info_abstractdemographicdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_abstractdemographicdata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractdemographicdata_id:integer)=(' || current_row.xnat_abstractdemographicdata_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.ie_xnat_abstractdemographicdata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_abstractprotocol(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractProtocol)(';
      FOR current_row IN SELECT * FROM xnat_abstractProtocol WHERE  xnat_abstractprotocol_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*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.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*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.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractProtocol_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractprotocol_info:integer)=(' || current_row.abstractprotocol_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractProtocol_meta_data(current_row.abstractProtocol_info, child_count,$3,false,false);
              fullText := fullText || '(abstractprotocol_info_abstractprotocol_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_projectData_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_projectdata_id:string)=(' || current_row.xnat_projectdata_id || ')';
        END IF;
          IF (current_row.xnat_abstractprotocol_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractprotocol_id:integer)=(' || current_row.xnat_abstractprotocol_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_abstractprotocol_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractProtocol_history)(';
      FOR current_row IN SELECT * FROM xnat_abstractProtocol_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*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.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*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.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractProtocol_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractprotocol_info:integer)=(' || current_row.abstractprotocol_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractProtocol_meta_data(current_row.abstractProtocol_info, child_count,$3,false,false);
              fullText := fullText || '(abstractprotocol_info_abstractprotocol_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_projectData_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_projectdata_id:string)=(' || current_row.xnat_projectdata_id || ')';
        END IF;
          IF (current_row.xnat_abstractprotocol_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractprotocol_id:integer)=(' || current_row.xnat_abstractprotocol_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.ie_xnat_abstractprotocol_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_abstractresource(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractResource)(';
      FOR current_row IN SELECT * FROM xnat_abstractResource WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.note IS NOT NULL) THEN 
              fullText := fullText || '(note:string)=(' || REPLACE(REPLACE(current_row.note,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractResource_tag WHERE tags_tag_xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id ORDER BY xnat_abstractresource_tag_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_tag( parent_row.xnat_abstractresource_tag_id, child_count,$3,false,false);
              fullText := fullText || '(tags_tag_abstractresource_tag' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.file_count IS NOT NULL) THEN 
              fullText := fullText || '(file_count:integer)=(' || current_row.file_count || ')';
          END IF;
          IF (current_row.file_size IS NOT NULL) THEN 
              fullText := fullText || '(file_size:long)=(' || current_row.file_size || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractResource_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractresource_info:integer)=(' || current_row.abstractresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_meta_data(current_row.abstractResource_info, child_count,$3,false,false);
              fullText := fullText || '(abstractresource_info_abstractresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_imageScanData_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_abstractresource_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_abstractresource_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractResource_history)(';
      FOR current_row IN SELECT * FROM xnat_abstractResource_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.note IS NOT NULL) THEN 
              fullText := fullText || '(note:string)=(' || REPLACE(REPLACE(current_row.note,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractResource_tag_history WHERE tags_tag_xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version ORDER BY xnat_abstractresource_tag_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_tag_history( parent_row.xnat_abstractresource_tag_id, child_count,$3,false,false);
              fullText := fullText || '(tags_tag_abstractresource_tag' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.file_count IS NOT NULL) THEN 
              fullText := fullText || '(file_count:integer)=(' || current_row.file_count || ')';
          END IF;
          IF (current_row.file_size IS NOT NULL) THEN 
              fullText := fullText || '(file_size:long)=(' || current_row.file_size || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractResource_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractresource_info:integer)=(' || current_row.abstractresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_meta_data(current_row.abstractResource_info, child_count,$3,false,false);
              fullText := fullText || '(abstractresource_info_abstractresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_imageScanData_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_abstractresource_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_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.ie_xnat_abstractresource_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_abstractstatistics(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractStatistics)(';
      FOR current_row IN SELECT * FROM xnat_abstractStatistics WHERE  xnat_abstractstatistics_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractStatistics_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractstatistics_info:integer)=(' || current_row.abstractstatistics_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractStatistics_meta_data(current_row.abstractStatistics_info, child_count,$3,false,false);
              fullText := fullText || '(abstractstatistics_info_abstractstatistics_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_abstractstatistics_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractstatistics_id:integer)=(' || current_row.xnat_abstractstatistics_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_abstractstatistics_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractStatistics_history)(';
      FOR current_row IN SELECT * FROM xnat_abstractStatistics_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractStatistics_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractstatistics_info:integer)=(' || current_row.abstractstatistics_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractStatistics_meta_data(current_row.abstractStatistics_info, child_count,$3,false,false);
              fullText := fullText || '(abstractstatistics_info_abstractstatistics_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_abstractstatistics_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractstatistics_id:integer)=(' || current_row.xnat_abstractstatistics_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.ie_xnat_abstractstatistics_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_abstractsubjectmetadata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractSubjectMetadata)(';
      FOR current_row IN SELECT * FROM xnat_abstractSubjectMetadata WHERE  xnat_abstractsubjectmetadata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractSubjectMetadata_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractsubjectmetadata_info:integer)=(' || current_row.abstractsubjectmetadata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractSubjectMetadata_meta_data(current_row.abstractSubjectMetadata_info, child_count,$3,false,false);
              fullText := fullText || '(abstractsubjectmetadata_info_abstractsubjectmetadata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_abstractsubjectmetadata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractsubjectmetadata_id:integer)=(' || current_row.xnat_abstractsubjectmetadata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_abstractsubjectmetadata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractSubjectMetadata_history)(';
      FOR current_row IN SELECT * FROM xnat_abstractSubjectMetadata_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.abstractSubjectMetadata_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractsubjectmetadata_info:integer)=(' || current_row.abstractsubjectmetadata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractSubjectMetadata_meta_data(current_row.abstractSubjectMetadata_info, child_count,$3,false,false);
              fullText := fullText || '(abstractsubjectmetadata_info_abstractsubjectmetadata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_abstractsubjectmetadata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractsubjectmetadata_id:integer)=(' || current_row.xnat_abstractsubjectmetadata_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.ie_xnat_abstractsubjectmetadata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_deriveddata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:derivedData)(';
      FOR current_row IN SELECT * FROM xnat_derivedData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_experimentData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.provenance_prov_process_id IS NOT NULL)) THEN
            fullText := fullText || '(provenance_prov_process_id:integer)=(' || current_row.provenance_prov_process_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_prov_process(current_row.provenance_prov_process_id, child_count,$3,false,false);
              fullText := fullText || '(provenance_process:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.derivedData_info IS NOT NULL)) THEN
            fullText := fullText || '(deriveddata_info:integer)=(' || current_row.deriveddata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_derivedData_meta_data(current_row.derivedData_info, child_count,$3,false,false);
              fullText := fullText || '(deriveddata_info_deriveddata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_experimentData( $1, child_count,$3,$4,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_deriveddata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:derivedData_history)(';
      FOR current_row IN SELECT * FROM xnat_derivedData_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_experimentData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_experimentData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(experimentdata_experimentdata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.provenance_prov_process_id IS NOT NULL)) THEN
            fullText := fullText || '(provenance_prov_process_id:integer)=(' || current_row.provenance_prov_process_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM prov_process_history WHERE  prov_process_id=current_row.provenance_prov_process_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_prov_process_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(provenance_process:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF ((current_row.derivedData_info IS NOT NULL)) THEN
            fullText := fullText || '(deriveddata_info:integer)=(' || current_row.deriveddata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_derivedData_meta_data(current_row.derivedData_info, child_count,$3,false,false);
              fullText := fullText || '(deriveddata_info_deriveddata_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_experimentData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_experimentdata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:experimentData)(';
      FOR current_row IN SELECT * FROM xnat_experimentData WHERE  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 xnat_experimentData_share WHERE sharing_share_xnat_experimentDa_id=current_row.id ORDER BY xnat_experimentdata_share_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_share( parent_row.xnat_experimentdata_share_id, child_count,$3,false,false);
              fullText := fullText || '(sharing_share_experimentdata_share' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.date IS NOT NULL) THEN 
              fullText := fullText || '(date:date)=(' || current_row.date || ')';
          END IF;
          IF (current_row.time IS NOT NULL) THEN 
              fullText := fullText || '(time:time)=(' || current_row.time || ')';
          END IF;
          IF (current_row.duration IS NOT NULL) THEN 
              fullText := fullText || '(duration:string)=(' || current_row.duration || ')';
          END IF;
          IF (current_row.delay IS NOT NULL) THEN 
              fullText := fullText || '(delay:integer)=(' || current_row.delay || ')';
          END IF;
          IF (current_row.delay_ref_expt_id IS NOT NULL) THEN 
              fullText := fullText || '(delay_ref_expt_id:string)=(' || REPLACE(REPLACE(current_row.delay_ref_expt_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.note IS NOT NULL) THEN 
              fullText := fullText || '(note:string)=(' || REPLACE(REPLACE(current_row.note,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.investigator_xnat_investigatordata_id IS NOT NULL)) THEN
            fullText := fullText || '(investigator_xnat_investigatordata_id:integer)=(' || current_row.investigator_xnat_investigatordata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData(current_row.investigator_xnat_investigatordata_id, child_count,$3,false,false);
              fullText := fullText || '(investigator_investigatordata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.validation_xnat_validationdata_id IS NOT NULL)) THEN
            fullText := fullText || '(validation_xnat_validationdata_id:integer)=(' || current_row.validation_xnat_validationdata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_validationData(current_row.validation_xnat_validationdata_id, child_count,$3,false,false);
              fullText := fullText || '(validation_validationdata:XFTItem)=(' || tempText || ')';
        END IF;
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_experimentData_resource WHERE  xnat_experimentData_id=current_row.id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(resources_resource_abstractresource' || 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 xnat_experimentData_field WHERE fields_field_xnat_experimentDat_id=current_row.id ORDER BY xnat_experimentdata_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_field( parent_row.xnat_experimentdata_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_experimentdata_field' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.acquisition_site IS NOT NULL) THEN 
              fullText := fullText || '(acquisition_site:string)=(' || REPLACE(REPLACE(current_row.acquisition_site,'(','*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.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit_id IS NOT NULL) THEN 
              fullText := fullText || '(visit_id:string)=(' || REPLACE(REPLACE(current_row.visit_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit IS NOT NULL) THEN 
              fullText := fullText || '(visit:string)=(' || REPLACE(REPLACE(current_row.visit,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.version IS NOT NULL) THEN 
              fullText := fullText || '(version:integer)=(' || current_row.version || ')';
          END IF;
          IF (current_row.original IS NOT NULL) THEN 
              fullText := fullText || '(original:string)=(' || REPLACE(REPLACE(current_row.original,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.protocol IS NOT NULL) THEN 
              fullText := fullText || '(protocol:string)=(' || REPLACE(REPLACE(current_row.protocol,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.experimentData_info IS NOT NULL)) THEN
            fullText := fullText || '(experimentdata_info:integer)=(' || current_row.experimentdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_meta_data(current_row.experimentData_info, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_info_experimentdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_experimentdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:experimentData_history)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_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 xnat_experimentData_share_history WHERE sharing_share_xnat_experimentDa_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_experimentdata_share_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_share_history( parent_row.xnat_experimentdata_share_id, child_count,$3,false,false);
              fullText := fullText || '(sharing_share_experimentdata_share' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.date IS NOT NULL) THEN 
              fullText := fullText || '(date:date)=(' || current_row.date || ')';
          END IF;
          IF (current_row.time IS NOT NULL) THEN 
              fullText := fullText || '(time:time)=(' || current_row.time || ')';
          END IF;
          IF (current_row.duration IS NOT NULL) THEN 
              fullText := fullText || '(duration:string)=(' || current_row.duration || ')';
          END IF;
          IF (current_row.delay IS NOT NULL) THEN 
              fullText := fullText || '(delay:integer)=(' || current_row.delay || ')';
          END IF;
          IF (current_row.delay_ref_expt_id IS NOT NULL) THEN 
              fullText := fullText || '(delay_ref_expt_id:string)=(' || REPLACE(REPLACE(current_row.delay_ref_expt_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.note IS NOT NULL) THEN 
              fullText := fullText || '(note:string)=(' || REPLACE(REPLACE(current_row.note,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.investigator_xnat_investigatordata_id IS NOT NULL)) THEN
            fullText := fullText || '(investigator_xnat_investigatordata_id:integer)=(' || current_row.investigator_xnat_investigatordata_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_investigatorData_history WHERE  xnat_investigatordata_id=current_row.investigator_xnat_investigatordata_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(investigator_investigatordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF ((current_row.validation_xnat_validationdata_id IS NOT NULL)) THEN
            fullText := fullText || '(validation_xnat_validationdata_id:integer)=(' || current_row.validation_xnat_validationdata_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_validationData_history WHERE  xnat_validationdata_id=current_row.validation_xnat_validationdata_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_validationData_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(validation_validationdata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_experimentData_resource_history WHERE  xnat_experimentData_id=current_row.id AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_history( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(resources_resource_abstractresource' || 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 xnat_experimentData_field_history WHERE fields_field_xnat_experimentDat_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_experimentdata_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_field_history( parent_row.xnat_experimentdata_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_experimentdata_field' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.acquisition_site IS NOT NULL) THEN 
              fullText := fullText || '(acquisition_site:string)=(' || REPLACE(REPLACE(current_row.acquisition_site,'(','*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.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit_id IS NOT NULL) THEN 
              fullText := fullText || '(visit_id:string)=(' || REPLACE(REPLACE(current_row.visit_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit IS NOT NULL) THEN 
              fullText := fullText || '(visit:string)=(' || REPLACE(REPLACE(current_row.visit,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.version IS NOT NULL) THEN 
              fullText := fullText || '(version:integer)=(' || current_row.version || ')';
          END IF;
          IF (current_row.original IS NOT NULL) THEN 
              fullText := fullText || '(original:string)=(' || REPLACE(REPLACE(current_row.original,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.protocol IS NOT NULL) THEN 
              fullText := fullText || '(protocol:string)=(' || REPLACE(REPLACE(current_row.protocol,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.experimentData_info IS NOT NULL)) THEN
            fullText := fullText || '(experimentdata_info:integer)=(' || current_row.experimentdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_meta_data(current_row.experimentData_info, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_info_experimentdata_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.ie_xnat_experimentdata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_genericdata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:genericData)(';
      FOR current_row IN SELECT * FROM xnat_genericData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_experimentData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.genericData_info IS NOT NULL)) THEN
            fullText := fullText || '(genericdata_info:integer)=(' || current_row.genericdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_genericData_meta_data(current_row.genericData_info, child_count,$3,false,false);
              fullText := fullText || '(genericdata_info_genericdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_experimentData( $1, child_count,$3,$4,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_genericdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:genericData_history)(';
      FOR current_row IN SELECT * FROM xnat_genericData_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_experimentData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_experimentData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(experimentdata_experimentdata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.genericData_info IS NOT NULL)) THEN
            fullText := fullText || '(genericdata_info:integer)=(' || current_row.genericdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_genericData_meta_data(current_row.genericData_info, child_count,$3,false,false);
              fullText := fullText || '(genericdata_info_genericdata_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_experimentData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_imageassessordata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:imageAssessorData)(';
      FOR current_row IN SELECT * FROM xnat_imageAssessorData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_derivedData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(deriveddata_deriveddata:XFTItem)=(' || tempText || ')';
        END IF;
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM img_assessor_in_resource WHERE  xnat_imageAssessorData_id=current_row.id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(in_file_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM img_assessor_out_resource WHERE  xnat_imageAssessorData_id=current_row.id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(out_file_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
          IF (current_row.imagesession_id IS NOT NULL) THEN 
              fullText := fullText || '(imagesession_id:string)=(' || REPLACE(REPLACE(current_row.imagesession_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField WHERE parameters_addparam_xnat_imageA_id=current_row.id ORDER BY xnat_addfield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_addField( parent_row.xnat_addfield_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_addparam_addfield' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.imageAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(imageassessordata_info:integer)=(' || current_row.imageassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageAssessorData_meta_data(current_row.imageAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(imageassessordata_info_imageassessordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_derivedData( $1, child_count,$3,$4,false);
              fullText := fullText || '(deriveddata_deriveddata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_imageassessordata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:imageAssessorData_history)(';
      FOR current_row IN SELECT * FROM xnat_imageAssessorData_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_derivedData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_derivedData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(deriveddata_deriveddata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM img_assessor_in_resource_history WHERE  xnat_imageAssessorData_id=current_row.id AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_history( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(in_file_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM img_assessor_out_resource_history WHERE  xnat_imageAssessorData_id=current_row.id AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_history( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(out_file_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
          IF (current_row.imagesession_id IS NOT NULL) THEN 
              fullText := fullText || '(imagesession_id:string)=(' || REPLACE(REPLACE(current_row.imagesession_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField_history WHERE parameters_addparam_xnat_imageA_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_addfield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_addField_history( parent_row.xnat_addfield_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_addparam_addfield' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.imageAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(imageassessordata_info:integer)=(' || current_row.imageassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageAssessorData_meta_data(current_row.imageAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(imageassessordata_info_imageassessordata_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_derivedData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(deriveddata_deriveddata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_imagescandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:imageScanData)(';
      FOR current_row IN SELECT * FROM xnat_imageScanData WHERE  xnat_imagescandata_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 xnat_imageScanData_share WHERE sharing_share_xnat_imageScanDat_xnat_imagescandata_id=current_row.xnat_imagescandata_id ORDER BY xnat_imagescandata_share_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData_share( parent_row.xnat_imagescandata_share_id, child_count,$3,false,false);
              fullText := fullText || '(sharing_share_imagescandata_share' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.image_session_id IS NOT NULL) THEN 
              fullText := fullText || '(image_session_id:string)=(' || REPLACE(REPLACE(current_row.image_session_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.note IS NOT NULL) THEN 
              fullText := fullText || '(note:string)=(' || REPLACE(REPLACE(current_row.note,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.quality IS NOT NULL) THEN 
              fullText := fullText || '(quality:string)=(' || REPLACE(REPLACE(current_row.quality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.condition IS NOT NULL) THEN 
              fullText := fullText || '(condition:string)=(' || REPLACE(REPLACE(current_row.condition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.series_description IS NOT NULL) THEN 
              fullText := fullText || '(series_description:string)=(' || REPLACE(REPLACE(current_row.series_description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.series_class IS NOT NULL) THEN 
              fullText := fullText || '(series_class:string)=(' || REPLACE(REPLACE(current_row.series_class,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.documentation IS NOT NULL) THEN 
              fullText := fullText || '(documentation:string)=(' || REPLACE(REPLACE(current_row.documentation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner IS NOT NULL) THEN 
              fullText := fullText || '(scanner:string)=(' || REPLACE(REPLACE(current_row.scanner,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_manufacturer IS NOT NULL) THEN 
              fullText := fullText || '(scanner_manufacturer:string)=(' || REPLACE(REPLACE(current_row.scanner_manufacturer,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_model IS NOT NULL) THEN 
              fullText := fullText || '(scanner_model:string)=(' || REPLACE(REPLACE(current_row.scanner_model,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_softwareversion IS NOT NULL) THEN 
              fullText := fullText || '(scanner_softwareversion:string)=(' || REPLACE(REPLACE(current_row.scanner_softwareversion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modality IS NOT NULL) THEN 
              fullText := fullText || '(modality:string)=(' || REPLACE(REPLACE(current_row.modality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.frames IS NOT NULL) THEN 
              fullText := fullText || '(frames:integer)=(' || current_row.frames || ')';
          END IF;
          IF (current_row.operator IS NOT NULL) THEN 
              fullText := fullText || '(operator:string)=(' || REPLACE(REPLACE(current_row.operator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractResource WHERE xnat_imageScanData_xnat_imagescandata_id=current_row.xnat_imagescandata_id ORDER BY xnat_abstractresource_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource( parent_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(file_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.validation_xnat_validationdata_id IS NOT NULL)) THEN
            fullText := fullText || '(validation_xnat_validationdata_id:integer)=(' || current_row.validation_xnat_validationdata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_validationData(current_row.validation_xnat_validationdata_id, child_count,$3,false,false);
              fullText := fullText || '(validation_validationdata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.starttime IS NOT NULL) THEN 
              fullText := fullText || '(starttime:time)=(' || current_row.starttime || ')';
          END IF;
          IF (current_row.start_date IS NOT NULL) THEN 
              fullText := fullText || '(start_date:date)=(' || current_row.start_date || ')';
          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.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uid IS NOT NULL) THEN 
              fullText := fullText || '(uid:string)=(' || REPLACE(REPLACE(current_row.uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.imageScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(imagescandata_info:integer)=(' || current_row.imagescandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData_meta_data(current_row.imageScanData_info, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_info_imagescandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_imagescandata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_imagescandata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:imageScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_imageScanData_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 xnat_imageScanData_share_history WHERE sharing_share_xnat_imageScanDat_xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version ORDER BY xnat_imagescandata_share_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData_share_history( parent_row.xnat_imagescandata_share_id, child_count,$3,false,false);
              fullText := fullText || '(sharing_share_imagescandata_share' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.image_session_id IS NOT NULL) THEN 
              fullText := fullText || '(image_session_id:string)=(' || REPLACE(REPLACE(current_row.image_session_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.note IS NOT NULL) THEN 
              fullText := fullText || '(note:string)=(' || REPLACE(REPLACE(current_row.note,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.quality IS NOT NULL) THEN 
              fullText := fullText || '(quality:string)=(' || REPLACE(REPLACE(current_row.quality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.condition IS NOT NULL) THEN 
              fullText := fullText || '(condition:string)=(' || REPLACE(REPLACE(current_row.condition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.series_description IS NOT NULL) THEN 
              fullText := fullText || '(series_description:string)=(' || REPLACE(REPLACE(current_row.series_description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.series_class IS NOT NULL) THEN 
              fullText := fullText || '(series_class:string)=(' || REPLACE(REPLACE(current_row.series_class,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.documentation IS NOT NULL) THEN 
              fullText := fullText || '(documentation:string)=(' || REPLACE(REPLACE(current_row.documentation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner IS NOT NULL) THEN 
              fullText := fullText || '(scanner:string)=(' || REPLACE(REPLACE(current_row.scanner,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_manufacturer IS NOT NULL) THEN 
              fullText := fullText || '(scanner_manufacturer:string)=(' || REPLACE(REPLACE(current_row.scanner_manufacturer,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_model IS NOT NULL) THEN 
              fullText := fullText || '(scanner_model:string)=(' || REPLACE(REPLACE(current_row.scanner_model,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_softwareversion IS NOT NULL) THEN 
              fullText := fullText || '(scanner_softwareversion:string)=(' || REPLACE(REPLACE(current_row.scanner_softwareversion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modality IS NOT NULL) THEN 
              fullText := fullText || '(modality:string)=(' || REPLACE(REPLACE(current_row.modality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.frames IS NOT NULL) THEN 
              fullText := fullText || '(frames:integer)=(' || current_row.frames || ')';
          END IF;
          IF (current_row.operator IS NOT NULL) THEN 
              fullText := fullText || '(operator:string)=(' || REPLACE(REPLACE(current_row.operator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractResource_history WHERE xnat_imageScanData_xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version ORDER BY xnat_abstractresource_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_history( parent_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(file_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.validation_xnat_validationdata_id IS NOT NULL)) THEN
            fullText := fullText || '(validation_xnat_validationdata_id:integer)=(' || current_row.validation_xnat_validationdata_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_validationData_history WHERE  xnat_validationdata_id=current_row.validation_xnat_validationdata_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_validationData_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(validation_validationdata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.starttime IS NOT NULL) THEN 
              fullText := fullText || '(starttime:time)=(' || current_row.starttime || ')';
          END IF;
          IF (current_row.start_date IS NOT NULL) THEN 
              fullText := fullText || '(start_date:date)=(' || current_row.start_date || ')';
          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.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uid IS NOT NULL) THEN 
              fullText := fullText || '(uid:string)=(' || REPLACE(REPLACE(current_row.uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.imageScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(imagescandata_info:integer)=(' || current_row.imagescandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData_meta_data(current_row.imageScanData_info, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_info_imagescandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_imagescandata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_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.ie_xnat_imagescandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_imagesessiondata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:imageSessionData)(';
      FOR current_row IN SELECT * FROM xnat_imageSessionData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
        END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_regionResource WHERE session_id=current_row.id ORDER BY xnat_regionresource_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource( parent_row.xnat_regionresource_id, child_count,$3,false,false);
              fullText := fullText || '(session_id_regionresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.scanner IS NOT NULL) THEN 
              fullText := fullText || '(scanner:string)=(' || REPLACE(REPLACE(current_row.scanner,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_manufacturer IS NOT NULL) THEN 
              fullText := fullText || '(scanner_manufacturer:string)=(' || REPLACE(REPLACE(current_row.scanner_manufacturer,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_model IS NOT NULL) THEN 
              fullText := fullText || '(scanner_model:string)=(' || REPLACE(REPLACE(current_row.scanner_model,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.operator IS NOT NULL) THEN 
              fullText := fullText || '(operator:string)=(' || REPLACE(REPLACE(current_row.operator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.prearchivepath IS NOT NULL) THEN 
              fullText := fullText || '(prearchivepath:string)=(' || REPLACE(REPLACE(current_row.prearchivepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_imageScanData WHERE image_session_id=current_row.id ORDER BY xnat_imagescandata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData( parent_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(image_session_id_imagescandata' || 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 xnat_reconstructedImageData WHERE image_session_id=current_row.id ORDER BY xnat_reconstructedimagedata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData( parent_row.xnat_reconstructedimagedata_id, child_count,$3,false,false);
              fullText := fullText || '(image_session_id_reconstructedimagedata' || 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 xnat_imageAssessorData WHERE imageSession_ID=current_row.id ORDER BY id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageAssessorData( parent_row.id, child_count,$3,false,false);
              fullText := fullText || '(imagesession_id_imageassessordata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.dcmaccessionnumber IS NOT NULL) THEN 
              fullText := fullText || '(dcmaccessionnumber:string)=(' || REPLACE(REPLACE(current_row.dcmaccessionnumber,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmpatientid IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientid:string)=(' || REPLACE(REPLACE(current_row.dcmpatientid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmpatientname IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientname:string)=(' || REPLACE(REPLACE(current_row.dcmpatientname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmpatientbirthdate IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientbirthdate:date)=(' || current_row.dcmpatientbirthdate || ')';
          END IF;
          IF (current_row.dcmpatientweight IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientweight:float)=(' || current_row.dcmpatientweight || ')';
          END IF;
          IF (current_row.session_type IS NOT NULL) THEN 
              fullText := fullText || '(session_type:string)=(' || REPLACE(REPLACE(current_row.session_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modality IS NOT NULL) THEN 
              fullText := fullText || '(modality:string)=(' || REPLACE(REPLACE(current_row.modality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uid IS NOT NULL) THEN 
              fullText := fullText || '(uid:string)=(' || REPLACE(REPLACE(current_row.uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.study_id IS NOT NULL) THEN 
              fullText := fullText || '(study_id:string)=(' || REPLACE(REPLACE(current_row.study_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.imageSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(imagesessiondata_info:integer)=(' || current_row.imagesessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageSessionData_meta_data(current_row.imageSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(imagesessiondata_info_imagesessiondata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_imagesessiondata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:imageSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_imageSessionData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_subjectAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_subjectAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_regionResource_history WHERE session_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_regionresource_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource_history( parent_row.xnat_regionresource_id, child_count,$3,false,false);
              fullText := fullText || '(session_id_regionresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.scanner IS NOT NULL) THEN 
              fullText := fullText || '(scanner:string)=(' || REPLACE(REPLACE(current_row.scanner,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_manufacturer IS NOT NULL) THEN 
              fullText := fullText || '(scanner_manufacturer:string)=(' || REPLACE(REPLACE(current_row.scanner_manufacturer,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.scanner_model IS NOT NULL) THEN 
              fullText := fullText || '(scanner_model:string)=(' || REPLACE(REPLACE(current_row.scanner_model,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.operator IS NOT NULL) THEN 
              fullText := fullText || '(operator:string)=(' || REPLACE(REPLACE(current_row.operator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.prearchivepath IS NOT NULL) THEN 
              fullText := fullText || '(prearchivepath:string)=(' || REPLACE(REPLACE(current_row.prearchivepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_imageScanData_history WHERE image_session_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_imagescandata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData_history( parent_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(image_session_id_imagescandata' || 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 xnat_reconstructedImageData_history WHERE image_session_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_reconstructedimagedata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData_history( parent_row.xnat_reconstructedimagedata_id, child_count,$3,false,false);
              fullText := fullText || '(image_session_id_reconstructedimagedata' || 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 xnat_imageAssessorData_history WHERE imageSession_ID=current_row.id AND xft_version=current_row.xft_version ORDER BY id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageAssessorData_history( parent_row.id, child_count,$3,false,false);
              fullText := fullText || '(imagesession_id_imageassessordata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.dcmaccessionnumber IS NOT NULL) THEN 
              fullText := fullText || '(dcmaccessionnumber:string)=(' || REPLACE(REPLACE(current_row.dcmaccessionnumber,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmpatientid IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientid:string)=(' || REPLACE(REPLACE(current_row.dcmpatientid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmpatientname IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientname:string)=(' || REPLACE(REPLACE(current_row.dcmpatientname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmpatientbirthdate IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientbirthdate:date)=(' || current_row.dcmpatientbirthdate || ')';
          END IF;
          IF (current_row.dcmpatientweight IS NOT NULL) THEN 
              fullText := fullText || '(dcmpatientweight:float)=(' || current_row.dcmpatientweight || ')';
          END IF;
          IF (current_row.session_type IS NOT NULL) THEN 
              fullText := fullText || '(session_type:string)=(' || REPLACE(REPLACE(current_row.session_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.modality IS NOT NULL) THEN 
              fullText := fullText || '(modality:string)=(' || REPLACE(REPLACE(current_row.modality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uid IS NOT NULL) THEN 
              fullText := fullText || '(uid:string)=(' || REPLACE(REPLACE(current_row.uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.study_id IS NOT NULL) THEN 
              fullText := fullText || '(study_id:string)=(' || REPLACE(REPLACE(current_row.study_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.imageSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(imagesessiondata_info:integer)=(' || current_row.imagesessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageSessionData_meta_data(current_row.imageSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(imagesessiondata_info_imagesessiondata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_mrassessordata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:mrAssessorData)(';
      FOR current_row IN SELECT * FROM xnat_mrAssessorData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.mrAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrassessordata_info:integer)=(' || current_row.mrassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrAssessorData_meta_data(current_row.mrAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(mrassessordata_info_mrassessordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageAssessorData( $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.ie_xnat_mrassessordata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_mrassessordata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:mrAssessorData_history)(';
      FOR current_row IN SELECT * FROM xnat_mrAssessorData_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 ((current_row.mrAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrassessordata_info:integer)=(' || current_row.mrassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrAssessorData_meta_data(current_row.mrAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(mrassessordata_info_mrassessordata_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.ie_xnat_mrassessordata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_qcscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:qcScanData)(';
      FOR current_row IN SELECT * FROM xnat_qcScanData WHERE  xnat_qcscandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.imagescan_id IS NOT NULL) THEN 
              fullText := fullText || '(imagescan_id:string)=(' || REPLACE(REPLACE(current_row.imagescan_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rater IS NOT NULL) THEN 
              fullText := fullText || '(rater:string)=(' || REPLACE(REPLACE(current_row.rater,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.coverage IS NOT NULL) THEN 
              fullText := fullText || '(coverage:string)=(' || REPLACE(REPLACE(current_row.coverage,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.motion IS NOT NULL) THEN 
              fullText := fullText || '(motion:string)=(' || REPLACE(REPLACE(current_row.motion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.otherimageartifacts IS NOT NULL) THEN 
              fullText := fullText || '(otherimageartifacts:string)=(' || REPLACE(REPLACE(current_row.otherimageartifacts,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.pass IS NOT NULL) THEN 
              fullText := fullText || '(pass:string)=(' || REPLACE(REPLACE(current_row.pass,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rating IS NOT NULL) THEN 
              fullText := fullText || '(rating:string)=(' || REPLACE(REPLACE(current_row.rating,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rating_scale IS NOT NULL) THEN 
              fullText := fullText || '(rating_scale:string)=(' || REPLACE(REPLACE(current_row.rating_scale,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcScanData_field WHERE fields_field_xnat_qcScanData_xnat_qcscandata_id=current_row.xnat_qcscandata_id ORDER BY xnat_qcscandata_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData_field( parent_row.xnat_qcscandata_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_qcscandata_field' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.qcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(qcscandata_info:integer)=(' || current_row.qcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData_meta_data(current_row.qcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(qcscandata_info_qcscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.scans_scan_xnat_qcManualAssesso_id IS NOT NULL)) THEN
            fullText := fullText || '(scans_scan_xnat_qcmanualassesso_id:string)=(' || current_row.scans_scan_xnat_qcmanualassesso_id || ')';
        END IF;
          IF (current_row.xnat_qcscandata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcscandata_id:integer)=(' || current_row.xnat_qcscandata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_qcscandata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:qcScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_qcScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.imagescan_id IS NOT NULL) THEN 
              fullText := fullText || '(imagescan_id:string)=(' || REPLACE(REPLACE(current_row.imagescan_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rater IS NOT NULL) THEN 
              fullText := fullText || '(rater:string)=(' || REPLACE(REPLACE(current_row.rater,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.coverage IS NOT NULL) THEN 
              fullText := fullText || '(coverage:string)=(' || REPLACE(REPLACE(current_row.coverage,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.motion IS NOT NULL) THEN 
              fullText := fullText || '(motion:string)=(' || REPLACE(REPLACE(current_row.motion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.otherimageartifacts IS NOT NULL) THEN 
              fullText := fullText || '(otherimageartifacts:string)=(' || REPLACE(REPLACE(current_row.otherimageartifacts,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.pass IS NOT NULL) THEN 
              fullText := fullText || '(pass:string)=(' || REPLACE(REPLACE(current_row.pass,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rating IS NOT NULL) THEN 
              fullText := fullText || '(rating:string)=(' || REPLACE(REPLACE(current_row.rating,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rating_scale IS NOT NULL) THEN 
              fullText := fullText || '(rating_scale:string)=(' || REPLACE(REPLACE(current_row.rating_scale,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcScanData_field_history WHERE fields_field_xnat_qcScanData_xnat_qcscandata_id=current_row.xnat_qcscandata_id AND xft_version=current_row.xft_version ORDER BY xnat_qcscandata_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData_field_history( parent_row.xnat_qcscandata_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_qcscandata_field' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.extension IS NOT NULL)) THEN
            fullText := fullText || '(extension:integer)=(' || current_row.extension || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xdat_meta_element(current_row.extension, child_count,$3,false,false);
              fullText := fullText || '(extension_meta_element:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.qcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(qcscandata_info:integer)=(' || current_row.qcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData_meta_data(current_row.qcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(qcscandata_info_qcscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.scans_scan_xnat_qcManualAssesso_id IS NOT NULL)) THEN
            fullText := fullText || '(scans_scan_xnat_qcmanualassesso_id:string)=(' || current_row.scans_scan_xnat_qcmanualassesso_id || ')';
        END IF;
          IF (current_row.xnat_qcscandata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcscandata_id:integer)=(' || current_row.xnat_qcscandata_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.ie_xnat_qcscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.ie_xnat_resource(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:resource)(';
      FOR current_row IN SELECT * FROM xnat_resource WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource(current_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.provenance_prov_process_id IS NOT NULL)) THEN
            fullText := fullText || '(provenance_prov_process_id:integer)=(' || current_row.provenance_prov_process_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_prov_process(current_row.provenance_prov_process_id, child_count,$3,false,false);
              fullText := fullText || '(provenance_process:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*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.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.resource_info IS NOT NULL)) THEN
            fullText := fullText || '(resource_info:integer)=(' || current_row.resource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_resource_meta_data(current_row.resource_info, child_count,$3,false,false);
              fullText := fullText || '(resource_info_resource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_resource_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:resource_history)(';
      FOR current_row IN SELECT * FROM xnat_resource_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_abstractResource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_abstractResource_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(abstractresource_abstractresource:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.provenance_prov_process_id IS NOT NULL)) THEN
            fullText := fullText || '(provenance_prov_process_id:integer)=(' || current_row.provenance_prov_process_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM prov_process_history WHERE  prov_process_id=current_row.provenance_prov_process_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_prov_process_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(provenance_process:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*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.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.resource_info IS NOT NULL)) THEN
            fullText := fullText || '(resource_info:integer)=(' || current_row.resource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_resource_meta_data(current_row.resource_info, child_count,$3,false,false);
              fullText := fullText || '(resource_info_resource_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_abstractResource_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_resourceseries(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:resourceSeries)(';
      FOR current_row IN SELECT * FROM xnat_resourceSeries WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource(current_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.path IS NOT NULL) THEN 
              fullText := fullText || '(path:string)=(' || REPLACE(REPLACE(current_row.path,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pattern IS NOT NULL) THEN 
              fullText := fullText || '(pattern:string)=(' || REPLACE(REPLACE(current_row.pattern,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.count IS NOT NULL) THEN 
              fullText := fullText || '(count:integer)=(' || current_row.count || ')';
          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.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*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.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.resourceSeries_info IS NOT NULL)) THEN
            fullText := fullText || '(resourceseries_info:integer)=(' || current_row.resourceseries_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_resourceSeries_meta_data(current_row.resourceSeries_info, child_count,$3,false,false);
              fullText := fullText || '(resourceseries_info_resourceseries_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_resourceseries_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:resourceSeries_history)(';
      FOR current_row IN SELECT * FROM xnat_resourceSeries_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_abstractResource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_abstractResource_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(abstractresource_abstractresource:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.path IS NOT NULL) THEN 
              fullText := fullText || '(path:string)=(' || REPLACE(REPLACE(current_row.path,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pattern IS NOT NULL) THEN 
              fullText := fullText || '(pattern:string)=(' || REPLACE(REPLACE(current_row.pattern,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.count IS NOT NULL) THEN 
              fullText := fullText || '(count:integer)=(' || current_row.count || ')';
          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.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*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.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.resourceSeries_info IS NOT NULL)) THEN
            fullText := fullText || '(resourceseries_info:integer)=(' || current_row.resourceseries_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_resourceSeries_meta_data(current_row.resourceSeries_info, child_count,$3,false,false);
              fullText := fullText || '(resourceseries_info_resourceseries_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_abstractResource_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_subjectassessordata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:subjectAssessorData)(';
      FOR current_row IN SELECT * FROM xnat_subjectAssessorData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_experimentData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.subject_id IS NOT NULL) THEN 
              fullText := fullText || '(subject_id:string)=(' || REPLACE(REPLACE(current_row.subject_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.age IS NOT NULL) THEN 
              fullText := fullText || '(age:float)=(' || current_row.age || ')';
          END IF;
        IF ((current_row.subjectAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(subjectassessordata_info:integer)=(' || current_row.subjectassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_subjectAssessorData_meta_data(current_row.subjectAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_info_subjectassessordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_experimentData( $1, child_count,$3,$4,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.ie_xnat_subjectassessordata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:subjectAssessorData_history)(';
      FOR current_row IN SELECT * FROM xnat_subjectAssessorData_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_experimentData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_experimentData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(experimentdata_experimentdata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.subject_id IS NOT NULL) THEN 
              fullText := fullText || '(subject_id:string)=(' || REPLACE(REPLACE(current_row.subject_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.age IS NOT NULL) THEN 
              fullText := fullText || '(age:float)=(' || current_row.age || ')';
          END IF;
        IF ((current_row.subjectAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(subjectassessordata_info:integer)=(' || current_row.subjectassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_subjectAssessorData_meta_data(current_row.subjectAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_info_subjectassessordata_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_experimentData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(experimentdata_experimentdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

--
-- Name: removeviews(); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.removeviews() RETURNS character varying
    LANGUAGE plpgsql
    AS $$ DECLARE  viewName name;  viewCounter int8; 
BEGIN  SELECT INTO viewName getnextview();  SELECT INTO viewCounter viewCount();  WHILE (viewCounter > 0)   LOOP
EXECUTE 'DROP VIEW '|| viewName || ' CASCADE';   RAISE NOTICE 'DROPPED %. % more.',viewName,viewCounter;   SELECT INTO viewName getnextview();
SELECT INTO viewCounter viewCount();  END LOOP;   RETURN ('DONE'); END; $$;


ALTER FUNCTION public.removeviews() OWNER TO xnat;

--
-- Name: schema_exists(character varying); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.schema_exists(character varying) RETURNS boolean
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM pg_namespace WHERE nspname=LOWER($1)
     LOOP
          RETURN TRUE;
      END LOOP;

	 RETURN FALSE;
    end;
$_$;


ALTER FUNCTION public.schema_exists(character varying) OWNER TO xnat;

--
-- Name: stringstosortedtable(character varying[]); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.stringstosortedtable(character varying[]) RETURNS SETOF public.sortedstrings
    LANGUAGE plpgsql
    AS $_$DECLARE  
ss sortedstrings%ROWTYPE; 
i int4;  
BEGIN  
i :=1 ;
WHILE ($1[i] IS NOT NULL) 
LOOP   
		FOR ss IN 
			SELECT * FROM getSortedString($1[i],i) 
		LOOP
			RAISE NOTICE 'SORTED STRING: %,%',ss.strings,ss.sort_order;
			RETURN NEXT ss;
		END LOOP;
		i:=i+1; 
	END LOOP; 
	RETURN; 
END;$_$;


ALTER FUNCTION public.stringstosortedtable(character varying[]) OWNER TO xnat;

--
-- Name: trigger_exists(character varying); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.trigger_exists(character varying) RETURNS boolean
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM pg_trigger WHERE  tgname=LOWER($1)
     LOOP
          RETURN TRUE;
      END LOOP;

	 RETURN FALSE;
    end;
$_$;


ALTER FUNCTION public.trigger_exists(character varying) OWNER TO xnat;

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

CREATE FUNCTION public.update_ls_arc_archivespecification(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='arc:ArchiveSpecification' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_ArchiveSpecification.*, meta.meta_data_id FROM arc_ArchiveSpecification LEFT JOIN arc_ArchiveSpecification_meta_data meta ON arc_ArchiveSpecification.ArchiveSpecification_info=meta.meta_data_id WHERE  arc_archivespecification_id=$1
      LOOP
         UPDATE arc_ArchiveSpecification_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_archivespecification_notification_type(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_ArchiveSpecification_notification_type.*, meta.meta_data_id FROM arc_ArchiveSpecification_notification_type LEFT JOIN arc_ArchiveSpecification_notification_type_meta_data meta ON arc_ArchiveSpecification_notification_type.ArchiveSpecification_notification_type_info=meta.meta_data_id WHERE  arc_archivespecification_notification_type_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:ArchiveSpecification/notification_types/notification_type
        IF ((current_row.notification_types_notification_arc_archivespecification_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_ArchiveSpecification(current_row.notification_types_notification_arc_archivespecification_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_fieldspecification(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_fieldSpecification.*, meta.meta_data_id FROM arc_fieldSpecification LEFT JOIN arc_fieldSpecification_meta_data meta ON arc_fieldSpecification.fieldSpecification_info=meta.meta_data_id WHERE  arc_fieldspecification_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:ArchiveSpecification/fieldSpecifications/fieldSpecification
        IF ((current_row.fieldspecifications_fieldspecif_arc_archivespecification_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_ArchiveSpecification(current_row.fieldspecifications_fieldspecif_arc_archivespecification_id, $2);
        END IF;

        --PROCESS SUBORDINATE RELATION arc:project/fieldSpecifications/fieldSpecification
        IF ((current_row.fieldspecifications_fieldspecif_arc_project_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_project(current_row.fieldspecifications_fieldspecif_arc_project_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_pathinfo(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_pathInfo.*, meta.meta_data_id FROM arc_pathInfo LEFT JOIN arc_pathInfo_meta_data meta ON arc_pathInfo.pathInfo_info=meta.meta_data_id WHERE  arc_pathinfo_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION arc:ArchiveSpecification/globalPaths
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_ArchiveSpecification WHERE globalpaths_arc_pathinfo_id=current_row.arc_pathinfo_id
        LOOP
        PERFORM update_ls_arc_ArchiveSpecification( parent_row.arc_archivespecification_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION arc:project/paths
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_project WHERE paths_arc_pathinfo_id=current_row.arc_pathinfo_id
        LOOP
        PERFORM update_ls_arc_project( parent_row.arc_project_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_pipelinedata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT arc_pipelineData.arc_pipelinedata_id AS arc_pipelineData7, table1.element_name AS xdat_meta_element31, table2.insert_date AS arc_pipelineData_meta_data38 FROM arc_pipelineData arc_pipelineData   LEFT JOIN xdat_meta_element table1 ON arc_pipelineData.extension=table1.xdat_meta_element_id   LEFT JOIN arc_pipelineData_meta_data table2 ON arc_pipelineData.pipelineData_info=table2.meta_data_id) SEARCH WHERE 
 ( (arc_pipelineData7=$1))
      LOOP
         IF (current_row.xdat_meta_element31 IS NULL) THEN 
             PERFORM update_ls_ext_arc_pipelineData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element31='arc:project_descendant_pipeline') THEN
                PERFORM update_ls_arc_project_descendant_pipeline( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element31='arc:project_pipeline') THEN
                PERFORM update_ls_arc_project_pipeline( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element31;
                    PERFORM update_ls_ext_arc_pipelineData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_pipelineparameterdata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_pipelineParameterData.*, meta.meta_data_id FROM arc_pipelineParameterData LEFT JOIN arc_pipelineParameterData_meta_data meta ON arc_pipelineParameterData.pipelineParameterData_info=meta.meta_data_id WHERE  arc_pipelineparameterdata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:pipelineData/parameters/parameter
        IF ((current_row.parameters_parameter_arc_pipeli_arc_pipelinedata_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_pipelineData(current_row.parameters_parameter_arc_pipeli_arc_pipelinedata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_project(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project.*, meta.meta_data_id FROM arc_project LEFT JOIN arc_project_meta_data meta ON arc_project.project_info=meta.meta_data_id WHERE  arc_project_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:ArchiveSpecification/projects/project
        IF ((current_row.projects_project_arc_ArchiveSpe_arc_archivespecification_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_ArchiveSpecification(current_row.projects_project_arc_ArchiveSpe_arc_archivespecification_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_project_descendant(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project_descendant.*, meta.meta_data_id FROM arc_project_descendant LEFT JOIN arc_project_descendant_meta_data meta ON arc_project_descendant.project_descendant_info=meta.meta_data_id WHERE  arc_project_descendant_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:project/pipelines/descendants/descendant
        IF ((current_row.pipelines_descendants_descendan_arc_project_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_project(current_row.pipelines_descendants_descendan_arc_project_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_project_descendant_pipeline(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project_descendant_pipeline.*, meta.meta_data_id FROM arc_project_descendant_pipeline LEFT JOIN arc_project_descendant_pipeline_meta_data meta ON arc_project_descendant_pipeline.project_descendant_pipeline_info=meta.meta_data_id WHERE  arc_pipelinedata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:project_descendant/pipeline
        IF ((current_row.arc_project_descendant_arc_project_descendant_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_project_descendant(current_row.arc_project_descendant_arc_project_descendant_id, $2);
        END IF;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_arc_pipelineData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_project_pipeline(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project_pipeline.*, meta.meta_data_id FROM arc_project_pipeline LEFT JOIN arc_project_pipeline_meta_data meta ON arc_project_pipeline.project_pipeline_info=meta.meta_data_id WHERE  arc_pipelinedata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:project/pipelines/pipeline
        IF ((current_row.pipelines_pipeline_arc_project_arc_project_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_project(current_row.pipelines_pipeline_arc_project_arc_project_id, $2);
        END IF;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_arc_pipelineData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_arc_property(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_property.*, meta.meta_data_id FROM arc_property LEFT JOIN arc_property_meta_data meta ON arc_property.property_info=meta.meta_data_id WHERE  arc_property_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION arc:project/properties/property
        IF ((current_row.properties_property_arc_project_arc_project_id IS NOT NULL)) THEN
        PERFORM update_ls_arc_project(current_row.properties_property_arc_project_arc_project_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_catalog(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT cat_catalog.cat_catalog_id AS cat_catalog6, table1.element_name AS xdat_meta_element105, table2.insert_date AS cat_catalog_meta_data112 FROM cat_catalog cat_catalog   LEFT JOIN xdat_meta_element table1 ON cat_catalog.extension=table1.xdat_meta_element_id   LEFT JOIN cat_catalog_meta_data table2 ON cat_catalog.catalog_info=table2.meta_data_id) SEARCH WHERE 
 ( (cat_catalog6=$1))
      LOOP
         IF (current_row.xdat_meta_element105 IS NULL) THEN 
             PERFORM update_ls_ext_cat_catalog( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element105='cat:dcmCatalog') THEN
                PERFORM update_ls_cat_dcmCatalog( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element105;
                    PERFORM update_ls_ext_cat_catalog( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_catalog_metafield(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_catalog_metaField.*, meta.meta_data_id FROM cat_catalog_metaField LEFT JOIN cat_catalog_metaField_meta_data meta ON cat_catalog_metaField.catalog_metaField_info=meta.meta_data_id WHERE  cat_catalog_metafield_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION cat:catalog/metaFields/metaField
        IF ((current_row.metafields_metafield_cat_catalo_cat_catalog_id IS NOT NULL)) THEN
        PERFORM update_ls_cat_catalog(current_row.metafields_metafield_cat_catalo_cat_catalog_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_catalog_tag(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_catalog_tag.*, meta.meta_data_id FROM cat_catalog_tag LEFT JOIN cat_catalog_tag_meta_data meta ON cat_catalog_tag.catalog_tag_info=meta.meta_data_id WHERE  cat_catalog_tag_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION cat:catalog/tags/tag
        IF ((current_row.tags_tag_cat_catalog_cat_catalog_id IS NOT NULL)) THEN
        PERFORM update_ls_cat_catalog(current_row.tags_tag_cat_catalog_cat_catalog_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_dcmcatalog(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='cat:dcmCatalog' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_dcmCatalog.*, meta.meta_data_id FROM cat_dcmCatalog LEFT JOIN cat_dcmCatalog_meta_data meta ON cat_dcmCatalog.dcmCatalog_info=meta.meta_data_id WHERE  cat_catalog_id=$1
      LOOP
         UPDATE cat_dcmCatalog_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_cat_catalog( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_dcmentry(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_dcmEntry.*, meta.meta_data_id FROM cat_dcmEntry LEFT JOIN cat_dcmEntry_meta_data meta ON cat_dcmEntry.dcmEntry_info=meta.meta_data_id WHERE  cat_entry_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_cat_entry( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_entry(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT cat_entry.cat_entry_id AS cat_entry16, table1.element_name AS xdat_meta_element51, table2.insert_date AS cat_entry_meta_data58 FROM cat_entry cat_entry   LEFT JOIN xdat_meta_element table1 ON cat_entry.extension=table1.xdat_meta_element_id   LEFT JOIN cat_entry_meta_data table2 ON cat_entry.entry_info=table2.meta_data_id) SEARCH WHERE 
 ( (cat_entry16=$1))
      LOOP
         IF (current_row.xdat_meta_element51 IS NULL) THEN 
             PERFORM update_ls_ext_cat_entry( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element51='cat:dcmEntry') THEN
                PERFORM update_ls_cat_dcmEntry( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element51;
                    PERFORM update_ls_ext_cat_entry( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_entry_metafield(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_entry_metaField.*, meta.meta_data_id FROM cat_entry_metaField LEFT JOIN cat_entry_metaField_meta_data meta ON cat_entry_metaField.entry_metaField_info=meta.meta_data_id WHERE  cat_entry_metafield_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION cat:entry/metaFields/metaField
        IF ((current_row.metafields_metafield_cat_entry_cat_entry_id IS NOT NULL)) THEN
        PERFORM update_ls_cat_entry(current_row.metafields_metafield_cat_entry_cat_entry_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_cat_entry_tag(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_entry_tag.*, meta.meta_data_id FROM cat_entry_tag LEFT JOIN cat_entry_tag_meta_data meta ON cat_entry_tag.entry_tag_info=meta.meta_data_id WHERE  cat_entry_tag_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION cat:entry/tags/tag
        IF ((current_row.tags_tag_cat_entry_cat_entry_id IS NOT NULL)) THEN
        PERFORM update_ls_cat_entry(current_row.tags_tag_cat_entry_cat_entry_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_arc_pipelinedata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_pipelineData.*, meta.meta_data_id FROM arc_pipelineData LEFT JOIN arc_pipelineData_meta_data meta ON arc_pipelineData.pipelineData_info=meta.meta_data_id WHERE  arc_pipelinedata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_cat_catalog(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='cat:catalog' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_catalog.*, meta.meta_data_id FROM cat_catalog LEFT JOIN cat_catalog_meta_data meta ON cat_catalog.catalog_info=meta.meta_data_id WHERE  cat_catalog_id=$1
      LOOP
         UPDATE cat_catalog_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_cat_entry(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='cat:entry' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_entry.*, meta.meta_data_id FROM cat_entry LEFT JOIN cat_entry_meta_data meta ON cat_entry.entry_info=meta.meta_data_id WHERE  cat_entry_id=$1
      LOOP
         UPDATE cat_entry_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION cat:catalog/entries/entry
        IF ((current_row.entries_entry_cat_catalog_cat_catalog_id IS NOT NULL)) THEN
        PERFORM update_ls_cat_catalog(current_row.entries_entry_cat_catalog_cat_catalog_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_wrk_abstractexecutionenvironment(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_abstractExecutionEnvironment.*, meta.meta_data_id FROM wrk_abstractExecutionEnvironment LEFT JOIN wrk_abstractExecutionEnvironment_meta_data meta ON wrk_abstractExecutionEnvironment.abstractExecutionEnvironment_info=meta.meta_data_id WHERE  wrk_abstractexecutionenvironment_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION wrk:workflowData/executionEnvironment
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM wrk_workflowData WHERE executionenvironment_wrk_abstractexecutionenvironment_id=current_row.wrk_abstractexecutionenvironment_id
        LOOP
        PERFORM update_ls_wrk_workflowData( parent_row.wrk_workflowdata_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xdat_stored_search(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:stored_search' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_stored_search.*, meta.meta_data_id FROM xdat_stored_search LEFT JOIN xdat_stored_search_meta_data meta ON xdat_stored_search.stored_search_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xdat_stored_search_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_abstractdemographicdata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_abstractDemographicData.*, meta.meta_data_id FROM xnat_abstractDemographicData LEFT JOIN xnat_abstractDemographicData_meta_data meta ON xnat_abstractDemographicData.abstractDemographicData_info=meta.meta_data_id WHERE  xnat_abstractdemographicdata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:subjectData/demographics
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_subjectData WHERE demographics_xnat_abstractdemographicdata_id=current_row.xnat_abstractdemographicdata_id
        LOOP
        PERFORM update_ls_xnat_subjectData( parent_row.id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_abstractprotocol(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_abstractProtocol.*, meta.meta_data_id FROM xnat_abstractProtocol LEFT JOIN xnat_abstractProtocol_meta_data meta ON xnat_abstractProtocol.abstractProtocol_info=meta.meta_data_id WHERE  xnat_abstractprotocol_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:projectData/studyProtocol
        IF ((current_row.xnat_projectData_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_projectData(current_row.xnat_projectData_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_abstractresource(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_abstractResource.*, meta.meta_data_id FROM xnat_abstractResource LEFT JOIN xnat_abstractResource_meta_data meta ON xnat_abstractResource.abstractResource_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS MAPPING TABLE RELATION xnat:projectData/resources/resource
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_resource WHERE  xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id
           LOOP 
               PERFORM update_ls_xnat_projectData( mapping_row.xnat_projectData_id, $2);
           END LOOP; 
        END; 

        --PROCESS MAPPING TABLE RELATION xnat:subjectData/resources/resource
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_subjectData_resource WHERE  xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id
           LOOP 
               PERFORM update_ls_xnat_subjectData( mapping_row.xnat_subjectData_id, $2);
           END LOOP; 
        END; 

        --PROCESS MAPPING TABLE RELATION xnat:experimentData/resources/resource
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_experimentData_resource WHERE  xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id
           LOOP 
               PERFORM update_ls_xnat_experimentData( mapping_row.xnat_experimentData_id, $2);
           END LOOP; 
        END; 

        --PROCESS MAPPING TABLE RELATION xnat:reconstructedImageData/in/file
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM recon_in_resource WHERE  xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id
           LOOP 
               PERFORM update_ls_xnat_reconstructedImageData( mapping_row.xnat_reconstructedImageData_xnat_reconstructedimagedata_id, $2);
           END LOOP; 
        END; 

        --PROCESS MAPPING TABLE RELATION xnat:reconstructedImageData/out/file
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM recon_out_resource WHERE  xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id
           LOOP 
               PERFORM update_ls_xnat_reconstructedImageData( mapping_row.xnat_reconstructedImageData_xnat_reconstructedimagedata_id, $2);
           END LOOP; 
        END; 

        --PROCESS SUPERIOR RELATION xnat:regionResource/file
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_regionResource WHERE file_xnat_abstractresource_id=current_row.xnat_abstractresource_id
        LOOP
        PERFORM update_ls_xnat_regionResource( parent_row.xnat_regionresource_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:regionResource/baseimage
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_regionResource WHERE baseimage_xnat_abstractresource_id=current_row.xnat_abstractresource_id
        LOOP
        PERFORM update_ls_xnat_regionResource( parent_row.xnat_regionresource_id, $2);
        END LOOP;
        END;

        --PROCESS MAPPING TABLE RELATION xnat:imageAssessorData/in/file
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM img_assessor_in_resource WHERE  xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id
           LOOP 
               PERFORM update_ls_xnat_imageAssessorData( mapping_row.xnat_imageAssessorData_id, $2);
           END LOOP; 
        END; 

        --PROCESS MAPPING TABLE RELATION xnat:imageAssessorData/out/file
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM img_assessor_out_resource WHERE  xnat_abstractResource_xnat_abstractresource_id=current_row.xnat_abstractresource_id
           LOOP 
               PERFORM update_ls_xnat_imageAssessorData( mapping_row.xnat_imageAssessorData_id, $2);
           END LOOP; 
        END; 

        --PROCESS SUBORDINATE RELATION xnat:imageScanData/file
        IF ((current_row.xnat_imageScanData_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_imageScanData(current_row.xnat_imageScanData_xnat_imagescandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_abstractstatistics(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_abstractStatistics.*, meta.meta_data_id FROM xnat_abstractStatistics LEFT JOIN xnat_abstractStatistics_meta_data meta ON xnat_abstractStatistics.abstractStatistics_info=meta.meta_data_id WHERE  xnat_abstractstatistics_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:qcAssessmentData_scan_slice/sliceStatistics
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcAssessmentData_scan_slice WHERE slicestatistics_xnat_abstractstatistics_id=current_row.xnat_abstractstatistics_id
        LOOP
        PERFORM update_ls_xnat_qcAssessmentData_scan_slice( parent_row.xnat_qcassessmentdata_scan_slice_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:qcAssessmentData_scan/scanStatistics
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcAssessmentData_scan WHERE scanstatistics_xnat_abstractstatistics_id=current_row.xnat_abstractstatistics_id
        LOOP
        PERFORM update_ls_xnat_qcAssessmentData_scan( parent_row.xnat_qcassessmentdata_scan_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_abstractsubjectmetadata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_abstractSubjectMetadata.*, meta.meta_data_id FROM xnat_abstractSubjectMetadata LEFT JOIN xnat_abstractSubjectMetadata_meta_data meta ON xnat_abstractSubjectMetadata.abstractSubjectMetadata_info=meta.meta_data_id WHERE  xnat_abstractsubjectmetadata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:subjectData/metadata
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_subjectData WHERE metadata_xnat_abstractsubjectmetadata_id=current_row.xnat_abstractsubjectmetadata_id
        LOOP
        PERFORM update_ls_xnat_subjectData( parent_row.id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_deriveddata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_derivedData.*, meta.meta_data_id FROM xnat_derivedData LEFT JOIN xnat_derivedData_meta_data meta ON xnat_derivedData.derivedData_info=meta.meta_data_id WHERE  id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_experimentData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_experimentdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_experimentData.*, meta.meta_data_id FROM xnat_experimentData LEFT JOIN xnat_experimentData_meta_data meta ON xnat_experimentData.experimentData_info=meta.meta_data_id WHERE  id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_genericdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:genericData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_genericData.*, meta.meta_data_id FROM xnat_genericData LEFT JOIN xnat_genericData_meta_data meta ON xnat_genericData.genericData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_genericData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_experimentData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_imageassessordata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageAssessorData.*, meta.meta_data_id FROM xnat_imageAssessorData LEFT JOIN xnat_imageAssessorData_meta_data meta ON xnat_imageAssessorData.imageAssessorData_info=meta.meta_data_id WHERE  id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:imageSessionData/assessors/assessor
        IF ((current_row.imageSession_ID IS NOT NULL)) THEN
        PERFORM update_ls_xnat_imageSessionData(current_row.imageSession_ID, $2);
        END IF;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_derivedData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_imagescandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageScanData.*, meta.meta_data_id FROM xnat_imageScanData LEFT JOIN xnat_imageScanData_meta_data meta ON xnat_imageScanData.imageScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:imageSessionData/scans/scan
        IF ((current_row.image_session_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_imageSessionData(current_row.image_session_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_imagesessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageSessionData.*, meta.meta_data_id FROM xnat_imageSessionData LEFT JOIN xnat_imageSessionData_meta_data meta ON xnat_imageSessionData.imageSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_mrassessordata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrAssessorData.*, meta.meta_data_id FROM xnat_mrAssessorData LEFT JOIN xnat_mrAssessorData_meta_data meta ON xnat_mrAssessorData.mrAssessorData_info=meta.meta_data_id WHERE  id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_qcscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcScanData.*, meta.meta_data_id FROM xnat_qcScanData LEFT JOIN xnat_qcScanData_meta_data meta ON xnat_qcScanData.qcScanData_info=meta.meta_data_id WHERE  xnat_qcscandata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:qcManualAssessorData/scans/scan
        IF ((current_row.scans_scan_xnat_qcManualAssesso_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_qcManualAssessorData(current_row.scans_scan_xnat_qcManualAssesso_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_resource(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_resource.*, meta.meta_data_id FROM xnat_resource LEFT JOIN xnat_resource_meta_data meta ON xnat_resource.resource_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractResource( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_resourceseries(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_resourceSeries.*, meta.meta_data_id FROM xnat_resourceSeries LEFT JOIN xnat_resourceSeries_meta_data meta ON xnat_resourceSeries.resourceSeries_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractResource( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_ext_xnat_subjectassessordata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_subjectAssessorData.*, meta.meta_data_id FROM xnat_subjectAssessorData LEFT JOIN xnat_subjectAssessorData_meta_data meta ON xnat_subjectAssessorData.subjectAssessorData_info=meta.meta_data_id WHERE  id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:subjectData/experiments/experiment
        IF ((current_row.subject_ID IS NOT NULL)) THEN
        PERFORM update_ls_xnat_subjectData(current_row.subject_ID, $2);
        END IF;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_experimentData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_pipe_pipelinedetails(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_pipelineDetails.*, meta.meta_data_id FROM pipe_pipelineDetails LEFT JOIN pipe_pipelineDetails_meta_data meta ON pipe_pipelineDetails.pipelineDetails_info=meta.meta_data_id WHERE  path=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION pipe:PipelineRepository/pipeline
        IF ((current_row.pipe_PipelineRepository_pipe_pipelinerepository_id IS NOT NULL)) THEN
        PERFORM update_ls_pipe_PipelineRepository(current_row.pipe_PipelineRepository_pipe_pipelinerepository_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_pipe_pipelinedetails_element(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_pipelineDetails_element.*, meta.meta_data_id FROM pipe_pipelineDetails_element LEFT JOIN pipe_pipelineDetails_element_meta_data meta ON pipe_pipelineDetails_element.pipelineDetails_element_info=meta.meta_data_id WHERE  pipe_pipelinedetails_element_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION pipe:pipelineDetails/generatesElements/element
        IF ((current_row.generateselements_element_pipe__path IS NOT NULL)) THEN
        PERFORM update_ls_pipe_pipelineDetails(current_row.generateselements_element_pipe__path, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_pipe_pipelinedetails_parameter(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_pipelineDetails_parameter.*, meta.meta_data_id FROM pipe_pipelineDetails_parameter LEFT JOIN pipe_pipelineDetails_parameter_meta_data meta ON pipe_pipelineDetails_parameter.pipelineDetails_parameter_info=meta.meta_data_id WHERE  pipe_pipelinedetails_parameter_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION pipe:pipelineDetails/parameters/parameter
        IF ((current_row.parameters_parameter_pipe_pipel_path IS NOT NULL)) THEN
        PERFORM update_ls_pipe_pipelineDetails(current_row.parameters_parameter_pipe_pipel_path, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_pipe_pipelinerepository(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='pipe:PipelineRepository' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_PipelineRepository.*, meta.meta_data_id FROM pipe_PipelineRepository LEFT JOIN pipe_PipelineRepository_meta_data meta ON pipe_PipelineRepository.PipelineRepository_info=meta.meta_data_id WHERE  pipe_pipelinerepository_id=$1
      LOOP
         UPDATE pipe_PipelineRepository_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_prov_process(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='prov:process' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT prov_process.*, meta.meta_data_id FROM prov_process LEFT JOIN prov_process_meta_data meta ON prov_process.process_info=meta.meta_data_id WHERE  prov_process_id=$1
      LOOP
         UPDATE prov_process_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:derivedData/provenance
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_derivedData WHERE provenance_prov_process_id=current_row.prov_process_id
        LOOP
        PERFORM update_ls_xnat_derivedData( parent_row.id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:reconstructedImageData/provenance
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_reconstructedImageData WHERE provenance_prov_process_id=current_row.prov_process_id
        LOOP
        PERFORM update_ls_xnat_reconstructedImageData( parent_row.xnat_reconstructedimagedata_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:resource/provenance
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_resource WHERE provenance_prov_process_id=current_row.prov_process_id
        LOOP
        PERFORM update_ls_xnat_resource( parent_row.xnat_abstractresource_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_prov_processstep(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT prov_processStep.*, meta.meta_data_id FROM prov_processStep LEFT JOIN prov_processStep_meta_data meta ON prov_processStep.processStep_info=meta.meta_data_id WHERE  prov_processstep_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION prov:process/processStep
        IF ((current_row.prov_process_prov_process_id IS NOT NULL)) THEN
        PERFORM update_ls_prov_process(current_row.prov_process_prov_process_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_prov_processstep_library(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT prov_processStep_library.*, meta.meta_data_id FROM prov_processStep_library LEFT JOIN prov_processStep_library_meta_data meta ON prov_processStep_library.processStep_library_info=meta.meta_data_id WHERE  prov_processstep_library_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION prov:processStep/library
        IF ((current_row.prov_processStep_prov_processstep_id IS NOT NULL)) THEN
        PERFORM update_ls_prov_processStep(current_row.prov_processStep_prov_processstep_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

--
