Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openmrs/openmrs-module-webservice…
Browse files Browse the repository at this point in the history
…s.rest into RESTWS-920
  • Loading branch information
slubwama committed Jul 20, 2024
2 parents 949c59f + 57b2e5e commit 611ec39
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 26 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ jobs:
JAVA_VERSION: ${{ matrix.java-version }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
- name: Cache local Maven repository
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
Expand Down
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.44.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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-1.10</artifactId>
<packaging>jar</packaging>
Expand Down
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.44.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.44.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.44.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 @@ -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
2 changes: 1 addition & 1 deletion omod-1.9/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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-1.9</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void setValue_shouldReturnUuidForConceptTrue() throws Exception {
Obs obs = new Obs();
obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID));
ObsResource1_8.setValue(obs, trueConcept);
assertEquals(trueConcept, ObsResource1_8.getValue(obs));
assertEquals(trueConcept, new ObsResource1_8().getValue(obs));
}

@Test
Expand All @@ -232,15 +232,15 @@ public void setValue_shouldReturnDrug() throws Exception {
String drugUuid = "3cfcf118-931c-46f7-8ff6-7b876f0d4202";
Drug drug = Context.getConceptService().getDrugByUuid(drugUuid);
ObsResource1_8.setValue(obs, drugUuid);
assertEquals(drug, ObsResource1_8.getValue(obs));
assertEquals(drug, new ObsResource1_8().getValue(obs));
}

@Test
public void setValue_shouldReturnUuidForConceptFalse() throws Exception {
Obs obs = new Obs();
obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID));
ObsResource1_8.setValue(obs, falseConcept);
assertEquals(falseConcept, ObsResource1_8.getValue(obs));
assertEquals(falseConcept, new ObsResource1_8().getValue(obs));
}

@Test(expected = ConversionException.class)
Expand All @@ -255,15 +255,15 @@ public void setValue_shouldReturnUuidForPrimitiveTrue() throws Exception {
Obs obs = new Obs();
obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID));
ObsResource1_8.setValue(obs, true);
assertEquals(trueConcept, ObsResource1_8.getValue(obs));
assertEquals(trueConcept, new ObsResource1_8().getValue(obs));
}

@Test
public void setValue_shouldReturnUuidForPrimitiveFalse() throws Exception {
Obs obs = new Obs();
obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID));
ObsResource1_8.setValue(obs, false);
assertEquals(falseConcept, ObsResource1_8.getValue(obs));
assertEquals(falseConcept, new ObsResource1_8().getValue(obs));
}

private void clearAndSetValue(Obs obs, ObsType type, Object value) {
Expand All @@ -287,6 +287,6 @@ public void setConvertedProperties_shouldAllowAnyPropertyOrder() throws Exceptio
propertyMap.put("obsDatetime", "2013-12-09T00:00:00.000+0100");

resource.setConvertedProperties(obs, propertyMap, resource.getUpdatableProperties(), false);
org.springframework.util.Assert.isTrue(((Double) ObsResource1_8.getValue(obs)) == 10.0);
org.springframework.util.Assert.isTrue(((Double) new ObsResource1_8().getValue(obs)) == 10.0);
}
}
2 changes: 1 addition & 1 deletion omod-2.0/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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-2.0</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion omod-2.1/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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-2.1</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion omod-2.2/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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-2.2</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion omod-2.3/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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-2.3</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion omod-2.4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>webservices.rest</artifactId>
<groupId>org.openmrs.module</groupId>
<version>2.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion omod-common/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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod-common</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion omod/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.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
</parent>
<artifactId>webservices.rest-omod</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.openmrs.module</groupId>
<artifactId>webservices.rest</artifactId>
<version>2.44.0-SNAPSHOT</version>
<version>2.45.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Rest Web Services</name>
<description>Parent project for the Rest Web Services Module</description>
Expand Down

0 comments on commit 611ec39

Please sign in to comment.