Data migration from OpenMRS

This page illustrates how to migrate data from OpenMRS to OpenSRP and Keycloak.

From version 2.2.x and above OpenSRP does not have any direct dependency on OpenMRS. Locations, team, team members were moved to OpenSRP while Users were moved to Keycloak

Location Tags

First export location tags from OpenMRS to a JSON file then run POST request for each of the returned location tag in the order of the location hierarchy beginning from the top e.g. starting from the Country to the village level. (NOTE: Currently OpenSRP does not support posting location tags in a JSON Array)

First delete any previously generated JSON file. The execute the SQL statement to generate the JSON.

sudo rm /tmp/location_tags.json
SELECT CONCAT('[', group_concat( json_object('name', name, 'description', if(description is null, concat(name, ' Tag'), description), 'active', if(retired = 0, true, false))), ']') as tags FROM location_tag INTO OUTFILE '/tmp/location_tags.json';

Locations


Get the secure directory that mysql permits to export data. Otherwise when the response returned by the following command is NULLcreate the directory and set the secure_file_priv = /var/lib/mysql-files/ property in your mysql.conf or mariadb.conf file.

mysql> SELECT @@global.secure_file_priv; +---------------------------+ | @@global.secure_file_priv | +---------------------------+ | /var/lib/mysql-files/ | +---------------------------+

Setting secure_file_priv

Run the following commands to create the directory used for importing and exporting data to and from mysql.

Exporting locations

Export locations from OpenMRS to csv format by executing the below query


Use the generated csv and format to get the Location JSON that can be posted to the location endpoint

Use the below JSON template on https://www.convertcsv.com/csv-to-json.htm. Select the option Step 4: Create Custom Output via Template



Download the JSON and POST to the location batch save endpoint `rest/location/add?is_jurisdiction=true`. The body should be JSON array of locations

Teams


Team Members



Users


TODO add steps