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

CREATE FUNCTION public.i_xnat_a_ybocsdata_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_a:ybocsData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_a_ybocsData_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_a_ybocsdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_a_ygtssdata(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_a:ygtssData)(';
      FOR current_row IN SELECT * FROM xnat_a_ygtssData WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData(current_row.id, child_count,$3,false,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.filledoutby IS NOT NULL) THEN 
              fullText := fullText || '(filledoutby:string)=(' || REPLACE(REPLACE(current_row.filledoutby,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.period IS NOT NULL) THEN 
              fullText := fullText || '(period:string)=(' || REPLACE(REPLACE(current_row.period,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.worsteverage IS NOT NULL) THEN 
              fullText := fullText || '(worsteverage:float)=(' || current_row.worsteverage || ')';
          END IF;
          IF (current_row.motor_number IS NOT NULL) THEN 
              fullText := fullText || '(motor_number:integer)=(' || current_row.motor_number || ')';
          END IF;
          IF (current_row.motor_frequency IS NOT NULL) THEN 
              fullText := fullText || '(motor_frequency:integer)=(' || current_row.motor_frequency || ')';
          END IF;
          IF (current_row.motor_intensity IS NOT NULL) THEN 
              fullText := fullText || '(motor_intensity:integer)=(' || current_row.motor_intensity || ')';
          END IF;
          IF (current_row.motor_complexity IS NOT NULL) THEN 
              fullText := fullText || '(motor_complexity:integer)=(' || current_row.motor_complexity || ')';
          END IF;
          IF (current_row.motor_interference IS NOT NULL) THEN 
              fullText := fullText || '(motor_interference:integer)=(' || current_row.motor_interference || ')';
          END IF;
          IF (current_row.motor_inventory IS NOT NULL) THEN 
              fullText := fullText || '(motor_inventory:string)=(' || REPLACE(REPLACE(current_row.motor_inventory,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.phonic_number IS NOT NULL) THEN 
              fullText := fullText || '(phonic_number:integer)=(' || current_row.phonic_number || ')';
          END IF;
          IF (current_row.phonic_frequency IS NOT NULL) THEN 
              fullText := fullText || '(phonic_frequency:integer)=(' || current_row.phonic_frequency || ')';
          END IF;
          IF (current_row.phonic_intensity IS NOT NULL) THEN 
              fullText := fullText || '(phonic_intensity:integer)=(' || current_row.phonic_intensity || ')';
          END IF;
          IF (current_row.phonic_complexity IS NOT NULL) THEN 
              fullText := fullText || '(phonic_complexity:integer)=(' || current_row.phonic_complexity || ')';
          END IF;
          IF (current_row.phonic_interference IS NOT NULL) THEN 
              fullText := fullText || '(phonic_interference:integer)=(' || current_row.phonic_interference || ')';
          END IF;
          IF (current_row.phonic_inventory IS NOT NULL) THEN 
              fullText := fullText || '(phonic_inventory:string)=(' || REPLACE(REPLACE(current_row.phonic_inventory,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.impairment IS NOT NULL) THEN 
              fullText := fullText || '(impairment:integer)=(' || current_row.impairment || ')';
          END IF;
        IF ((current_row.ygtssData_info IS NOT NULL)) THEN
            fullText := fullText || '(ygtssdata_info:integer)=(' || current_row.ygtssdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_ygtssData_meta_data(current_row.ygtssData_info, child_count,$3,false,false);
              fullText := fullText || '(ygtssdata_info_ygtssdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_a_ygtssdata_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_a:ygtssData_history)(';
      FOR current_row IN SELECT * FROM xnat_a_ygtssData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.id IS NOT NULL)) THEN
            fullText := fullText || '(id:string)=(' || current_row.id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_subjectAssessorData_history WHERE id=current_row.id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_subjectAssessorData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.filledoutby IS NOT NULL) THEN 
              fullText := fullText || '(filledoutby:string)=(' || REPLACE(REPLACE(current_row.filledoutby,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.period IS NOT NULL) THEN 
              fullText := fullText || '(period:string)=(' || REPLACE(REPLACE(current_row.period,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.worsteverage IS NOT NULL) THEN 
              fullText := fullText || '(worsteverage:float)=(' || current_row.worsteverage || ')';
          END IF;
          IF (current_row.motor_number IS NOT NULL) THEN 
              fullText := fullText || '(motor_number:integer)=(' || current_row.motor_number || ')';
          END IF;
          IF (current_row.motor_frequency IS NOT NULL) THEN 
              fullText := fullText || '(motor_frequency:integer)=(' || current_row.motor_frequency || ')';
          END IF;
          IF (current_row.motor_intensity IS NOT NULL) THEN 
              fullText := fullText || '(motor_intensity:integer)=(' || current_row.motor_intensity || ')';
          END IF;
          IF (current_row.motor_complexity IS NOT NULL) THEN 
              fullText := fullText || '(motor_complexity:integer)=(' || current_row.motor_complexity || ')';
          END IF;
          IF (current_row.motor_interference IS NOT NULL) THEN 
              fullText := fullText || '(motor_interference:integer)=(' || current_row.motor_interference || ')';
          END IF;
          IF (current_row.motor_inventory IS NOT NULL) THEN 
              fullText := fullText || '(motor_inventory:string)=(' || REPLACE(REPLACE(current_row.motor_inventory,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.phonic_number IS NOT NULL) THEN 
              fullText := fullText || '(phonic_number:integer)=(' || current_row.phonic_number || ')';
          END IF;
          IF (current_row.phonic_frequency IS NOT NULL) THEN 
              fullText := fullText || '(phonic_frequency:integer)=(' || current_row.phonic_frequency || ')';
          END IF;
          IF (current_row.phonic_intensity IS NOT NULL) THEN 
              fullText := fullText || '(phonic_intensity:integer)=(' || current_row.phonic_intensity || ')';
          END IF;
          IF (current_row.phonic_complexity IS NOT NULL) THEN 
              fullText := fullText || '(phonic_complexity:integer)=(' || current_row.phonic_complexity || ')';
          END IF;
          IF (current_row.phonic_interference IS NOT NULL) THEN 
              fullText := fullText || '(phonic_interference:integer)=(' || current_row.phonic_interference || ')';
          END IF;
          IF (current_row.phonic_inventory IS NOT NULL) THEN 
              fullText := fullText || '(phonic_inventory:string)=(' || REPLACE(REPLACE(current_row.phonic_inventory,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.impairment IS NOT NULL) THEN 
              fullText := fullText || '(impairment:integer)=(' || current_row.impairment || ')';
          END IF;
        IF ((current_row.ygtssData_info IS NOT NULL)) THEN
            fullText := fullText || '(ygtssdata_info:integer)=(' || current_row.ygtssdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_a_ygtssData_meta_data(current_row.ygtssData_info, child_count,$3,false,false);
              fullText := fullText || '(ygtssdata_info_ygtssdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_subjectAssessorData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(subjectassessordata_subjectassessordata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_a_ygtssdata_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_a:ygtssData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_a_ygtssData_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_a_ygtssdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_abstractdemographicdata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractDemographicData.xnat_abstractdemographicdata_id AS xnat_abstractDemographicData2, table1.element_name AS xdat_meta_element3, table2.insert_date AS xnat_abstractDemographicData_meta_data10 FROM xnat_abstractDemographicData xnat_abstractDemographicData   LEFT JOIN xdat_meta_element table1 ON xnat_abstractDemographicData.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_abstractDemographicData_meta_data table2 ON xnat_abstractDemographicData.abstractDemographicData_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xnat_abstractDemographicData2=$1))
      LOOP
         IF (current_row.xdat_meta_element3 IS NULL) THEN 
             fullText:= ie_xnat_abstractDemographicData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:demographicData') THEN
                fullText:= i_xnat_demographicData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractDemographicData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractdemographicdata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractDemographicData_history.history_id AS xnat_abstractDemographicData_history4, table1.element_name AS xdat_meta_element9, xnat_abstractDemographicData_history.xft_version AS xnat_abstractDemographicData_history_xft_version, xnat_abstractDemographicData_history.xnat_abstractdemographicdata_id AS xnat_abstractDemographicData_history1 FROM xnat_abstractDemographicData_history xnat_abstractDemographicData_history   LEFT JOIN xdat_meta_element table1 ON xnat_abstractDemographicData_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_abstractDemographicData_history4=$1))
      LOOP
         IF (current_row.xdat_meta_element9 IS NULL) THEN 
             fullText:= ie_xnat_abstractDemographicData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element9='xnat:demographicData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_demographicData_history WHERE xnat_abstractdemographicdata_id=current_row.xnat_abstractDemographicData_history1 AND xft_version=current_row.xnat_abstractDemographicData_history_xft_version
           	LOOP
                fullText:= i_xnat_demographicData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractDemographicData_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractdemographicdata_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:abstractDemographicData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_abstractDemographicData_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_abstractdemographicdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_abstractprotocol(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractProtocol.xnat_abstractprotocol_id AS xnat_abstractProtocol6, table1.element_name AS xdat_meta_element8, table2.insert_date AS xnat_abstractProtocol_meta_data15 FROM xnat_abstractProtocol xnat_abstractProtocol   LEFT JOIN xdat_meta_element table1 ON xnat_abstractProtocol.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_abstractProtocol_meta_data table2 ON xnat_abstractProtocol.abstractProtocol_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xnat_abstractProtocol6=$1))
      LOOP
         IF (current_row.xdat_meta_element8 IS NULL) THEN 
             fullText:= ie_xnat_abstractProtocol( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element8='xnat:studyProtocol') THEN
                fullText:= i_xnat_studyProtocol( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element8='xnat:datatypeProtocol') THEN
                fullText:= i_xnat_datatypeProtocol( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractProtocol( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractprotocol_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractProtocol_history.history_id AS xnat_abstractProtocol_history6, table1.element_name AS xdat_meta_element14, xnat_abstractProtocol_history.xft_version AS xnat_abstractProtocol_history_xft_version, xnat_abstractProtocol_history.xnat_abstractprotocol_id AS xnat_abstractProtocol_history3 FROM xnat_abstractProtocol_history xnat_abstractProtocol_history   LEFT JOIN xdat_meta_element table1 ON xnat_abstractProtocol_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_abstractProtocol_history6=$1))
      LOOP
         IF (current_row.xdat_meta_element14 IS NULL) THEN 
             fullText:= ie_xnat_abstractProtocol( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element14='xnat:studyProtocol') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_studyProtocol_history WHERE xnat_abstractprotocol_id=current_row.xnat_abstractProtocol_history3 AND xft_version=current_row.xnat_abstractProtocol_history_xft_version
           	LOOP
                fullText:= i_xnat_studyProtocol_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element14='xnat:datatypeProtocol') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_datatypeProtocol_history WHERE xnat_abstractprotocol_id=current_row.xnat_abstractProtocol_history3 AND xft_version=current_row.xnat_abstractProtocol_history_xft_version
           	LOOP
                fullText:= i_xnat_datatypeProtocol_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractProtocol_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractprotocol_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:abstractProtocol_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_abstractProtocol_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_abstractprotocol_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_abstractresource(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractResource.xnat_abstractresource_id AS xnat_abstractResource6, table1.element_name AS xdat_meta_element25, table2.insert_date AS xnat_abstractResource_meta_data32 FROM xnat_abstractResource xnat_abstractResource   LEFT JOIN xdat_meta_element table1 ON xnat_abstractResource.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_abstractResource_meta_data table2 ON xnat_abstractResource.abstractResource_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xnat_abstractResource6=$1))
      LOOP
         IF (current_row.xdat_meta_element25 IS NULL) THEN 
             fullText:= ie_xnat_abstractResource( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element25='xnat:resource') THEN
                fullText:= ie_xnat_resource( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageResource') THEN
                fullText:= i_xnat_imageResource( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:resourceSeries') THEN
                fullText:= ie_xnat_resourceSeries( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageResourceSeries') THEN
                fullText:= i_xnat_imageResourceSeries( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:dicomSeries') THEN
                fullText:= i_xnat_dicomSeries( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:publicationResource') THEN
                fullText:= i_xnat_publicationResource( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:resourceCatalog') THEN
                fullText:= i_xnat_resourceCatalog( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractResource( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractresource_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractResource_history.history_id AS xnat_abstractResource_history5, table1.element_name AS xdat_meta_element14, xnat_abstractResource_history.xft_version AS xnat_abstractResource_history_xft_version, xnat_abstractResource_history.xnat_abstractresource_id AS xnat_abstractResource_history9 FROM xnat_abstractResource_history xnat_abstractResource_history   LEFT JOIN xdat_meta_element table1 ON xnat_abstractResource_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_abstractResource_history5=$1))
      LOOP
         IF (current_row.xdat_meta_element14 IS NULL) THEN 
             fullText:= ie_xnat_abstractResource( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element14='xnat:resource') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_resource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractResource_history9 AND xft_version=current_row.xnat_abstractResource_history_xft_version
           	LOOP
                fullText:= ie_xnat_resource_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element14='xnat:imageResource') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_imageResource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractResource_history9 AND xft_version=current_row.xnat_abstractResource_history_xft_version
           	LOOP
                fullText:= i_xnat_imageResource_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element14='xnat:resourceSeries') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_resourceSeries_history WHERE xnat_abstractresource_id=current_row.xnat_abstractResource_history9 AND xft_version=current_row.xnat_abstractResource_history_xft_version
           	LOOP
                fullText:= ie_xnat_resourceSeries_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element14='xnat:imageResourceSeries') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_imageResourceSeries_history WHERE xnat_abstractresource_id=current_row.xnat_abstractResource_history9 AND xft_version=current_row.xnat_abstractResource_history_xft_version
           	LOOP
                fullText:= i_xnat_imageResourceSeries_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element14='xnat:dicomSeries') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_dicomSeries_history WHERE xnat_abstractresource_id=current_row.xnat_abstractResource_history9 AND xft_version=current_row.xnat_abstractResource_history_xft_version
           	LOOP
                fullText:= i_xnat_dicomSeries_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element14='xnat:publicationResource') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_publicationResource_history WHERE xnat_abstractresource_id=current_row.xnat_abstractResource_history9 AND xft_version=current_row.xnat_abstractResource_history_xft_version
           	LOOP
                fullText:= i_xnat_publicationResource_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
            IF (current_row.xdat_meta_element14='xnat:resourceCatalog') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_resourceCatalog_history WHERE xnat_abstractresource_id=current_row.xnat_abstractResource_history9 AND xft_version=current_row.xnat_abstractResource_history_xft_version
           	LOOP
                fullText:= i_xnat_resourceCatalog_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractResource_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractresource_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:abstractResource_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_abstractResource_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_abstractresource_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_abstractresource_tag(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractResource_tag)(';
      FOR current_row IN SELECT * FROM xnat_abstractResource_tag WHERE  xnat_abstractresource_tag_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.tag IS NOT NULL) THEN 
              fullText := fullText || '(tag:string)=(' || REPLACE(REPLACE(current_row.tag,'(','*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.abstractResource_tag_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractresource_tag_info:integer)=(' || current_row.abstractresource_tag_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_tag_meta_data(current_row.abstractResource_tag_info, child_count,$3,false,false);
              fullText := fullText || '(abstractresource_tag_info_abstractresource_tag_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.tags_tag_xnat_abstractResource_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(tags_tag_xnat_abstractresource_xnat_abstractresource_id:integer)=(' || current_row.tags_tag_xnat_abstractresource_xnat_abstractresource_id || ')';
        END IF;
          IF (current_row.xnat_abstractresource_tag_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractresource_tag_id:integer)=(' || current_row.xnat_abstractresource_tag_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractresource_tag_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:abstractResource_tag_history)(';
      FOR current_row IN SELECT * FROM xnat_abstractResource_tag_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.tag IS NOT NULL) THEN 
              fullText := fullText || '(tag:string)=(' || REPLACE(REPLACE(current_row.tag,'(','*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.abstractResource_tag_info IS NOT NULL)) THEN
            fullText := fullText || '(abstractresource_tag_info:integer)=(' || current_row.abstractresource_tag_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_abstractResource_tag_meta_data(current_row.abstractResource_tag_info, child_count,$3,false,false);
              fullText := fullText || '(abstractresource_tag_info_abstractresource_tag_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.tags_tag_xnat_abstractResource_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(tags_tag_xnat_abstractresource_xnat_abstractresource_id:integer)=(' || current_row.tags_tag_xnat_abstractresource_xnat_abstractresource_id || ')';
        END IF;
          IF (current_row.xnat_abstractresource_tag_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_abstractresource_tag_id:integer)=(' || current_row.xnat_abstractresource_tag_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_abstractresource_tag_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_abstractresource_tag_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:abstractResource_tag_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_abstractResource_tag_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_abstractresource_tag_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_abstractstatistics(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractStatistics.xnat_abstractstatistics_id AS xnat_abstractStatistics2, table1.element_name AS xdat_meta_element3, table2.insert_date AS xnat_abstractStatistics_meta_data10 FROM xnat_abstractStatistics xnat_abstractStatistics   LEFT JOIN xdat_meta_element table1 ON xnat_abstractStatistics.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_abstractStatistics_meta_data table2 ON xnat_abstractStatistics.abstractStatistics_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xnat_abstractStatistics2=$1))
      LOOP
         IF (current_row.xdat_meta_element3 IS NULL) THEN 
             fullText:= ie_xnat_abstractStatistics( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:statisticsData') THEN
                fullText:= i_xnat_statisticsData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractStatistics( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractstatistics_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractStatistics_history.history_id AS xnat_abstractStatistics_history3, table1.element_name AS xdat_meta_element9, xnat_abstractStatistics_history.xft_version AS xnat_abstractStatistics_history_xft_version, xnat_abstractStatistics_history.xnat_abstractstatistics_id AS xnat_abstractStatistics_history4 FROM xnat_abstractStatistics_history xnat_abstractStatistics_history   LEFT JOIN xdat_meta_element table1 ON xnat_abstractStatistics_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_abstractStatistics_history3=$1))
      LOOP
         IF (current_row.xdat_meta_element9 IS NULL) THEN 
             fullText:= ie_xnat_abstractStatistics( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element9='xnat:statisticsData') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_statisticsData_history WHERE xnat_abstractstatistics_id=current_row.xnat_abstractStatistics_history4 AND xft_version=current_row.xnat_abstractStatistics_history_xft_version
           	LOOP
                fullText:= i_xnat_statisticsData_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractStatistics_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractstatistics_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:abstractStatistics_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_abstractStatistics_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_abstractstatistics_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_abstractsubjectmetadata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractSubjectMetadata.xnat_abstractsubjectmetadata_id AS xnat_abstractSubjectMetadata2, table1.element_name AS xdat_meta_element3, table2.insert_date AS xnat_abstractSubjectMetadata_meta_data10 FROM xnat_abstractSubjectMetadata xnat_abstractSubjectMetadata   LEFT JOIN xdat_meta_element table1 ON xnat_abstractSubjectMetadata.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_abstractSubjectMetadata_meta_data table2 ON xnat_abstractSubjectMetadata.abstractSubjectMetadata_info=table2.meta_data_id) SEARCH  WHERE 
 ( (xnat_abstractSubjectMetadata2=$1))
      LOOP
         IF (current_row.xdat_meta_element3 IS NULL) THEN 
             fullText:= ie_xnat_abstractSubjectMetadata( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:subjectMetadata') THEN
                fullText:= i_xnat_subjectMetadata( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractSubjectMetadata( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractsubjectmetadata_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_abstractSubjectMetadata_history.history_id AS xnat_abstractSubjectMetadata_history3, table1.element_name AS xdat_meta_element9, xnat_abstractSubjectMetadata_history.xft_version AS xnat_abstractSubjectMetadata_history_xft_version, xnat_abstractSubjectMetadata_history.xnat_abstractsubjectmetadata_id AS xnat_abstractSubjectMetadata_history0 FROM xnat_abstractSubjectMetadata_history xnat_abstractSubjectMetadata_history   LEFT JOIN xdat_meta_element table1 ON xnat_abstractSubjectMetadata_history.extension=table1.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_abstractSubjectMetadata_history3=$1))
      LOOP
         IF (current_row.xdat_meta_element9 IS NULL) THEN 
             fullText:= ie_xnat_abstractSubjectMetadata( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element9='xnat:subjectMetadata') THEN
            --907 
            DECLARE
            	ext_row RECORD;
            BEGIN 
            	FOR ext_row IN SELECT * FROM xnat_subjectMetadata_history WHERE xnat_abstractsubjectmetadata_id=current_row.xnat_abstractSubjectMetadata_history0 AND xft_version=current_row.xnat_abstractSubjectMetadata_history_xft_version
           	LOOP
                fullText:= i_xnat_subjectMetadata_history(ext_row.history_id, $2,$3,$4,$5);
                matches:=1;
            	END LOOP;
            END;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_abstractSubjectMetadata_history( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_abstractsubjectmetadata_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:abstractSubjectMetadata_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_abstractSubjectMetadata_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_abstractsubjectmetadata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_addfield(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:addField)(';
      FOR current_row IN SELECT * FROM xnat_addField WHERE  xnat_addfield_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.addfield IS NOT NULL) THEN 
              fullText := fullText || '(addfield:string)=(' || REPLACE(REPLACE(current_row.addfield,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.addField_info IS NOT NULL)) THEN
            fullText := fullText || '(addfield_info:integer)=(' || current_row.addfield_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_addField_meta_data(current_row.addField_info, child_count,$3,false,false);
              fullText := fullText || '(addfield_info_addfield_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_mrScan_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_mrscan_xnat_imagescandata_id:integer)=(' || current_row.parameters_addparam_xnat_mrscan_xnat_imagescandata_id || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id:integer)=(' || current_row.parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_petSca_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_petsca_xnat_imagescandata_id:integer)=(' || current_row.parameters_addparam_xnat_petsca_xnat_imagescandata_id || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_imageA_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_imagea_id:string)=(' || current_row.parameters_addparam_xnat_imagea_id || ')';
        END IF;
          IF (current_row.xnat_addfield_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_addfield_id:integer)=(' || current_row.xnat_addfield_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_addfield_history(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:addField_history)(';
      FOR current_row IN SELECT * FROM xnat_addField_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.addfield IS NOT NULL) THEN 
              fullText := fullText || '(addfield:string)=(' || REPLACE(REPLACE(current_row.addfield,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.addField_info IS NOT NULL)) THEN
            fullText := fullText || '(addfield_info:integer)=(' || current_row.addfield_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_addField_meta_data(current_row.addField_info, child_count,$3,false,false);
              fullText := fullText || '(addfield_info_addfield_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_mrScan_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_mrscan_xnat_imagescandata_id:integer)=(' || current_row.parameters_addparam_xnat_mrscan_xnat_imagescandata_id || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id:integer)=(' || current_row.parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_petSca_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_petsca_xnat_imagescandata_id:integer)=(' || current_row.parameters_addparam_xnat_petsca_xnat_imagescandata_id || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_addparam_xnat_imageA_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_addparam_xnat_imagea_id:string)=(' || current_row.parameters_addparam_xnat_imagea_id || ')';
        END IF;
          IF (current_row.xnat_addfield_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_addfield_id:integer)=(' || current_row.xnat_addfield_id || ')';
          END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_algorithm(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:algorithm)(';
      FOR current_row IN SELECT * FROM xnat_algorithm WHERE  xnat_algorithm_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.family_xnat_dicomcodedvalue_id IS NOT NULL)) THEN
            fullText := fullText || '(family_xnat_dicomcodedvalue_id:integer)=(' || current_row.family_xnat_dicomcodedvalue_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomCodedValue(current_row.family_xnat_dicomcodedvalue_id, child_count,$3,false,false);
              fullText := fullText || '(family_dicomcodedvalue:XFTItem)=(' || tempText || ')';
        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.version IS NOT NULL) THEN 
              fullText := fullText || '(version:string)=(' || REPLACE(REPLACE(current_row.version,'(','*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.parameters IS NOT NULL) THEN 
              fullText := fullText || '(parameters:string)=(' || REPLACE(REPLACE(current_row.parameters,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.namecode_xnat_dicomcodedvalue_id IS NOT NULL)) THEN
            fullText := fullText || '(namecode_xnat_dicomcodedvalue_id:integer)=(' || current_row.namecode_xnat_dicomcodedvalue_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomCodedValue(current_row.namecode_xnat_dicomcodedvalue_id, child_count,$3,false,false);
              fullText := fullText || '(namecode_dicomcodedvalue:XFTItem)=(' || tempText || ')';
        END IF;
        IF ((current_row.algorithm_info IS NOT NULL)) THEN
            fullText := fullText || '(algorithm_info:integer)=(' || current_row.algorithm_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_algorithm_meta_data(current_row.algorithm_info, child_count,$3,false,false);
              fullText := fullText || '(algorithm_info_algorithm_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_algorithm_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_algorithm_id:integer)=(' || current_row.xnat_algorithm_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_algorithm_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:algorithm_history)(';
      FOR current_row IN SELECT * FROM xnat_algorithm_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.family_xnat_dicomcodedvalue_id IS NOT NULL)) THEN
            fullText := fullText || '(family_xnat_dicomcodedvalue_id:integer)=(' || current_row.family_xnat_dicomcodedvalue_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_dicomCodedValue_history WHERE  xnat_dicomcodedvalue_id=current_row.family_xnat_dicomcodedvalue_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomCodedValue_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(family_dicomcodedvalue:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.version IS NOT NULL) THEN 
              fullText := fullText || '(version:string)=(' || REPLACE(REPLACE(current_row.version,'(','*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.parameters IS NOT NULL) THEN 
              fullText := fullText || '(parameters:string)=(' || REPLACE(REPLACE(current_row.parameters,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.namecode_xnat_dicomcodedvalue_id IS NOT NULL)) THEN
            fullText := fullText || '(namecode_xnat_dicomcodedvalue_id:integer)=(' || current_row.namecode_xnat_dicomcodedvalue_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_dicomCodedValue_history WHERE  xnat_dicomcodedvalue_id=current_row.namecode_xnat_dicomcodedvalue_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomCodedValue_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(namecode_dicomcodedvalue:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        END IF;
        IF ((current_row.algorithm_info IS NOT NULL)) THEN
            fullText := fullText || '(algorithm_info:integer)=(' || current_row.algorithm_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_algorithm_meta_data(current_row.algorithm_info, child_count,$3,false,false);
              fullText := fullText || '(algorithm_info_algorithm_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_algorithm_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_algorithm_id:integer)=(' || current_row.xnat_algorithm_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_algorithm_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_algorithm_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:algorithm_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_algorithm_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_algorithm_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_computationdata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:computationData)(';
      FOR current_row IN SELECT * FROM xnat_computationData WHERE  xnat_computationdata_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.source IS NOT NULL) THEN 
              fullText := fullText || '(source:string)=(' || REPLACE(REPLACE(current_row.source,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.computationData_info IS NOT NULL)) THEN
            fullText := fullText || '(computationdata_info:integer)=(' || current_row.computationdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_computationData_meta_data(current_row.computationData_info, child_count,$3,false,false);
              fullText := fullText || '(computationdata_info_computationdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.computations_datum_xnat_reconst_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
            fullText := fullText || '(computations_datum_xnat_reconst_xnat_reconstructedimagedata_id:integer)=(' || current_row.computations_datum_xnat_reconst_xnat_reconstructedimagedata_id || ')';
        END IF;
          IF (current_row.xnat_computationdata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_computationdata_id:integer)=(' || current_row.xnat_computationdata_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_computationdata_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:computationData_history)(';
      FOR current_row IN SELECT * FROM xnat_computationData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.name IS NOT NULL) THEN 
              fullText := fullText || '(name:string)=(' || REPLACE(REPLACE(current_row.name,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.source IS NOT NULL) THEN 
              fullText := fullText || '(source:string)=(' || REPLACE(REPLACE(current_row.source,'(','*OPEN*'),')','*CLOSE*') || ')';
          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.computationData_info IS NOT NULL)) THEN
            fullText := fullText || '(computationdata_info:integer)=(' || current_row.computationdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_computationData_meta_data(current_row.computationData_info, child_count,$3,false,false);
              fullText := fullText || '(computationdata_info_computationdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.computations_datum_xnat_reconst_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
            fullText := fullText || '(computations_datum_xnat_reconst_xnat_reconstructedimagedata_id:integer)=(' || current_row.computations_datum_xnat_reconst_xnat_reconstructedimagedata_id || ')';
        END IF;
          IF (current_row.xnat_computationdata_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_computationdata_id:integer)=(' || current_row.xnat_computationdata_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_computationdata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_computationdata_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:computationData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_computationData_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_computationdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_contrastbolus(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:contrastBolus)(';
      FOR current_row IN SELECT * FROM xnat_contrastBolus WHERE  xnat_contrastbolus_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.agent IS NOT NULL) THEN 
              fullText := fullText || '(agent:string)=(' || REPLACE(REPLACE(current_row.agent,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.route IS NOT NULL) THEN 
              fullText := fullText || '(route:string)=(' || REPLACE(REPLACE(current_row.route,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.volume IS NOT NULL) THEN 
              fullText := fullText || '(volume:float)=(' || current_row.volume || ')';
          END IF;
          IF (current_row.totaldose IS NOT NULL) THEN 
              fullText := fullText || '(totaldose:float)=(' || current_row.totaldose || ')';
          END IF;
          IF (current_row.flowrate IS NOT NULL) THEN 
              fullText := fullText || '(flowrate:float)=(' || current_row.flowrate || ')';
          END IF;
          IF (current_row.flowduration IS NOT NULL) THEN 
              fullText := fullText || '(flowduration:float)=(' || current_row.flowduration || ')';
          END IF;
          IF (current_row.activeingredient IS NOT NULL) THEN 
              fullText := fullText || '(activeingredient:string)=(' || REPLACE(REPLACE(current_row.activeingredient,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.concentration IS NOT NULL) THEN 
              fullText := fullText || '(concentration:float)=(' || current_row.concentration || ')';
          END IF;
        IF ((current_row.contrastBolus_info IS NOT NULL)) THEN
            fullText := fullText || '(contrastbolus_info:integer)=(' || current_row.contrastbolus_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_contrastBolus_meta_data(current_row.contrastBolus_info, child_count,$3,false,false);
              fullText := fullText || '(contrastbolus_info_contrastbolus_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_contrastbolus_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_contrastbolus_id:integer)=(' || current_row.xnat_contrastbolus_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_contrastbolus_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:contrastBolus_history)(';
      FOR current_row IN SELECT * FROM xnat_contrastBolus_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.agent IS NOT NULL) THEN 
              fullText := fullText || '(agent:string)=(' || REPLACE(REPLACE(current_row.agent,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.route IS NOT NULL) THEN 
              fullText := fullText || '(route:string)=(' || REPLACE(REPLACE(current_row.route,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.volume IS NOT NULL) THEN 
              fullText := fullText || '(volume:float)=(' || current_row.volume || ')';
          END IF;
          IF (current_row.totaldose IS NOT NULL) THEN 
              fullText := fullText || '(totaldose:float)=(' || current_row.totaldose || ')';
          END IF;
          IF (current_row.flowrate IS NOT NULL) THEN 
              fullText := fullText || '(flowrate:float)=(' || current_row.flowrate || ')';
          END IF;
          IF (current_row.flowduration IS NOT NULL) THEN 
              fullText := fullText || '(flowduration:float)=(' || current_row.flowduration || ')';
          END IF;
          IF (current_row.activeingredient IS NOT NULL) THEN 
              fullText := fullText || '(activeingredient:string)=(' || REPLACE(REPLACE(current_row.activeingredient,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.concentration IS NOT NULL) THEN 
              fullText := fullText || '(concentration:float)=(' || current_row.concentration || ')';
          END IF;
        IF ((current_row.contrastBolus_info IS NOT NULL)) THEN
            fullText := fullText || '(contrastbolus_info:integer)=(' || current_row.contrastbolus_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_contrastBolus_meta_data(current_row.contrastBolus_info, child_count,$3,false,false);
              fullText := fullText || '(contrastbolus_info_contrastbolus_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_contrastbolus_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_contrastbolus_id:integer)=(' || current_row.xnat_contrastbolus_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_contrastbolus_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_contrastbolus_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:contrastBolus_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_contrastBolus_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_contrastbolus_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

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

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

CREATE FUNCTION public.i_xnat_crscandata_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:crScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_crScanData_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.crScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(crscandata_info:integer)=(' || current_row.crscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_crScanData_meta_data(current_row.crScanData_info, child_count,$3,false,false);
              fullText := fullText || '(crscandata_info_crscandata_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_crscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_crscandata_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:crScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_crScanData_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_crscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_crsessiondata(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:crSessionData)(';
      FOR current_row IN SELECT * FROM xnat_crSessionData 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.crSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(crsessiondata_info:integer)=(' || current_row.crsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_crSessionData_meta_data(current_row.crSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(crsessiondata_info_crsessiondata_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_crsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_crsessiondata_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:crSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_crSessionData_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.crSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(crsessiondata_info:integer)=(' || current_row.crsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_crSessionData_meta_data(current_row.crSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(crsessiondata_info_crsessiondata_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_crsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_crsessiondata_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:crSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_crSessionData_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_crsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctscandata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:ctScanData)(';
      FOR current_row IN SELECT * FROM xnat_ctScanData 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_orientation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_orientation:string)=(' || REPLACE(REPLACE(current_row.parameters_orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_subjectposition IS NOT NULL) THEN 
              fullText := fullText || '(parameters_subjectposition:string)=(' || REPLACE(REPLACE(current_row.parameters_subjectposition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_fov_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_x:integer)=(' || current_row.parameters_fov_x || ')';
          END IF;
          IF (current_row.parameters_fov_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_y:integer)=(' || current_row.parameters_fov_y || ')';
          END IF;
          IF (current_row.parameters_rescale_intercept IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rescale_intercept:string)=(' || REPLACE(REPLACE(current_row.parameters_rescale_intercept,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_rescale_slope IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rescale_slope:string)=(' || REPLACE(REPLACE(current_row.parameters_rescale_slope,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_kvp IS NOT NULL) THEN 
              fullText := fullText || '(parameters_kvp:float)=(' || current_row.parameters_kvp || ')';
          END IF;
          IF (current_row.parameters_acquisitionnumber IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acquisitionnumber:integer)=(' || current_row.parameters_acquisitionnumber || ')';
          END IF;
          IF (current_row.parameters_imagetype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_imagetype:string)=(' || REPLACE(REPLACE(current_row.parameters_imagetype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_options IS NOT NULL) THEN 
              fullText := fullText || '(parameters_options:string)=(' || REPLACE(REPLACE(current_row.parameters_options,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_collectiondiameter IS NOT NULL) THEN 
              fullText := fullText || '(parameters_collectiondiameter:float)=(' || current_row.parameters_collectiondiameter || ')';
          END IF;
          IF (current_row.parameters_distancesourcetodetector IS NOT NULL) THEN 
              fullText := fullText || '(parameters_distancesourcetodetector:float)=(' || current_row.parameters_distancesourcetodetector || ')';
          END IF;
          IF (current_row.parameters_distancesourcetopatient IS NOT NULL) THEN 
              fullText := fullText || '(parameters_distancesourcetopatient:float)=(' || current_row.parameters_distancesourcetopatient || ')';
          END IF;
          IF (current_row.parameters_gantrytilt IS NOT NULL) THEN 
              fullText := fullText || '(parameters_gantrytilt:float)=(' || current_row.parameters_gantrytilt || ')';
          END IF;
          IF (current_row.parameters_tableheight IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tableheight:float)=(' || current_row.parameters_tableheight || ')';
          END IF;
          IF (current_row.parameters_rotationdirection IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rotationdirection:string)=(' || REPLACE(REPLACE(current_row.parameters_rotationdirection,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_exposuretime IS NOT NULL) THEN 
              fullText := fullText || '(parameters_exposuretime:float)=(' || current_row.parameters_exposuretime || ')';
          END IF;
          IF (current_row.parameters_xraytubecurrent IS NOT NULL) THEN 
              fullText := fullText || '(parameters_xraytubecurrent:float)=(' || current_row.parameters_xraytubecurrent || ')';
          END IF;
          IF (current_row.parameters_exposure IS NOT NULL) THEN 
              fullText := fullText || '(parameters_exposure:float)=(' || current_row.parameters_exposure || ')';
          END IF;
          IF (current_row.parameters_filter IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filter:string)=(' || REPLACE(REPLACE(current_row.parameters_filter,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_generatorpower IS NOT NULL) THEN 
              fullText := fullText || '(parameters_generatorpower:float)=(' || current_row.parameters_generatorpower || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_ctScanData_focalSpot WHERE parameters_focalspots_focalspot_xnat_imagescandata_id=current_row.xnat_imagescandata_id ORDER BY xnat_ctscandata_focalspot_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctScanData_focalSpot( parent_row.xnat_ctscandata_focalspot_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_focalspots_focalspot_ctscandata_focalspot' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.parameters_convolutionkernel IS NOT NULL) THEN 
              fullText := fullText || '(parameters_convolutionkernel:string)=(' || REPLACE(REPLACE(current_row.parameters_convolutionkernel,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_collimationwidth_single IS NOT NULL) THEN 
              fullText := fullText || '(parameters_collimationwidth_single:float)=(' || current_row.parameters_collimationwidth_single || ')';
          END IF;
          IF (current_row.parameters_collimationwidth_total IS NOT NULL) THEN 
              fullText := fullText || '(parameters_collimationwidth_total:float)=(' || current_row.parameters_collimationwidth_total || ')';
          END IF;
          IF (current_row.parameters_tablespeed IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tablespeed:float)=(' || current_row.parameters_tablespeed || ')';
          END IF;
          IF (current_row.parameters_tablefeedperrotation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tablefeedperrotation:float)=(' || current_row.parameters_tablefeedperrotation || ')';
          END IF;
          IF (current_row.parameters_pitchfactor IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pitchfactor:float)=(' || current_row.parameters_pitchfactor || ')';
          END IF;
          IF (current_row.parameters_estimateddosesaving_modulation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_estimateddosesaving_modulation:string)=(' || REPLACE(REPLACE(current_row.parameters_estimateddosesaving_modulation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_estimateddosesaving IS NOT NULL) THEN 
              fullText := fullText || '(parameters_estimateddosesaving:float)=(' || current_row.parameters_estimateddosesaving || ')';
          END IF;
          IF (current_row.parameters_ctdivol IS NOT NULL) THEN 
              fullText := fullText || '(parameters_ctdivol:float)=(' || current_row.parameters_ctdivol || ')';
          END IF;
          IF (current_row.parameters_derivation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_derivation:string)=(' || REPLACE(REPLACE(current_row.parameters_derivation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.parameters_contrastbolus_xnat_contrastbolus_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_contrastbolus_xnat_contrastbolus_id:integer)=(' || current_row.parameters_contrastbolus_xnat_contrastbolus_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_contrastBolus(current_row.parameters_contrastbolus_xnat_contrastbolus_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_contrastbolus_contrastbolus:XFTItem)=(' || tempText || ')';
        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.ctScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(ctscandata_info:integer)=(' || current_row.ctscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctScanData_meta_data(current_row.ctScanData_info, child_count,$3,false,false);
              fullText := fullText || '(ctscandata_info_ctscandata_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_ctscandata(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctscandata_focalspot(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:ctScanData_focalSpot)(';
      FOR current_row IN SELECT * FROM xnat_ctScanData_focalSpot WHERE  xnat_ctscandata_focalspot_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.focalspot IS NOT NULL) THEN 
              fullText := fullText || '(focalspot:float)=(' || current_row.focalspot || ')';
          END IF;
        IF ((current_row.ctScanData_focalSpot_info IS NOT NULL)) THEN
            fullText := fullText || '(ctscandata_focalspot_info:integer)=(' || current_row.ctscandata_focalspot_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctScanData_focalSpot_meta_data(current_row.ctScanData_focalSpot_info, child_count,$3,false,false);
              fullText := fullText || '(ctscandata_focalspot_info_ctscandata_focalspot_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_focalspots_focalspot_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_focalspots_focalspot_xnat_imagescandata_id:integer)=(' || current_row.parameters_focalspots_focalspot_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_ctscandata_focalspot_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_ctscandata_focalspot_id:integer)=(' || current_row.xnat_ctscandata_focalspot_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_ctscandata_focalspot_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:ctScanData_focalSpot_history)(';
      FOR current_row IN SELECT * FROM xnat_ctScanData_focalSpot_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.focalspot IS NOT NULL) THEN 
              fullText := fullText || '(focalspot:float)=(' || current_row.focalspot || ')';
          END IF;
        IF ((current_row.ctScanData_focalSpot_info IS NOT NULL)) THEN
            fullText := fullText || '(ctscandata_focalspot_info:integer)=(' || current_row.ctscandata_focalspot_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctScanData_focalSpot_meta_data(current_row.ctScanData_focalSpot_info, child_count,$3,false,false);
              fullText := fullText || '(ctscandata_focalspot_info_ctscandata_focalspot_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.parameters_focalspots_focalspot_xnat_imagescandata_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_focalspots_focalspot_xnat_imagescandata_id:integer)=(' || current_row.parameters_focalspots_focalspot_xnat_imagescandata_id || ')';
        END IF;
          IF (current_row.xnat_ctscandata_focalspot_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_ctscandata_focalspot_id:integer)=(' || current_row.xnat_ctscandata_focalspot_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_ctscandata_focalspot_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctscandata_focalspot_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:ctScanData_focalSpot_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_ctScanData_focalSpot_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_ctscandata_focalspot_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctscandata_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:ctScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_ctScanData_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_orientation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_orientation:string)=(' || REPLACE(REPLACE(current_row.parameters_orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_subjectposition IS NOT NULL) THEN 
              fullText := fullText || '(parameters_subjectposition:string)=(' || REPLACE(REPLACE(current_row.parameters_subjectposition,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_fov_x IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_x:integer)=(' || current_row.parameters_fov_x || ')';
          END IF;
          IF (current_row.parameters_fov_y IS NOT NULL) THEN 
              fullText := fullText || '(parameters_fov_y:integer)=(' || current_row.parameters_fov_y || ')';
          END IF;
          IF (current_row.parameters_rescale_intercept IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rescale_intercept:string)=(' || REPLACE(REPLACE(current_row.parameters_rescale_intercept,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_rescale_slope IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rescale_slope:string)=(' || REPLACE(REPLACE(current_row.parameters_rescale_slope,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_kvp IS NOT NULL) THEN 
              fullText := fullText || '(parameters_kvp:float)=(' || current_row.parameters_kvp || ')';
          END IF;
          IF (current_row.parameters_acquisitionnumber IS NOT NULL) THEN 
              fullText := fullText || '(parameters_acquisitionnumber:integer)=(' || current_row.parameters_acquisitionnumber || ')';
          END IF;
          IF (current_row.parameters_imagetype IS NOT NULL) THEN 
              fullText := fullText || '(parameters_imagetype:string)=(' || REPLACE(REPLACE(current_row.parameters_imagetype,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_options IS NOT NULL) THEN 
              fullText := fullText || '(parameters_options:string)=(' || REPLACE(REPLACE(current_row.parameters_options,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_collectiondiameter IS NOT NULL) THEN 
              fullText := fullText || '(parameters_collectiondiameter:float)=(' || current_row.parameters_collectiondiameter || ')';
          END IF;
          IF (current_row.parameters_distancesourcetodetector IS NOT NULL) THEN 
              fullText := fullText || '(parameters_distancesourcetodetector:float)=(' || current_row.parameters_distancesourcetodetector || ')';
          END IF;
          IF (current_row.parameters_distancesourcetopatient IS NOT NULL) THEN 
              fullText := fullText || '(parameters_distancesourcetopatient:float)=(' || current_row.parameters_distancesourcetopatient || ')';
          END IF;
          IF (current_row.parameters_gantrytilt IS NOT NULL) THEN 
              fullText := fullText || '(parameters_gantrytilt:float)=(' || current_row.parameters_gantrytilt || ')';
          END IF;
          IF (current_row.parameters_tableheight IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tableheight:float)=(' || current_row.parameters_tableheight || ')';
          END IF;
          IF (current_row.parameters_rotationdirection IS NOT NULL) THEN 
              fullText := fullText || '(parameters_rotationdirection:string)=(' || REPLACE(REPLACE(current_row.parameters_rotationdirection,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_exposuretime IS NOT NULL) THEN 
              fullText := fullText || '(parameters_exposuretime:float)=(' || current_row.parameters_exposuretime || ')';
          END IF;
          IF (current_row.parameters_xraytubecurrent IS NOT NULL) THEN 
              fullText := fullText || '(parameters_xraytubecurrent:float)=(' || current_row.parameters_xraytubecurrent || ')';
          END IF;
          IF (current_row.parameters_exposure IS NOT NULL) THEN 
              fullText := fullText || '(parameters_exposure:float)=(' || current_row.parameters_exposure || ')';
          END IF;
          IF (current_row.parameters_filter IS NOT NULL) THEN 
              fullText := fullText || '(parameters_filter:string)=(' || REPLACE(REPLACE(current_row.parameters_filter,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_generatorpower IS NOT NULL) THEN 
              fullText := fullText || '(parameters_generatorpower:float)=(' || current_row.parameters_generatorpower || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_ctScanData_focalSpot_history WHERE parameters_focalspots_focalspot_xnat_imagescandata_id=current_row.xnat_imagescandata_id AND xft_version=current_row.xft_version ORDER BY xnat_ctscandata_focalspot_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctScanData_focalSpot_history( parent_row.xnat_ctscandata_focalspot_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_focalspots_focalspot_ctscandata_focalspot' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.parameters_convolutionkernel IS NOT NULL) THEN 
              fullText := fullText || '(parameters_convolutionkernel:string)=(' || REPLACE(REPLACE(current_row.parameters_convolutionkernel,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_collimationwidth_single IS NOT NULL) THEN 
              fullText := fullText || '(parameters_collimationwidth_single:float)=(' || current_row.parameters_collimationwidth_single || ')';
          END IF;
          IF (current_row.parameters_collimationwidth_total IS NOT NULL) THEN 
              fullText := fullText || '(parameters_collimationwidth_total:float)=(' || current_row.parameters_collimationwidth_total || ')';
          END IF;
          IF (current_row.parameters_tablespeed IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tablespeed:float)=(' || current_row.parameters_tablespeed || ')';
          END IF;
          IF (current_row.parameters_tablefeedperrotation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_tablefeedperrotation:float)=(' || current_row.parameters_tablefeedperrotation || ')';
          END IF;
          IF (current_row.parameters_pitchfactor IS NOT NULL) THEN 
              fullText := fullText || '(parameters_pitchfactor:float)=(' || current_row.parameters_pitchfactor || ')';
          END IF;
          IF (current_row.parameters_estimateddosesaving_modulation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_estimateddosesaving_modulation:string)=(' || REPLACE(REPLACE(current_row.parameters_estimateddosesaving_modulation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.parameters_estimateddosesaving IS NOT NULL) THEN 
              fullText := fullText || '(parameters_estimateddosesaving:float)=(' || current_row.parameters_estimateddosesaving || ')';
          END IF;
          IF (current_row.parameters_ctdivol IS NOT NULL) THEN 
              fullText := fullText || '(parameters_ctdivol:float)=(' || current_row.parameters_ctdivol || ')';
          END IF;
          IF (current_row.parameters_derivation IS NOT NULL) THEN 
              fullText := fullText || '(parameters_derivation:string)=(' || REPLACE(REPLACE(current_row.parameters_derivation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.parameters_contrastbolus_xnat_contrastbolus_id IS NOT NULL)) THEN
            fullText := fullText || '(parameters_contrastbolus_xnat_contrastbolus_id:integer)=(' || current_row.parameters_contrastbolus_xnat_contrastbolus_id || ')';
 -- 661
           DECLARE
           mapping_row RECORD; 
           loop_count int4:=0; 
           BEGIN 
           	FOR mapping_row IN SELECT * FROM xnat_contrastBolus_history WHERE  xnat_contrastbolus_id=current_row.parameters_contrastbolus_xnat_contrastbolus_id AND xft_version=current_row.xft_version LIMIT 1
           	LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_contrastBolus_history(mapping_row.history_id, child_count,$3,false,false);
              fullText := fullText || '(parameters_contrastbolus_contrastbolus:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END; 
        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.ctScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(ctscandata_info:integer)=(' || current_row.ctscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctScanData_meta_data(current_row.ctScanData_info, child_count,$3,false,false);
              fullText := fullText || '(ctscandata_info_ctscandata_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_ctscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctscandata_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:ctScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_ctScanData_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_ctscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctsessiondata(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:ctSessionData)(';
      FOR current_row IN SELECT * FROM xnat_ctSessionData 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.ctSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(ctsessiondata_info:integer)=(' || current_row.ctsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctSessionData_meta_data(current_row.ctSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(ctsessiondata_info_ctsessiondata_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_ctsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctsessiondata_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:ctSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_ctSessionData_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.ctSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(ctsessiondata_info:integer)=(' || current_row.ctsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_ctSessionData_meta_data(current_row.ctSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(ctsessiondata_info_ctsessiondata_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_ctsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_ctsessiondata_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:ctSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_ctSessionData_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_ctsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_datatypeprotocol(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:datatypeProtocol)(';
      FOR current_row IN SELECT * FROM xnat_datatypeProtocol WHERE  xnat_abstractprotocol_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractprotocol_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractprotocol_id:integer)=(' || current_row.xnat_abstractprotocol_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractProtocol(current_row.xnat_abstractprotocol_id, child_count,$3,false,false);
              fullText := fullText || '(abstractprotocol_abstractprotocol:XFTItem)=(' || tempText || ')';
        END IF;
        IF($3) THEN 
        DECLARE 
  --    120
        mapping_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_datatypeProtocol_fieldGroups WHERE  xnat_datatypeProtocol_xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup( mapping_row.xnat_fieldDefinitionGroup_xnat_fielddefinitiongroup_id, child_count,$3,false,false);
              fullText := fullText || '(definitions_definition_fielddefinitiongroup' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF ((current_row.datatypeProtocol_info IS NOT NULL)) THEN
            fullText := fullText || '(datatypeprotocol_info:integer)=(' || current_row.datatypeprotocol_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_datatypeProtocol_meta_data(current_row.datatypeProtocol_info, child_count,$3,false,false);
              fullText := fullText || '(datatypeprotocol_info_datatypeprotocol_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractProtocol( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractprotocol_abstractprotocol:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_datatypeprotocol_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:datatypeProtocol_history)(';
      FOR current_row IN SELECT * FROM xnat_datatypeProtocol_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractprotocol_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractprotocol_id:integer)=(' || current_row.xnat_abstractprotocol_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_abstractProtocol_history WHERE xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_abstractProtocol_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(abstractprotocol_abstractprotocol: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_datatypeProtocol_fieldGroups_history WHERE  xnat_datatypeProtocol_xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id AND xft_version=current_row.xft_version
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_fieldDefinitionGroup_history( mapping_row.xnat_fieldDefinitionGroup_xnat_fielddefinitiongroup_id, child_count,$3,false,false);
              fullText := fullText || '(definitions_definition_fielddefinitiongroup' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END; 
        END IF; 
        IF ((current_row.datatypeProtocol_info IS NOT NULL)) THEN
            fullText := fullText || '(datatypeprotocol_info:integer)=(' || current_row.datatypeprotocol_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_datatypeProtocol_meta_data(current_row.datatypeProtocol_info, child_count,$3,false,false);
              fullText := fullText || '(datatypeprotocol_info_datatypeprotocol_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_abstractProtocol_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractprotocol_abstractprotocol:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_datatypeprotocol_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:datatypeProtocol_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_datatypeProtocol_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_datatypeprotocol_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_demographicdata(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:demographicData)(';
      FOR current_row IN SELECT * FROM xnat_demographicData WHERE  xnat_abstractdemographicdata_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractdemographicdata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractdemographicdata_id:integer)=(' || current_row.xnat_abstractdemographicdata_id || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractDemographicData(current_row.xnat_abstractdemographicdata_id, child_count,$3,false,false);
              fullText := fullText || '(abstractdemographicdata_abstractdemographicdata:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.dob IS NOT NULL) THEN 
              fullText := fullText || '(dob:date)=(' || current_row.dob || ')';
          END IF;
          IF (current_row.yob IS NOT NULL) THEN 
              fullText := fullText || '(yob:integer)=(' || current_row.yob || ')';
          END IF;
          IF (current_row.age IS NOT NULL) THEN 
              fullText := fullText || '(age:integer)=(' || current_row.age || ')';
          END IF;
          IF (current_row.gender IS NOT NULL) THEN 
              fullText := fullText || '(gender:string)=(' || REPLACE(REPLACE(current_row.gender,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.handedness IS NOT NULL) THEN 
              fullText := fullText || '(handedness:string)=(' || REPLACE(REPLACE(current_row.handedness,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ses IS NOT NULL) THEN 
              fullText := fullText || '(ses:integer)=(' || current_row.ses || ')';
          END IF;
          IF (current_row.employment IS NOT NULL) THEN 
              fullText := fullText || '(employment:integer)=(' || current_row.employment || ')';
          END IF;
          IF (current_row.education IS NOT NULL) THEN 
              fullText := fullText || '(education:integer)=(' || current_row.education || ')';
          END IF;
          IF (current_row.educationdesc IS NOT NULL) THEN 
              fullText := fullText || '(educationdesc:string)=(' || REPLACE(REPLACE(current_row.educationdesc,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race IS NOT NULL) THEN 
              fullText := fullText || '(race:string)=(' || REPLACE(REPLACE(current_row.race,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race2 IS NOT NULL) THEN 
              fullText := fullText || '(race2:string)=(' || REPLACE(REPLACE(current_row.race2,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race3 IS NOT NULL) THEN 
              fullText := fullText || '(race3:string)=(' || REPLACE(REPLACE(current_row.race3,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race4 IS NOT NULL) THEN 
              fullText := fullText || '(race4:string)=(' || REPLACE(REPLACE(current_row.race4,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race5 IS NOT NULL) THEN 
              fullText := fullText || '(race5:string)=(' || REPLACE(REPLACE(current_row.race5,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race6 IS NOT NULL) THEN 
              fullText := fullText || '(race6:string)=(' || REPLACE(REPLACE(current_row.race6,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ethnicity IS NOT NULL) THEN 
              fullText := fullText || '(ethnicity:string)=(' || REPLACE(REPLACE(current_row.ethnicity,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.weight IS NOT NULL) THEN 
              fullText := fullText || '(weight:float)=(' || current_row.weight || ')';
          END IF;
          IF (current_row.weight_units IS NOT NULL) THEN 
              fullText := fullText || '(weight_units:string)=(' || REPLACE(REPLACE(current_row.weight_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.height IS NOT NULL) THEN 
              fullText := fullText || '(height:float)=(' || current_row.height || ')';
          END IF;
          IF (current_row.height_units IS NOT NULL) THEN 
              fullText := fullText || '(height_units:string)=(' || REPLACE(REPLACE(current_row.height_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.gestational_age IS NOT NULL) THEN 
              fullText := fullText || '(gestational_age:float)=(' || current_row.gestational_age || ')';
          END IF;
          IF (current_row.post_menstrual_age IS NOT NULL) THEN 
              fullText := fullText || '(post_menstrual_age:float)=(' || current_row.post_menstrual_age || ')';
          END IF;
          IF (current_row.birth_weight IS NOT NULL) THEN 
              fullText := fullText || '(birth_weight:float)=(' || current_row.birth_weight || ')';
          END IF;
        IF ((current_row.demographicData_info IS NOT NULL)) THEN
            fullText := fullText || '(demographicdata_info:integer)=(' || current_row.demographicdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_demographicData_meta_data(current_row.demographicData_info, child_count,$3,false,false);
              fullText := fullText || '(demographicdata_info_demographicdata_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractDemographicData( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractdemographicdata_abstractdemographicdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_demographicdata_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:demographicData_history)(';
      FOR current_row IN SELECT * FROM xnat_demographicData_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
        IF ((current_row.xnat_abstractdemographicdata_id IS NOT NULL)) THEN
            fullText := fullText || '(xnat_abstractdemographicdata_id:integer)=(' || current_row.xnat_abstractdemographicdata_id || ')';
           child_count := child_count+1;
           tempText := NULL;
           DECLARE
           	ext_row RECORD;
           BEGIN 
           	FOR ext_row IN SELECT * FROM xnat_abstractDemographicData_history WHERE xnat_abstractdemographicdata_id=current_row.xnat_abstractdemographicdata_id AND xft_version=current_row.xft_version
           	LOOP
 -- 632
           	   tempText := ie_xnat_abstractDemographicData_history(ext_row.history_id, child_count,$3,false,false);
           	      fullText := fullText || '(abstractdemographicdata_abstractdemographicdata:XFTItem)=(' || tempText || ')';
           	END LOOP;
           END;
        END IF;
          IF (current_row.dob IS NOT NULL) THEN 
              fullText := fullText || '(dob:date)=(' || current_row.dob || ')';
          END IF;
          IF (current_row.yob IS NOT NULL) THEN 
              fullText := fullText || '(yob:integer)=(' || current_row.yob || ')';
          END IF;
          IF (current_row.age IS NOT NULL) THEN 
              fullText := fullText || '(age:integer)=(' || current_row.age || ')';
          END IF;
          IF (current_row.gender IS NOT NULL) THEN 
              fullText := fullText || '(gender:string)=(' || REPLACE(REPLACE(current_row.gender,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.handedness IS NOT NULL) THEN 
              fullText := fullText || '(handedness:string)=(' || REPLACE(REPLACE(current_row.handedness,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ses IS NOT NULL) THEN 
              fullText := fullText || '(ses:integer)=(' || current_row.ses || ')';
          END IF;
          IF (current_row.employment IS NOT NULL) THEN 
              fullText := fullText || '(employment:integer)=(' || current_row.employment || ')';
          END IF;
          IF (current_row.education IS NOT NULL) THEN 
              fullText := fullText || '(education:integer)=(' || current_row.education || ')';
          END IF;
          IF (current_row.educationdesc IS NOT NULL) THEN 
              fullText := fullText || '(educationdesc:string)=(' || REPLACE(REPLACE(current_row.educationdesc,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race IS NOT NULL) THEN 
              fullText := fullText || '(race:string)=(' || REPLACE(REPLACE(current_row.race,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race2 IS NOT NULL) THEN 
              fullText := fullText || '(race2:string)=(' || REPLACE(REPLACE(current_row.race2,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race3 IS NOT NULL) THEN 
              fullText := fullText || '(race3:string)=(' || REPLACE(REPLACE(current_row.race3,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race4 IS NOT NULL) THEN 
              fullText := fullText || '(race4:string)=(' || REPLACE(REPLACE(current_row.race4,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race5 IS NOT NULL) THEN 
              fullText := fullText || '(race5:string)=(' || REPLACE(REPLACE(current_row.race5,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.race6 IS NOT NULL) THEN 
              fullText := fullText || '(race6:string)=(' || REPLACE(REPLACE(current_row.race6,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.ethnicity IS NOT NULL) THEN 
              fullText := fullText || '(ethnicity:string)=(' || REPLACE(REPLACE(current_row.ethnicity,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.weight IS NOT NULL) THEN 
              fullText := fullText || '(weight:float)=(' || current_row.weight || ')';
          END IF;
          IF (current_row.weight_units IS NOT NULL) THEN 
              fullText := fullText || '(weight_units:string)=(' || REPLACE(REPLACE(current_row.weight_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.height IS NOT NULL) THEN 
              fullText := fullText || '(height:float)=(' || current_row.height || ')';
          END IF;
          IF (current_row.height_units IS NOT NULL) THEN 
              fullText := fullText || '(height_units:string)=(' || REPLACE(REPLACE(current_row.height_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.gestational_age IS NOT NULL) THEN 
              fullText := fullText || '(gestational_age:float)=(' || current_row.gestational_age || ')';
          END IF;
          IF (current_row.post_menstrual_age IS NOT NULL) THEN 
              fullText := fullText || '(post_menstrual_age:float)=(' || current_row.post_menstrual_age || ')';
          END IF;
          IF (current_row.birth_weight IS NOT NULL) THEN 
              fullText := fullText || '(birth_weight:float)=(' || current_row.birth_weight || ')';
          END IF;
        IF ((current_row.demographicData_info IS NOT NULL)) THEN
            fullText := fullText || '(demographicdata_info:integer)=(' || current_row.demographicdata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_demographicData_meta_data(current_row.demographicData_info, child_count,$3,false,false);
              fullText := fullText || '(demographicdata_info_demographicdata_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_abstractDemographicData_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractdemographicdata_abstractdemographicdata:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_demographicdata_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:demographicData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_demographicData_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_demographicdata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_deriveddata(character varying, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     fullText TEXT;
    begin
      FOR current_row IN SELECT * FROM (SELECT table0.id AS xnat_derivedData0, table2.element_name AS xdat_meta_element139, table0.date AS xnat_experimentData3 FROM xnat_derivedData xnat_derivedData   LEFT JOIN xnat_experimentData table0 ON xnat_derivedData.id=table0.id   LEFT JOIN xdat_meta_element table2 ON table0.extension=table2.xdat_meta_element_id) SEARCH  WHERE 
 ( (xnat_derivedData0=$1))
      LOOP
         IF (current_row.xdat_meta_element139 IS NULL) THEN 
             fullText:= ie_xnat_derivedData( $1, $2,$3,$4,$5);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element139='scr:screeningAssessment') THEN
                fullText:= i_scr_screeningAssessment( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='val:protocolData') THEN
                fullText:= i_val_protocolData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:mrAssessorData') THEN
                fullText:= ie_xnat_mrAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:petAssessorData') THEN
                fullText:= i_xnat_petAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:qcAssessmentData') THEN
                fullText:= i_xnat_qcAssessmentData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:imageAssessorData') THEN
                fullText:= ie_xnat_imageAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:qcManualAssessorData') THEN
                fullText:= i_xnat_qcManualAssessorData( $1, $2,$3,$4,$5);
                matches:=1;
            END IF;
                IF (matches=0) THEN
                    fullText:= ie_xnat_derivedData( $1, $2,$3,$4,$5);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN fullText;
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.i_xnat_deriveddata_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:derivedData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_derivedData_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_deriveddata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dicomcodedvalue(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:dicomCodedValue)(';
      FOR current_row IN SELECT * FROM xnat_dicomCodedValue WHERE  xnat_dicomcodedvalue_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.designator IS NOT NULL) THEN 
              fullText := fullText || '(designator:string)=(' || REPLACE(REPLACE(current_row.designator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.version IS NOT NULL) THEN 
              fullText := fullText || '(version:string)=(' || REPLACE(REPLACE(current_row.version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.meaning IS NOT NULL) THEN 
              fullText := fullText || '(meaning:string)=(' || REPLACE(REPLACE(current_row.meaning,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.dicomCodedValue_info IS NOT NULL)) THEN
            fullText := fullText || '(dicomcodedvalue_info:integer)=(' || current_row.dicomcodedvalue_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomCodedValue_meta_data(current_row.dicomCodedValue_info, child_count,$3,false,false);
              fullText := fullText || '(dicomcodedvalue_info_dicomcodedvalue_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_dicomcodedvalue_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_dicomcodedvalue_id:integer)=(' || current_row.xnat_dicomcodedvalue_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_dicomcodedvalue_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:dicomCodedValue_history)(';
      FOR current_row IN SELECT * FROM xnat_dicomCodedValue_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.value IS NOT NULL) THEN 
              fullText := fullText || '(value:string)=(' || REPLACE(REPLACE(current_row.value,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.designator IS NOT NULL) THEN 
              fullText := fullText || '(designator:string)=(' || REPLACE(REPLACE(current_row.designator,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.version IS NOT NULL) THEN 
              fullText := fullText || '(version:string)=(' || REPLACE(REPLACE(current_row.version,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.meaning IS NOT NULL) THEN 
              fullText := fullText || '(meaning:string)=(' || REPLACE(REPLACE(current_row.meaning,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.dicomCodedValue_info IS NOT NULL)) THEN
            fullText := fullText || '(dicomcodedvalue_info:integer)=(' || current_row.dicomcodedvalue_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomCodedValue_meta_data(current_row.dicomCodedValue_info, child_count,$3,false,false);
              fullText := fullText || '(dicomcodedvalue_info_dicomcodedvalue_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xnat_dicomcodedvalue_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_dicomcodedvalue_id:integer)=(' || current_row.xnat_dicomcodedvalue_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_dicomcodedvalue_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dicomcodedvalue_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:dicomCodedValue_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_dicomCodedValue_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_dicomcodedvalue_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dicomseries(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:dicomSeries)(';
      FOR current_row IN SELECT * FROM xnat_dicomSeries 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.dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_x:integer)=(' || current_row.dimensions_x || ')';
          END IF;
          IF (current_row.dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_y:integer)=(' || current_row.dimensions_y || ')';
          END IF;
          IF (current_row.dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_z:integer)=(' || current_row.dimensions_z || ')';
          END IF;
          IF (current_row.dimensions_volumes IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_volumes:integer)=(' || current_row.dimensions_volumes || ')';
          END IF;
          IF (current_row.voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_x:float)=(' || current_row.voxelres_x || ')';
          END IF;
          IF (current_row.voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_y:float)=(' || current_row.voxelres_y || ')';
          END IF;
          IF (current_row.voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_z:float)=(' || current_row.voxelres_z || ')';
          END IF;
          IF (current_row.voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_units:string)=(' || REPLACE(REPLACE(current_row.voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.orientation IS NOT NULL) THEN 
              fullText := fullText || '(orientation:string)=(' || REPLACE(REPLACE(current_row.orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_dicomSeries_image WHERE imageset_image_xnat_dicomSeries_xnat_abstractresource_id=current_row.xnat_abstractresource_id ORDER BY xnat_dicomseries_image_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomSeries_image( parent_row.xnat_dicomseries_image_id, child_count,$3,false,false);
              fullText := fullText || '(imageset_image_dicomseries_image' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uid IS NOT NULL) THEN 
              fullText := fullText || '(uid:string)=(' || REPLACE(REPLACE(current_row.uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.dicomSeries_info IS NOT NULL)) THEN
            fullText := fullText || '(dicomseries_info:integer)=(' || current_row.dicomseries_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomSeries_meta_data(current_row.dicomSeries_info, child_count,$3,false,false);
              fullText := fullText || '(dicomseries_info_dicomseries_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_dicomseries_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:dicomSeries_history)(';
      FOR current_row IN SELECT * FROM xnat_dicomSeries_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.dimensions_x IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_x:integer)=(' || current_row.dimensions_x || ')';
          END IF;
          IF (current_row.dimensions_y IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_y:integer)=(' || current_row.dimensions_y || ')';
          END IF;
          IF (current_row.dimensions_z IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_z:integer)=(' || current_row.dimensions_z || ')';
          END IF;
          IF (current_row.dimensions_volumes IS NOT NULL) THEN 
              fullText := fullText || '(dimensions_volumes:integer)=(' || current_row.dimensions_volumes || ')';
          END IF;
          IF (current_row.voxelres_x IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_x:float)=(' || current_row.voxelres_x || ')';
          END IF;
          IF (current_row.voxelres_y IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_y:float)=(' || current_row.voxelres_y || ')';
          END IF;
          IF (current_row.voxelres_z IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_z:float)=(' || current_row.voxelres_z || ')';
          END IF;
          IF (current_row.voxelres_units IS NOT NULL) THEN 
              fullText := fullText || '(voxelres_units:string)=(' || REPLACE(REPLACE(current_row.voxelres_units,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.orientation IS NOT NULL) THEN 
              fullText := fullText || '(orientation:string)=(' || REPLACE(REPLACE(current_row.orientation,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF($3) THEN 
        DECLARE 
  --    198
        parent_row RECORD; 
        loop_count int4:=0; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_dicomSeries_image_history WHERE imageset_image_xnat_dicomSeries_xnat_abstractresource_id=current_row.xnat_abstractresource_id AND xft_version=current_row.xft_version ORDER BY xnat_dicomseries_image_id
        LOOP
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomSeries_image_history( parent_row.xnat_dicomseries_image_id, child_count,$3,false,false);
              fullText := fullText || '(imageset_image_dicomseries_image' || loop_count || ':XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
              loop_count := loop_count+1;
        END LOOP;
        END;
        END IF; 
          IF (current_row.format IS NOT NULL) THEN 
              fullText := fullText || '(format:string)=(' || REPLACE(REPLACE(current_row.format,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.description IS NOT NULL) THEN 
              fullText := fullText || '(description:string)=(' || REPLACE(REPLACE(current_row.description,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.content IS NOT NULL) THEN 
              fullText := fullText || '(content:string)=(' || REPLACE(REPLACE(current_row.content,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.cachepath IS NOT NULL) THEN 
              fullText := fullText || '(cachepath:string)=(' || REPLACE(REPLACE(current_row.cachepath,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.uid IS NOT NULL) THEN 
              fullText := fullText || '(uid:string)=(' || REPLACE(REPLACE(current_row.uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
        IF ((current_row.dicomSeries_info IS NOT NULL)) THEN
            fullText := fullText || '(dicomseries_info:integer)=(' || current_row.dicomseries_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomSeries_meta_data(current_row.dicomSeries_info, child_count,$3,false,false);
              fullText := fullText || '(dicomseries_info_dicomseries_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
          IF (current_row.xft_version IS NOT NULL) THEN 
              fullText := fullText || '(xft_version:integer)=(' || current_row.xft_version || ')';
          END IF;
          IF (current_row.history_id IS NOT NULL) THEN 
              fullText := fullText || '(history_id:integer)=(' || current_row.history_id || ')';
          END IF;
          IF (current_row.change_user IS NOT NULL) THEN 
              fullText := fullText || '(change_user:integer)=(' || current_row.change_user || ')';
          END IF;
          IF (current_row.change_date IS NOT NULL) THEN 
              fullText := fullText || '(change_date:dateTime)=(' || current_row.change_date || ')';
          END IF;
          IF (current_row.previous_change_date IS NOT NULL) THEN 
              fullText := fullText || '(previous_change_date:dateTime)=(' || current_row.previous_change_date || ')';
          END IF;
      END LOOP;
      IF (row_ct=0) THEN 
           child_count := child_count+1;
           tempText := NULL;
           tempText := ie_xnat_abstractResource_history( $1, child_count,$3,$4,false);
              fullText := fullText || '(abstractresource_abstractresource:XFTItem)=';
              fullText := fullText || '(' || tempText || ')';
          
      END IF;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_dicomseries_image(integer, integer, boolean, boolean, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     tempText TEXT;
     fullText TEXT;
     row_ct int4;
     local_count int4;
     child_count int4;
    begin
  --    72
      local_count := $2;
      child_count := $2;
      row_ct := 0;
      fullText := 'Item:(' || local_count || '(xnat:dicomSeries_image)(';
      FOR current_row IN SELECT * FROM xnat_dicomSeries_image WHERE  xnat_dicomseries_image_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sop_instance_uid IS NOT NULL) THEN 
              fullText := fullText || '(sop_instance_uid:string)=(' || REPLACE(REPLACE(current_row.sop_instance_uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.instance_number IS NOT NULL) THEN 
              fullText := fullText || '(instance_number:integer)=(' || current_row.instance_number || ')';
          END IF;
        IF ((current_row.dicomSeries_image_info IS NOT NULL)) THEN
            fullText := fullText || '(dicomseries_image_info:integer)=(' || current_row.dicomseries_image_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomSeries_image_meta_data(current_row.dicomSeries_image_info, child_count,$3,false,false);
              fullText := fullText || '(dicomseries_image_info_dicomseries_image_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.imageset_image_xnat_dicomSeries_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(imageset_image_xnat_dicomseries_xnat_abstractresource_id:integer)=(' || current_row.imageset_image_xnat_dicomseries_xnat_abstractresource_id || ')';
        END IF;
          IF (current_row.xnat_dicomseries_image_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_dicomseries_image_id:integer)=(' || current_row.xnat_dicomseries_image_id || ')';
          END IF;
      END LOOP;
	   fullText := fullText || ')*END_ITEM*' || local_count || ')';
	
	 RETURN fullText;
    end;
$_$;


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

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

CREATE FUNCTION public.i_xnat_dicomseries_image_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:dicomSeries_image_history)(';
      FOR current_row IN SELECT * FROM xnat_dicomSeries_image_history WHERE  history_id=$1
      LOOP
           row_ct := row_ct+1;
          
          IF (current_row.uri IS NOT NULL) THEN 
              fullText := fullText || '(uri:string)=(' || REPLACE(REPLACE(current_row.uri,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.sop_instance_uid IS NOT NULL) THEN 
              fullText := fullText || '(sop_instance_uid:string)=(' || REPLACE(REPLACE(current_row.sop_instance_uid,'(','*OPEN*'),')','*CLOSE*') || ')';
          END IF;
          IF (current_row.instance_number IS NOT NULL) THEN 
              fullText := fullText || '(instance_number:integer)=(' || current_row.instance_number || ')';
          END IF;
        IF ((current_row.dicomSeries_image_info IS NOT NULL)) THEN
            fullText := fullText || '(dicomseries_image_info:integer)=(' || current_row.dicomseries_image_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dicomSeries_image_meta_data(current_row.dicomSeries_image_info, child_count,$3,false,false);
              fullText := fullText || '(dicomseries_image_info_dicomseries_image_meta_data:XFTItem)=(' || tempText || ')';
        END IF;
  -- 475
        IF ((current_row.imageset_image_xnat_dicomSeries_xnat_abstractresource_id IS NOT NULL)) THEN
            fullText := fullText || '(imageset_image_xnat_dicomseries_xnat_abstractresource_id:integer)=(' || current_row.imageset_image_xnat_dicomseries_xnat_abstractresource_id || ')';
        END IF;
          IF (current_row.xnat_dicomseries_image_id IS NOT NULL) THEN 
              fullText := fullText || '(xnat_dicomseries_image_id:integer)=(' || current_row.xnat_dicomseries_image_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_dicomseries_image_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dicomseries_image_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:dicomSeries_image_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_dicomSeries_image_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_dicomseries_image_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dicomseries_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:dicomSeries_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_dicomSeries_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_dicomseries_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

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

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

CREATE FUNCTION public.i_xnat_dx3dcraniofacialscandata_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:dx3DCraniofacialScanData_history)(';
      FOR current_row IN SELECT * FROM xnat_dx3DCraniofacialScanData_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.dx3DCraniofacialScanData_info IS NOT NULL)) THEN
            fullText := fullText || '(dx3dcraniofacialscandata_info:integer)=(' || current_row.dx3dcraniofacialscandata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dx3DCraniofacialScanData_meta_data(current_row.dx3DCraniofacialScanData_info, child_count,$3,false,false);
              fullText := fullText || '(dx3dcraniofacialscandata_info_dx3dcraniofacialscandata_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_dx3dcraniofacialscandata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dx3dcraniofacialscandata_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:dx3DCraniofacialScanData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_dx3DCraniofacialScanData_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_dx3dcraniofacialscandata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dx3dcraniofacialsessiondata(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:dx3DCraniofacialSessionData)(';
      FOR current_row IN SELECT * FROM xnat_dx3DCraniofacialSessionData 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.dx3DCraniofacialSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(dx3dcraniofacialsessiondata_info:integer)=(' || current_row.dx3dcraniofacialsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dx3DCraniofacialSessionData_meta_data(current_row.dx3DCraniofacialSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(dx3dcraniofacialsessiondata_info_dx3dcraniofacialsessiondata_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_dx3dcraniofacialsessiondata(character varying, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dx3dcraniofacialsessiondata_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:dx3DCraniofacialSessionData_history)(';
      FOR current_row IN SELECT * FROM xnat_dx3DCraniofacialSessionData_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.dx3DCraniofacialSessionData_info IS NOT NULL)) THEN
            fullText := fullText || '(dx3dcraniofacialsessiondata_info:integer)=(' || current_row.dx3dcraniofacialsessiondata_info || ')';
 -- 693
           child_count := child_count+1;
           tempText := NULL;
           tempText := i_xnat_dx3DCraniofacialSessionData_meta_data(current_row.dx3DCraniofacialSessionData_info, child_count,$3,false,false);
              fullText := fullText || '(dx3dcraniofacialsessiondata_info_dx3dcraniofacialsessiondata_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_dx3dcraniofacialsessiondata_history(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

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

CREATE FUNCTION public.i_xnat_dx3dcraniofacialsessiondata_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:dx3DCraniofacialSessionData_meta_data)(';
      FOR current_row IN SELECT * FROM xnat_dx3DCraniofacialSessionData_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_dx3dcraniofacialsessiondata_meta_data(integer, integer, boolean, boolean, boolean) OWNER TO xnat;

--
