From f038fbbf946adea395802854774dac30ea60b3e8 Mon Sep 17 00:00:00 2001 From: Tusha Date: Sun, 24 Sep 2023 23:38:32 +0300 Subject: [PATCH] RESTWS-716: Orders resource returns no results when only status is specified (#585) * RESTWS-716: Orders resource returns no results when only status is specified * RESTWS-716: Orders resource returns no results when only status is specified --- .../v1_0/resource/openmrs1_10/OrderResource1_10.java | 6 ++++-- .../openmrs1_10/OrderController1_10Test.java | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java index ac14bb135..6ce57c38d 100644 --- a/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java +++ b/omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/OrderResource1_10.java @@ -33,6 +33,7 @@ import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult; import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; +import org.openmrs.module.webservices.rest.web.response.InvalidSearchException; import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException; import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.response.ResponseException; @@ -273,9 +274,10 @@ protected PageableResult doSearch(RequestContext context) throws ResponseExcepti else { return new NeedsPaging(orders, context); } + } else { + throw new InvalidSearchException("Please provide patientUuid in the patient parameter"); } - - return new EmptySearchResult(); + } private static Date getUsableDate(Order order) { diff --git a/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderController1_10Test.java b/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderController1_10Test.java index 20708aeeb..323a4265c 100644 --- a/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderController1_10Test.java +++ b/omod-1.10/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_10/OrderController1_10Test.java @@ -26,6 +26,7 @@ import org.openmrs.module.webservices.rest.test.Util; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.RestTestConstants1_10; +import org.openmrs.module.webservices.rest.web.response.InvalidSearchException; import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException; import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest; @@ -361,7 +362,7 @@ public void shouldReviseAnActiveOrder() throws Exception { revisedOrder.add("orderer", "c2299800-cca9-11e0-9572-0800200c9a66"); revisedOrder.add("instructions", "To be taken after a meal"); revisedOrder.add("orderReasonNonCoded", "Changed instructions"); - + SimpleObject savedOrder = deserialize(handle(newPostRequest(getURI(), revisedOrder))); List newActiveOrders = orderService.getActiveOrders(patient, null, null, null); @@ -589,4 +590,12 @@ public void invalidCareCenterShouldThrowException() throws Exception { ); handle(req); } + + @Test(expected = InvalidSearchException.class) + public void doSearch_shouldReturnExceptionIfNoPatientUuidIsSpecified() throws Exception { + MockHttpServletRequest req = newGetRequest(getURI(), + new Parameter("status", "active") + ); + handle(req); + } }