diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5cd382ca2..b383af10b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -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') }} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 320aabbcd..addba8f33 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-integration-tests jar diff --git a/omod-1.10/pom.xml b/omod-1.10/pom.xml index 8f1f99fce..1f5124358 100644 --- a/omod-1.10/pom.xml +++ b/omod-1.10/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-1.10 jar diff --git a/omod-1.11/pom.xml b/omod-1.11/pom.xml index dddcb3843..1e7e8c04f 100644 --- a/omod-1.11/pom.xml +++ b/omod-1.11/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-1.11 jar diff --git a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java index c5dca8ed0..14626f497 100644 --- a/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java +++ b/omod-1.11/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11.java @@ -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; @@ -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(); + } } diff --git a/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java b/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java index 9d525cbdf..3be6db0ea 100644 --- a/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java +++ b/omod-1.11/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_11/ObsResource1_11Test.java @@ -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 { @@ -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()); + } } diff --git a/omod-1.12/pom.xml b/omod-1.12/pom.xml index fb6670c2c..8fe7929b2 100644 --- a/omod-1.12/pom.xml +++ b/omod-1.12/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-1.12 jar diff --git a/omod-1.8/pom.xml b/omod-1.8/pom.xml index cdad25989..5ee535590 100644 --- a/omod-1.8/pom.xml +++ b/omod-1.8/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-1.8 jar diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java index 1ed900c8b..00a5900e1 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/ObsResource1_8.java @@ -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(); @@ -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 diff --git a/omod-1.9/pom.xml b/omod-1.9/pom.xml index 1af38f67f..198d8fc91 100644 --- a/omod-1.9/pom.xml +++ b/omod-1.9/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-1.9 jar diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java index f4e637738..ec560b4ce 100644 --- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java +++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ObsResource1_9Test.java @@ -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 @@ -232,7 +232,7 @@ 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 @@ -240,7 +240,7 @@ 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) @@ -255,7 +255,7 @@ 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 @@ -263,7 +263,7 @@ 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) { @@ -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); } } diff --git a/omod-2.0/pom.xml b/omod-2.0/pom.xml index 1dbc19f7c..510c47f7a 100644 --- a/omod-2.0/pom.xml +++ b/omod-2.0/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-2.0 jar diff --git a/omod-2.1/pom.xml b/omod-2.1/pom.xml index 38f2110ce..ab7fccf71 100644 --- a/omod-2.1/pom.xml +++ b/omod-2.1/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-2.1 jar diff --git a/omod-2.2/pom.xml b/omod-2.2/pom.xml index 729e37a60..3ede534b6 100644 --- a/omod-2.2/pom.xml +++ b/omod-2.2/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-2.2 jar diff --git a/omod-2.3/pom.xml b/omod-2.3/pom.xml index 3f0d67476..03b416069 100644 --- a/omod-2.3/pom.xml +++ b/omod-2.3/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-2.3 jar diff --git a/omod-2.4/pom.xml b/omod-2.4/pom.xml index 78a239735..959fbf09e 100644 --- a/omod-2.4/pom.xml +++ b/omod-2.4/pom.xml @@ -3,7 +3,7 @@ webservices.rest org.openmrs.module - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT 4.0.0 diff --git a/omod-common/pom.xml b/omod-common/pom.xml index 0b135e521..6ae78c967 100644 --- a/omod-common/pom.xml +++ b/omod-common/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod-common jar diff --git a/omod/pom.xml b/omod/pom.xml index ce479593e..e2a42d1bc 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT webservices.rest-omod jar diff --git a/pom.xml b/pom.xml index 6506e0ff2..cd1c9c437 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.openmrs.module webservices.rest - 2.44.0-SNAPSHOT + 2.45.0-SNAPSHOT pom Rest Web Services Parent project for the Rest Web Services Module