Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

What this page is for

These are the instructions for OpenMRS 1.6 and OpenMRS 1.8.3. They cover how to delete all of the patient data from OpenMRS while keeping all of the forms, users, and settings that you've made (i.e. this is how to clear or delete all patient information but keeping everything else).  I found a forum page which described how to do this by only exporting the tables that you wanted using mysqldump, but I can't find it now.  I've decided to take the second option which is deleting the data from the patient tables.

Documentation / How-To

To do this, you should log into your mysql database using a user that has delete privileges (best option is probably as an administrator).

For OpenMRS v1.6, paste the following queries in and you're done.

delete from obs;
delete from accesslogging_accesslog;
delete from encounter;
delete from patient_identifier;
delete from cohort_member;
delete from usagestatistics_usage;
delete from call_log;
delete from patient_program;
delete from sms_history;
delete from patient;
delete from person_address where person_id not in (select person_id from users);
delete from person_attribute where person_id not in (select person_id from users);
delete from person_name where person_id not in (select person_id from users);
delete from relationship;
delete from person where person_id not in (select person_id from users);

For OpenMRS v1.8.3, the command would need to take foreign keys into consideration and would look like this:

SET foreign_key_checks = 0;
delete from obs;
delete from accesslogging_accesslog;
delete from encounter;
delete from patient_identifier;
delete from cohort_member;
delete from usagestatistics_usage;
delete from call_log;
delete from patient_program;
delete from sms_history;
delete from patient;
delete from person_address where person_id not in (select person_id from users);
delete from person_attribute where person_id not in (select person_id from users);
delete from person_name where person_id not in (select person_id from users);
delete from relationship;
delete from person where person_id not in (select person_id from users);
delete from alert_archive;
delete from alert_error;

SET foreign_key_checks = 1;

Important Side Note: The first command disables foreign keys to allow deletion of the pt(patient tables) data. The second command deletes the pt data, but not user data, and the third command enables foreign keys again.

  • No labels