Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when retrieving non-active(soft deleted) patient identifiers #304

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> patientIdentifiers;
if (context.getIncludeAll()) {
patientIdentifiers = new ArrayList<PatientIdentifier>(parent.getIdentifiers());
} else {
patientIdentifiers = parent.getActiveIdentifiers();
}
return new NeedsPaging<PatientIdentifier>(patientIdentifiers, 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,23 @@ 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());
final String reason = "none";
req.addParameter("reason", 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));

SimpleObject nextResult = deserialize(handle(newGetRequest(getURI(), new Parameter(
RestConstants.REQUEST_PROPERTY_FOR_INCLUDE_ALL, "false"))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't getAllCount() the one that has all, including the voided ones?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Get all returns only the active Identifiers

return service.getPatientByUuid(RestTestConstants1_8.PATIENT_UUID).getActiveIdentifiers().size();

That is why getAllCount() returns 1 after we void an identifier instead of two but REQUEST_PROPERTY_FOR_INCLUDE_ALL returns 2 including the voided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh i see! 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 😄 Is there any other thing I should do?

assertEquals(getAllCount(), Util.getResultsSize(nextResult));
}

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