 
 ALTER TABLE dw_events_treatments
     ADD CONSTRAINT pk_dw_events_treatments PRIMARY KEY (id);
+CREATE INDEX dw_events_treatments_morbidity_id_ix
+    ON dw_events_treatments (dw_morbidity_events_id);
+CREATE INDEX dw_events_treatments_contact_id_ix
+    ON dw_events_treatments (dw_contact_events_id);
+CREATE INDEX dw_events_treatments_date_of_treatment_ix
+    ON dw_events_treatments (date_of_treatment);
 
 CREATE TABLE dw_morbidity_clinicians AS
 SELECT


ALTER TABLE dw_contact_events
    ADD CONSTRAINT pk_dw_contact_events PRIMARY KEY (id);

CREATE INDEX dw_contact_events_patient_id ON dw_contact_events (dw_patients_id);

CREATE INDEX dw_contact_events_parent_id ON dw_contact_events (parent_id);

-- UPDATE dw_patients p
-- SET is_morbidity_patient = TRUE
-- FROM dw_morbidity_events dm
-- WHERE dm.dw_patients_id = p.id;

-- UPDATE dw_patients p
-- SET is_contact_patient = TRUE
-- FROM dw_contact_events dm
-- WHERE dm.dw_patients_id = p.id;

-- ALTER TABLE dw_patients
--     ADD CONSTRAINT pk_dw_patients PRIMARY KEY (id);

CREATE TABLE dw_secondary_jurisdictions AS
SELECT
    -- TODO: Test this with contact events with secondary jurisdictions
    events.id,
    CASE
        WHEN events.type = 'MorbidityEvent' THEN events.id

        ON (f.primary_entity_id = people.entity_id)
;

ALTER TABLE dw_morbidity_patients
    ADD CONSTRAINT dw_morbidity_patients_pkey PRIMARY KEY (id);
CREATE INDEX dw_morbidity_patients_entity_ix ON dw_morbidity_patients (entity_id);
CREATE INDEX dw_morbidity_patients_birth_gender_ix
    ON dw_morbidity_patients (birth_gender);
CREATE INDEX dw_morbidity_patients_ethnicity_ix ON dw_morbidity_patients (ethnicity);
CREATE INDEX dw_morbidity_patients_birth_date_ix
    ON dw_morbidity_patients (birth_date);
CREATE INDEX dw_morbidity_patients_date_of_death_ix
    ON dw_morbidity_patients (date_of_death);

CREATE TABLE dw_contact_patients AS
SELECT
    people.id,
