/*
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,
    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 text COLLATE pg_catalog.default NOT NULL,
    description text COLLATE pg_catalog.default,
    CONSTRAINT MedicalSpecialty_pkey PRIMARY KEY (name)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE MyHealth.MedicalSpecialty
    OWNER to "USER";
    
-- Table: MyHealth.MedicalTest

-- DROP TABLE MyHealth.MedicalTest;

CREATE TABLE MyHealth.MedicalTest
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
    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,
    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,
    FamilyDoctorId character varying(50) COLLATE pg_catalog.default,
    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,
    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,
    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,
    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,
    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,
    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";
    
