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
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'; |
Get the secure directory that mysql permits to export data. Otherwise when the response returned by the following command is NULL
create 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/ | +---------------------------+ |
Run the following commands to create the directory used for importing and exporting data to and from mysql.
cd /var/lib/ mkdir /var/lib/mysql-files/ chown mysql:mysql mysql-files chmod 750 mysql-files |
Export locations from OpenMRS to csv format by executing the below query
select 'id','name','parentId','status','version','geographicLevel','id','name' union all select l.uuid id ,l.name,p.uuid parentId,'Active' status ,0 version,0 geographicLevel,t.location_tag_id id, t.name as name from location l left join location p on p.location_id=l.parent_location left join location_tag_map tm on l.location_id=tm.location_id left join location_tag t on t.location_tag_id=tm.location_tag_id where l.retired=0 INTO OUTFILE '/var/lib/mysql-files/locations.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ',' LINES TERMINATED BY '\r\n'; |
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
{lb} "{h1}":"{f1}" , "type" :"Feature" , "properties": { "{h2}":"{f2}", "{h3}":"{(f3)==""?"null":f3}", "{h4}":"{f4}", "{h5}":{(f5)==""?"null":f5}, "{h6}":{(f6)==""?"null":f6} }, "locationTags":[ { "{h7}":"{f7}" , "{h8}":"{(f8)==""?"null":f8}" }] {rb} |
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
TODO add steps