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

CREATE FUNCTION public.i_xnat_dxscandata(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:dxScanData)(';
      FOR current_row IN SELECT * FROM xnat_dxScanData 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.dxScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(dxscandata_info:integer)=(' || current_row.dxscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dxScanData_meta_data(current_row.dxScanData_info, child_count,$3,false,false);
              fullText := fullText || '(dxscandata_info_dxscandata_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_dxscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dxscandata_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:dxScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_dxScanData_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.dxScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(dxscandata_info:integer)=(' || current_row.dxscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dxScanData_meta_data(current_row.dxScanData_info, child_count,$3,false,false);
              fullText := fullText || '(dxscandata_info_dxscandata_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_dxscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dxscandata_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:dxScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_dxScanData_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_dxscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dxsessiondata(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:dxSessionData)(';
      FOR current_row IN SELECT * FROM xnat_dxSessionData 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.dxSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(dxsessiondata_info:integer)=(' || current_row.dxsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dxSessionData_meta_data(current_row.dxSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(dxsessiondata_info_dxsessiondata_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_dxsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dxsessiondata_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:dxSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_dxSessionData_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.dxSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(dxsessiondata_info:integer)=(' || current_row.dxsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dxSessionData_meta_data(current_row.dxSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(dxsessiondata_info_dxsessiondata_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_dxsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dxsessiondata_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:dxSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_dxSessionData_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_dxsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ecgscandata(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:ecgScanData)(';
      FOR current_row IN SELECT * FROM xnat_ecgScanData 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.ecgScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(ecgscandata_info:integer)=(' || current_row.ecgscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ecgScanData_meta_data(current_row.ecgScanData_info, child_count,$3,false,false);
              fullText := fullText || '(ecgscandata_info_ecgscandata_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_ecgscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ecgscandata_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:ecgScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_ecgScanData_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.ecgScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(ecgscandata_info:integer)=(' || current_row.ecgscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ecgScanData_meta_data(current_row.ecgScanData_info, child_count,$3,false,false);
              fullText := fullText || '(ecgscandata_info_ecgscandata_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_ecgscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ecgscandata_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:ecgScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_ecgScanData_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_ecgscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ecgsessiondata(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:ecgSessionData)(';
      FOR current_row IN SELECT * FROM xnat_ecgSessionData 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.ecgSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(ecgsessiondata_info:integer)=(' || current_row.ecgsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ecgSessionData_meta_data(current_row.ecgSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(ecgsessiondata_info_ecgsessiondata_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_ecgsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ecgsessiondata_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:ecgSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_ecgSessionData_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.ecgSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(ecgsessiondata_info:integer)=(' || current_row.ecgsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ecgSessionData_meta_data(current_row.ecgSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(ecgsessiondata_info_ecgsessiondata_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_ecgsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ecgsessiondata_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:ecgSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_ecgSessionData_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_ecgsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegscandata(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:eegScanData)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData 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.parameters_numberofdatarecords IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numberofdatarecords:integer)=(' || current_row.parameters_numberofdatarecords || ')';
          END IF;
          IF (current_row.parameters_datarecord_units IS NOT NULL) THEN 
              fullText := fullText || '(parameters_datarecord_units:string)=(' || REPLACE(REPLACE(current_row.parameters_datarecord_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_datarecord_duration IS NOT NULL) THEN 
              fullText := fullText || '(parameters_datarecord_duration:float)=(' || current_row.parameters_datarecord_duration || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_eegScanData_channel WHERE channels_channel_xnat_eegScanDa_xnat_imagescandata_id=current_row.xnat_imagescandata_id ORDER BY xnat_eegscandata_channel_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_channel( parent_row.xnat_eegscandata_channel_id, child_count,$3,false,false);
              fullText := fullText || '(channels_channel_eegscandata_channel' || 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_eegScanData_impedance WHERE softwarefiltersimpedances_imped_xnat_imagescandata_id=current_row.xnat_imagescandata_id ORDER BY xnat_eegscandata_impedance_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_impedance( parent_row.xnat_eegscandata_impedance_id, child_count,$3,false,false);
              fullText := fullText || '(softwarefiltersimpedances_impedance_eegscandata_impedance' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.softwarefiltersimpedances_mean IS NOT NULL) THEN 
              fullText := fullText || '(softwarefiltersimpedances_mean:float)=(' || current_row.softwarefiltersimpedances_mean || ')';
          END IF;
        IF ((current_row.eegScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(eegscandata_info:integer)=(' || current_row.eegscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_meta_data(current_row.eegScanData_info, child_count,$3,false,false);
              fullText := fullText || '(eegscandata_info_eegscandata_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_eegscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegscandata_channel(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:eegScanData_channel)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_channel WHERE  xnat_eegscandata_channel_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.resolution IS NOT NULL) THEN 
              fullText := fullText || '(resolution:float)=(' || current_row.resolution || ')';
          END IF;
          IF (current_row.lowcutoff IS NOT NULL) THEN 
              fullText := fullText || '(lowcutoff:string)=(' || REPLACE(REPLACE(current_row.lowcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.highcutoff IS NOT NULL) THEN 
              fullText := fullText || '(highcutoff:string)=(' || REPLACE(REPLACE(current_row.highcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.notch IS NOT NULL) THEN 
              fullText := fullText || '(notch:string)=(' || REPLACE(REPLACE(current_row.notch,'(','*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.eegScanData_channel_info IS NOT NULL)) THEN
            fullText := fullText || '(eegscandata_channel_info:integer)=(' || current_row.eegscandata_channel_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_channel_meta_data(current_row.eegScanData_channel_info, child_count,$3,false,false);
              fullText := fullText || '(eegscandata_channel_info_eegscandata_channel_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.channels_channel_xnat_eegScanDa_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(channels_channel_xnat_eegscanda_xnat_imagescandata_id:integer)=(' || current_row.channels_channel_xnat_eegscanda_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_eegscandata_channel_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_eegscandata_channel_id:integer)=(' || current_row.xnat_eegscandata_channel_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_eegscandata_channel_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:eegScanData_channel_history)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_channel_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.resolution IS NOT NULL) THEN 
              fullText := fullText || '(resolution:float)=(' || current_row.resolution || ')';
          END IF;
          IF (current_row.lowcutoff IS NOT NULL) THEN 
              fullText := fullText || '(lowcutoff:string)=(' || REPLACE(REPLACE(current_row.lowcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.highcutoff IS NOT NULL) THEN 
              fullText := fullText || '(highcutoff:string)=(' || REPLACE(REPLACE(current_row.highcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.notch IS NOT NULL) THEN 
              fullText := fullText || '(notch:string)=(' || REPLACE(REPLACE(current_row.notch,'(','*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.eegScanData_channel_info IS NOT NULL)) THEN
            fullText := fullText || '(eegscandata_channel_info:integer)=(' || current_row.eegscandata_channel_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_channel_meta_data(current_row.eegScanData_channel_info, child_count,$3,false,false);
              fullText := fullText || '(eegscandata_channel_info_eegscandata_channel_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.channels_channel_xnat_eegScanDa_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(channels_channel_xnat_eegscanda_xnat_imagescandata_id:integer)=(' || current_row.channels_channel_xnat_eegscanda_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_eegscandata_channel_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_eegscandata_channel_id:integer)=(' || current_row.xnat_eegscandata_channel_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_eegscandata_channel_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegscandata_channel_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:eegScanData_channel_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_channel_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_eegscandata_channel_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegscandata_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:eegScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_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.parameters_numberofdatarecords IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numberofdatarecords:integer)=(' || current_row.parameters_numberofdatarecords || ')';
          END IF;
          IF (current_row.parameters_datarecord_units IS NOT NULL) THEN 
              fullText := fullText || '(parameters_datarecord_units:string)=(' || REPLACE(REPLACE(current_row.parameters_datarecord_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_datarecord_duration IS NOT NULL) THEN 
              fullText := fullText || '(parameters_datarecord_duration:float)=(' || current_row.parameters_datarecord_duration || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_eegScanData_channel_history WHERE channels_channel_xnat_eegScanDa_xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version ORDER BY xnat_eegscandata_channel_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_channel_history( parent_row.xnat_eegscandata_channel_id, child_count,$3,false,false);
              fullText := fullText || '(channels_channel_eegscandata_channel' || 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_eegScanData_impedance_history WHERE softwarefiltersimpedances_imped_xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version ORDER BY xnat_eegscandata_impedance_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_impedance_history( parent_row.xnat_eegscandata_impedance_id, child_count,$3,false,false);
              fullText := fullText || '(softwarefiltersimpedances_impedance_eegscandata_impedance' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.softwarefiltersimpedances_mean IS NOT NULL) THEN 
              fullText := fullText || '(softwarefiltersimpedances_mean:float)=(' || current_row.softwarefiltersimpedances_mean || ')';
          END IF;
        IF ((current_row.eegScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(eegscandata_info:integer)=(' || current_row.eegscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_meta_data(current_row.eegScanData_info, child_count,$3,false,false);
              fullText := fullText || '(eegscandata_info_eegscandata_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_eegscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegscandata_impedance(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:eegScanData_impedance)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_impedance WHERE  xnat_eegscandata_impedance_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.eegScanData_impedance_info IS NOT NULL)) THEN
            fullText := fullText || '(eegscandata_impedance_info:integer)=(' || current_row.eegscandata_impedance_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_impedance_meta_data(current_row.eegScanData_impedance_info, child_count,$3,false,false);
              fullText := fullText || '(eegscandata_impedance_info_eegscandata_impedance_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.softwarefiltersimpedances_imped_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(softwarefiltersimpedances_imped_xnat_imagescandata_id:integer)=(' || current_row.softwarefiltersimpedances_imped_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_eegscandata_impedance_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_eegscandata_impedance_id:integer)=(' || current_row.xnat_eegscandata_impedance_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_eegscandata_impedance_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:eegScanData_impedance_history)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_impedance_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.eegScanData_impedance_info IS NOT NULL)) THEN
            fullText := fullText || '(eegscandata_impedance_info:integer)=(' || current_row.eegscandata_impedance_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegScanData_impedance_meta_data(current_row.eegScanData_impedance_info, child_count,$3,false,false);
              fullText := fullText || '(eegscandata_impedance_info_eegscandata_impedance_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.softwarefiltersimpedances_imped_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(softwarefiltersimpedances_imped_xnat_imagescandata_id:integer)=(' || current_row.softwarefiltersimpedances_imped_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_eegscandata_impedance_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_eegscandata_impedance_id:integer)=(' || current_row.xnat_eegscandata_impedance_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_eegscandata_impedance_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegscandata_impedance_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:eegScanData_impedance_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_impedance_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_eegscandata_impedance_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegscandata_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:eegScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_eegScanData_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_eegscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegsessiondata(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:eegSessionData)(';
      FOR current_row IN SELECT * FROM xnat_eegSessionData 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.dataformatversion IS NOT NULL) THEN 
              fullText := fullText || '(dataformatversion:string)=(' || REPLACE(REPLACE(current_row.dataformatversion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.numberofchannels IS NOT NULL) THEN 
              fullText := fullText || '(numberofchannels:integer)=(' || current_row.numberofchannels || ')';
          END IF;
          IF (current_row.samplingrate IS NOT NULL) THEN 
              fullText := fullText || '(samplingrate:float)=(' || current_row.samplingrate || ')';
          END IF;
          IF (current_row.samplingrate_units IS NOT NULL) THEN 
              fullText := fullText || '(samplingrate_units:string)=(' || REPLACE(REPLACE(current_row.samplingrate_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.samplinginterval IS NOT NULL) THEN 
              fullText := fullText || '(samplinginterval:float)=(' || current_row.samplinginterval || ')';
          END IF;
          IF (current_row.samplinginterval_units IS NOT NULL) THEN 
              fullText := fullText || '(samplinginterval_units:string)=(' || REPLACE(REPLACE(current_row.samplinginterval_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.eegSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(eegsessiondata_info:integer)=(' || current_row.eegsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegSessionData_meta_data(current_row.eegSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(eegsessiondata_info_eegsessiondata_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_eegsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegsessiondata_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:eegSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_eegSessionData_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.dataformatversion IS NOT NULL) THEN 
              fullText := fullText || '(dataformatversion:string)=(' || REPLACE(REPLACE(current_row.dataformatversion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.numberofchannels IS NOT NULL) THEN 
              fullText := fullText || '(numberofchannels:integer)=(' || current_row.numberofchannels || ')';
          END IF;
          IF (current_row.samplingrate IS NOT NULL) THEN 
              fullText := fullText || '(samplingrate:float)=(' || current_row.samplingrate || ')';
          END IF;
          IF (current_row.samplingrate_units IS NOT NULL) THEN 
              fullText := fullText || '(samplingrate_units:string)=(' || REPLACE(REPLACE(current_row.samplingrate_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.samplinginterval IS NOT NULL) THEN 
              fullText := fullText || '(samplinginterval:float)=(' || current_row.samplinginterval || ')';
          END IF;
          IF (current_row.samplinginterval_units IS NOT NULL) THEN 
              fullText := fullText || '(samplinginterval_units:string)=(' || REPLACE(REPLACE(current_row.samplinginterval_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.eegSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(eegsessiondata_info:integer)=(' || current_row.eegsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_eegSessionData_meta_data(current_row.eegSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(eegsessiondata_info_eegsessiondata_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_eegsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_eegsessiondata_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:eegSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_eegSessionData_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_eegsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_epsscandata(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:epsScanData)(';
      FOR current_row IN SELECT * FROM xnat_epsScanData 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.epsScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(epsscandata_info:integer)=(' || current_row.epsscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_epsScanData_meta_data(current_row.epsScanData_info, child_count,$3,false,false);
              fullText := fullText || '(epsscandata_info_epsscandata_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_epsscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_epsscandata_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:epsScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_epsScanData_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.epsScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(epsscandata_info:integer)=(' || current_row.epsscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_epsScanData_meta_data(current_row.epsScanData_info, child_count,$3,false,false);
              fullText := fullText || '(epsscandata_info_epsscandata_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_epsscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_epsscandata_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:epsScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_epsScanData_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_epsscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_epssessiondata(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:epsSessionData)(';
      FOR current_row IN SELECT * FROM xnat_epsSessionData 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.epsSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(epssessiondata_info:integer)=(' || current_row.epssessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_epsSessionData_meta_data(current_row.epsSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(epssessiondata_info_epssessiondata_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_epssessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_epssessiondata_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:epsSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_epsSessionData_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.epsSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(epssessiondata_info:integer)=(' || current_row.epssessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_epsSessionData_meta_data(current_row.epsSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(epssessiondata_info_epssessiondata_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_epssessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_epssessiondata_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:epsSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_epsSessionData_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_epssessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esscandata(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:esScanData)(';
      FOR current_row IN SELECT * FROM xnat_esScanData 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.esScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(esscandata_info:integer)=(' || current_row.esscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esScanData_meta_data(current_row.esScanData_info, child_count,$3,false,false);
              fullText := fullText || '(esscandata_info_esscandata_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_esscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esscandata_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:esScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_esScanData_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.esScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(esscandata_info:integer)=(' || current_row.esscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esScanData_meta_data(current_row.esScanData_info, child_count,$3,false,false);
              fullText := fullText || '(esscandata_info_esscandata_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_esscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esscandata_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:esScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_esScanData_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_esscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_essessiondata(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:esSessionData)(';
      FOR current_row IN SELECT * FROM xnat_esSessionData 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.esSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(essessiondata_info:integer)=(' || current_row.essessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esSessionData_meta_data(current_row.esSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(essessiondata_info_essessiondata_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_essessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_essessiondata_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:esSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_esSessionData_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.esSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(essessiondata_info:integer)=(' || current_row.essessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esSessionData_meta_data(current_row.esSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(essessiondata_info_essessiondata_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_essessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_essessiondata_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:esSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_esSessionData_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_essessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esvscandata(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:esvScanData)(';
      FOR current_row IN SELECT * FROM xnat_esvScanData 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.esvScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(esvscandata_info:integer)=(' || current_row.esvscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esvScanData_meta_data(current_row.esvScanData_info, child_count,$3,false,false);
              fullText := fullText || '(esvscandata_info_esvscandata_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_esvscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esvscandata_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:esvScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_esvScanData_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.esvScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(esvscandata_info:integer)=(' || current_row.esvscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esvScanData_meta_data(current_row.esvScanData_info, child_count,$3,false,false);
              fullText := fullText || '(esvscandata_info_esvscandata_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_esvscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esvscandata_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:esvScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_esvScanData_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_esvscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esvsessiondata(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:esvSessionData)(';
      FOR current_row IN SELECT * FROM xnat_esvSessionData 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.esvSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(esvsessiondata_info:integer)=(' || current_row.esvsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esvSessionData_meta_data(current_row.esvSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(esvsessiondata_info_esvsessiondata_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_esvsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esvsessiondata_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:esvSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_esvSessionData_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.esvSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(esvsessiondata_info:integer)=(' || current_row.esvsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_esvSessionData_meta_data(current_row.esvSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(esvsessiondata_info_esvsessiondata_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_esvsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_esvsessiondata_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:esvSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_esvSessionData_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_esvsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_experimentdata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_experimentData.id AS xnat_experimentData9, table1.element_name AS xdat_meta_element136, xnat_experimentData.date AS xnat_experimentData0 FROM xnat_experimentData xnat_experimentData   LEFT JOIN xdat_meta_element table1 ON xnat_experimentData.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_experimentData9=$1))
      LOOP
         IF (current_row.xdat_meta_element136 IS NULL) THEN 
             fullText:= ie_xnat_experimentData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element136='scr:screeningAssessment') THEN
                fullText:= i_scr_screeningAssessment( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='val:protocolData') THEN
                fullText:= i_val_protocolData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:genericData') THEN
                fullText:= ie_xnat_genericData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:pVisitData') THEN
                fullText:= i_xnat_pVisitData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:subjectAssessorData') THEN
                fullText:= ie_xnat_subjectAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:subjectVariablesData') THEN
                fullText:= i_xnat_subjectVariablesData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:imageSessionData') THEN
                fullText:= ie_xnat_imageSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mrSessionData') THEN
                fullText:= i_xnat_mrSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mrAssessorData') THEN
                fullText:= ie_xnat_mrAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:derivedData') THEN
                fullText:= ie_xnat_derivedData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petAssessorData') THEN
                fullText:= i_xnat_petAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petSessionData') THEN
                fullText:= i_xnat_petSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petmrSessionData') THEN
                fullText:= i_xnat_petmrSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:qcAssessmentData') THEN
                fullText:= i_xnat_qcAssessmentData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:imageAssessorData') THEN
                fullText:= ie_xnat_imageAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ctSessionData') THEN
                fullText:= i_xnat_ctSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:crSessionData') THEN
                fullText:= i_xnat_crSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:dxSessionData') THEN
                fullText:= i_xnat_dxSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mgSessionData') THEN
                fullText:= i_xnat_mgSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ioSessionData') THEN
                fullText:= i_xnat_ioSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:usSessionData') THEN
                fullText:= i_xnat_usSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ecgSessionData') THEN
                fullText:= i_xnat_ecgSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:hdSessionData') THEN
                fullText:= i_xnat_hdSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:epsSessionData') THEN
                fullText:= i_xnat_epsSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xaSessionData') THEN
                fullText:= i_xnat_xaSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:rfSessionData') THEN
                fullText:= i_xnat_rfSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xa3DSessionData') THEN
                fullText:= i_xnat_xa3DSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:dx3DCraniofacialSessionData') THEN
                fullText:= i_xnat_dx3DCraniofacialSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:nmSessionData') THEN
                fullText:= i_xnat_nmSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:srSessionData') THEN
                fullText:= i_xnat_srSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:esSessionData') THEN
                fullText:= i_xnat_esSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:esvSessionData') THEN
                fullText:= i_xnat_esvSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:gmSessionData') THEN
                fullText:= i_xnat_gmSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:gmvSessionData') THEN
                fullText:= i_xnat_gmvSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:smSessionData') THEN
                fullText:= i_xnat_smSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xcSessionData') THEN
                fullText:= i_xnat_xcSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xcvSessionData') THEN
                fullText:= i_xnat_xcvSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:opSessionData') THEN
                fullText:= i_xnat_opSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:optSessionData') THEN
                fullText:= i_xnat_optSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:rtSessionData') THEN
                fullText:= i_xnat_rtSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:otherDicomSessionData') THEN
                fullText:= i_xnat_otherDicomSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:qcManualAssessorData') THEN
                fullText:= i_xnat_qcManualAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:megSessionData') THEN
                fullText:= i_xnat_megSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:eegSessionData') THEN
                fullText:= i_xnat_eegSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:sideEffectsPittsburghData') THEN
                fullText:= i_xnat_a_sideEffectsPittsburghData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:ybocsData') THEN
                fullText:= i_xnat_a_ybocsData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:ygtssData') THEN
                fullText:= i_xnat_a_ygtssData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:updrs3Data') THEN
                fullText:= i_xnat_a_updrs3Data( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:scidResearchData') THEN
                fullText:= i_xnat_a_scidResearchData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_experimentData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_experimentdata_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:experimentData_field)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_field WHERE  xnat_experimentdata_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.experimentData_field_info IS NOT NULL)) THEN
            fullText := fullText || '(experimentdata_field_info:integer)=(' || current_row.experimentdata_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_field_meta_data(current_row.experimentData_field_info, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_field_info_experimentdata_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_experimentDat_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_experimentdat_id:string)=(' || current_row.fields_field_xnat_experimentdat_id || ')';
        END IF;
          IF (current_row.xnat_experimentdata_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_experimentdata_field_id:integer)=(' || current_row.xnat_experimentdata_field_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_experimentdata_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:experimentData_field_history)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_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.experimentData_field_info IS NOT NULL)) THEN
            fullText := fullText || '(experimentdata_field_info:integer)=(' || current_row.experimentdata_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_field_meta_data(current_row.experimentData_field_info, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_field_info_experimentdata_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_experimentDat_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_experimentdat_id:string)=(' || current_row.fields_field_xnat_experimentdat_id || ')';
        END IF;
          IF (current_row.xnat_experimentdata_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_experimentdata_field_id:integer)=(' || current_row.xnat_experimentdata_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_experimentdata_field_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_experimentdata_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:experimentData_field_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_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_experimentdata_field_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_experimentdata_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_experimentData_history.history_id AS xnat_experimentData_history17, table1.element_name AS xdat_meta_element25, xnat_experimentData_history.xft_version AS xnat_experimentData_history_xft_version, xnat_experimentData_history.id AS xnat_experimentData_history16 FROM xnat_experimentData_history xnat_experimentData_history   LEFT JOIN xdat_meta_element table1 ON xnat_experimentData_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_experimentData_history17=$1))
      LOOP
         IF (current_row.xdat_meta_element25 IS NULL) THEN 
             fullText:= ie_xnat_experimentData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element25='scr:screeningAssessment') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM scr_screeningAssessment_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_scr_screeningAssessment_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='val:protocolData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM val_protocolData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_val_protocolData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:genericData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_genericData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= ie_xnat_genericData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:pVisitData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_pVisitData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_pVisitData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:subjectAssessorData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_subjectAssessorData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= ie_xnat_subjectAssessorData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:subjectVariablesData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_subjectVariablesData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_subjectVariablesData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_imageSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= ie_xnat_imageSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:mrSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_mrSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_mrSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:mrAssessorData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_mrAssessorData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= ie_xnat_mrAssessorData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:derivedData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_derivedData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= ie_xnat_derivedData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:petAssessorData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_petAssessorData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_petAssessorData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:petSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_petSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_petSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:petmrSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_petmrSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_petmrSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:qcAssessmentData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_qcAssessmentData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_qcAssessmentData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageAssessorData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_imageAssessorData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= ie_xnat_imageAssessorData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:ctSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_ctSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_ctSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:crSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_crSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_crSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:dxSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_dxSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_dxSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:mgSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_mgSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_mgSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:ioSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_ioSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_ioSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:usSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_usSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_usSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:ecgSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_ecgSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_ecgSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:hdSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_hdSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_hdSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:epsSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_epsSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_epsSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:xaSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xaSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_xaSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:rfSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_rfSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_rfSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:xa3DSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xa3DSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_xa3DSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:dx3DCraniofacialSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_dx3DCraniofacialSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_dx3DCraniofacialSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:nmSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_nmSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_nmSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:srSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_srSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_srSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:esSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_esSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_esSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:esvSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_esvSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_esvSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:gmSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_gmSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_gmSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:gmvSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_gmvSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_gmvSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:smSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_smSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_smSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:xcSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xcSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_xcSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:xcvSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xcvSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_xcvSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:opSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_opSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_opSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:optSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_optSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_optSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:rtSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_rtSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_rtSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:otherDicomSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_otherDicomSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_otherDicomSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:qcManualAssessorData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_qcManualAssessorData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_qcManualAssessorData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:megSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_megSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_megSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:eegSessionData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_eegSessionData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_eegSessionData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat_a:sideEffectsPittsburghData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_a_sideEffectsPittsburghData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_a_sideEffectsPittsburghData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat_a:ybocsData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_a_ybocsData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_a_ybocsData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat_a:ygtssData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_a_ygtssData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_a_ygtssData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat_a:updrs3Data') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_a_updrs3Data_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_a_updrs3Data_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element25='xnat_a:scidResearchData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_a_scidResearchData_history WHERE id=current_row.xnat_experimentData_history16 AND xft_version=current_row.xnat_experimentData_history_xft_version
           	LOOP
                fullText:= i_xnat_a_scidResearchData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_experimentData_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_experimentdata_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:experimentData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_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_experimentdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_experimentdata_share(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:experimentData_share)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_share WHERE  xnat_experimentdata_share_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.share IS NOT NULL) THEN 
              fullText := fullText || '(share:string)=(' || REPLACE(REPLACE(current_row.share,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit IS NOT NULL) THEN 
              fullText := fullText || '(visit:string)=(' || REPLACE(REPLACE(current_row.visit,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.protocol IS NOT NULL) THEN 
              fullText := fullText || '(protocol:string)=(' || REPLACE(REPLACE(current_row.protocol,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.experimentData_share_info IS NOT NULL)) THEN
            fullText := fullText || '(experimentdata_share_info:integer)=(' || current_row.experimentdata_share_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_share_meta_data(current_row.experimentData_share_info, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_share_info_experimentdata_share_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.sharing_share_xnat_experimentDa_id IS NOT NULL)) THEN
            fullText := fullText || '(sharing_share_xnat_experimentda_id:string)=(' || current_row.sharing_share_xnat_experimentda_id || ')';
        END IF;
          IF (current_row.xnat_experimentdata_share_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_experimentdata_share_id:integer)=(' || current_row.xnat_experimentdata_share_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_experimentdata_share_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:experimentData_share_history)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_share_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.share IS NOT NULL) THEN 
              fullText := fullText || '(share:string)=(' || REPLACE(REPLACE(current_row.share,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit IS NOT NULL) THEN 
              fullText := fullText || '(visit:string)=(' || REPLACE(REPLACE(current_row.visit,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.protocol IS NOT NULL) THEN 
              fullText := fullText || '(protocol:string)=(' || REPLACE(REPLACE(current_row.protocol,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.experimentData_share_info IS NOT NULL)) THEN
            fullText := fullText || '(experimentdata_share_info:integer)=(' || current_row.experimentdata_share_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_experimentData_share_meta_data(current_row.experimentData_share_info, child_count,$3,false,false);
              fullText := fullText || '(experimentdata_share_info_experimentdata_share_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.sharing_share_xnat_experimentDa_id IS NOT NULL)) THEN
            fullText := fullText || '(sharing_share_xnat_experimentda_id:string)=(' || current_row.sharing_share_xnat_experimentda_id || ')';
        END IF;
          IF (current_row.xnat_experimentdata_share_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_experimentdata_share_id:integer)=(' || current_row.xnat_experimentdata_share_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_experimentdata_share_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_experimentdata_share_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:experimentData_share_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_experimentData_share_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_experimentdata_share_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup(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:fieldDefinitionGroup)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup WHERE  xnat_fielddefinitiongroup_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_fieldDefinitionGroup_field WHERE fields_field_xnat_fieldDefiniti_xnat_fielddefinitiongroup_id=current_row.xnat_fielddefinitiongroup_id ORDER BY xnat_fielddefinitiongroup_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field( parent_row.xnat_fielddefinitiongroup_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_fielddefinitiongroup_field' || 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.data_type IS NOT NULL) THEN 
              fullText := fullText || '(data_type:string)=(' || REPLACE(REPLACE(current_row.data_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.project_specific IS NOT NULL) THEN 
              fullText := fullText || '(project_specific:integer)=(' || current_row.project_specific || ')';
          END IF;
        IF ((current_row.fieldDefinitionGroup_info IS NOT NULL)) THEN
            fullText := fullText || '(fielddefinitiongroup_info:integer)=(' || current_row.fielddefinitiongroup_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_meta_data(current_row.fieldDefinitionGroup_info, child_count,$3,false,false);
              fullText := fullText || '(fielddefinitiongroup_info_fielddefinitiongroup_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_fielddefinitiongroup_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_fielddefinitiongroup_id:integer)=(' || current_row.xnat_fielddefinitiongroup_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_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:fieldDefinitionGroup_field)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_field WHERE  xnat_fielddefinitiongroup_field_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_fieldDefinitionGroup_field_possibleValue WHERE possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field=current_row.xnat_fielddefinitiongroup_field_id ORDER BY xnat_fielddefinitiongroup_field_possiblevalue_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field_possibleValue( parent_row.xnat_fielddefinitiongroup_field_possiblevalue_id, child_count,$3,false,false);
              fullText := fullText || '(possiblevalues_possiblevalue_fielddefinitiongroup_field_possiblevalue' || 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.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.datatype IS NOT NULL) THEN 
              fullText := fullText || '(datatype:string)=(' || REPLACE(REPLACE(current_row.datatype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.required IS NOT NULL) THEN 
              fullText := fullText || '(required:integer)=(' || current_row.required || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.xmlpath IS NOT NULL) THEN 
              fullText := fullText || '(xmlpath:string)=(' || REPLACE(REPLACE(current_row.xmlpath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row._group IS NOT NULL) THEN 
              fullText := fullText || '(_group:string)=(' || REPLACE(REPLACE(current_row._group,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.fieldDefinitionGroup_field_info IS NOT NULL)) THEN
            fullText := fullText || '(fielddefinitiongroup_field_info:integer)=(' || current_row.fielddefinitiongroup_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field_meta_data(current_row.fieldDefinitionGroup_field_info, child_count,$3,false,false);
              fullText := fullText || '(fielddefinitiongroup_field_info_fielddefinitiongroup_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_fieldDefiniti_xnat_fielddefinitiongroup_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_fielddefiniti_xnat_fielddefinitiongroup_id:integer)=(' || current_row.fields_field_xnat_fielddefiniti_xnat_fielddefinitiongroup_id || ')';
        END IF;
          IF (current_row.xnat_fielddefinitiongroup_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_fielddefinitiongroup_field_id:integer)=(' || current_row.xnat_fielddefinitiongroup_field_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_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:fieldDefinitionGroup_field_history)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_field_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_fieldDefinitionGroup_field_possibleValue_history WHERE possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field=current_row.xnat_fielddefinitiongroup_field_id AND xft_version=current_row.xft_version ORDER BY xnat_fielddefinitiongroup_field_possiblevalue_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field_possibleValue_history( parent_row.xnat_fielddefinitiongroup_field_possiblevalue_id, child_count,$3,false,false);
              fullText := fullText || '(possiblevalues_possiblevalue_fielddefinitiongroup_field_possiblevalue' || 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.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.datatype IS NOT NULL) THEN 
              fullText := fullText || '(datatype:string)=(' || REPLACE(REPLACE(current_row.datatype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.required IS NOT NULL) THEN 
              fullText := fullText || '(required:integer)=(' || current_row.required || ')';
          END IF;
          IF (current_row.sequence IS NOT NULL) THEN 
              fullText := fullText || '(sequence:integer)=(' || current_row.sequence || ')';
          END IF;
          IF (current_row.xmlpath IS NOT NULL) THEN 
              fullText := fullText || '(xmlpath:string)=(' || REPLACE(REPLACE(current_row.xmlpath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row._group IS NOT NULL) THEN 
              fullText := fullText || '(_group:string)=(' || REPLACE(REPLACE(current_row._group,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.fieldDefinitionGroup_field_info IS NOT NULL)) THEN
            fullText := fullText || '(fielddefinitiongroup_field_info:integer)=(' || current_row.fielddefinitiongroup_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field_meta_data(current_row.fieldDefinitionGroup_field_info, child_count,$3,false,false);
              fullText := fullText || '(fielddefinitiongroup_field_info_fielddefinitiongroup_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_fieldDefiniti_xnat_fielddefinitiongroup_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_fielddefiniti_xnat_fielddefinitiongroup_id:integer)=(' || current_row.fields_field_xnat_fielddefiniti_xnat_fielddefinitiongroup_id || ')';
        END IF;
          IF (current_row.xnat_fielddefinitiongroup_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_fielddefinitiongroup_field_id:integer)=(' || current_row.xnat_fielddefinitiongroup_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_fielddefinitiongroup_field_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_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:fieldDefinitionGroup_field_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_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_fielddefinitiongroup_field_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_field_possiblevalue(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:fieldDefinitionGroup_field_possibleValue)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_field_possibleValue WHERE  xnat_fielddefinitiongroup_field_possiblevalue_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.possiblevalue IS NOT NULL) THEN 
              fullText := fullText || '(possiblevalue:string)=(' || REPLACE(REPLACE(current_row.possiblevalue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display IS NOT NULL) THEN 
              fullText := fullText || '(display:string)=(' || REPLACE(REPLACE(current_row.display,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.fieldDefinitionGroup_field_possibleValue_info IS NOT NULL)) THEN
            fullText := fullText || '(fielddefinitiongroup_field_possiblevalue_info:integer)=(' || current_row.fielddefinitiongroup_field_possiblevalue_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field_possibleValue_meta_data(current_row.fieldDefinitionGroup_field_possibleValue_info, child_count,$3,false,false);
              fullText := fullText || '(fielddefinitiongroup_field_possiblevalue_info_fielddefinitiongroup_field_possiblevalue_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field IS NOT NULL)) THEN
            fullText := fullText || '(possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field:integer)=(' || current_row.possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field || ')';
        END IF;
          IF (current_row.xnat_fielddefinitiongroup_field_possiblevalue_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_fielddefinitiongroup_field_possiblevalue_id:integer)=(' || current_row.xnat_fielddefinitiongroup_field_possiblevalue_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_field_possiblevalue_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:fieldDefinitionGroup_field_possibleValue_history)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_field_possibleValue_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.possiblevalue IS NOT NULL) THEN 
              fullText := fullText || '(possiblevalue:string)=(' || REPLACE(REPLACE(current_row.possiblevalue,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.display IS NOT NULL) THEN 
              fullText := fullText || '(display:string)=(' || REPLACE(REPLACE(current_row.display,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.fieldDefinitionGroup_field_possibleValue_info IS NOT NULL)) THEN
            fullText := fullText || '(fielddefinitiongroup_field_possiblevalue_info:integer)=(' || current_row.fielddefinitiongroup_field_possiblevalue_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field_possibleValue_meta_data(current_row.fieldDefinitionGroup_field_possibleValue_info, child_count,$3,false,false);
              fullText := fullText || '(fielddefinitiongroup_field_possiblevalue_info_fielddefinitiongroup_field_possiblevalue_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field IS NOT NULL)) THEN
            fullText := fullText || '(possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field:integer)=(' || current_row.possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field || ')';
        END IF;
          IF (current_row.xnat_fielddefinitiongroup_field_possiblevalue_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_fielddefinitiongroup_field_possiblevalue_id:integer)=(' || current_row.xnat_fielddefinitiongroup_field_possiblevalue_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_fielddefinitiongroup_field_possiblevalue_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_field_possiblevalue_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:fieldDefinitionGroup_field_possibleValue_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_field_possibleValue_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_fielddefinitiongroup_field_possiblevalue_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_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:fieldDefinitionGroup_history)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_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_fieldDefinitionGroup_field_history WHERE fields_field_xnat_fieldDefiniti_xnat_fielddefinitiongroup_id=current_row.xnat_fielddefinitiongroup_id AND xft_version=current_row.xft_version ORDER BY xnat_fielddefinitiongroup_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_field_history( parent_row.xnat_fielddefinitiongroup_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_fielddefinitiongroup_field' || 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.data_type IS NOT NULL) THEN 
              fullText := fullText || '(data_type:string)=(' || REPLACE(REPLACE(current_row.data_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.shareable IS NOT NULL) THEN 
              fullText := fullText || '(shareable:integer)=(' || current_row.shareable || ')';
          END IF;
          IF (current_row.project_specific IS NOT NULL) THEN 
              fullText := fullText || '(project_specific:integer)=(' || current_row.project_specific || ')';
          END IF;
        IF ((current_row.fieldDefinitionGroup_info IS NOT NULL)) THEN
            fullText := fullText || '(fielddefinitiongroup_info:integer)=(' || current_row.fielddefinitiongroup_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_meta_data(current_row.fieldDefinitionGroup_info, child_count,$3,false,false);
              fullText := fullText || '(fielddefinitiongroup_info_fielddefinitiongroup_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_fielddefinitiongroup_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_fielddefinitiongroup_id:integer)=(' || current_row.xnat_fielddefinitiongroup_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_fielddefinitiongroup_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_fielddefinitiongroup_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:fieldDefinitionGroup_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_fieldDefinitionGroup_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_fielddefinitiongroup_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_genericdata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT table0.id AS xnat_genericData0, table2.element_name AS xdat_meta_element138, table0.date AS xnat_experimentData2 FROM xnat_genericData xnat_genericData   LEFT JOIN xnat_experimentData table0 ON xnat_genericData.id=table0.id   LEFT JOIN xdat_meta_element table2 ON table0.extension=table2.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_genericData0=$1))
      LOOP
         IF (current_row.xdat_meta_element138 IS NULL) THEN 
             fullText:= ie_xnat_genericData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element138='xnat:pVisitData') THEN
                fullText:= i_xnat_pVisitData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_genericData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_genericdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      FOR current_row IN SELECT * FROM xnat_genericData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_experimentData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
           	   tempText := i_xnat_experimentData_history(ext_row.history_id, child_count,$3,false,false);
 RETURN tempText;
           	END LOOP;
           END;
        END IF;
      END LOOP;
      fullText:= ie_xnat_genericData_history( $1, $2,$3,$4,$5);
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_genericdata_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:genericData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_genericData_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_genericdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmscandata(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:gmScanData)(';
      FOR current_row IN SELECT * FROM xnat_gmScanData 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.gmScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmscandata_info:integer)=(' || current_row.gmscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmScanData_meta_data(current_row.gmScanData_info, child_count,$3,false,false);
              fullText := fullText || '(gmscandata_info_gmscandata_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_gmscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmscandata_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:gmScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_gmScanData_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.gmScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmscandata_info:integer)=(' || current_row.gmscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmScanData_meta_data(current_row.gmScanData_info, child_count,$3,false,false);
              fullText := fullText || '(gmscandata_info_gmscandata_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_gmscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmscandata_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:gmScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_gmScanData_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_gmscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmsessiondata(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:gmSessionData)(';
      FOR current_row IN SELECT * FROM xnat_gmSessionData 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.gmSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmsessiondata_info:integer)=(' || current_row.gmsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmSessionData_meta_data(current_row.gmSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(gmsessiondata_info_gmsessiondata_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_gmsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmsessiondata_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:gmSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_gmSessionData_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.gmSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmsessiondata_info:integer)=(' || current_row.gmsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmSessionData_meta_data(current_row.gmSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(gmsessiondata_info_gmsessiondata_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_gmsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmsessiondata_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:gmSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_gmSessionData_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_gmsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmvscandata(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:gmvScanData)(';
      FOR current_row IN SELECT * FROM xnat_gmvScanData 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.gmvScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmvscandata_info:integer)=(' || current_row.gmvscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmvScanData_meta_data(current_row.gmvScanData_info, child_count,$3,false,false);
              fullText := fullText || '(gmvscandata_info_gmvscandata_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_gmvscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmvscandata_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:gmvScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_gmvScanData_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.gmvScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmvscandata_info:integer)=(' || current_row.gmvscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmvScanData_meta_data(current_row.gmvScanData_info, child_count,$3,false,false);
              fullText := fullText || '(gmvscandata_info_gmvscandata_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_gmvscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmvscandata_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:gmvScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_gmvScanData_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_gmvscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
