How to delete all subresources in webservices.rest

Reference Application: 2.4:

Question: How do I implement DELETE /patient/{patient_uuid}/allergy/ to delete all allergies for a patient. I can implement DELETE /patient/{patient_uuid}/allergy/{allergy_uuid} to delete a single allergy no problem.

It seems webservices.rest does not support the delete all requirement.

Any ideas

Did you try the solution proposed here?

This was discussed on the talk topic that Lluis mentioned and he proposed to override public void delete(String parentUniqueId, String uuid, String reason, RequestContext context) and if uuid is null delete all allergies

@wyclf: I tried that but got an error DELETE not supported when I run my tests: here is the pull request: https://github.com/openmrs/openmrs-module-webservices.rest/pull/183 problem tests are ignored in this pull reqest

Can you trace where the DELETE not supported is thrown? I guess you will need to hack a bit more.

I commented on the pull request, could be because you’re not adding the ‘purge’ request parameter like here.

I’m not sure I’m reading this correctly, but we should not have a “bulk purge” operation to hard-delete >1 allergy at a time.

The discussion Questions about resources in Allergy UI module mentions this in the summary.

I also think it is a bad idea to allow bulk deletes of allergies.

I agree. Purge is a permanent deletion (erase from database) and we probably shouldn’t provide a bulk method for this.

I don’t see the word “purge” anywhere in that thread.

Anyway, to be clear:

  • doing DELETE .../patient/{uuid}/allergy should void all of the patient’s allergies (and set them back to the unknown status.
  • DELETE .../patient/{uuid}/allergy?purge=true should fail with a 4xx status (or, alternately, it should just not be recognized as anything different from DELETE without the parameter.

And, per my comment on the commit, I’m not sure what purging has to do with any of this. (Because the test method wyclif commented on is about voiding, not purging.)

@darius, and @Wyclif, I have a pull request for review. It solves the DELETE all subresource problem It is a bit untidy (WIP) with some comments remaining however I want the approach evaluated as I may have to do the same to support the PUT requirement. pull request: https://github.com/openmrs/openmrs-module-webservices.rest/pull/183

@jdegraft I made a bunch of comments on the PR before I ran out of steam.

One big question I have is why you’re saying that we can’t get allergies by UUID?

@darius, new pull request: https://github.com/openmrs/openmrs-module-webservices.rest/pull/185

MainSubResourceController.java is a major change, having difficulty with git, but changes are at the end of the file, from line 168 onwards.

some changes are some problem to do with the git pull: ConversionUtil,java, ConversionUtilTest.java & SwaggerSpecificationController.java. I did not change these files.

some changes are going into openmrs-core to support this pull request including adding UUID support to allergy.