Here at PIH, we are working on a task to migrate patients from one instance of OpenMRS to another instance. We thought we would use the REST API to export the patient record to a JSON file and then import the JSON file on the destination system and create patient with demographics and encounters and visits via REST API.
It looks like the REST API does not support creating resources with a given UUID. Example: If I try to POST the following json to http://localhost:8080/openmrs/ws/rest/v1/encounter
{
"uuid": "49F44F03-C16B-4562-8DDC-89D20093918B",
"patient": {
"uuid": "5861aeea-c6d3-44f5-b016-07e78b4d1c3f"
},
"location": {
"uuid": "23e7bb0d-51f9-4d5f-b34b-2fbbfeea1960"
},
"encounterType": {
"uuid": "a8584ab8-cc2a-11e5-9956-625662870761"
},
"encounterDatetime": "2017-05-09T08:44:50.000-0400"
}
I get the following error:
{
"error": {
"message": "[Some properties are not allowed to be set: uuid]",
"code": "org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource:625"
}
}
because Encounter.UUID is not on the list of the CreatableProperties.
Hovewer, I could create a visit with the Encounter above and the created encounter would have the UUID that i specified in the JSON: POST http://localhost:8080/openmrs/ws/rest/v1/visit
{
"patient": {
"uuid": "5861aeea-c6d3-44f5-b016-07e78b4d1c3f"
},
"startDatetime": "2017-05-09T08:44:50.000-0400",
"stopDatetime": "2017-05-10T08:44:50.000-0400",
"location": {
"uuid": "d6dafa1a-9a2f-4f61-a33e-410acb64b0e9"
},
"visitType": {
"uuid": "f01c54cb-2225-471a-9cd5-d348552c337c"
},
"encounters": [
{
"uuid": "49F44F03-C16B-4562-8DDC-89D20093918B",
"patient": {
"uuid": "5861aeea-c6d3-44f5-b016-07e78b4d1c3f"
},
"location": {
"uuid": "23e7bb0d-51f9-4d5f-b34b-2fbbfeea1960"
},
"encounterType": {
"uuid": "a8584ab8-cc2a-11e5-9956-625662870761"
},
"encounterDatetime": "2017-05-09T08:44:50.000-0400"
}
]
}
Peeking through the code it seems that it is by design that you cannot create objects via REST with a specified UUID? But, it is possible to create objects with specified UUIDs if they are children of another object. Is this correct? Is there a better way to create objects via REST with specified UUID?
Any other suggestions on how to migrate data from one OpenMRS system to another and persisting the UUID of the original objects?
Thanks!