Search in sources :

Example 96 with Base

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

the class FHIRPathEngine method opIs.

private List<Base> opIs(List<Base> left, List<Base> right) {
    List<Base> result = new ArrayList<Base>();
    if (left.size() != 1 || right.size() != 1)
        result.add(new BooleanType(false));
    else {
        String tn = convertToString(right);
        result.add(new BooleanType(left.get(0).hasType(tn)));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu2016may.model.BooleanType) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base)

Example 97 with Base

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

the class FHIRPathEngine method opTimes.

private List<Base> opTimes(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()).multiply(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.dstu2016may.model.IntegerType) ArrayList(java.util.ArrayList) DecimalType(org.hl7.fhir.dstu2016may.model.DecimalType) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base) BigDecimal(java.math.BigDecimal)

Example 98 with Base

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

the class FHIRPathEngine method funcSupersetOf.

private List<Base> funcSupersetOf(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    List<Base> target = execute(context, focus, exp.getParameters().get(0), true);
    boolean valid = true;
    for (Base item : target) {
        boolean found = false;
        for (Base t : focus) {
            if (Base.compareDeep(item, t, false)) {
                found = true;
                break;
            }
        }
        if (!found) {
            valid = false;
            break;
        }
    }
    List<Base> result = new ArrayList<Base>();
    result.add(new BooleanType(valid));
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu2016may.model.BooleanType) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base)

Example 99 with Base

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

the class FHIRPathEngine method funcIs.

private List<Base> funcIs(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws PathEngineException {
    List<Base> result = new ArrayList<Base>();
    if (focus.size() == 0 || focus.size() > 1)
        result.add(new BooleanType(false));
    else {
        String tn = exp.getParameters().get(0).getName();
        result.add(new BooleanType(focus.get(0).hasType(tn)));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu2016may.model.BooleanType) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base)

Example 100 with Base

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

the class FHIRPathEngine method funcExists.

private List<Base> funcExists(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    result.add(new BooleanType(!focus.isEmpty()));
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu2016may.model.BooleanType) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base)

Aggregations

ArrayList (java.util.ArrayList)324 FHIRException (org.hl7.fhir.exceptions.FHIRException)177 Base (org.hl7.fhir.r4b.model.Base)87 Base (org.hl7.fhir.r5.model.Base)87 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)76 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)70 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)66 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)64 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)55 NotImplementedException (org.apache.commons.lang3.NotImplementedException)47 Base (org.hl7.fhir.dstu2016may.model.Base)47 UcumException (org.fhir.ucum.UcumException)43 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)41 Base (org.hl7.fhir.dstu2.model.Base)40 BigDecimal (java.math.BigDecimal)39 IOException (java.io.IOException)37 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)34 FileOutputStream (java.io.FileOutputStream)29 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)28 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)28