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
This commit is contained in:
TynerGjs 2023-11-14 16:53:49 -05:00 committed by GitHub
parent 9dace159b4
commit 41d9abf6ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View File

@ -403,8 +403,15 @@ public class ParametersUtil {
public static void addPartDecimal(FhirContext theContext, IBase theParameter, String theName, Double theValue) {
IPrimitiveType<BigDecimal> value = (IPrimitiveType<BigDecimal>)
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);
}

View File

@ -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."

View File

@ -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<String> results = ParametersUtil.getNamedParameterPartAsString(ourFhirContext, parameters, "link", "linkCreated");
assertEquals(expected, results.get(0));
}
}