Skip to content

Commit

Permalink
Bug when retrieving non-active(soft deleted) patient identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
chibujax committed Sep 27, 2017
1 parent bba5380 commit 52cfa64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource;
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import java.util.List;
import java.util.ArrayList;

/**
* Sub-resource for patient identifiers
Expand Down Expand Up @@ -248,7 +250,13 @@ public void purge(PatientIdentifier delegate, RequestContext context) throws Res
*/
@Override
public NeedsPaging<PatientIdentifier> doGetAll(Patient parent, RequestContext context) throws ResponseException {
return new NeedsPaging<PatientIdentifier>(parent.getActiveIdentifiers(), context);
List<PatientIdentifier> newPatientIdentifier;
if (context.getIncludeAll()) {
newPatientIdentifier = new ArrayList<PatientIdentifier>(parent.getIdentifiers());
} else {
newPatientIdentifier = parent.getActiveIdentifiers();
}
return new NeedsPaging<PatientIdentifier>(newPatientIdentifier, context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotEquals;

import org.apache.commons.beanutils.PropertyUtils;
import org.codehaus.jackson.map.ObjectMapper;
Expand Down Expand Up @@ -124,6 +125,20 @@ public void shouldVoidAPatientIdentifier() throws Exception {
assertEquals(reason, service.getPatientIdentifierByUuid(getUuid()).getVoidReason());
}

@Test
public void shouldListAllPatientIdentifiersWithVoidedIdentifiersForAPatient() throws Exception {
assertEquals(false, service.getPatientIdentifierByUuid(getUuid()).isVoided());
MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + getUuid());
req.addParameter("!purge", "");
final String reason = "none";
req.addParameter("testing voided", reason);
handle(req);
assertEquals(true, service.getPatientIdentifierByUuid(getUuid()).isVoided());
SimpleObject result = deserialize(handle(newGetRequest(getURI(), new Parameter(
RestConstants.REQUEST_PROPERTY_FOR_INCLUDE_ALL, "true"))));
assertNotEquals(getAllCount(), Util.getResultsSize(result));
}

@Test
public void shouldPurgeAPatientIdentifier() throws Exception {
long initialIdCount = getAllCount();
Expand Down

0 comments on commit 52cfa64

Please sign in to comment.