Inserting 'void_reason' while deleting patient using REST

I’m working on RA-1089 which requires me to create a way to delete(essentially void) a patient from the ref app. I’ve been quite successful in the implementation, except for the fact that I can’t pass in the parameter to the ‘void_reason’.

Here is the JS code. I am creating an AJAX in jQuery to make the REST call:

jq.ajax({
    url: '/openmrs/ws/rest/v1/patient/'+delPatient.patientUUID,
    type: 'DELETE',
    body: {
        "void_reason": deleteReason //Already obtained input from user
    },
    success: function() {
        emr.successMessage('coreapps.task.deletePatient.deletePatientSuccessful');
        jq('#delete-patient-creation-dialog' + ' .icon-spin').css('display', 'inline-block').parent().addClass('disabled');
        delPatient.deletePatientCreationDialog.close();
        jq(setTimeout(delPatient.goToReturnUrl, 1285)); //Allow the success message to display before redirecting to another page
    },
    error: function() {
        emr.errorMessage("coreapps.task.deletePatient.deletePatientUnsuccessful");
        delPatient.deletePatientCreationDialog.close();
    }
});

Now, when I make a GET request for the same patient through REST, I don’t see void_reason inserted. All I see is ‘web application request’ or something. How do I resolve this issue?

I’m making the call from the coreapps module. Here is the PR

@darius, @dkayiwa, @pascal Looking forward to some guidance

What reason do you see at this point in the code?

Not sure what you mean at ‘this point’. I noted the uuid of the patient, deleted him, and then sent a GET request to http://localhost:8080/openmrs/ws/rest/v1/patient/d3adeed6-42b1-4228-ab79-2cc1c74ebc5a?v=full where the voidReason is listed as web service call.

I meant put a breakpoint in the code at the line I linked to and make sure your reason is correctly received.

Are you sure the patient you are trying to void is not already voided, since I can see from the code that we’ll bail out early if they are (and therefore not set the void reason).

Based on what I’m seeing here, the reason needs to be a request parameter, so you need to do something like:

curl -u admin:Admin123 \
     -X DELETE \
     http://example.com/openmrs/ws/rest/v1/patient/uuid?reason=ThisWillBeTheReason
2 Likes

Thanks! That gave me the idea alright. I did

url: '/openmrs/ws/rest/v1/patient/uuid?reason=ThisIsTheReason

and it works just fine :smiley:

To avoid future errors, should this code be encapsulated in the JS API ? Something like:

function deletePatient(patientId, reason, success, error)  {
  // ...
}

I think it should. I’ve got the following ticket open to make it happen:

1 Like