Skip to content

Commit

Permalink
Merge branch 'openmrs:master' into RESTWS-908
Browse files Browse the repository at this point in the history
  • Loading branch information
suubi-joshua committed Jul 9, 2024
2 parents ebbc9a0 + ff78c3a commit 50c14e4
Show file tree
Hide file tree
Showing 48 changed files with 688 additions and 116 deletions.
2 changes: 1 addition & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<version>2.40.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-integration-tests</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion omod-1.10/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<version>2.40.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-1.10</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -273,9 +274,10 @@ protected PageableResult doSearch(RequestContext context) throws ResponseExcepti
else {
return new NeedsPaging<Order>(orders, context);
}
} else {
throw new InvalidSearchException("Please provide patientUuid in the patient parameter");
}

return new EmptySearchResult();

}

private static Date getUsableDate(Order order) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PersonResource1_8;

/**
Expand Down Expand Up @@ -46,12 +47,19 @@ public DelegatingResourceDescription getCreatableProperties() {
description.addProperty("birthtime");
return description;
}



/**
* @throws org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
*/
@Override
public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException {
DelegatingResourceDescription description = super.getUpdatableProperties();
description.addProperty("birthtime");
return description;
}
@Override
public Model getGETModel(Representation rep) {
return addNewProperties(super.getGETModel(rep), rep);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Order> newActiveOrders = orderService.getActiveOrders(patient, null, null, null);
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion omod-1.11/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<version>2.40.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-1.11</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.StringProperty;
import org.apache.commons.lang.BooleanUtils;
import org.openmrs.Concept;
import org.openmrs.ConceptNumeric;
import org.openmrs.Obs;
import org.openmrs.api.db.hibernate.HibernateUtil;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.PropertySetter;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
Expand Down Expand Up @@ -92,4 +96,22 @@ public static void setFormFieldNamespace(Obs obs, Object namespace) {
public String getResourceVersion() {
return RestConstants1_11.RESOURCE_VERSION;
}

/**
* @return a Double if the ConceptNumeric is configured as allowDecimal, but an Integer otherwise
* This changes the implementation from the pre-1.11 field named precise.
*/
protected Number getValueNumeric(Obs obs) {
if (obs.getValueNumeric() == null) {
return null;
}
Concept concept = HibernateUtil.getRealObjectFromProxy(obs.getConcept());
if (concept instanceof ConceptNumeric) {
ConceptNumeric conceptNumeric = (ConceptNumeric) concept;
if (BooleanUtils.isFalse(conceptNumeric.getAllowDecimal())) {
return obs.getValueNumeric().intValue();
}
}
return obs.getValueNumeric();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_11;

import org.junit.Assert;
import org.junit.Test;
import org.openmrs.ConceptNumeric;
import org.openmrs.Obs;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.module.webservices.rest.web.RestTestConstants1_8;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest;

public class ObsResource1_11Test extends BaseDelegatingResourceTest<ObsResource1_11, Obs> {
Expand Down Expand Up @@ -44,4 +49,22 @@ public String getDisplayProperty() {
public String getUuidProperty() {
return RestTestConstants1_8.OBS_UUID;
}

@Test
public void asRepresentation_shouldReturnNumericValueBasedOnConceptNumericAllowDecimal() {
Obs obs = getObject();
obs.setValueNumeric(20.0);
ConceptNumeric cn = Context.getConceptService().getConceptNumeric(5497);
obs.setConcept(cn);
cn.setAllowDecimal(true);
SimpleObject rep = getResource().asRepresentation(getObject(), Representation.DEFAULT);
Object value = rep.get("value");
Assert.assertEquals(20.0, value);
Assert.assertEquals(Double.class, value.getClass());
cn.setAllowDecimal(false);
rep = getResource().asRepresentation(getObject(), Representation.DEFAULT);
value = rep.get("value");
Assert.assertEquals(20, value);
Assert.assertEquals(Integer.class, value.getClass());
}
}
2 changes: 1 addition & 1 deletion omod-1.12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<version>2.40.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-1.12</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion omod-1.8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<version>2.40.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-1.8</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import io.swagger.models.properties.IntegerProperty;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import org.openmrs.EncounterType;
import org.openmrs.Field;
import org.openmrs.Form;
import org.openmrs.FormField;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.rest.web.RestConstants;
Expand Down Expand Up @@ -194,7 +197,11 @@ protected NeedsPaging<Form> doGetAll(RequestContext context) throws ResponseExce
*/
@Override
protected NeedsPaging<Form> doSearch(RequestContext context) {
return new NeedsPaging<Form>(Context.getFormService().getForms(context.getParameter("q"), false), context);
String fuzzyName = context.getParameter("q");
boolean includeRetired = context.getIncludeAll();

return new NeedsPaging<Form>(Context.getFormService().getForms(fuzzyName, null, null,
includeRetired, null, null, null), context);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8;

import java.util.Arrays;
import java.util.List;

import io.swagger.models.Model;
Expand Down Expand Up @@ -267,7 +268,7 @@ protected PageableResult doSearch(RequestContext context) {

if (tagUuid != null) {
LocationTag locationTag = locationService.getLocationTagByUuid(tagUuid);
locationsByTag = locationService.getLocationsByTag(locationTag);
locationsByTag = locationService.getLocationsHavingAllTags(Arrays.asList(locationTag));
}

if (query != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Object create(SimpleObject post, RequestContext context) throws ResponseE
throw new IllegalRequestException("Cannot execute action " + action.getAction() + " on empty set of modules.");
} else {
if (action.getAction() == Action.INSTALL) {
if (installUri == null || !ResourceUtils.isUrl(installUri)) {
if (!ResourceUtils.isUrl(installUri)) {
throw new IllegalRequestException("The installUri needs to be a URL for this action to be performed");
}
}
Expand Down Expand Up @@ -171,11 +171,7 @@ private Module installModule(Collection<Module> modules, String installUri, Serv
}
catch (MalformedURLException e) {
throw new APIException(e.getMessage(), e);
}
catch (IOException e) {
throw new APIException(e.getMessage(), e);
}
finally {
} finally {
if (tempModule == null && moduleFile != null) {
FileUtils.deleteQuietly(moduleFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public class ModuleResource1_8 extends BaseDelegatingReadableResource<Module> im

private ModuleFactoryWrapper moduleFactoryWrapper = new ModuleFactoryWrapper();

private String moduleActionLink = ModuleActionResource1_8.class.getAnnotation(Resource.class).name();
private final String moduleActionLink = ModuleActionResource1_8.class.getAnnotation(Resource.class).name();

public void setModuleFactoryWrapper(ModuleFactoryWrapper moduleFactoryWrapper) {
this.moduleFactoryWrapper = moduleFactoryWrapper;
}

@Override
public Module getByUniqueId(String uniqueId) {
moduleFactoryWrapper.checkPrivilege();
moduleFactoryWrapper.checkReadonlyPrivilege();
return moduleFactoryWrapper.getModuleById(uniqueId);
}

Expand Down Expand Up @@ -136,11 +136,11 @@ public Model getGETModel(Representation rep) {
}

/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext)
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingReadableResource#doGetAll(RequestContext)
*/
@Override
public NeedsPaging<Module> doGetAll(RequestContext context) throws ResponseException {
moduleFactoryWrapper.checkPrivilege();
moduleFactoryWrapper.checkReadonlyPrivilege();
return new NeedsPaging<Module>(new ArrayList<Module>(moduleFactoryWrapper.getLoadedModules()), context);
}

Expand Down Expand Up @@ -185,7 +185,7 @@ public Object upload(MultipartFile file, RequestContext context) throws Response
module = moduleFactoryWrapper.loadModule(moduleFile);
moduleFactoryWrapper.startModule(module, servletContext);

if (existingModule != null && dependentModulesStopped.size() > 0
if (existingModule != null && !dependentModulesStopped.isEmpty()
&& moduleFactoryWrapper.isModuleStarted(module)) {
startModules(dependentModulesStopped, existingModule, servletContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public String getDisplayString(Obs obs) {
* @return
*/
@PropertyGetter("value")
public static Object getValue(Obs obs) throws ConversionException {
public Object getValue(Obs obs) throws ConversionException {
if (obs.isComplex()) {
//Note that complex obs value is handled by ObsComplexValueController1_8
SimpleObject so = new SimpleObject();
Expand Down Expand Up @@ -322,13 +322,20 @@ public static Object getValue(Obs obs) throws ConversionException {
}

}

if (obs.getValueNumeric() != null) {
return obs.getValueNumeric();
return getValueNumeric(obs);
}

return null;
}

/**
* @return the valueNumeric from the obs
*/
protected Number getValueNumeric(Obs obs) {
return obs.getValueNumeric();
}

/**
* Sets the members of an obs group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
description.addProperty("display");
description.addProperty("uuid");
description.addProperty("value");
description.addProperty("attributeType", Representation.REF);
description.addProperty("attributeType", Representation.FULL);
description.addProperty("voided");
description.addProperty("auditInfo");
description.addProperty("hydratedObject");
Expand Down Expand Up @@ -284,17 +284,18 @@ public void purge(PersonAttribute delegate, RequestContext context) throws Respo
* Gets the display string for a person attribute.
*
* @param pa the person attribute.
* @return attribute type + value (for concise display purposes)
* @return value (for concise display purposes)
*/
@PropertyGetter("display")
public String getDisplayString(PersonAttribute pa) {
if (pa.getAttributeType() == null)
return "";
if (Concept.class.getName().equals(pa.getAttributeType().getFormat()) && pa.getValue() != null) {
Concept concept = Context.getConceptService().getConcept(pa.getValue());
return concept == null ? null : concept.getDisplayString();
// a PersonAttribute without a type cannot really be converted
if (pa.getAttributeType() == null) {
return pa.getValue() != null ? pa.getValue() : "";
}
return pa.getAttributeType().getName() + " = " + pa.getValue();

// PersonAttribute#toString() calls PersonAttribute#hydrateObject() and Attributable#getDisplayString()
String value = pa.toString();
return value == null ? "" : value;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.openmrs.module.webservices.rest.web.v1_0.search.openmrs1_8;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -64,7 +65,7 @@ public PageableResult search(RequestContext context) throws ResponseException {
}

if (locationTag != null) {
locations = Context.getLocationService().getLocationsByTag(locationTag);
locations = Context.getLocationService().getLocationsHavingAllTags(Arrays.asList(locationTag));
}
}
finally {
Expand Down
Loading

0 comments on commit 50c14e4

Please sign in to comment.