-- Name: xnat_imagescandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_imagescandata (
    image_session_id character varying(255),
    note character varying(255),
    quality character varying(255),
    condition character varying(255),
    series_description character varying(255),
    series_class character varying(255),
    documentation text,
    scanner character varying(255),
    scanner_manufacturer character varying(255),
    scanner_model character varying(255),
    scanner_softwareversion character varying(255),
    modality character varying(255),
    frames integer,
    operator character varying(255),
    validation_xnat_validationdata_id integer,
    starttime time without time zone,
    start_date date,
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    type character varying(255),
    uid character varying(255),
    project character varying(255),
    extension integer,
    imagescandata_info integer,
    xnat_imagescandata_id integer NOT NULL
);


ALTER TABLE public.xnat_imagescandata OWNER TO xnat;

--
-- Name: displayfields_xnat_crscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_crscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_crscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_crscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_crscandata0,
            table2.status AS xnat_crscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_crscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_crscandata xnat_crscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_crscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_crscandata_meta_data table2 ON ((xnat_crscandata.crscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_crscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_crscandata0,
                    table2.insert_date AS xnat_crscandata_meta_data121
                   FROM ((public.xnat_crscandata xnat_crscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_crscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_crscandata_meta_data table2 ON ((xnat_crscandata.crscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_crscandata0 = search.xnat_crscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_crscandata OWNER TO xnat;

--
-- Name: xnat_crsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_crsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    crsessiondata_info integer
);


ALTER TABLE public.xnat_crsessiondata OWNER TO xnat;

--
-- Name: xnat_crsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_crsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_crsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_crsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_crsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:crSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_crsessiondata_projects OWNER TO xnat;

--
-- Name: xnat_imagesessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_imagesessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    scanner character varying(255),
    scanner_manufacturer character varying(255),
    scanner_model character varying(255),
    operator character varying(255),
    prearchivepath character varying(255),
    dcmaccessionnumber character varying(255),
    dcmpatientid character varying(255),
    dcmpatientname character varying(255),
    dcmpatientbirthdate date,
    dcmpatientweight double precision,
    session_type character varying(255),
    modality character varying(255),
    uid character varying(255),
    study_id character varying(255),
    imagesessiondata_info integer
);


ALTER TABLE public.xnat_imagesessiondata OWNER TO xnat;

--
-- Name: displayfields_xnat_crsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_crsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_crsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_crsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_crsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_crsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_crsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_crsessiondata0) search_1.xnat_crsessiondata0,
            search_1.xnat_crsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_crsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_crsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_crsessiondata0,
                    table4.status AS xnat_crsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_crsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_crsessiondata_projects.projects AS xnat_crsessiondata_projects_projects
                   FROM ((((((((public.xnat_crsessiondata xnat_crsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_crsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_crsessiondata_meta_data table4 ON ((xnat_crsessiondata.crsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_crsessiondata_projects xnat_crsessiondata_projects ON (((table2.id)::text = (xnat_crsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_crsessiondata_sordata_ex_xnat_crsessiondata0,
                            search_2.xnat_crsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_crsessiondata_sor_xnat_subjectassessordata19,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_crsessiondata_1.xnat_crsessiondata0 AS xnat_crsessiondata_sordata_ex_xnat_crsessiondata0,
                                    xnat_crsessiondata_1.xnat_experimentdata22 AS xnat_crsessiondata_sordata__xnat_experimentdata22,
                                    xnat_crsessiondata_1.xnat_subjectassessordata19 AS xnat_crsessiondata_sor_xnat_subjectassessordata19,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_crsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_crsessiondata xnat_crsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_crsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_crsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_crsessiondata_1.xnat_subjectassessordata19)::text)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, search_2.xnat_crsessiondata_sordata__xnat_experimentdata22 DESC, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)))) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_crsessiondata_sordata_ex_xnat_crsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_crsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_crsessiondata0
           FROM ( SELECT table2.id AS xnat_crsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_crsessiondata xnat_crsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_crsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_crsessiondata0)::text = (search.xnat_crsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_crsessiondata OWNER TO xnat;

--
-- Name: xnat_ctscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ctscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    parameters_voxelres_units character varying(255),
    parameters_voxelres_x double precision,
    parameters_voxelres_y double precision,
    parameters_voxelres_z double precision,
    parameters_orientation character varying(255),
    parameters_subjectposition character varying(255),
    parameters_fov_x integer,
    parameters_fov_y integer,
    parameters_rescale_intercept character varying(255),
    parameters_rescale_slope character varying(255),
    parameters_kvp double precision,
    parameters_acquisitionnumber integer,
    parameters_imagetype character varying(255),
    parameters_options character varying(255),
    parameters_collectiondiameter double precision,
    parameters_distancesourcetodetector double precision,
    parameters_distancesourcetopatient double precision,
    parameters_gantrytilt double precision,
    parameters_tableheight double precision,
    parameters_rotationdirection character varying(255),
    parameters_exposuretime double precision,
    parameters_xraytubecurrent double precision,
    parameters_exposure double precision,
    parameters_filter character varying(255),
    parameters_generatorpower double precision,
    parameters_convolutionkernel character varying(255),
    parameters_collimationwidth_single double precision,
    parameters_collimationwidth_total double precision,
    parameters_tablespeed double precision,
    parameters_tablefeedperrotation double precision,
    parameters_pitchfactor double precision,
    parameters_estimateddosesaving_modulation character varying(255),
    parameters_estimateddosesaving double precision,
    parameters_ctdivol double precision,
    parameters_derivation character varying(255),
    parameters_contrastbolus_xnat_contrastbolus_id integer,
    dcmvalidation character varying(255),
    dcmvalidation_status integer,
    ctscandata_info integer
);


ALTER TABLE public.xnat_ctscandata OWNER TO xnat;

--
-- Name: xnat_ctscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ctscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_ctscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_ctscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_ctscandata AS
 SELECT search.xnat_imagescandata40 AS image_session_id,
    search.xnat_imagescandata41 AS note,
    search.xnat_imagescandata42 AS quality,
    search.xnat_imagescandata43 AS condition,
    search.xnat_imagescandata44 AS series_description,
    search.xnat_imagescandata46 AS documentation,
    search.xnat_imagescandata47 AS scanner,
    search.xnat_imagescandata48 AS scanner_manufacturer,
    search.xnat_imagescandata49 AS scanner_model,
    search.xnat_imagescandata51 AS modality,
    search.xnat_imagescandata52 AS frames,
    search.xnat_imagescandata53 AS operator,
    search.xnat_imagescandata55 AS starttime,
    search.xnat_imagescandata57 AS id,
    search.xnat_imagescandata58 AS type,
    search.xnat_imagescandata59 AS uid,
    search.xnat_imagescandata60 AS project,
    search.xnat_ctscandata_meta_data197 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_ctscandata1 AS parameters_voxelres_units,
    search.xnat_ctscandata2 AS parameters_voxelres_x,
    search.xnat_ctscandata3 AS parameters_voxelres_y,
    search.xnat_ctscandata4 AS parameters_voxelres_z,
    search.xnat_ctscandata5 AS parameters_orientation,
    search.xnat_ctscandata7 AS parameters_fov_x,
    search.xnat_ctscandata8 AS parameters_fov_y,
    search.xnat_ctscandata9 AS parameters_rescale_intercept,
    search.xnat_ctscandata10 AS parameters_rescale_slope,
    search.xnat_ctscandata11 AS parameters_kvp,
    search.xnat_ctscandata12 AS parameters_acquisitionnumber,
    search.xnat_ctscandata13 AS parameters_imagetype,
    search.xnat_ctscandata14 AS parameters_options,
    search.xnat_ctscandata15 AS parameters_collectiondiameter,
    search.xnat_ctscandata16 AS parameters_distancesourcetodetector,
    search.xnat_ctscandata17 AS parameters_distancesourcetopatient,
    search.xnat_ctscandata18 AS parameters_gantrytilt,
    search.xnat_ctscandata19 AS parameters_tableheight,
    search.xnat_ctscandata20 AS parameters_rotationdirection,
    search.xnat_ctscandata21 AS parameters_exposuretime,
    search.xnat_ctscandata22 AS parameters_xraytubecurrent,
    search.xnat_ctscandata23 AS parameters_exposure,
    search.xnat_ctscandata24 AS parameters_filter,
    search.xnat_ctscandata25 AS parameters_generatorpower,
    search.xnat_ctscandata26 AS parameters_convolutionkernel,
    search.xnat_ctscandata27 AS parameters_collimationwidth_single,
    search.xnat_ctscandata28 AS parameters_collimationwidth_total,
    search.xnat_ctscandata29 AS parameters_tablespeed,
    search.xnat_ctscandata30 AS parameters_tablefeedperrotation,
    search.xnat_ctscandata31 AS parameters_pitchfactor,
    search.xnat_ctscandata32 AS parameters_estimateddosesaving_modulation,
    search.xnat_ctscandata33 AS parameters_estimateddosesaving,
    search.xnat_ctscandata34 AS parameters_ctdivol,
    search.xnat_ctscandata35 AS parameters_derivation,
    search.xnat_ctscandata37 AS dcmvalidation,
    search.xnat_ctscandata38 AS dcmvalidation_status,
    search.xnat_ctscandata_meta_data194 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_ctscandata0,
            table2.status AS xnat_ctscandata_meta_data194,
            table0.image_session_id AS xnat_imagescandata40,
            table0.note AS xnat_imagescandata41,
            table0.quality AS xnat_imagescandata42,
            table0.condition AS xnat_imagescandata43,
            table0.series_description AS xnat_imagescandata44,
            table0.documentation AS xnat_imagescandata46,
            table0.scanner AS xnat_imagescandata47,
            table0.scanner_manufacturer AS xnat_imagescandata48,
            table0.scanner_model AS xnat_imagescandata49,
            table0.modality AS xnat_imagescandata51,
            table0.frames AS xnat_imagescandata52,
            table0.operator AS xnat_imagescandata53,
            table0.starttime AS xnat_imagescandata55,
            table0.id AS xnat_imagescandata57,
            table0.type AS xnat_imagescandata58,
            table0.uid AS xnat_imagescandata59,
            table0.project AS xnat_imagescandata60,
            table2.insert_date AS xnat_ctscandata_meta_data197,
            table4.login AS table4_login,
            xnat_ctscandata.parameters_voxelres_units AS xnat_ctscandata1,
            xnat_ctscandata.parameters_voxelres_x AS xnat_ctscandata2,
            xnat_ctscandata.parameters_voxelres_y AS xnat_ctscandata3,
            xnat_ctscandata.parameters_voxelres_z AS xnat_ctscandata4,
            xnat_ctscandata.parameters_orientation AS xnat_ctscandata5,
            xnat_ctscandata.parameters_fov_x AS xnat_ctscandata7,
            xnat_ctscandata.parameters_fov_y AS xnat_ctscandata8,
            xnat_ctscandata.parameters_rescale_intercept AS xnat_ctscandata9,
            xnat_ctscandata.parameters_rescale_slope AS xnat_ctscandata10,
            xnat_ctscandata.parameters_kvp AS xnat_ctscandata11,
            xnat_ctscandata.parameters_acquisitionnumber AS xnat_ctscandata12,
            xnat_ctscandata.parameters_imagetype AS xnat_ctscandata13,
            xnat_ctscandata.parameters_options AS xnat_ctscandata14,
            xnat_ctscandata.parameters_collectiondiameter AS xnat_ctscandata15,
            xnat_ctscandata.parameters_distancesourcetodetector AS xnat_ctscandata16,
            xnat_ctscandata.parameters_distancesourcetopatient AS xnat_ctscandata17,
            xnat_ctscandata.parameters_gantrytilt AS xnat_ctscandata18,
            xnat_ctscandata.parameters_tableheight AS xnat_ctscandata19,
            xnat_ctscandata.parameters_rotationdirection AS xnat_ctscandata20,
            xnat_ctscandata.parameters_exposuretime AS xnat_ctscandata21,
            xnat_ctscandata.parameters_xraytubecurrent AS xnat_ctscandata22,
            xnat_ctscandata.parameters_exposure AS xnat_ctscandata23,
            xnat_ctscandata.parameters_filter AS xnat_ctscandata24,
            xnat_ctscandata.parameters_generatorpower AS xnat_ctscandata25,
            xnat_ctscandata.parameters_convolutionkernel AS xnat_ctscandata26,
            xnat_ctscandata.parameters_collimationwidth_single AS xnat_ctscandata27,
            xnat_ctscandata.parameters_collimationwidth_total AS xnat_ctscandata28,
            xnat_ctscandata.parameters_tablespeed AS xnat_ctscandata29,
            xnat_ctscandata.parameters_tablefeedperrotation AS xnat_ctscandata30,
            xnat_ctscandata.parameters_pitchfactor AS xnat_ctscandata31,
            xnat_ctscandata.parameters_estimateddosesaving_modulation AS xnat_ctscandata32,
            xnat_ctscandata.parameters_estimateddosesaving AS xnat_ctscandata33,
            xnat_ctscandata.parameters_ctdivol AS xnat_ctscandata34,
            xnat_ctscandata.parameters_derivation AS xnat_ctscandata35,
            xnat_ctscandata.dcmvalidation AS xnat_ctscandata37,
            xnat_ctscandata.dcmvalidation_status AS xnat_ctscandata38
           FROM (((public.xnat_ctscandata xnat_ctscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_ctscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_ctscandata_meta_data table2 ON ((xnat_ctscandata.ctscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_ctscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_ctscandata0,
                    table2.insert_date AS xnat_ctscandata_meta_data197
                   FROM ((public.xnat_ctscandata xnat_ctscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_ctscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_ctscandata_meta_data table2 ON ((xnat_ctscandata.ctscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_ctscandata0 = search.xnat_ctscandata0)))
  ORDER BY search.xnat_imagescandata40;


ALTER TABLE public.displayfields_xnat_ctscandata OWNER TO xnat;

--
-- Name: xnat_ctsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ctsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    ctsessiondata_info integer
);


ALTER TABLE public.xnat_ctsessiondata OWNER TO xnat;

--
-- Name: xnat_ctsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ctsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_ctsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_ctsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_ctsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:ctSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_ctsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_ctsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_ctsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_ctsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE(date_part('year'::text, age((search.xnat_experimentdata22)::timestamp with time zone, (search.xnat_demographicdata_xnat_demographicdata1)::timestamp with time zone)), floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_ctsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_ctsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_ctsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_imagesessiondata8 AS dcmaccessionnumber,
    search.xnat_imagesessiondata9 AS dcmpatientid,
    search.xnat_imagesessiondata10 AS dcmpatientname,
    search.xnat_imagesessiondata15 AS uid,
    search.xnat_ctsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_ctsessiondata0) search_1.xnat_ctsessiondata0,
            search_1.xnat_ctsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_ctsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_imagesessiondata8,
            search_1.xnat_imagesessiondata9,
            search_1.xnat_imagesessiondata10,
            search_1.xnat_imagesessiondata15,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_ctsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_ctsessiondata0,
                    table4.status AS xnat_ctsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_ctsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    table0.dcmaccessionnumber AS xnat_imagesessiondata8,
                    table0.dcmpatientid AS xnat_imagesessiondata9,
                    table0.dcmpatientname AS xnat_imagesessiondata10,
                    table0.uid AS xnat_imagesessiondata15,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_ctsessiondata_projects.projects AS xnat_ctsessiondata_projects_projects
                   FROM ((((((((public.xnat_ctsessiondata xnat_ctsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_ctsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_ctsessiondata_meta_data table4 ON ((xnat_ctsessiondata.ctsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_ctsessiondata_projects xnat_ctsessiondata_projects ON (((table2.id)::text = (xnat_ctsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_ctsessiondata_sordata_ex_xnat_ctsessiondata0,
                            search_2.xnat_ctsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_ctsessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_ctsessiondata_1.xnat_ctsessiondata0 AS xnat_ctsessiondata_sordata_ex_xnat_ctsessiondata0,
                                    xnat_ctsessiondata_1.xnat_experimentdata22 AS xnat_ctsessiondata_sordata__xnat_experimentdata22,
                                    xnat_ctsessiondata_1.xnat_subjectassessordata19 AS xnat_ctsessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_ctsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_ctsessiondata xnat_ctsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_ctsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_ctsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_ctsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_ctsessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_ctsessiondata_sordata_ex_xnat_ctsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_ctsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_ctsessiondata0
           FROM ( SELECT table2.id AS xnat_ctsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_ctsessiondata xnat_ctsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_ctsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_ctsessiondata0)::text = (search.xnat_ctsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_ctsessiondata OWNER TO xnat;

--
-- Name: xnat_dicomcodedvalue; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dicomcodedvalue (
    value character varying(255),
    designator character varying(255),
    version character varying(255),
    meaning character varying(255),
    dicomcodedvalue_info integer,
    xnat_dicomcodedvalue_id integer NOT NULL
);


ALTER TABLE public.xnat_dicomcodedvalue OWNER TO xnat;

--
-- Name: xnat_dicomcodedvalue_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dicomcodedvalue_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_dicomcodedvalue_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_dicomcodedvalue; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_dicomcodedvalue AS
 SELECT search.xnat_dicomcodedvalue_meta_data11 AS insert_date,
    search.table2_login AS insert_user,
    search.xnat_dicomcodedvalue0 AS value,
    search.xnat_dicomcodedvalue1 AS designator,
    search.xnat_dicomcodedvalue2 AS version,
    search.xnat_dicomcodedvalue3 AS meaning,
    search.xnat_dicomcodedvalue_meta_data8 AS quarantine_status
   FROM (( SELECT DISTINCT xnat_dicomcodedvalue.xnat_dicomcodedvalue_id AS xnat_dicomcodedvalue5,
            table1.status AS xnat_dicomcodedvalue_meta_data8,
            table1.insert_date AS xnat_dicomcodedvalue_meta_data11,
            table2.login AS table2_login,
            xnat_dicomcodedvalue.value AS xnat_dicomcodedvalue0,
            xnat_dicomcodedvalue.designator AS xnat_dicomcodedvalue1,
            xnat_dicomcodedvalue.version AS xnat_dicomcodedvalue2,
            xnat_dicomcodedvalue.meaning AS xnat_dicomcodedvalue3
           FROM ((public.xnat_dicomcodedvalue xnat_dicomcodedvalue
             LEFT JOIN public.xnat_dicomcodedvalue_meta_data table1 ON ((xnat_dicomcodedvalue.dicomcodedvalue_info = table1.meta_data_id)))
             LEFT JOIN public.xdat_user table2 ON ((table1.insert_user_xdat_user_id = table2.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_dicomcodedvalue5
           FROM ( SELECT xnat_dicomcodedvalue.xnat_dicomcodedvalue_id AS xnat_dicomcodedvalue5,
                    table1.insert_date AS xnat_dicomcodedvalue_meta_data11
                   FROM (public.xnat_dicomcodedvalue xnat_dicomcodedvalue
                     LEFT JOIN public.xnat_dicomcodedvalue_meta_data table1 ON ((xnat_dicomcodedvalue.dicomcodedvalue_info = table1.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_dicomcodedvalue5 = search.xnat_dicomcodedvalue5)))
  ORDER BY search.xnat_dicomcodedvalue_meta_data11;


ALTER TABLE public.displayfields_xnat_dicomcodedvalue OWNER TO xnat;

--
-- Name: xnat_dx3dcraniofacialscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dx3dcraniofacialscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    dx3dcraniofacialscandata_info integer
);


ALTER TABLE public.xnat_dx3dcraniofacialscandata OWNER TO xnat;

--
-- Name: xnat_dx3dcraniofacialscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dx3dcraniofacialscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_dx3dcraniofacialscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_dx3dcraniofacialscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_dx3dcraniofacialscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_dx3dcraniofacialscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_dx3dcraniofacialscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_dx3dcraniofacialscandata0,
            table2.status AS xnat_dx3dcraniofacialscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_dx3dcraniofacialscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_dx3dcraniofacialscandata xnat_dx3dcraniofacialscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_dx3dcraniofacialscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_dx3dcraniofacialscandata_meta_data table2 ON ((xnat_dx3dcraniofacialscandata.dx3dcraniofacialscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_dx3dcraniofacialscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_dx3dcraniofacialscandata0,
                    table2.insert_date AS xnat_dx3dcraniofacialscandata_meta_data121
                   FROM ((public.xnat_dx3dcraniofacialscandata xnat_dx3dcraniofacialscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_dx3dcraniofacialscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_dx3dcraniofacialscandata_meta_data table2 ON ((xnat_dx3dcraniofacialscandata.dx3dcraniofacialscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_dx3dcraniofacialscandata0 = search.xnat_dx3dcraniofacialscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_dx3dcraniofacialscandata OWNER TO xnat;

--
-- Name: xnat_dx3dcraniofacialsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dx3dcraniofacialsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    dx3dcraniofacialsessiondata_info integer
);


ALTER TABLE public.xnat_dx3dcraniofacialsessiondata OWNER TO xnat;

--
-- Name: xnat_dx3dcraniofacialsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dx3dcraniofacialsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_dx3dcraniofacialsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_dx3dcraniofacialsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_dx3dcraniofacialsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:dx3DCraniofacialSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_dx3dcraniofacialsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_dx3dcraniofacialsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_dx3dcraniofacialsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_dx3dcraniofacialsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_dx3dcraniofacialsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_dx3dcraniofacialsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_dx3dcraniofacialsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_dx3dcraniofacialsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_dx3dcraniofacialsessiondata0) search_1.xnat_dx3dcraniofacialsessiondata0,
            search_1.xnat_dx3dcraniofacialsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_dx3dcraniofacialsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_dx3dcraniofacialsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_dx3dcraniofacialsessiondata0,
                    table4.status AS xnat_dx3dcraniofacialsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_dx3dcraniofacialsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_dx3dcraniofacialsessiondata_projects.projects AS xnat_dx3dcraniofacialsessiondata_projects_projects
                   FROM ((((((((public.xnat_dx3dcraniofacialsessiondata xnat_dx3dcraniofacialsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_dx3dcraniofacialsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_dx3dcraniofacialsessiondata_meta_data table4 ON ((xnat_dx3dcraniofacialsessiondata.dx3dcraniofacialsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_dx3dcraniofacialsessiondata_projects xnat_dx3dcraniofacialsessiondata_projects ON (((table2.id)::text = (xnat_dx3dcraniofacialsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_dx3dcraniofacialsessionda_t_dx3dcraniofacialsessiondata0,
                            search_2.xnat_dx3dcraniofacialsessionda_sordata__xnat_experimentdata22,
                            search_2.xnat_dx3dcraniofacialsessionda_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_dx3dcraniofacialsessiondata_1.xnat_dx3dcraniofacialsessiondata0 AS xnat_dx3dcraniofacialsessionda_t_dx3dcraniofacialsessiondata0,
                                    xnat_dx3dcraniofacialsessiondata_1.xnat_experimentdata22 AS xnat_dx3dcraniofacialsessionda_sordata__xnat_experimentdata22,
                                    xnat_dx3dcraniofacialsessiondata_1.xnat_subjectassessordata19 AS xnat_dx3dcraniofacialsessionda_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_dx3dcraniofacialsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_dx3dcraniofacialsessiondata xnat_dx3dcraniofacialsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_dx3dcraniofacialsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_dx3dcraniofacialsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_dx3dcraniofacialsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_dx3dcraniofacialsessionda_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_dx3dcraniofacialsessionda_t_dx3dcraniofacialsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_dx3dcraniofacialsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_dx3dcraniofacialsessiondata0
           FROM ( SELECT table2.id AS xnat_dx3dcraniofacialsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_dx3dcraniofacialsessiondata xnat_dx3dcraniofacialsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_dx3dcraniofacialsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_dx3dcraniofacialsessiondata0)::text = (search.xnat_dx3dcraniofacialsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_dx3dcraniofacialsessiondata OWNER TO xnat;

--
-- Name: xnat_dxscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dxscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    dxscandata_info integer
);


ALTER TABLE public.xnat_dxscandata OWNER TO xnat;

--
-- Name: xnat_dxscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dxscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_dxscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_dxscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_dxscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_dxscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_dxscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_dxscandata0,
            table2.status AS xnat_dxscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_dxscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_dxscandata xnat_dxscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_dxscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_dxscandata_meta_data table2 ON ((xnat_dxscandata.dxscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_dxscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_dxscandata0,
                    table2.insert_date AS xnat_dxscandata_meta_data121
                   FROM ((public.xnat_dxscandata xnat_dxscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_dxscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_dxscandata_meta_data table2 ON ((xnat_dxscandata.dxscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_dxscandata0 = search.xnat_dxscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_dxscandata OWNER TO xnat;

--
-- Name: xnat_dxsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dxsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    dxsessiondata_info integer
);


ALTER TABLE public.xnat_dxsessiondata OWNER TO xnat;

--
-- Name: xnat_dxsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_dxsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_dxsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_dxsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_dxsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:dxSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_dxsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_dxsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_dxsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_dxsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_dxsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_dxsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_dxsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_dxsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_dxsessiondata0) search_1.xnat_dxsessiondata0,
            search_1.xnat_dxsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_dxsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_dxsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_dxsessiondata0,
                    table4.status AS xnat_dxsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_dxsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_dxsessiondata_projects.projects AS xnat_dxsessiondata_projects_projects
                   FROM ((((((((public.xnat_dxsessiondata xnat_dxsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_dxsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_dxsessiondata_meta_data table4 ON ((xnat_dxsessiondata.dxsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_dxsessiondata_projects xnat_dxsessiondata_projects ON (((table2.id)::text = (xnat_dxsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_dxsessiondata_sordata_ex_xnat_dxsessiondata0,
                            search_2.xnat_dxsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_dxsessiondata_sor_xnat_subjectassessordata19,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_dxsessiondata_1.xnat_dxsessiondata0 AS xnat_dxsessiondata_sordata_ex_xnat_dxsessiondata0,
                                    xnat_dxsessiondata_1.xnat_experimentdata22 AS xnat_dxsessiondata_sordata__xnat_experimentdata22,
                                    xnat_dxsessiondata_1.xnat_subjectassessordata19 AS xnat_dxsessiondata_sor_xnat_subjectassessordata19,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_dxsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_dxsessiondata xnat_dxsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_dxsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_dxsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_dxsessiondata_1.xnat_subjectassessordata19)::text)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, search_2.xnat_dxsessiondata_sordata__xnat_experimentdata22 DESC, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)))) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_dxsessiondata_sordata_ex_xnat_dxsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_dxsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_dxsessiondata0
           FROM ( SELECT table2.id AS xnat_dxsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_dxsessiondata xnat_dxsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_dxsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_dxsessiondata0)::text = (search.xnat_dxsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_dxsessiondata OWNER TO xnat;

--
-- Name: xnat_ecgscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ecgscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    ecgscandata_info integer
);


ALTER TABLE public.xnat_ecgscandata OWNER TO xnat;

--
-- Name: xnat_ecgscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ecgscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_ecgscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_ecgscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_ecgscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_ecgscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_ecgscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_ecgscandata0,
            table2.status AS xnat_ecgscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_ecgscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_ecgscandata xnat_ecgscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_ecgscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_ecgscandata_meta_data table2 ON ((xnat_ecgscandata.ecgscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_ecgscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_ecgscandata0,
                    table2.insert_date AS xnat_ecgscandata_meta_data121
                   FROM ((public.xnat_ecgscandata xnat_ecgscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_ecgscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_ecgscandata_meta_data table2 ON ((xnat_ecgscandata.ecgscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_ecgscandata0 = search.xnat_ecgscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_ecgscandata OWNER TO xnat;

--
-- Name: xnat_ecgsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ecgsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    ecgsessiondata_info integer
);


ALTER TABLE public.xnat_ecgsessiondata OWNER TO xnat;

--
-- Name: xnat_ecgsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ecgsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_ecgsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_ecgsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_ecgsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:ecgSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_ecgsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_ecgsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_ecgsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_ecgsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_ecgsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_ecgsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_ecgsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_ecgsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_ecgsessiondata0) search_1.xnat_ecgsessiondata0,
            search_1.xnat_ecgsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_ecgsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_ecgsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_ecgsessiondata0,
                    table4.status AS xnat_ecgsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_ecgsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_ecgsessiondata_projects.projects AS xnat_ecgsessiondata_projects_projects
                   FROM ((((((((public.xnat_ecgsessiondata xnat_ecgsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_ecgsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_ecgsessiondata_meta_data table4 ON ((xnat_ecgsessiondata.ecgsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_ecgsessiondata_projects xnat_ecgsessiondata_projects ON (((table2.id)::text = (xnat_ecgsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_ecgsessiondata_sordata_e_xnat_ecgsessiondata0,
                            search_2.xnat_ecgsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_ecgsessiondata_sor_xnat_subjectassessordata19,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_ecgsessiondata_1.xnat_ecgsessiondata0 AS xnat_ecgsessiondata_sordata_e_xnat_ecgsessiondata0,
                                    xnat_ecgsessiondata_1.xnat_experimentdata22 AS xnat_ecgsessiondata_sordata__xnat_experimentdata22,
                                    xnat_ecgsessiondata_1.xnat_subjectassessordata19 AS xnat_ecgsessiondata_sor_xnat_subjectassessordata19,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_ecgsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_ecgsessiondata xnat_ecgsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_ecgsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_ecgsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_ecgsessiondata_1.xnat_subjectassessordata19)::text)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, search_2.xnat_ecgsessiondata_sordata__xnat_experimentdata22 DESC, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)))) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_ecgsessiondata_sordata_e_xnat_ecgsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_ecgsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_ecgsessiondata0
           FROM ( SELECT table2.id AS xnat_ecgsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_ecgsessiondata xnat_ecgsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_ecgsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_ecgsessiondata0)::text = (search.xnat_ecgsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_ecgsessiondata OWNER TO xnat;

--
-- Name: xnat_eegscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_eegscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    parameters_numberofdatarecords integer,
    parameters_datarecord_units character varying(255),
    parameters_datarecord_duration double precision,
    softwarefiltersimpedances_mean double precision,
    eegscandata_info integer
);


ALTER TABLE public.xnat_eegscandata OWNER TO xnat;

--
-- Name: xnat_eegscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_eegscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_eegscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_eegscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_eegscandata AS
 SELECT search.xnat_imagescandata6 AS image_session_id,
    search.xnat_imagescandata7 AS note,
    search.xnat_imagescandata8 AS quality,
    search.xnat_imagescandata9 AS condition,
    search.xnat_imagescandata10 AS series_description,
    search.xnat_imagescandata12 AS documentation,
    search.xnat_imagescandata13 AS scanner,
    search.xnat_imagescandata14 AS scanner_manufacturer,
    search.xnat_imagescandata15 AS scanner_model,
    search.xnat_imagescandata17 AS modality,
    search.xnat_imagescandata18 AS frames,
    search.xnat_imagescandata19 AS operator,
    search.xnat_imagescandata21 AS starttime,
    search.xnat_imagescandata23 AS id,
    search.xnat_imagescandata24 AS type,
    search.xnat_imagescandata25 AS uid,
    search.xnat_imagescandata26 AS project,
    search.xnat_eegscandata_meta_data162 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_eegscandata_meta_data159 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_eegscandata0,
            table2.status AS xnat_eegscandata_meta_data159,
            table0.image_session_id AS xnat_imagescandata6,
            table0.note AS xnat_imagescandata7,
            table0.quality AS xnat_imagescandata8,
            table0.condition AS xnat_imagescandata9,
            table0.series_description AS xnat_imagescandata10,
            table0.documentation AS xnat_imagescandata12,
            table0.scanner AS xnat_imagescandata13,
            table0.scanner_manufacturer AS xnat_imagescandata14,
            table0.scanner_model AS xnat_imagescandata15,
            table0.modality AS xnat_imagescandata17,
            table0.frames AS xnat_imagescandata18,
            table0.operator AS xnat_imagescandata19,
            table0.starttime AS xnat_imagescandata21,
            table0.id AS xnat_imagescandata23,
            table0.type AS xnat_imagescandata24,
            table0.uid AS xnat_imagescandata25,
            table0.project AS xnat_imagescandata26,
            table2.insert_date AS xnat_eegscandata_meta_data162,
            table4.login AS table4_login
           FROM (((public.xnat_eegscandata xnat_eegscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_eegscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_eegscandata_meta_data table2 ON ((xnat_eegscandata.eegscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_eegscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_eegscandata0,
                    table2.insert_date AS xnat_eegscandata_meta_data162
                   FROM ((public.xnat_eegscandata xnat_eegscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_eegscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_eegscandata_meta_data table2 ON ((xnat_eegscandata.eegscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_eegscandata0 = search.xnat_eegscandata0)))
  ORDER BY search.xnat_imagescandata6;


ALTER TABLE public.displayfields_xnat_eegscandata OWNER TO xnat;

--
-- Name: xnat_eegsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_eegsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    dataformatversion character varying(255),
    numberofchannels integer,
    samplingrate double precision,
    samplingrate_units character varying(255),
    samplinginterval double precision,
    samplinginterval_units character varying(255),
    eegsessiondata_info integer
);


ALTER TABLE public.xnat_eegsessiondata OWNER TO xnat;

--
-- Name: xnat_eegsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_eegsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_eegsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_eegsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_eegsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:eegSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_eegsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_eegsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_eegsessiondata AS
 SELECT search.xnat_subjectassessordata25 AS subject_id,
    search.xnat_eegsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata28 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata28 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata28) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_eegsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata44, search.xnat_eegsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_eegsessiondata_meta_data982 AS insert_date,
    search.xnat_experimentdata38 AS project,
    search.xnat_eegsessiondata_meta_data979 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_eegsessiondata0) search_1.xnat_eegsessiondata0,
            search_1.xnat_eegsessiondata_meta_data979,
            search_1.xnat_subjectassessordata25,
            search_1.xnat_experimentdata28,
            search_1.xnat_experimentdata44,
            search_1.table5_login,
            search_1.xnat_eegsessiondata_meta_data982,
            search_1.xnat_experimentdata38,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_eegsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_eegsessiondata0,
                    table4.status AS xnat_eegsessiondata_meta_data979,
                    table1.subject_id AS xnat_subjectassessordata25,
                    table2.date AS xnat_experimentdata28,
                    table2.label AS xnat_experimentdata44,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_eegsessiondata_meta_data982,
                    table2.project AS xnat_experimentdata38,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_eegsessiondata_projects.projects AS xnat_eegsessiondata_projects_projects
                   FROM ((((((((public.xnat_eegsessiondata xnat_eegsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_eegsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_eegsessiondata_meta_data table4 ON ((xnat_eegsessiondata.eegsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_eegsessiondata_projects xnat_eegsessiondata_projects ON (((table2.id)::text = (xnat_eegsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_eegsessiondata_sordata_e_xnat_eegsessiondata0,
                            search_2.xnat_eegsessiondata_sordata__xnat_experimentdata28,
                            search_2.xnat_eegsessiondata_sor_xnat_subjectassessordata25,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_eegsessiondata_1.xnat_eegsessiondata0 AS xnat_eegsessiondata_sordata_e_xnat_eegsessiondata0,
                                    xnat_eegsessiondata_1.xnat_experimentdata28 AS xnat_eegsessiondata_sordata__xnat_experimentdata28,
                                    xnat_eegsessiondata_1.xnat_subjectassessordata25 AS xnat_eegsessiondata_sor_xnat_subjectassessordata25,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_eegsessiondata0,
    table2_1.date AS xnat_experimentdata28,
    table1_2.subject_id AS xnat_subjectassessordata25
   FROM (((public.xnat_eegsessiondata xnat_eegsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_eegsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_eegsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_eegsessiondata_1.xnat_subjectassessordata25)::text)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, search_2.xnat_eegsessiondata_sordata__xnat_experimentdata28 DESC, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)))) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_eegsessiondata_sordata_e_xnat_eegsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_eegsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_eegsessiondata0
           FROM ( SELECT table2.id AS xnat_eegsessiondata0,
                    table2.date AS xnat_experimentdata28
                   FROM (((public.xnat_eegsessiondata xnat_eegsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_eegsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_eegsessiondata0)::text = (search.xnat_eegsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata25;


ALTER TABLE public.displayfields_xnat_eegsessiondata OWNER TO xnat;

--
-- Name: xnat_epsscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_epsscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    epsscandata_info integer
);


ALTER TABLE public.xnat_epsscandata OWNER TO xnat;

--
-- Name: xnat_epsscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_epsscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_epsscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_epsscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_epsscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_epsscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_epsscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_epsscandata0,
            table2.status AS xnat_epsscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_epsscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_epsscandata xnat_epsscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_epsscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_epsscandata_meta_data table2 ON ((xnat_epsscandata.epsscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_epsscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_epsscandata0,
                    table2.insert_date AS xnat_epsscandata_meta_data121
                   FROM ((public.xnat_epsscandata xnat_epsscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_epsscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_epsscandata_meta_data table2 ON ((xnat_epsscandata.epsscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_epsscandata0 = search.xnat_epsscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_epsscandata OWNER TO xnat;

--
-- Name: xnat_epssessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_epssessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    epssessiondata_info integer
);


ALTER TABLE public.xnat_epssessiondata OWNER TO xnat;

--
-- Name: xnat_epssessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_epssessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_epssessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_epssessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_epssessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:epsSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_epssessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_epssessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_epssessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_epssessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_epssessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_epssessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_epssessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_epssessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_epssessiondata0) search_1.xnat_epssessiondata0,
            search_1.xnat_epssessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_epssessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_epssessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_epssessiondata0,
                    table4.status AS xnat_epssessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_epssessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_epssessiondata_projects.projects AS xnat_epssessiondata_projects_projects
                   FROM ((((((((public.xnat_epssessiondata xnat_epssessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_epssessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_epssessiondata_meta_data table4 ON ((xnat_epssessiondata.epssessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_epssessiondata_projects xnat_epssessiondata_projects ON (((table2.id)::text = (xnat_epssessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_epssessiondata_sordata_e_xnat_epssessiondata0,
                            search_2.xnat_epssessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_epssessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_epssessiondata_1.xnat_epssessiondata0 AS xnat_epssessiondata_sordata_e_xnat_epssessiondata0,
                                    xnat_epssessiondata_1.xnat_experimentdata22 AS xnat_epssessiondata_sordata__xnat_experimentdata22,
                                    xnat_epssessiondata_1.xnat_subjectassessordata19 AS xnat_epssessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_epssessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_epssessiondata xnat_epssessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_epssessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_epssessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_epssessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_epssessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_epssessiondata_sordata_e_xnat_epssessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_epssessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_epssessiondata0
           FROM ( SELECT table2.id AS xnat_epssessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_epssessiondata xnat_epssessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_epssessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_epssessiondata0)::text = (search.xnat_epssessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_epssessiondata OWNER TO xnat;

--
-- Name: xnat_esscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_esscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    esscandata_info integer
);


ALTER TABLE public.xnat_esscandata OWNER TO xnat;

--
-- Name: xnat_esscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_esscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_esscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_esscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_esscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_esscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_esscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_esscandata0,
            table2.status AS xnat_esscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_esscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_esscandata xnat_esscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_esscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_esscandata_meta_data table2 ON ((xnat_esscandata.esscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_esscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_esscandata0,
                    table2.insert_date AS xnat_esscandata_meta_data121
                   FROM ((public.xnat_esscandata xnat_esscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_esscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_esscandata_meta_data table2 ON ((xnat_esscandata.esscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_esscandata0 = search.xnat_esscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_esscandata OWNER TO xnat;

--
-- Name: xnat_essessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_essessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    essessiondata_info integer
);


ALTER TABLE public.xnat_essessiondata OWNER TO xnat;

--
-- Name: xnat_essessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_essessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_essessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_essessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_essessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:esSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_essessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_essessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_essessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_essessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_essessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_essessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_essessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_essessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_essessiondata0) search_1.xnat_essessiondata0,
            search_1.xnat_essessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_essessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_essessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_essessiondata0,
                    table4.status AS xnat_essessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_essessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_essessiondata_projects.projects AS xnat_essessiondata_projects_projects
                   FROM ((((((((public.xnat_essessiondata xnat_essessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_essessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_essessiondata_meta_data table4 ON ((xnat_essessiondata.essessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_essessiondata_projects xnat_essessiondata_projects ON (((table2.id)::text = (xnat_essessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_essessiondata_sordata_ex_xnat_essessiondata0,
                            search_2.xnat_essessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_essessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_essessiondata_1.xnat_essessiondata0 AS xnat_essessiondata_sordata_ex_xnat_essessiondata0,
                                    xnat_essessiondata_1.xnat_experimentdata22 AS xnat_essessiondata_sordata__xnat_experimentdata22,
                                    xnat_essessiondata_1.xnat_subjectassessordata19 AS xnat_essessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_essessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_essessiondata xnat_essessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_essessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_essessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_essessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_essessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_essessiondata_sordata_ex_xnat_essessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_essessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_essessiondata0
           FROM ( SELECT table2.id AS xnat_essessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_essessiondata xnat_essessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_essessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_essessiondata0)::text = (search.xnat_essessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_essessiondata OWNER TO xnat;

--
-- Name: xnat_esvscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_esvscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    esvscandata_info integer
);


ALTER TABLE public.xnat_esvscandata OWNER TO xnat;

--
-- Name: xnat_esvscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_esvscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_esvscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_esvscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_esvscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_esvscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_esvscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_esvscandata0,
            table2.status AS xnat_esvscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_esvscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_esvscandata xnat_esvscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_esvscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_esvscandata_meta_data table2 ON ((xnat_esvscandata.esvscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_esvscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_esvscandata0,
                    table2.insert_date AS xnat_esvscandata_meta_data121
                   FROM ((public.xnat_esvscandata xnat_esvscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_esvscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_esvscandata_meta_data table2 ON ((xnat_esvscandata.esvscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_esvscandata0 = search.xnat_esvscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_esvscandata OWNER TO xnat;

--
-- Name: xnat_esvsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_esvsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    esvsessiondata_info integer
);


ALTER TABLE public.xnat_esvsessiondata OWNER TO xnat;

--
-- Name: xnat_esvsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_esvsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_esvsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_esvsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_esvsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:esvSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_esvsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_esvsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_esvsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_esvsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_esvsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_esvsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_esvsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_esvsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_esvsessiondata0) search_1.xnat_esvsessiondata0,
            search_1.xnat_esvsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_esvsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_esvsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_esvsessiondata0,
                    table4.status AS xnat_esvsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_esvsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_esvsessiondata_projects.projects AS xnat_esvsessiondata_projects_projects
                   FROM ((((((((public.xnat_esvsessiondata xnat_esvsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_esvsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_esvsessiondata_meta_data table4 ON ((xnat_esvsessiondata.esvsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_esvsessiondata_projects xnat_esvsessiondata_projects ON (((table2.id)::text = (xnat_esvsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_esvsessiondata_sordata_e_xnat_esvsessiondata0,
                            search_2.xnat_esvsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_esvsessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_esvsessiondata_1.xnat_esvsessiondata0 AS xnat_esvsessiondata_sordata_e_xnat_esvsessiondata0,
                                    xnat_esvsessiondata_1.xnat_experimentdata22 AS xnat_esvsessiondata_sordata__xnat_experimentdata22,
                                    xnat_esvsessiondata_1.xnat_subjectassessordata19 AS xnat_esvsessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_esvsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_esvsessiondata xnat_esvsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_esvsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_esvsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_esvsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_esvsessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_esvsessiondata_sordata_e_xnat_esvsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_esvsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_esvsessiondata0
           FROM ( SELECT table2.id AS xnat_esvsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_esvsessiondata xnat_esvsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_esvsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_esvsessiondata0)::text = (search.xnat_esvsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_esvsessiondata OWNER TO xnat;

--
-- Name: xnat_fielddefinitiongroup; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_fielddefinitiongroup (
    id character varying(255),
    data_type character varying(255),
    description text,
    shareable integer,
    project_specific integer,
    fielddefinitiongroup_info integer,
    xnat_fielddefinitiongroup_id integer NOT NULL
);


ALTER TABLE public.xnat_fielddefinitiongroup OWNER TO xnat;

--
-- Name: xnat_fielddefinitiongroup_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_fielddefinitiongroup_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_fielddefinitiongroup_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_fielddefinitiongroup; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_fielddefinitiongroup AS
 SELECT search.xnat_fielddefinitiongroup_meta_data51 AS insert_date,
    search.table2_login AS insert_user,
    search.xnat_fielddefinitiongroup0 AS id,
    search.xnat_fielddefinitiongroup1 AS data_type,
    search.xnat_fielddefinitiongroup2 AS description,
    search.xnat_fielddefinitiongroup3 AS shareable,
    search.xnat_fielddefinitiongroup4 AS project_specific,
    search.xnat_fielddefinitiongroup_meta_data48 AS quarantine_status
   FROM (( SELECT DISTINCT xnat_fielddefinitiongroup.xnat_fielddefinitiongroup_id AS xnat_fielddefinitiongroup6,
            table1.status AS xnat_fielddefinitiongroup_meta_data48,
            table1.insert_date AS xnat_fielddefinitiongroup_meta_data51,
            table2.login AS table2_login,
            xnat_fielddefinitiongroup.id AS xnat_fielddefinitiongroup0,
            xnat_fielddefinitiongroup.data_type AS xnat_fielddefinitiongroup1,
            xnat_fielddefinitiongroup.description AS xnat_fielddefinitiongroup2,
            xnat_fielddefinitiongroup.shareable AS xnat_fielddefinitiongroup3,
            xnat_fielddefinitiongroup.project_specific AS xnat_fielddefinitiongroup4
           FROM ((public.xnat_fielddefinitiongroup xnat_fielddefinitiongroup
             LEFT JOIN public.xnat_fielddefinitiongroup_meta_data table1 ON ((xnat_fielddefinitiongroup.fielddefinitiongroup_info = table1.meta_data_id)))
             LEFT JOIN public.xdat_user table2 ON ((table1.insert_user_xdat_user_id = table2.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_fielddefinitiongroup6
           FROM ( SELECT xnat_fielddefinitiongroup.xnat_fielddefinitiongroup_id AS xnat_fielddefinitiongroup6,
                    table1.insert_date AS xnat_fielddefinitiongroup_meta_data51
                   FROM (public.xnat_fielddefinitiongroup xnat_fielddefinitiongroup
                     LEFT JOIN public.xnat_fielddefinitiongroup_meta_data table1 ON ((xnat_fielddefinitiongroup.fielddefinitiongroup_info = table1.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_fielddefinitiongroup6 = search.xnat_fielddefinitiongroup6)))
  ORDER BY search.xnat_fielddefinitiongroup_meta_data51;


ALTER TABLE public.displayfields_xnat_fielddefinitiongroup OWNER TO xnat;

--
-- Name: xnat_genericdata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_genericdata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    genericdata_info integer
);


ALTER TABLE public.xnat_genericdata OWNER TO xnat;

--
-- Name: xnat_genericdata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_genericdata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_genericdata_meta_data OWNER TO xnat;

--
-- Name: xnat_genericdata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_genericdata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:genericData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_genericdata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_genericdata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_genericdata AS
 SELECT search.xnat_genericdata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata2 AS date,
    search.xnat_genericdata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata18, search.xnat_genericdata0) AS label,
    search.table3_login AS insert_user,
    search.xnat_genericdata_meta_data157 AS insert_date,
    search.xnat_experimentdata12 AS project,
    search.xnat_genericdata_meta_data154 AS quarantine_status
   FROM (( SELECT DISTINCT table0.id AS xnat_genericdata0,
            table2.status AS xnat_genericdata_meta_data154,
            table0.date AS xnat_experimentdata2,
            table0.label AS xnat_experimentdata18,
            table3.login AS table3_login,
            table2.insert_date AS xnat_genericdata_meta_data157,
            table0.project AS xnat_experimentdata12,
            xnat_genericdata_projects.projects AS xnat_genericdata_projects_projects
           FROM ((((public.xnat_genericdata xnat_genericdata
             LEFT JOIN public.xnat_experimentdata table0 ON (((xnat_genericdata.id)::text = (table0.id)::text)))
             LEFT JOIN public.xnat_genericdata_meta_data table2 ON ((xnat_genericdata.genericdata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table3 ON ((table2.insert_user_xdat_user_id = table3.xdat_user_id)))
             LEFT JOIN public.xnat_genericdata_projects xnat_genericdata_projects ON (((table0.id)::text = (xnat_genericdata_projects.id)::text)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_genericdata0
           FROM ( SELECT table0.id AS xnat_genericdata0,
                    table0.date AS xnat_experimentdata2
                   FROM (public.xnat_genericdata xnat_genericdata
                     LEFT JOIN public.xnat_experimentdata table0 ON (((xnat_genericdata.id)::text = (table0.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_genericdata0)::text = (search.xnat_genericdata0)::text)))
  ORDER BY search.xnat_genericdata0;


ALTER TABLE public.displayfields_xnat_genericdata OWNER TO xnat;

--
-- Name: xnat_gmscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    gmscandata_info integer
);


ALTER TABLE public.xnat_gmscandata OWNER TO xnat;

--
-- Name: xnat_gmscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_gmscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_gmscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_gmscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_gmscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_gmscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_gmscandata0,
            table2.status AS xnat_gmscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_gmscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_gmscandata xnat_gmscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_gmscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_gmscandata_meta_data table2 ON ((xnat_gmscandata.gmscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_gmscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_gmscandata0,
                    table2.insert_date AS xnat_gmscandata_meta_data121
                   FROM ((public.xnat_gmscandata xnat_gmscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_gmscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_gmscandata_meta_data table2 ON ((xnat_gmscandata.gmscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_gmscandata0 = search.xnat_gmscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_gmscandata OWNER TO xnat;

--
-- Name: xnat_gmsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    gmsessiondata_info integer
);


ALTER TABLE public.xnat_gmsessiondata OWNER TO xnat;

--
-- Name: xnat_gmsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_gmsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_gmsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_gmsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:gmSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_gmsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_gmsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_gmsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_gmsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_gmsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_gmsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_gmsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_gmsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_gmsessiondata0) search_1.xnat_gmsessiondata0,
            search_1.xnat_gmsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_gmsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_gmsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_gmsessiondata0,
                    table4.status AS xnat_gmsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_gmsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_gmsessiondata_projects.projects AS xnat_gmsessiondata_projects_projects
                   FROM ((((((((public.xnat_gmsessiondata xnat_gmsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_gmsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_gmsessiondata_meta_data table4 ON ((xnat_gmsessiondata.gmsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_gmsessiondata_projects xnat_gmsessiondata_projects ON (((table2.id)::text = (xnat_gmsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_gmsessiondata_sordata_ex_xnat_gmsessiondata0,
                            search_2.xnat_gmsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_gmsessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_gmsessiondata_1.xnat_gmsessiondata0 AS xnat_gmsessiondata_sordata_ex_xnat_gmsessiondata0,
                                    xnat_gmsessiondata_1.xnat_experimentdata22 AS xnat_gmsessiondata_sordata__xnat_experimentdata22,
                                    xnat_gmsessiondata_1.xnat_subjectassessordata19 AS xnat_gmsessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_gmsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_gmsessiondata xnat_gmsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_gmsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_gmsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_gmsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_gmsessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_gmsessiondata_sordata_ex_xnat_gmsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_gmsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_gmsessiondata0
           FROM ( SELECT table2.id AS xnat_gmsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_gmsessiondata xnat_gmsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_gmsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_gmsessiondata0)::text = (search.xnat_gmsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_gmsessiondata OWNER TO xnat;

--
-- Name: xnat_gmvscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmvscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    gmvscandata_info integer
);


ALTER TABLE public.xnat_gmvscandata OWNER TO xnat;

--
-- Name: xnat_gmvscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmvscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_gmvscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_gmvscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_gmvscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_gmvscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_gmvscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_gmvscandata0,
            table2.status AS xnat_gmvscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_gmvscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_gmvscandata xnat_gmvscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_gmvscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_gmvscandata_meta_data table2 ON ((xnat_gmvscandata.gmvscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_gmvscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_gmvscandata0,
                    table2.insert_date AS xnat_gmvscandata_meta_data121
                   FROM ((public.xnat_gmvscandata xnat_gmvscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_gmvscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_gmvscandata_meta_data table2 ON ((xnat_gmvscandata.gmvscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_gmvscandata0 = search.xnat_gmvscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_gmvscandata OWNER TO xnat;

--
-- Name: xnat_gmvsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmvsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    gmvsessiondata_info integer
);


ALTER TABLE public.xnat_gmvsessiondata OWNER TO xnat;

--
-- Name: xnat_gmvsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_gmvsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_gmvsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_gmvsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_gmvsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:gmvSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_gmvsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_gmvsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_gmvsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_gmvsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_gmvsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_gmvsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_gmvsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_gmvsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_gmvsessiondata0) search_1.xnat_gmvsessiondata0,
            search_1.xnat_gmvsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_gmvsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_gmvsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_gmvsessiondata0,
                    table4.status AS xnat_gmvsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_gmvsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_gmvsessiondata_projects.projects AS xnat_gmvsessiondata_projects_projects
                   FROM ((((((((public.xnat_gmvsessiondata xnat_gmvsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_gmvsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_gmvsessiondata_meta_data table4 ON ((xnat_gmvsessiondata.gmvsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_gmvsessiondata_projects xnat_gmvsessiondata_projects ON (((table2.id)::text = (xnat_gmvsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_gmvsessiondata_sordata_e_xnat_gmvsessiondata0,
                            search_2.xnat_gmvsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_gmvsessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_gmvsessiondata_1.xnat_gmvsessiondata0 AS xnat_gmvsessiondata_sordata_e_xnat_gmvsessiondata0,
                                    xnat_gmvsessiondata_1.xnat_experimentdata22 AS xnat_gmvsessiondata_sordata__xnat_experimentdata22,
                                    xnat_gmvsessiondata_1.xnat_subjectassessordata19 AS xnat_gmvsessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_gmvsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_gmvsessiondata xnat_gmvsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_gmvsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_gmvsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_gmvsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_gmvsessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_gmvsessiondata_sordata_e_xnat_gmvsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_gmvsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_gmvsessiondata0
           FROM ( SELECT table2.id AS xnat_gmvsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_gmvsessiondata xnat_gmvsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_gmvsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_gmvsessiondata0)::text = (search.xnat_gmvsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_gmvsessiondata OWNER TO xnat;

--
-- Name: xnat_hdscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_hdscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    hdscandata_info integer
);


ALTER TABLE public.xnat_hdscandata OWNER TO xnat;

--
-- Name: xnat_hdscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_hdscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_hdscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_hdscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_hdscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_hdscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_hdscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_hdscandata0,
            table2.status AS xnat_hdscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_hdscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_hdscandata xnat_hdscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_hdscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_hdscandata_meta_data table2 ON ((xnat_hdscandata.hdscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_hdscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_hdscandata0,
                    table2.insert_date AS xnat_hdscandata_meta_data121
                   FROM ((public.xnat_hdscandata xnat_hdscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_hdscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_hdscandata_meta_data table2 ON ((xnat_hdscandata.hdscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_hdscandata0 = search.xnat_hdscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_hdscandata OWNER TO xnat;

--
-- Name: xnat_hdsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_hdsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    hdsessiondata_info integer
);


ALTER TABLE public.xnat_hdsessiondata OWNER TO xnat;

--
-- Name: xnat_hdsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_hdsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_hdsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_hdsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_hdsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:hdSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_hdsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_hdsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_hdsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_hdsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_hdsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_hdsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_hdsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_hdsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_hdsessiondata0) search_1.xnat_hdsessiondata0,
            search_1.xnat_hdsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_hdsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_hdsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_hdsessiondata0,
                    table4.status AS xnat_hdsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_hdsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_hdsessiondata_projects.projects AS xnat_hdsessiondata_projects_projects
                   FROM ((((((((public.xnat_hdsessiondata xnat_hdsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_hdsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_hdsessiondata_meta_data table4 ON ((xnat_hdsessiondata.hdsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_hdsessiondata_projects xnat_hdsessiondata_projects ON (((table2.id)::text = (xnat_hdsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_hdsessiondata_sordata_ex_xnat_hdsessiondata0,
                            search_2.xnat_hdsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_hdsessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_hdsessiondata_1.xnat_hdsessiondata0 AS xnat_hdsessiondata_sordata_ex_xnat_hdsessiondata0,
                                    xnat_hdsessiondata_1.xnat_experimentdata22 AS xnat_hdsessiondata_sordata__xnat_experimentdata22,
                                    xnat_hdsessiondata_1.xnat_subjectassessordata19 AS xnat_hdsessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_hdsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_hdsessiondata xnat_hdsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_hdsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_hdsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_hdsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_hdsessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_hdsessiondata_sordata_ex_xnat_hdsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_hdsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_hdsessiondata0
           FROM ( SELECT table2.id AS xnat_hdsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_hdsessiondata xnat_hdsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_hdsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_hdsessiondata0)::text = (search.xnat_hdsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_hdsessiondata OWNER TO xnat;

--
-- Name: xnat_investigatordata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_investigatordata (
    title character varying(10),
    firstname character varying(25),
    lastname character varying(25),
    institution character varying(255),
    department character varying(128),
    email character varying(64),
    phone character varying(25),
    id character varying(255),
    investigatordata_info integer,
    xnat_investigatordata_id integer NOT NULL
);


ALTER TABLE public.xnat_investigatordata OWNER TO xnat;

--
-- Name: xnat_investigatordata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_investigatordata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_investigatordata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_investigatordata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_investigatordata AS
 SELECT search.xnat_investigatordata9 AS investigator_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    (((search.xnat_investigatordata1)::text || ' '::text) || (search.xnat_investigatordata2)::text) AS investigator_name,
    search.xnat_investigatordata5 AS email,
    search.xnat_investigatordata6 AS phone,
    search.xnat_investigatordata_meta_data12 AS quarantine_status
   FROM (( SELECT DISTINCT xnat_investigatordata.xnat_investigatordata_id AS xnat_investigatordata9,
            table1.status AS xnat_investigatordata_meta_data12,
            xnat_investigatordata.firstname AS xnat_investigatordata1,
            xnat_investigatordata.lastname AS xnat_investigatordata2,
            xnat_investigatordata.email AS xnat_investigatordata5,
            xnat_investigatordata.phone AS xnat_investigatordata6,
            table1.insert_date AS xnat_investigatordata_meta_data15
           FROM (public.xnat_investigatordata xnat_investigatordata
             LEFT JOIN public.xnat_investigatordata_meta_data table1 ON ((xnat_investigatordata.investigatordata_info = table1.meta_data_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_investigatordata9
           FROM ( SELECT xnat_investigatordata.xnat_investigatordata_id AS xnat_investigatordata9,
                    table1.insert_date AS xnat_investigatordata_meta_data15
                   FROM (public.xnat_investigatordata xnat_investigatordata
                     LEFT JOIN public.xnat_investigatordata_meta_data table1 ON ((xnat_investigatordata.investigatordata_info = table1.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_investigatordata9 = search.xnat_investigatordata9)))
  ORDER BY search.xnat_investigatordata9;


ALTER TABLE public.displayfields_xnat_investigatordata OWNER TO xnat;

--
-- Name: xnat_ioscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ioscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    ioscandata_info integer
);


ALTER TABLE public.xnat_ioscandata OWNER TO xnat;

--
-- Name: xnat_ioscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_ioscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_ioscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_ioscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_ioscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_ioscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_ioscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_ioscandata0,
            table2.status AS xnat_ioscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_ioscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_ioscandata xnat_ioscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_ioscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_ioscandata_meta_data table2 ON ((xnat_ioscandata.ioscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_ioscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_ioscandata0,
                    table2.insert_date AS xnat_ioscandata_meta_data121
                   FROM ((public.xnat_ioscandata xnat_ioscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_ioscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_ioscandata_meta_data table2 ON ((xnat_ioscandata.ioscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_ioscandata0 = search.xnat_ioscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_ioscandata OWNER TO xnat;

--
-- Name: xnat_iosessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_iosessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    iosessiondata_info integer
);


ALTER TABLE public.xnat_iosessiondata OWNER TO xnat;

--
-- Name: xnat_iosessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_iosessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_iosessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_iosessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_iosessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:ioSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_iosessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_iosessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_iosessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_iosessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_iosessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_iosessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_iosessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_iosessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_iosessiondata0) search_1.xnat_iosessiondata0,
            search_1.xnat_iosessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_iosessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_iosessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_iosessiondata0,
                    table4.status AS xnat_iosessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_iosessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_iosessiondata_projects.projects AS xnat_iosessiondata_projects_projects
                   FROM ((((((((public.xnat_iosessiondata xnat_iosessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_iosessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_iosessiondata_meta_data table4 ON ((xnat_iosessiondata.iosessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_iosessiondata_projects xnat_iosessiondata_projects ON (((table2.id)::text = (xnat_iosessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_iosessiondata_sordata_ex_xnat_iosessiondata0,
                            search_2.xnat_iosessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_iosessiondata_sor_xnat_subjectassessordata19,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_iosessiondata_1.xnat_iosessiondata0 AS xnat_iosessiondata_sordata_ex_xnat_iosessiondata0,
                                    xnat_iosessiondata_1.xnat_experimentdata22 AS xnat_iosessiondata_sordata__xnat_experimentdata22,
                                    xnat_iosessiondata_1.xnat_subjectassessordata19 AS xnat_iosessiondata_sor_xnat_subjectassessordata19,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_iosessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_iosessiondata xnat_iosessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_iosessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_iosessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_iosessiondata_1.xnat_subjectassessordata19)::text)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, search_2.xnat_iosessiondata_sordata__xnat_experimentdata22 DESC, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)))) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_iosessiondata_sordata_ex_xnat_iosessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_iosessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_iosessiondata0
           FROM ( SELECT table2.id AS xnat_iosessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_iosessiondata xnat_iosessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_iosessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_iosessiondata0)::text = (search.xnat_iosessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_iosessiondata OWNER TO xnat;

--
-- Name: xnat_megscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_megscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    megscandata_info integer
);


ALTER TABLE public.xnat_megscandata OWNER TO xnat;

--
-- Name: xnat_megscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_megscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_megscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_megscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_megscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_megscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_megscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_megscandata0,
            table2.status AS xnat_megscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_megscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_megscandata xnat_megscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_megscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_megscandata_meta_data table2 ON ((xnat_megscandata.megscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_megscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_megscandata0,
                    table2.insert_date AS xnat_megscandata_meta_data121
                   FROM ((public.xnat_megscandata xnat_megscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_megscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_megscandata_meta_data table2 ON ((xnat_megscandata.megscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_megscandata0 = search.xnat_megscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_megscandata OWNER TO xnat;

--
-- Name: xnat_megsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_megsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    megsessiondata_info integer
);


ALTER TABLE public.xnat_megsessiondata OWNER TO xnat;

--
-- Name: xnat_megsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_megsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_megsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_megsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_megsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:megSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_megsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_megsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_megsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_megsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_megsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_megsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_megsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_megsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_megsessiondata0) search_1.xnat_megsessiondata0,
            search_1.xnat_megsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_megsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_megsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_megsessiondata0,
                    table4.status AS xnat_megsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_megsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_megsessiondata_projects.projects AS xnat_megsessiondata_projects_projects
                   FROM ((((((((public.xnat_megsessiondata xnat_megsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_megsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_megsessiondata_meta_data table4 ON ((xnat_megsessiondata.megsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_megsessiondata_projects xnat_megsessiondata_projects ON (((table2.id)::text = (xnat_megsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_megsessiondata_sordata_e_xnat_megsessiondata0,
                            search_2.xnat_megsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_megsessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_megsessiondata_1.xnat_megsessiondata0 AS xnat_megsessiondata_sordata_e_xnat_megsessiondata0,
                                    xnat_megsessiondata_1.xnat_experimentdata22 AS xnat_megsessiondata_sordata__xnat_experimentdata22,
                                    xnat_megsessiondata_1.xnat_subjectassessordata19 AS xnat_megsessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_megsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_megsessiondata xnat_megsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_megsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_megsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_megsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_megsessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_megsessiondata_sordata_e_xnat_megsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_megsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_megsessiondata0
           FROM ( SELECT table2.id AS xnat_megsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_megsessiondata xnat_megsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_megsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_megsessiondata0)::text = (search.xnat_megsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_megsessiondata OWNER TO xnat;

--
-- Name: xnat_mgscandata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_mgscandata (
    xnat_imagescandata_id integer DEFAULT 0 NOT NULL,
    mgscandata_info integer
);


ALTER TABLE public.xnat_mgscandata OWNER TO xnat;

--
-- Name: xnat_mgscandata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_mgscandata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_mgscandata_meta_data OWNER TO xnat;

--
-- Name: displayfields_xnat_mgscandata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_mgscandata AS
 SELECT search.xnat_imagescandata2 AS image_session_id,
    search.xnat_imagescandata3 AS note,
    search.xnat_imagescandata4 AS quality,
    search.xnat_imagescandata5 AS condition,
    search.xnat_imagescandata6 AS series_description,
    search.xnat_imagescandata8 AS documentation,
    search.xnat_imagescandata9 AS scanner,
    search.xnat_imagescandata10 AS scanner_manufacturer,
    search.xnat_imagescandata11 AS scanner_model,
    search.xnat_imagescandata13 AS modality,
    search.xnat_imagescandata14 AS frames,
    search.xnat_imagescandata15 AS operator,
    search.xnat_imagescandata17 AS starttime,
    search.xnat_imagescandata19 AS id,
    search.xnat_imagescandata20 AS type,
    search.xnat_imagescandata21 AS uid,
    search.xnat_imagescandata22 AS project,
    search.xnat_mgscandata_meta_data121 AS insert_date,
    search.table4_login AS insert_user,
    search.xnat_mgscandata_meta_data118 AS quarantine_status
   FROM (( SELECT DISTINCT table0.xnat_imagescandata_id AS xnat_mgscandata0,
            table2.status AS xnat_mgscandata_meta_data118,
            table0.image_session_id AS xnat_imagescandata2,
            table0.note AS xnat_imagescandata3,
            table0.quality AS xnat_imagescandata4,
            table0.condition AS xnat_imagescandata5,
            table0.series_description AS xnat_imagescandata6,
            table0.documentation AS xnat_imagescandata8,
            table0.scanner AS xnat_imagescandata9,
            table0.scanner_manufacturer AS xnat_imagescandata10,
            table0.scanner_model AS xnat_imagescandata11,
            table0.modality AS xnat_imagescandata13,
            table0.frames AS xnat_imagescandata14,
            table0.operator AS xnat_imagescandata15,
            table0.starttime AS xnat_imagescandata17,
            table0.id AS xnat_imagescandata19,
            table0.type AS xnat_imagescandata20,
            table0.uid AS xnat_imagescandata21,
            table0.project AS xnat_imagescandata22,
            table2.insert_date AS xnat_mgscandata_meta_data121,
            table4.login AS table4_login
           FROM (((public.xnat_mgscandata xnat_mgscandata
             LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_mgscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
             LEFT JOIN public.xnat_mgscandata_meta_data table2 ON ((xnat_mgscandata.mgscandata_info = table2.meta_data_id)))
             LEFT JOIN public.xdat_user table4 ON ((table2.insert_user_xdat_user_id = table4.xdat_user_id)))) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_mgscandata0
           FROM ( SELECT table0.xnat_imagescandata_id AS xnat_mgscandata0,
                    table2.insert_date AS xnat_mgscandata_meta_data121
                   FROM ((public.xnat_mgscandata xnat_mgscandata
                     LEFT JOIN public.xnat_imagescandata table0 ON ((xnat_mgscandata.xnat_imagescandata_id = table0.xnat_imagescandata_id)))
                     LEFT JOIN public.xnat_mgscandata_meta_data table2 ON ((xnat_mgscandata.mgscandata_info = table2.meta_data_id)))) where_clause_1) where_clause ON ((where_clause.xnat_mgscandata0 = search.xnat_mgscandata0)))
  ORDER BY search.xnat_imagescandata2;


ALTER TABLE public.displayfields_xnat_mgscandata OWNER TO xnat;

--
-- Name: xnat_mgsessiondata; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_mgsessiondata (
    id character varying(255) DEFAULT ''::character varying NOT NULL,
    mgsessiondata_info integer
);


ALTER TABLE public.xnat_mgsessiondata OWNER TO xnat;

--
-- Name: xnat_mgsessiondata_meta_data; Type: TABLE; Schema: public; Owner: xnat
--

CREATE TABLE public.xnat_mgsessiondata_meta_data (
    xft_version character varying(255),
    last_modified timestamp without time zone,
    status character varying(255),
    activation_date timestamp without time zone,
    row_last_modified timestamp without time zone,
    insert_date timestamp without time zone,
    activation_user_xdat_user_id integer,
    insert_user_xdat_user_id integer,
    origin character varying(255),
    modified integer,
    shareable integer,
    meta_data_id integer NOT NULL
);


ALTER TABLE public.xnat_mgsessiondata_meta_data OWNER TO xnat;

--
-- Name: xnat_mgsessiondata_projects; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.xnat_mgsessiondata_projects AS
 SELECT expt.id,
    ((('<'::text || (expt.project)::text) || '>'::text) || public.xs_a_concat(((',<'::text || (shared.project)::text) || '>'::text))) AS projects
   FROM ((public.xnat_experimentdata expt
     LEFT JOIN public.xnat_experimentdata_share shared ON (((expt.id)::text = (shared.sharing_share_xnat_experimentda_id)::text)))
     LEFT JOIN public.xdat_meta_element xme ON ((expt.extension = xme.xdat_meta_element_id)))
  WHERE ((xme.element_name)::text = 'xnat:mgSessionData'::text)
  GROUP BY expt.id, expt.project;


ALTER TABLE public.xnat_mgsessiondata_projects OWNER TO xnat;

--
-- Name: displayfields_xnat_mgsessiondata; Type: VIEW; Schema: public; Owner: xnat
--

CREATE VIEW public.displayfields_xnat_mgsessiondata AS
 SELECT search.xnat_subjectassessordata19 AS subject_id,
    search.xnat_mgsessiondata0 AS expt_id,
    '/@WEBAPP/images/r.gif'::text AS rpt,
    search.xnat_experimentdata22 AS date,
    (COALESCE((floor(((((search.xnat_experimentdata22 - search.xnat_demographicdata_xnat_demographicdata1))::real / (365)::double precision))::numeric))::double precision, floor((date_part('year'::text, search.xnat_experimentdata22) - (search.xnat_demographicdata_xnat_demographicdata2)::double precision))))::numeric AS age,
    search.xnat_mgsessiondata_projects_projects AS projects,
    COALESCE(search.xnat_experimentdata38, search.xnat_mgsessiondata0) AS label,
    search.table5_login AS insert_user,
    search.xnat_mgsessiondata_meta_data976 AS insert_date,
    search.xnat_experimentdata32 AS project,
    search.xnat_mgsessiondata_meta_data973 AS quarantine_status
   FROM (( SELECT DISTINCT ON (search_1.xnat_mgsessiondata0) search_1.xnat_mgsessiondata0,
            search_1.xnat_mgsessiondata_meta_data973,
            search_1.xnat_subjectassessordata19,
            search_1.xnat_experimentdata22,
            search_1.xnat_experimentdata38,
            search_1.table5_login,
            search_1.xnat_mgsessiondata_meta_data976,
            search_1.xnat_experimentdata32,
            search_1.xnat_demographicdata_demograp_xnat_demographicdata0,
            search_1.xnat_demographicdata_at_demographicdata_meta_data47,
            search_1.xnat_demographicdata_xnat_demographicdata1,
            search_1.xnat_demographicdata_xnat_demographicdata2,
            search_1.xnat_mgsessiondata_projects_projects
           FROM ( SELECT table2.id AS xnat_mgsessiondata0,
                    table4.status AS xnat_mgsessiondata_meta_data973,
                    table1.subject_id AS xnat_subjectassessordata19,
                    table2.date AS xnat_experimentdata22,
                    table2.label AS xnat_experimentdata38,
                    table5.login AS table5_login,
                    table4.insert_date AS xnat_mgsessiondata_meta_data976,
                    table2.project AS xnat_experimentdata32,
                    xnat_demographicdata.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                    xnat_demographicdata.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                    xnat_demographicdata.xnat_demographicdata1 AS xnat_demographicdata_xnat_demographicdata1,
                    xnat_demographicdata.xnat_demographicdata2 AS xnat_demographicdata_xnat_demographicdata2,
                    xnat_mgsessiondata_projects.projects AS xnat_mgsessiondata_projects_projects
                   FROM ((((((((public.xnat_mgsessiondata xnat_mgsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_mgsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))
                     LEFT JOIN public.xnat_mgsessiondata_meta_data table4 ON ((xnat_mgsessiondata.mgsessiondata_info = table4.meta_data_id)))
                     LEFT JOIN public.xdat_user table5 ON ((table4.insert_user_xdat_user_id = table5.xdat_user_id)))
                     LEFT JOIN public.xnat_mgsessiondata_projects xnat_mgsessiondata_projects ON (((table2.id)::text = (xnat_mgsessiondata_projects.id)::text)))
                     LEFT JOIN ( SELECT search_2.xnat_subjectdata3,
                            search_2.xnat_subjectdata_meta_data328,
                            search_2.xnat_demographicdata_demograp_xnat_demographicdata0,
                            search_2.xnat_demographicdata_at_demographicdata_meta_data47,
                            search_2.xnat_demographicdata_xnat_abstractdemographicdata27,
                            search_2.xnat_mgsessiondata_sordata_ex_xnat_mgsessiondata0,
                            search_2.xnat_mgsessiondata_sordata__xnat_experimentdata22,
                            search_2.xnat_mgsessiondata_sor_xnat_subjectassessordata19,
                            date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47)) AS xnat_subjectdata_xnat_demographicdata_diff
                           FROM ( SELECT xnat_subjectdata.id AS xnat_subjectdata3,
                                    table1_1.insert_date AS xnat_subjectdata_meta_data328,
                                    xnat_demographicdata_1.xnat_demographicdata0 AS xnat_demographicdata_demograp_xnat_demographicdata0,
                                    xnat_demographicdata_1.xnat_demographicdata_meta_data47 AS xnat_demographicdata_at_demographicdata_meta_data47,
                                    xnat_demographicdata_1.xnat_abstractdemographicdata27 AS xnat_demographicdata_xnat_abstractdemographicdata27,
                                    xnat_mgsessiondata_1.xnat_mgsessiondata0 AS xnat_mgsessiondata_sordata_ex_xnat_mgsessiondata0,
                                    xnat_mgsessiondata_1.xnat_experimentdata22 AS xnat_mgsessiondata_sordata__xnat_experimentdata22,
                                    xnat_mgsessiondata_1.xnat_subjectassessordata19 AS xnat_mgsessiondata_sor_xnat_subjectassessordata19
                                   FROM ((((public.xnat_subjectdata xnat_subjectdata
                                     LEFT JOIN public.xnat_subjectdata_meta_data table1_1 ON ((xnat_subjectdata.subjectdata_info = table1_1.meta_data_id)))
                                     LEFT JOIN ( SELECT xnat_subjectdata_1.id AS xnat_subjectdata3,
    table1_2.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata91,
    table2_1.insert_date AS xnat_subjectdata_meta_data328
   FROM ((public.xnat_subjectdata xnat_subjectdata_1
     LEFT JOIN public.xnat_abstractdemographicdata table1_2 ON ((xnat_subjectdata_1.demographics_xnat_abstractdemographicdata_id = table1_2.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_subjectdata_meta_data table2_1 ON ((xnat_subjectdata_1.subjectdata_info = table2_1.meta_data_id)))) map_xnat_demographicdata ON (((xnat_subjectdata.id)::text = (map_xnat_demographicdata.xnat_subjectdata3)::text)))
                                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
    table2_1.insert_date AS xnat_demographicdata_meta_data47,
    table0_1.xnat_abstractdemographicdata_id AS xnat_abstractdemographicdata27
   FROM ((public.xnat_demographicdata xnat_demographicdata_2
     LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_2.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
     LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_2.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata_1 ON ((map_xnat_demographicdata.xnat_abstractdemographicdata91 = xnat_demographicdata_1.xnat_abstractdemographicdata27)))
                                     LEFT JOIN ( SELECT table2_1.id AS xnat_mgsessiondata0,
    table2_1.date AS xnat_experimentdata22,
    table1_2.subject_id AS xnat_subjectassessordata19
   FROM (((public.xnat_mgsessiondata xnat_mgsessiondata_2
     LEFT JOIN public.xnat_imagesessiondata table0_1 ON (((xnat_mgsessiondata_2.id)::text = (table0_1.id)::text)))
     LEFT JOIN public.xnat_subjectassessordata table1_2 ON (((table0_1.id)::text = (table1_2.id)::text)))
     LEFT JOIN public.xnat_experimentdata table2_1 ON (((table1_2.id)::text = (table2_1.id)::text)))) xnat_mgsessiondata_1 ON (((xnat_subjectdata.id)::text = (xnat_mgsessiondata_1.xnat_subjectassessordata19)::text)))) search_2
                          ORDER BY search_2.xnat_subjectdata3, (date_part('milliseconds'::text, (search_2.xnat_subjectdata_meta_data328 - search_2.xnat_demographicdata_at_demographicdata_meta_data47))), search_2.xnat_mgsessiondata_sordata__xnat_experimentdata22 DESC) map_xnat_subjectdata_xnat_demographicdata ON (((table2.id)::text = (map_xnat_subjectdata_xnat_demographicdata.xnat_mgsessiondata_sordata_ex_xnat_mgsessiondata0)::text)))
                     LEFT JOIN ( SELECT table0_1.xnat_abstractdemographicdata_id AS xnat_demographicdata0,
                            table2_1.insert_date AS xnat_demographicdata_meta_data47,
                            xnat_demographicdata_1.dob AS xnat_demographicdata1,
                            xnat_demographicdata_1.yob AS xnat_demographicdata2
                           FROM ((public.xnat_demographicdata xnat_demographicdata_1
                             LEFT JOIN public.xnat_abstractdemographicdata table0_1 ON ((xnat_demographicdata_1.xnat_abstractdemographicdata_id = table0_1.xnat_abstractdemographicdata_id)))
                             LEFT JOIN public.xnat_demographicdata_meta_data table2_1 ON ((xnat_demographicdata_1.demographicdata_info = table2_1.meta_data_id)))) xnat_demographicdata ON ((map_xnat_subjectdata_xnat_demographicdata.xnat_demographicdata_demograp_xnat_demographicdata0 = xnat_demographicdata.xnat_demographicdata0)))) search_1
          ORDER BY search_1.xnat_mgsessiondata0, search_1.xnat_demographicdata_at_demographicdata_meta_data47 DESC) search
     RIGHT JOIN ( SELECT DISTINCT where_clause_1.xnat_mgsessiondata0
           FROM ( SELECT table2.id AS xnat_mgsessiondata0,
                    table2.date AS xnat_experimentdata22
                   FROM (((public.xnat_mgsessiondata xnat_mgsessiondata
                     LEFT JOIN public.xnat_imagesessiondata table0 ON (((xnat_mgsessiondata.id)::text = (table0.id)::text)))
                     LEFT JOIN public.xnat_subjectassessordata table1 ON (((table0.id)::text = (table1.id)::text)))
                     LEFT JOIN public.xnat_experimentdata table2 ON (((table1.id)::text = (table2.id)::text)))) where_clause_1) where_clause ON (((where_clause.xnat_mgsessiondata0)::text = (search.xnat_mgsessiondata0)::text)))
  ORDER BY search.xnat_subjectassessordata19;


ALTER TABLE public.displayfields_xnat_mgsessiondata OWNER TO xnat;

--
