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

CREATE FUNCTION public.i_xnat_qcassessmentdata(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:qcAssessmentData)(';
      FOR current_row IN SELECT * FROM xnat_qcAssessmentData 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_mrAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(mrassessordata_mrassessordata:XFTItem)=(' || tempText || ')';
        END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcAssessmentData_scan WHERE scans_scan_xnat_qcAssessmentDat_id=current_row.id ORDER BY xnat_qcassessmentdata_scan_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan( parent_row.xnat_qcassessmentdata_scan_id, child_count,$3,false,false);
              fullText := fullText || '(scans_scan_qcassessmentdata_scan' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        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.qcAssessmentData_info IS NOT NULL)) THEN
            fullText := fullText || '(qcassessmentdata_info:integer)=(' || current_row.qcassessmentdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_meta_data(current_row.qcAssessmentData_info, child_count,$3,false,false);
              fullText := fullText || '(qcassessmentdata_info_qcassessmentdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_mrAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(mrassessordata_mrassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_qcassessmentdata_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:qcAssessmentData_history)(';
      FOR current_row IN SELECT * FROM xnat_qcAssessmentData_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_mrAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_mrAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(mrassessordata_mrassessordata: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_qcAssessmentData_scan_history WHERE scans_scan_xnat_qcAssessmentDat_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_qcassessmentdata_scan_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan_history( parent_row.xnat_qcassessmentdata_scan_id, child_count,$3,false,false);
              fullText := fullText || '(scans_scan_qcassessmentdata_scan' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        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.qcAssessmentData_info IS NOT NULL)) THEN
            fullText := fullText || '(qcassessmentdata_info:integer)=(' || current_row.qcassessmentdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_meta_data(current_row.qcAssessmentData_info, child_count,$3,false,false);
              fullText := fullText || '(qcassessmentdata_info_qcassessmentdata_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_mrAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(mrassessordata_mrassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_qcassessmentdata_scan(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:qcAssessmentData_scan)(';
      FOR current_row IN SELECT * FROM xnat_qcAssessmentData_scan WHERE  xnat_qcassessmentdata_scan_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_qcAssessmentData_scan_slice WHERE sliceqc_slice_xnat_qcAssessment_xnat_qcassessmentdata_scan_id=current_row.xnat_qcassessmentdata_scan_id ORDER BY xnat_qcassessmentdata_scan_slice_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan_slice( parent_row.xnat_qcassessmentdata_scan_slice_id, child_count,$3,false,false);
              fullText := fullText || '(sliceqc_slice_qcassessmentdata_scan_slice' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.scanstatistics_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(scanstatistics_xnat_abstractstatistics_id:integer)=(' || current_row.scanstatistics_xnat_abstractstatistics_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractStatistics(current_row.scanstatistics_xnat_abstractstatistics_id, child_count,$3,false,false);
              fullText := fullText || '(scanstatistics_abstractstatistics:XFTItem)=(' || tempText || ')';
        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.qcAssessmentData_scan_info IS NOT NULL)) THEN
            fullText := fullText || '(qcassessmentdata_scan_info:integer)=(' || current_row.qcassessmentdata_scan_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan_meta_data(current_row.qcAssessmentData_scan_info, child_count,$3,false,false);
              fullText := fullText || '(qcassessmentdata_scan_info_qcassessmentdata_scan_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.scans_scan_xnat_qcAssessmentDat_id IS NOT NULL)) THEN
            fullText := fullText || '(scans_scan_xnat_qcassessmentdat_id:string)=(' || current_row.scans_scan_xnat_qcassessmentdat_id || ')';
        END IF;
          IF (current_row.xnat_qcassessmentdata_scan_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcassessmentdata_scan_id:integer)=(' || current_row.xnat_qcassessmentdata_scan_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_qcassessmentdata_scan_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:qcAssessmentData_scan_history)(';
      FOR current_row IN SELECT * FROM xnat_qcAssessmentData_scan_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_qcAssessmentData_scan_slice_history WHERE sliceqc_slice_xnat_qcAssessment_xnat_qcassessmentdata_scan_id=current_row.xnat_qcassessmentdata_scan_id AND xft_version=current_row.xft_version ORDER BY xnat_qcassessmentdata_scan_slice_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan_slice_history( parent_row.xnat_qcassessmentdata_scan_slice_id, child_count,$3,false,false);
              fullText := fullText || '(sliceqc_slice_qcassessmentdata_scan_slice' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.scanstatistics_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(scanstatistics_xnat_abstractstatistics_id:integer)=(' || current_row.scanstatistics_xnat_abstractstatistics_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_abstractStatistics_history WHERE  xnat_abstractstatistics_id=current_row.scanstatistics_xnat_abstractstatistics_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractStatistics_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(scanstatistics_abstractstatistics:XFTItem)=(' || tempText || ')';
           	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.qcAssessmentData_scan_info IS NOT NULL)) THEN
            fullText := fullText || '(qcassessmentdata_scan_info:integer)=(' || current_row.qcassessmentdata_scan_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan_meta_data(current_row.qcAssessmentData_scan_info, child_count,$3,false,false);
              fullText := fullText || '(qcassessmentdata_scan_info_qcassessmentdata_scan_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.scans_scan_xnat_qcAssessmentDat_id IS NOT NULL)) THEN
            fullText := fullText || '(scans_scan_xnat_qcassessmentdat_id:string)=(' || current_row.scans_scan_xnat_qcassessmentdat_id || ')';
        END IF;
          IF (current_row.xnat_qcassessmentdata_scan_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcassessmentdata_scan_id:integer)=(' || current_row.xnat_qcassessmentdata_scan_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_qcassessmentdata_scan_slice(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:qcAssessmentData_scan_slice)(';
      FOR current_row IN SELECT * FROM xnat_qcAssessmentData_scan_slice WHERE  xnat_qcassessmentdata_scan_slice_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.slicestatistics_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(slicestatistics_xnat_abstractstatistics_id:integer)=(' || current_row.slicestatistics_xnat_abstractstatistics_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractStatistics(current_row.slicestatistics_xnat_abstractstatistics_id, child_count,$3,false,false);
              fullText := fullText || '(slicestatistics_abstractstatistics:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.number IS NOT NULL) THEN 
              fullText := fullText || '(number:string)=(' || REPLACE(REPLACE(current_row.number,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.qcAssessmentData_scan_slice_info IS NOT NULL)) THEN
            fullText := fullText || '(qcassessmentdata_scan_slice_info:integer)=(' || current_row.qcassessmentdata_scan_slice_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan_slice_meta_data(current_row.qcAssessmentData_scan_slice_info, child_count,$3,false,false);
              fullText := fullText || '(qcassessmentdata_scan_slice_info_qcassessmentdata_scan_slice_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.sliceqc_slice_xnat_qcAssessment_xnat_qcassessmentdata_scan_id IS NOT NULL)) THEN
            fullText := fullText || '(sliceqc_slice_xnat_qcassessment_xnat_qcassessmentdata_scan_id:integer)=(' || current_row.sliceqc_slice_xnat_qcassessment_xnat_qcassessmentdata_scan_id || ')';
        END IF;
          IF (current_row.xnat_qcassessmentdata_scan_slice_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcassessmentdata_scan_slice_id:integer)=(' || current_row.xnat_qcassessmentdata_scan_slice_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_qcassessmentdata_scan_slice_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:qcAssessmentData_scan_slice_history)(';
      FOR current_row IN SELECT * FROM xnat_qcAssessmentData_scan_slice_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.slicestatistics_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(slicestatistics_xnat_abstractstatistics_id:integer)=(' || current_row.slicestatistics_xnat_abstractstatistics_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_abstractStatistics_history WHERE  xnat_abstractstatistics_id=current_row.slicestatistics_xnat_abstractstatistics_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractStatistics_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(slicestatistics_abstractstatistics:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.number IS NOT NULL) THEN 
              fullText := fullText || '(number:string)=(' || REPLACE(REPLACE(current_row.number,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.qcAssessmentData_scan_slice_info IS NOT NULL)) THEN
            fullText := fullText || '(qcassessmentdata_scan_slice_info:integer)=(' || current_row.qcassessmentdata_scan_slice_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcAssessmentData_scan_slice_meta_data(current_row.qcAssessmentData_scan_slice_info, child_count,$3,false,false);
              fullText := fullText || '(qcassessmentdata_scan_slice_info_qcassessmentdata_scan_slice_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.sliceqc_slice_xnat_qcAssessment_xnat_qcassessmentdata_scan_id IS NOT NULL)) THEN
            fullText := fullText || '(sliceqc_slice_xnat_qcassessment_xnat_qcassessmentdata_scan_id:integer)=(' || current_row.sliceqc_slice_xnat_qcassessment_xnat_qcassessmentdata_scan_id || ')';
        END IF;
          IF (current_row.xnat_qcassessmentdata_scan_slice_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcassessmentdata_scan_slice_id:integer)=(' || current_row.xnat_qcassessmentdata_scan_slice_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_qcmanualassessordata(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:qcManualAssessorData)(';
      FOR current_row IN SELECT * FROM xnat_qcManualAssessorData 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.rater IS NOT NULL) THEN 
              fullText := fullText || '(rater:string)=(' || REPLACE(REPLACE(current_row.rater,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.stereotacticmarker IS NOT NULL) THEN 
              fullText := fullText || '(stereotacticmarker:string)=(' || REPLACE(REPLACE(current_row.stereotacticmarker,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.incidentalfindings IS NOT NULL) THEN 
              fullText := fullText || '(incidentalfindings:string)=(' || REPLACE(REPLACE(current_row.incidentalfindings,'(','*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 WHERE scans_scan_xnat_qcManualAssesso_id=current_row.id ORDER BY xnat_qcscandata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData( parent_row.xnat_qcscandata_id, child_count,$3,false,false);
              fullText := fullText || '(scans_scan_qcscandata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.comments IS NOT NULL) THEN 
              fullText := fullText || '(comments:string)=(' || REPLACE(REPLACE(current_row.comments,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pass IS NOT NULL) THEN 
              fullText := fullText || '(pass:string)=(' || REPLACE(REPLACE(current_row.pass,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.payable IS NOT NULL) THEN 
              fullText := fullText || '(payable:string)=(' || REPLACE(REPLACE(current_row.payable,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rescan IS NOT NULL) THEN 
              fullText := fullText || '(rescan:string)=(' || REPLACE(REPLACE(current_row.rescan,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.resolvable IS NOT NULL) THEN 
              fullText := fullText || '(resolvable:string)=(' || REPLACE(REPLACE(current_row.resolvable,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.retrain IS NOT NULL) THEN 
              fullText := fullText || '(retrain:string)=(' || REPLACE(REPLACE(current_row.retrain,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.qcManualAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(qcmanualassessordata_info:integer)=(' || current_row.qcmanualassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcManualAssessorData_meta_data(current_row.qcManualAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(qcmanualassessordata_info_qcmanualassessordata_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.i_xnat_qcmanualassessordata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_qcmanualassessordata_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:qcManualAssessorData_history)(';
      FOR current_row IN SELECT * FROM xnat_qcManualAssessorData_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.rater IS NOT NULL) THEN 
              fullText := fullText || '(rater:string)=(' || REPLACE(REPLACE(current_row.rater,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.stereotacticmarker IS NOT NULL) THEN 
              fullText := fullText || '(stereotacticmarker:string)=(' || REPLACE(REPLACE(current_row.stereotacticmarker,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.incidentalfindings IS NOT NULL) THEN 
              fullText := fullText || '(incidentalfindings:string)=(' || REPLACE(REPLACE(current_row.incidentalfindings,'(','*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_history WHERE scans_scan_xnat_qcManualAssesso_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_qcscandata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData_history( parent_row.xnat_qcscandata_id, child_count,$3,false,false);
              fullText := fullText || '(scans_scan_qcscandata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.comments IS NOT NULL) THEN 
              fullText := fullText || '(comments:string)=(' || REPLACE(REPLACE(current_row.comments,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pass IS NOT NULL) THEN 
              fullText := fullText || '(pass:string)=(' || REPLACE(REPLACE(current_row.pass,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.payable IS NOT NULL) THEN 
              fullText := fullText || '(payable:string)=(' || REPLACE(REPLACE(current_row.payable,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.rescan IS NOT NULL) THEN 
              fullText := fullText || '(rescan:string)=(' || REPLACE(REPLACE(current_row.rescan,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.resolvable IS NOT NULL) THEN 
              fullText := fullText || '(resolvable:string)=(' || REPLACE(REPLACE(current_row.resolvable,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.retrain IS NOT NULL) THEN 
              fullText := fullText || '(retrain:string)=(' || REPLACE(REPLACE(current_row.retrain,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.qcManualAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(qcmanualassessordata_info:integer)=(' || current_row.qcmanualassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcManualAssessorData_meta_data(current_row.qcManualAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(qcmanualassessordata_info_qcmanualassessordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_qcscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_qcScanData.xnat_qcscandata_id AS xnat_qcScanData11, table1.element_name AS xdat_meta_element30, table2.insert_date AS xnat_qcScanData_meta_data37 FROM xnat_qcScanData xnat_qcScanData   LEFT JOIN xdat_meta_element table1 ON xnat_qcScanData.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_qcScanData_meta_data table2 ON xnat_qcScanData.qcScanData_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xnat_qcScanData11=$1))
      LOOP
         IF (current_row.xdat_meta_element30 IS NULL) THEN 
             fullText:= ie_xnat_qcScanData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element30='xnat:mrQcScanData') THEN
                fullText:= i_xnat_mrQcScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:petQcScanData') THEN
                fullText:= i_xnat_petQcScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:otherQcScanData') THEN
                fullText:= i_xnat_otherQcScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_qcScanData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_qcscandata_field(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:qcScanData_field)(';
      FOR current_row IN SELECT * FROM xnat_qcScanData_field WHERE  xnat_qcscandata_field_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.field IS NOT NULL) THEN 
              fullText := fullText || '(field:string)=(' || REPLACE(REPLACE(current_row.field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.qcScanData_field_info IS NOT NULL)) THEN
            fullText := fullText || '(qcscandata_field_info:integer)=(' || current_row.qcscandata_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData_field_meta_data(current_row.qcScanData_field_info, child_count,$3,false,false);
              fullText := fullText || '(qcscandata_field_info_qcscandata_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_qcScanData_xnat_qcscandata_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_qcscandata_xnat_qcscandata_id:integer)=(' || current_row.fields_field_xnat_qcscandata_xnat_qcscandata_id || ')';
        END IF;
          IF (current_row.xnat_qcscandata_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcscandata_field_id:integer)=(' || current_row.xnat_qcscandata_field_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_qcscandata_field_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:qcScanData_field_history)(';
      FOR current_row IN SELECT * FROM xnat_qcScanData_field_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.field IS NOT NULL) THEN 
              fullText := fullText || '(field:string)=(' || REPLACE(REPLACE(current_row.field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.qcScanData_field_info IS NOT NULL)) THEN
            fullText := fullText || '(qcscandata_field_info:integer)=(' || current_row.qcscandata_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_qcScanData_field_meta_data(current_row.qcScanData_field_info, child_count,$3,false,false);
              fullText := fullText || '(qcscandata_field_info_qcscandata_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_qcScanData_xnat_qcscandata_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_qcscandata_xnat_qcscandata_id:integer)=(' || current_row.fields_field_xnat_qcscandata_xnat_qcscandata_id || ')';
        END IF;
          IF (current_row.xnat_qcscandata_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_qcscandata_field_id:integer)=(' || current_row.xnat_qcscandata_field_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_qcscandata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_qcScanData_history.history_id AS xnat_qcScanData_history13, table1.element_name AS xdat_meta_element19, xnat_qcScanData_history.xft_version AS xnat_qcScanData_history_xft_version, xnat_qcScanData_history.xnat_qcscandata_id AS xnat_qcScanData_history11 FROM xnat_qcScanData_history xnat_qcScanData_history   LEFT JOIN xdat_meta_element table1 ON xnat_qcScanData_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_qcScanData_history13=$1))
      LOOP
         IF (current_row.xdat_meta_element19 IS NULL) THEN 
             fullText:= ie_xnat_qcScanData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element19='xnat:mrQcScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_mrQcScanData_history WHERE xnat_qcscandata_id=current_row.xnat_qcScanData_history11 AND xft_version=current_row.xnat_qcScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_mrQcScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element19='xnat:petQcScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_petQcScanData_history WHERE xnat_qcscandata_id=current_row.xnat_qcScanData_history11 AND xft_version=current_row.xnat_qcScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_petQcScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element19='xnat:otherQcScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_otherQcScanData_history WHERE xnat_qcscandata_id=current_row.xnat_qcScanData_history11 AND xft_version=current_row.xnat_qcScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_otherQcScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_qcScanData_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_reconstructedimagedata(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:reconstructedImageData)(';
      FOR current_row IN SELECT * FROM xnat_reconstructedImageData WHERE  xnat_reconstructedimagedata_id=$1
      LOOP
           row_ct := row_ct+1;
          
          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($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_reconstructedImageData_scanID WHERE inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id ORDER BY xnat_reconstructedimagedata_scanid_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData_scanID( parent_row.xnat_reconstructedimagedata_scanid_id, child_count,$3,false,false);
              fullText := fullText || '(inscans_scanid_reconstructedimagedata_scanid' || 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 recon_in_resource WHERE  xnat_reconstructedImageData_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_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 recon_out_resource WHERE  xnat_reconstructedImageData_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_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.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($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField WHERE parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_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($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_computationData WHERE computations_datum_xnat_reconst_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id ORDER BY xnat_computationdata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_computationData( parent_row.xnat_computationdata_id, child_count,$3,false,false);
              fullText := fullText || '(computations_datum_computationdata' || 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.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.basescantype IS NOT NULL) THEN 
              fullText := fullText || '(basescantype:string)=(' || REPLACE(REPLACE(current_row.basescantype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.reconstructedImageData_info IS NOT NULL)) THEN
            fullText := fullText || '(reconstructedimagedata_info:integer)=(' || current_row.reconstructedimagedata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData_meta_data(current_row.reconstructedImageData_info, child_count,$3,false,false);
              fullText := fullText || '(reconstructedimagedata_info_reconstructedimagedata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_reconstructedimagedata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_reconstructedimagedata_id:integer)=(' || current_row.xnat_reconstructedimagedata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_reconstructedimagedata_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:reconstructedImageData_history)(';
      FOR current_row IN SELECT * FROM xnat_reconstructedImageData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          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($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_reconstructedImageData_scanID_history WHERE inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id AND xft_version=current_row.xft_version ORDER BY xnat_reconstructedimagedata_scanid_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData_scanID_history( parent_row.xnat_reconstructedimagedata_scanid_id, child_count,$3,false,false);
              fullText := fullText || '(inscans_scanid_reconstructedimagedata_scanid' || 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 recon_in_resource_history WHERE  xnat_reconstructedImageData_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_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 recon_out_resource_history WHERE  xnat_reconstructedImageData_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_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.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($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_recons_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_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($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_computationData_history WHERE computations_datum_xnat_reconst_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id AND xft_version=current_row.xft_version ORDER BY xnat_computationdata_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_computationData_history( parent_row.xnat_computationdata_id, child_count,$3,false,false);
              fullText := fullText || '(computations_datum_computationdata' || 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.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.basescantype IS NOT NULL) THEN 
              fullText := fullText || '(basescantype:string)=(' || REPLACE(REPLACE(current_row.basescantype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.reconstructedImageData_info IS NOT NULL)) THEN
            fullText := fullText || '(reconstructedimagedata_info:integer)=(' || current_row.reconstructedimagedata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData_meta_data(current_row.reconstructedImageData_info, child_count,$3,false,false);
              fullText := fullText || '(reconstructedimagedata_info_reconstructedimagedata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_reconstructedimagedata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_reconstructedimagedata_id:integer)=(' || current_row.xnat_reconstructedimagedata_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_reconstructedimagedata_scanid(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:reconstructedImageData_scanID)(';
      FOR current_row IN SELECT * FROM xnat_reconstructedImageData_scanID WHERE  xnat_reconstructedimagedata_scanid_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.scanid IS NOT NULL) THEN 
              fullText := fullText || '(scanid:string)=(' || REPLACE(REPLACE(current_row.scanid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.reconstructedImageData_scanID_info IS NOT NULL)) THEN
            fullText := fullText || '(reconstructedimagedata_scanid_info:integer)=(' || current_row.reconstructedimagedata_scanid_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData_scanID_meta_data(current_row.reconstructedImageData_scanID_info, child_count,$3,false,false);
              fullText := fullText || '(reconstructedimagedata_scanid_info_reconstructedimagedata_scanid_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
            fullText := fullText || '(inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id:integer)=(' || current_row.inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id || ')';
        END IF;
          IF (current_row.xnat_reconstructedimagedata_scanid_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_reconstructedimagedata_scanid_id:integer)=(' || current_row.xnat_reconstructedimagedata_scanid_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_reconstructedimagedata_scanid_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:reconstructedImageData_scanID_history)(';
      FOR current_row IN SELECT * FROM xnat_reconstructedImageData_scanID_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.scanid IS NOT NULL) THEN 
              fullText := fullText || '(scanid:string)=(' || REPLACE(REPLACE(current_row.scanid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.reconstructedImageData_scanID_info IS NOT NULL)) THEN
            fullText := fullText || '(reconstructedimagedata_scanid_info:integer)=(' || current_row.reconstructedimagedata_scanid_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_reconstructedImageData_scanID_meta_data(current_row.reconstructedImageData_scanID_info, child_count,$3,false,false);
              fullText := fullText || '(reconstructedimagedata_scanid_info_reconstructedimagedata_scanid_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
            fullText := fullText || '(inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id:integer)=(' || current_row.inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id || ')';
        END IF;
          IF (current_row.xnat_reconstructedimagedata_scanid_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_reconstructedimagedata_scanid_id:integer)=(' || current_row.xnat_reconstructedimagedata_scanid_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_regionresource(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:regionResource)(';
      FOR current_row IN SELECT * FROM xnat_regionResource WHERE  xnat_regionresource_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.file_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(file_xnat_abstractresource_id:integer)=(' || current_row.file_xnat_abstractresource_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource(current_row.file_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(file_abstractresource:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.baseimage_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(baseimage_xnat_abstractresource_id:integer)=(' || current_row.baseimage_xnat_abstractresource_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource(current_row.baseimage_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(baseimage_abstractresource:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.creator_firstname IS NOT NULL) THEN 
              fullText := fullText || '(creator_firstname:string)=(' || REPLACE(REPLACE(current_row.creator_firstname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.creator_lastname IS NOT NULL) THEN 
              fullText := fullText || '(creator_lastname:string)=(' || REPLACE(REPLACE(current_row.creator_lastname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_regionResource_label WHERE subregionlabels_label_xnat_regi_xnat_regionresource_id=current_row.xnat_regionresource_id ORDER BY xnat_regionresource_label_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource_label( parent_row.xnat_regionresource_label_id, child_count,$3,false,false);
              fullText := fullText || '(subregionlabels_label_regionresource_label' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        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.hemisphere IS NOT NULL) THEN 
              fullText := fullText || '(hemisphere:string)=(' || REPLACE(REPLACE(current_row.hemisphere,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.session_id IS NOT NULL) THEN 
              fullText := fullText || '(session_id:string)=(' || REPLACE(REPLACE(current_row.session_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.regionResource_info IS NOT NULL)) THEN
            fullText := fullText || '(regionresource_info:integer)=(' || current_row.regionresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource_meta_data(current_row.regionResource_info, child_count,$3,false,false);
              fullText := fullText || '(regionresource_info_regionresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_regionresource_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_regionresource_id:integer)=(' || current_row.xnat_regionresource_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_regionresource_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:regionResource_history)(';
      FOR current_row IN SELECT * FROM xnat_regionResource_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.file_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(file_xnat_abstractresource_id:integer)=(' || current_row.file_xnat_abstractresource_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_abstractResource_history WHERE  xnat_abstractresource_id=current_row.file_xnat_abstractresource_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(file_abstractresource:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF ((current_row.baseimage_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(baseimage_xnat_abstractresource_id:integer)=(' || current_row.baseimage_xnat_abstractresource_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_abstractResource_history WHERE  xnat_abstractresource_id=current_row.baseimage_xnat_abstractresource_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(baseimage_abstractresource:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.creator_firstname IS NOT NULL) THEN 
              fullText := fullText || '(creator_firstname:string)=(' || REPLACE(REPLACE(current_row.creator_firstname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.creator_lastname IS NOT NULL) THEN 
              fullText := fullText || '(creator_lastname:string)=(' || REPLACE(REPLACE(current_row.creator_lastname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_regionResource_label_history WHERE subregionlabels_label_xnat_regi_xnat_regionresource_id=current_row.xnat_regionresource_id AND xft_version=current_row.xft_version ORDER BY xnat_regionresource_label_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource_label_history( parent_row.xnat_regionresource_label_id, child_count,$3,false,false);
              fullText := fullText || '(subregionlabels_label_regionresource_label' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        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.hemisphere IS NOT NULL) THEN 
              fullText := fullText || '(hemisphere:string)=(' || REPLACE(REPLACE(current_row.hemisphere,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.session_id IS NOT NULL) THEN 
              fullText := fullText || '(session_id:string)=(' || REPLACE(REPLACE(current_row.session_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.regionResource_info IS NOT NULL)) THEN
            fullText := fullText || '(regionresource_info:integer)=(' || current_row.regionresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource_meta_data(current_row.regionResource_info, child_count,$3,false,false);
              fullText := fullText || '(regionresource_info_regionresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_regionresource_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_regionresource_id:integer)=(' || current_row.xnat_regionresource_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_regionresource_label(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:regionResource_label)(';
      FOR current_row IN SELECT * FROM xnat_regionResource_label WHERE  xnat_regionresource_label_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:integer)=(' || current_row.id || ')';
          END IF;
          IF (current_row.hemisphere IS NOT NULL) THEN 
              fullText := fullText || '(hemisphere:string)=(' || REPLACE(REPLACE(current_row.hemisphere,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.regionResource_label_info IS NOT NULL)) THEN
            fullText := fullText || '(regionresource_label_info:integer)=(' || current_row.regionresource_label_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource_label_meta_data(current_row.regionResource_label_info, child_count,$3,false,false);
              fullText := fullText || '(regionresource_label_info_regionresource_label_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.subregionlabels_label_xnat_regi_xnat_regionresource_id IS NOT NULL)) THEN
            fullText := fullText || '(subregionlabels_label_xnat_regi_xnat_regionresource_id:integer)=(' || current_row.subregionlabels_label_xnat_regi_xnat_regionresource_id || ')';
        END IF;
          IF (current_row.xnat_regionresource_label_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_regionresource_label_id:integer)=(' || current_row.xnat_regionresource_label_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_regionresource_label_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:regionResource_label_history)(';
      FOR current_row IN SELECT * FROM xnat_regionResource_label_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:integer)=(' || current_row.id || ')';
          END IF;
          IF (current_row.hemisphere IS NOT NULL) THEN 
              fullText := fullText || '(hemisphere:string)=(' || REPLACE(REPLACE(current_row.hemisphere,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.regionResource_label_info IS NOT NULL)) THEN
            fullText := fullText || '(regionresource_label_info:integer)=(' || current_row.regionresource_label_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_regionResource_label_meta_data(current_row.regionResource_label_info, child_count,$3,false,false);
              fullText := fullText || '(regionresource_label_info_regionresource_label_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.subregionlabels_label_xnat_regi_xnat_regionresource_id IS NOT NULL)) THEN
            fullText := fullText || '(subregionlabels_label_xnat_regi_xnat_regionresource_id:integer)=(' || current_row.subregionlabels_label_xnat_regi_xnat_regionresource_id || ')';
        END IF;
          IF (current_row.xnat_regionresource_label_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_regionresource_label_id:integer)=(' || current_row.xnat_regionresource_label_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

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


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

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

CREATE FUNCTION public.i_xnat_resource(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT table0.xnat_abstractresource_id AS xnat_resource0, table2.element_name AS xdat_meta_element33, table4.insert_date AS xnat_resource_meta_data109 FROM xnat_resource xnat_resource   LEFT JOIN xnat_abstractResource table0 ON xnat_resource.xnat_abstractresource_id=table0.xnat_abstractresource_id   LEFT JOIN xdat_meta_element table2 ON table0.extension=table2.xdat_meta_element_id   LEFT JOIN xnat_resource_meta_data table4 ON xnat_resource.resource_info=table4.meta_data_id) SEARCH  WHERE 
 ( (xnat_resource0=$1))
      LOOP
         IF (current_row.xdat_meta_element33 IS NULL) THEN 
             fullText:= ie_xnat_resource( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element33='xnat:imageResource') THEN
                fullText:= i_xnat_imageResource( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element33='xnat:resourceCatalog') THEN
                fullText:= i_xnat_resourceCatalog( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_resource( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_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;
      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
           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
           	   tempText := i_xnat_abstractResource_history(ext_row.history_id, child_count,$3,false,false);
 RETURN tempText;
           	END LOOP;
           END;
        END IF;
      END LOOP;
      fullText:= ie_xnat_resource_history( $1, $2,$3,$4,$5);
	
	RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_resourcecatalog(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:resourceCatalog)(';
      FOR current_row IN SELECT * FROM xnat_resourceCatalog 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_resource(current_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(resource_resource:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.resourceCatalog_info IS NOT NULL)) THEN
            fullText := fullText || '(resourcecatalog_info:integer)=(' || current_row.resourcecatalog_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_resourceCatalog_meta_data(current_row.resourceCatalog_info, child_count,$3,false,false);
              fullText := fullText || '(resourcecatalog_info_resourcecatalog_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_resource( $1, child_count,$3,$4,false);
              fullText := fullText || '(resource_resource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_resourcecatalog_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:resourceCatalog_history)(';
      FOR current_row IN SELECT * FROM xnat_resourceCatalog_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_resource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_resource_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(resource_resource:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.resourceCatalog_info IS NOT NULL)) THEN
            fullText := fullText || '(resourcecatalog_info:integer)=(' || current_row.resourcecatalog_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_resourceCatalog_meta_data(current_row.resourceCatalog_info, child_count,$3,false,false);
              fullText := fullText || '(resourcecatalog_info_resourcecatalog_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_resource_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(resource_resource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_resourceseries(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT table0.xnat_abstractresource_id AS xnat_resourceSeries0, table2.element_name AS xdat_meta_element35, table4.insert_date AS xnat_resourceSeries_meta_data54 FROM xnat_resourceSeries xnat_resourceSeries   LEFT JOIN xnat_abstractResource table0 ON xnat_resourceSeries.xnat_abstractresource_id=table0.xnat_abstractresource_id   LEFT JOIN xdat_meta_element table2 ON table0.extension=table2.xdat_meta_element_id   LEFT JOIN xnat_resourceSeries_meta_data table4 ON xnat_resourceSeries.resourceSeries_info=table4.meta_data_id) SEARCH  WHERE 
 ( (xnat_resourceSeries0=$1))
      LOOP
         IF (current_row.xdat_meta_element35 IS NULL) THEN 
             fullText:= ie_xnat_resourceSeries( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element35='xnat:imageResourceSeries') THEN
                fullText:= i_xnat_imageResourceSeries( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_resourceSeries( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_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;
      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
           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
           	   tempText := i_xnat_abstractResource_history(ext_row.history_id, child_count,$3,false,false);
 RETURN tempText;
           	END LOOP;
           END;
        END IF;
      END LOOP;
      fullText:= ie_xnat_resourceSeries_history( $1, $2,$3,$4,$5);
	
	RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_rfscandata(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:rfScanData)(';
      FOR current_row IN SELECT * FROM xnat_rfScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.rfScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(rfscandata_info:integer)=(' || current_row.rfscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rfScanData_meta_data(current_row.rfScanData_info, child_count,$3,false,false);
              fullText := fullText || '(rfscandata_info_rfscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_rfscandata_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:rfScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_rfScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.rfScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(rfscandata_info:integer)=(' || current_row.rfscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rfScanData_meta_data(current_row.rfScanData_info, child_count,$3,false,false);
              fullText := fullText || '(rfscandata_info_rfscandata_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_imageScanData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_rfsessiondata(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:rfSessionData)(';
      FOR current_row IN SELECT * FROM xnat_rfSessionData 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_imageSessionData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.rfSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(rfsessiondata_info:integer)=(' || current_row.rfsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rfSessionData_meta_data(current_row.rfSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(rfsessiondata_info_rfsessiondata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageSessionData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_rfsessiondata_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:rfSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_rfSessionData_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_imageSessionData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageSessionData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.rfSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(rfsessiondata_info:integer)=(' || current_row.rfsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rfSessionData_meta_data(current_row.rfSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(rfsessiondata_info_rfsessiondata_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_imageSessionData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_rtimagescandata(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:rtImageScanData)(';
      FOR current_row IN SELECT * FROM xnat_rtImageScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.rtImageScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(rtimagescandata_info:integer)=(' || current_row.rtimagescandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rtImageScanData_meta_data(current_row.rtImageScanData_info, child_count,$3,false,false);
              fullText := fullText || '(rtimagescandata_info_rtimagescandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_rtimagescandata_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:rtImageScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_rtImageScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.rtImageScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(rtimagescandata_info:integer)=(' || current_row.rtimagescandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rtImageScanData_meta_data(current_row.rtImageScanData_info, child_count,$3,false,false);
              fullText := fullText || '(rtimagescandata_info_rtimagescandata_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_imageScanData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_rtsessiondata(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:rtSessionData)(';
      FOR current_row IN SELECT * FROM xnat_rtSessionData 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_imageSessionData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.rtSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(rtsessiondata_info:integer)=(' || current_row.rtsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rtSessionData_meta_data(current_row.rtSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(rtsessiondata_info_rtsessiondata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageSessionData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_rtsessiondata_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:rtSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_rtSessionData_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_imageSessionData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageSessionData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.rtSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(rtsessiondata_info:integer)=(' || current_row.rtsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_rtSessionData_meta_data(current_row.rtSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(rtsessiondata_info_rtsessiondata_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_imageSessionData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_scscandata(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:scScanData)(';
      FOR current_row IN SELECT * FROM xnat_scScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.scScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(scscandata_info:integer)=(' || current_row.scscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_scScanData_meta_data(current_row.scScanData_info, child_count,$3,false,false);
              fullText := fullText || '(scscandata_info_scscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_scscandata_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:scScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_scScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.scScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(scscandata_info:integer)=(' || current_row.scscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_scScanData_meta_data(current_row.scScanData_info, child_count,$3,false,false);
              fullText := fullText || '(scscandata_info_scscandata_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_imageScanData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_segscandata(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:segScanData)(';
      FOR current_row IN SELECT * FROM xnat_segScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.segScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(segscandata_info:integer)=(' || current_row.segscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_segScanData_meta_data(current_row.segScanData_info, child_count,$3,false,false);
              fullText := fullText || '(segscandata_info_segscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_segscandata_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:segScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_segScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.segScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(segscandata_info:integer)=(' || current_row.segscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_segScanData_meta_data(current_row.segScanData_info, child_count,$3,false,false);
              fullText := fullText || '(segscandata_info_segscandata_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_imageScanData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_smscandata(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:smScanData)(';
      FOR current_row IN SELECT * FROM xnat_smScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.smScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(smscandata_info:integer)=(' || current_row.smscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_smScanData_meta_data(current_row.smScanData_info, child_count,$3,false,false);
              fullText := fullText || '(smscandata_info_smscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_smscandata_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:smScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_smScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.smScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(smscandata_info:integer)=(' || current_row.smscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_smScanData_meta_data(current_row.smScanData_info, child_count,$3,false,false);
              fullText := fullText || '(smscandata_info_smscandata_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_imageScanData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_smsessiondata(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:smSessionData)(';
      FOR current_row IN SELECT * FROM xnat_smSessionData 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_imageSessionData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.smSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(smsessiondata_info:integer)=(' || current_row.smsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_smSessionData_meta_data(current_row.smSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(smsessiondata_info_smsessiondata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageSessionData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_smsessiondata_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:smSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_smSessionData_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_imageSessionData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageSessionData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.smSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(smsessiondata_info:integer)=(' || current_row.smsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_smSessionData_meta_data(current_row.smSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(smsessiondata_info_smsessiondata_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_imageSessionData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_srscandata(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:srScanData)(';
      FOR current_row IN SELECT * FROM xnat_srScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.srScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(srscandata_info:integer)=(' || current_row.srscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_srScanData_meta_data(current_row.srScanData_info, child_count,$3,false,false);
              fullText := fullText || '(srscandata_info_srscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_srscandata_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:srScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_srScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.srScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(srscandata_info:integer)=(' || current_row.srscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_srScanData_meta_data(current_row.srScanData_info, child_count,$3,false,false);
              fullText := fullText || '(srscandata_info_srscandata_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_imageScanData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_srsessiondata(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:srSessionData)(';
      FOR current_row IN SELECT * FROM xnat_srSessionData 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_imageSessionData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.srSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(srsessiondata_info:integer)=(' || current_row.srsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_srSessionData_meta_data(current_row.srSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(srsessiondata_info_srsessiondata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageSessionData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_srsessiondata_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:srSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_srSessionData_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_imageSessionData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageSessionData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.srSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(srsessiondata_info:integer)=(' || current_row.srsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_srSessionData_meta_data(current_row.srSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(srsessiondata_info_srsessiondata_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_imageSessionData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imagesessiondata_imagesessiondata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_statisticsdata(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:statisticsData)(';
      FOR current_row IN SELECT * FROM xnat_statisticsData WHERE  xnat_abstractstatistics_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractstatistics_id:integer)=(' || current_row.xnat_abstractstatistics_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractStatistics(current_row.xnat_abstractstatistics_id, child_count,$3,false,false);
              fullText := fullText || '(abstractstatistics_abstractstatistics:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.mean IS NOT NULL) THEN 
              fullText := fullText || '(mean:float)=(' || current_row.mean || ')';
          END IF;
          IF (current_row.snr IS NOT NULL) THEN 
              fullText := fullText || '(snr:float)=(' || current_row.snr || ')';
          END IF;
          IF (current_row.min IS NOT NULL) THEN 
              fullText := fullText || '(min:float)=(' || current_row.min || ')';
          END IF;
          IF (current_row.max IS NOT NULL) THEN 
              fullText := fullText || '(max:float)=(' || current_row.max || ')';
          END IF;
          IF (current_row.stddev IS NOT NULL) THEN 
              fullText := fullText || '(stddev:float)=(' || current_row.stddev || ')';
          END IF;
          IF (current_row.no_of_voxels IS NOT NULL) THEN 
              fullText := fullText || '(no_of_voxels:integer)=(' || current_row.no_of_voxels || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_statisticsData_additionalStatistics WHERE xnat_statisticsData_xnat_abstractstatistics_id=current_row.xnat_abstractstatistics_id ORDER BY xnat_statisticsdata_additionalstatistics_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_additionalStatistics( parent_row.xnat_statisticsdata_additionalstatistics_id, child_count,$3,false,false);
              fullText := fullText || '(additionalstatistics_statisticsdata_additionalstatistics' || 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_statisticsData_addField WHERE xnat_statisticsData_xnat_abstractstatistics_id=current_row.xnat_abstractstatistics_id ORDER BY xnat_statisticsdata_addfield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_addField( parent_row.xnat_statisticsdata_addfield_id, child_count,$3,false,false);
              fullText := fullText || '(addfield_statisticsdata_addfield' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.statisticsData_info IS NOT NULL)) THEN
            fullText := fullText || '(statisticsdata_info:integer)=(' || current_row.statisticsdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_meta_data(current_row.statisticsData_info, child_count,$3,false,false);
              fullText := fullText || '(statisticsdata_info_statisticsdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractStatistics( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractstatistics_abstractstatistics:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_statisticsdata_addfield(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:statisticsData_addField)(';
      FOR current_row IN SELECT * FROM xnat_statisticsData_addField WHERE  xnat_statisticsdata_addfield_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.addfield IS NOT NULL) THEN 
              fullText := fullText || '(addfield:string)=(' || REPLACE(REPLACE(current_row.addfield,'(','*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.statisticsData_addField_info IS NOT NULL)) THEN
            fullText := fullText || '(statisticsdata_addfield_info:integer)=(' || current_row.statisticsdata_addfield_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_addField_meta_data(current_row.statisticsData_addField_info, child_count,$3,false,false);
              fullText := fullText || '(statisticsdata_addfield_info_statisticsdata_addfield_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_statisticsData_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_statisticsdata_xnat_abstractstatistics_id:integer)=(' || current_row.xnat_statisticsdata_xnat_abstractstatistics_id || ')';
        END IF;
          IF (current_row.xnat_statisticsdata_addfield_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_statisticsdata_addfield_id:integer)=(' || current_row.xnat_statisticsdata_addfield_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_statisticsdata_addfield_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:statisticsData_addField_history)(';
      FOR current_row IN SELECT * FROM xnat_statisticsData_addField_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.addfield IS NOT NULL) THEN 
              fullText := fullText || '(addfield:string)=(' || REPLACE(REPLACE(current_row.addfield,'(','*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.statisticsData_addField_info IS NOT NULL)) THEN
            fullText := fullText || '(statisticsdata_addfield_info:integer)=(' || current_row.statisticsdata_addfield_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_addField_meta_data(current_row.statisticsData_addField_info, child_count,$3,false,false);
              fullText := fullText || '(statisticsdata_addfield_info_statisticsdata_addfield_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_statisticsData_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_statisticsdata_xnat_abstractstatistics_id:integer)=(' || current_row.xnat_statisticsdata_xnat_abstractstatistics_id || ')';
        END IF;
          IF (current_row.xnat_statisticsdata_addfield_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_statisticsdata_addfield_id:integer)=(' || current_row.xnat_statisticsdata_addfield_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_statisticsdata_additionalstatistics(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:statisticsData_additionalStatistics)(';
      FOR current_row IN SELECT * FROM xnat_statisticsData_additionalStatistics WHERE  xnat_statisticsdata_additionalstatistics_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.additionalstatistics IS NOT NULL) THEN 
              fullText := fullText || '(additionalstatistics:float)=(' || current_row.additionalstatistics || ')';
          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.statisticsData_additionalStatistics_info IS NOT NULL)) THEN
            fullText := fullText || '(statisticsdata_additionalstatistics_info:integer)=(' || current_row.statisticsdata_additionalstatistics_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_additionalStatistics_meta_data(current_row.statisticsData_additionalStatistics_info, child_count,$3,false,false);
              fullText := fullText || '(statisticsdata_additionalstatistics_info_statisticsdata_additionalstatistics_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_statisticsData_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_statisticsdata_xnat_abstractstatistics_id:integer)=(' || current_row.xnat_statisticsdata_xnat_abstractstatistics_id || ')';
        END IF;
          IF (current_row.xnat_statisticsdata_additionalstatistics_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_statisticsdata_additionalstatistics_id:integer)=(' || current_row.xnat_statisticsdata_additionalstatistics_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_statisticsdata_additionalstatistics_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:statisticsData_additionalStatistics_history)(';
      FOR current_row IN SELECT * FROM xnat_statisticsData_additionalStatistics_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.additionalstatistics IS NOT NULL) THEN 
              fullText := fullText || '(additionalstatistics:float)=(' || current_row.additionalstatistics || ')';
          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.statisticsData_additionalStatistics_info IS NOT NULL)) THEN
            fullText := fullText || '(statisticsdata_additionalstatistics_info:integer)=(' || current_row.statisticsdata_additionalstatistics_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_additionalStatistics_meta_data(current_row.statisticsData_additionalStatistics_info, child_count,$3,false,false);
              fullText := fullText || '(statisticsdata_additionalstatistics_info_statisticsdata_additionalstatistics_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.xnat_statisticsData_xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_statisticsdata_xnat_abstractstatistics_id:integer)=(' || current_row.xnat_statisticsdata_xnat_abstractstatistics_id || ')';
        END IF;
          IF (current_row.xnat_statisticsdata_additionalstatistics_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_statisticsdata_additionalstatistics_id:integer)=(' || current_row.xnat_statisticsdata_additionalstatistics_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_statisticsdata_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:statisticsData_history)(';
      FOR current_row IN SELECT * FROM xnat_statisticsData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractstatistics_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractstatistics_id:integer)=(' || current_row.xnat_abstractstatistics_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_abstractStatistics_history WHERE xnat_abstractstatistics_id=current_row.xnat_abstractstatistics_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_abstractStatistics_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(abstractstatistics_abstractstatistics:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.mean IS NOT NULL) THEN 
              fullText := fullText || '(mean:float)=(' || current_row.mean || ')';
          END IF;
          IF (current_row.snr IS NOT NULL) THEN 
              fullText := fullText || '(snr:float)=(' || current_row.snr || ')';
          END IF;
          IF (current_row.min IS NOT NULL) THEN 
              fullText := fullText || '(min:float)=(' || current_row.min || ')';
          END IF;
          IF (current_row.max IS NOT NULL) THEN 
              fullText := fullText || '(max:float)=(' || current_row.max || ')';
          END IF;
          IF (current_row.stddev IS NOT NULL) THEN 
              fullText := fullText || '(stddev:float)=(' || current_row.stddev || ')';
          END IF;
          IF (current_row.no_of_voxels IS NOT NULL) THEN 
              fullText := fullText || '(no_of_voxels:integer)=(' || current_row.no_of_voxels || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_statisticsData_additionalStatistics_history WHERE xnat_statisticsData_xnat_abstractstatistics_id=current_row.xnat_abstractstatistics_id AND xft_version=current_row.xft_version ORDER BY xnat_statisticsdata_additionalstatistics_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_additionalStatistics_history( parent_row.xnat_statisticsdata_additionalstatistics_id, child_count,$3,false,false);
              fullText := fullText || '(additionalstatistics_statisticsdata_additionalstatistics' || 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_statisticsData_addField_history WHERE xnat_statisticsData_xnat_abstractstatistics_id=current_row.xnat_abstractstatistics_id AND xft_version=current_row.xft_version ORDER BY xnat_statisticsdata_addfield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_addField_history( parent_row.xnat_statisticsdata_addfield_id, child_count,$3,false,false);
              fullText := fullText || '(addfield_statisticsdata_addfield' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.statisticsData_info IS NOT NULL)) THEN
            fullText := fullText || '(statisticsdata_info:integer)=(' || current_row.statisticsdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_statisticsData_meta_data(current_row.statisticsData_info, child_count,$3,false,false);
              fullText := fullText || '(statisticsdata_info_statisticsdata_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_abstractStatistics_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractstatistics_abstractstatistics:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_studyprotocol(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:studyProtocol)(';
      FOR current_row IN SELECT * FROM xnat_studyProtocol WHERE  xnat_abstractprotocol_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractprotocol_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractprotocol_id:integer)=(' || current_row.xnat_abstractprotocol_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractProtocol(current_row.xnat_abstractprotocol_id, child_count,$3,false,false);
              fullText := fullText || '(abstractprotocol_abstractprotocol:XFTItem)=(' || tempText || ')';
        END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_studyProtocol_condition WHERE acqconditions_condition_xnat_st_xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id ORDER BY xnat_studyprotocol_condition_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_studyProtocol_condition( parent_row.xnat_studyprotocol_condition_id, child_count,$3,false,false);
              fullText := fullText || '(acqconditions_condition_studyprotocol_condition' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_studyProtocol_group WHERE subjectgroups_group_xnat_studyP_xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id ORDER BY xnat_studyprotocol_group_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_studyProtocol_group( parent_row.xnat_studyprotocol_group_id, child_count,$3,false,false);
              fullText := fullText || '(subjectgroups_group_studyprotocol_group' || 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_studyProtocol_variable WHERE subjectvariables_variable_xnat__xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id ORDER BY xnat_studyprotocol_variable_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_studyProtocol_variable( parent_row.xnat_studyprotocol_variable_id, child_count,$3,false,false);
              fullText := fullText || '(subjectvariables_variable_studyprotocol_variable' || 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_studyProtocol_session WHERE imagesessiontypes_session_xnat__xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id ORDER BY xnat_studyprotocol_session_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_studyProtocol_session( parent_row.xnat_studyprotocol_session_id, child_count,$3,false,false);
              fullText := fullText || '(imagesessiontypes_session_studyprotocol_session' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.studyProtocol_info IS NOT NULL)) THEN
            fullText := fullText || '(studyprotocol_info:integer)=(' || current_row.studyprotocol_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_studyProtocol_meta_data(current_row.studyProtocol_info, child_count,$3,false,false);
              fullText := fullText || '(studyprotocol_info_studyprotocol_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractProtocol( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractprotocol_abstractprotocol:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

--
