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

CREATE FUNCTION public.update_ls_scr_screeningassessment(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='scr:screeningAssessment' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT scr_screeningAssessment.*, meta.meta_data_id FROM scr_screeningAssessment LEFT JOIN scr_screeningAssessment_meta_data meta ON scr_screeningAssessment.screeningAssessment_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE scr_screeningAssessment_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_scr_screeningscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT scr_screeningScanData.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION scr:screeningAssessment/scans/scan
        IF ((current_row.scans_scan_scr_screeningAssessm_id IS NOT NULL)) THEN
        PERFORM update_ls_scr_screeningAssessment(current_row.scans_scan_scr_screeningAssessm_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_val_additionalval(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_additionalVal.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION val:protocolData/check/additionalVal
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData WHERE check_additionalval_val_additionalval_id=current_row.val_additionalval_id
        LOOP
        PERFORM update_ls_val_protocolData( parent_row.id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION val:protocolData_scan_check/additionalVal
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM val_protocolData_scan_check WHERE additionalval_val_additionalval_id=current_row.val_additionalval_id
        LOOP
        PERFORM update_ls_val_protocolData_scan_check( parent_row.val_protocoldata_scan_check_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_val_protocoldata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='val:protocolData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData.*, meta.meta_data_id FROM val_protocolData LEFT JOIN val_protocolData_meta_data meta ON val_protocolData.protocolData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE val_protocolData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_val_protocoldata_comment(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_comment.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION val:protocolData/check/comments/comment
        IF ((current_row.check_comments_comment_val_prot_id IS NOT NULL)) THEN
        PERFORM update_ls_val_protocolData(current_row.check_comments_comment_val_prot_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_val_protocoldata_condition(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_condition.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION val:protocolData/check/conditions/condition
        IF ((current_row.check_conditions_condition_val__id IS NOT NULL)) THEN
        PERFORM update_ls_val_protocolData(current_row.check_conditions_condition_val__id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_val_protocoldata_scan_check(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_scan_check.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION val:protocolData/scans/scan_check
        IF ((current_row.scans_scan_check_val_protocolDa_id IS NOT NULL)) THEN
        PERFORM update_ls_val_protocolData(current_row.scans_scan_check_val_protocolDa_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_val_protocoldata_scan_check_comment(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_scan_check_comment.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION val:protocolData_scan_check/comments/comment
        IF ((current_row.comments_comment_val_protocolDa_val_protocoldata_scan_check_id IS NOT NULL)) THEN
        PERFORM update_ls_val_protocolData_scan_check(current_row.comments_comment_val_protocolDa_val_protocoldata_scan_check_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_val_protocoldata_scan_check_condition(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT val_protocolData_scan_check_condition.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION val:protocolData_scan_check/conditions/condition
        IF ((current_row.conditions_condition_val_protoc_val_protocoldata_scan_check_id IS NOT NULL)) THEN
        PERFORM update_ls_val_protocolData_scan_check(current_row.conditions_condition_val_protoc_val_protocoldata_scan_check_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_wrk_abstractexecutionenvironment(integer, integer) RETURNS character varying
    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 update_ls_ext_wrk_abstractExecutionEnvironment( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='wrk:xnatExecutionEnvironment') THEN
                PERFORM update_ls_wrk_xnatExecutionEnvironment( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element3;
                    PERFORM update_ls_ext_wrk_abstractExecutionEnvironment( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_wrk_workflowdata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='wrk:workflowData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_workflowData.*, meta.meta_data_id 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
         UPDATE wrk_workflowData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_wrk_xnatexecutionenvironment(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_xnatExecutionEnvironment.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_wrk_abstractExecutionEnvironment( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_wrk_xnatexecutionenvironment_notify(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_xnatExecutionEnvironment_notify.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION wrk:xnatExecutionEnvironment/notify
        IF ((current_row.wrk_xnatExecutionEnvironment_wrk_abstractexecutionenvironmen IS NOT NULL)) THEN
        PERFORM update_ls_wrk_xnatExecutionEnvironment(current_row.wrk_xnatExecutionEnvironment_wrk_abstractexecutionenvironmen, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_wrk_xnatexecutionenvironment_parameter(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT wrk_xnatExecutionEnvironment_parameter.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION wrk:xnatExecutionEnvironment/parameters/parameter
        IF ((current_row.parameters_parameter_wrk_xnatEx_wrk_abstractexecutionenvironmen IS NOT NULL)) THEN
        PERFORM update_ls_wrk_xnatExecutionEnvironment(current_row.parameters_parameter_wrk_xnatEx_wrk_abstractexecutionenvironmen, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_access_log(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_access_log.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_action_type(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_action_type.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:security/actions/action
        IF ((current_row.actions_action_xdat_security_xdat_security_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_security(current_row.actions_action_xdat_security_xdat_security_id, $2);
        END IF;

        --PROCESS MAPPING TABLE RELATION xdat:role_type/allowed_actions/allowed_action
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_a_xdat_action_type_allowe_xdat_role_type WHERE  xdat_action_type_action_name=current_row.action_name
           LOOP 
               PERFORM update_ls_xdat_role_type( mapping_row.xdat_role_type_role_name, $2);
           END LOOP; 
        END; 
	
	RETURN 'DONE';
    end;
$_$;


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

--
-- Name: update_ls_xdat_change_info(bigint, integer); Type: FUNCTION; Schema: public; Owner: xnat
--

CREATE FUNCTION public.update_ls_xdat_change_info(bigint, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_change_info.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


ALTER FUNCTION public.update_ls_xdat_change_info(bigint, integer) OWNER TO xnat;

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

CREATE FUNCTION public.update_ls_xdat_criteria(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_criteria.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:criteria_set/criteria
        IF ((current_row.xdat_criteria_set_xdat_criteria_set_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_criteria_set(current_row.xdat_criteria_set_xdat_criteria_set_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_criteria_set(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_criteria_set.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:stored_search/search_where
        IF ((current_row.xdat_stored_search_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_stored_search(current_row.xdat_stored_search_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_element_access(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:element_access' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_access.*, meta.meta_data_id 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
         UPDATE xdat_element_access_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:user/element_access
        IF ((current_row.xdat_user_xdat_user_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_user(current_row.xdat_user_xdat_user_id, $2);
        END IF;

        --PROCESS SUBORDINATE RELATION xdat:userGroup/element_access
        IF ((current_row.xdat_userGroup_xdat_usergroup_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_userGroup(current_row.xdat_userGroup_xdat_usergroup_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_element_access_secure_ip(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_access_secure_ip.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:element_access/secure_ip
        IF ((current_row.xdat_element_access_xdat_element_access_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_element_access(current_row.xdat_element_access_xdat_element_access_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_element_action_type(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_action_type.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:element_security/element_actions/element_action
        IF ((current_row.element_actions_element_action__element_name IS NOT NULL)) THEN
        PERFORM update_ls_xdat_element_security(current_row.element_actions_element_action__element_name, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_element_security(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_security.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:security/element_security_set/element_security
        IF ((current_row.element_security_set_element_se_xdat_security_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_security(current_row.element_security_set_element_se_xdat_security_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_element_security_listing_action(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_element_security_listing_action.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:element_security/listing_actions/listing_action
        IF ((current_row.listing_actions_listing_action__element_name IS NOT NULL)) THEN
        PERFORM update_ls_xdat_element_security(current_row.listing_actions_listing_action__element_name, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_field_mapping(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_field_mapping.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:field_mapping_set/allow
        IF ((current_row.xdat_field_mapping_set_xdat_field_mapping_set_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_field_mapping_set(current_row.xdat_field_mapping_set_xdat_field_mapping_set_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_field_mapping_set(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_field_mapping_set.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:element_access/permissions/allow_set
        IF ((current_row.permissions_allow_set_xdat_elem_xdat_element_access_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_element_access(current_row.permissions_allow_set_xdat_elem_xdat_element_access_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_infoentry(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:infoEntry' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_infoEntry.*, meta.meta_data_id 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
         UPDATE xdat_infoEntry_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xdat:security/infoList/info
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_security WHERE infolist_info_xdat_infoentry_id=current_row.xdat_infoentry_id
        LOOP
        PERFORM update_ls_xdat_security( parent_row.xdat_security_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_meta_element(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_meta_element.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION wrk:abstractExecutionEnvironment/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM wrk_abstractExecutionEnvironment WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_wrk_abstractExecutionEnvironment( parent_row.wrk_abstractexecutionenvironment_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION cat:catalog/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM cat_catalog WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_cat_catalog( parent_row.cat_catalog_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION cat:entry/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM cat_entry WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_cat_entry( parent_row.cat_entry_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION arc:pipelineData/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM arc_pipelineData WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_arc_pipelineData( parent_row.arc_pipelinedata_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:experimentData/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_experimentData WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_experimentData( parent_row.id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:abstractSubjectMetadata/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractSubjectMetadata WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_abstractSubjectMetadata( parent_row.xnat_abstractsubjectmetadata_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:abstractDemographicData/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractDemographicData WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_abstractDemographicData( parent_row.xnat_abstractdemographicdata_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:abstractResource/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractResource WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_abstractResource( parent_row.xnat_abstractresource_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:abstractProtocol/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractProtocol WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_abstractProtocol( parent_row.xnat_abstractprotocol_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:abstractStatistics/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_abstractStatistics WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_abstractStatistics( parent_row.xnat_abstractstatistics_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:imageScanData/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_imageScanData WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_imageScanData( parent_row.xnat_imagescandata_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:qcScanData/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_qcScanData WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xnat_qcScanData( parent_row.xnat_qcscandata_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xdat:stored_search/extension_item
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_stored_search WHERE extension=current_row.xdat_meta_element_id
        LOOP
        PERFORM update_ls_xdat_stored_search( parent_row.id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_newsentry(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:newsEntry' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_newsEntry.*, meta.meta_data_id 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
         UPDATE xdat_newsEntry_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xdat:security/newsList/news
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xdat_security WHERE newslist_news_xdat_newsentry_id=current_row.xdat_newsentry_id
        LOOP
        PERFORM update_ls_xdat_security( parent_row.xdat_security_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_primary_security_field(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_primary_security_field.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:element_security/primary_security_fields/primary_security_field
        IF ((current_row.primary_security_fields_primary_element_name IS NOT NULL)) THEN
        PERFORM update_ls_xdat_element_security(current_row.primary_security_fields_primary_element_name, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_role_type(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_role_type.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:security/roles/role
        IF ((current_row.roles_role_xdat_security_xdat_security_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_security(current_row.roles_role_xdat_security_xdat_security_id, $2);
        END IF;

        --PROCESS MAPPING TABLE RELATION xdat:user/assigned_roles/assigned_role
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xdat_r_xdat_role_type_assign_xdat_user WHERE  xdat_role_type_role_name=current_row.role_name
           LOOP 
               PERFORM update_ls_xdat_user( mapping_row.xdat_user_xdat_user_id, $2);
           END LOOP; 
        END; 
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_search(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:Search' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_Search.*, meta.meta_data_id FROM xdat_Search LEFT JOIN xdat_Search_meta_data meta ON xdat_Search.Search_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xdat_Search_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xdat_stored_search( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_search_field(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_search_field.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:stored_search/search_field
        IF ((current_row.xdat_stored_search_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_stored_search(current_row.xdat_stored_search_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_security(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:security' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_security.*, meta.meta_data_id 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
         UPDATE xdat_security_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_stored_search(character varying, integer) RETURNS character varying
    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 update_ls_ext_xdat_stored_search( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element103='xdat:Search') THEN
                PERFORM update_ls_xdat_Search( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element103;
                    PERFORM update_ls_ext_xdat_stored_search( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_stored_search_allowed_user(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_stored_search_allowed_user.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:stored_search/allowed_user
        IF ((current_row.xdat_stored_search_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_stored_search(current_row.xdat_stored_search_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_stored_search_groupid(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_stored_search_groupID.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:stored_search/allowed_groups/groupID
        IF ((current_row.allowed_groups_groupid_xdat_sto_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_stored_search(current_row.allowed_groups_groupid_xdat_sto_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_user(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:user' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_user.*, meta.meta_data_id 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
         UPDATE xdat_user_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:security/users/user
        IF ((current_row.users_user_xdat_security_xdat_security_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_security(current_row.users_user_xdat_security_xdat_security_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_user_groupid(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_user_groupID.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:user/groups/groupID
        IF ((current_row.groups_groupid_xdat_user_xdat_user_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_user(current_row.groups_groupid_xdat_user_xdat_user_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_user_login(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_user_login.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xdat_usergroup(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xdat:userGroup' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xdat_userGroup.*, meta.meta_data_id 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
         UPDATE xdat_userGroup_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xdat:security/groups/group
        IF ((current_row.groups_group_xdat_security_xdat_security_id IS NOT NULL)) THEN
        PERFORM update_ls_xdat_security(current_row.groups_group_xdat_security_xdat_security_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_a_scidresearchdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat_a:scidResearchData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_scidResearchData.*, meta.meta_data_id 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
         UPDATE xnat_a_scidResearchData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_a_sideeffectspittsburghdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat_a:sideEffectsPittsburghData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_sideEffectsPittsburghData.*, meta.meta_data_id 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
         UPDATE xnat_a_sideEffectsPittsburghData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_a_updrs3data(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat_a:updrs3Data' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_updrs3Data.*, meta.meta_data_id 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
         UPDATE xnat_a_updrs3Data_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_a_ybocsdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat_a:ybocsData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_ybocsData.*, meta.meta_data_id 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
         UPDATE xnat_a_ybocsData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_a_ygtssdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat_a:ygtssData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_a_ygtssData.*, meta.meta_data_id 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
         UPDATE xnat_a_ygtssData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_abstractdemographicdata(integer, integer) RETURNS character varying
    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 update_ls_ext_xnat_abstractDemographicData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:demographicData') THEN
                PERFORM update_ls_xnat_demographicData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element3;
                    PERFORM update_ls_ext_xnat_abstractDemographicData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_abstractprotocol(integer, integer) RETURNS character varying
    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 update_ls_ext_xnat_abstractProtocol( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element8='xnat:studyProtocol') THEN
                PERFORM update_ls_xnat_studyProtocol( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element8='xnat:datatypeProtocol') THEN
                PERFORM update_ls_xnat_datatypeProtocol( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element8;
                    PERFORM update_ls_ext_xnat_abstractProtocol( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_abstractresource(integer, integer) RETURNS character varying
    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 update_ls_ext_xnat_abstractResource( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element25='xnat:resource') THEN
                PERFORM update_ls_ext_xnat_resource( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageResource') THEN
                PERFORM update_ls_xnat_imageResource( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:resourceSeries') THEN
                PERFORM update_ls_ext_xnat_resourceSeries( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:imageResourceSeries') THEN
                PERFORM update_ls_xnat_imageResourceSeries( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:dicomSeries') THEN
                PERFORM update_ls_xnat_dicomSeries( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:publicationResource') THEN
                PERFORM update_ls_xnat_publicationResource( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element25='xnat:resourceCatalog') THEN
                PERFORM update_ls_xnat_resourceCatalog( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element25;
                    PERFORM update_ls_ext_xnat_abstractResource( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_abstractresource_tag(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_abstractResource_tag.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:abstractResource/tags/tag
        IF ((current_row.tags_tag_xnat_abstractResource_xnat_abstractresource_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_abstractResource(current_row.tags_tag_xnat_abstractResource_xnat_abstractresource_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_abstractstatistics(integer, integer) RETURNS character varying
    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 update_ls_ext_xnat_abstractStatistics( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:statisticsData') THEN
                PERFORM update_ls_xnat_statisticsData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element3;
                    PERFORM update_ls_ext_xnat_abstractStatistics( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_abstractsubjectmetadata(integer, integer) RETURNS character varying
    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 update_ls_ext_xnat_abstractSubjectMetadata( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element3='xnat:subjectMetadata') THEN
                PERFORM update_ls_xnat_subjectMetadata( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element3;
                    PERFORM update_ls_ext_xnat_abstractSubjectMetadata( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_addfield(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_addField.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:mrScanData/parameters/addParam
        IF ((current_row.parameters_addparam_xnat_mrScan_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_mrScanData(current_row.parameters_addparam_xnat_mrScan_xnat_imagescandata_id, $2);
        END IF;

        --PROCESS SUBORDINATE RELATION xnat:reconstructedImageData/parameters/addParam
        IF ((current_row.parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_reconstructedImageData(current_row.parameters_addparam_xnat_recons_xnat_reconstructedimagedata_id, $2);
        END IF;

        --PROCESS SUBORDINATE RELATION xnat:petScanData/parameters/addParam
        IF ((current_row.parameters_addparam_xnat_petSca_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_petScanData(current_row.parameters_addparam_xnat_petSca_xnat_imagescandata_id, $2);
        END IF;

        --PROCESS SUBORDINATE RELATION xnat:imageAssessorData/parameters/addParam
        IF ((current_row.parameters_addparam_xnat_imageA_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_imageAssessorData(current_row.parameters_addparam_xnat_imageA_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_algorithm(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:algorithm' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_algorithm.*, meta.meta_data_id 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
         UPDATE xnat_algorithm_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_computationdata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_computationData.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:reconstructedImageData/computations/datum
        IF ((current_row.computations_datum_xnat_reconst_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_reconstructedImageData(current_row.computations_datum_xnat_reconst_xnat_reconstructedimagedata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_contrastbolus(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_contrastBolus.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:ctScanData/parameters/contrastBolus
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_ctScanData WHERE parameters_contrastbolus_xnat_contrastbolus_id=current_row.xnat_contrastbolus_id
        LOOP
        PERFORM update_ls_xnat_ctScanData( parent_row.xnat_imagescandata_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:xaScanData/parameters/contrastBolus
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_xaScanData WHERE parameters_contrastbolus_xnat_contrastbolus_id=current_row.xnat_contrastbolus_id
        LOOP
        PERFORM update_ls_xnat_xaScanData( parent_row.xnat_imagescandata_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_crscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:crScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_crScanData.*, meta.meta_data_id 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
         UPDATE xnat_crScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_crsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:crSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_crSessionData.*, meta.meta_data_id FROM xnat_crSessionData LEFT JOIN xnat_crSessionData_meta_data meta ON xnat_crSessionData.crSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_crSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_ctscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:ctScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ctScanData.*, meta.meta_data_id 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
         UPDATE xnat_ctScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_ctscandata_focalspot(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ctScanData_focalSpot.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:ctScanData/parameters/focalSpots/focalSpot
        IF ((current_row.parameters_focalspots_focalspot_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_ctScanData(current_row.parameters_focalspots_focalspot_xnat_imagescandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_ctsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:ctSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ctSessionData.*, meta.meta_data_id FROM xnat_ctSessionData LEFT JOIN xnat_ctSessionData_meta_data meta ON xnat_ctSessionData.ctSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_ctSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_datatypeprotocol(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_datatypeProtocol.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractProtocol( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_demographicdata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_demographicData.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractDemographicData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_deriveddata(character varying, integer) RETURNS character varying
    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 update_ls_ext_xnat_derivedData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element139='scr:screeningAssessment') THEN
                PERFORM update_ls_scr_screeningAssessment( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='val:protocolData') THEN
                PERFORM update_ls_val_protocolData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:mrAssessorData') THEN
                PERFORM update_ls_ext_xnat_mrAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:petAssessorData') THEN
                PERFORM update_ls_xnat_petAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:qcAssessmentData') THEN
                PERFORM update_ls_xnat_qcAssessmentData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:imageAssessorData') THEN
                PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element139='xnat:qcManualAssessorData') THEN
                PERFORM update_ls_xnat_qcManualAssessorData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element139;
                    PERFORM update_ls_ext_xnat_derivedData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_dicomcodedvalue(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:dicomCodedValue' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dicomCodedValue.*, meta.meta_data_id 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
         UPDATE xnat_dicomCodedValue_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:algorithm/family
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_algorithm WHERE family_xnat_dicomcodedvalue_id=current_row.xnat_dicomcodedvalue_id
        LOOP
        PERFORM update_ls_xnat_algorithm( parent_row.xnat_algorithm_id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:algorithm/nameCode
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_algorithm WHERE namecode_xnat_dicomcodedvalue_id=current_row.xnat_dicomcodedvalue_id
        LOOP
        PERFORM update_ls_xnat_algorithm( parent_row.xnat_algorithm_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_dicomseries(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dicomSeries.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractResource( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_dicomseries_image(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dicomSeries_image.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:dicomSeries/imageSet/image
        IF ((current_row.imageset_image_xnat_dicomSeries_xnat_abstractresource_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_dicomSeries(current_row.imageset_image_xnat_dicomSeries_xnat_abstractresource_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_dx3dcraniofacialscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:dx3DCraniofacialScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dx3DCraniofacialScanData.*, meta.meta_data_id 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
         UPDATE xnat_dx3DCraniofacialScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_dx3dcraniofacialsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:dx3DCraniofacialSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dx3DCraniofacialSessionData.*, meta.meta_data_id FROM xnat_dx3DCraniofacialSessionData LEFT JOIN xnat_dx3DCraniofacialSessionData_meta_data meta ON xnat_dx3DCraniofacialSessionData.dx3DCraniofacialSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_dx3DCraniofacialSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_dxscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:dxScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dxScanData.*, meta.meta_data_id 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
         UPDATE xnat_dxScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_dxsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:dxSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_dxSessionData.*, meta.meta_data_id FROM xnat_dxSessionData LEFT JOIN xnat_dxSessionData_meta_data meta ON xnat_dxSessionData.dxSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_dxSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_ecgscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:ecgScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ecgScanData.*, meta.meta_data_id 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
         UPDATE xnat_ecgScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_ecgsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:ecgSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ecgSessionData.*, meta.meta_data_id FROM xnat_ecgSessionData LEFT JOIN xnat_ecgSessionData_meta_data meta ON xnat_ecgSessionData.ecgSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_ecgSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_eegscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:eegScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegScanData.*, meta.meta_data_id 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
         UPDATE xnat_eegScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_eegscandata_channel(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegScanData_channel.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:eegScanData/channels/channel
        IF ((current_row.channels_channel_xnat_eegScanDa_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_eegScanData(current_row.channels_channel_xnat_eegScanDa_xnat_imagescandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_eegscandata_impedance(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegScanData_impedance.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:eegScanData/softwareFiltersImpedances/impedance
        IF ((current_row.softwarefiltersimpedances_imped_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_eegScanData(current_row.softwarefiltersimpedances_imped_xnat_imagescandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_eegsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:eegSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_eegSessionData.*, meta.meta_data_id FROM xnat_eegSessionData LEFT JOIN xnat_eegSessionData_meta_data meta ON xnat_eegSessionData.eegSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_eegSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_epsscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:epsScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_epsScanData.*, meta.meta_data_id 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
         UPDATE xnat_epsScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_epssessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:epsSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_epsSessionData.*, meta.meta_data_id FROM xnat_epsSessionData LEFT JOIN xnat_epsSessionData_meta_data meta ON xnat_epsSessionData.epsSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_epsSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_esscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:esScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esScanData.*, meta.meta_data_id 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
         UPDATE xnat_esScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_essessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:esSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esSessionData.*, meta.meta_data_id FROM xnat_esSessionData LEFT JOIN xnat_esSessionData_meta_data meta ON xnat_esSessionData.esSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_esSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_esvscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:esvScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esvScanData.*, meta.meta_data_id 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
         UPDATE xnat_esvScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_esvsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:esvSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_esvSessionData.*, meta.meta_data_id FROM xnat_esvSessionData LEFT JOIN xnat_esvSessionData_meta_data meta ON xnat_esvSessionData.esvSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_esvSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_experimentdata(character varying, integer) RETURNS character varying
    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 update_ls_ext_xnat_experimentData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element136='scr:screeningAssessment') THEN
                PERFORM update_ls_scr_screeningAssessment( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='val:protocolData') THEN
                PERFORM update_ls_val_protocolData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:genericData') THEN
                PERFORM update_ls_ext_xnat_genericData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:pVisitData') THEN
                PERFORM update_ls_xnat_pVisitData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:subjectAssessorData') THEN
                PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:subjectVariablesData') THEN
                PERFORM update_ls_xnat_subjectVariablesData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:imageSessionData') THEN
                PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mrSessionData') THEN
                PERFORM update_ls_xnat_mrSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mrAssessorData') THEN
                PERFORM update_ls_ext_xnat_mrAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:derivedData') THEN
                PERFORM update_ls_ext_xnat_derivedData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petAssessorData') THEN
                PERFORM update_ls_xnat_petAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petSessionData') THEN
                PERFORM update_ls_xnat_petSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:petmrSessionData') THEN
                PERFORM update_ls_xnat_petmrSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:qcAssessmentData') THEN
                PERFORM update_ls_xnat_qcAssessmentData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:imageAssessorData') THEN
                PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ctSessionData') THEN
                PERFORM update_ls_xnat_ctSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:crSessionData') THEN
                PERFORM update_ls_xnat_crSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:dxSessionData') THEN
                PERFORM update_ls_xnat_dxSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:mgSessionData') THEN
                PERFORM update_ls_xnat_mgSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ioSessionData') THEN
                PERFORM update_ls_xnat_ioSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:usSessionData') THEN
                PERFORM update_ls_xnat_usSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:ecgSessionData') THEN
                PERFORM update_ls_xnat_ecgSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:hdSessionData') THEN
                PERFORM update_ls_xnat_hdSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:epsSessionData') THEN
                PERFORM update_ls_xnat_epsSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xaSessionData') THEN
                PERFORM update_ls_xnat_xaSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:rfSessionData') THEN
                PERFORM update_ls_xnat_rfSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xa3DSessionData') THEN
                PERFORM update_ls_xnat_xa3DSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:dx3DCraniofacialSessionData') THEN
                PERFORM update_ls_xnat_dx3DCraniofacialSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:nmSessionData') THEN
                PERFORM update_ls_xnat_nmSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:srSessionData') THEN
                PERFORM update_ls_xnat_srSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:esSessionData') THEN
                PERFORM update_ls_xnat_esSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:esvSessionData') THEN
                PERFORM update_ls_xnat_esvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:gmSessionData') THEN
                PERFORM update_ls_xnat_gmSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:gmvSessionData') THEN
                PERFORM update_ls_xnat_gmvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:smSessionData') THEN
                PERFORM update_ls_xnat_smSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xcSessionData') THEN
                PERFORM update_ls_xnat_xcSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:xcvSessionData') THEN
                PERFORM update_ls_xnat_xcvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:opSessionData') THEN
                PERFORM update_ls_xnat_opSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:optSessionData') THEN
                PERFORM update_ls_xnat_optSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:rtSessionData') THEN
                PERFORM update_ls_xnat_rtSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:otherDicomSessionData') THEN
                PERFORM update_ls_xnat_otherDicomSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:qcManualAssessorData') THEN
                PERFORM update_ls_xnat_qcManualAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:megSessionData') THEN
                PERFORM update_ls_xnat_megSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat:eegSessionData') THEN
                PERFORM update_ls_xnat_eegSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:sideEffectsPittsburghData') THEN
                PERFORM update_ls_xnat_a_sideEffectsPittsburghData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:ybocsData') THEN
                PERFORM update_ls_xnat_a_ybocsData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:ygtssData') THEN
                PERFORM update_ls_xnat_a_ygtssData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:updrs3Data') THEN
                PERFORM update_ls_xnat_a_updrs3Data( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element136='xnat_a:scidResearchData') THEN
                PERFORM update_ls_xnat_a_scidResearchData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element136;
                    PERFORM update_ls_ext_xnat_experimentData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_experimentdata_field(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_experimentData_field.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:experimentData/fields/field
        IF ((current_row.fields_field_xnat_experimentDat_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_experimentData(current_row.fields_field_xnat_experimentDat_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_experimentdata_share(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_experimentData_share.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:experimentData/sharing/share
        IF ((current_row.sharing_share_xnat_experimentDa_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_experimentData(current_row.sharing_share_xnat_experimentDa_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_fielddefinitiongroup(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:fieldDefinitionGroup' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_fieldDefinitionGroup.*, meta.meta_data_id 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
         UPDATE xnat_fieldDefinitionGroup_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS MAPPING TABLE RELATION xnat:datatypeProtocol/definitions/definition
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_datatypeProtocol_fieldGroups WHERE  xnat_fieldDefinitionGroup_xnat_fielddefinitiongroup_id=current_row.xnat_fielddefinitiongroup_id
           LOOP 
               PERFORM update_ls_xnat_datatypeProtocol( mapping_row.xnat_datatypeProtocol_xnat_abstractprotocol_id, $2);
           END LOOP; 
        END; 
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_fielddefinitiongroup_field(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_fieldDefinitionGroup_field.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:fieldDefinitionGroup/fields/field
        IF ((current_row.fields_field_xnat_fieldDefiniti_xnat_fielddefinitiongroup_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_fieldDefinitionGroup(current_row.fields_field_xnat_fieldDefiniti_xnat_fielddefinitiongroup_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_fielddefinitiongroup_field_possiblevalue(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_fieldDefinitionGroup_field_possibleValue.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:fieldDefinitionGroup_field/possibleValues/possibleValue
        IF ((current_row.possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field IS NOT NULL)) THEN
        PERFORM update_ls_xnat_fieldDefinitionGroup_field(current_row.possiblevalues_possiblevalue_xn_xnat_fielddefinitiongroup_field, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_genericdata(character varying, integer) RETURNS character varying
    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 update_ls_ext_xnat_genericData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element138='xnat:pVisitData') THEN
                PERFORM update_ls_xnat_pVisitData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element138;
                    PERFORM update_ls_ext_xnat_genericData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_gmscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:gmScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmScanData.*, meta.meta_data_id 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
         UPDATE xnat_gmScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_gmsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:gmSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmSessionData.*, meta.meta_data_id FROM xnat_gmSessionData LEFT JOIN xnat_gmSessionData_meta_data meta ON xnat_gmSessionData.gmSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_gmSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_gmvscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:gmvScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmvScanData.*, meta.meta_data_id 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
         UPDATE xnat_gmvScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_gmvsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:gmvSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_gmvSessionData.*, meta.meta_data_id FROM xnat_gmvSessionData LEFT JOIN xnat_gmvSessionData_meta_data meta ON xnat_gmvSessionData.gmvSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_gmvSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_hdscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:hdScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_hdScanData.*, meta.meta_data_id 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
         UPDATE xnat_hdScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_hdsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:hdSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_hdSessionData.*, meta.meta_data_id FROM xnat_hdSessionData LEFT JOIN xnat_hdSessionData_meta_data meta ON xnat_hdSessionData.hdSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_hdSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_imageassessordata(character varying, integer) RETURNS character varying
    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 update_ls_ext_xnat_imageAssessorData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element142='scr:screeningAssessment') THEN
                PERFORM update_ls_scr_screeningAssessment( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='val:protocolData') THEN
                PERFORM update_ls_val_protocolData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:mrAssessorData') THEN
                PERFORM update_ls_ext_xnat_mrAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:petAssessorData') THEN
                PERFORM update_ls_xnat_petAssessorData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:qcAssessmentData') THEN
                PERFORM update_ls_xnat_qcAssessmentData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element142='xnat:qcManualAssessorData') THEN
                PERFORM update_ls_xnat_qcManualAssessorData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element142;
                    PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_imageresource(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageResource.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_resource( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_imageresourceseries(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageResourceSeries.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_resourceSeries( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_imagescandata(integer, integer) RETURNS character varying
    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 update_ls_ext_xnat_imageScanData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element100='xnat:mrScanData') THEN
                PERFORM update_ls_xnat_mrScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:petScanData') THEN
                PERFORM update_ls_xnat_petScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ctScanData') THEN
                PERFORM update_ls_xnat_ctScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:crScanData') THEN
                PERFORM update_ls_xnat_crScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:dxScanData') THEN
                PERFORM update_ls_xnat_dxScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:mgScanData') THEN
                PERFORM update_ls_xnat_mgScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ioScanData') THEN
                PERFORM update_ls_xnat_ioScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:usScanData') THEN
                PERFORM update_ls_xnat_usScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:ecgScanData') THEN
                PERFORM update_ls_xnat_ecgScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:hdScanData') THEN
                PERFORM update_ls_xnat_hdScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:epsScanData') THEN
                PERFORM update_ls_xnat_epsScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xaScanData') THEN
                PERFORM update_ls_xnat_xaScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:rfScanData') THEN
                PERFORM update_ls_xnat_rfScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xa3DScanData') THEN
                PERFORM update_ls_xnat_xa3DScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:dx3DCraniofacialScanData') THEN
                PERFORM update_ls_xnat_dx3DCraniofacialScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:nmScanData') THEN
                PERFORM update_ls_xnat_nmScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:srScanData') THEN
                PERFORM update_ls_xnat_srScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:esScanData') THEN
                PERFORM update_ls_xnat_esScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:esvScanData') THEN
                PERFORM update_ls_xnat_esvScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:gmScanData') THEN
                PERFORM update_ls_xnat_gmScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:gmvScanData') THEN
                PERFORM update_ls_xnat_gmvScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:smScanData') THEN
                PERFORM update_ls_xnat_smScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xcScanData') THEN
                PERFORM update_ls_xnat_xcScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:xcvScanData') THEN
                PERFORM update_ls_xnat_xcvScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:opScanData') THEN
                PERFORM update_ls_xnat_opScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:optScanData') THEN
                PERFORM update_ls_xnat_optScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:rtImageScanData') THEN
                PERFORM update_ls_xnat_rtImageScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:scScanData') THEN
                PERFORM update_ls_xnat_scScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:segScanData') THEN
                PERFORM update_ls_xnat_segScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:mrsScanData') THEN
                PERFORM update_ls_xnat_mrsScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:voiceAudioScanData') THEN
                PERFORM update_ls_xnat_voiceAudioScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:otherDicomScanData') THEN
                PERFORM update_ls_xnat_otherDicomScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:megScanData') THEN
                PERFORM update_ls_xnat_megScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element100='xnat:eegScanData') THEN
                PERFORM update_ls_xnat_eegScanData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element100;
                    PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_imagescandata_share(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_imageScanData_share.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:imageScanData/sharing/share
        IF ((current_row.sharing_share_xnat_imageScanDat_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_imageScanData(current_row.sharing_share_xnat_imageScanDat_xnat_imagescandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_imagesessiondata(character varying, integer) RETURNS character varying
    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 update_ls_ext_xnat_imageSessionData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element156='xnat:mrSessionData') THEN
                PERFORM update_ls_xnat_mrSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:petSessionData') THEN
                PERFORM update_ls_xnat_petSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:petmrSessionData') THEN
                PERFORM update_ls_xnat_petmrSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ctSessionData') THEN
                PERFORM update_ls_xnat_ctSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:crSessionData') THEN
                PERFORM update_ls_xnat_crSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:dxSessionData') THEN
                PERFORM update_ls_xnat_dxSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:mgSessionData') THEN
                PERFORM update_ls_xnat_mgSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ioSessionData') THEN
                PERFORM update_ls_xnat_ioSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:usSessionData') THEN
                PERFORM update_ls_xnat_usSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:ecgSessionData') THEN
                PERFORM update_ls_xnat_ecgSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:hdSessionData') THEN
                PERFORM update_ls_xnat_hdSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:epsSessionData') THEN
                PERFORM update_ls_xnat_epsSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xaSessionData') THEN
                PERFORM update_ls_xnat_xaSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:rfSessionData') THEN
                PERFORM update_ls_xnat_rfSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xa3DSessionData') THEN
                PERFORM update_ls_xnat_xa3DSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:dx3DCraniofacialSessionData') THEN
                PERFORM update_ls_xnat_dx3DCraniofacialSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:nmSessionData') THEN
                PERFORM update_ls_xnat_nmSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:srSessionData') THEN
                PERFORM update_ls_xnat_srSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:esSessionData') THEN
                PERFORM update_ls_xnat_esSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:esvSessionData') THEN
                PERFORM update_ls_xnat_esvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:gmSessionData') THEN
                PERFORM update_ls_xnat_gmSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:gmvSessionData') THEN
                PERFORM update_ls_xnat_gmvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:smSessionData') THEN
                PERFORM update_ls_xnat_smSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xcSessionData') THEN
                PERFORM update_ls_xnat_xcSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:xcvSessionData') THEN
                PERFORM update_ls_xnat_xcvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:opSessionData') THEN
                PERFORM update_ls_xnat_opSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:optSessionData') THEN
                PERFORM update_ls_xnat_optSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:rtSessionData') THEN
                PERFORM update_ls_xnat_rtSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:otherDicomSessionData') THEN
                PERFORM update_ls_xnat_otherDicomSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:megSessionData') THEN
                PERFORM update_ls_xnat_megSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element156='xnat:eegSessionData') THEN
                PERFORM update_ls_xnat_eegSessionData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element156;
                    PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_investigatordata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:investigatorData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_investigatorData.*, meta.meta_data_id 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
         UPDATE xnat_investigatorData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:projectData/PI
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_projectData WHERE pi_xnat_investigatordata_id=current_row.xnat_investigatordata_id
        LOOP
        PERFORM update_ls_xnat_projectData( parent_row.id, $2);
        END LOOP;
        END;

        --PROCESS MAPPING TABLE RELATION xnat:projectData/investigators/investigator
        DECLARE 
        mapping_row RECORD; 
        BEGIN 
        FOR mapping_row IN SELECT * FROM xnat_projectData_investigator WHERE  xnat_investigatorData_xnat_investigatordata_id=current_row.xnat_investigatordata_id
           LOOP 
               PERFORM update_ls_xnat_projectData( mapping_row.xnat_projectData_id, $2);
           END LOOP; 
        END; 

        --PROCESS SUPERIOR RELATION xnat:subjectData/investigator
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_subjectData WHERE investigator_xnat_investigatordata_id=current_row.xnat_investigatordata_id
        LOOP
        PERFORM update_ls_xnat_subjectData( parent_row.id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:experimentData/investigator
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_experimentData WHERE investigator_xnat_investigatordata_id=current_row.xnat_investigatordata_id
        LOOP
        PERFORM update_ls_xnat_experimentData( parent_row.id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_ioscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:ioScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ioScanData.*, meta.meta_data_id 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
         UPDATE xnat_ioScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_iosessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:ioSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_ioSessionData.*, meta.meta_data_id FROM xnat_ioSessionData LEFT JOIN xnat_ioSessionData_meta_data meta ON xnat_ioSessionData.ioSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_ioSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_megscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:megScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_megScanData.*, meta.meta_data_id 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
         UPDATE xnat_megScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_megsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:megSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_megSessionData.*, meta.meta_data_id FROM xnat_megSessionData LEFT JOIN xnat_megSessionData_meta_data meta ON xnat_megSessionData.megSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_megSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_mgscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:mgScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mgScanData.*, meta.meta_data_id 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
         UPDATE xnat_mgScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_mgsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:mgSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mgSessionData.*, meta.meta_data_id FROM xnat_mgSessionData LEFT JOIN xnat_mgSessionData_meta_data meta ON xnat_mgSessionData.mgSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_mgSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_mrassessordata(character varying, integer) RETURNS character varying
    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 update_ls_ext_xnat_mrAssessorData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element144='xnat:qcAssessmentData') THEN
                PERFORM update_ls_xnat_qcAssessmentData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element144;
                    PERFORM update_ls_ext_xnat_mrAssessorData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_mrqcscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrQcScanData.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_qcScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_mrscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:mrScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrScanData.*, meta.meta_data_id 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
         UPDATE xnat_mrScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_mrsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:mrSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrSessionData.*, meta.meta_data_id FROM xnat_mrSessionData LEFT JOIN xnat_mrSessionData_meta_data meta ON xnat_mrSessionData.mrSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_mrSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_mrsscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:mrsScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_mrsScanData.*, meta.meta_data_id 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
         UPDATE xnat_mrsScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_nmscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:nmScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_nmScanData.*, meta.meta_data_id 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
         UPDATE xnat_nmScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_nmsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:nmSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_nmSessionData.*, meta.meta_data_id FROM xnat_nmSessionData LEFT JOIN xnat_nmSessionData_meta_data meta ON xnat_nmSessionData.nmSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_nmSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_opscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:opScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_opScanData.*, meta.meta_data_id 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
         UPDATE xnat_opScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_opsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:opSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_opSessionData.*, meta.meta_data_id FROM xnat_opSessionData LEFT JOIN xnat_opSessionData_meta_data meta ON xnat_opSessionData.opSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_opSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_optscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:optScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_optScanData.*, meta.meta_data_id 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
         UPDATE xnat_optScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_optsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:optSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_optSessionData.*, meta.meta_data_id FROM xnat_optSessionData LEFT JOIN xnat_optSessionData_meta_data meta ON xnat_optSessionData.optSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_optSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_otherdicomscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:otherDicomScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_otherDicomScanData.*, meta.meta_data_id 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
         UPDATE xnat_otherDicomScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_otherdicomsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:otherDicomSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_otherDicomSessionData.*, meta.meta_data_id FROM xnat_otherDicomSessionData LEFT JOIN xnat_otherDicomSessionData_meta_data meta ON xnat_otherDicomSessionData.otherDicomSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_otherDicomSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_otherqcscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_otherQcScanData.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_qcScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_petassessordata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petAssessorData.*, meta.meta_data_id FROM xnat_petAssessorData LEFT JOIN xnat_petAssessorData_meta_data meta ON xnat_petAssessorData.petAssessorData_info=meta.meta_data_id WHERE  id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_petmrsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:petmrSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petmrSessionData.*, meta.meta_data_id FROM xnat_petmrSessionData LEFT JOIN xnat_petmrSessionData_meta_data meta ON xnat_petmrSessionData.petmrSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_petmrSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_petqcscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petQcScanData.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_qcScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_petqcscandata_processingerror(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petQcScanData_processingError.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:petQcScanData/processingErrors/processingError
        IF ((current_row.processingerrors_processingerro_xnat_qcscandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_petQcScanData(current_row.processingerrors_processingerro_xnat_qcscandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_petscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:petScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petScanData.*, meta.meta_data_id 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
         UPDATE xnat_petScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_petscandata_frame(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petScanData_frame.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:petScanData/parameters/frames/frame
        IF ((current_row.parameters_frames_frame_xnat_pe_xnat_imagescandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_petScanData(current_row.parameters_frames_frame_xnat_pe_xnat_imagescandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_petsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:petSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_petSessionData.*, meta.meta_data_id FROM xnat_petSessionData LEFT JOIN xnat_petSessionData_meta_data meta ON xnat_petSessionData.petSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_petSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_projectdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:projectData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectData.*, meta.meta_data_id FROM xnat_projectData LEFT JOIN xnat_projectData_meta_data meta ON xnat_projectData.projectData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_projectData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_projectdata_alias(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectData_alias.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:projectData/aliases/alias
        IF ((current_row.aliases_alias_xnat_projectData_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_projectData(current_row.aliases_alias_xnat_projectData_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_projectdata_field(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectData_field.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:projectData/fields/field
        IF ((current_row.fields_field_xnat_projectData_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_projectData(current_row.fields_field_xnat_projectData_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_projectparticipant(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_projectParticipant.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:subjectData/sharing/share
        IF ((current_row.subject_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_subjectData(current_row.subject_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_publicationresource(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_publicationResource.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:projectData/publications/publication
        IF ((current_row.publications_publication_xnat_p_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_projectData(current_row.publications_publication_xnat_p_id, $2);
        END IF;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractResource( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_pvisitdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:pVisitData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_pVisitData.*, meta.meta_data_id FROM xnat_pVisitData LEFT JOIN xnat_pVisitData_meta_data meta ON xnat_pVisitData.pVisitData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_pVisitData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_genericData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_qcassessmentdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:qcAssessmentData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcAssessmentData.*, meta.meta_data_id FROM xnat_qcAssessmentData LEFT JOIN xnat_qcAssessmentData_meta_data meta ON xnat_qcAssessmentData.qcAssessmentData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_qcAssessmentData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_mrAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_qcassessmentdata_scan(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcAssessmentData_scan.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:qcAssessmentData/scans/scan
        IF ((current_row.scans_scan_xnat_qcAssessmentDat_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_qcAssessmentData(current_row.scans_scan_xnat_qcAssessmentDat_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_qcassessmentdata_scan_slice(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcAssessmentData_scan_slice.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:qcAssessmentData_scan/sliceQC/slice
        IF ((current_row.sliceqc_slice_xnat_qcAssessment_xnat_qcassessmentdata_scan_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_qcAssessmentData_scan(current_row.sliceqc_slice_xnat_qcAssessment_xnat_qcassessmentdata_scan_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_qcmanualassessordata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:qcManualAssessorData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcManualAssessorData.*, meta.meta_data_id FROM xnat_qcManualAssessorData LEFT JOIN xnat_qcManualAssessorData_meta_data meta ON xnat_qcManualAssessorData.qcManualAssessorData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_qcManualAssessorData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_qcscandata(integer, integer) RETURNS character varying
    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 update_ls_ext_xnat_qcScanData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element30='xnat:mrQcScanData') THEN
                PERFORM update_ls_xnat_mrQcScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:petQcScanData') THEN
                PERFORM update_ls_xnat_petQcScanData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element30='xnat:otherQcScanData') THEN
                PERFORM update_ls_xnat_otherQcScanData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element30;
                    PERFORM update_ls_ext_xnat_qcScanData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_qcscandata_field(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_qcScanData_field.*, meta.meta_data_id 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
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:qcScanData/fields/field
        IF ((current_row.fields_field_xnat_qcScanData_xnat_qcscandata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_qcScanData(current_row.fields_field_xnat_qcScanData_xnat_qcscandata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_reconstructedimagedata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:reconstructedImageData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_reconstructedImageData.*, meta.meta_data_id 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
         UPDATE xnat_reconstructedImageData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:imageSessionData/reconstructions/reconstructedImage
        IF ((current_row.image_session_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_imageSessionData(current_row.image_session_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_reconstructedimagedata_scanid(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_reconstructedImageData_scanID.*, meta.meta_data_id FROM xnat_reconstructedImageData_scanID LEFT JOIN xnat_reconstructedImageData_scanID_meta_data meta ON xnat_reconstructedImageData_scanID.reconstructedImageData_scanID_info=meta.meta_data_id WHERE  xnat_reconstructedimagedata_scanid_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:reconstructedImageData/inScans/scanID
        IF ((current_row.inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_reconstructedImageData(current_row.inscans_scanid_xnat_reconstruct_xnat_reconstructedimagedata_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_regionresource(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:regionResource' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_regionResource.*, meta.meta_data_id FROM xnat_regionResource LEFT JOIN xnat_regionResource_meta_data meta ON xnat_regionResource.regionResource_info=meta.meta_data_id WHERE  xnat_regionresource_id=$1
      LOOP
         UPDATE xnat_regionResource_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:imageSessionData/regions/region
        IF ((current_row.session_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_imageSessionData(current_row.session_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_regionresource_label(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_regionResource_label.*, meta.meta_data_id FROM xnat_regionResource_label LEFT JOIN xnat_regionResource_label_meta_data meta ON xnat_regionResource_label.regionResource_label_info=meta.meta_data_id WHERE  xnat_regionresource_label_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:regionResource/subregionlabels/label
        IF ((current_row.subregionlabels_label_xnat_regi_xnat_regionresource_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_regionResource(current_row.subregionlabels_label_xnat_regi_xnat_regionresource_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_resource(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT table0.xnat_abstractresource_id AS xnat_resource0, table2.element_name AS xdat_meta_element33, table4.insert_date AS xnat_resource_meta_data109 FROM xnat_resource xnat_resource   LEFT JOIN xnat_abstractResource table0 ON xnat_resource.xnat_abstractresource_id=table0.xnat_abstractresource_id   LEFT JOIN xdat_meta_element table2 ON table0.extension=table2.xdat_meta_element_id   LEFT JOIN xnat_resource_meta_data table4 ON xnat_resource.resource_info=table4.meta_data_id) SEARCH WHERE 
 ( (xnat_resource0=$1))
      LOOP
         IF (current_row.xdat_meta_element33 IS NULL) THEN 
             PERFORM update_ls_ext_xnat_resource( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element33='xnat:imageResource') THEN
                PERFORM update_ls_xnat_imageResource( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element33='xnat:resourceCatalog') THEN
                PERFORM update_ls_xnat_resourceCatalog( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element33;
                    PERFORM update_ls_ext_xnat_resource( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_resourcecatalog(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:resourceCatalog' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_resourceCatalog.*, meta.meta_data_id FROM xnat_resourceCatalog LEFT JOIN xnat_resourceCatalog_meta_data meta ON xnat_resourceCatalog.resourceCatalog_info=meta.meta_data_id WHERE  xnat_abstractresource_id=$1
      LOOP
         UPDATE xnat_resourceCatalog_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_resource( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_resourceseries(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT table0.xnat_abstractresource_id AS xnat_resourceSeries0, table2.element_name AS xdat_meta_element35, table4.insert_date AS xnat_resourceSeries_meta_data54 FROM xnat_resourceSeries xnat_resourceSeries   LEFT JOIN xnat_abstractResource table0 ON xnat_resourceSeries.xnat_abstractresource_id=table0.xnat_abstractresource_id   LEFT JOIN xdat_meta_element table2 ON table0.extension=table2.xdat_meta_element_id   LEFT JOIN xnat_resourceSeries_meta_data table4 ON xnat_resourceSeries.resourceSeries_info=table4.meta_data_id) SEARCH WHERE 
 ( (xnat_resourceSeries0=$1))
      LOOP
         IF (current_row.xdat_meta_element35 IS NULL) THEN 
             PERFORM update_ls_ext_xnat_resourceSeries( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element35='xnat:imageResourceSeries') THEN
                PERFORM update_ls_xnat_imageResourceSeries( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element35;
                    PERFORM update_ls_ext_xnat_resourceSeries( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_rfscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:rfScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_rfScanData.*, meta.meta_data_id FROM xnat_rfScanData LEFT JOIN xnat_rfScanData_meta_data meta ON xnat_rfScanData.rfScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_rfScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_rfsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:rfSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_rfSessionData.*, meta.meta_data_id FROM xnat_rfSessionData LEFT JOIN xnat_rfSessionData_meta_data meta ON xnat_rfSessionData.rfSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_rfSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_rtimagescandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:rtImageScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_rtImageScanData.*, meta.meta_data_id FROM xnat_rtImageScanData LEFT JOIN xnat_rtImageScanData_meta_data meta ON xnat_rtImageScanData.rtImageScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_rtImageScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_rtsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:rtSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_rtSessionData.*, meta.meta_data_id FROM xnat_rtSessionData LEFT JOIN xnat_rtSessionData_meta_data meta ON xnat_rtSessionData.rtSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_rtSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_scscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:scScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_scScanData.*, meta.meta_data_id FROM xnat_scScanData LEFT JOIN xnat_scScanData_meta_data meta ON xnat_scScanData.scScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_scScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_segscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:segScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_segScanData.*, meta.meta_data_id FROM xnat_segScanData LEFT JOIN xnat_segScanData_meta_data meta ON xnat_segScanData.segScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_segScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_smscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:smScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_smScanData.*, meta.meta_data_id FROM xnat_smScanData LEFT JOIN xnat_smScanData_meta_data meta ON xnat_smScanData.smScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_smScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_smsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:smSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_smSessionData.*, meta.meta_data_id FROM xnat_smSessionData LEFT JOIN xnat_smSessionData_meta_data meta ON xnat_smSessionData.smSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_smSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_srscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:srScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_srScanData.*, meta.meta_data_id FROM xnat_srScanData LEFT JOIN xnat_srScanData_meta_data meta ON xnat_srScanData.srScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_srScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_srsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:srSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_srSessionData.*, meta.meta_data_id FROM xnat_srSessionData LEFT JOIN xnat_srSessionData_meta_data meta ON xnat_srSessionData.srSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_srSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_statisticsdata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_statisticsData.*, meta.meta_data_id FROM xnat_statisticsData LEFT JOIN xnat_statisticsData_meta_data meta ON xnat_statisticsData.statisticsData_info=meta.meta_data_id WHERE  xnat_abstractstatistics_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractStatistics( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_statisticsdata_addfield(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_statisticsData_addField.*, meta.meta_data_id FROM xnat_statisticsData_addField LEFT JOIN xnat_statisticsData_addField_meta_data meta ON xnat_statisticsData_addField.statisticsData_addField_info=meta.meta_data_id WHERE  xnat_statisticsdata_addfield_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:statisticsData/addField
        IF ((current_row.xnat_statisticsData_xnat_abstractstatistics_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_statisticsData(current_row.xnat_statisticsData_xnat_abstractstatistics_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_statisticsdata_additionalstatistics(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_statisticsData_additionalStatistics.*, meta.meta_data_id FROM xnat_statisticsData_additionalStatistics LEFT JOIN xnat_statisticsData_additionalStatistics_meta_data meta ON xnat_statisticsData_additionalStatistics.statisticsData_additionalStatistics_info=meta.meta_data_id WHERE  xnat_statisticsdata_additionalstatistics_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:statisticsData/additionalStatistics
        IF ((current_row.xnat_statisticsData_xnat_abstractstatistics_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_statisticsData(current_row.xnat_statisticsData_xnat_abstractstatistics_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_studyprotocol(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_studyProtocol.*, meta.meta_data_id FROM xnat_studyProtocol LEFT JOIN xnat_studyProtocol_meta_data meta ON xnat_studyProtocol.studyProtocol_info=meta.meta_data_id WHERE  xnat_abstractprotocol_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractProtocol( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_studyprotocol_condition(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_studyProtocol_condition.*, meta.meta_data_id FROM xnat_studyProtocol_condition LEFT JOIN xnat_studyProtocol_condition_meta_data meta ON xnat_studyProtocol_condition.studyProtocol_condition_info=meta.meta_data_id WHERE  xnat_studyprotocol_condition_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:studyProtocol/acqConditions/condition
        IF ((current_row.acqconditions_condition_xnat_st_xnat_abstractprotocol_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_studyProtocol(current_row.acqconditions_condition_xnat_st_xnat_abstractprotocol_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_studyprotocol_group(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_studyProtocol_group.*, meta.meta_data_id FROM xnat_studyProtocol_group LEFT JOIN xnat_studyProtocol_group_meta_data meta ON xnat_studyProtocol_group.studyProtocol_group_info=meta.meta_data_id WHERE  xnat_studyprotocol_group_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:studyProtocol/subjectGroups/group
        IF ((current_row.subjectgroups_group_xnat_studyP_xnat_abstractprotocol_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_studyProtocol(current_row.subjectgroups_group_xnat_studyP_xnat_abstractprotocol_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_studyprotocol_session(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_studyProtocol_session.*, meta.meta_data_id FROM xnat_studyProtocol_session LEFT JOIN xnat_studyProtocol_session_meta_data meta ON xnat_studyProtocol_session.studyProtocol_session_info=meta.meta_data_id WHERE  xnat_studyprotocol_session_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:studyProtocol/imageSessionTypes/session
        IF ((current_row.imagesessiontypes_session_xnat__xnat_abstractprotocol_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_studyProtocol(current_row.imagesessiontypes_session_xnat__xnat_abstractprotocol_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_studyprotocol_variable(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_studyProtocol_variable.*, meta.meta_data_id FROM xnat_studyProtocol_variable LEFT JOIN xnat_studyProtocol_variable_meta_data meta ON xnat_studyProtocol_variable.studyProtocol_variable_info=meta.meta_data_id WHERE  xnat_studyprotocol_variable_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:studyProtocol/subjectVariables/variable
        IF ((current_row.subjectvariables_variable_xnat__xnat_abstractprotocol_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_studyProtocol(current_row.subjectvariables_variable_xnat__xnat_abstractprotocol_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_subjectassessordata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin
      FOR current_row IN SELECT * FROM (SELECT table0.id AS xnat_subjectAssessorData0, table2.element_name AS xdat_meta_element140, table0.date AS xnat_experimentData4 FROM xnat_subjectAssessorData xnat_subjectAssessorData   LEFT JOIN xnat_experimentData table0 ON xnat_subjectAssessorData.id=table0.id   LEFT JOIN xdat_meta_element table2 ON table0.extension=table2.xdat_meta_element_id) SEARCH WHERE 
 ( (xnat_subjectAssessorData0=$1))
      LOOP
         IF (current_row.xdat_meta_element140 IS NULL) THEN 
             PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
         ELSE
            --CALL EXTENDER 
            declare
               matches int4:=0;
            begin
            IF (current_row.xdat_meta_element140='xnat:subjectVariablesData') THEN
                PERFORM update_ls_xnat_subjectVariablesData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:imageSessionData') THEN
                PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:mrSessionData') THEN
                PERFORM update_ls_xnat_mrSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:petSessionData') THEN
                PERFORM update_ls_xnat_petSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:petmrSessionData') THEN
                PERFORM update_ls_xnat_petmrSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:ctSessionData') THEN
                PERFORM update_ls_xnat_ctSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:crSessionData') THEN
                PERFORM update_ls_xnat_crSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:dxSessionData') THEN
                PERFORM update_ls_xnat_dxSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:mgSessionData') THEN
                PERFORM update_ls_xnat_mgSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:ioSessionData') THEN
                PERFORM update_ls_xnat_ioSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:usSessionData') THEN
                PERFORM update_ls_xnat_usSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:ecgSessionData') THEN
                PERFORM update_ls_xnat_ecgSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:hdSessionData') THEN
                PERFORM update_ls_xnat_hdSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:epsSessionData') THEN
                PERFORM update_ls_xnat_epsSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:xaSessionData') THEN
                PERFORM update_ls_xnat_xaSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:rfSessionData') THEN
                PERFORM update_ls_xnat_rfSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:xa3DSessionData') THEN
                PERFORM update_ls_xnat_xa3DSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:dx3DCraniofacialSessionData') THEN
                PERFORM update_ls_xnat_dx3DCraniofacialSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:nmSessionData') THEN
                PERFORM update_ls_xnat_nmSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:srSessionData') THEN
                PERFORM update_ls_xnat_srSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:esSessionData') THEN
                PERFORM update_ls_xnat_esSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:esvSessionData') THEN
                PERFORM update_ls_xnat_esvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:gmSessionData') THEN
                PERFORM update_ls_xnat_gmSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:gmvSessionData') THEN
                PERFORM update_ls_xnat_gmvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:smSessionData') THEN
                PERFORM update_ls_xnat_smSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:xcSessionData') THEN
                PERFORM update_ls_xnat_xcSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:xcvSessionData') THEN
                PERFORM update_ls_xnat_xcvSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:opSessionData') THEN
                PERFORM update_ls_xnat_opSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:optSessionData') THEN
                PERFORM update_ls_xnat_optSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:rtSessionData') THEN
                PERFORM update_ls_xnat_rtSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:otherDicomSessionData') THEN
                PERFORM update_ls_xnat_otherDicomSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:megSessionData') THEN
                PERFORM update_ls_xnat_megSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat:eegSessionData') THEN
                PERFORM update_ls_xnat_eegSessionData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat_a:sideEffectsPittsburghData') THEN
                PERFORM update_ls_xnat_a_sideEffectsPittsburghData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat_a:ybocsData') THEN
                PERFORM update_ls_xnat_a_ybocsData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat_a:ygtssData') THEN
                PERFORM update_ls_xnat_a_ygtssData( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat_a:updrs3Data') THEN
                PERFORM update_ls_xnat_a_updrs3Data( $1, $2);
                matches:=1;
            END IF;
            IF (current_row.xdat_meta_element140='xnat_a:scidResearchData') THEN
                PERFORM update_ls_xnat_a_scidResearchData( $1, $2);
                matches:=1;
            END IF;
                IF (matches=0) THEN
       RAISE NOTICE 'ERROR: NO MATCHING EXTENSION FOUND FOR (%)', current_row.xdat_meta_element140;
                    PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
                END IF;
            end;
         end IF;
      END LOOP;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_subjectdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:subjectData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_subjectData.*, meta.meta_data_id FROM xnat_subjectData LEFT JOIN xnat_subjectData_meta_data meta ON xnat_subjectData.subjectData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_subjectData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_subjectdata_addid(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_subjectData_addID.*, meta.meta_data_id FROM xnat_subjectData_addID LEFT JOIN xnat_subjectData_addID_meta_data meta ON xnat_subjectData_addID.subjectData_addID_info=meta.meta_data_id WHERE  xnat_subjectdata_addid_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:subjectData/addID
        IF ((current_row.xnat_subjectData_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_subjectData(current_row.xnat_subjectData_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_subjectdata_field(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_subjectData_field.*, meta.meta_data_id FROM xnat_subjectData_field LEFT JOIN xnat_subjectData_field_meta_data meta ON xnat_subjectData_field.subjectData_field_info=meta.meta_data_id WHERE  xnat_subjectdata_field_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:subjectData/fields/field
        IF ((current_row.fields_field_xnat_subjectData_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_subjectData(current_row.fields_field_xnat_subjectData_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_subjectmetadata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_subjectMetadata.*, meta.meta_data_id FROM xnat_subjectMetadata LEFT JOIN xnat_subjectMetadata_meta_data meta ON xnat_subjectMetadata.subjectMetadata_info=meta.meta_data_id WHERE  xnat_abstractsubjectmetadata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_abstractSubjectMetadata( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_subjectvariablesdata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:subjectVariablesData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_subjectVariablesData.*, meta.meta_data_id FROM xnat_subjectVariablesData LEFT JOIN xnat_subjectVariablesData_meta_data meta ON xnat_subjectVariablesData.subjectVariablesData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_subjectVariablesData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_subjectAssessorData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_subjectvariablesdata_variable(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_subjectVariablesData_variable.*, meta.meta_data_id FROM xnat_subjectVariablesData_variable LEFT JOIN xnat_subjectVariablesData_variable_meta_data meta ON xnat_subjectVariablesData_variable.subjectVariablesData_variable_info=meta.meta_data_id WHERE  xnat_subjectvariablesdata_variable_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:subjectVariablesData/variables/variable
        IF ((current_row.variables_variable_xnat_subject_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_subjectVariablesData(current_row.variables_variable_xnat_subject_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_usscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:usScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_usScanData.*, meta.meta_data_id FROM xnat_usScanData LEFT JOIN xnat_usScanData_meta_data meta ON xnat_usScanData.usScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_usScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_ussessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:usSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_usSessionData.*, meta.meta_data_id FROM xnat_usSessionData LEFT JOIN xnat_usSessionData_meta_data meta ON xnat_usSessionData.usSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_usSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_validationdata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_validationData.*, meta.meta_data_id FROM xnat_validationData LEFT JOIN xnat_validationData_meta_data meta ON xnat_validationData.validationData_info=meta.meta_data_id WHERE  xnat_validationdata_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUPERIOR RELATION xnat:experimentData/validation
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_experimentData WHERE validation_xnat_validationdata_id=current_row.xnat_validationdata_id
        LOOP
        PERFORM update_ls_xnat_experimentData( parent_row.id, $2);
        END LOOP;
        END;

        --PROCESS SUPERIOR RELATION xnat:imageScanData/validation
        DECLARE 
        parent_row RECORD; 
        BEGIN 
        FOR parent_row IN SELECT * FROM xnat_imageScanData WHERE validation_xnat_validationdata_id=current_row.xnat_validationdata_id
        LOOP
        PERFORM update_ls_xnat_imageScanData( parent_row.xnat_imagescandata_id, $2);
        END LOOP;
        END;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_voiceaudioscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:voiceAudioScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_voiceAudioScanData.*, meta.meta_data_id FROM xnat_voiceAudioScanData LEFT JOIN xnat_voiceAudioScanData_meta_data meta ON xnat_voiceAudioScanData.voiceAudioScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_voiceAudioScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_volumetricregion(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_volumetricRegion.*, meta.meta_data_id FROM xnat_volumetricRegion LEFT JOIN xnat_volumetricRegion_meta_data meta ON xnat_volumetricRegion.volumetricRegion_info=meta.meta_data_id WHERE  xnat_volumetricregion_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_volumetricregion_subregion(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_volumetricRegion_subregion.*, meta.meta_data_id FROM xnat_volumetricRegion_subregion LEFT JOIN xnat_volumetricRegion_subregion_meta_data meta ON xnat_volumetricRegion_subregion.volumetricRegion_subregion_info=meta.meta_data_id WHERE  xnat_volumetricregion_subregion_id=$1
      LOOP
      END LOOP;

      --UPDATE PARENTS;

        --PROCESS SUBORDINATE RELATION xnat:volumetricRegion/subregions/subregion
        IF ((current_row.subregions_subregion_xnat_volum_xnat_volumetricregion_id IS NOT NULL)) THEN
        PERFORM update_ls_xnat_volumetricRegion(current_row.subregions_subregion_xnat_volum_xnat_volumetricregion_id, $2);
        END IF;
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_xa3dscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:xa3DScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_xa3DScanData.*, meta.meta_data_id FROM xnat_xa3DScanData LEFT JOIN xnat_xa3DScanData_meta_data meta ON xnat_xa3DScanData.xa3DScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_xa3DScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_xa3dsessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:xa3DSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_xa3DSessionData.*, meta.meta_data_id FROM xnat_xa3DSessionData LEFT JOIN xnat_xa3DSessionData_meta_data meta ON xnat_xa3DSessionData.xa3DSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_xa3DSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_xascandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:xaScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_xaScanData.*, meta.meta_data_id FROM xnat_xaScanData LEFT JOIN xnat_xaScanData_meta_data meta ON xnat_xaScanData.xaScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_xaScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_xasessiondata(character varying, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:xaSessionData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_xaSessionData.*, meta.meta_data_id FROM xnat_xaSessionData LEFT JOIN xnat_xaSessionData_meta_data meta ON xnat_xaSessionData.xaSessionData_info=meta.meta_data_id WHERE  id=$1
      LOOP
         UPDATE xnat_xaSessionData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageSessionData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

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

CREATE FUNCTION public.update_ls_xnat_xcscandata(integer, integer) RETURNS character varying
    LANGUAGE plpgsql
    AS $_$
    declare
     current_row RECORD;
    begin

       --DELETE CACHE
      declare
        current_cache RECORD;
      BEGIN
        FOR current_cache IN SELECT oid FROM xs_item_cache WHERE elementname='xnat:xcScanData' AND ids=CAST($1 AS text)
        LOOP
         DELETE FROM xs_item_cache WHERE oid=current_cache.oid;
        END LOOP;
      END;

       --UPDATE LOCAL ROW
      FOR current_row IN SELECT xnat_xcScanData.*, meta.meta_data_id FROM xnat_xcScanData LEFT JOIN xnat_xcScanData_meta_data meta ON xnat_xcScanData.xcScanData_info=meta.meta_data_id WHERE  xnat_imagescandata_id=$1
      LOOP
         UPDATE xnat_xcScanData_meta_data SET last_modified=NOW(), modified=1 WHERE meta_data_id=current_row.meta_data_id;
      END LOOP;

      --UPDATE PARENTS;

        -- PROCESS EXTENSION
        PERFORM update_ls_ext_xnat_imageScanData( $1, $2);
	
	RETURN 'DONE';
    end;
$_$;


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

--
