Search in sources :

Example 81 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilitiesTests method testMaxValueChange.

/**
 * Change max value
 */
@Test
void testMaxValueChange() {
    // Given
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Appointment").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType(base.getType());
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    ElementDefinition id = focus.getDifferential().addElement();
    id.setPath("Appointment.minutesDuration");
    id.setMaxValue(new IntegerType(1));
    List<ValidationMessage> messages = new ArrayList<>();
    // When
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test");
    // Then
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        if (ok) {
            ElementDefinition b = base.getSnapshot().getElement().get(i);
            ElementDefinition f = focus.getSnapshot().getElement().get(i);
            b.setRequirements(null);
            f.setRequirements(null);
            for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                c.setSource(null);
            }
            for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                c.setSource(null);
            }
            if (!f.hasBase() || !b.getPath().equals(f.getPath())) {
                ok = false;
            } else {
                if (f.getPath().equals("Appointment.minutesDuration")) {
                    ok = f.getMaxValue() instanceof IntegerType && ((IntegerType) f.getMaxValue()).getValue() == 1;
                    if (ok) {
                        // Can't set maxValue to null so change base maxValue to IntegerType(1)
                        b.setMaxValue(new IntegerType(1));
                    }
                }
                if (!Base.compareDeep(b, f, true)) {
                    ok = false;
                }
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : IntegerType(org.hl7.fhir.r4b.model.IntegerType) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 82 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class IntegerTypeNullTest method testToString.

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

Example 83 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method buildFixedExpression.

private void buildFixedExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
    DataType fixed = criteriaElement.getFixed();
    if (fixed instanceof CodeableConcept) {
        CodeableConcept cc = (CodeableConcept) fixed;
        expression.append(" and ");
        buildCodeableConceptExpression(ed, expression, discriminator, cc);
    } else if (fixed instanceof Identifier) {
        Identifier ii = (Identifier) fixed;
        expression.append(" and ");
        buildIdentifierExpression(ed, expression, discriminator, ii);
    } else if (fixed instanceof Coding) {
        Coding c = (Coding) fixed;
        expression.append(" and ");
        buildCodingExpression(ed, expression, discriminator, c);
    } else {
        expression.append(" and (");
        if (fixed instanceof StringType) {
            Gson gson = new Gson();
            String json = gson.toJson((StringType) fixed);
            String escapedString = json.substring(json.indexOf(":") + 2);
            escapedString = escapedString.substring(0, escapedString.indexOf(",\"myStringValue") - 1);
            expression.append("'" + escapedString + "'");
        } else if (fixed instanceof UriType) {
            expression.append("'" + ((UriType) fixed).asStringValue() + "'");
        } else if (fixed instanceof IntegerType) {
            expression.append(((IntegerType) fixed).asStringValue());
        } else if (fixed instanceof DecimalType) {
            expression.append(((IntegerType) fixed).asStringValue());
        } else if (fixed instanceof BooleanType) {
            expression.append(((BooleanType) fixed).asStringValue());
        } else
            throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_VALUE_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), fixed.getClass().getName()));
        expression.append(" in " + discriminator + ")");
    }
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) Identifier(org.hl7.fhir.r5.model.Identifier) Coding(org.hl7.fhir.r5.model.Coding) StringType(org.hl7.fhir.r5.model.StringType) BooleanType(org.hl7.fhir.r5.model.BooleanType) DataType(org.hl7.fhir.r5.model.DataType) Gson(com.google.gson.Gson) DecimalType(org.hl7.fhir.r5.model.DecimalType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) UriType(org.hl7.fhir.r5.model.UriType)

Example 84 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method buildPattternExpression.

