/*
DROP TABLE myhealth.Administrator;
DROP TABLE myhealth.FamilyDoctor;
DROP TABLE myhealth.MedicalSpecialty;
DROP TABLE myhealth.MedicalTest;
DROP TABLE myhealth.Patient;
DROP TABLE myhealth.PrimaryHealthCareCenter;
DROP TABLE myhealth.Question;
DROP TABLE myhealth.Response;
DROP TABLE myhealth.SpecialistDoctor;
DROP TABLE myhealth.Visit;
*/

-- Table: myhealth.administrator

-- DROP TABLE myhealth.administrator;

CREATE TABLE myhealth.administrator
(
    email character varying(50) COLLATE pg_catalog."default" NOT NULL,
    password character varying(100) COLLATE pg_catalog."default",
    CONSTRAINT administrator_pkey PRIMARY KEY (email)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.administrator
    OWNER to "USER";
    
-- Table: myhealth.familydoctor

-- DROP TABLE myhealth.familydoctor;

CREATE TABLE myhealth.familydoctor
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    password character(50) COLLATE pg_catalog."default",
    nif character(50) COLLATE pg_catalog."default",
    surname character varying(100) COLLATE pg_catalog."default",
    email character varying(120) COLLATE pg_catalog."default",
    name character varying(100) COLLATE pg_catalog."default",
    primaryhealthcarecenterid character varying(50) COLLATE pg_catalog."default",
    CONSTRAINT familydoctor_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.familydoctor
    OWNER to "USER";

-- Table: myhealth.medicalspecialty

-- DROP TABLE myhealth.medicalspecialty;

CREATE TABLE myhealth.medicalspecialty
(
    name character varying(50) COLLATE pg_catalog."default" NOT NULL,
    description character varying(1000) COLLATE pg_catalog."default",
    CONSTRAINT medicalspecialty_pkey PRIMARY KEY (name)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.medicalspecialty
    OWNER to postgres;

-- Table: myhealth.medicaltest

-- DROP TABLE myhealth.medicaltest;

CREATE TABLE myhealth.medicaltest
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    date date,
    "time" abstime,
    result text COLLATE pg_catalog."default",
    highresimage bytea,
    type integer,
    patientid character varying(50) COLLATE pg_catalog."default" NOT NULL,
    specialistdoctorid character varying(50) COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT medicaltest_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.medicaltest
    OWNER to "USER";
    
-- Table: myhealth.patient

-- DROP TABLE myhealth.patient;

CREATE TABLE myhealth.patient
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    password character varying COLLATE pg_catalog."default",
    nif character varying COLLATE pg_catalog."default",
    surname character varying(100) COLLATE pg_catalog."default",
    email character varying(120) COLLATE pg_catalog."default",
    name character varying(100) COLLATE pg_catalog."default",
    familydoctorid integer,
    CONSTRAINT patient_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.patient
    OWNER to "USER";

-- Table: myhealth.primaryhealthcarecenter

-- DROP TABLE myhealth.primaryhealthcarecenter;

CREATE TABLE myhealth.primaryhealthcarecenter
(
    name character varying(50) COLLATE pg_catalog."default" NOT NULL,
    location character varying(256) COLLATE pg_catalog."default",
    CONSTRAINT primaryhealthcarecenter_pkey PRIMARY KEY (name)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.primaryhealthcarecenter
    OWNER to "USER";
    
-- Table: myhealth.question

-- DROP TABLE myhealth.question;

CREATE TABLE myhealth.question
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    title character varying(512) COLLATE pg_catalog."default" NOT NULL,
    message character varying(8000) COLLATE pg_catalog."default" NOT NULL,
    status integer,
    patientid character varying(50) COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT question_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.question
    OWNER to "USER";

-- Table: myhealth.response

-- DROP TABLE myhealth.response;

CREATE TABLE myhealth.response
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    response character varying(8000) COLLATE pg_catalog."default",
    questionid integer NOT NULL,
    CONSTRAINT response_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.response
    OWNER to "USER";

-- Table: myhealth.specialistdoctor

-- DROP TABLE myhealth.specialistdoctor;

CREATE TABLE myhealth.specialistdoctor
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    password character varying COLLATE pg_catalog."default",
    nif character varying COLLATE pg_catalog."default",
    surname character varying(100) COLLATE pg_catalog."default",
    email character varying(120) COLLATE pg_catalog."default",
    name character varying(100) COLLATE pg_catalog."default",
    medicalspecialtyid character varying(50) COLLATE pg_catalog."default",
    CONSTRAINT specialistdoctor_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.specialistdoctor
    OWNER to "USER";

-- Table: myhealth.visit

-- DROP TABLE myhealth.visit;

CREATE TABLE myhealth.visit
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    date date NOT NULL,
    "time" abstime NOT NULL,
    observations character varying(4000) COLLATE pg_catalog."default",
    result text COLLATE pg_catalog."default",
    patientid character varying(50) COLLATE pg_catalog."default" NOT NULL,
    familydoctorid character varying(50) COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT visit_pkey PRIMARY KEY (id)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE myhealth.visit
    OWNER to "USER";

