Search in sources :

Example 51 with DecimalType

use of org.hl7.fhir.dstu2.model.DecimalType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcPower.

private List<Base> funcPower(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
    if (focus.size() != 1) {
        throw makeException(expr, I18nConstants.FHIRPATH_FOCUS_PLURAL, "power", focus.size());
    }
    Base base = focus.get(0);
    List<Base> result = new ArrayList<Base>();
    if (base.hasType("integer", "decimal", "unsignedInt", "positiveInt")) {
        List<Base> n1 = execute(context, focus, expr.getParameters().get(0), true);
        if (n1.size() != 1) {
            throw makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "power", "0", "Multiple Values", "integer or decimal");
        }
        Double e = Double.parseDouble(n1.get(0).primitiveValue());
        Double d = Double.parseDouble(base.primitiveValue());
        try {
            result.add(new DecimalType(Math.pow(d, e)));
        } catch (Exception ex) {
        // just return nothing
        }
    } else {
        makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "power", "(focus)", base.fhirType(), "integer or decimal");
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DecimalType(org.hl7.fhir.r4b.model.DecimalType) Base(org.hl7.fhir.r4b.model.Base) UcumException(org.fhir.ucum.UcumException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) FHIRLexerException(org.hl7.fhir.r4b.utils.FHIRLexer.FHIRLexerException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 52 with DecimalType

use of org.hl7.fhir.dstu2.model.DecimalType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcLog.

private List<Base> funcLog(ExecutionContext context, List<Base> focus, ExpressionNode expr) {
    if (focus.size() != 1) {
        throw makeException(expr, I18nConstants.FHIRPATH_FOCUS_PLURAL, "log", focus.size());
    }
    Base base = focus.get(0);
    List<Base> result = new ArrayList<Base>();
    if (base.hasType("integer", "decimal", "unsignedInt", "positiveInt")) {
        List<Base> n1 = execute(context, focus, expr.getParameters().get(0), true);
        if (n1.size() != 1) {
            throw makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "log", "0", "Multiple Values", "integer or decimal");
        }
        Double e = Double.parseDouble(n1.get(0).primitiveValue());
        Double d = Double.parseDouble(base.primitiveValue());
        try {
            result.add(new DecimalType(customLog(e, d)));
        } catch (Exception ex) {
        // just return nothing
        }
    } else {
        makeException(expr, I18nConstants.FHIRPATH_WRONG_PARAM_TYPE, "log", "(focus)", base.fhirType(), "integer or decimal");
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DecimalType(org.hl7.fhir.r4b.model.DecimalType) Base(org.hl7.fhir.r4b.model.Base) UcumException(org.fhir.ucum.UcumException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) FHIRLexerException(org.hl7.fhir.r4b.utils.FHIRLexer.FHIRLexerException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 53 with DecimalType

use of org.hl7.fhir.dstu2.model.DecimalType in project org.hl7.fhir.core by hapifhir.

the class DecimalTypeNullTest method equalsShallow.

@Test
@DisplayName("Test null value equalsShallow()")
void equalsShallow() {
    DecimalType nullDecimal = new DecimalType();
    DecimalType validDecimal = new DecimalType("3.14");
    Assertions.assertFalse(nullDecimal.equalsShallow(validDecimal));
}
Also used : DecimalType(org.hl7.fhir.r4b.model.DecimalType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 54 with DecimalType

use of org.hl7.fhir.dstu2.model.DecimalType in project org.hl7.fhir.core by hapifhir.

the class DecimalTypeNullTest method testToString.

@Test
@DisplayName("Test null value toString()")
void testToString() {
    DecimalType nullDecimal = new DecimalType();
    System.out.println("Value -> " + nullDecimal);
}
Also used : DecimalType(org.hl7.fhir.r4b.model.DecimalType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 55 with DecimalType

use of org.hl7.fhir.dstu2.model.DecimalType in project org.hl7.fhir.core by hapifhir.

the class DecimalTypeNullTest method typedCopy.

@Test
@DisplayName("Test null value typedCopy()")
void typedCopy() {
    DecimalType nullDecimal = new DecimalType();
    DecimalType copyDecimal = (DecimalType) nullDecimal.typedCopy();
    Assertions.assertNull(copyDecimal.getValue());
}
Also used : DecimalType(org.hl7.fhir.r4b.model.DecimalType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

DecimalType (org.hl7.fhir.r4.model.DecimalType)48 Test (org.junit.jupiter.api.Test)47 Coding (org.hl7.fhir.r4.model.Coding)44 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)42 Money (org.hl7.fhir.r4.model.Money)41 BigDecimal (java.math.BigDecimal)40 ArrayList (java.util.ArrayList)38 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)36 BenefitComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.BenefitComponent)31 UcumException (org.fhir.ucum.UcumException)29 DecimalType (org.hl7.fhir.r4b.model.DecimalType)22 DecimalType (org.hl7.fhir.r5.model.DecimalType)20 FHIRException (org.hl7.fhir.exceptions.FHIRException)19 Decimal (org.fhir.ucum.Decimal)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)14 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 Pair (org.fhir.ucum.Pair)12 Base (org.hl7.fhir.r4b.model.Base)12 Base (org.hl7.fhir.r5.model.Base)12 AdjudicationComponent (org.hl7.fhir.r4.model.ExplanationOfBenefit.AdjudicationComponent)8