From 52cfa64827fe825d77451d198ec6a4038c960e47 Mon Sep 17 00:00:00 2001 From: andela_cuchendu Date: Wed, 27 Sep 2017 12:48:13 +0100 Subject: [PATCH] Bug when retrieving non-active(soft deleted) patient identifiers --- .../openmrs1_8/PatientIdentifierResource1_8.java | 10 +++++++++- .../PatientIdentifierController1_9Test.java | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java index 9886a15e7a..fadd6a6c03 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientIdentifierResource1_8.java @@ -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 @@ -248,7 +250,13 @@ public void purge(PatientIdentifier delegate, RequestContext context) throws Res */ @Override public NeedsPaging doGetAll(Patient parent, RequestContext context) throws ResponseException { - return new NeedsPaging(parent.getActiveIdentifiers(), context); + List newPatientIdentifier; + if (context.getIncludeAll()) { + newPatientIdentifier = new ArrayList(parent.getIdentifiers()); + } else { + newPatientIdentifier = parent.getActiveIdentifiers(); + } + return new NeedsPaging(newPatientIdentifier, context); } /** diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/PatientIdentifierController1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/PatientIdentifierController1_9Test.java index 6312609e82..3b7e6e9d0f 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/PatientIdentifierController1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/PatientIdentifierController1_9Test.java @@ -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; @@ -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();