CREATE TABLE IF NOT EXISTS Symptom
(
    symptom_id          INT          NOT NULL AUTO_INCREMENT,
    symptom             VARCHAR(50)  NOT NULL,
    symptom_description VARCHAR(100) NOT NULL,
    PRIMARY KEY (symptom_id)
);

CREATE TABLE IF NOT EXISTS Patient
(
    patient_id INT          NOT NULL,
    first_name VARCHAR(100) NOT NULL,
    last_name  VARCHAR(100) NOT NULL,
    address    VARCHAR(100) NOT NULL,
    gender     VARCHAR(100) NOT NULL,
    birth_date DATE         NOT NULL,
    PRIMARY KEY (patient_id)
);

# CREATE TABLE IF NOT EXISTS Patient_Symptom
# (
#     date       DATE NOT NULL,
#     patient_id INT  NOT NULL,
#     symptom_id INT  NOT NULL,
#     PRIMARY KEY (date, patient_id),
#     FOREIGN KEY (patient_id) REFERENCES Patient (patient_id),
#     FOREIGN KEY (symptom_id) REFERENCES Symptom (symptom_id)
# );

CREATE TABLE IF NOT EXISTS Question
(
    question_id   INT          NOT NULL AUTO_INCREMENT,
    question_text VARCHAR(255) NOT NULL,
    PRIMARY KEY (question_id)
);

CREATE TABLE IF NOT EXISTS Symptom_Question
(
    symptom_id  INT NOT NULL,
    question_id INT NOT NULL,
    PRIMARY KEY (symptom_id, question_id),
    FOREIGN KEY (symptom_id) REFERENCES Symptom (symptom_id),
    FOREIGN KEY (question_id) REFERENCES Question (question_id)
);

CREATE TABLE IF NOT EXISTS Answer
(
    answer_id   INT          NOT NULL AUTO_INCREMENT,
    answer_text VARCHAR(255) NOT NULL,
    PRIMARY KEY (answer_id)
);

CREATE TABLE IF NOT EXISTS Question_Answer
(
    question_id INT NOT NULL,
    answer_id   INT NOT NULL,
    PRIMARY KEY (question_id, answer_id),
    FOREIGN KEY (question_id) REFERENCES Question (question_id),
    FOREIGN KEY (answer_id) REFERENCES Answer (answer_id)
);

CREATE TABLE IF NOT EXISTS Questionnaire
(
    questionnaire_id VARCHAR(50),
    patient_id       INT NOT NULL,
    PRIMARY KEY (questionnaire_id),
    FOREIGN KEY (patient_id) REFERENCES Patient (patient_id)
);

CREATE TABLE IF NOT EXISTS Questionnaire_Response
(
    questionnaire_id VARCHAR(50) NOT NULL,
    question_id      INT         NOT NULL,
    answer_id        INT         NOT NULL,
    PRIMARY KEY (questionnaire_id, question_id, answer_id),
    FOREIGN KEY (questionnaire_id) REFERENCES Questionnaire (questionnaire_id),
    FOREIGN KEY (question_id) REFERENCES Question (question_id),
    FOREIGN KEY (answer_id) REFERENCES Answer (answer_id)
);

CREATE TABLE IF NOT EXISTS Waiting_Queue
(
    patient_id INT      NOT NULL AUTO_INCREMENT,
    start_time DATETIME NOT NULL,
    end_TIME   DATETIME NULL,
    PRIMARY KEY (patient_id, start_time),
    FOREIGN KEY (patient_id) REFERENCES Patient (patient_id)
);



