--
--


SELECT pg_catalog.set_config('search_path', '', false);

--
-- Name: xdat_search; Type: SCHEMA; Schema: -; Owner: xnat
--

CREATE SCHEMA xdat_search;


ALTER SCHEMA xdat_search OWNER TO xnat;

--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: 
--

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


--
-- Name: sortedstrings; Type: TYPE; Schema: public; Owner: xnat
--

CREATE TYPE public.sortedstrings AS (
	strings character varying,
	sort_order integer
);


ALTER TYPE public.sortedstrings OWNER TO xnat;

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

CREATE FUNCTION public.a_arc_archivespecification(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_ArchiveSpecification.*, meta.meta_data_id, meta.status AS meta_status FROM arc_ArchiveSpecification LEFT JOIN arc_ArchiveSpecification_meta_data meta ON arc_ArchiveSpecification.ArchiveSpecification_info=meta.meta_data_id WHERE  arc_archivespecification_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_ArchiveSpecification_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.globalpaths_arc_pathinfo_id IS NOT NULL)) THEN
          PERFORM  a_arc_pathInfo(current_row.globalpaths_arc_pathinfo_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_fieldSpecification WHERE fieldspecifications_fieldspecif_arc_archivespecification_id=current_row.arc_archivespecification_id
        LOOP
          PERFORM  a_arc_fieldSpecification( parent_row.arc_fieldspecification_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_project WHERE projects_project_arc_ArchiveSpe_arc_archivespecification_id=current_row.arc_archivespecification_id
        LOOP
          PERFORM  a_arc_project( parent_row.arc_project_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_ArchiveSpecification_notification_type WHERE notification_types_notification_arc_archivespecification_id=current_row.arc_archivespecification_id
        LOOP
          PERFORM  a_arc_ArchiveSpecification_notification_type( parent_row.arc_archivespecification_notification_type_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_archivespecification_notification_type(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_ArchiveSpecification_notification_type.*, meta.meta_data_id, meta.status AS meta_status FROM arc_ArchiveSpecification_notification_type LEFT JOIN arc_ArchiveSpecification_notification_type_meta_data meta ON arc_ArchiveSpecification_notification_type.ArchiveSpecification_notification_type_info=meta.meta_data_id WHERE  arc_archivespecification_notification_type_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_ArchiveSpecification_notification_type_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_fieldspecification(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_fieldSpecification.*, meta.meta_data_id, meta.status AS meta_status FROM arc_fieldSpecification LEFT JOIN arc_fieldSpecification_meta_data meta ON arc_fieldSpecification.fieldSpecification_info=meta.meta_data_id WHERE  arc_fieldspecification_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_fieldSpecification_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_pathinfo(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_pathInfo.*, meta.meta_data_id, meta.status AS meta_status FROM arc_pathInfo LEFT JOIN arc_pathInfo_meta_data meta ON arc_pathInfo.pathInfo_info=meta.meta_data_id WHERE  arc_pathinfo_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_pathInfo_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_pipelinedata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT arc_pipelineData.arc_pipelinedata_id AS arc_pipelineData7, table1.element_name AS xdat_meta_element31, table2.insert_date AS arc_pipelineData_meta_data38 FROM arc_pipelineData arc_pipelineData   LEFT JOIN xdat_meta_element table1 ON arc_pipelineData.extension=table1.xdat_meta_element_id   LEFT JOIN arc_pipelineData_meta_data table2 ON arc_pipelineData.pipelineData_info=table2.meta_data_id) SEARCH WHERE 
 ( (arc_pipelineData7=$1))
      LOOP
         IF (current_row.xdat_meta_element31 IS NULL) THEN 
            PERFORM  ae_arc_pipelineData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element31='arc:project_descendant_pipeline') THEN
            PERFORM  a_arc_project_descendant_pipeline( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element31='arc:project_pipeline') THEN
            PERFORM  a_arc_project_pipeline( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_arc_pipelineData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_pipelineparameterdata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_pipelineParameterData.*, meta.meta_data_id, meta.status AS meta_status FROM arc_pipelineParameterData LEFT JOIN arc_pipelineParameterData_meta_data meta ON arc_pipelineParameterData.pipelineParameterData_info=meta.meta_data_id WHERE  arc_pipelineparameterdata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_pipelineParameterData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_project(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project.*, meta.meta_data_id, meta.status AS meta_status FROM arc_project LEFT JOIN arc_project_meta_data meta ON arc_project.project_info=meta.meta_data_id WHERE  arc_project_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_project_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.paths_arc_pathinfo_id IS NOT NULL)) THEN
          PERFORM  a_arc_pathInfo(current_row.paths_arc_pathinfo_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_fieldSpecification WHERE fieldspecifications_fieldspecif_arc_project_id=current_row.arc_project_id
        LOOP
          PERFORM  a_arc_fieldSpecification( parent_row.arc_fieldspecification_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_property WHERE properties_property_arc_project_arc_project_id=current_row.arc_project_id
        LOOP
          PERFORM  a_arc_property( parent_row.arc_property_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_project_descendant WHERE pipelines_descendants_descendan_arc_project_id=current_row.arc_project_id
        LOOP
          PERFORM  a_arc_project_descendant( parent_row.arc_project_descendant_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_project_pipeline WHERE pipelines_pipeline_arc_project_arc_project_id=current_row.arc_project_id
        LOOP
          PERFORM  a_arc_project_pipeline( parent_row.arc_pipelinedata_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_project_descendant(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project_descendant.*, meta.meta_data_id, meta.status AS meta_status FROM arc_project_descendant LEFT JOIN arc_project_descendant_meta_data meta ON arc_project_descendant.project_descendant_info=meta.meta_data_id WHERE  arc_project_descendant_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_project_descendant_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_project_descendant_pipeline WHERE arc_project_descendant_arc_project_descendant_id=current_row.arc_project_descendant_id
        LOOP
          PERFORM  a_arc_project_descendant_pipeline( parent_row.arc_pipelinedata_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_project_descendant_pipeline(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project_descendant_pipeline.*, meta.meta_data_id, meta.status AS meta_status FROM arc_project_descendant_pipeline LEFT JOIN arc_project_descendant_pipeline_meta_data meta ON arc_project_descendant_pipeline.project_descendant_pipeline_info=meta.meta_data_id WHERE  arc_pipelinedata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_project_descendant_pipeline_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.arc_pipelinedata_id IS NOT NULL)) THEN
          PERFORM  ae_arc_pipelineData(current_row.arc_pipelinedata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_arc_pipelineData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_project_pipeline(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_project_pipeline.*, meta.meta_data_id, meta.status AS meta_status FROM arc_project_pipeline LEFT JOIN arc_project_pipeline_meta_data meta ON arc_project_pipeline.project_pipeline_info=meta.meta_data_id WHERE  arc_pipelinedata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_project_pipeline_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.arc_pipelinedata_id IS NOT NULL)) THEN
          PERFORM  ae_arc_pipelineData(current_row.arc_pipelinedata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_arc_pipelineData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_arc_property(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT arc_property.*, meta.meta_data_id, meta.status AS meta_status FROM arc_property LEFT JOIN arc_property_meta_data meta ON arc_property.property_info=meta.meta_data_id WHERE  arc_property_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE arc_property_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_catalog(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT cat_catalog.cat_catalog_id AS cat_catalog6, table1.element_name AS xdat_meta_element105, table2.insert_date AS cat_catalog_meta_data112 FROM cat_catalog cat_catalog   LEFT JOIN xdat_meta_element table1 ON cat_catalog.extension=table1.xdat_meta_element_id   LEFT JOIN cat_catalog_meta_data table2 ON cat_catalog.catalog_info=table2.meta_data_id) SEARCH WHERE 
 ( (cat_catalog6=$1))
      LOOP
         IF (current_row.xdat_meta_element105 IS NULL) THEN 
            PERFORM  ae_cat_catalog( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element105='cat:dcmCatalog') THEN
            PERFORM  a_cat_dcmCatalog( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_cat_catalog( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_catalog_metafield(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_catalog_metaField.*, meta.meta_data_id, meta.status AS meta_status FROM cat_catalog_metaField LEFT JOIN cat_catalog_metaField_meta_data meta ON cat_catalog_metaField.catalog_metaField_info=meta.meta_data_id WHERE  cat_catalog_metafield_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE cat_catalog_metaField_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_catalog_tag(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_catalog_tag.*, meta.meta_data_id, meta.status AS meta_status FROM cat_catalog_tag LEFT JOIN cat_catalog_tag_meta_data meta ON cat_catalog_tag.catalog_tag_info=meta.meta_data_id WHERE  cat_catalog_tag_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE cat_catalog_tag_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_dcmcatalog(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_dcmCatalog.*, meta.meta_data_id, meta.status AS meta_status FROM cat_dcmCatalog LEFT JOIN cat_dcmCatalog_meta_data meta ON cat_dcmCatalog.dcmCatalog_info=meta.meta_data_id WHERE  cat_catalog_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE cat_dcmCatalog_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.cat_catalog_id IS NOT NULL)) THEN
          PERFORM  ae_cat_catalog(current_row.cat_catalog_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_cat_catalog( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_dcmentry(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_dcmEntry.*, meta.meta_data_id, meta.status AS meta_status FROM cat_dcmEntry LEFT JOIN cat_dcmEntry_meta_data meta ON cat_dcmEntry.dcmEntry_info=meta.meta_data_id WHERE  cat_entry_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE cat_dcmEntry_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.cat_entry_id IS NOT NULL)) THEN
          PERFORM  ae_cat_entry(current_row.cat_entry_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_cat_entry( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_entry(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT cat_entry.cat_entry_id AS cat_entry16, table1.element_name AS xdat_meta_element51, table2.insert_date AS cat_entry_meta_data58 FROM cat_entry cat_entry   LEFT JOIN xdat_meta_element table1 ON cat_entry.extension=table1.xdat_meta_element_id   LEFT JOIN cat_entry_meta_data table2 ON cat_entry.entry_info=table2.meta_data_id) SEARCH WHERE 
 ( (cat_entry16=$1))
      LOOP
         IF (current_row.xdat_meta_element51 IS NULL) THEN 
            PERFORM  ae_cat_entry( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element51='cat:dcmEntry') THEN
            PERFORM  a_cat_dcmEntry( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_cat_entry( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_entry_metafield(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_entry_metaField.*, meta.meta_data_id, meta.status AS meta_status FROM cat_entry_metaField LEFT JOIN cat_entry_metaField_meta_data meta ON cat_entry_metaField.entry_metaField_info=meta.meta_data_id WHERE  cat_entry_metafield_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE cat_entry_metaField_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_cat_entry_tag(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT cat_entry_tag.*, meta.meta_data_id, meta.status AS meta_status FROM cat_entry_tag LEFT JOIN cat_entry_tag_meta_data meta ON cat_entry_tag.entry_tag_info=meta.meta_data_id WHERE  cat_entry_tag_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE cat_entry_tag_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_pipe_pipelinedetails(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_pipelineDetails.*, meta.meta_data_id, meta.status AS meta_status FROM pipe_pipelineDetails LEFT JOIN pipe_pipelineDetails_meta_data meta ON pipe_pipelineDetails.pipelineDetails_info=meta.meta_data_id WHERE  path=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE pipe_pipelineDetails_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM pipe_pipelineDetails_element WHERE generateselements_element_pipe__path=current_row.path
        LOOP
          PERFORM  a_pipe_pipelineDetails_element( parent_row.pipe_pipelinedetails_element_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM pipe_pipelineDetails_parameter WHERE parameters_parameter_pipe_pipel_path=current_row.path
        LOOP
          PERFORM  a_pipe_pipelineDetails_parameter( parent_row.pipe_pipelinedetails_parameter_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_pipe_pipelinedetails_element(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_pipelineDetails_element.*, meta.meta_data_id, meta.status AS meta_status FROM pipe_pipelineDetails_element LEFT JOIN pipe_pipelineDetails_element_meta_data meta ON pipe_pipelineDetails_element.pipelineDetails_element_info=meta.meta_data_id WHERE  pipe_pipelinedetails_element_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE pipe_pipelineDetails_element_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_pipe_pipelinedetails_parameter(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_pipelineDetails_parameter.*, meta.meta_data_id, meta.status AS meta_status FROM pipe_pipelineDetails_parameter LEFT JOIN pipe_pipelineDetails_parameter_meta_data meta ON pipe_pipelineDetails_parameter.pipelineDetails_parameter_info=meta.meta_data_id WHERE  pipe_pipelinedetails_parameter_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE pipe_pipelineDetails_parameter_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_pipe_pipelinerepository(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT pipe_PipelineRepository.*, meta.meta_data_id, meta.status AS meta_status FROM pipe_PipelineRepository LEFT JOIN pipe_PipelineRepository_meta_data meta ON pipe_PipelineRepository.PipelineRepository_info=meta.meta_data_id WHERE  pipe_pipelinerepository_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE pipe_PipelineRepository_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM pipe_pipelineDetails WHERE pipe_PipelineRepository_pipe_pipelinerepository_id=current_row.pipe_pipelinerepository_id
        LOOP
          PERFORM  a_pipe_pipelineDetails( parent_row.path, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_prov_process(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT prov_process.*, meta.meta_data_id, meta.status AS meta_status FROM prov_process LEFT JOIN prov_process_meta_data meta ON prov_process.process_info=meta.meta_data_id WHERE  prov_process_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE prov_process_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM prov_processStep WHERE prov_process_prov_process_id=current_row.prov_process_id
        LOOP
          PERFORM  a_prov_processStep( parent_row.prov_processstep_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_prov_processstep(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT prov_processStep.*, meta.meta_data_id, meta.status AS meta_status FROM prov_processStep LEFT JOIN prov_processStep_meta_data meta ON prov_processStep.processStep_info=meta.meta_data_id WHERE  prov_processstep_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE prov_processStep_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM prov_processStep_library WHERE prov_processStep_prov_processstep_id=current_row.prov_processstep_id
        LOOP
          PERFORM  a_prov_processStep_library( parent_row.prov_processstep_library_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_prov_processstep_library(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT prov_processStep_library.*, meta.meta_data_id, meta.status AS meta_status FROM prov_processStep_library LEFT JOIN prov_processStep_library_meta_data meta ON prov_processStep_library.processStep_library_info=meta.meta_data_id WHERE  prov_processstep_library_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE prov_processStep_library_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_scr_screeningassessment(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT scr_screeningAssessment.*, meta.meta_data_id, meta.status AS meta_status FROM scr_screeningAssessment LEFT JOIN scr_screeningAssessment_meta_data meta ON scr_screeningAssessment.screeningAssessment_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE scr_screeningAssessment_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageAssessorData(current_row.id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM scr_screeningScanData WHERE scans_scan_scr_screeningAssessm_id=current_row.id
        LOOP
          PERFORM  a_scr_screeningScanData( parent_row.scr_screeningscandata_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_scr_screeningscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT scr_screeningScanData.*, meta.meta_data_id, meta.status AS meta_status FROM scr_screeningScanData LEFT JOIN scr_screeningScanData_meta_data meta ON scr_screeningScanData.screeningScanData_info=meta.meta_data_id WHERE  scr_screeningscandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE scr_screeningScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_val_additionalval(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_additionalVal.*, meta.meta_data_id, meta.status AS meta_status FROM val_additionalVal LEFT JOIN val_additionalVal_meta_data meta ON val_additionalVal.additionalVal_info=meta.meta_data_id WHERE  val_additionalval_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE val_additionalVal_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_val_protocoldata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData.*, meta.meta_data_id, meta.status AS meta_status FROM val_protocolData LEFT JOIN val_protocolData_meta_data meta ON val_protocolData.protocolData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE val_protocolData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageAssessorData(current_row.id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_condition WHERE check_conditions_condition_val__id=current_row.id
        LOOP
          PERFORM  a_val_protocolData_condition( parent_row.val_protocoldata_condition_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_comment WHERE check_comments_comment_val_prot_id=current_row.id
        LOOP
          PERFORM  a_val_protocolData_comment( parent_row.val_protocoldata_comment_id, $2,$3,false);
        END LOOP;
        END;
        IF ((current_row.check_additionalval_val_additionalval_id IS NOT NULL)) THEN
          PERFORM  a_val_additionalVal(current_row.check_additionalval_val_additionalval_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_scan_check WHERE scans_scan_check_val_protocolDa_id=current_row.id
        LOOP
          PERFORM  a_val_protocolData_scan_check( parent_row.val_protocoldata_scan_check_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_val_protocoldata_comment(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_comment.*, meta.meta_data_id, meta.status AS meta_status FROM val_protocolData_comment LEFT JOIN val_protocolData_comment_meta_data meta ON val_protocolData_comment.protocolData_comment_info=meta.meta_data_id WHERE  val_protocoldata_comment_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE val_protocolData_comment_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_val_protocoldata_condition(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_condition.*, meta.meta_data_id, meta.status AS meta_status FROM val_protocolData_condition LEFT JOIN val_protocolData_condition_meta_data meta ON val_protocolData_condition.protocolData_condition_info=meta.meta_data_id WHERE  val_protocoldata_condition_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE val_protocolData_condition_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_val_protocoldata_scan_check(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_scan_check.*, meta.meta_data_id, meta.status AS meta_status FROM val_protocolData_scan_check LEFT JOIN val_protocolData_scan_check_meta_data meta ON val_protocolData_scan_check.protocolData_scan_check_info=meta.meta_data_id WHERE  val_protocoldata_scan_check_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE val_protocolData_scan_check_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_scan_check_condition WHERE conditions_condition_val_protoc_val_protocoldata_scan_check_id=current_row.val_protocoldata_scan_check_id
        LOOP
          PERFORM  a_val_protocolData_scan_check_condition( parent_row.val_protocoldata_scan_check_condition_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_scan_check_comment WHERE comments_comment_val_protocolDa_val_protocoldata_scan_check_id=current_row.val_protocoldata_scan_check_id
        LOOP
          PERFORM  a_val_protocolData_scan_check_comment( parent_row.val_protocoldata_scan_check_comment_id, $2,$3,false);
        END LOOP;
        END;
        IF ((current_row.additionalval_val_additionalval_id IS NOT NULL)) THEN
          PERFORM  a_val_additionalVal(current_row.additionalval_val_additionalval_id, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_val_protocoldata_scan_check_comment(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_scan_check_comment.*, meta.meta_data_id, meta.status AS meta_status FROM val_protocolData_scan_check_comment LEFT JOIN val_protocolData_scan_check_comment_meta_data meta ON val_protocolData_scan_check_comment.protocolData_scan_check_comment_info=meta.meta_data_id WHERE  val_protocoldata_scan_check_comment_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE val_protocolData_scan_check_comment_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_val_protocoldata_scan_check_condition(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_scan_check_condition.*, meta.meta_data_id, meta.status AS meta_status FROM val_protocolData_scan_check_condition LEFT JOIN val_protocolData_scan_check_condition_meta_data meta ON val_protocolData_scan_check_condition.protocolData_scan_check_condition_info=meta.meta_data_id WHERE  val_protocoldata_scan_check_condition_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE val_protocolData_scan_check_condition_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_wrk_abstractexecutionenvironment(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT wrk_abstractExecutionEnvironment.wrk_abstractexecutionenvironment_id AS wrk_abstractExecutionEnvironment2, table1.element_name AS xdat_meta_element3, table2.insert_date AS wrk_abstractExecutionEnvironment_meta_data10 FROM wrk_abstractExecutionEnvironment wrk_abstractExecutionEnvironment   LEFT JOIN xdat_meta_element table1 ON wrk_abstractExecutionEnvironment.extension=table1.xdat_meta_element_id   LEFT JOIN wrk_abstractExecutionEnvironment_meta_data table2 ON wrk_abstractExecutionEnvironment.abstractExecutionEnvironment_info=table2.meta_data_id) SEARCH WHERE 
 ( (wrk_abstractExecutionEnvironment2=$1))
      LOOP
         IF (current_row.xdat_meta_element3 IS NULL) THEN 
            PERFORM  ae_wrk_abstractExecutionEnvironment( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='wrk:xnatExecutionEnvironment') THEN
            PERFORM  a_wrk_xnatExecutionEnvironment( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_wrk_abstractExecutionEnvironment( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_wrk_workflowdata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_workflowData.*, meta.meta_data_id, meta.status AS meta_status FROM wrk_workflowData LEFT JOIN wrk_workflowData_meta_data meta ON wrk_workflowData.workflowData_info=meta.meta_data_id WHERE  wrk_workflowdata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE wrk_workflowData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.executionenvironment_wrk_abstractexecutionenvironment_id IS NOT NULL)) THEN
          PERFORM  a_wrk_abstractExecutionEnvironment(current_row.executionenvironment_wrk_abstractexecutionenvironment_id, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_wrk_xnatexecutionenvironment(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_xnatExecutionEnvironment.*, meta.meta_data_id, meta.status AS meta_status FROM wrk_xnatExecutionEnvironment LEFT JOIN wrk_xnatExecutionEnvironment_meta_data meta ON wrk_xnatExecutionEnvironment.xnatExecutionEnvironment_info=meta.meta_data_id WHERE  wrk_abstractexecutionenvironment_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE wrk_xnatExecutionEnvironment_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.wrk_abstractexecutionenvironment_id IS NOT NULL)) THEN
          PERFORM  ae_wrk_abstractExecutionEnvironment(current_row.wrk_abstractexecutionenvironment_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM wrk_xnatExecutionEnvironment_parameter WHERE parameters_parameter_wrk_xnatEx_wrk_abstractexecutionenvironmen=current_row.wrk_abstractexecutionenvironment_id
        LOOP
          PERFORM  a_wrk_xnatExecutionEnvironment_parameter( parent_row.wrk_xnatexecutionenvironment_parameter_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM wrk_xnatExecutionEnvironment_notify WHERE wrk_xnatExecutionEnvironment_wrk_abstractexecutionenvironmen=current_row.wrk_abstractexecutionenvironment_id
        LOOP
          PERFORM  a_wrk_xnatExecutionEnvironment_notify( parent_row.wrk_xnatexecutionenvironment_notify_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_wrk_abstractExecutionEnvironment( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_wrk_xnatexecutionenvironment_notify(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_xnatExecutionEnvironment_notify.*, meta.meta_data_id, meta.status AS meta_status FROM wrk_xnatExecutionEnvironment_notify LEFT JOIN wrk_xnatExecutionEnvironment_notify_meta_data meta ON wrk_xnatExecutionEnvironment_notify.xnatExecutionEnvironment_notify_info=meta.meta_data_id WHERE  wrk_xnatexecutionenvironment_notify_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE wrk_xnatExecutionEnvironment_notify_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_wrk_xnatexecutionenvironment_parameter(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_xnatExecutionEnvironment_parameter.*, meta.meta_data_id, meta.status AS meta_status FROM wrk_xnatExecutionEnvironment_parameter LEFT JOIN wrk_xnatExecutionEnvironment_parameter_meta_data meta ON wrk_xnatExecutionEnvironment_parameter.xnatExecutionEnvironment_parameter_info=meta.meta_data_id WHERE  wrk_xnatexecutionenvironment_parameter_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE wrk_xnatExecutionEnvironment_parameter_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_access_log(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_access_log.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_access_log LEFT JOIN xdat_access_log_meta_data meta ON xdat_access_log.access_log_info=meta.meta_data_id WHERE  xdat_access_log_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_access_log_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_action_type(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_action_type.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_action_type LEFT JOIN xdat_action_type_meta_data meta ON xdat_action_type.action_type_info=meta.meta_data_id WHERE  action_name=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_action_type_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_change_info(bigint, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_change_info.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_change_info LEFT JOIN xdat_change_info_meta_data meta ON xdat_change_info.change_info_info=meta.meta_data_id WHERE  xdat_change_info_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_change_info_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.change_user IS NOT NULL)) THEN
          PERFORM  a_xdat_user(current_row.change_user, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_criteria(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_criteria.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_criteria LEFT JOIN xdat_criteria_meta_data meta ON xdat_criteria.criteria_info=meta.meta_data_id WHERE  xdat_criteria_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_criteria_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_criteria_set(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_criteria_set.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_criteria_set LEFT JOIN xdat_criteria_set_meta_data meta ON xdat_criteria_set.criteria_set_info=meta.meta_data_id WHERE  xdat_criteria_set_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_criteria_set_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_criteria WHERE xdat_criteria_set_xdat_criteria_set_id=current_row.xdat_criteria_set_id
        LOOP
          PERFORM  a_xdat_criteria( parent_row.xdat_criteria_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_criteria_set WHERE child_set_xdat_criteria_set_id=current_row.xdat_criteria_set_id
        LOOP
          PERFORM  a_xdat_criteria_set( parent_row.xdat_criteria_set_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_element_access(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_access.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_element_access LEFT JOIN xdat_element_access_meta_data meta ON xdat_element_access.element_access_info=meta.meta_data_id WHERE  xdat_element_access_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_element_access_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_access_secure_ip WHERE xdat_element_access_xdat_element_access_id=current_row.xdat_element_access_id
        LOOP
          PERFORM  a_xdat_element_access_secure_ip( parent_row.xdat_element_access_secure_ip_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_field_mapping_set WHERE permissions_allow_set_xdat_elem_xdat_element_access_id=current_row.xdat_element_access_id
        LOOP
          PERFORM  a_xdat_field_mapping_set( parent_row.xdat_field_mapping_set_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_element_access_secure_ip(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_access_secure_ip.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_element_access_secure_ip LEFT JOIN xdat_element_access_secure_ip_meta_data meta ON xdat_element_access_secure_ip.element_access_secure_ip_info=meta.meta_data_id WHERE  xdat_element_access_secure_ip_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_element_access_secure_ip_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_element_action_type(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_action_type.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_element_action_type LEFT JOIN xdat_element_action_type_meta_data meta ON xdat_element_action_type.element_action_type_info=meta.meta_data_id WHERE  xdat_element_action_type_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_element_action_type_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_element_security(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_security.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_element_security LEFT JOIN xdat_element_security_meta_data meta ON xdat_element_security.element_security_info=meta.meta_data_id WHERE  element_name=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_element_security_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_primary_security_field WHERE primary_security_fields_primary_element_name=current_row.element_name
        LOOP
          PERFORM  a_xdat_primary_security_field( parent_row.xdat_primary_security_field_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_action_type WHERE element_actions_element_action__element_name=current_row.element_name
        LOOP
          PERFORM  a_xdat_element_action_type( parent_row.xdat_element_action_type_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_security_listing_action WHERE listing_actions_listing_action__element_name=current_row.element_name
        LOOP
          PERFORM  a_xdat_element_security_listing_action( parent_row.xdat_element_security_listing_action_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_element_security_listing_action(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_security_listing_action.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_element_security_listing_action LEFT JOIN xdat_element_security_listing_action_meta_data meta ON xdat_element_security_listing_action.element_security_listing_action_info=meta.meta_data_id WHERE  xdat_element_security_listing_action_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_element_security_listing_action_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_field_mapping(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_field_mapping.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_field_mapping LEFT JOIN xdat_field_mapping_meta_data meta ON xdat_field_mapping.field_mapping_info=meta.meta_data_id WHERE  xdat_field_mapping_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_field_mapping_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_field_mapping_set(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_field_mapping_set.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_field_mapping_set LEFT JOIN xdat_field_mapping_set_meta_data meta ON xdat_field_mapping_set.field_mapping_set_info=meta.meta_data_id WHERE  xdat_field_mapping_set_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_field_mapping_set_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_field_mapping WHERE xdat_field_mapping_set_xdat_field_mapping_set_id=current_row.xdat_field_mapping_set_id
        LOOP
          PERFORM  a_xdat_field_mapping( parent_row.xdat_field_mapping_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_field_mapping_set WHERE sub_set_xdat_field_mapping_set_id=current_row.xdat_field_mapping_set_id
        LOOP
          PERFORM  a_xdat_field_mapping_set( parent_row.xdat_field_mapping_set_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_infoentry(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_infoEntry.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_infoEntry LEFT JOIN xdat_infoEntry_meta_data meta ON xdat_infoEntry.infoEntry_info=meta.meta_data_id WHERE  xdat_infoentry_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_infoEntry_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_meta_element(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_meta_element.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_meta_element LEFT JOIN xdat_meta_element_meta_data meta ON xdat_meta_element.meta_element_info=meta.meta_data_id WHERE  xdat_meta_element_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_meta_element_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_newsentry(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_newsEntry.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_newsEntry LEFT JOIN xdat_newsEntry_meta_data meta ON xdat_newsEntry.newsEntry_info=meta.meta_data_id WHERE  xdat_newsentry_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_newsEntry_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_primary_security_field(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_primary_security_field.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_primary_security_field LEFT JOIN xdat_primary_security_field_meta_data meta ON xdat_primary_security_field.primary_security_field_info=meta.meta_data_id WHERE  xdat_primary_security_field_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_primary_security_field_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_role_type(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_role_type.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_role_type LEFT JOIN xdat_role_type_meta_data meta ON xdat_role_type.role_type_info=meta.meta_data_id WHERE  role_name=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_role_type_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_a_xdat_action_type_allowe_xdat_role_type WHERE  xdat_role_type_role_name=current_row.role_name
        LOOP
          PERFORM  a_xdat_action_type( mapping_row.xdat_action_type_action_name, $2,$3,false);
        END LOOP;
        END; 
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_search(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_Search.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_Search LEFT JOIN xdat_Search_meta_data meta ON xdat_Search.Search_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_Search_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xdat_stored_search(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xdat_stored_search( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_search_field(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_search_field.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_search_field LEFT JOIN xdat_search_field_meta_data meta ON xdat_search_field.search_field_info=meta.meta_data_id WHERE  xdat_search_field_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_search_field_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_security(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_security.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_security LEFT JOIN xdat_security_meta_data meta ON xdat_security.security_info=meta.meta_data_id WHERE  xdat_security_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_security_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_userGroup WHERE groups_group_xdat_security_xdat_security_id=current_row.xdat_security_id
        LOOP
          PERFORM  a_xdat_userGroup( parent_row.xdat_usergroup_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_user WHERE users_user_xdat_security_xdat_security_id=current_row.xdat_security_id
        LOOP
          PERFORM  a_xdat_user( parent_row.xdat_user_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_role_type WHERE roles_role_xdat_security_xdat_security_id=current_row.xdat_security_id
        LOOP
          PERFORM  a_xdat_role_type( parent_row.role_name, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_action_type WHERE actions_action_xdat_security_xdat_security_id=current_row.xdat_security_id
        LOOP
          PERFORM  a_xdat_action_type( parent_row.action_name, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_security WHERE element_security_set_element_se_xdat_security_id=current_row.xdat_security_id
        LOOP
          PERFORM  a_xdat_element_security( parent_row.element_name, $2,$3,false);
        END LOOP;
        END;
        IF ((current_row.newslist_news_xdat_newsentry_id IS NOT NULL)) THEN
          PERFORM  a_xdat_newsEntry(current_row.newslist_news_xdat_newsentry_id, $2,$3,false);
        END IF;
        IF ((current_row.infolist_info_xdat_infoentry_id IS NOT NULL)) THEN
          PERFORM  a_xdat_infoEntry(current_row.infolist_info_xdat_infoentry_id, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_stored_search(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT xdat_stored_search.id AS xdat_stored_search3, table1.element_name AS xdat_meta_element103, table2.insert_date AS xdat_stored_search_meta_data110 FROM xdat_stored_search xdat_stored_search   LEFT JOIN xdat_meta_element table1 ON xdat_stored_search.extension=table1.xdat_meta_element_id   LEFT JOIN xdat_stored_search_meta_data table2 ON xdat_stored_search.stored_search_info=table2.meta_data_id) SEARCH WHERE 
 ( (xdat_stored_search3=$1))
      LOOP
         IF (current_row.xdat_meta_element103 IS NULL) THEN 
            PERFORM  ae_xdat_stored_search( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element103='xdat:Search') THEN
            PERFORM  a_xdat_Search( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xdat_stored_search( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_stored_search_allowed_user(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_stored_search_allowed_user.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_stored_search_allowed_user LEFT JOIN xdat_stored_search_allowed_user_meta_data meta ON xdat_stored_search_allowed_user.stored_search_allowed_user_info=meta.meta_data_id WHERE  xdat_stored_search_allowed_user_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_stored_search_allowed_user_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_stored_search_groupid(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_stored_search_groupID.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_stored_search_groupID LEFT JOIN xdat_stored_search_groupID_meta_data meta ON xdat_stored_search_groupID.stored_search_groupID_info=meta.meta_data_id WHERE  xdat_stored_search_groupid_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_stored_search_groupID_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_user(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_user.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_user LEFT JOIN xdat_user_meta_data meta ON xdat_user.user_info=meta.meta_data_id WHERE  xdat_user_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_user_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_access WHERE xdat_user_xdat_user_id=current_row.xdat_user_id
        LOOP
          PERFORM  a_xdat_element_access( parent_row.xdat_element_access_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_r_xdat_role_type_assign_xdat_user WHERE  xdat_user_xdat_user_id=current_row.xdat_user_id
        LOOP
          PERFORM  a_xdat_role_type( mapping_row.xdat_role_type_role_name, $2,$3,false);
        END LOOP;
        END; 
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_user_groupID WHERE groups_groupid_xdat_user_xdat_user_id=current_row.xdat_user_id
        LOOP
          PERFORM  a_xdat_user_groupID( parent_row.xdat_user_groupid_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_user_groupid(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_user_groupID.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_user_groupID LEFT JOIN xdat_user_groupID_meta_data meta ON xdat_user_groupID.user_groupID_info=meta.meta_data_id WHERE  xdat_user_groupid_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_user_groupID_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_user_login(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_user_login.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_user_login LEFT JOIN xdat_user_login_meta_data meta ON xdat_user_login.user_login_info=meta.meta_data_id WHERE  xdat_user_login_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_user_login_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.user_xdat_user_id IS NOT NULL)) THEN
          PERFORM  a_xdat_user(current_row.user_xdat_user_id, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xdat_usergroup(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_userGroup.*, meta.meta_data_id, meta.status AS meta_status FROM xdat_userGroup LEFT JOIN xdat_userGroup_meta_data meta ON xdat_userGroup.userGroup_info=meta.meta_data_id WHERE  xdat_usergroup_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xdat_userGroup_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_element_access WHERE xdat_userGroup_xdat_usergroup_id=current_row.xdat_usergroup_id
        LOOP
          PERFORM  a_xdat_element_access( parent_row.xdat_element_access_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_a_scidresearchdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_scidResearchData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_a_scidResearchData LEFT JOIN xnat_a_scidResearchData_meta_data meta ON xnat_a_scidResearchData.scidResearchData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_a_scidResearchData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_subjectAssessorData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_subjectAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_a_sideeffectspittsburghdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_sideEffectsPittsburghData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_a_sideEffectsPittsburghData LEFT JOIN xnat_a_sideEffectsPittsburghData_meta_data meta ON xnat_a_sideEffectsPittsburghData.sideEffectsPittsburghData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_a_sideEffectsPittsburghData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_subjectAssessorData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_subjectAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_a_updrs3data(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_updrs3Data.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_a_updrs3Data LEFT JOIN xnat_a_updrs3Data_meta_data meta ON xnat_a_updrs3Data.updrs3Data_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_a_updrs3Data_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_subjectAssessorData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_subjectAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_a_ybocsdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_ybocsData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_a_ybocsData LEFT JOIN xnat_a_ybocsData_meta_data meta ON xnat_a_ybocsData.ybocsData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_a_ybocsData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_subjectAssessorData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_subjectAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_a_ygtssdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_ygtssData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_a_ygtssData LEFT JOIN xnat_a_ygtssData_meta_data meta ON xnat_a_ygtssData.ygtssData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_a_ygtssData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_subjectAssessorData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_subjectAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_abstractdemographicdata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    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 
            PERFORM  ae_xnat_abstractDemographicData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:demographicData') THEN
            PERFORM  a_xnat_demographicData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_abstractDemographicData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_abstractprotocol(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    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 
            PERFORM  ae_xnat_abstractProtocol( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element8='xnat:studyProtocol') THEN
            PERFORM  a_xnat_studyProtocol( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element8='xnat:datatypeProtocol') THEN
            PERFORM  a_xnat_datatypeProtocol( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_abstractProtocol( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_abstractresource(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    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 
            PERFORM  ae_xnat_abstractResource( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element25='xnat:resource') THEN
            PERFORM  ae_xnat_resource( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageResource') THEN
            PERFORM  a_xnat_imageResource( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:resourceSeries') THEN
            PERFORM  ae_xnat_resourceSeries( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageResourceSeries') THEN
            PERFORM  a_xnat_imageResourceSeries( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:dicomSeries') THEN
            PERFORM  a_xnat_dicomSeries( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:publicationResource') THEN
            PERFORM  a_xnat_publicationResource( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:resourceCatalog') THEN
            PERFORM  a_xnat_resourceCatalog( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_abstractResource( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_abstractresource_tag(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_abstractResource_tag.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_abstractResource_tag LEFT JOIN xnat_abstractResource_tag_meta_data meta ON xnat_abstractResource_tag.abstractResource_tag_info=meta.meta_data_id WHERE  xnat_abstractresource_tag_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_abstractResource_tag_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_abstractstatistics(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    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 
            PERFORM  ae_xnat_abstractStatistics( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:statisticsData') THEN
            PERFORM  a_xnat_statisticsData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_abstractStatistics( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_abstractsubjectmetadata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    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 
            PERFORM  ae_xnat_abstractSubjectMetadata( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:subjectMetadata') THEN
            PERFORM  a_xnat_subjectMetadata( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_abstractSubjectMetadata( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_addfield(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_addField.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_addField LEFT JOIN xnat_addField_meta_data meta ON xnat_addField.addField_info=meta.meta_data_id WHERE  xnat_addfield_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_addField_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_algorithm(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_algorithm.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_algorithm LEFT JOIN xnat_algorithm_meta_data meta ON xnat_algorithm.algorithm_info=meta.meta_data_id WHERE  xnat_algorithm_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_algorithm_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.family_xnat_dicomcodedvalue_id IS NOT NULL)) THEN
          PERFORM  a_xnat_dicomCodedValue(current_row.family_xnat_dicomcodedvalue_id, $2,$3,false);
        END IF;
        IF ((current_row.namecode_xnat_dicomcodedvalue_id IS NOT NULL)) THEN
          PERFORM  a_xnat_dicomCodedValue(current_row.namecode_xnat_dicomcodedvalue_id, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_computationdata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_computationData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_computationData LEFT JOIN xnat_computationData_meta_data meta ON xnat_computationData.computationData_info=meta.meta_data_id WHERE  xnat_computationdata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_computationData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_contrastbolus(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_contrastBolus.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_contrastBolus LEFT JOIN xnat_contrastBolus_meta_data meta ON xnat_contrastBolus.contrastBolus_info=meta.meta_data_id WHERE  xnat_contrastbolus_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_contrastBolus_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_crscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_crScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_crScanData LEFT JOIN xnat_crScanData_meta_data meta ON xnat_crScanData.crScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_crScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_crsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_crSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_crSessionData LEFT JOIN xnat_crSessionData_meta_data meta ON xnat_crSessionData.crSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_crSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_ctscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ctScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_ctScanData LEFT JOIN xnat_ctScanData_meta_data meta ON xnat_ctScanData.ctScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_ctScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_ctScanData_focalSpot WHERE parameters_focalspots_focalspot_xnat_imagescandata_id=current_row.xnat_imagescandata_id
        LOOP
          PERFORM  a_xnat_ctScanData_focalSpot( parent_row.xnat_ctscandata_focalspot_id, $2,$3,false);
        END LOOP;
        END;
        IF ((current_row.parameters_contrastbolus_xnat_contrastbolus_id IS NOT NULL)) THEN
          PERFORM  a_xnat_contrastBolus(current_row.parameters_contrastbolus_xnat_contrastbolus_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_ctscandata_focalspot(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ctScanData_focalSpot.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_ctScanData_focalSpot LEFT JOIN xnat_ctScanData_focalSpot_meta_data meta ON xnat_ctScanData_focalSpot.ctScanData_focalSpot_info=meta.meta_data_id WHERE  xnat_ctscandata_focalspot_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_ctScanData_focalSpot_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_ctsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ctSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_ctSessionData LEFT JOIN xnat_ctSessionData_meta_data meta ON xnat_ctSessionData.ctSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_ctSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_datatypeprotocol(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_datatypeProtocol.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_datatypeProtocol LEFT JOIN xnat_datatypeProtocol_meta_data meta ON xnat_datatypeProtocol.datatypeProtocol_info=meta.meta_data_id WHERE  xnat_abstractprotocol_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_datatypeProtocol_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_abstractprotocol_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_abstractProtocol(current_row.xnat_abstractprotocol_id, $2,$3,false);
        END IF;
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_datatypeProtocol_fieldGroups WHERE  xnat_datatypeProtocol_xnat_abstractprotocol_id=current_row.xnat_abstractprotocol_id
        LOOP
          PERFORM  a_xnat_fieldDefinitionGroup( mapping_row.xnat_fieldDefinitionGroup_xnat_fielddefinitiongroup_id, $2,$3,false);
        END LOOP;
        END; 
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_abstractProtocol( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_demographicdata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_demographicData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_demographicData LEFT JOIN xnat_demographicData_meta_data meta ON xnat_demographicData.demographicData_info=meta.meta_data_id WHERE  xnat_abstractdemographicdata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_demographicData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_abstractdemographicdata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_abstractDemographicData(current_row.xnat_abstractdemographicdata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_abstractDemographicData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_deriveddata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    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 
            PERFORM  ae_xnat_derivedData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element139='scr:screeningAssessment') THEN
            PERFORM  a_scr_screeningAssessment( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='val:protocolData') THEN
            PERFORM  a_val_protocolData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:mrAssessorData') THEN
            PERFORM  ae_xnat_mrAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:petAssessorData') THEN
            PERFORM  a_xnat_petAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:qcAssessmentData') THEN
            PERFORM  a_xnat_qcAssessmentData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:imageAssessorData') THEN
            PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:qcManualAssessorData') THEN
            PERFORM  a_xnat_qcManualAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_derivedData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_dicomcodedvalue(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dicomCodedValue.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_dicomCodedValue LEFT JOIN xnat_dicomCodedValue_meta_data meta ON xnat_dicomCodedValue.dicomCodedValue_info=meta.meta_data_id WHERE  xnat_dicomcodedvalue_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_dicomCodedValue_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_dicomseries(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dicomSeries.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_dicomSeries LEFT JOIN xnat_dicomSeries_meta_data meta ON xnat_dicomSeries.dicomSeries_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_dicomSeries_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_abstractResource(current_row.xnat_abstractresource_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_dicomSeries_image WHERE imageset_image_xnat_dicomSeries_xnat_abstractresource_id=current_row.xnat_abstractresource_id
        LOOP
          PERFORM  a_xnat_dicomSeries_image( parent_row.xnat_dicomseries_image_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_abstractResource( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_dicomseries_image(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dicomSeries_image.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_dicomSeries_image LEFT JOIN xnat_dicomSeries_image_meta_data meta ON xnat_dicomSeries_image.dicomSeries_image_info=meta.meta_data_id WHERE  xnat_dicomseries_image_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_dicomSeries_image_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_dx3dcraniofacialscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dx3DCraniofacialScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_dx3DCraniofacialScanData LEFT JOIN xnat_dx3DCraniofacialScanData_meta_data meta ON xnat_dx3DCraniofacialScanData.dx3DCraniofacialScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_dx3DCraniofacialScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_dx3dcraniofacialsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dx3DCraniofacialSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_dx3DCraniofacialSessionData LEFT JOIN xnat_dx3DCraniofacialSessionData_meta_data meta ON xnat_dx3DCraniofacialSessionData.dx3DCraniofacialSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_dx3DCraniofacialSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_dxscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dxScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_dxScanData LEFT JOIN xnat_dxScanData_meta_data meta ON xnat_dxScanData.dxScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_dxScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_dxsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dxSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_dxSessionData LEFT JOIN xnat_dxSessionData_meta_data meta ON xnat_dxSessionData.dxSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_dxSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_ecgscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ecgScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_ecgScanData LEFT JOIN xnat_ecgScanData_meta_data meta ON xnat_ecgScanData.ecgScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_ecgScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_ecgsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ecgSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_ecgSessionData LEFT JOIN xnat_ecgSessionData_meta_data meta ON xnat_ecgSessionData.ecgSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_ecgSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_eegscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_eegScanData LEFT JOIN xnat_eegScanData_meta_data meta ON xnat_eegScanData.eegScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_eegScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_eegScanData_channel WHERE channels_channel_xnat_eegScanDa_xnat_imagescandata_id=current_row.xnat_imagescandata_id
        LOOP
          PERFORM  a_xnat_eegScanData_channel( parent_row.xnat_eegscandata_channel_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_eegScanData_impedance WHERE softwarefiltersimpedances_imped_xnat_imagescandata_id=current_row.xnat_imagescandata_id
        LOOP
          PERFORM  a_xnat_eegScanData_impedance( parent_row.xnat_eegscandata_impedance_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_eegscandata_channel(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegScanData_channel.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_eegScanData_channel LEFT JOIN xnat_eegScanData_channel_meta_data meta ON xnat_eegScanData_channel.eegScanData_channel_info=meta.meta_data_id WHERE  xnat_eegscandata_channel_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_eegScanData_channel_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_eegscandata_impedance(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegScanData_impedance.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_eegScanData_impedance LEFT JOIN xnat_eegScanData_impedance_meta_data meta ON xnat_eegScanData_impedance.eegScanData_impedance_info=meta.meta_data_id WHERE  xnat_eegscandata_impedance_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_eegScanData_impedance_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_eegsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_eegSessionData LEFT JOIN xnat_eegSessionData_meta_data meta ON xnat_eegSessionData.eegSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_eegSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_epsscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_epsScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_epsScanData LEFT JOIN xnat_epsScanData_meta_data meta ON xnat_epsScanData.epsScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_epsScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_epssessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_epsSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_epsSessionData LEFT JOIN xnat_epsSessionData_meta_data meta ON xnat_epsSessionData.epsSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_epsSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_esscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_esScanData LEFT JOIN xnat_esScanData_meta_data meta ON xnat_esScanData.esScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_esScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_essessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_esSessionData LEFT JOIN xnat_esSessionData_meta_data meta ON xnat_esSessionData.esSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_esSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_esvscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esvScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_esvScanData LEFT JOIN xnat_esvScanData_meta_data meta ON xnat_esvScanData.esvScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_esvScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_esvsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esvSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_esvSessionData LEFT JOIN xnat_esvSessionData_meta_data meta ON xnat_esvSessionData.esvSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_esvSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_experimentdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_experimentData.id AS xnat_experimentData9, table1.element_name AS xdat_meta_element136, xnat_experimentData.date AS xnat_experimentData0 FROM xnat_experimentData xnat_experimentData   LEFT JOIN xdat_meta_element table1 ON xnat_experimentData.extension=table1.xdat_meta_element_id) SEARCH WHERE 
 ( (xnat_experimentData9=$1))
      LOOP
         IF (current_row.xdat_meta_element136 IS NULL) THEN 
            PERFORM  ae_xnat_experimentData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element136='scr:screeningAssessment') THEN
            PERFORM  a_scr_screeningAssessment( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='val:protocolData') THEN
            PERFORM  a_val_protocolData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:genericData') THEN
            PERFORM  ae_xnat_genericData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:pVisitData') THEN
            PERFORM  a_xnat_pVisitData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:subjectAssessorData') THEN
            PERFORM  ae_xnat_subjectAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:subjectVariablesData') THEN
            PERFORM  a_xnat_subjectVariablesData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:imageSessionData') THEN
            PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mrSessionData') THEN
            PERFORM  a_xnat_mrSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mrAssessorData') THEN
            PERFORM  ae_xnat_mrAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:derivedData') THEN
            PERFORM  ae_xnat_derivedData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petAssessorData') THEN
            PERFORM  a_xnat_petAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petSessionData') THEN
            PERFORM  a_xnat_petSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petmrSessionData') THEN
            PERFORM  a_xnat_petmrSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:qcAssessmentData') THEN
            PERFORM  a_xnat_qcAssessmentData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:imageAssessorData') THEN
            PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ctSessionData') THEN
            PERFORM  a_xnat_ctSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:crSessionData') THEN
            PERFORM  a_xnat_crSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:dxSessionData') THEN
            PERFORM  a_xnat_dxSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mgSessionData') THEN
            PERFORM  a_xnat_mgSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ioSessionData') THEN
            PERFORM  a_xnat_ioSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:usSessionData') THEN
            PERFORM  a_xnat_usSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ecgSessionData') THEN
            PERFORM  a_xnat_ecgSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:hdSessionData') THEN
            PERFORM  a_xnat_hdSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:epsSessionData') THEN
            PERFORM  a_xnat_epsSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xaSessionData') THEN
            PERFORM  a_xnat_xaSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:rfSessionData') THEN
            PERFORM  a_xnat_rfSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xa3DSessionData') THEN
            PERFORM  a_xnat_xa3DSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:dx3DCraniofacialSessionData') THEN
            PERFORM  a_xnat_dx3DCraniofacialSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:nmSessionData') THEN
            PERFORM  a_xnat_nmSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:srSessionData') THEN
            PERFORM  a_xnat_srSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:esSessionData') THEN
            PERFORM  a_xnat_esSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:esvSessionData') THEN
            PERFORM  a_xnat_esvSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:gmSessionData') THEN
            PERFORM  a_xnat_gmSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:gmvSessionData') THEN
            PERFORM  a_xnat_gmvSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:smSessionData') THEN
            PERFORM  a_xnat_smSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xcSessionData') THEN
            PERFORM  a_xnat_xcSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xcvSessionData') THEN
            PERFORM  a_xnat_xcvSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:opSessionData') THEN
            PERFORM  a_xnat_opSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:optSessionData') THEN
            PERFORM  a_xnat_optSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:rtSessionData') THEN
            PERFORM  a_xnat_rtSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:otherDicomSessionData') THEN
            PERFORM  a_xnat_otherDicomSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:qcManualAssessorData') THEN
            PERFORM  a_xnat_qcManualAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:megSessionData') THEN
            PERFORM  a_xnat_megSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:eegSessionData') THEN
            PERFORM  a_xnat_eegSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:sideEffectsPittsburghData') THEN
            PERFORM  a_xnat_a_sideEffectsPittsburghData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:ybocsData') THEN
            PERFORM  a_xnat_a_ybocsData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:ygtssData') THEN
            PERFORM  a_xnat_a_ygtssData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:updrs3Data') THEN
            PERFORM  a_xnat_a_updrs3Data( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:scidResearchData') THEN
            PERFORM  a_xnat_a_scidResearchData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_experimentData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_experimentdata_field(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_experimentData_field.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_experimentData_field LEFT JOIN xnat_experimentData_field_meta_data meta ON xnat_experimentData_field.experimentData_field_info=meta.meta_data_id WHERE  xnat_experimentdata_field_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_experimentData_field_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_experimentdata_share(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_experimentData_share.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_experimentData_share LEFT JOIN xnat_experimentData_share_meta_data meta ON xnat_experimentData_share.experimentData_share_info=meta.meta_data_id WHERE  xnat_experimentdata_share_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_experimentData_share_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_fielddefinitiongroup(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_fieldDefinitionGroup.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_fieldDefinitionGroup LEFT JOIN xnat_fieldDefinitionGroup_meta_data meta ON xnat_fieldDefinitionGroup.fieldDefinitionGroup_info=meta.meta_data_id WHERE  xnat_fielddefinitiongroup_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_fieldDefinitionGroup_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_fieldDefinitionGroup_field WHERE fields_field_xnat_fieldDefiniti_xnat_fielddefinitiongroup_id=current_row.xnat_fielddefinitiongroup_id
        LOOP
          PERFORM  a_xnat_fieldDefinitionGroup_field( parent_row.xnat_fielddefinitiongroup_field_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_fielddefinitiongroup_field(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_fieldDefinitionGroup_field.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_fieldDefinitionGroup_field LEFT JOIN xnat_fieldDefinitionGroup_field_meta_data meta ON xnat_fieldDefinitionGroup_field.fieldDefinitionGroup_field_info=meta.meta_data_id WHERE  xnat_fielddefinitiongroup_field_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_fieldDefinitionGroup_field_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_fieldDefinitionGroup_field_possibleValue WHERE possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field=current_row.xnat_fielddefinitiongroup_field_id
        LOOP
          PERFORM  a_xnat_fieldDefinitionGroup_field_possibleValue( parent_row.xnat_fielddefinitiongroup_field_possiblevalue_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_fielddefinitiongroup_field_possiblevalue(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_fieldDefinitionGroup_field_possibleValue.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_fieldDefinitionGroup_field_possibleValue LEFT JOIN xnat_fieldDefinitionGroup_field_possibleValue_meta_data meta ON xnat_fieldDefinitionGroup_field_possibleValue.fieldDefinitionGroup_field_possibleValue_info=meta.meta_data_id WHERE  xnat_fielddefinitiongroup_field_possiblevalue_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_fieldDefinitionGroup_field_possibleValue_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.a_xnat_gmscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_gmScanData LEFT JOIN xnat_gmScanData_meta_data meta ON xnat_gmScanData.gmScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_gmScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_gmsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_gmSessionData LEFT JOIN xnat_gmSessionData_meta_data meta ON xnat_gmSessionData.gmSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_gmSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_gmvscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmvScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_gmvScanData LEFT JOIN xnat_gmvScanData_meta_data meta ON xnat_gmvScanData.gmvScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_gmvScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_gmvsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmvSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_gmvSessionData LEFT JOIN xnat_gmvSessionData_meta_data meta ON xnat_gmvSessionData.gmvSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_gmvSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_hdscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_hdScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_hdScanData LEFT JOIN xnat_hdScanData_meta_data meta ON xnat_hdScanData.hdScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_hdScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_hdsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_hdSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_hdSessionData LEFT JOIN xnat_hdSessionData_meta_data meta ON xnat_hdSessionData.hdSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_hdSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_imageassessordata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT table1.id AS xnat_imageAssessorData0, table3.element_name AS xdat_meta_element142, table1.date AS xnat_experimentData6 FROM xnat_imageAssessorData xnat_imageAssessorData   LEFT JOIN xnat_derivedData table0 ON xnat_imageAssessorData.id=table0.id   LEFT JOIN xnat_experimentData table1 ON table0.id=table1.id   LEFT JOIN xdat_meta_element table3 ON table1.extension=table3.xdat_meta_element_id) SEARCH WHERE 
 ( (xnat_imageAssessorData0=$1))
      LOOP
         IF (current_row.xdat_meta_element142 IS NULL) THEN 
            PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element142='scr:screeningAssessment') THEN
            PERFORM  a_scr_screeningAssessment( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='val:protocolData') THEN
            PERFORM  a_val_protocolData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:mrAssessorData') THEN
            PERFORM  ae_xnat_mrAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:petAssessorData') THEN
            PERFORM  a_xnat_petAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:qcAssessmentData') THEN
            PERFORM  a_xnat_qcAssessmentData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:qcManualAssessorData') THEN
            PERFORM  a_xnat_qcManualAssessorData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_imageresource(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageResource.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_imageResource LEFT JOIN xnat_imageResource_meta_data meta ON xnat_imageResource.imageResource_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_imageResource_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_resource(current_row.xnat_abstractresource_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_resource( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_imageresourceseries(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageResourceSeries.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_imageResourceSeries LEFT JOIN xnat_imageResourceSeries_meta_data meta ON xnat_imageResourceSeries.imageResourceSeries_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_imageResourceSeries_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_resourceSeries(current_row.xnat_abstractresource_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_resourceSeries( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_imagescandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT xnat_imageScanData.xnat_imagescandata_id AS xnat_imageScanData23, table1.element_name AS xdat_meta_element100, table2.insert_date AS xnat_imageScanData_meta_data107 FROM xnat_imageScanData xnat_imageScanData   LEFT JOIN xdat_meta_element table1 ON xnat_imageScanData.extension=table1.xdat_meta_element_id   LEFT JOIN xnat_imageScanData_meta_data table2 ON xnat_imageScanData.imageScanData_info=table2.meta_data_id) SEARCH WHERE 
 ( (xnat_imageScanData23=$1))
      LOOP
         IF (current_row.xdat_meta_element100 IS NULL) THEN 
            PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element100='xnat:mrScanData') THEN
            PERFORM  a_xnat_mrScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:petScanData') THEN
            PERFORM  a_xnat_petScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ctScanData') THEN
            PERFORM  a_xnat_ctScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:crScanData') THEN
            PERFORM  a_xnat_crScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:dxScanData') THEN
            PERFORM  a_xnat_dxScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:mgScanData') THEN
            PERFORM  a_xnat_mgScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ioScanData') THEN
            PERFORM  a_xnat_ioScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:usScanData') THEN
            PERFORM  a_xnat_usScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ecgScanData') THEN
            PERFORM  a_xnat_ecgScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:hdScanData') THEN
            PERFORM  a_xnat_hdScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:epsScanData') THEN
            PERFORM  a_xnat_epsScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xaScanData') THEN
            PERFORM  a_xnat_xaScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:rfScanData') THEN
            PERFORM  a_xnat_rfScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xa3DScanData') THEN
            PERFORM  a_xnat_xa3DScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:dx3DCraniofacialScanData') THEN
            PERFORM  a_xnat_dx3DCraniofacialScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:nmScanData') THEN
            PERFORM  a_xnat_nmScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:srScanData') THEN
            PERFORM  a_xnat_srScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:esScanData') THEN
            PERFORM  a_xnat_esScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:esvScanData') THEN
            PERFORM  a_xnat_esvScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:gmScanData') THEN
            PERFORM  a_xnat_gmScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:gmvScanData') THEN
            PERFORM  a_xnat_gmvScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:smScanData') THEN
            PERFORM  a_xnat_smScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xcScanData') THEN
            PERFORM  a_xnat_xcScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xcvScanData') THEN
            PERFORM  a_xnat_xcvScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:opScanData') THEN
            PERFORM  a_xnat_opScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:optScanData') THEN
            PERFORM  a_xnat_optScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:rtImageScanData') THEN
            PERFORM  a_xnat_rtImageScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:scScanData') THEN
            PERFORM  a_xnat_scScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:segScanData') THEN
            PERFORM  a_xnat_segScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:mrsScanData') THEN
            PERFORM  a_xnat_mrsScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:voiceAudioScanData') THEN
            PERFORM  a_xnat_voiceAudioScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:otherDicomScanData') THEN
            PERFORM  a_xnat_otherDicomScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:megScanData') THEN
            PERFORM  a_xnat_megScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:eegScanData') THEN
            PERFORM  a_xnat_eegScanData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_imagescandata_share(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageScanData_share.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_imageScanData_share LEFT JOIN xnat_imageScanData_share_meta_data meta ON xnat_imageScanData_share.imageScanData_share_info=meta.meta_data_id WHERE  xnat_imagescandata_share_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_imageScanData_share_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_imagesessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT table1.id AS xnat_imageSessionData0, table3.element_name AS xdat_meta_element156, table1.date AS xnat_experimentData20 FROM xnat_imageSessionData xnat_imageSessionData   LEFT JOIN xnat_subjectAssessorData table0 ON xnat_imageSessionData.id=table0.id   LEFT JOIN xnat_experimentData table1 ON table0.id=table1.id   LEFT JOIN xdat_meta_element table3 ON table1.extension=table3.xdat_meta_element_id) SEARCH WHERE 
 ( (xnat_imageSessionData0=$1))
      LOOP
         IF (current_row.xdat_meta_element156 IS NULL) THEN 
            PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element156='xnat:mrSessionData') THEN
            PERFORM  a_xnat_mrSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:petSessionData') THEN
            PERFORM  a_xnat_petSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:petmrSessionData') THEN
            PERFORM  a_xnat_petmrSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ctSessionData') THEN
            PERFORM  a_xnat_ctSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:crSessionData') THEN
            PERFORM  a_xnat_crSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:dxSessionData') THEN
            PERFORM  a_xnat_dxSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:mgSessionData') THEN
            PERFORM  a_xnat_mgSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ioSessionData') THEN
            PERFORM  a_xnat_ioSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:usSessionData') THEN
            PERFORM  a_xnat_usSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ecgSessionData') THEN
            PERFORM  a_xnat_ecgSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:hdSessionData') THEN
            PERFORM  a_xnat_hdSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:epsSessionData') THEN
            PERFORM  a_xnat_epsSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xaSessionData') THEN
            PERFORM  a_xnat_xaSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:rfSessionData') THEN
            PERFORM  a_xnat_rfSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xa3DSessionData') THEN
            PERFORM  a_xnat_xa3DSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:dx3DCraniofacialSessionData') THEN
            PERFORM  a_xnat_dx3DCraniofacialSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:nmSessionData') THEN
            PERFORM  a_xnat_nmSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:srSessionData') THEN
            PERFORM  a_xnat_srSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:esSessionData') THEN
            PERFORM  a_xnat_esSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:esvSessionData') THEN
            PERFORM  a_xnat_esvSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:gmSessionData') THEN
            PERFORM  a_xnat_gmSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:gmvSessionData') THEN
            PERFORM  a_xnat_gmvSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:smSessionData') THEN
            PERFORM  a_xnat_smSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xcSessionData') THEN
            PERFORM  a_xnat_xcSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xcvSessionData') THEN
            PERFORM  a_xnat_xcvSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:opSessionData') THEN
            PERFORM  a_xnat_opSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:optSessionData') THEN
            PERFORM  a_xnat_optSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:rtSessionData') THEN
            PERFORM  a_xnat_rtSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:otherDicomSessionData') THEN
            PERFORM  a_xnat_otherDicomSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:megSessionData') THEN
            PERFORM  a_xnat_megSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:eegSessionData') THEN
            PERFORM  a_xnat_eegSessionData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_investigatordata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_investigatorData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_investigatorData LEFT JOIN xnat_investigatorData_meta_data meta ON xnat_investigatorData.investigatorData_info=meta.meta_data_id WHERE  xnat_investigatordata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_investigatorData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_ioscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ioScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_ioScanData LEFT JOIN xnat_ioScanData_meta_data meta ON xnat_ioScanData.ioScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_ioScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_iosessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ioSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_ioSessionData LEFT JOIN xnat_ioSessionData_meta_data meta ON xnat_ioSessionData.ioSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_ioSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_megscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_megScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_megScanData LEFT JOIN xnat_megScanData_meta_data meta ON xnat_megScanData.megScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_megScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_megsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_megSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_megSessionData LEFT JOIN xnat_megSessionData_meta_data meta ON xnat_megSessionData.megSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_megSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_mgscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mgScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_mgScanData LEFT JOIN xnat_mgScanData_meta_data meta ON xnat_mgScanData.mgScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_mgScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_mgsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mgSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_mgSessionData LEFT JOIN xnat_mgSessionData_meta_data meta ON xnat_mgSessionData.mgSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_mgSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_mrassessordata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT table2.id AS xnat_mrAssessorData0, table4.element_name AS xdat_meta_element144, table2.date AS xnat_experimentData8 FROM xnat_mrAssessorData xnat_mrAssessorData   LEFT JOIN xnat_imageAssessorData table0 ON xnat_mrAssessorData.id=table0.id   LEFT JOIN xnat_derivedData table1 ON table0.id=table1.id   LEFT JOIN xnat_experimentData table2 ON table1.id=table2.id   LEFT JOIN xdat_meta_element table4 ON table2.extension=table4.xdat_meta_element_id) SEARCH WHERE 
 ( (xnat_mrAssessorData0=$1))
      LOOP
         IF (current_row.xdat_meta_element144 IS NULL) THEN 
            PERFORM  ae_xnat_mrAssessorData( $1, $2,$3,$4);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element144='xnat:qcAssessmentData') THEN
            PERFORM  a_xnat_qcAssessmentData( $1, $2,$3,$4);
                matches:=1;
            END IF;
                IF (matches=0) THEN
            PERFORM  ae_xnat_mrAssessorData( $1, $2,$3,$4);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_mrqcscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrQcScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_mrQcScanData LEFT JOIN xnat_mrQcScanData_meta_data meta ON xnat_mrQcScanData.mrQcScanData_info=meta.meta_data_id WHERE  xnat_qcscandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_mrQcScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_qcscandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_qcScanData(current_row.xnat_qcscandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_qcScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_mrscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_mrScanData LEFT JOIN xnat_mrScanData_meta_data meta ON xnat_mrScanData.mrScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_mrScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField WHERE parameters_addparam_xnat_mrScan_xnat_imagescandata_id=current_row.xnat_imagescandata_id
        LOOP
          PERFORM  a_xnat_addField( parent_row.xnat_addfield_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_mrsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_mrSessionData LEFT JOIN xnat_mrSessionData_meta_data meta ON xnat_mrSessionData.mrSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_mrSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_mrsscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrsScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_mrsScanData LEFT JOIN xnat_mrsScanData_meta_data meta ON xnat_mrsScanData.mrsScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_mrsScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_nmscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_nmScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_nmScanData LEFT JOIN xnat_nmScanData_meta_data meta ON xnat_nmScanData.nmScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_nmScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_nmsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_nmSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_nmSessionData LEFT JOIN xnat_nmSessionData_meta_data meta ON xnat_nmSessionData.nmSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_nmSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_opscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_opScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_opScanData LEFT JOIN xnat_opScanData_meta_data meta ON xnat_opScanData.opScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_opScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_opsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_opSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_opSessionData LEFT JOIN xnat_opSessionData_meta_data meta ON xnat_opSessionData.opSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_opSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_optscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_optScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_optScanData LEFT JOIN xnat_optScanData_meta_data meta ON xnat_optScanData.optScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_optScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_optsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_optSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_optSessionData LEFT JOIN xnat_optSessionData_meta_data meta ON xnat_optSessionData.optSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_optSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_otherdicomscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_otherDicomScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_otherDicomScanData LEFT JOIN xnat_otherDicomScanData_meta_data meta ON xnat_otherDicomScanData.otherDicomScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_otherDicomScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_otherdicomsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_otherDicomSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_otherDicomSessionData LEFT JOIN xnat_otherDicomSessionData_meta_data meta ON xnat_otherDicomSessionData.otherDicomSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_otherDicomSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_otherqcscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_otherQcScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_otherQcScanData LEFT JOIN xnat_otherQcScanData_meta_data meta ON xnat_otherQcScanData.otherQcScanData_info=meta.meta_data_id WHERE  xnat_qcscandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_otherQcScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_qcscandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_qcScanData(current_row.xnat_qcscandata_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_qcScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_petassessordata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petAssessorData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_petAssessorData LEFT JOIN xnat_petAssessorData_meta_data meta ON xnat_petAssessorData.petAssessorData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_petAssessorData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageAssessorData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_petmrsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petmrSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_petmrSessionData LEFT JOIN xnat_petmrSessionData_meta_data meta ON xnat_petmrSessionData.petmrSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_petmrSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_petqcscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petQcScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_petQcScanData LEFT JOIN xnat_petQcScanData_meta_data meta ON xnat_petQcScanData.petQcScanData_info=meta.meta_data_id WHERE  xnat_qcscandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_petQcScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_qcscandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_qcScanData(current_row.xnat_qcscandata_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_petQcScanData_processingError WHERE processingerrors_processingerro_xnat_qcscandata_id=current_row.xnat_qcscandata_id
        LOOP
          PERFORM  a_xnat_petQcScanData_processingError( parent_row.xnat_petqcscandata_processingerror_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_qcScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_petqcscandata_processingerror(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petQcScanData_processingError.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_petQcScanData_processingError LEFT JOIN xnat_petQcScanData_processingError_meta_data meta ON xnat_petQcScanData_processingError.petQcScanData_processingError_info=meta.meta_data_id WHERE  xnat_petqcscandata_processingerror_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_petQcScanData_processingError_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_petscandata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petScanData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_petScanData LEFT JOIN xnat_petScanData_meta_data meta ON xnat_petScanData.petScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_petScanData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_imagescandata_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageScanData(current_row.xnat_imagescandata_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField WHERE parameters_addparam_xnat_petSca_xnat_imagescandata_id=current_row.xnat_imagescandata_id
        LOOP
          PERFORM  a_xnat_addField( parent_row.xnat_addfield_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_petScanData_frame WHERE parameters_frames_frame_xnat_pe_xnat_imagescandata_id=current_row.xnat_imagescandata_id
        LOOP
          PERFORM  a_xnat_petScanData_frame( parent_row.xnat_petscandata_frame_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageScanData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_petscandata_frame(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petScanData_frame.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_petScanData_frame LEFT JOIN xnat_petScanData_frame_meta_data meta ON xnat_petScanData_frame.petScanData_frame_info=meta.meta_data_id WHERE  xnat_petscandata_frame_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_petScanData_frame_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_petsessiondata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petSessionData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_petSessionData LEFT JOIN xnat_petSessionData_meta_data meta ON xnat_petSessionData.petSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_petSessionData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageSessionData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageSessionData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_projectdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_projectData LEFT JOIN xnat_projectData_meta_data meta ON xnat_projectData.projectData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_projectData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_projectData_alias WHERE aliases_alias_xnat_projectData_id=current_row.id
        LOOP
          PERFORM  a_xnat_projectData_alias( parent_row.xnat_projectdata_alias_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_publicationResource WHERE publications_publication_xnat_p_id=current_row.id
        LOOP
          PERFORM  a_xnat_publicationResource( parent_row.xnat_abstractresource_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_resource WHERE  xnat_projectData_id=current_row.id
        LOOP
          PERFORM  a_xnat_abstractResource( mapping_row.xnat_abstractResource_xnat_abstractresource_id, $2,$3,false);
        END LOOP;
        END; 
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractProtocol WHERE xnat_projectData_id=current_row.id
        LOOP
          PERFORM  a_xnat_abstractProtocol( parent_row.xnat_abstractprotocol_id, $2,$3,false);
        END LOOP;
        END;
        IF ((current_row.pi_xnat_investigatordata_id IS NOT NULL)) THEN
          PERFORM  a_xnat_investigatorData(current_row.pi_xnat_investigatordata_id, $2,$3,false);
        END IF;
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_investigator WHERE  xnat_projectData_id=current_row.id
        LOOP
          PERFORM  a_xnat_investigatorData( mapping_row.xnat_investigatorData_xnat_investigatordata_id, $2,$3,false);
        END LOOP;
        END; 
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_projectData_field WHERE fields_field_xnat_projectData_id=current_row.id
        LOOP
          PERFORM  a_xnat_projectData_field( parent_row.xnat_projectdata_field_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_projectdata_alias(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectData_alias.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_projectData_alias LEFT JOIN xnat_projectData_alias_meta_data meta ON xnat_projectData_alias.projectData_alias_info=meta.meta_data_id WHERE  xnat_projectdata_alias_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_projectData_alias_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_projectdata_field(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectData_field.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_projectData_field LEFT JOIN xnat_projectData_field_meta_data meta ON xnat_projectData_field.projectData_field_info=meta.meta_data_id WHERE  xnat_projectdata_field_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_projectData_field_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_projectparticipant(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectParticipant.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_projectParticipant LEFT JOIN xnat_projectParticipant_meta_data meta ON xnat_projectParticipant.projectParticipant_info=meta.meta_data_id WHERE  xnat_projectparticipant_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_projectParticipant_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_publicationresource(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_publicationResource.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_publicationResource LEFT JOIN xnat_publicationResource_meta_data meta ON xnat_publicationResource.publicationResource_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_publicationResource_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.xnat_abstractresource_id IS NOT NULL)) THEN
          PERFORM  ae_xnat_abstractResource(current_row.xnat_abstractresource_id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_abstractResource( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_pvisitdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_pVisitData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_pVisitData LEFT JOIN xnat_pVisitData_meta_data meta ON xnat_pVisitData.pVisitData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_pVisitData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_genericData(current_row.id, $2,$3,false);
        END IF;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_genericData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_qcassessmentdata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcAssessmentData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_qcAssessmentData LEFT JOIN xnat_qcAssessmentData_meta_data meta ON xnat_qcAssessmentData.qcAssessmentData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_qcAssessmentData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_mrAssessorData(current_row.id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcAssessmentData_scan WHERE scans_scan_xnat_qcAssessmentDat_id=current_row.id
        LOOP
          PERFORM  a_xnat_qcAssessmentData_scan( parent_row.xnat_qcassessmentdata_scan_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_mrAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_qcassessmentdata_scan(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcAssessmentData_scan.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_qcAssessmentData_scan LEFT JOIN xnat_qcAssessmentData_scan_meta_data meta ON xnat_qcAssessmentData_scan.qcAssessmentData_scan_info=meta.meta_data_id WHERE  xnat_qcassessmentdata_scan_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_qcAssessmentData_scan_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcAssessmentData_scan_slice WHERE sliceqc_slice_xnat_qcAssessment_xnat_qcassessmentdata_scan_id=current_row.xnat_qcassessmentdata_scan_id
        LOOP
          PERFORM  a_xnat_qcAssessmentData_scan_slice( parent_row.xnat_qcassessmentdata_scan_slice_id, $2,$3,false);
        END LOOP;
        END;
        IF ((current_row.scanstatistics_xnat_abstractstatistics_id IS NOT NULL)) THEN
          PERFORM  a_xnat_abstractStatistics(current_row.scanstatistics_xnat_abstractstatistics_id, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_qcassessmentdata_scan_slice(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcAssessmentData_scan_slice.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_qcAssessmentData_scan_slice LEFT JOIN xnat_qcAssessmentData_scan_slice_meta_data meta ON xnat_qcAssessmentData_scan_slice.qcAssessmentData_scan_slice_info=meta.meta_data_id WHERE  xnat_qcassessmentdata_scan_slice_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_qcAssessmentData_scan_slice_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.slicestatistics_xnat_abstractstatistics_id IS NOT NULL)) THEN
          PERFORM  a_xnat_abstractStatistics(current_row.slicestatistics_xnat_abstractstatistics_id, $2,$3,false);
        END IF;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_qcmanualassessordata(character varying, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcManualAssessorData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_qcManualAssessorData LEFT JOIN xnat_qcManualAssessorData_meta_data meta ON xnat_qcManualAssessorData.qcManualAssessorData_info=meta.meta_data_id WHERE  id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_qcManualAssessorData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        IF ((current_row.id IS NOT NULL)) THEN
          PERFORM  ae_xnat_imageAssessorData(current_row.id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcScanData WHERE scans_scan_xnat_qcManualAssesso_id=current_row.id
        LOOP
          PERFORM  a_xnat_qcScanData( parent_row.xnat_qcscandata_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
      IF (row_ct=0) THEN 
          PERFORM  ae_xnat_imageAssessorData( $1, $2,$3,$4);
          
      END IF;
	
	 RETURN '';
    end;
$_$;


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

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

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


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

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

CREATE FUNCTION public.a_xnat_qcscandata_field(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcScanData_field.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_qcScanData_field LEFT JOIN xnat_qcScanData_field_meta_data meta ON xnat_qcScanData_field.qcScanData_field_info=meta.meta_data_id WHERE  xnat_qcscandata_field_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_qcScanData_field_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

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

CREATE FUNCTION public.a_xnat_reconstructedimagedata(integer, integer, character varying, boolean) RETURNS text
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
     row_ct int4;
    begin
      row_ct := 0;
       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_reconstructedImageData.*, meta.meta_data_id, meta.status AS meta_status FROM xnat_reconstructedImageData LEFT JOIN xnat_reconstructedImageData_meta_data meta ON xnat_reconstructedImageData.reconstructedImageData_info=meta.meta_data_id WHERE  xnat_reconstructedimagedata_id=$1
      LOOP
           row_ct := row_ct+1;
           IF (current_row.meta_status!=$3) THEN
         UPDATE xnat_reconstructedImageData_meta_data SET status=$3,activation_date=NOW(),activation_user_xdat_user_id=$2 WHERE meta_data_id=current_row.meta_data_id;
           END IF;
          
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_reconstructedImageData_scanID WHERE inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id
        LOOP
          PERFORM  a_xnat_reconstructedImageData_scanID( parent_row.xnat_reconstructedimagedata_scanid_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM recon_in_resource WHERE  xnat_reconstructedImageData_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id
        LOOP
          PERFORM  a_xnat_abstractResource( mapping_row.xnat_abstractResource_xnat_abstractresource_id, $2,$3,false);
        END LOOP;
        END; 
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM recon_out_resource WHERE  xnat_reconstructedImageData_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id
        LOOP
          PERFORM  a_xnat_abstractResource( mapping_row.xnat_abstractResource_xnat_abstractresource_id, $2,$3,false);
        END LOOP;
        END; 
        IF ((current_row.provenance_prov_process_id IS NOT NULL)) THEN
          PERFORM  a_prov_process(current_row.provenance_prov_process_id, $2,$3,false);
        END IF;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_addField WHERE parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id
        LOOP
          PERFORM  a_xnat_addField( parent_row.xnat_addfield_id, $2,$3,false);
        END LOOP;
        END;
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_computationData WHERE computations_datum_xnat_reconst_xnat_reconstructedimagedata_id=current_row.xnat_reconstructedimagedata_id
        LOOP
          PERFORM  a_xnat_computationData( parent_row.xnat_computationdata_id, $2,$3,false);
        END LOOP;
        END;
      END LOOP;
	
	 RETURN '';
    end;
$_$;


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

--
