REST: deleting (and purging) a complex obs

Hi all,

What’s the way to ensure that the complex data is purged when deleting a complex obs via REST?
In Angular, when doing

Obs.delete({
  uuid: "44b6cc5e-30..."
});

the obs is indeed voided but the purge methods are never invoked.

Not sure about angular here but in the delete request the param “purge” needs to be true. See the openmrs rest client wiki page https://wiki.openmrs.org/plugins/servlet/mobile#content/view/18514495 hope this link will work, am writing from my phone :slight_smile:

Hi @teleivo,

Thanks, I think you definitely pointed me to the right direction. Indeed the purge param had to be set to true for the purging routines to be triggered. Which, by the way, is simply done like this in Angular:

Obs.delete({
  uuid: "44b6cc5e-30...",
  purge: true
});

However if one calls the above on a complex obs, it will not be purged and this exception gets thrown:

public void purgeObs(Obs obs, boolean cascade) throws APIException {
  if (!purgeComplexData(obs)) {
    throw new APIException("Obs.error.unable.purge.complex.data", new Object[] { obs });
  }
  ...
}

Long story short it is the same issue as the one I encountered and detailed in ‘REST: Cannot update complex obs because complex data is null’, and it can be solved with a similar overload (of the purge method this time.)
The bottom line being that ObsResource does not check whether the obs may be complex. And therefore doesn’t trigger complex obs specific behaviour(s).