private void buildPattternExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
    DataType pattern = criteriaElement.getPattern();
    if (pattern instanceof CodeableConcept) {
        CodeableConcept cc = (CodeableConcept) pattern;
        expression.append(" and ");
        buildCodeableConceptExpression(ed, expression, discriminator, cc);
    } else if (pattern instanceof Coding) {
        Coding c = (Coding) pattern;
        expression.append(" and ");
        buildCodingExpression(ed, expression, discriminator, c);
    } else if (pattern instanceof BooleanType || pattern instanceof IntegerType || pattern instanceof DecimalType) {
        expression.append(" and ");
        buildPrimitiveExpression(ed, expression, discriminator, pattern, false);
    } else if (pattern instanceof PrimitiveType) {
        expression.append(" and ");
        buildPrimitiveExpression(ed, expression, discriminator, pattern, true);
    } else if (pattern instanceof Identifier) {
        Identifier ii = (Identifier) pattern;
        expression.append(" and ");
        buildIdentifierExpression(ed, expression, discriminator, ii);
    } else if (pattern instanceof HumanName) {
        HumanName name = (HumanName) pattern;
        expression.append(" and ");
        buildHumanNameExpression(ed, expression, discriminator, name);
    } else if (pattern instanceof Address) {
        Address add = (Address) pattern;
        expression.append(" and ");
        buildAddressExpression(ed, expression, discriminator, add);
    } else {
        throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_PATTERN_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), pattern.fhirType()));
    }
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) HumanName(org.hl7.fhir.r5.model.HumanName) Identifier(org.hl7.fhir.r5.model.Identifier) Address(org.hl7.fhir.r5.model.Address) Coding(org.hl7.fhir.r5.model.Coding) BooleanType(org.hl7.fhir.r5.model.BooleanType) DataType(org.hl7.fhir.r5.model.DataType) DecimalType(org.hl7.fhir.r5.model.DecimalType) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept)

Example 85 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opMinus.

private List<Base> opMinus(List<Base> left, List<Base> right) throws PathEngineException {
    if (left.size() == 0)
        throw new PathEngineException("Error performing -: left operand has no value");
    if (left.size() > 1)
        throw new PathEngineException("Error performing -: left operand has more than one value");
    if (!left.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType()));
    if (right.size() == 0)
        throw new PathEngineException("Error performing -: right operand has no value");
    if (right.size() > 1)
        throw new PathEngineException("Error performing -: right operand has more than one value");
    if (!right.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing -: right operand has the wrong type (%s)", right.get(0).fhirType()));
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType("integer") && r.hasType("integer"))
        result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) - Integer.parseInt(r.primitiveValue())));
    else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer"))
        result.add(new DecimalType(new BigDecimal(l.primitiveValue()).subtract(new BigDecimal(r.primitiveValue()))));
    else
        throw new PathEngineException(String.format("Error performing -: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()));
    return result;
}
Also used : IntegerType(org.hl7.fhir.dstu2.model.IntegerType) ArrayList(java.util.ArrayList) DecimalType(org.hl7.fhir.dstu2.model.DecimalType) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Base(org.hl7.fhir.dstu2.model.Base) BigDecimal(java.math.BigDecimal)

Aggregations

ArrayList (java.util.ArrayList)51 BigDecimal (java.math.BigDecimal)34 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)28 IntegerType (org.hl7.fhir.r5.model.IntegerType)26 IntegerType (org.hl7.fhir.r4.model.IntegerType)23 IntegerType (org.hl7.fhir.r4b.model.IntegerType)23 UcumException (org.fhir.ucum.UcumException)19 Test (org.junit.jupiter.api.Test)13 Decimal (org.fhir.ucum.Decimal)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 Base (org.hl7.fhir.r4b.model.Base)11 Base (org.hl7.fhir.r5.model.Base)11 IntegerType (org.hl7.fhir.dstu2.model.IntegerType)10 IntegerType (org.hl7.fhir.dstu2016may.model.IntegerType)10 StringType (org.hl7.fhir.r4.model.StringType)10 Patient (org.hl7.fhir.r4.model.Patient)9 Map (java.util.Map)7 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)7 DecimalType (org.hl7.fhir.r5.model.DecimalType)7 List (java.util.List)6