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

CREATE FUNCTION public.i_xnat_opscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:opScanData)(';
      FOR current_row IN SELECT * FROM xnat_opScanData 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.opScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(opscandata_info:integer)=(' || current_row.opscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_opScanData_meta_data(current_row.opScanData_info, child_count,$3,false,false);
              fullText := fullText || '(opscandata_info_opscandata_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_opscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_opscandata_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:opScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_opScanData_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.opScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(opscandata_info:integer)=(' || current_row.opscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_opScanData_meta_data(current_row.opScanData_info, child_count,$3,false,false);
              fullText := fullText || '(opscandata_info_opscandata_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_opscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_opscandata_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:opScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_opScanData_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_opscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_opsessiondata(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:opSessionData)(';
      FOR current_row IN SELECT * FROM xnat_opSessionData 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.opSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(opsessiondata_info:integer)=(' || current_row.opsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_opSessionData_meta_data(current_row.opSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(opsessiondata_info_opsessiondata_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_opsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_opsessiondata_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:opSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_opSessionData_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.opSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(opsessiondata_info:integer)=(' || current_row.opsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_opSessionData_meta_data(current_row.opSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(opsessiondata_info_opsessiondata_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_opsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_opsessiondata_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:opSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_opSessionData_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_opsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_optscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:optScanData)(';
      FOR current_row IN SELECT * FROM xnat_optScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.parameters_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_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_laterality IS NOT NULL) THEN 
              fullText := fullText || '(parameters_laterality:string)=(' || REPLACE(REPLACE(current_row.parameters_laterality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_illumination_wavelength IS NOT NULL) THEN 
              fullText := fullText || '(parameters_illumination_wavelength:string)=(' || REPLACE(REPLACE(current_row.parameters_illumination_wavelength,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_illumination_power IS NOT NULL) THEN 
              fullText := fullText || '(parameters_illumination_power:string)=(' || REPLACE(REPLACE(current_row.parameters_illumination_power,'(','*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.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.optScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(optscandata_info:integer)=(' || current_row.optscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_optScanData_meta_data(current_row.optScanData_info, child_count,$3,false,false);
              fullText := fullText || '(optscandata_info_optscandata_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_optscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_optscandata_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:optScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_optScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.parameters_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_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_laterality IS NOT NULL) THEN 
              fullText := fullText || '(parameters_laterality:string)=(' || REPLACE(REPLACE(current_row.parameters_laterality,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_illumination_wavelength IS NOT NULL) THEN 
              fullText := fullText || '(parameters_illumination_wavelength:string)=(' || REPLACE(REPLACE(current_row.parameters_illumination_wavelength,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_illumination_power IS NOT NULL) THEN 
              fullText := fullText || '(parameters_illumination_power:string)=(' || REPLACE(REPLACE(current_row.parameters_illumination_power,'(','*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.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.optScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(optscandata_info:integer)=(' || current_row.optscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_optScanData_meta_data(current_row.optScanData_info, child_count,$3,false,false);
              fullText := fullText || '(optscandata_info_optscandata_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_optscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_optscandata_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:optScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_optScanData_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_optscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_optsessiondata(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:optSessionData)(';
      FOR current_row IN SELECT * FROM xnat_optSessionData 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.optSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(optsessiondata_info:integer)=(' || current_row.optsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_optSessionData_meta_data(current_row.optSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(optsessiondata_info_optsessiondata_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_optsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_optsessiondata_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:optSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_optSessionData_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.optSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(optsessiondata_info:integer)=(' || current_row.optsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_optSessionData_meta_data(current_row.optSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(optsessiondata_info_optsessiondata_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_optsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_optsessiondata_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:optSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_optSessionData_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_optsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherdicomscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:otherDicomScanData)(';
      FOR current_row IN SELECT * FROM xnat_otherDicomScanData 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.otherDicomScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(otherdicomscandata_info:integer)=(' || current_row.otherdicomscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_otherDicomScanData_meta_data(current_row.otherDicomScanData_info, child_count,$3,false,false);
              fullText := fullText || '(otherdicomscandata_info_otherdicomscandata_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_otherdicomscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherdicomscandata_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:otherDicomScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_otherDicomScanData_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.otherDicomScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(otherdicomscandata_info:integer)=(' || current_row.otherdicomscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_otherDicomScanData_meta_data(current_row.otherDicomScanData_info, child_count,$3,false,false);
              fullText := fullText || '(otherdicomscandata_info_otherdicomscandata_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_otherdicomscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherdicomscandata_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:otherDicomScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_otherDicomScanData_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_otherdicomscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherdicomsessiondata(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:otherDicomSessionData)(';
      FOR current_row IN SELECT * FROM xnat_otherDicomSessionData 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.otherDicomSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(otherdicomsessiondata_info:integer)=(' || current_row.otherdicomsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_otherDicomSessionData_meta_data(current_row.otherDicomSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(otherdicomsessiondata_info_otherdicomsessiondata_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_otherdicomsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherdicomsessiondata_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:otherDicomSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_otherDicomSessionData_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.otherDicomSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(otherdicomsessiondata_info:integer)=(' || current_row.otherdicomsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_otherDicomSessionData_meta_data(current_row.otherDicomSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(otherdicomsessiondata_info_otherdicomsessiondata_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_otherdicomsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherdicomsessiondata_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:otherDicomSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_otherDicomSessionData_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_otherdicomsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherqcscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:otherQcScanData)(';
      FOR current_row IN SELECT * FROM xnat_otherQcScanData 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.other IS NOT NULL) THEN 
              fullText := fullText || '(other:string)=(' || REPLACE(REPLACE(current_row.other,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.otherQcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(otherqcscandata_info:integer)=(' || current_row.otherqcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_otherQcScanData_meta_data(current_row.otherQcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(otherqcscandata_info_otherqcscandata_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_otherqcscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherqcscandata_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:otherQcScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_otherQcScanData_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.other IS NOT NULL) THEN 
              fullText := fullText || '(other:string)=(' || REPLACE(REPLACE(current_row.other,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.otherQcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(otherqcscandata_info:integer)=(' || current_row.otherqcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_otherQcScanData_meta_data(current_row.otherQcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(otherqcscandata_info_otherqcscandata_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_otherqcscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_otherqcscandata_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:otherQcScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_otherQcScanData_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_otherqcscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petassessordata(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:petAssessorData)(';
      FOR current_row IN SELECT * FROM xnat_petAssessorData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.petAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(petassessordata_info:integer)=(' || current_row.petassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petAssessorData_meta_data(current_row.petAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(petassessordata_info_petassessordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_petassessordata_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:petAssessorData_history)(';
      FOR current_row IN SELECT * FROM xnat_petAssessorData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
        IF ((current_row.petAssessorData_info IS NOT NULL)) THEN
            fullText := fullText || '(petassessordata_info:integer)=(' || current_row.petassessordata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petAssessorData_meta_data(current_row.petAssessorData_info, child_count,$3,false,false);
              fullText := fullText || '(petassessordata_info_petassessordata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(imageassessordata_imageassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_petassessordata_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:petAssessorData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_petAssessorData_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_petassessordata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petmrsessiondata(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:petmrSessionData)(';
      FOR current_row IN SELECT * FROM xnat_petmrSessionData 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.studytype IS NOT NULL) THEN 
              fullText := fullText || '(studytype:string)=(' || REPLACE(REPLACE(current_row.studytype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientid IS NOT NULL) THEN 
              fullText := fullText || '(patientid:string)=(' || REPLACE(REPLACE(current_row.patientid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientname IS NOT NULL) THEN 
              fullText := fullText || '(patientname:string)=(' || REPLACE(REPLACE(current_row.patientname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose_units:string)=(' || REPLACE(REPLACE(current_row.tracer_dose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose:float)=(' || current_row.tracer_dose || ')';
          END IF;
          IF (current_row.tracer_specificactivity IS NOT NULL) THEN 
              fullText := fullText || '(tracer_specificactivity:float)=(' || current_row.tracer_specificactivity || ')';
          END IF;
          IF (current_row.tracer_totalmass_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass_units:string)=(' || REPLACE(REPLACE(current_row.tracer_totalmass_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_totalmass IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass:float)=(' || current_row.tracer_totalmass || ')';
          END IF;
          IF (current_row.tracer_intermediate_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate_units:string)=(' || REPLACE(REPLACE(current_row.tracer_intermediate_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_intermediate IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate:float)=(' || current_row.tracer_intermediate || ')';
          END IF;
          IF (current_row.tracer_isotope_half_life IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope_half_life:float)=(' || current_row.tracer_isotope_half_life || ')';
          END IF;
          IF (current_row.tracer_isotope IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope:string)=(' || REPLACE(REPLACE(current_row.tracer_isotope,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_transmissions IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions:integer)=(' || current_row.tracer_transmissions || ')';
          END IF;
          IF (current_row.tracer_transmissions_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions_starttime:dateTime)=(' || current_row.tracer_transmissions_starttime || ')';
          END IF;
          IF (current_row.tracer_name IS NOT NULL) THEN 
              fullText := fullText || '(tracer_name:string)=(' || REPLACE(REPLACE(current_row.tracer_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_starttime:dateTime)=(' || current_row.tracer_starttime || ')';
          END IF;
          IF (current_row.start_time IS NOT NULL) THEN 
              fullText := fullText || '(start_time:dateTime)=(' || current_row.start_time || ')';
          END IF;
          IF (current_row.start_time_scan IS NOT NULL) THEN 
              fullText := fullText || '(start_time_scan:dateTime)=(' || current_row.start_time_scan || ')';
          END IF;
          IF (current_row.start_time_injection IS NOT NULL) THEN 
              fullText := fullText || '(start_time_injection:dateTime)=(' || current_row.start_time_injection || ')';
          END IF;
          IF (current_row.blood_glucose IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose:float)=(' || current_row.blood_glucose || ')';
          END IF;
          IF (current_row.blood_glucose_units IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_units:string)=(' || REPLACE(REPLACE(current_row.blood_glucose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.blood_glucose_time IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_time:dateTime)=(' || current_row.blood_glucose_time || ')';
          END IF;
        IF ((current_row.petmrSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(petmrsessiondata_info:integer)=(' || current_row.petmrsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petmrSessionData_meta_data(current_row.petmrSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(petmrsessiondata_info_petmrsessiondata_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_petmrsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petmrsessiondata_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:petmrSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_petmrSessionData_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.studytype IS NOT NULL) THEN 
              fullText := fullText || '(studytype:string)=(' || REPLACE(REPLACE(current_row.studytype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientid IS NOT NULL) THEN 
              fullText := fullText || '(patientid:string)=(' || REPLACE(REPLACE(current_row.patientid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientname IS NOT NULL) THEN 
              fullText := fullText || '(patientname:string)=(' || REPLACE(REPLACE(current_row.patientname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose_units:string)=(' || REPLACE(REPLACE(current_row.tracer_dose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose:float)=(' || current_row.tracer_dose || ')';
          END IF;
          IF (current_row.tracer_specificactivity IS NOT NULL) THEN 
              fullText := fullText || '(tracer_specificactivity:float)=(' || current_row.tracer_specificactivity || ')';
          END IF;
          IF (current_row.tracer_totalmass_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass_units:string)=(' || REPLACE(REPLACE(current_row.tracer_totalmass_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_totalmass IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass:float)=(' || current_row.tracer_totalmass || ')';
          END IF;
          IF (current_row.tracer_intermediate_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate_units:string)=(' || REPLACE(REPLACE(current_row.tracer_intermediate_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_intermediate IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate:float)=(' || current_row.tracer_intermediate || ')';
          END IF;
          IF (current_row.tracer_isotope_half_life IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope_half_life:float)=(' || current_row.tracer_isotope_half_life || ')';
          END IF;
          IF (current_row.tracer_isotope IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope:string)=(' || REPLACE(REPLACE(current_row.tracer_isotope,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_transmissions IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions:integer)=(' || current_row.tracer_transmissions || ')';
          END IF;
          IF (current_row.tracer_transmissions_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions_starttime:dateTime)=(' || current_row.tracer_transmissions_starttime || ')';
          END IF;
          IF (current_row.tracer_name IS NOT NULL) THEN 
              fullText := fullText || '(tracer_name:string)=(' || REPLACE(REPLACE(current_row.tracer_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_starttime:dateTime)=(' || current_row.tracer_starttime || ')';
          END IF;
          IF (current_row.start_time IS NOT NULL) THEN 
              fullText := fullText || '(start_time:dateTime)=(' || current_row.start_time || ')';
          END IF;
          IF (current_row.start_time_scan IS NOT NULL) THEN 
              fullText := fullText || '(start_time_scan:dateTime)=(' || current_row.start_time_scan || ')';
          END IF;
          IF (current_row.start_time_injection IS NOT NULL) THEN 
              fullText := fullText || '(start_time_injection:dateTime)=(' || current_row.start_time_injection || ')';
          END IF;
          IF (current_row.blood_glucose IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose:float)=(' || current_row.blood_glucose || ')';
          END IF;
          IF (current_row.blood_glucose_units IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_units:string)=(' || REPLACE(REPLACE(current_row.blood_glucose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.blood_glucose_time IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_time:dateTime)=(' || current_row.blood_glucose_time || ')';
          END IF;
        IF ((current_row.petmrSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(petmrsessiondata_info:integer)=(' || current_row.petmrsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petmrSessionData_meta_data(current_row.petmrSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(petmrsessiondata_info_petmrsessiondata_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_petmrsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petmrsessiondata_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:petmrSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_petmrSessionData_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_petmrsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petqcscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:petQcScanData)(';
      FOR current_row IN SELECT * FROM xnat_petQcScanData 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.acquisition IS NOT NULL) THEN 
              fullText := fullText || '(acquisition:string)=(' || REPLACE(REPLACE(current_row.acquisition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctreconstructionalgorithm IS NOT NULL) THEN 
              fullText := fullText || '(correctreconstructionalgorithm:string)=(' || REPLACE(REPLACE(current_row.correctreconstructionalgorithm,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.reconstructionalgorithmused IS NOT NULL) THEN 
              fullText := fullText || '(reconstructionalgorithmused:string)=(' || REPLACE(REPLACE(current_row.reconstructionalgorithmused,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctiterationsandsubsets IS NOT NULL) THEN 
              fullText := fullText || '(correctiterationsandsubsets:string)=(' || REPLACE(REPLACE(current_row.correctiterationsandsubsets,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctfilters IS NOT NULL) THEN 
              fullText := fullText || '(correctfilters:string)=(' || REPLACE(REPLACE(current_row.correctfilters,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctslicethickness IS NOT NULL) THEN 
              fullText := fullText || '(correctslicethickness:string)=(' || REPLACE(REPLACE(current_row.correctslicethickness,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.acceptablevoxelsize IS NOT NULL) THEN 
              fullText := fullText || '(acceptablevoxelsize:string)=(' || REPLACE(REPLACE(current_row.acceptablevoxelsize,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.unacceptableframes IS NOT NULL) THEN 
              fullText := fullText || '(unacceptableframes:string)=(' || REPLACE(REPLACE(current_row.unacceptableframes,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.reasonframesunacceptable IS NOT NULL) THEN 
              fullText := fullText || '(reasonframesunacceptable:string)=(' || REPLACE(REPLACE(current_row.reasonframesunacceptable,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_petQcScanData_processingError WHERE processingerrors_processingerro_xnat_qcscandata_id=current_row.xnat_qcscandata_id ORDER BY xnat_petqcscandata_processingerror_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petQcScanData_processingError( parent_row.xnat_petqcscandata_processingerror_id, child_count,$3,false,false);
              fullText := fullText || '(processingerrors_processingerror_petqcscandata_processingerror' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.qcoutcome IS NOT NULL) THEN 
              fullText := fullText || '(qcoutcome:string)=(' || REPLACE(REPLACE(current_row.qcoutcome,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.qcoutcomereason IS NOT NULL) THEN 
              fullText := fullText || '(qcoutcomereason:string)=(' || REPLACE(REPLACE(current_row.qcoutcomereason,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.topcutoff IS NOT NULL) THEN 
              fullText := fullText || '(topcutoff:string)=(' || REPLACE(REPLACE(current_row.topcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.bottomcutoff IS NOT NULL) THEN 
              fullText := fullText || '(bottomcutoff:string)=(' || REPLACE(REPLACE(current_row.bottomcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.petQcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(petqcscandata_info:integer)=(' || current_row.petqcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petQcScanData_meta_data(current_row.petQcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(petqcscandata_info_petqcscandata_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_petqcscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petqcscandata_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:petQcScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_petQcScanData_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.acquisition IS NOT NULL) THEN 
              fullText := fullText || '(acquisition:string)=(' || REPLACE(REPLACE(current_row.acquisition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctreconstructionalgorithm IS NOT NULL) THEN 
              fullText := fullText || '(correctreconstructionalgorithm:string)=(' || REPLACE(REPLACE(current_row.correctreconstructionalgorithm,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.reconstructionalgorithmused IS NOT NULL) THEN 
              fullText := fullText || '(reconstructionalgorithmused:string)=(' || REPLACE(REPLACE(current_row.reconstructionalgorithmused,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctiterationsandsubsets IS NOT NULL) THEN 
              fullText := fullText || '(correctiterationsandsubsets:string)=(' || REPLACE(REPLACE(current_row.correctiterationsandsubsets,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctfilters IS NOT NULL) THEN 
              fullText := fullText || '(correctfilters:string)=(' || REPLACE(REPLACE(current_row.correctfilters,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.correctslicethickness IS NOT NULL) THEN 
              fullText := fullText || '(correctslicethickness:string)=(' || REPLACE(REPLACE(current_row.correctslicethickness,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.acceptablevoxelsize IS NOT NULL) THEN 
              fullText := fullText || '(acceptablevoxelsize:string)=(' || REPLACE(REPLACE(current_row.acceptablevoxelsize,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.unacceptableframes IS NOT NULL) THEN 
              fullText := fullText || '(unacceptableframes:string)=(' || REPLACE(REPLACE(current_row.unacceptableframes,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.reasonframesunacceptable IS NOT NULL) THEN 
              fullText := fullText || '(reasonframesunacceptable:string)=(' || REPLACE(REPLACE(current_row.reasonframesunacceptable,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_petQcScanData_processingError_history WHERE processingerrors_processingerro_xnat_qcscandata_id=current_row.xnat_qcscandata_id AND xft_version=current_row.xft_version ORDER BY xnat_petqcscandata_processingerror_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petQcScanData_processingError_history( parent_row.xnat_petqcscandata_processingerror_id, child_count,$3,false,false);
              fullText := fullText || '(processingerrors_processingerror_petqcscandata_processingerror' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.qcoutcome IS NOT NULL) THEN 
              fullText := fullText || '(qcoutcome:string)=(' || REPLACE(REPLACE(current_row.qcoutcome,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.qcoutcomereason IS NOT NULL) THEN 
              fullText := fullText || '(qcoutcomereason:string)=(' || REPLACE(REPLACE(current_row.qcoutcomereason,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.topcutoff IS NOT NULL) THEN 
              fullText := fullText || '(topcutoff:string)=(' || REPLACE(REPLACE(current_row.topcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.bottomcutoff IS NOT NULL) THEN 
              fullText := fullText || '(bottomcutoff:string)=(' || REPLACE(REPLACE(current_row.bottomcutoff,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.petQcScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(petqcscandata_info:integer)=(' || current_row.petqcscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petQcScanData_meta_data(current_row.petQcScanData_info, child_count,$3,false,false);
              fullText := fullText || '(petqcscandata_info_petqcscandata_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_petqcscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petqcscandata_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:petQcScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_petQcScanData_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_petqcscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petqcscandata_processingerror(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:petQcScanData_processingError)(';
      FOR current_row IN SELECT * FROM xnat_petQcScanData_processingError WHERE  xnat_petqcscandata_processingerror_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.processingerror IS NOT NULL) THEN 
              fullText := fullText || '(processingerror:string)=(' || REPLACE(REPLACE(current_row.processingerror,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.petQcScanData_processingError_info IS NOT NULL)) THEN
            fullText := fullText || '(petqcscandata_processingerror_info:integer)=(' || current_row.petqcscandata_processingerror_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petQcScanData_processingError_meta_data(current_row.petQcScanData_processingError_info, child_count,$3,false,false);
              fullText := fullText || '(petqcscandata_processingerror_info_petqcscandata_processingerror_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.processingerrors_processingerro_xnat_qcscandata_id IS NOT NULL)) THEN
            fullText := fullText || '(processingerrors_processingerro_xnat_qcscandata_id:integer)=(' || current_row.processingerrors_processingerro_xnat_qcscandata_id || ')';
        END IF;
          IF (current_row.xnat_petqcscandata_processingerror_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_petqcscandata_processingerror_id:integer)=(' || current_row.xnat_petqcscandata_processingerror_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_petqcscandata_processingerror_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:petQcScanData_processingError_history)(';
      FOR current_row IN SELECT * FROM xnat_petQcScanData_processingError_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.processingerror IS NOT NULL) THEN 
              fullText := fullText || '(processingerror:string)=(' || REPLACE(REPLACE(current_row.processingerror,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.petQcScanData_processingError_info IS NOT NULL)) THEN
            fullText := fullText || '(petqcscandata_processingerror_info:integer)=(' || current_row.petqcscandata_processingerror_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petQcScanData_processingError_meta_data(current_row.petQcScanData_processingError_info, child_count,$3,false,false);
              fullText := fullText || '(petqcscandata_processingerror_info_petqcscandata_processingerror_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.processingerrors_processingerro_xnat_qcscandata_id IS NOT NULL)) THEN
            fullText := fullText || '(processingerrors_processingerro_xnat_qcscandata_id:integer)=(' || current_row.processingerrors_processingerro_xnat_qcscandata_id || ')';
        END IF;
          IF (current_row.xnat_petqcscandata_processingerror_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_petqcscandata_processingerror_id:integer)=(' || current_row.xnat_petqcscandata_processingerror_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_petqcscandata_processingerror_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petqcscandata_processingerror_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:petQcScanData_processingError_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_petQcScanData_processingError_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_petqcscandata_processingerror_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:petScanData)(';
      FOR current_row IN SELECT * FROM xnat_petScanData WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_imageScanData(current_row.xnat_imagescandata_id, child_count,$3,false,false);
              fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.parameters_orientation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_orientation:integer)=(' || current_row.parameters_orientation || ')';
          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_petSca_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_originalfilename IS NOT NULL) THEN 
              fullText := fullText || '(parameters_originalfilename:string)=(' || REPLACE(REPLACE(current_row.parameters_originalfilename,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_systemtype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_systemtype:integer)=(' || current_row.parameters_systemtype || ')';
          END IF;
          IF (current_row.parameters_filetype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filetype:integer)=(' || current_row.parameters_filetype || ')';
          END IF;
          IF (current_row.parameters_transaxialfov IS NOT NULL) THEN 
              fullText := fullText || '(parameters_transaxialfov:float)=(' || current_row.parameters_transaxialfov || ')';
          END IF;
          IF (current_row.parameters_acqtype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acqtype:integer)=(' || current_row.parameters_acqtype || ')';
          END IF;
          IF (current_row.parameters_facility IS NOT NULL) THEN 
              fullText := fullText || '(parameters_facility:string)=(' || REPLACE(REPLACE(current_row.parameters_facility,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_numplanes IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numplanes:integer)=(' || current_row.parameters_numplanes || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_petScanData_frame WHERE parameters_frames_frame_xnat_pe_xnat_imagescandata_id=current_row.xnat_imagescandata_id ORDER BY xnat_petscandata_frame_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petScanData_frame( parent_row.xnat_petscandata_frame_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_frames_frame_petscandata_frame' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.parameters_frames_numframes IS NOT NULL) THEN 
              fullText := fullText || '(parameters_frames_numframes:integer)=(' || current_row.parameters_frames_numframes || ')';
          END IF;
          IF (current_row.parameters_numgates IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numgates:integer)=(' || current_row.parameters_numgates || ')';
          END IF;
          IF (current_row.parameters_planeseparation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_planeseparation:float)=(' || current_row.parameters_planeseparation || ')';
          END IF;
          IF (current_row.parameters_binsize IS NOT NULL) THEN 
              fullText := fullText || '(parameters_binsize:float)=(' || current_row.parameters_binsize || ')';
          END IF;
          IF (current_row.parameters_datatype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_datatype:integer)=(' || current_row.parameters_datatype || ')';
          END IF;
          IF (current_row.parameters_dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_x:integer)=(' || current_row.parameters_dimensions_x || ')';
          END IF;
          IF (current_row.parameters_dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_y:integer)=(' || current_row.parameters_dimensions_y || ')';
          END IF;
          IF (current_row.parameters_dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_z:integer)=(' || current_row.parameters_dimensions_z || ')';
          END IF;
          IF (current_row.parameters_dimensions_num IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_num:integer)=(' || current_row.parameters_dimensions_num || ')';
          END IF;
          IF (current_row.parameters_offset_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_offset_x:float)=(' || current_row.parameters_offset_x || ')';
          END IF;
          IF (current_row.parameters_offset_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_offset_y:float)=(' || current_row.parameters_offset_y || ')';
          END IF;
          IF (current_row.parameters_offset_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_offset_z:float)=(' || current_row.parameters_offset_z || ')';
          END IF;
          IF (current_row.parameters_reconzoom IS NOT NULL) THEN 
              fullText := fullText || '(parameters_reconzoom:float)=(' || current_row.parameters_reconzoom || ')';
          END IF;
          IF (current_row.parameters_pixelsize_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelsize_x:float)=(' || current_row.parameters_pixelsize_x || ')';
          END IF;
          IF (current_row.parameters_pixelsize_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelsize_y:float)=(' || current_row.parameters_pixelsize_y || ')';
          END IF;
          IF (current_row.parameters_pixelsize_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelsize_z:float)=(' || current_row.parameters_pixelsize_z || ')';
          END IF;
          IF (current_row.parameters_filtercode IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filtercode:integer)=(' || current_row.parameters_filtercode || ')';
          END IF;
          IF (current_row.parameters_resolution_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_resolution_x:float)=(' || current_row.parameters_resolution_x || ')';
          END IF;
          IF (current_row.parameters_resolution_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_resolution_y:float)=(' || current_row.parameters_resolution_y || ')';
          END IF;
          IF (current_row.parameters_resolution_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_resolution_z:float)=(' || current_row.parameters_resolution_z || ')';
          END IF;
          IF (current_row.parameters_numrelements IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numrelements:float)=(' || current_row.parameters_numrelements || ')';
          END IF;
          IF (current_row.parameters_numangles IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numangles:float)=(' || current_row.parameters_numangles || ')';
          END IF;
          IF (current_row.parameters_zrotationangle IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zrotationangle:float)=(' || current_row.parameters_zrotationangle || ')';
          END IF;
          IF (current_row.parameters_processingcode IS NOT NULL) THEN 
              fullText := fullText || '(parameters_processingcode:integer)=(' || current_row.parameters_processingcode || ')';
          END IF;
          IF (current_row.parameters_gateduration IS NOT NULL) THEN 
              fullText := fullText || '(parameters_gateduration:integer)=(' || current_row.parameters_gateduration || ')';
          END IF;
          IF (current_row.parameters_rwaveoffset IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rwaveoffset:integer)=(' || current_row.parameters_rwaveoffset || ')';
          END IF;
          IF (current_row.parameters_numacceptedbeats IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numacceptedbeats:integer)=(' || current_row.parameters_numacceptedbeats || ')';
          END IF;
          IF (current_row.parameters_filter_cutoff IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filter_cutoff:float)=(' || current_row.parameters_filter_cutoff || ')';
          END IF;
          IF (current_row.parameters_annotation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_annotation:string)=(' || REPLACE(REPLACE(current_row.parameters_annotation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_mt_1_1 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_1:float)=(' || current_row.parameters_mt_1_1 || ')';
          END IF;
          IF (current_row.parameters_mt_1_2 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_2:float)=(' || current_row.parameters_mt_1_2 || ')';
          END IF;
          IF (current_row.parameters_mt_1_3 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_3:float)=(' || current_row.parameters_mt_1_3 || ')';
          END IF;
          IF (current_row.parameters_mt_1_4 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_4:float)=(' || current_row.parameters_mt_1_4 || ')';
          END IF;
          IF (current_row.parameters_mt_2_1 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_1:float)=(' || current_row.parameters_mt_2_1 || ')';
          END IF;
          IF (current_row.parameters_mt_2_2 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_2:float)=(' || current_row.parameters_mt_2_2 || ')';
          END IF;
          IF (current_row.parameters_mt_2_3 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_3:float)=(' || current_row.parameters_mt_2_3 || ')';
          END IF;
          IF (current_row.parameters_mt_2_4 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_4:float)=(' || current_row.parameters_mt_2_4 || ')';
          END IF;
          IF (current_row.parameters_mt_3_1 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_1:float)=(' || current_row.parameters_mt_3_1 || ')';
          END IF;
          IF (current_row.parameters_mt_3_2 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_2:float)=(' || current_row.parameters_mt_3_2 || ')';
          END IF;
          IF (current_row.parameters_mt_3_3 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_3:float)=(' || current_row.parameters_mt_3_3 || ')';
          END IF;
          IF (current_row.parameters_mt_3_4 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_4:float)=(' || current_row.parameters_mt_3_4 || ')';
          END IF;
          IF (current_row.parameters_rfilter_cutoff IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_cutoff:float)=(' || current_row.parameters_rfilter_cutoff || ')';
          END IF;
          IF (current_row.parameters_rfilter_resolution IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_resolution:float)=(' || current_row.parameters_rfilter_resolution || ')';
          END IF;
          IF (current_row.parameters_rfilter_code IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_code:integer)=(' || current_row.parameters_rfilter_code || ')';
          END IF;
          IF (current_row.parameters_rfilter_order IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_order:integer)=(' || current_row.parameters_rfilter_order || ')';
          END IF;
          IF (current_row.parameters_zfilter_cutoff IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_cutoff:float)=(' || current_row.parameters_zfilter_cutoff || ')';
          END IF;
          IF (current_row.parameters_zfilter_resolution IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_resolution:float)=(' || current_row.parameters_zfilter_resolution || ')';
          END IF;
          IF (current_row.parameters_zfilter_code IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_code:integer)=(' || current_row.parameters_zfilter_code || ')';
          END IF;
          IF (current_row.parameters_zfilter_order IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_order:integer)=(' || current_row.parameters_zfilter_order || ')';
          END IF;
          IF (current_row.parameters_scattertype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_scattertype:integer)=(' || current_row.parameters_scattertype || ')';
          END IF;
          IF (current_row.parameters_recontype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_recontype:integer)=(' || current_row.parameters_recontype || ')';
          END IF;
          IF (current_row.parameters_reconviews IS NOT NULL) THEN 
              fullText := fullText || '(parameters_reconviews:integer)=(' || current_row.parameters_reconviews || ')';
          END IF;
          IF (current_row.parameters_bedposition IS NOT NULL) THEN 
              fullText := fullText || '(parameters_bedposition:float)=(' || current_row.parameters_bedposition || ')';
          END IF;
          IF (current_row.parameters_ecatcalibrationfactor IS NOT NULL) THEN 
              fullText := fullText || '(parameters_ecatcalibrationfactor:float)=(' || current_row.parameters_ecatcalibrationfactor || ')';
          END IF;
          IF (current_row.ecatvalidation IS NOT NULL) THEN 
              fullText := fullText || '(ecatvalidation:string)=(' || REPLACE(REPLACE(current_row.ecatvalidation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ecatvalidation_status IS NOT NULL) THEN 
              fullText := fullText || '(ecatvalidation_status:integer)=(' || current_row.ecatvalidation_status || ')';
          END IF;
        IF ((current_row.petScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(petscandata_info:integer)=(' || current_row.petscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petScanData_meta_data(current_row.petScanData_info, child_count,$3,false,false);
              fullText := fullText || '(petscandata_info_petscandata_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_petscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petscandata_frame(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:petScanData_frame)(';
      FOR current_row IN SELECT * FROM xnat_petScanData_frame WHERE  xnat_petscandata_frame_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.number IS NOT NULL) THEN 
              fullText := fullText || '(number:integer)=(' || current_row.number || ')';
          END IF;
          IF (current_row.starttime IS NOT NULL) THEN 
              fullText := fullText || '(starttime:float)=(' || current_row.starttime || ')';
          END IF;
          IF (current_row.length IS NOT NULL) THEN 
              fullText := fullText || '(length:float)=(' || current_row.length || ')';
          END IF;
          IF (current_row.units IS NOT NULL) THEN 
              fullText := fullText || '(units:string)=(' || REPLACE(REPLACE(current_row.units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.petScanData_frame_info IS NOT NULL)) THEN
            fullText := fullText || '(petscandata_frame_info:integer)=(' || current_row.petscandata_frame_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petScanData_frame_meta_data(current_row.petScanData_frame_info, child_count,$3,false,false);
              fullText := fullText || '(petscandata_frame_info_petscandata_frame_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_frames_frame_xnat_pe_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_frames_frame_xnat_pe_xnat_imagescandata_id:integer)=(' || current_row.parameters_frames_frame_xnat_pe_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_petscandata_frame_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_petscandata_frame_id:integer)=(' || current_row.xnat_petscandata_frame_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_petscandata_frame_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:petScanData_frame_history)(';
      FOR current_row IN SELECT * FROM xnat_petScanData_frame_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.number IS NOT NULL) THEN 
              fullText := fullText || '(number:integer)=(' || current_row.number || ')';
          END IF;
          IF (current_row.starttime IS NOT NULL) THEN 
              fullText := fullText || '(starttime:float)=(' || current_row.starttime || ')';
          END IF;
          IF (current_row.length IS NOT NULL) THEN 
              fullText := fullText || '(length:float)=(' || current_row.length || ')';
          END IF;
          IF (current_row.units IS NOT NULL) THEN 
              fullText := fullText || '(units:string)=(' || REPLACE(REPLACE(current_row.units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.petScanData_frame_info IS NOT NULL)) THEN
            fullText := fullText || '(petscandata_frame_info:integer)=(' || current_row.petscandata_frame_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petScanData_frame_meta_data(current_row.petScanData_frame_info, child_count,$3,false,false);
              fullText := fullText || '(petscandata_frame_info_petscandata_frame_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_frames_frame_xnat_pe_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_frames_frame_xnat_pe_xnat_imagescandata_id:integer)=(' || current_row.parameters_frames_frame_xnat_pe_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_petscandata_frame_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_petscandata_frame_id:integer)=(' || current_row.xnat_petscandata_frame_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_petscandata_frame_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petscandata_frame_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:petScanData_frame_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_petScanData_frame_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_petscandata_frame_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petscandata_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:petScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_petScanData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_imagescandata_id:integer)=(' || current_row.xnat_imagescandata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_imageScanData_history WHERE xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_imageScanData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(imagescandata_imagescandata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.parameters_orientation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_orientation:integer)=(' || current_row.parameters_orientation || ')';
          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_petSca_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_originalfilename IS NOT NULL) THEN 
              fullText := fullText || '(parameters_originalfilename:string)=(' || REPLACE(REPLACE(current_row.parameters_originalfilename,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_systemtype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_systemtype:integer)=(' || current_row.parameters_systemtype || ')';
          END IF;
          IF (current_row.parameters_filetype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filetype:integer)=(' || current_row.parameters_filetype || ')';
          END IF;
          IF (current_row.parameters_transaxialfov IS NOT NULL) THEN 
              fullText := fullText || '(parameters_transaxialfov:float)=(' || current_row.parameters_transaxialfov || ')';
          END IF;
          IF (current_row.parameters_acqtype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acqtype:integer)=(' || current_row.parameters_acqtype || ')';
          END IF;
          IF (current_row.parameters_facility IS NOT NULL) THEN 
              fullText := fullText || '(parameters_facility:string)=(' || REPLACE(REPLACE(current_row.parameters_facility,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_numplanes IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numplanes:integer)=(' || current_row.parameters_numplanes || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_petScanData_frame_history WHERE parameters_frames_frame_xnat_pe_xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version ORDER BY xnat_petscandata_frame_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petScanData_frame_history( parent_row.xnat_petscandata_frame_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_frames_frame_petscandata_frame' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.parameters_frames_numframes IS NOT NULL) THEN 
              fullText := fullText || '(parameters_frames_numframes:integer)=(' || current_row.parameters_frames_numframes || ')';
          END IF;
          IF (current_row.parameters_numgates IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numgates:integer)=(' || current_row.parameters_numgates || ')';
          END IF;
          IF (current_row.parameters_planeseparation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_planeseparation:float)=(' || current_row.parameters_planeseparation || ')';
          END IF;
          IF (current_row.parameters_binsize IS NOT NULL) THEN 
              fullText := fullText || '(parameters_binsize:float)=(' || current_row.parameters_binsize || ')';
          END IF;
          IF (current_row.parameters_datatype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_datatype:integer)=(' || current_row.parameters_datatype || ')';
          END IF;
          IF (current_row.parameters_dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_x:integer)=(' || current_row.parameters_dimensions_x || ')';
          END IF;
          IF (current_row.parameters_dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_y:integer)=(' || current_row.parameters_dimensions_y || ')';
          END IF;
          IF (current_row.parameters_dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_z:integer)=(' || current_row.parameters_dimensions_z || ')';
          END IF;
          IF (current_row.parameters_dimensions_num IS NOT NULL) THEN 
              fullText := fullText || '(parameters_dimensions_num:integer)=(' || current_row.parameters_dimensions_num || ')';
          END IF;
          IF (current_row.parameters_offset_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_offset_x:float)=(' || current_row.parameters_offset_x || ')';
          END IF;
          IF (current_row.parameters_offset_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_offset_y:float)=(' || current_row.parameters_offset_y || ')';
          END IF;
          IF (current_row.parameters_offset_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_offset_z:float)=(' || current_row.parameters_offset_z || ')';
          END IF;
          IF (current_row.parameters_reconzoom IS NOT NULL) THEN 
              fullText := fullText || '(parameters_reconzoom:float)=(' || current_row.parameters_reconzoom || ')';
          END IF;
          IF (current_row.parameters_pixelsize_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelsize_x:float)=(' || current_row.parameters_pixelsize_x || ')';
          END IF;
          IF (current_row.parameters_pixelsize_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelsize_y:float)=(' || current_row.parameters_pixelsize_y || ')';
          END IF;
          IF (current_row.parameters_pixelsize_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pixelsize_z:float)=(' || current_row.parameters_pixelsize_z || ')';
          END IF;
          IF (current_row.parameters_filtercode IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filtercode:integer)=(' || current_row.parameters_filtercode || ')';
          END IF;
          IF (current_row.parameters_resolution_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_resolution_x:float)=(' || current_row.parameters_resolution_x || ')';
          END IF;
          IF (current_row.parameters_resolution_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_resolution_y:float)=(' || current_row.parameters_resolution_y || ')';
          END IF;
          IF (current_row.parameters_resolution_z IS NOT NULL) THEN 
              fullText := fullText || '(parameters_resolution_z:float)=(' || current_row.parameters_resolution_z || ')';
          END IF;
          IF (current_row.parameters_numrelements IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numrelements:float)=(' || current_row.parameters_numrelements || ')';
          END IF;
          IF (current_row.parameters_numangles IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numangles:float)=(' || current_row.parameters_numangles || ')';
          END IF;
          IF (current_row.parameters_zrotationangle IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zrotationangle:float)=(' || current_row.parameters_zrotationangle || ')';
          END IF;
          IF (current_row.parameters_processingcode IS NOT NULL) THEN 
              fullText := fullText || '(parameters_processingcode:integer)=(' || current_row.parameters_processingcode || ')';
          END IF;
          IF (current_row.parameters_gateduration IS NOT NULL) THEN 
              fullText := fullText || '(parameters_gateduration:integer)=(' || current_row.parameters_gateduration || ')';
          END IF;
          IF (current_row.parameters_rwaveoffset IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rwaveoffset:integer)=(' || current_row.parameters_rwaveoffset || ')';
          END IF;
          IF (current_row.parameters_numacceptedbeats IS NOT NULL) THEN 
              fullText := fullText || '(parameters_numacceptedbeats:integer)=(' || current_row.parameters_numacceptedbeats || ')';
          END IF;
          IF (current_row.parameters_filter_cutoff IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filter_cutoff:float)=(' || current_row.parameters_filter_cutoff || ')';
          END IF;
          IF (current_row.parameters_annotation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_annotation:string)=(' || REPLACE(REPLACE(current_row.parameters_annotation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_mt_1_1 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_1:float)=(' || current_row.parameters_mt_1_1 || ')';
          END IF;
          IF (current_row.parameters_mt_1_2 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_2:float)=(' || current_row.parameters_mt_1_2 || ')';
          END IF;
          IF (current_row.parameters_mt_1_3 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_3:float)=(' || current_row.parameters_mt_1_3 || ')';
          END IF;
          IF (current_row.parameters_mt_1_4 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_1_4:float)=(' || current_row.parameters_mt_1_4 || ')';
          END IF;
          IF (current_row.parameters_mt_2_1 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_1:float)=(' || current_row.parameters_mt_2_1 || ')';
          END IF;
          IF (current_row.parameters_mt_2_2 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_2:float)=(' || current_row.parameters_mt_2_2 || ')';
          END IF;
          IF (current_row.parameters_mt_2_3 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_3:float)=(' || current_row.parameters_mt_2_3 || ')';
          END IF;
          IF (current_row.parameters_mt_2_4 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_2_4:float)=(' || current_row.parameters_mt_2_4 || ')';
          END IF;
          IF (current_row.parameters_mt_3_1 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_1:float)=(' || current_row.parameters_mt_3_1 || ')';
          END IF;
          IF (current_row.parameters_mt_3_2 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_2:float)=(' || current_row.parameters_mt_3_2 || ')';
          END IF;
          IF (current_row.parameters_mt_3_3 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_3:float)=(' || current_row.parameters_mt_3_3 || ')';
          END IF;
          IF (current_row.parameters_mt_3_4 IS NOT NULL) THEN 
              fullText := fullText || '(parameters_mt_3_4:float)=(' || current_row.parameters_mt_3_4 || ')';
          END IF;
          IF (current_row.parameters_rfilter_cutoff IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_cutoff:float)=(' || current_row.parameters_rfilter_cutoff || ')';
          END IF;
          IF (current_row.parameters_rfilter_resolution IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_resolution:float)=(' || current_row.parameters_rfilter_resolution || ')';
          END IF;
          IF (current_row.parameters_rfilter_code IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_code:integer)=(' || current_row.parameters_rfilter_code || ')';
          END IF;
          IF (current_row.parameters_rfilter_order IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rfilter_order:integer)=(' || current_row.parameters_rfilter_order || ')';
          END IF;
          IF (current_row.parameters_zfilter_cutoff IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_cutoff:float)=(' || current_row.parameters_zfilter_cutoff || ')';
          END IF;
          IF (current_row.parameters_zfilter_resolution IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_resolution:float)=(' || current_row.parameters_zfilter_resolution || ')';
          END IF;
          IF (current_row.parameters_zfilter_code IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_code:integer)=(' || current_row.parameters_zfilter_code || ')';
          END IF;
          IF (current_row.parameters_zfilter_order IS NOT NULL) THEN 
              fullText := fullText || '(parameters_zfilter_order:integer)=(' || current_row.parameters_zfilter_order || ')';
          END IF;
          IF (current_row.parameters_scattertype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_scattertype:integer)=(' || current_row.parameters_scattertype || ')';
          END IF;
          IF (current_row.parameters_recontype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_recontype:integer)=(' || current_row.parameters_recontype || ')';
          END IF;
          IF (current_row.parameters_reconviews IS NOT NULL) THEN 
              fullText := fullText || '(parameters_reconviews:integer)=(' || current_row.parameters_reconviews || ')';
          END IF;
          IF (current_row.parameters_bedposition IS NOT NULL) THEN 
              fullText := fullText || '(parameters_bedposition:float)=(' || current_row.parameters_bedposition || ')';
          END IF;
          IF (current_row.parameters_ecatcalibrationfactor IS NOT NULL) THEN 
              fullText := fullText || '(parameters_ecatcalibrationfactor:float)=(' || current_row.parameters_ecatcalibrationfactor || ')';
          END IF;
          IF (current_row.ecatvalidation IS NOT NULL) THEN 
              fullText := fullText || '(ecatvalidation:string)=(' || REPLACE(REPLACE(current_row.ecatvalidation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ecatvalidation_status IS NOT NULL) THEN 
              fullText := fullText || '(ecatvalidation_status:integer)=(' || current_row.ecatvalidation_status || ')';
          END IF;
        IF ((current_row.petScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(petscandata_info:integer)=(' || current_row.petscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petScanData_meta_data(current_row.petScanData_info, child_count,$3,false,false);
              fullText := fullText || '(petscandata_info_petscandata_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_petscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petscandata_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:petScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_petScanData_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_petscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petsessiondata(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:petSessionData)(';
      FOR current_row IN SELECT * FROM xnat_petSessionData 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.stabilization IS NOT NULL) THEN 
              fullText := fullText || '(stabilization:string)=(' || REPLACE(REPLACE(current_row.stabilization,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.studytype IS NOT NULL) THEN 
              fullText := fullText || '(studytype:string)=(' || REPLACE(REPLACE(current_row.studytype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientid IS NOT NULL) THEN 
              fullText := fullText || '(patientid:string)=(' || REPLACE(REPLACE(current_row.patientid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientname IS NOT NULL) THEN 
              fullText := fullText || '(patientname:string)=(' || REPLACE(REPLACE(current_row.patientname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose_units:string)=(' || REPLACE(REPLACE(current_row.tracer_dose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose:float)=(' || current_row.tracer_dose || ')';
          END IF;
          IF (current_row.tracer_specificactivity IS NOT NULL) THEN 
              fullText := fullText || '(tracer_specificactivity:float)=(' || current_row.tracer_specificactivity || ')';
          END IF;
          IF (current_row.tracer_totalmass_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass_units:string)=(' || REPLACE(REPLACE(current_row.tracer_totalmass_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_totalmass IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass:float)=(' || current_row.tracer_totalmass || ')';
          END IF;
          IF (current_row.tracer_intermediate_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate_units:string)=(' || REPLACE(REPLACE(current_row.tracer_intermediate_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_intermediate IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate:float)=(' || current_row.tracer_intermediate || ')';
          END IF;
          IF (current_row.tracer_isotope_half_life IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope_half_life:float)=(' || current_row.tracer_isotope_half_life || ')';
          END IF;
          IF (current_row.tracer_isotope IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope:string)=(' || REPLACE(REPLACE(current_row.tracer_isotope,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_transmissions IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions:integer)=(' || current_row.tracer_transmissions || ')';
          END IF;
          IF (current_row.tracer_transmissions_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions_starttime:dateTime)=(' || current_row.tracer_transmissions_starttime || ')';
          END IF;
          IF (current_row.tracer_name IS NOT NULL) THEN 
              fullText := fullText || '(tracer_name:string)=(' || REPLACE(REPLACE(current_row.tracer_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_starttime:dateTime)=(' || current_row.tracer_starttime || ')';
          END IF;
          IF (current_row.start_time IS NOT NULL) THEN 
              fullText := fullText || '(start_time:dateTime)=(' || current_row.start_time || ')';
          END IF;
          IF (current_row.start_time_scan IS NOT NULL) THEN 
              fullText := fullText || '(start_time_scan:dateTime)=(' || current_row.start_time_scan || ')';
          END IF;
          IF (current_row.start_time_injection IS NOT NULL) THEN 
              fullText := fullText || '(start_time_injection:dateTime)=(' || current_row.start_time_injection || ')';
          END IF;
          IF (current_row.blood_glucose IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose:float)=(' || current_row.blood_glucose || ')';
          END IF;
          IF (current_row.blood_glucose_units IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_units:string)=(' || REPLACE(REPLACE(current_row.blood_glucose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.blood_glucose_time IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_time:dateTime)=(' || current_row.blood_glucose_time || ')';
          END IF;
        IF ((current_row.petSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(petsessiondata_info:integer)=(' || current_row.petsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petSessionData_meta_data(current_row.petSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(petsessiondata_info_petsessiondata_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_petsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petsessiondata_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:petSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_petSessionData_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.stabilization IS NOT NULL) THEN 
              fullText := fullText || '(stabilization:string)=(' || REPLACE(REPLACE(current_row.stabilization,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.studytype IS NOT NULL) THEN 
              fullText := fullText || '(studytype:string)=(' || REPLACE(REPLACE(current_row.studytype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientid IS NOT NULL) THEN 
              fullText := fullText || '(patientid:string)=(' || REPLACE(REPLACE(current_row.patientid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.patientname IS NOT NULL) THEN 
              fullText := fullText || '(patientname:string)=(' || REPLACE(REPLACE(current_row.patientname,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose_units:string)=(' || REPLACE(REPLACE(current_row.tracer_dose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_dose IS NOT NULL) THEN 
              fullText := fullText || '(tracer_dose:float)=(' || current_row.tracer_dose || ')';
          END IF;
          IF (current_row.tracer_specificactivity IS NOT NULL) THEN 
              fullText := fullText || '(tracer_specificactivity:float)=(' || current_row.tracer_specificactivity || ')';
          END IF;
          IF (current_row.tracer_totalmass_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass_units:string)=(' || REPLACE(REPLACE(current_row.tracer_totalmass_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_totalmass IS NOT NULL) THEN 
              fullText := fullText || '(tracer_totalmass:float)=(' || current_row.tracer_totalmass || ')';
          END IF;
          IF (current_row.tracer_intermediate_units IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate_units:string)=(' || REPLACE(REPLACE(current_row.tracer_intermediate_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_intermediate IS NOT NULL) THEN 
              fullText := fullText || '(tracer_intermediate:float)=(' || current_row.tracer_intermediate || ')';
          END IF;
          IF (current_row.tracer_isotope_half_life IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope_half_life:float)=(' || current_row.tracer_isotope_half_life || ')';
          END IF;
          IF (current_row.tracer_isotope IS NOT NULL) THEN 
              fullText := fullText || '(tracer_isotope:string)=(' || REPLACE(REPLACE(current_row.tracer_isotope,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_transmissions IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions:integer)=(' || current_row.tracer_transmissions || ')';
          END IF;
          IF (current_row.tracer_transmissions_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_transmissions_starttime:dateTime)=(' || current_row.tracer_transmissions_starttime || ')';
          END IF;
          IF (current_row.tracer_name IS NOT NULL) THEN 
              fullText := fullText || '(tracer_name:string)=(' || REPLACE(REPLACE(current_row.tracer_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.tracer_starttime IS NOT NULL) THEN 
              fullText := fullText || '(tracer_starttime:dateTime)=(' || current_row.tracer_starttime || ')';
          END IF;
          IF (current_row.start_time IS NOT NULL) THEN 
              fullText := fullText || '(start_time:dateTime)=(' || current_row.start_time || ')';
          END IF;
          IF (current_row.start_time_scan IS NOT NULL) THEN 
              fullText := fullText || '(start_time_scan:dateTime)=(' || current_row.start_time_scan || ')';
          END IF;
          IF (current_row.start_time_injection IS NOT NULL) THEN 
              fullText := fullText || '(start_time_injection:dateTime)=(' || current_row.start_time_injection || ')';
          END IF;
          IF (current_row.blood_glucose IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose:float)=(' || current_row.blood_glucose || ')';
          END IF;
          IF (current_row.blood_glucose_units IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_units:string)=(' || REPLACE(REPLACE(current_row.blood_glucose_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.blood_glucose_time IS NOT NULL) THEN 
              fullText := fullText || '(blood_glucose_time:dateTime)=(' || current_row.blood_glucose_time || ')';
          END IF;
        IF ((current_row.petSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(petsessiondata_info:integer)=(' || current_row.petsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_petSessionData_meta_data(current_row.petSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(petsessiondata_info_petsessiondata_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_petsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_petsessiondata_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:petSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_petSessionData_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_petsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_projectdata(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:projectData)(';
      FOR current_row IN SELECT * FROM xnat_projectData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.keywords IS NOT NULL) THEN 
              fullText := fullText || '(keywords:string)=(' || REPLACE(REPLACE(current_row.keywords,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_projectData_alias WHERE aliases_alias_xnat_projectData_id=current_row.id ORDER BY xnat_projectdata_alias_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_alias( parent_row.xnat_projectdata_alias_id, child_count,$3,false,false);
              fullText := fullText || '(aliases_alias_projectdata_alias' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_publicationResource WHERE publications_publication_xnat_p_id=current_row.id ORDER BY xnat_abstractresource_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_publicationResource( parent_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(publications_publication_publicationresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_resource WHERE  xnat_projectData_id=current_row.id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(resources_resource_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractProtocol WHERE xnat_projectData_id=current_row.id ORDER BY xnat_abstractprotocol_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractProtocol( parent_row.xnat_abstractprotocol_id, child_count,$3,false,false);
              fullText := fullText || '(studyprotocol_abstractprotocol' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.pi_xnat_investigatordata_id IS NOT NULL)) THEN
            fullText := fullText || '(pi_xnat_investigatordata_id:integer)=(' || current_row.pi_xnat_investigatordata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData(current_row.pi_xnat_investigatordata_id, child_count,$3,false,false);
              fullText := fullText || '(pi_investigatordata:XFTItem)=(' || tempText || ')';
        END IF;
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_investigator WHERE  xnat_projectData_id=current_row.id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData( mapping_row.xnat_investigatorData_xnat_investigatordata_id, child_count,$3,false,false);
              fullText := fullText || '(investigators_investigator_investigatordata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_projectData_field WHERE fields_field_xnat_projectData_id=current_row.id ORDER BY xnat_projectdata_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_field( parent_row.xnat_projectdata_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_projectdata_field' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secondary_id IS NOT NULL) THEN 
              fullText := fullText || '(secondary_id:string)=(' || REPLACE(REPLACE(current_row.secondary_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.active IS NOT NULL) THEN 
              fullText := fullText || '(active:integer)=(' || current_row.active || ')';
          END IF;
        IF ((current_row.projectData_info IS NOT NULL)) THEN
            fullText := fullText || '(projectdata_info:integer)=(' || current_row.projectdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_meta_data(current_row.projectData_info, child_count,$3,false,false);
              fullText := fullText || '(projectdata_info_projectdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_projectdata_alias(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:projectData_alias)(';
      FOR current_row IN SELECT * FROM xnat_projectData_alias WHERE  xnat_projectdata_alias_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.alias IS NOT NULL) THEN 
              fullText := fullText || '(alias:string)=(' || REPLACE(REPLACE(current_row.alias,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.source IS NOT NULL) THEN 
              fullText := fullText || '(source:string)=(' || REPLACE(REPLACE(current_row.source,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.projectData_alias_info IS NOT NULL)) THEN
            fullText := fullText || '(projectdata_alias_info:integer)=(' || current_row.projectdata_alias_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_alias_meta_data(current_row.projectData_alias_info, child_count,$3,false,false);
              fullText := fullText || '(projectdata_alias_info_projectdata_alias_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.aliases_alias_xnat_projectData_id IS NOT NULL)) THEN
            fullText := fullText || '(aliases_alias_xnat_projectdata_id:string)=(' || current_row.aliases_alias_xnat_projectdata_id || ')';
        END IF;
          IF (current_row.xnat_projectdata_alias_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_projectdata_alias_id:integer)=(' || current_row.xnat_projectdata_alias_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_projectdata_alias_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:projectData_alias_history)(';
      FOR current_row IN SELECT * FROM xnat_projectData_alias_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.alias IS NOT NULL) THEN 
              fullText := fullText || '(alias:string)=(' || REPLACE(REPLACE(current_row.alias,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.source IS NOT NULL) THEN 
              fullText := fullText || '(source:string)=(' || REPLACE(REPLACE(current_row.source,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.projectData_alias_info IS NOT NULL)) THEN
            fullText := fullText || '(projectdata_alias_info:integer)=(' || current_row.projectdata_alias_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_alias_meta_data(current_row.projectData_alias_info, child_count,$3,false,false);
              fullText := fullText || '(projectdata_alias_info_projectdata_alias_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.aliases_alias_xnat_projectData_id IS NOT NULL)) THEN
            fullText := fullText || '(aliases_alias_xnat_projectdata_id:string)=(' || current_row.aliases_alias_xnat_projectdata_id || ')';
        END IF;
          IF (current_row.xnat_projectdata_alias_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_projectdata_alias_id:integer)=(' || current_row.xnat_projectdata_alias_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_projectdata_alias_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_projectdata_alias_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:projectData_alias_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_projectData_alias_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_projectdata_alias_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_projectdata_field(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:projectData_field)(';
      FOR current_row IN SELECT * FROM xnat_projectData_field WHERE  xnat_projectdata_field_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.field IS NOT NULL) THEN 
              fullText := fullText || '(field:string)=(' || REPLACE(REPLACE(current_row.field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.projectData_field_info IS NOT NULL)) THEN
            fullText := fullText || '(projectdata_field_info:integer)=(' || current_row.projectdata_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_field_meta_data(current_row.projectData_field_info, child_count,$3,false,false);
              fullText := fullText || '(projectdata_field_info_projectdata_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_projectData_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_projectdata_id:string)=(' || current_row.fields_field_xnat_projectdata_id || ')';
        END IF;
          IF (current_row.xnat_projectdata_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_projectdata_field_id:integer)=(' || current_row.xnat_projectdata_field_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_projectdata_field_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:projectData_field_history)(';
      FOR current_row IN SELECT * FROM xnat_projectData_field_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.field IS NOT NULL) THEN 
              fullText := fullText || '(field:string)=(' || REPLACE(REPLACE(current_row.field,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.projectData_field_info IS NOT NULL)) THEN
            fullText := fullText || '(projectdata_field_info:integer)=(' || current_row.projectdata_field_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_field_meta_data(current_row.projectData_field_info, child_count,$3,false,false);
              fullText := fullText || '(projectdata_field_info_projectdata_field_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.fields_field_xnat_projectData_id IS NOT NULL)) THEN
            fullText := fullText || '(fields_field_xnat_projectdata_id:string)=(' || current_row.fields_field_xnat_projectdata_id || ')';
        END IF;
          IF (current_row.xnat_projectdata_field_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_projectdata_field_id:integer)=(' || current_row.xnat_projectdata_field_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_projectdata_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:projectData_history)(';
      FOR current_row IN SELECT * FROM xnat_projectData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.keywords IS NOT NULL) THEN 
              fullText := fullText || '(keywords:string)=(' || REPLACE(REPLACE(current_row.keywords,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_projectData_alias_history WHERE aliases_alias_xnat_projectData_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_projectdata_alias_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_alias_history( parent_row.xnat_projectdata_alias_id, child_count,$3,false,false);
              fullText := fullText || '(aliases_alias_projectdata_alias' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_publicationResource_history WHERE publications_publication_xnat_p_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_abstractresource_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_publicationResource_history( parent_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(publications_publication_publicationresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_resource_history WHERE  xnat_projectData_id=current_row.id AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_history( mapping_row.xnat_abstractResource_xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(resources_resource_abstractresource' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractProtocol_history WHERE xnat_projectData_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_abstractprotocol_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractProtocol_history( parent_row.xnat_abstractprotocol_id, child_count,$3,false,false);
              fullText := fullText || '(studyprotocol_abstractprotocol' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
        IF ((current_row.pi_xnat_investigatordata_id IS NOT NULL)) THEN
            fullText := fullText || '(pi_xnat_investigatordata_id:integer)=(' || current_row.pi_xnat_investigatordata_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_investigatorData_history WHERE  xnat_investigatordata_id=current_row.pi_xnat_investigatordata_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(pi_investigatordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_investigator_history WHERE  xnat_projectData_id=current_row.id AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_investigatorData_history( mapping_row.xnat_investigatorData_xnat_investigatordata_id, child_count,$3,false,false);
              fullText := fullText || '(investigators_investigator_investigatordata' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_projectData_field_history WHERE fields_field_xnat_projectData_id=current_row.id AND xft_version=current_row.xft_version ORDER BY xnat_projectdata_field_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_field_history( parent_row.xnat_projectdata_field_id, child_count,$3,false,false);
              fullText := fullText || '(fields_field_projectdata_field' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.id IS NOT NULL) THEN 
              fullText := fullText || '(id:string)=(' || REPLACE(REPLACE(current_row.id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.secondary_id IS NOT NULL) THEN 
              fullText := fullText || '(secondary_id:string)=(' || REPLACE(REPLACE(current_row.secondary_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.active IS NOT NULL) THEN 
              fullText := fullText || '(active:integer)=(' || current_row.active || ')';
          END IF;
        IF ((current_row.projectData_info IS NOT NULL)) THEN
            fullText := fullText || '(projectdata_info:integer)=(' || current_row.projectdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectData_meta_data(current_row.projectData_info, child_count,$3,false,false);
              fullText := fullText || '(projectdata_info_projectdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_projectdata_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:projectData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_projectData_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_projectdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_projectparticipant(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:projectParticipant)(';
      FOR current_row IN SELECT * FROM xnat_projectParticipant WHERE  xnat_projectparticipant_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.subject_id IS NOT NULL) THEN 
              fullText := fullText || '(subject_id:string)=(' || REPLACE(REPLACE(current_row.subject_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row._group IS NOT NULL) THEN 
              fullText := fullText || '(_group:string)=(' || REPLACE(REPLACE(current_row._group,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.projectParticipant_info IS NOT NULL)) THEN
            fullText := fullText || '(projectparticipant_info:integer)=(' || current_row.projectparticipant_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectParticipant_meta_data(current_row.projectParticipant_info, child_count,$3,false,false);
              fullText := fullText || '(projectparticipant_info_projectparticipant_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_projectparticipant_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_projectparticipant_id:integer)=(' || current_row.xnat_projectparticipant_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_projectparticipant_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:projectParticipant_history)(';
      FOR current_row IN SELECT * FROM xnat_projectParticipant_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.label IS NOT NULL) THEN 
              fullText := fullText || '(label:string)=(' || REPLACE(REPLACE(current_row.label,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.project IS NOT NULL) THEN 
              fullText := fullText || '(project:string)=(' || REPLACE(REPLACE(current_row.project,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.subject_id IS NOT NULL) THEN 
              fullText := fullText || '(subject_id:string)=(' || REPLACE(REPLACE(current_row.subject_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row._group IS NOT NULL) THEN 
              fullText := fullText || '(_group:string)=(' || REPLACE(REPLACE(current_row._group,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.projectParticipant_info IS NOT NULL)) THEN
            fullText := fullText || '(projectparticipant_info:integer)=(' || current_row.projectparticipant_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_projectParticipant_meta_data(current_row.projectParticipant_info, child_count,$3,false,false);
              fullText := fullText || '(projectparticipant_info_projectparticipant_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_projectparticipant_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_projectparticipant_id:integer)=(' || current_row.xnat_projectparticipant_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_projectparticipant_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_projectparticipant_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:projectParticipant_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_projectParticipant_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_projectparticipant_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_publicationresource(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     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:publicationResource)(';
      FOR current_row IN SELECT * FROM xnat_publicationResource WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource(current_row.xnat_abstractresource_id, child_count,$3,false,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.title IS NOT NULL) THEN 
              fullText := fullText || '(title:string)=(' || REPLACE(REPLACE(current_row.title,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.citation IS NOT NULL) THEN 
              fullText := fullText || '(citation:string)=(' || REPLACE(REPLACE(current_row.citation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.abstract IS NOT NULL) THEN 
              fullText := fullText || '(abstract:string)=(' || REPLACE(REPLACE(current_row.abstract,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.commentary IS NOT NULL) THEN 
              fullText := fullText || '(commentary:string)=(' || REPLACE(REPLACE(current_row.commentary,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.isprimary IS NOT NULL) THEN 
              fullText := fullText || '(isprimary:integer)=(' || current_row.isprimary || ')';
          END IF;
          IF (current_row.doi IS NOT NULL) THEN 
              fullText := fullText || '(doi:string)=(' || REPLACE(REPLACE(current_row.doi,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pubmed IS NOT NULL) THEN 
              fullText := fullText || '(pubmed:string)=(' || REPLACE(REPLACE(current_row.pubmed,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.medline IS NOT NULL) THEN 
              fullText := fullText || '(medline:string)=(' || REPLACE(REPLACE(current_row.medline,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.other IS NOT NULL) THEN 
              fullText := fullText || '(other:string)=(' || REPLACE(REPLACE(current_row.other,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.publicationResource_info IS NOT NULL)) THEN
            fullText := fullText || '(publicationresource_info:integer)=(' || current_row.publicationresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_publicationResource_meta_data(current_row.publicationResource_info, child_count,$3,false,false);
              fullText := fullText || '(publicationresource_info_publicationresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.publications_publication_xnat_p_id IS NOT NULL)) THEN
            fullText := fullText || '(publications_publication_xnat_p_id:string)=(' || current_row.publications_publication_xnat_p_id || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_publicationresource_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:publicationResource_history)(';
      FOR current_row IN SELECT * FROM xnat_publicationResource_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractresource_id:integer)=(' || current_row.xnat_abstractresource_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_abstractResource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_abstractResource_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(abstractresource_abstractresource:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.title IS NOT NULL) THEN 
              fullText := fullText || '(title:string)=(' || REPLACE(REPLACE(current_row.title,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.citation IS NOT NULL) THEN 
              fullText := fullText || '(citation:string)=(' || REPLACE(REPLACE(current_row.citation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.abstract IS NOT NULL) THEN 
              fullText := fullText || '(abstract:string)=(' || REPLACE(REPLACE(current_row.abstract,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.commentary IS NOT NULL) THEN 
              fullText := fullText || '(commentary:string)=(' || REPLACE(REPLACE(current_row.commentary,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.isprimary IS NOT NULL) THEN 
              fullText := fullText || '(isprimary:integer)=(' || current_row.isprimary || ')';
          END IF;
          IF (current_row.doi IS NOT NULL) THEN 
              fullText := fullText || '(doi:string)=(' || REPLACE(REPLACE(current_row.doi,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.pubmed IS NOT NULL) THEN 
              fullText := fullText || '(pubmed:string)=(' || REPLACE(REPLACE(current_row.pubmed,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.medline IS NOT NULL) THEN 
              fullText := fullText || '(medline:string)=(' || REPLACE(REPLACE(current_row.medline,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.other IS NOT NULL) THEN 
              fullText := fullText || '(other:string)=(' || REPLACE(REPLACE(current_row.other,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.type IS NOT NULL) THEN 
              fullText := fullText || '(type:string)=(' || REPLACE(REPLACE(current_row.type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.publicationResource_info IS NOT NULL)) THEN
            fullText := fullText || '(publicationresource_info:integer)=(' || current_row.publicationresource_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_publicationResource_meta_data(current_row.publicationResource_info, child_count,$3,false,false);
              fullText := fullText || '(publicationresource_info_publicationresource_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.publications_publication_xnat_p_id IS NOT NULL)) THEN
            fullText := fullText || '(publications_publication_xnat_p_id:string)=(' || current_row.publications_publication_xnat_p_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;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_publicationresource_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:publicationResource_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_publicationResource_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_publicationresource_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_pvisitdata(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:pVisitData)(';
      FOR current_row IN SELECT * FROM xnat_pVisitData 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_genericData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(genericdata_genericdata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.subject_id IS NOT NULL) THEN 
              fullText := fullText || '(subject_id:string)=(' || REPLACE(REPLACE(current_row.subject_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit_type IS NOT NULL) THEN 
              fullText := fullText || '(visit_type:string)=(' || REPLACE(REPLACE(current_row.visit_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit_name IS NOT NULL) THEN 
              fullText := fullText || '(visit_name:string)=(' || REPLACE(REPLACE(current_row.visit_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.notes IS NOT NULL) THEN 
              fullText := fullText || '(notes:string)=(' || REPLACE(REPLACE(current_row.notes,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.start_date IS NOT NULL) THEN 
              fullText := fullText || '(start_date:dateTime)=(' || current_row.start_date || ')';
          END IF;
          IF (current_row.end_date IS NOT NULL) THEN 
              fullText := fullText || '(end_date:dateTime)=(' || current_row.end_date || ')';
          END IF;
          IF (current_row.closed IS NOT NULL) THEN 
              fullText := fullText || '(closed:integer)=(' || current_row.closed || ')';
          END IF;
          IF (current_row.terminal IS NOT NULL) THEN 
              fullText := fullText || '(terminal:integer)=(' || current_row.terminal || ')';
          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.protocolversion IS NOT NULL) THEN 
              fullText := fullText || '(protocolversion:integer)=(' || current_row.protocolversion || ')';
          END IF;
          IF (current_row.protocolid IS NOT NULL) THEN 
              fullText := fullText || '(protocolid:string)=(' || REPLACE(REPLACE(current_row.protocolid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.pVisitData_info IS NOT NULL)) THEN
            fullText := fullText || '(pvisitdata_info:integer)=(' || current_row.pvisitdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_pVisitData_meta_data(current_row.pVisitData_info, child_count,$3,false,false);
              fullText := fullText || '(pvisitdata_info_pvisitdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_genericData( $1, child_count,$3,$4,false);
              fullText := fullText || '(genericdata_genericdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_pvisitdata_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:pVisitData_history)(';
      FOR current_row IN SELECT * FROM xnat_pVisitData_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_genericData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_genericData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(genericdata_genericdata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.subject_id IS NOT NULL) THEN 
              fullText := fullText || '(subject_id:string)=(' || REPLACE(REPLACE(current_row.subject_id,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit_type IS NOT NULL) THEN 
              fullText := fullText || '(visit_type:string)=(' || REPLACE(REPLACE(current_row.visit_type,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.visit_name IS NOT NULL) THEN 
              fullText := fullText || '(visit_name:string)=(' || REPLACE(REPLACE(current_row.visit_name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.notes IS NOT NULL) THEN 
              fullText := fullText || '(notes:string)=(' || REPLACE(REPLACE(current_row.notes,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.start_date IS NOT NULL) THEN 
              fullText := fullText || '(start_date:dateTime)=(' || current_row.start_date || ')';
          END IF;
          IF (current_row.end_date IS NOT NULL) THEN 
              fullText := fullText || '(end_date:dateTime)=(' || current_row.end_date || ')';
          END IF;
          IF (current_row.closed IS NOT NULL) THEN 
              fullText := fullText || '(closed:integer)=(' || current_row.closed || ')';
          END IF;
          IF (current_row.terminal IS NOT NULL) THEN 
              fullText := fullText || '(terminal:integer)=(' || current_row.terminal || ')';
          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.protocolversion IS NOT NULL) THEN 
              fullText := fullText || '(protocolversion:integer)=(' || current_row.protocolversion || ')';
          END IF;
          IF (current_row.protocolid IS NOT NULL) THEN 
              fullText := fullText || '(protocolid:string)=(' || REPLACE(REPLACE(current_row.protocolid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.pVisitData_info IS NOT NULL)) THEN
            fullText := fullText || '(pvisitdata_info:integer)=(' || current_row.pvisitdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_pVisitData_meta_data(current_row.pVisitData_info, child_count,$3,false,false);
              fullText := fullText || '(pvisitdata_info_pvisitdata_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_genericData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(genericdata_genericdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_pvisitdata_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:pVisitData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_pVisitData_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_pvisitdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
