How to keep custom settings in Open EMR but delete all patient records?

Hello. Is there a way to keep the custom settings but delete the entire patient database? I can only see how to delete one patient at a time? Thanks.

You can truncate the patient_data table. That should work. Things like the insurance_data, billing_table, etc all have counters so truncating the patient_data table shouldn’t cause too many issues .

You really don’t want abandoned data floating around.
Suggest you check out the interface/patient_file/deleter.php script. Recm modifying a cloned version to batch delete patients by iterating from top level of script.
Then go back into database and reset you auto increment columns or truncate the appropriate tables.

1 Like

Thanks, Daniel. Can you please explain how to truncate the patient_data table?

Thanks, Jerry. Can you please point to me where I can find that script and how to run it?

I have a few questions.
How many encounters are associated with the patients? Do you want to delete the encounters too?
Do you have insurance data associated with these patients?
Do you care about any of the data associated with the patients?

@sjpadgett offered great advice with checking out the interface/patient_file/deleter.php script which could be called by a simple script to loop through all patients in the db.

Thanks. I have 9000 patients with many encounters each. I have no insurance information and no data with any of the patients that I want to save. Basically, we have another doctor starting in another clinic, and I want to create a blank database for her using the customized settings that were created for us in our current clinic.

Can you elaborate when you refer to β€œcustomized settings”? Are you referring to just the Administration-> Global settings or are you referring to custom Layout Based Forms, forms, the address book, users, etc.?

The deleter.php script does take care of most the tables related to patients, but may be incomplete for what you are looking for. In the openemr_600 database there are 77 tables that store pid values, but not every table that has patient data has a pid column (i.e. lbf_data).

A few of the tables that are missed by the deleter.php script (I searched the script to find these strings and could not find them):
amc_misc_data
amendments
ac_activity
audit_master
ccda
…

and there are quite a few more.

I think the following should be through enough:

  1. Query the patient data.
  2. For each pid, run the deleter script.
  3. Truncate the remaining tables that contain a reference to pids. (Note: some tables have columns like ct_pid, pc_pid, etc.)
  4. There are tables that hold the next value of things like encounters and such. It might not be necessary to reset these, but maybe Jerry or Stephen can elaborate.

@stephenwaite @sjpadgett - Is there anything that I am missing here?

Actually, I am not entirely sure as an IT consultant set up our system so I don’t know exactly what he customized. So I am thinking of at least the global settings and the layout based forms. I don’t need the address book nor users.

Sorry I am a very basic user. I have no idea how to run the deleter.php script. Can you explain how to do that or point me to a site? Thanks.

I think that Jerry and Stephen (and myself) assumed that you are a developer that has experience with php or mySQL. Currently I’m not aware of a script that will do exactly what you are looking for so there really isn’t an easy button for this task.

Are you looking for the version of OpenEMR with an empty database to be used in a production environment or is this just for training purposes? If this is being used for training purposes I can write a quick set of instructions that will get you what you need with no guarantee that data issues won’t happen in the future. This solution should not ever be used in Production.

If this instance of OpenEMR will be used in a production environment it will need more attention to detail and coding will be required, probably 4 - 6 (max) hours of coding and testing.

1 Like

Thanks, Daniel, just need a quick set of instructions to create an empty database for training. Thank you.

Tom,

Do you have access to phpMyAdmin? This would be easiest. Also, are you running this on LAMP or XAMP?

Before reading this, make a backup of your current database.


Once you get a second instance of OpenEMR going, the following instructions should be fine for training purposes only. Here are a few things that this does:

  1. We remove all patient demographics, billing, and insurance data.
  2. We remove all form data and encounter data. The encounter increment is not reset to prevent unexpected behavior.
  3. We remove all calendar events associated with patients, keeping things like staff schedules.
  4. We load the sample_patient_data.sql info using the info provided. The current sample_patient_data.sql file has issues. This should work for you.

When you have confirmed that you are in the training database, you can put the following in phpMyAdmin screen. If you have not yet made a backup, read the first line of this post.
copy and paste in its entirety everything below this line.

Truncate table patient_data;
truncate table insurance_data;
truncate table billing;
truncate table form_encounter;
delete from openemr_postcalendar_events where pc_pid > 0;

INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Ms.’, β€˜english’, β€˜β€™, β€˜Farrah’, β€˜Rolle’, β€˜A.’, β€˜1973-10-11’, β€˜111 Main Street’, β€˜92101’, β€˜San Luis’, β€˜CA’, β€˜β€™, β€˜456789123’, β€˜β€™, β€˜(619) 555-2222’, β€˜(619) 555-3333’, β€˜(619) 555-1111’, β€˜β€™, β€˜married’, β€˜Joe’, β€˜2003-11-17 12:06:00’, β€˜Female’, β€˜Phil Martin’, β€˜β€™, NULL, β€˜frolle@pennfirm.com’, β€˜Latina’, β€˜β€™, β€˜β€™, β€˜3’, β€˜3200’, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜10’, 5,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2)VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜Ted’, β€˜Shaw’, β€˜β€™, β€˜1947-03-11’, β€˜222 1st Avenue’, β€˜92101’, β€˜San Diego’, β€˜CA’, β€˜β€™, β€˜920-24-2256’, β€˜Landscape Architect’, β€˜(619) 555-7568’, β€˜(619) 555-9867’, β€˜(619) 555-7567’, β€˜β€™, β€˜married’, β€˜Marion Shaw’, β€˜2003-11-17 13:47:42’, β€˜Male’, β€˜Phil Martin’, β€˜β€™, NULL, β€˜info@pennfirm.com’, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜24555’, 1,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mrs.’, β€˜english’, β€˜β€™, β€˜Eduardo’, β€˜Perez’, β€˜β€™, β€˜1957-01-09’, β€˜789 Third Avenue’, β€˜β€™, β€˜San Diego’, β€˜CA’, β€˜β€™, β€˜234567891’, β€˜Manager of Transportation’, β€˜(619) 555-4859’, β€˜(619) 555-7821’, β€˜(619) 555-7823 x251’, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2004-01-20 15:43:30’, β€˜Male’, β€˜Ynez Jones’, β€˜β€™, 4, β€˜info@pennfirm.com’, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜789456’, 4,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mrs.’, β€˜spanish’, β€˜β€™, β€˜Nora’, β€˜Cohen’, β€˜β€™, β€˜1967-06-04’, β€˜155 First Avenue’, β€˜92101’, β€˜San Luis’, β€˜CA’, β€˜β€™, β€˜891-23-4567’, β€˜β€™, β€˜(213) 555-5555’, β€˜(213) 555-4444’, β€˜(818) 555-5555’, β€˜β€™, β€˜married’, β€˜β€™, β€˜2004-01-16 10:28:22’, β€˜Female’, β€˜Phil Martin’, β€˜β€™, 5, β€˜β€™, β€˜Latina’, β€˜β€™, β€˜β€™, β€˜3’, β€˜1500’, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜8’, 8,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜Brent’, β€˜Perez’, β€˜β€™, β€˜1960-01-01’, β€˜1234 1st Avenue’, β€˜92101’, β€˜San Diego’, β€˜CA’, β€˜β€™, β€˜123456789’, β€˜Airline Mechanic’, β€˜(619) 696-5050’, β€˜(888) 480-5050’, β€˜(619) 696-5050’, β€˜β€™, β€˜married’, β€˜Maria Perez’, β€˜2004-01-14 17:30:09’, β€˜Male’, β€˜Phil Martin’, β€˜β€™, 5, β€˜bperez@pennfirm.com’, β€˜Latino’, β€˜β€™, β€˜β€™, β€˜3’, β€˜2200’, β€˜β€™, β€˜2004-04-02 00:00:00’, β€˜1001’, 41,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜β€™, β€˜β€™, β€˜Jim’, β€˜Moses’, β€˜β€™, β€˜1945-02-14’, β€˜β€™, β€˜β€™, β€˜Los Angeles’, β€˜CA’, β€˜β€™, β€˜545676767’, β€˜β€™, β€˜(323) 555-4444’, β€˜(909) 555-6767’, β€˜(310) 555-1212’, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2004-01-15 13:45:08’, β€˜Male’, β€˜Administrator Administrator’, β€˜β€™, 1, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜17’, 17,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜β€™, β€˜β€™, β€˜Richard’, β€˜Jones’, β€˜β€™, β€˜1940-12-16’, β€˜400 West Broadway’, β€˜92101’, β€˜San Diego’, β€˜CA’, β€˜β€™, β€˜555-11-1111’, β€˜β€™, β€˜(619) 555-5555’, β€˜(619) 333-3333’, β€˜(619) 444-4444’, β€˜β€™, β€˜married’, β€˜β€™, β€˜2004-01-16 10:02:41’, β€˜β€™, β€˜Ynez Jones’, β€˜β€™, 4, β€˜richard@pennfirm.com’, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜18’, 18,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜Ilias’, β€˜Jenane’, β€˜β€™, β€˜1933-03-22’, β€˜145 N. East Street’, β€˜92111’, β€˜La Mesa’, β€˜CA’, β€˜β€™, β€˜111-11-2222’, β€˜retired - school teacher’, β€˜(619) 555-2222’, β€˜(619) 555-3333’, β€˜(619) 555-1111’, β€˜β€™, β€˜single’, β€˜β€™, β€˜2004-01-16 10:23:47’, β€˜Female’, β€˜Ynez Jones’, β€˜β€™, 4, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜22’, 22,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜Jason’, β€˜Binder’, β€˜β€™, β€˜1961-12-11’, β€˜100 West Sepulveda’, β€˜92020’, β€˜Los Angeles’, β€˜CA’, β€˜β€™, β€˜222-11-8888’, β€˜Real Estate Agent’, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜single’, β€˜β€™, β€˜2004-01-16 10:13:50’, β€˜Male’, β€˜Ynez Jones’, β€˜β€™, 4, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜30’, 30,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜John’, β€˜Dockerty’, β€˜D’, β€˜1977-05-02’, β€˜800 West Way’, β€˜92101’, β€˜San Diego’, β€˜CA’, β€˜β€™, β€˜111-11-1111’, β€˜Physical therapist’, β€˜(567) 789-7891’, β€˜(567) 789-1234’, β€˜(567) 567-5678’, β€˜β€™, β€˜single’, β€˜β€™, β€˜2004-01-16 10:21:05’, β€˜β€™, β€˜Phil Martin’, β€˜β€™, 5, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜25’, 25,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜James’, β€˜Janssen’, β€˜β€™, β€˜1966-04-28’, β€˜111 North Street’, β€˜90205’, β€˜Irvine’, β€˜CA’, β€˜β€™, β€˜555-11-1111’, β€˜Office Manager’, β€˜(818) 555-2222’, β€˜(818) 555-2323’, β€˜(5555) 555-1111’, β€˜β€™, β€˜single’, β€˜β€™, β€˜2004-01-19 14:21:25’, β€˜Male’, β€˜β€™, β€˜β€™, 1, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜26’, 26,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜Wallace’, β€˜Buckley’, β€˜β€™, β€˜1952-04-03’, β€˜123 West Street’, β€˜90400’, β€˜Barstow’, β€˜California’, β€˜β€™, β€˜999-99-1111’, β€˜Accountant’, β€˜(555) 111-1111’, β€˜(555) 111-1234’, β€˜(555) 555-5555’, β€˜β€™, β€˜domestic partner’, β€˜Mike Hart’, β€˜2004-01-16 10:18:28’, β€˜β€™, β€˜Ynez Jones’, β€˜β€™, 4, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜40’, 40,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜Robert’, β€˜Dickey’, β€˜β€™, β€˜1955-04-12’, β€˜111 North Kearny’, β€˜91040’, β€˜Torrance’, β€˜CA’, β€˜β€™, β€˜214-22-1111’, β€˜Project Manager’, β€˜(808) 555-1234’, β€˜(808) 555-4444’, β€˜(808) 555-1111’, β€˜β€™, β€˜married’, β€˜β€™, β€˜2004-01-16 10:31:45’, β€˜β€™, β€˜Phil Martin’, β€˜β€™, 5, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜34’, 34,’’,’’,’’,’’);
INSERT INTO patient_data
(title, language, financial, fname, lname, mname, DOB, street, postal_code, city, state, drivers_license, ss, occupation, phone_home, phone_biz, phone_contact, phone_cell, status, contact_relationship, date, sex, referrer, referrerID, providerID, email, ethnoracial, interpretter, migrantseasonal, family_size, monthly_income, homeless, financial_review, pubpid, pid, genericname1, genericval1, genericname2, genericval2) VALUES ( β€˜Mr.’, β€˜english’, β€˜β€™, β€˜Jillian’, β€˜Mahoney’, β€˜β€™, β€˜1968-08-11’, β€˜444 North State Street’, β€˜90204’, β€˜Santa Ana’, β€˜CA’, β€˜β€™, β€˜222-11-1111’, β€˜β€™, β€˜(808) 555-4444’, β€˜(808) 555-3333’, β€˜(808) 555-5555’, β€˜β€™, β€˜married’, β€˜β€™, β€˜2004-01-19 12:14:06’, β€˜Female’, β€˜Ynez Jones’, β€˜β€™, 4, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜β€™, β€˜2021-01-01 00:00:00’, β€˜35’, 35,’’,’’,’’,’’);

Thanks, Daniel. Yes, I do have access to phpMy Admin. And I am running this on XAMP. I am going to need some time to work through your instructions-thank you very much.