-
Notifications
You must be signed in to change notification settings - Fork 15
Clean Patient Data
Michaël Bontyes edited this page May 5, 2025
·
2 revisions
This script is designed to clean up an OpenMRS 3.x database before go-live by removing patient demographic data, clinical data, and resetting various database elements. It's specifically prepared for the Mosul Go-Live (April, 2025).
- Temporarily disables foreign key checks to allow deletion operations
- Creates error-handling procedures to safely delete from tables without crashing on errors
The script systematically removes data from the following categories:
- Patient demographic data (person, patient, identifiers, etc.)
- Clinical data (observations, encounters, visits, etc.)
- Appointment-related data
- Drug and medication information
- Allergy records
- Program enrollment data
- User data
- System logs and queues
- Resets auto-increment counters for key tables
- Resets patient identifier sequence
- Removes temporary procedures created during execution
- Re-enables foreign key checks
-
safe_delete: Handles errors during table deletion operations -
safe_reset_auto_increment: Safely resets auto-increment counters -
safe_reset_sequence: Resets the patient identifier sequence
To execute this script against an OpenMRS database running in Docker:
cat -v reset_db.sql | docker exec -i ozone-msf-mosul-mysql-1 /usr/bin/mysql -u openmrs --password='password' openmrs -v-
cat -v cleanup.sql: Outputs the SQL script content, with the-vflag showing non-printing characters -
|: Pipes the script content to the next command -
docker exec -i ozone-msf-mosul-mysql-1: Executes a command inside the running MySQL Docker container -
/usr/bin/mysql: The MySQL client command -
-u openmrs: Specifies the MySQL username -
--password='password': Specifies the MySQL password -
openmrs: Specifies the target database -
-v: Enables verbose mode in MySQL to show detailed execution output
- Backup Recommendation: Always create a database backup before running this script
- Irreversible: The data deletion is permanent and cannot be undone
- Purpose: This script is intended for cleaning test data before going live, not for production use
- Customization: The script may need adjustments based on specific OpenMRS configurations and modules
- User Removal: This script will remove all users from the system. You will need to run a separate user creation script after cleanup to add necessary user accounts back into the system.
After running the script, the OpenMRS database will:
- Contain no patient or clinical data
- Have reset counters for new patient registrations
- Retain all system configurations and metadata
- Require new user accounts to be created