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

CREATE FUNCTION public.i_xnat_gmvsessiondata(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:gmvSessionData)(';
      FOR current_row IN SELECT * FROM xnat_gmvSessionData 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.gmvSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmvsessiondata_info:integer)=(' || current_row.gmvsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmvSessionData_meta_data(current_row.gmvSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(gmvsessiondata_info_gmvsessiondata_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_gmvsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmvsessiondata_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:gmvSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_gmvSessionData_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.gmvSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(gmvsessiondata_info:integer)=(' || current_row.gmvsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_gmvSessionData_meta_data(current_row.gmvSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(gmvsessiondata_info_gmvsessiondata_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_gmvsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_gmvsessiondata_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:gmvSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_gmvSessionData_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_gmvsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_hdscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:hdScanData)(';
      FOR current_row IN SELECT * FROM xnat_hdScanData 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.hdScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(hdscandata_info:integer)=(' || current_row.hdscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_hdScanData_meta_data(current_row.hdScanData_info, child_count,$3,false,false);
              fullText := fullText || '(hdscandata_info_hdscandata_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_hdscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_hdscandata_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:hdScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_hdScanData_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.hdScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(hdscandata_info:integer)=(' || current_row.hdscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_hdScanData_meta_data(current_row.hdScanData_info, child_count,$3,false,false);
              fullText := fullText || '(hdscandata_info_hdscandata_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_hdscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_hdscandata_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:hdScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_hdScanData_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_hdscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_hdsessiondata(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:hdSessionData)(';
      FOR current_row IN SELECT * FROM xnat_hdSessionData 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.hdSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(hdsessiondata_info:integer)=(' || current_row.hdsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_hdSessionData_meta_data(current_row.hdSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(hdsessiondata_info_hdsessiondata_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_hdsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_hdsessiondata_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:hdSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_hdSessionData_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.hdSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(hdsessiondata_info:integer)=(' || current_row.hdsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_hdSessionData_meta_data(current_row.hdSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(hdsessiondata_info_hdsessiondata_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_hdsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_hdsessiondata_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:hdSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_hdSessionData_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_hdsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_imageassessordata(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 table1.id AS xnat_imageAssessorData0, table3.element_name AS xdat_meta_element142, table1.date AS xnat_experimentData6 FROM xnat_imageAssessorData xnat_imageAssessorData   LEFT JOIN xnat_derivedData table0 ON xnat_imageAssessorData.id=table0.id   LEFT JOIN xnat_experimentData table1 ON table0.id=table1.id   LEFT JOIN xdat_meta_element table3 ON table1.extension=table3.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_imageAssessorData0=$1))
      LOOP
         IF (current_row.xdat_meta_element142 IS NULL) THEN 
             fullText:= ie_xnat_imageAssessorData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element142='scr:screeningAssessment') THEN
                fullText:= i_scr_screeningAssessment( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='val:protocolData') THEN
                fullText:= i_val_protocolData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:mrAssessorData') THEN
                fullText:= ie_xnat_mrAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:petAssessorData') THEN
                fullText:= i_xnat_petAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:qcAssessmentData') THEN
                fullText:= i_xnat_qcAssessmentData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:qcManualAssessorData') THEN
                fullText:= i_xnat_qcManualAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_imageAssessorData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_imageassessordata_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:imageAssessorData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_imageAssessorData_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_imageassessordata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_imageresource(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:imageResource)(';
      FOR current_row IN SELECT * FROM xnat_imageResource WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_resource(current_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(resource_resource:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_x:integer)=(' || current_row.dimensions_x || ')';
          END IF;
          IF (current_row.dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_y:integer)=(' || current_row.dimensions_y || ')';
          END IF;
          IF (current_row.dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_z:integer)=(' || current_row.dimensions_z || ')';
          END IF;
          IF (current_row.dimensions_volumes IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_volumes:integer)=(' || current_row.dimensions_volumes || ')';
          END IF;
          IF (current_row.voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_x:float)=(' || current_row.voxelres_x || ')';
          END IF;
          IF (current_row.voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_y:float)=(' || current_row.voxelres_y || ')';
          END IF;
          IF (current_row.voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_z:float)=(' || current_row.voxelres_z || ')';
          END IF;
          IF (current_row.voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_units:string)=(' || REPLACE(REPLACE(current_row.voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.orientation IS NOT NULL) THEN 
              fullText := fullText || '(orientation:string)=(' || REPLACE(REPLACE(current_row.orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.imageResource_info IS NOT NULL)) THEN
            fullText := fullText || '(imageresource_info:integer)=(' || current_row.imageresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageResource_meta_data(current_row.imageResource_info, child_count,$3,false,false);
              fullText := fullText || '(imageresource_info_imageresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_resource( $1, child_count,$3,$4,false);
              fullText := fullText || '(resource_resource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_imageresource_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:imageResource_history)(';
      FOR current_row IN SELECT * FROM xnat_imageResource_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_resource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_resource_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(resource_resource:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_x:integer)=(' || current_row.dimensions_x || ')';
          END IF;
          IF (current_row.dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_y:integer)=(' || current_row.dimensions_y || ')';
          END IF;
          IF (current_row.dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_z:integer)=(' || current_row.dimensions_z || ')';
          END IF;
          IF (current_row.dimensions_volumes IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_volumes:integer)=(' || current_row.dimensions_volumes || ')';
          END IF;
          IF (current_row.voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_x:float)=(' || current_row.voxelres_x || ')';
          END IF;
          IF (current_row.voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_y:float)=(' || current_row.voxelres_y || ')';
          END IF;
          IF (current_row.voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_z:float)=(' || current_row.voxelres_z || ')';
          END IF;
          IF (current_row.voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_units:string)=(' || REPLACE(REPLACE(current_row.voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.orientation IS NOT NULL) THEN 
              fullText := fullText || '(orientation:string)=(' || REPLACE(REPLACE(current_row.orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.imageResource_info IS NOT NULL)) THEN
            fullText := fullText || '(imageresource_info:integer)=(' || current_row.imageresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageResource_meta_data(current_row.imageResource_info, child_count,$3,false,false);
              fullText := fullText || '(imageresource_info_imageresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_resource_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(resource_resource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_imageresource_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:imageResource_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_imageResource_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_imageresource_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_imageresourceseries(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:imageResourceSeries)(';
      FOR current_row IN SELECT * FROM xnat_imageResourceSeries WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_resourceSeries(current_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(resourceseries_resourceseries:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_x:integer)=(' || current_row.dimensions_x || ')';
          END IF;
          IF (current_row.dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_y:integer)=(' || current_row.dimensions_y || ')';
          END IF;
          IF (current_row.dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_z:integer)=(' || current_row.dimensions_z || ')';
          END IF;
          IF (current_row.dimensions_volumes IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_volumes:integer)=(' || current_row.dimensions_volumes || ')';
          END IF;
          IF (current_row.voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_x:float)=(' || current_row.voxelres_x || ')';
          END IF;
          IF (current_row.voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_y:float)=(' || current_row.voxelres_y || ')';
          END IF;
          IF (current_row.voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_z:float)=(' || current_row.voxelres_z || ')';
          END IF;
          IF (current_row.voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_units:string)=(' || REPLACE(REPLACE(current_row.voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.orientation IS NOT NULL) THEN 
              fullText := fullText || '(orientation:string)=(' || REPLACE(REPLACE(current_row.orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.imageResourceSeries_info IS NOT NULL)) THEN
            fullText := fullText || '(imageresourceseries_info:integer)=(' || current_row.imageresourceseries_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageResourceSeries_meta_data(current_row.imageResourceSeries_info, child_count,$3,false,false);
              fullText := fullText || '(imageresourceseries_info_imageresourceseries_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_resourceSeries( $1, child_count,$3,$4,false);
              fullText := fullText || '(resourceseries_resourceseries:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_imageresourceseries_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:imageResourceSeries_history)(';
      FOR current_row IN SELECT * FROM xnat_imageResourceSeries_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_resourceSeries_history WHERE xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_resourceSeries_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(resourceseries_resourceseries:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_x:integer)=(' || current_row.dimensions_x || ')';
          END IF;
          IF (current_row.dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_y:integer)=(' || current_row.dimensions_y || ')';
          END IF;
          IF (current_row.dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_z:integer)=(' || current_row.dimensions_z || ')';
          END IF;
          IF (current_row.dimensions_volumes IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_volumes:integer)=(' || current_row.dimensions_volumes || ')';
          END IF;
          IF (current_row.voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_x:float)=(' || current_row.voxelres_x || ')';
          END IF;
          IF (current_row.voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_y:float)=(' || current_row.voxelres_y || ')';
          END IF;
          IF (current_row.voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_z:float)=(' || current_row.voxelres_z || ')';
          END IF;
          IF (current_row.voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_units:string)=(' || REPLACE(REPLACE(current_row.voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.orientation IS NOT NULL) THEN 
              fullText := fullText || '(orientation:string)=(' || REPLACE(REPLACE(current_row.orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.imageResourceSeries_info IS NOT NULL)) THEN
            fullText := fullText || '(imageresourceseries_info:integer)=(' || current_row.imageresourceseries_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageResourceSeries_meta_data(current_row.imageResourceSeries_info, child_count,$3,false,false);
              fullText := fullText || '(imageresourceseries_info_imageresourceseries_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_resourceSeries_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(resourceseries_resourceseries:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_imageresourceseries_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:imageResourceSeries_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_imageResourceSeries_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_imageresourceseries_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_imagescandata(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_imageScanData.xnat_imagescandata_id AS xnat_imageScanData23, table1.element_name AS xdat_meta_element100, table2.insert_date AS xnat_imageScanData_meta_data107 FROM xnat_imageScanData xnat_imageScanData   LEFT JOIN xdat_meta_element table1 ON xnat_imageScanData.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_imageScanData_meta_data table2 ON xnat_imageScanData.imageScanData_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xnat_imageScanData23=$1))
      LOOP
         IF (current_row.xdat_meta_element100 IS NULL) THEN 
             fullText:= ie_xnat_imageScanData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element100='xnat:mrScanData') THEN
                fullText:= i_xnat_mrScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:petScanData') THEN
                fullText:= i_xnat_petScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ctScanData') THEN
                fullText:= i_xnat_ctScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:crScanData') THEN
                fullText:= i_xnat_crScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:dxScanData') THEN
                fullText:= i_xnat_dxScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:mgScanData') THEN
                fullText:= i_xnat_mgScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ioScanData') THEN
                fullText:= i_xnat_ioScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:usScanData') THEN
                fullText:= i_xnat_usScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ecgScanData') THEN
                fullText:= i_xnat_ecgScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:hdScanData') THEN
                fullText:= i_xnat_hdScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:epsScanData') THEN
                fullText:= i_xnat_epsScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xaScanData') THEN
                fullText:= i_xnat_xaScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:rfScanData') THEN
                fullText:= i_xnat_rfScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xa3DScanData') THEN
                fullText:= i_xnat_xa3DScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:dx3DCraniofacialScanData') THEN
                fullText:= i_xnat_dx3DCraniofacialScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:nmScanData') THEN
                fullText:= i_xnat_nmScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:srScanData') THEN
                fullText:= i_xnat_srScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:esScanData') THEN
                fullText:= i_xnat_esScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:esvScanData') THEN
                fullText:= i_xnat_esvScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:gmScanData') THEN
                fullText:= i_xnat_gmScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:gmvScanData') THEN
                fullText:= i_xnat_gmvScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:smScanData') THEN
                fullText:= i_xnat_smScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xcScanData') THEN
                fullText:= i_xnat_xcScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xcvScanData') THEN
                fullText:= i_xnat_xcvScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:opScanData') THEN
                fullText:= i_xnat_opScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:optScanData') THEN
                fullText:= i_xnat_optScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:rtImageScanData') THEN
                fullText:= i_xnat_rtImageScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:scScanData') THEN
                fullText:= i_xnat_scScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:segScanData') THEN
                fullText:= i_xnat_segScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:mrsScanData') THEN
                fullText:= i_xnat_mrsScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:voiceAudioScanData') THEN
                fullText:= i_xnat_voiceAudioScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:otherDicomScanData') THEN
                fullText:= i_xnat_otherDicomScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:megScanData') THEN
                fullText:= i_xnat_megScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:eegScanData') THEN
                fullText:= i_xnat_eegScanData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_imageScanData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_imagescandata_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_imageScanData_history.history_id AS xnat_imageScanData_history21, table1.element_name AS xdat_meta_element30, xnat_imageScanData_history.xft_version AS xnat_imageScanData_history_xft_version, xnat_imageScanData_history.xnat_imagescandata_id AS xnat_imageScanData_history15 FROM xnat_imageScanData_history xnat_imageScanData_history   LEFT JOIN xdat_meta_element table1 ON xnat_imageScanData_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_imageScanData_history21=$1))
      LOOP
         IF (current_row.xdat_meta_element30 IS NULL) THEN 
             fullText:= ie_xnat_imageScanData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element30='xnat:mrScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_mrScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_mrScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:petScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_petScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_petScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:ctScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_ctScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_ctScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:crScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_crScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_crScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:dxScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_dxScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_dxScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:mgScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_mgScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_mgScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:ioScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_ioScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_ioScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:usScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_usScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_usScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:ecgScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_ecgScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_ecgScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:hdScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_hdScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_hdScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:epsScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_epsScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_epsScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:xaScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xaScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_xaScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:rfScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_rfScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_rfScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:xa3DScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xa3DScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_xa3DScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:dx3DCraniofacialScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_dx3DCraniofacialScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_dx3DCraniofacialScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:nmScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_nmScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_nmScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:srScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_srScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_srScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:esScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_esScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_esScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:esvScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_esvScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_esvScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:gmScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_gmScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_gmScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:gmvScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_gmvScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_gmvScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:smScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_smScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_smScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:xcScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xcScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_xcScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:xcvScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_xcvScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_xcvScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:opScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_opScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_opScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:optScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_optScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_optScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:rtImageScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_rtImageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_rtImageScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:scScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_scScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_scScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:segScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_segScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_segScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:mrsScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_mrsScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_mrsScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:voiceAudioScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_voiceAudioScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_voiceAudioScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:otherDicomScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_otherDicomScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_otherDicomScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:megScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_megScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_megScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:eegScanData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_eegScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imageScanData_history15 AND xft_version=current_row.xnat_imageScanData_history_xft_version
           	LOOP
                fullText:= i_xnat_eegScanData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_imageScanData_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_imagescandata_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:imageScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_imageScanData_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_imagescandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_imagescandata_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:imageScanData_share)(';
      FOR current_row IN SELECT * FROM xnat_imageScanData_share WHERE  xnat_imagescandata_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.imageScanData_share_info IS NOT NULL)) THEN
            fullText := fullText || '(imagescandata_share_info:integer)=(' || current_row.imagescandata_share_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData_share_meta_data(current_row.imageScanData_share_info, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_share_info_imagescandata_share_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.sharing_share_xnat_imageScanDat_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(sharing_share_xnat_imagescandat_xnat_imagescandata_id:integer)=(' || current_row.sharing_share_xnat_imagescandat_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_imagescandata_share_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_imagescandata_share_id:integer)=(' || current_row.xnat_imagescandata_share_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_imagescandata_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:imageScanData_share_history)(';
      FOR current_row IN SELECT * FROM xnat_imageScanData_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.imageScanData_share_info IS NOT NULL)) THEN
            fullText := fullText || '(imagescandata_share_info:integer)=(' || current_row.imagescandata_share_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_imageScanData_share_meta_data(current_row.imageScanData_share_info, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_share_info_imagescandata_share_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.sharing_share_xnat_imageScanDat_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(sharing_share_xnat_imagescandat_xnat_imagescandata_id:integer)=(' || current_row.sharing_share_xnat_imagescandat_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_imagescandata_share_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_imagescandata_share_id:integer)=(' || current_row.xnat_imagescandata_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_imagescandata_share_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_imagescandata_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:imageScanData_share_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_imageScanData_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_imagescandata_share_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_imagesessiondata(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 table1.id AS xnat_imageSessionData0, table3.element_name AS xdat_meta_element156, table1.date AS xnat_experimentData20 FROM xnat_imageSessionData xnat_imageSessionData   LEFT JOIN xnat_subjectAssessorData table0 ON xnat_imageSessionData.id=table0.id   LEFT JOIN xnat_experimentData table1 ON table0.id=table1.id   LEFT JOIN xdat_meta_element table3 ON table1.extension=table3.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_imageSessionData0=$1))
      LOOP
         IF (current_row.xdat_meta_element156 IS NULL) THEN 
             fullText:= ie_xnat_imageSessionData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element156='xnat:mrSessionData') THEN
                fullText:= i_xnat_mrSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:petSessionData') THEN
                fullText:= i_xnat_petSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:petmrSessionData') THEN
                fullText:= i_xnat_petmrSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ctSessionData') THEN
                fullText:= i_xnat_ctSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:crSessionData') THEN
                fullText:= i_xnat_crSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:dxSessionData') THEN
                fullText:= i_xnat_dxSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:mgSessionData') THEN
                fullText:= i_xnat_mgSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ioSessionData') THEN
                fullText:= i_xnat_ioSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:usSessionData') THEN
                fullText:= i_xnat_usSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ecgSessionData') THEN
                fullText:= i_xnat_ecgSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:hdSessionData') THEN
                fullText:= i_xnat_hdSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:epsSessionData') THEN
                fullText:= i_xnat_epsSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xaSessionData') THEN
                fullText:= i_xnat_xaSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:rfSessionData') THEN
                fullText:= i_xnat_rfSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xa3DSessionData') THEN
                fullText:= i_xnat_xa3DSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:dx3DCraniofacialSessionData') THEN
                fullText:= i_xnat_dx3DCraniofacialSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:nmSessionData') THEN
                fullText:= i_xnat_nmSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:srSessionData') THEN
                fullText:= i_xnat_srSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:esSessionData') THEN
                fullText:= i_xnat_esSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:esvSessionData') THEN
                fullText:= i_xnat_esvSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:gmSessionData') THEN
                fullText:= i_xnat_gmSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:gmvSessionData') THEN
                fullText:= i_xnat_gmvSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:smSessionData') THEN
                fullText:= i_xnat_smSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xcSessionData') THEN
                fullText:= i_xnat_xcSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xcvSessionData') THEN
                fullText:= i_xnat_xcvSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:opSessionData') THEN
                fullText:= i_xnat_opSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:optSessionData') THEN
                fullText:= i_xnat_optSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:rtSessionData') THEN
                fullText:= i_xnat_rtSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:otherDicomSessionData') THEN
                fullText:= i_xnat_otherDicomSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:megSessionData') THEN
                fullText:= i_xnat_megSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:eegSessionData') THEN
                fullText:= i_xnat_eegSessionData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_imageSessionData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_imagesessiondata_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:imageSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_imageSessionData_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_imagesessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_investigatordata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:investigatorData)(';
      FOR current_row IN SELECT * FROM xnat_investigatorData WHERE  xnat_investigatordata_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.title IS NOT NULL) THEN 
              fullText := fullText || '(title:string)=(' || REPLACE(REPLACE(current_row.title,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.firstname IS NOT NULL) THEN 
              fullText := fullText || '(firstname:string)=(' || REPLACE(REPLACE(current_row.firstname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.lastname IS NOT NULL) THEN 
              fullText := fullText || '(lastname:string)=(' || REPLACE(REPLACE(current_row.lastname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.institution IS NOT NULL) THEN 
              fullText := fullText || '(institution:string)=(' || REPLACE(REPLACE(current_row.institution,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.department IS NOT NULL) THEN 
              fullText := fullText || '(department:string)=(' || REPLACE(REPLACE(current_row.department,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.email IS NOT NULL) THEN 
              fullText := fullText || '(email:string)=(' || REPLACE(REPLACE(current_row.email,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.phone IS NOT NULL) THEN 
              fullText := fullText || '(phone:string)=(' || REPLACE(REPLACE(current_row.phone,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.investigatorData_info IS NOT NULL)) THEN
            fullText := fullText || '(investigatordata_info:integer)=(' || current_row.investigatordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData_meta_data(current_row.investigatorData_info, child_count,$3,false,false);
              fullText := fullText || '(investigatordata_info_investigatordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_investigatordata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_investigatordata_id:integer)=(' || current_row.xnat_investigatordata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_investigatordata_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:investigatorData_history)(';
      FOR current_row IN SELECT * FROM xnat_investigatorData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.title IS NOT NULL) THEN 
              fullText := fullText || '(title:string)=(' || REPLACE(REPLACE(current_row.title,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.firstname IS NOT NULL) THEN 
              fullText := fullText || '(firstname:string)=(' || REPLACE(REPLACE(current_row.firstname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.lastname IS NOT NULL) THEN 
              fullText := fullText || '(lastname:string)=(' || REPLACE(REPLACE(current_row.lastname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.institution IS NOT NULL) THEN 
              fullText := fullText || '(institution:string)=(' || REPLACE(REPLACE(current_row.institution,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.department IS NOT NULL) THEN 
              fullText := fullText || '(department:string)=(' || REPLACE(REPLACE(current_row.department,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.email IS NOT NULL) THEN 
              fullText := fullText || '(email:string)=(' || REPLACE(REPLACE(current_row.email,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.phone IS NOT NULL) THEN 
              fullText := fullText || '(phone:string)=(' || REPLACE(REPLACE(current_row.phone,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.investigatorData_info IS NOT NULL)) THEN
            fullText := fullText || '(investigatordata_info:integer)=(' || current_row.investigatordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData_meta_data(current_row.investigatorData_info, child_count,$3,false,false);
              fullText := fullText || '(investigatordata_info_investigatordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_investigatordata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_investigatordata_id:integer)=(' || current_row.xnat_investigatordata_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_investigatordata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_investigatordata_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:investigatorData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_investigatorData_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_investigatordata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ioscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:ioScanData)(';
      FOR current_row IN SELECT * FROM xnat_ioScanData 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.ioScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(ioscandata_info:integer)=(' || current_row.ioscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ioScanData_meta_data(current_row.ioScanData_info, child_count,$3,false,false);
              fullText := fullText || '(ioscandata_info_ioscandata_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_ioscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ioscandata_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:ioScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_ioScanData_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.ioScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(ioscandata_info:integer)=(' || current_row.ioscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ioScanData_meta_data(current_row.ioScanData_info, child_count,$3,false,false);
              fullText := fullText || '(ioscandata_info_ioscandata_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_ioscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ioscandata_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:ioScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_ioScanData_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_ioscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_iosessiondata(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:ioSessionData)(';
      FOR current_row IN SELECT * FROM xnat_ioSessionData 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.ioSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(iosessiondata_info:integer)=(' || current_row.iosessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ioSessionData_meta_data(current_row.ioSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(iosessiondata_info_iosessiondata_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_iosessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_iosessiondata_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:ioSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_ioSessionData_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.ioSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(iosessiondata_info:integer)=(' || current_row.iosessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ioSessionData_meta_data(current_row.ioSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(iosessiondata_info_iosessiondata_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_iosessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_iosessiondata_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:ioSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_ioSessionData_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_iosessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_megscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:megScanData)(';
      FOR current_row IN SELECT * FROM xnat_megScanData 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.megScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(megscandata_info:integer)=(' || current_row.megscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_megScanData_meta_data(current_row.megScanData_info, child_count,$3,false,false);
              fullText := fullText || '(megscandata_info_megscandata_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_megscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_megscandata_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:megScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_megScanData_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.megScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(megscandata_info:integer)=(' || current_row.megscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_megScanData_meta_data(current_row.megScanData_info, child_count,$3,false,false);
              fullText := fullText || '(megscandata_info_megscandata_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_megscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_megscandata_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:megScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_megScanData_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_megscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_megsessiondata(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:megSessionData)(';
      FOR current_row IN SELECT * FROM xnat_megSessionData 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.megSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(megsessiondata_info:integer)=(' || current_row.megsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_megSessionData_meta_data(current_row.megSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(megsessiondata_info_megsessiondata_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_megsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_megsessiondata_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:megSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_megSessionData_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.megSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(megsessiondata_info:integer)=(' || current_row.megsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_megSessionData_meta_data(current_row.megSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(megsessiondata_info_megsessiondata_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_megsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_megsessiondata_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:megSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_megSessionData_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_megsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mgscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:mgScanData)(';
      FOR current_row IN SELECT * FROM xnat_mgScanData 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.mgScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mgscandata_info:integer)=(' || current_row.mgscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mgScanData_meta_data(current_row.mgScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mgscandata_info_mgscandata_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_mgscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mgscandata_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:mgScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_mgScanData_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.mgScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mgscandata_info:integer)=(' || current_row.mgscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mgScanData_meta_data(current_row.mgScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mgscandata_info_mgscandata_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_mgscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mgscandata_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:mgScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_mgScanData_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_mgscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mgsessiondata(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:mgSessionData)(';
      FOR current_row IN SELECT * FROM xnat_mgSessionData 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.mgSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(mgsessiondata_info:integer)=(' || current_row.mgsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mgSessionData_meta_data(current_row.mgSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(mgsessiondata_info_mgsessiondata_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_mgsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mgsessiondata_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:mgSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_mgSessionData_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.mgSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(mgsessiondata_info:integer)=(' || current_row.mgsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mgSessionData_meta_data(current_row.mgSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(mgsessiondata_info_mgsessiondata_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_mgsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mgsessiondata_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:mgSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_mgSessionData_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_mgsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrassessordata(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 table2.id AS xnat_mrAssessorData0, table4.element_name AS xdat_meta_element144, table2.date AS xnat_experimentData8 FROM xnat_mrAssessorData xnat_mrAssessorData   LEFT JOIN xnat_imageAssessorData table0 ON xnat_mrAssessorData.id=table0.id   LEFT JOIN xnat_derivedData table1 ON table0.id=table1.id   LEFT JOIN xnat_experimentData table2 ON table1.id=table2.id   LEFT JOIN xdat_meta_element table4 ON table2.extension=table4.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_mrAssessorData0=$1))
      LOOP
         IF (current_row.xdat_meta_element144 IS NULL) THEN 
             fullText:= ie_xnat_mrAssessorData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element144='xnat:qcAssessmentData') THEN
                fullText:= i_xnat_qcAssessmentData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_mrAssessorData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_mrassessordata_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:mrAssessorData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_mrAssessorData_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_mrassessordata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrqcscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:mrQcScanData)(';
      FOR current_row IN SELECT * FROM xnat_mrQcScanData WHERE  xnat_qcscandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_qcscandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_qcscandata_id:integer)=(' || current_row.xnat_qcscandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_qcScanData(current_row.xnat_qcscandata_id, child_count,$3,false,false);
              fullText := fullText || '(qcscandata_qcscandata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.blurring IS NOT NULL) THEN 
              fullText := fullText || '(blurring:string)=(' || REPLACE(REPLACE(current_row.blurring,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.flow IS NOT NULL) THEN 
              fullText := fullText || '(flow:string)=(' || REPLACE(REPLACE(current_row.flow,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.imagecontrast IS NOT NULL) THEN 
              fullText := fullText || '(imagecontrast:string)=(' || REPLACE(REPLACE(current_row.imagecontrast,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.inhomogeneity IS NOT NULL) THEN 
              fullText := fullText || '(inhomogeneity:string)=(' || REPLACE(REPLACE(current_row.inhomogeneity,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.wrap IS NOT NULL) THEN 
              fullText := fullText || '(wrap:string)=(' || REPLACE(REPLACE(current_row.wrap,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.susceptibility IS NOT NULL) THEN 
              fullText := fullText || '(susceptibility:string)=(' || REPLACE(REPLACE(current_row.susceptibility,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.interpacmotion IS NOT NULL) THEN 
              fullText := fullText || '(interpacmotion:string)=(' || REPLACE(REPLACE(current_row.interpacmotion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.mrQcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrqcscandata_info:integer)=(' || current_row.mrqcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrQcScanData_meta_data(current_row.mrQcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mrqcscandata_info_mrqcscandata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_qcScanData( $1, child_count,$3,$4,false);
              fullText := fullText || '(qcscandata_qcscandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_mrqcscandata_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:mrQcScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_mrQcScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_qcscandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_qcscandata_id:integer)=(' || current_row.xnat_qcscandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_qcScanData_history WHERE xnat_qcscandata_id=current_row.xnat_qcscandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_qcScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(qcscandata_qcscandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.blurring IS NOT NULL) THEN 
              fullText := fullText || '(blurring:string)=(' || REPLACE(REPLACE(current_row.blurring,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.flow IS NOT NULL) THEN 
              fullText := fullText || '(flow:string)=(' || REPLACE(REPLACE(current_row.flow,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.imagecontrast IS NOT NULL) THEN 
              fullText := fullText || '(imagecontrast:string)=(' || REPLACE(REPLACE(current_row.imagecontrast,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.inhomogeneity IS NOT NULL) THEN 
              fullText := fullText || '(inhomogeneity:string)=(' || REPLACE(REPLACE(current_row.inhomogeneity,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.wrap IS NOT NULL) THEN 
              fullText := fullText || '(wrap:string)=(' || REPLACE(REPLACE(current_row.wrap,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.susceptibility IS NOT NULL) THEN 
              fullText := fullText || '(susceptibility:string)=(' || REPLACE(REPLACE(current_row.susceptibility,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.interpacmotion IS NOT NULL) THEN 
              fullText := fullText || '(interpacmotion:string)=(' || REPLACE(REPLACE(current_row.interpacmotion,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.mrQcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrqcscandata_info:integer)=(' || current_row.mrqcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrQcScanData_meta_data(current_row.mrQcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mrqcscandata_info_mrqcscandata_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_qcScanData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(qcscandata_qcscandata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_mrqcscandata_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:mrQcScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_mrQcScanData_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_mrqcscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:mrScanData)(';
      FOR current_row IN SELECT * FROM xnat_mrScanData 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.coil IS NOT NULL) THEN 
              fullText := fullText || '(coil:string)=(' || REPLACE(REPLACE(current_row.coil,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.fieldstrength IS NOT NULL) THEN 
              fullText := fullText || '(fieldstrength:string)=(' || REPLACE(REPLACE(current_row.fieldstrength,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.marker IS NOT NULL) THEN 
              fullText := fullText || '(marker:string)=(' || REPLACE(REPLACE(current_row.marker,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.stabilization IS NOT NULL) THEN 
              fullText := fullText || '(stabilization:string)=(' || REPLACE(REPLACE(current_row.stabilization,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.filenameuuid IS NOT NULL) THEN 
              fullText := fullText || '(filenameuuid:string)=(' || REPLACE(REPLACE(current_row.filenameuuid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_units:string)=(' || REPLACE(REPLACE(current_row.parameters_voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_x:float)=(' || current_row.parameters_voxelres_x || ')';
          END IF;
          IF (current_row.parameters_voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_y:float)=(' || current_row.parameters_voxelres_y || ')';
          END IF;
          IF (current_row.parameters_voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_z:float)=(' || current_row.parameters_voxelres_z || ')';
          END IF;
          IF (current_row.parameters_orientation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_orientation:string)=(' || REPLACE(REPLACE(current_row.parameters_orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_subjectposition IS NOT NULL) THEN 
              fullText := fullText || '(parameters_subjectposition:string)=(' || REPLACE(REPLACE(current_row.parameters_subjectposition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_fov_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_x:integer)=(' || current_row.parameters_fov_x || ')';
          END IF;
          IF (current_row.parameters_fov_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_y:integer)=(' || current_row.parameters_fov_y || ')';
          END IF;
          IF (current_row.parameters_matrix_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_matrix_x:integer)=(' || current_row.parameters_matrix_x || ')';
          END IF;
          IF (current_row.parameters_matrix_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_matrix_y:integer)=(' || current_row.parameters_matrix_y || ')';
          END IF;
          IF (current_row.parameters_partitions IS NOT NULL) THEN 
              fullText := fullText || '(parameters_partitions:integer)=(' || current_row.parameters_partitions || ')';
          END IF;
          IF (current_row.parameters_tr IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tr:float)=(' || current_row.parameters_tr || ')';
          END IF;
          IF (current_row.parameters_te IS NOT NULL) THEN 
              fullText := fullText || '(parameters_te:float)=(' || current_row.parameters_te || ')';
          END IF;
          IF (current_row.parameters_deltate IS NOT NULL) THEN 
              fullText := fullText || '(parameters_deltate:float)=(' || current_row.parameters_deltate || ')';
          END IF;
          IF (current_row.parameters_ti IS NOT NULL) THEN 
              fullText := fullText || '(parameters_ti:float)=(' || current_row.parameters_ti || ')';
          END IF;
          IF (current_row.parameters_flip IS NOT NULL) THEN 
              fullText := fullText || '(parameters_flip:integer)=(' || current_row.parameters_flip || ')';
          END IF;
          IF (current_row.parameters_sequence IS NOT NULL) THEN 
              fullText := fullText || '(parameters_sequence:string)=(' || REPLACE(REPLACE(current_row.parameters_sequence,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_origin IS NOT NULL) THEN 
              fullText := fullText || '(parameters_origin:string)=(' || REPLACE(REPLACE(current_row.parameters_origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_imagetype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_imagetype:string)=(' || REPLACE(REPLACE(current_row.parameters_imagetype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_scansequence IS NOT NULL) THEN 
              fullText := fullText || '(parameters_scansequence:string)=(' || REPLACE(REPLACE(current_row.parameters_scansequence,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_seqvariant IS NOT NULL) THEN 
              fullText := fullText || '(parameters_seqvariant:string)=(' || REPLACE(REPLACE(current_row.parameters_seqvariant,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_scanoptions IS NOT NULL) THEN 
              fullText := fullText || '(parameters_scanoptions:string)=(' || REPLACE(REPLACE(current_row.parameters_scanoptions,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_acqtype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acqtype:string)=(' || REPLACE(REPLACE(current_row.parameters_acqtype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_readoutsamplespacing IS NOT NULL) THEN 
              fullText := fullText || '(parameters_readoutsamplespacing:string)=(' || REPLACE(REPLACE(current_row.parameters_readoutsamplespacing,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_coil IS NOT NULL) THEN 
              fullText := fullText || '(parameters_coil:string)=(' || REPLACE(REPLACE(current_row.parameters_coil,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_coilelements IS NOT NULL) THEN 
              fullText := fullText || '(parameters_coilelements:string)=(' || REPLACE(REPLACE(current_row.parameters_coilelements,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_dtiacqcount IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dtiacqcount:integer)=(' || current_row.parameters_dtiacqcount || ')';
          END IF;
          IF (current_row.parameters_pixelbandwidth IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelbandwidth:float)=(' || current_row.parameters_pixelbandwidth || ')';
          END IF;
          IF (current_row.parameters_echospacing IS NOT NULL) THEN 
              fullText := fullText || '(parameters_echospacing:float)=(' || current_row.parameters_echospacing || ')';
          END IF;
          IF (current_row.parameters_phaseencodingdirection IS NOT NULL) THEN 
              fullText := fullText || '(parameters_phaseencodingdirection:string)=(' || REPLACE(REPLACE(current_row.parameters_phaseencodingdirection,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_acqtime IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acqtime:string)=(' || REPLACE(REPLACE(current_row.parameters_acqtime,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_bvalues IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_bvalues:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_bvalues,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_bmax IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_bmax:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_bmax,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_directionality IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_directionality:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_directionality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_orientations IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_orientations:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_orientations,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_anisotropytype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_anisotropytype:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_anisotropytype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_refocusflipangle IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_refocusflipangle:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_refocusflipangle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField WHERE parameters_addparam_xnat_mrScan_xnat_imagescandata_id=current_row.xnat_imagescandata_id ORDER BY xnat_addfield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_addField( parent_row.xnat_addfield_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_addparam_addfield' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.parameters_inplanephaseencoding_direction IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_direction:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_direction,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_inplanephaseencoding_rotation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_rotation:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_rotation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_inplanephaseencoding_polarityswap IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_polarityswap:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_polarityswap,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_inplanephaseencoding_directionpositive IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_directionpositive:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_directionpositive,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_pmc IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pmc:string)=(' || REPLACE(REPLACE(current_row.parameters_pmc,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmvalidation IS NOT NULL) THEN 
              fullText := fullText || '(dcmvalidation:string)=(' || REPLACE(REPLACE(current_row.dcmvalidation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmvalidation_status IS NOT NULL) THEN 
              fullText := fullText || '(dcmvalidation_status:integer)=(' || current_row.dcmvalidation_status || ')';
          END IF;
        IF ((current_row.mrScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrscandata_info:integer)=(' || current_row.mrscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrScanData_meta_data(current_row.mrScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mrscandata_info_mrscandata_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_mrscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrscandata_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:mrScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_mrScanData_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.coil IS NOT NULL) THEN 
              fullText := fullText || '(coil:string)=(' || REPLACE(REPLACE(current_row.coil,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.fieldstrength IS NOT NULL) THEN 
              fullText := fullText || '(fieldstrength:string)=(' || REPLACE(REPLACE(current_row.fieldstrength,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.marker IS NOT NULL) THEN 
              fullText := fullText || '(marker:string)=(' || REPLACE(REPLACE(current_row.marker,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.stabilization IS NOT NULL) THEN 
              fullText := fullText || '(stabilization:string)=(' || REPLACE(REPLACE(current_row.stabilization,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.filenameuuid IS NOT NULL) THEN 
              fullText := fullText || '(filenameuuid:string)=(' || REPLACE(REPLACE(current_row.filenameuuid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_units:string)=(' || REPLACE(REPLACE(current_row.parameters_voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_x:float)=(' || current_row.parameters_voxelres_x || ')';
          END IF;
          IF (current_row.parameters_voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_y:float)=(' || current_row.parameters_voxelres_y || ')';
          END IF;
          IF (current_row.parameters_voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_voxelres_z:float)=(' || current_row.parameters_voxelres_z || ')';
          END IF;
          IF (current_row.parameters_orientation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_orientation:string)=(' || REPLACE(REPLACE(current_row.parameters_orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_subjectposition IS NOT NULL) THEN 
              fullText := fullText || '(parameters_subjectposition:string)=(' || REPLACE(REPLACE(current_row.parameters_subjectposition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_fov_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_x:integer)=(' || current_row.parameters_fov_x || ')';
          END IF;
          IF (current_row.parameters_fov_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_y:integer)=(' || current_row.parameters_fov_y || ')';
          END IF;
          IF (current_row.parameters_matrix_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_matrix_x:integer)=(' || current_row.parameters_matrix_x || ')';
          END IF;
          IF (current_row.parameters_matrix_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_matrix_y:integer)=(' || current_row.parameters_matrix_y || ')';
          END IF;
          IF (current_row.parameters_partitions IS NOT NULL) THEN 
              fullText := fullText || '(parameters_partitions:integer)=(' || current_row.parameters_partitions || ')';
          END IF;
          IF (current_row.parameters_tr IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tr:float)=(' || current_row.parameters_tr || ')';
          END IF;
          IF (current_row.parameters_te IS NOT NULL) THEN 
              fullText := fullText || '(parameters_te:float)=(' || current_row.parameters_te || ')';
          END IF;
          IF (current_row.parameters_deltate IS NOT NULL) THEN 
              fullText := fullText || '(parameters_deltate:float)=(' || current_row.parameters_deltate || ')';
          END IF;
          IF (current_row.parameters_ti IS NOT NULL) THEN 
              fullText := fullText || '(parameters_ti:float)=(' || current_row.parameters_ti || ')';
          END IF;
          IF (current_row.parameters_flip IS NOT NULL) THEN 
              fullText := fullText || '(parameters_flip:integer)=(' || current_row.parameters_flip || ')';
          END IF;
          IF (current_row.parameters_sequence IS NOT NULL) THEN 
              fullText := fullText || '(parameters_sequence:string)=(' || REPLACE(REPLACE(current_row.parameters_sequence,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_origin IS NOT NULL) THEN 
              fullText := fullText || '(parameters_origin:string)=(' || REPLACE(REPLACE(current_row.parameters_origin,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_imagetype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_imagetype:string)=(' || REPLACE(REPLACE(current_row.parameters_imagetype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_scansequence IS NOT NULL) THEN 
              fullText := fullText || '(parameters_scansequence:string)=(' || REPLACE(REPLACE(current_row.parameters_scansequence,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_seqvariant IS NOT NULL) THEN 
              fullText := fullText || '(parameters_seqvariant:string)=(' || REPLACE(REPLACE(current_row.parameters_seqvariant,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_scanoptions IS NOT NULL) THEN 
              fullText := fullText || '(parameters_scanoptions:string)=(' || REPLACE(REPLACE(current_row.parameters_scanoptions,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_acqtype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acqtype:string)=(' || REPLACE(REPLACE(current_row.parameters_acqtype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_readoutsamplespacing IS NOT NULL) THEN 
              fullText := fullText || '(parameters_readoutsamplespacing:string)=(' || REPLACE(REPLACE(current_row.parameters_readoutsamplespacing,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_coil IS NOT NULL) THEN 
              fullText := fullText || '(parameters_coil:string)=(' || REPLACE(REPLACE(current_row.parameters_coil,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_coilelements IS NOT NULL) THEN 
              fullText := fullText || '(parameters_coilelements:string)=(' || REPLACE(REPLACE(current_row.parameters_coilelements,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_dtiacqcount IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dtiacqcount:integer)=(' || current_row.parameters_dtiacqcount || ')';
          END IF;
          IF (current_row.parameters_pixelbandwidth IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelbandwidth:float)=(' || current_row.parameters_pixelbandwidth || ')';
          END IF;
          IF (current_row.parameters_echospacing IS NOT NULL) THEN 
              fullText := fullText || '(parameters_echospacing:float)=(' || current_row.parameters_echospacing || ')';
          END IF;
          IF (current_row.parameters_phaseencodingdirection IS NOT NULL) THEN 
              fullText := fullText || '(parameters_phaseencodingdirection:string)=(' || REPLACE(REPLACE(current_row.parameters_phaseencodingdirection,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_acqtime IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acqtime:string)=(' || REPLACE(REPLACE(current_row.parameters_acqtime,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_bvalues IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_bvalues:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_bvalues,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_bmax IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_bmax:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_bmax,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_directionality IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_directionality:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_directionality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_orientations IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_orientations:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_orientations,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_anisotropytype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_anisotropytype:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_anisotropytype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_diffusion_refocusflipangle IS NOT NULL) THEN 
              fullText := fullText || '(parameters_diffusion_refocusflipangle:string)=(' || REPLACE(REPLACE(current_row.parameters_diffusion_refocusflipangle,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField_history WHERE parameters_addparam_xnat_mrScan_xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version ORDER BY xnat_addfield_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_addField_history( parent_row.xnat_addfield_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_addparam_addfield' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.parameters_inplanephaseencoding_direction IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_direction:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_direction,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_inplanephaseencoding_rotation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_rotation:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_rotation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_inplanephaseencoding_polarityswap IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_polarityswap:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_polarityswap,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_inplanephaseencoding_directionpositive IS NOT NULL) THEN 
              fullText := fullText || '(parameters_inplanephaseencoding_directionpositive:string)=(' || REPLACE(REPLACE(current_row.parameters_inplanephaseencoding_directionpositive,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_pmc IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pmc:string)=(' || REPLACE(REPLACE(current_row.parameters_pmc,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmvalidation IS NOT NULL) THEN 
              fullText := fullText || '(dcmvalidation:string)=(' || REPLACE(REPLACE(current_row.dcmvalidation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.dcmvalidation_status IS NOT NULL) THEN 
              fullText := fullText || '(dcmvalidation_status:integer)=(' || current_row.dcmvalidation_status || ')';
          END IF;
        IF ((current_row.mrScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrscandata_info:integer)=(' || current_row.mrscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrScanData_meta_data(current_row.mrScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mrscandata_info_mrscandata_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_mrscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrscandata_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:mrScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_mrScanData_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_mrscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrsessiondata(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:mrSessionData)(';
      FOR current_row IN SELECT * FROM xnat_mrSessionData 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.coil IS NOT NULL) THEN 
              fullText := fullText || '(coil:string)=(' || REPLACE(REPLACE(current_row.coil,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.fieldstrength IS NOT NULL) THEN 
              fullText := fullText || '(fieldstrength:string)=(' || REPLACE(REPLACE(current_row.fieldstrength,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.marker IS NOT NULL) THEN 
              fullText := fullText || '(marker:string)=(' || REPLACE(REPLACE(current_row.marker,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.stabilization IS NOT NULL) THEN 
              fullText := fullText || '(stabilization:string)=(' || REPLACE(REPLACE(current_row.stabilization,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.mrSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrsessiondata_info:integer)=(' || current_row.mrsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrSessionData_meta_data(current_row.mrSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(mrsessiondata_info_mrsessiondata_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_mrsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrsessiondata_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:mrSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_mrSessionData_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.coil IS NOT NULL) THEN 
              fullText := fullText || '(coil:string)=(' || REPLACE(REPLACE(current_row.coil,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.fieldstrength IS NOT NULL) THEN 
              fullText := fullText || '(fieldstrength:string)=(' || REPLACE(REPLACE(current_row.fieldstrength,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.marker IS NOT NULL) THEN 
              fullText := fullText || '(marker:string)=(' || REPLACE(REPLACE(current_row.marker,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.stabilization IS NOT NULL) THEN 
              fullText := fullText || '(stabilization:string)=(' || REPLACE(REPLACE(current_row.stabilization,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.mrSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrsessiondata_info:integer)=(' || current_row.mrsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrSessionData_meta_data(current_row.mrSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(mrsessiondata_info_mrsessiondata_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_mrsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrsessiondata_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:mrSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_mrSessionData_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_mrsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrsscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:mrsScanData)(';
      FOR current_row IN SELECT * FROM xnat_mrsScanData 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.mrsScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrsscandata_info:integer)=(' || current_row.mrsscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrsScanData_meta_data(current_row.mrsScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mrsscandata_info_mrsscandata_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_mrsscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrsscandata_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:mrsScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_mrsScanData_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.mrsScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(mrsscandata_info:integer)=(' || current_row.mrsscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_mrsScanData_meta_data(current_row.mrsScanData_info, child_count,$3,false,false);
              fullText := fullText || '(mrsscandata_info_mrsscandata_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_mrsscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_mrsscandata_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:mrsScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_mrsScanData_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_mrsscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_nmscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:nmScanData)(';
      FOR current_row IN SELECT * FROM xnat_nmScanData 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.nmScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(nmscandata_info:integer)=(' || current_row.nmscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_nmScanData_meta_data(current_row.nmScanData_info, child_count,$3,false,false);
              fullText := fullText || '(nmscandata_info_nmscandata_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_nmscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_nmscandata_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:nmScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_nmScanData_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.nmScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(nmscandata_info:integer)=(' || current_row.nmscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_nmScanData_meta_data(current_row.nmScanData_info, child_count,$3,false,false);
              fullText := fullText || '(nmscandata_info_nmscandata_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_nmscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_nmscandata_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:nmScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_nmScanData_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_nmscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_nmsessiondata(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:nmSessionData)(';
      FOR current_row IN SELECT * FROM xnat_nmSessionData 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.nmSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(nmsessiondata_info:integer)=(' || current_row.nmsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_nmSessionData_meta_data(current_row.nmSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(nmsessiondata_info_nmsessiondata_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_nmsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_nmsessiondata_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:nmSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_nmSessionData_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.nmSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(nmsessiondata_info:integer)=(' || current_row.nmsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_nmSessionData_meta_data(current_row.nmSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(nmsessiondata_info_nmsessiondata_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_nmsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_nmsessiondata_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:nmSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_nmSessionData_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_nmsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
