         OR qra.value_date IS NOT NULL
         OR qra.value_datetime IS NOT NULL
         OR qra.value_string IS NOT NULL
-);
+    )
+;
 
 -- Reset ISOLATION level to previous setting
 COMMIT;
+
+
+ALTER TABLE cdm.src_clean ADD KEY (participant_id);
+
+-- -------------------------------------------------------------------
+-- Update cdm.src_clean to filter specific surveys.
+-- -------------------------------------------------------------------
+UPDATE combined_survey_filter SET survey_name = REPLACE(survey_name, '\r', '');
+
+UPDATE cdm.src_clean
+    INNER JOIN cdm.combined_survey_filter ON
+        cdm.src_clean.survey_name = cdm.combined_survey_filter.survey_name
+SET cdm.src_clean.filter = 1
+WHERE TRUE;
+
+-- -------------------------------------------------------------------
+-- Update cdm.src_clean to filter specific survey questions.
+-- -------------------------------------------------------------------
+
+UPDATE combined_question_filter SET question_ppi_code = REPLACE(question_ppi_code, '\r', '');
+
+UPDATE cdm.src_clean
+    INNER JOIN cdm.combined_question_filter ON
+        cdm.src_clean.question_ppi_code = cdm.combined_question_filter.question_ppi_code
+SET cdm.src_clean.filter = 1
+WHERE TRUE;
 
 -- -------------------------------------------------------------------
 -- source_file: src/src_mapped.sql

            WHEN qra.value_datetime IS NOT NULL THEN 'dtime'
            WHEN qra.value_string IS NOT NULL THEN 'str'
            ELSE ''
        END)                        AS unit_id

FROM rdr.participant pa
JOIN rdr.hpo hp
    ON  pa.hpo_id = hp.hpo_id
JOIN rdr.questionnaire_response qr
    ON  qr.participant_id = pa.participant_id
JOIN rdr.questionnaire_response_answer qra
    ON  qra.questionnaire_response_id = qr.questionnaire_response_id
JOIN rdr.questionnaire_question qq

-- table: src_clean
-- Contains persons observations
-- -------------------------------------------------------------------

DROP TABLE IF EXISTS cdm.src_clean;

CREATE TABLE cdm.src_clean (
    participant_id              bigint,
    survey_name                 varchar(200),
    date_of_survey              datetime,
    question_ppi_code           varchar(200),
    question_code_id            bigint,
    value_ppi_code              varchar(200),
    topic_value                 varchar(200),
    value_code_id               bigint,
    value_number                decimal(20,6),
    value_boolean               tinyint,
    value_date                  datetime,
    value_string                varchar(1024),
    questionnaire_response_id   bigint,
    unit_id                     varchar(50),
    filter                      smallint
);

-- -------------------------------------------------------------------
-- Rules all together
