From 41d9abf6acf7772a17afb7aef8d9ed8d4a246d5a Mon Sep 17 00:00:00 2001 From: TynerGjs <132295567+TynerGjs@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:53:49 -0500 Subject: [PATCH] Resolve 5452-mdm-query-link-returns-scientific-notation-in-linkcreated-and-linkupdated (#5453) * set the scale to 0 when transforming double to BigDecimal * - set negative scale to 0 when transforming double to BigDecimal - added test --- .../java/ca/uhn/fhir/util/ParametersUtil.java | 11 +++++++++-- ...notation-in-linkCreated-and-linkUpdated.yaml | 5 +++++ .../ca/uhn/fhir/util/ParametersUtilR4Test.java | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5452-mdm-query-link-returns-scientific-notation-in-linkCreated-and-linkUpdated.yaml diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java index 44d26280759..c7ffd7cb439 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java @@ -403,8 +403,15 @@ public class ParametersUtil { public static void addPartDecimal(FhirContext theContext, IBase theParameter, String theName, Double theValue) { IPrimitiveType value = (IPrimitiveType) theContext.getElementDefinition("decimal").newInstance(); - value.setValue(theValue == null ? null : BigDecimal.valueOf(theValue)); - + if (theValue == null) { + value.setValue(null); + } else { + BigDecimal decimalValue = BigDecimal.valueOf(theValue); + if (decimalValue.scale() < 0) { + decimalValue = decimalValue.setScale(0); + } + value.setValue(decimalValue); + } addPart(theContext, theParameter, theName, value); } diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5452-mdm-query-link-returns-scientific-notation-in-linkCreated-and-linkUpdated.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5452-mdm-query-link-returns-scientific-notation-in-linkCreated-and-linkUpdated.yaml new file mode 100644 index 00000000000..9221fe51456 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/7_0_0/5452-mdm-query-link-returns-scientific-notation-in-linkCreated-and-linkUpdated.yaml @@ -0,0 +1,5 @@ +--- +type: fix +issue: 5452 +title: "Previously, the $mdm-query-link operation would return values of field linkCreated and linkUpdated in scientific +notation when the last digits are 0. This is now fixed and always returns in standard notation." diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ParametersUtilR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ParametersUtilR4Test.java index 7e03c8097e6..f8c90c4e453 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ParametersUtilR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/util/ParametersUtilR4Test.java @@ -9,6 +9,7 @@ import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.Test; +import java.math.BigDecimal; import java.util.List; import java.util.Optional; @@ -79,4 +80,20 @@ public class ParametersUtilR4Test { assertThat(values.get(1), is(TEST_PERSON_ID)); assertThat(values.get(2), is(TEST_PERSON_ID)); } + + @Test + public void testAddPartDecimalNoScientificNotation() { + // setup + Double decimalValue = Double.valueOf("10000000"); + IBaseParameters parameters = ParametersUtil.newInstance(ourFhirContext); + IBase resultPart = ParametersUtil.addParameterToParameters(ourFhirContext, parameters, "link"); + + // execute + ParametersUtil.addPartDecimal(ourFhirContext, resultPart, "linkCreated", decimalValue); + + // verify + String expected = BigDecimal.valueOf(decimalValue).toPlainString(); + List results = ParametersUtil.getNamedParameterPartAsString(ourFhirContext, parameters, "link", "linkCreated"); + assertEquals(expected, results.get(0)); + } }