 UPDATE encounter_type SET retired_by = @buendia_admin_id WHERE
     retired_by IS NOT NULL AND retired_by != @admin_id;
 
-UPDATE field SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-UPDATE field SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE field SET retired_by = @buendia_admin_id WHERE
-    retired_by IS NOT NULL AND retired_by != @admin_id;
-
-UPDATE field_answer SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-
 UPDATE field_type SET creator = @buendia_admin_id WHERE
     creator IS NOT NULL AND creator != @admin_id;
 
-UPDATE form SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE form SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-UPDATE form SET retired_by = @buendia_admin_id WHERE
-    retired_by IS NOT NULL AND retired_by != @admin_id;
-
-UPDATE form_field SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE form_field SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-
 UPDATE hl7_source SET creator = @buendia_admin_id WHERE
     creator IS NOT NULL AND creator != @admin_id;
 
-UPDATE location SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-UPDATE location SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE location SET retired_by = @buendia_admin_id WHERE
-    retired_by IS NOT NULL AND retired_by != @admin_id;
-
-UPDATE location_attribute SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-UPDATE location_attribute SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE location_attribute SET voided_by = @buendia_admin_id WHERE
-    voided_by IS NOT NULL AND voided_by != @admin_id;
-
-UPDATE location_attribute_type SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-UPDATE location_attribute_type SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE location_attribute_type SET retired_by = @buendia_admin_id WHERE
-    retired_by IS NOT NULL AND retired_by != @admin_id;
-
-UPDATE location_tag SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-UPDATE location_tag SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE location_tag SET retired_by = @buendia_admin_id WHERE
-    retired_by IS NOT NULL AND retired_by != @admin_id;
-
-UPDATE note SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-UPDATE note SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-
-UPDATE notification_alert SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE notification_alert SET changed_by = @buendia_admin_id WHERE
-    changed_by IS NOT NULL AND changed_by != @admin_id;
-
-UPDATE obs SET creator = @buendia_admin_id WHERE
-    creator IS NOT NULL AND creator != @admin_id;
-UPDATE obs SET voided_by = @buendia_admin_id WHERE
-    voided_by IS NOT NULL AND voided_by != @admin_id;
-
 UPDATE order_frequency SET changed_by = @buendia_admin_id WHERE
     changed_by IS NOT NULL AND changed_by != @admin_id;
 UPDATE order_frequency SET creator = @buendia_admin_id WHERE

    changed_by IS NOT NULL AND changed_by != @admin_id;
UPDATE program_workflow_state SET creator = @buendia_admin_id WHERE
    creator IS NOT NULL AND creator != @admin_id;

UPDATE provider SET changed_by = @buendia_admin_id WHERE
    changed_by IS NOT NULL AND changed_by != @admin_id;
UPDATE provider SET creator = @buendia_admin_id WHERE
    creator IS NOT NULL AND creator != @admin_id;
UPDATE provider SET retired_by = @buendia_admin_id WHERE
    retired_by IS NOT NULL AND retired_by != @admin_id;

UPDATE provider_attribute SET changed_by = @buendia_admin_id WHERE
    changed_by IS NOT NULL AND changed_by != @admin_id;
UPDATE provider_attribute SET creator = @buendia_admin_id WHERE
    creator IS NOT NULL AND creator != @admin_id;
UPDATE provider_attribute SET voided_by = @buendia_admin_id WHERE
    voided_by IS NOT NULL AND voided_by != @admin_id;

UPDATE provider_attribute_type SET changed_by = @buendia_admin_id WHERE
    changed_by IS NOT NULL AND changed_by != @admin_id;


DELETE FROM person WHERE person_id NOT IN (SELECT person_id FROM keep_users);

-- Clear the huge concept word and concept reference tables; we don't need them.
DELETE FROM concept_word;
DELETE FROM concept_reference_term_map;
DELETE FROM concept_reference_map;
DELETE FROM concept_reference_term;

-- Delete all the custom Buendia concepts.
SET @max_id := 999999;
DELETE FROM concept_answer WHERE concept_id > @max_id;
DELETE FROM concept_answer WHERE answer_concept > @max_id;
DELETE FROM concept_complex WHERE concept_id > @max_id;
DELETE FROM concept_description WHERE concept_id > @max_id;
DELETE FROM concept_name WHERE concept_id > @max_id;
DELETE FROM concept_numeric WHERE concept_id > @max_id;
DELETE FROM concept_proposal WHERE concept_id > @max_id;
DELETE FROM concept_proposal WHERE obs_concept_id > @max_id;
DELETE FROM concept_set WHERE concept_id > @max_id;
DELETE FROM concept_set WHERE concept_set > @max_id;
DELETE FROM concept_state_conversion WHERE concept_id > @max_id;
DELETE FROM concept_word WHERE concept_id > @max_id;
DELETE FROM drug WHERE concept_id > @max_id;
DELETE FROM drug WHERE dosage_form > @max_id;
DELETE FROM drug WHERE route > @max_id;
DELETE FROM drug_ingredient WHERE concept_id > @max_id;
DELETE FROM drug_ingredient WHERE ingredient_id > @max_id;
DELETE FROM order_frequency WHERE concept_id > @max_id;
DELETE FROM orders WHERE concept_id > @max_id;
DELETE FROM concept WHERE concept_id > @max_id;
