drop table if exists "DiseaseBurden".trial_to_icd10;

CREATE TABLE "DiseaseBurden".trial_to_icd10 (
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY,
    nct_id varchar NOT NULL,
    "condition" varchar NOT NULL,
    ui varchar NULL,
    uri varchar NULL,
    rootsource varchar NULL,
    "name" varchar NULL,
    "source" varchar null,
    CONSTRAINT trial_to_icd10_pk PRIMARY KEY (id)
);
comment on type "DiseaseBurden".trial_to_icd10 is 'This represents potential links between trials and icd10 codes. Most of the links are both automatic and wrong.';



DROP TABLE if exists "DiseaseBurden".icd10_to_cause;
 
CREATE TABLE "DiseaseBurden".icd10_to_cause (
    id SERIAL NOT NULL ,
    code varchar NOT NULL,
    cause_text varchar NOT NULL,
    CONSTRAINT icd10_to_cause_pk PRIMARY KEY (id)
);




drop table if exists "DiseaseBurden".match_status;
drop type if exists "DiseaseBurden".validation_type;

create type "DiseaseBurden".validation_type as enum ('accepted', 'rejected', 'unmatched');
comment on type "DiseaseBurden".validation_type is 'This is used to record interactions with each type. It can be accepted (yes this should be used), rejected (no this doesn`t match), or unmatched (where non of the proposed options match)';

CREATE TABLE "DiseaseBurden".match_status (
    id serial4 NOT NULL,
    approved "DiseaseBurden".validation_type NOT NULL,
    approval_timestamp timestamp NOT NULL,
    CONSTRAINT match_status_pk PRIMARY KEY (id, approval_timestamp)
);
COMMENT ON TABLE "DiseaseBurden".match_status IS 'This allows me to record if a particular proposed match is approved or not.';

