Search in sources :

Example 86 with Base

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

the class FHIRPathEngine method opGreater.

private List<Base> opGreater(List<Base> left, List<Base> right) throws PathEngineException {
    if (left.size() == 1 && right.size() == 1 && left.get(0).isPrimitive() && right.get(0).isPrimitive()) {
        Base l = left.get(0);
        Base r = right.get(0);
        if (l.hasType("string") && r.hasType("string"))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
        else if ((l.hasType("integer", "decimal")) && (r.hasType("integer", "decimal")))
            return makeBoolean(new Double(l.primitiveValue()) > new Double(r.primitiveValue()));
        else if ((l.hasType("date", "dateTime", "instant")) && (r.hasType("date", "dateTime", "instant")))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
        else if ((l.hasType("time")) && (r.hasType("time")))
            return makeBoolean(l.primitiveValue().compareTo(r.primitiveValue()) > 0);
    } else if (left.size() == 1 && right.size() == 1 && left.get(0).fhirType().equals("Quantity") && right.get(0).fhirType().equals("Quantity")) {
        List<Base> lUnit = left.get(0).listChildrenByName("unit");
        List<Base> rUnit = right.get(0).listChildrenByName("unit");
        if (Base.compareDeep(lUnit, rUnit, true)) {
            return opGreater(left.get(0).listChildrenByName("value"), right.get(0).listChildrenByName("value"));
        } else {
            throw new PathEngineException("Canonical Comparison isn't done yet");
        }
    }
    return new ArrayList<Base>();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Base(org.hl7.fhir.dstu2.model.Base)

Example 87 with Base

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

the class FHIRPathEngine method funcAll.

private List<Base> funcAll(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws PathEngineException {
    if (exp.getParameters().size() == 1) {
        List<Base> result = new ArrayList<Base>();
        List<Base> pc = new ArrayList<Base>();
        boolean all = true;
        for (Base item : focus) {
            pc.clear();
            pc.add(item);
            if (!convertToBoolean(execute(changeThis(context, item), pc, exp.getParameters().get(0), false))) {
                all = false;
                break;
            }
        }
        result.add(new BooleanType(all));
        return result;
    } else {
        // (exp.getParameters().size() == 0) {
        List<Base> result = new ArrayList<Base>();
        boolean all = true;
        for (Base item : focus) {
            boolean v = false;
            if (item instanceof BooleanType) {
                v = ((BooleanType) item).booleanValue();
            } else
                v = item != null;
            if (!v) {
                all = false;
                break;
            }
        }
        result.add(new BooleanType(all));
        return result;
    }
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Base(org.hl7.fhir.dstu2.model.Base)

Example 88 with Base

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

the class FHIRPathEngine method funcExtension.

private List<Base> funcExtension(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws PathEngineException {
    List<Base> result = new ArrayList<Base>();
    List<Base> nl = execute(context, focus, exp.getParameters().get(0), true);
    String url = nl.get(0).primitiveValue();
    for (Base item : focus) {
        List<Base> ext = new ArrayList<Base>();
        getChildrenByName(item, "extension", ext);
        getChildrenByName(item, "modifierExtension", ext);
        for (Base ex : ext) {
            List<Base> vl = new ArrayList<Base>();
            getChildrenByName(ex, "url", vl);
            if (convertToString(vl).equals(url))
                result.add(ex);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Base(org.hl7.fhir.dstu2.model.Base)

Example 89 with Base

use of org.hl7.fhir.dstu2016may.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.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)

Example 90 with Base

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

the class FHIRPathEngine method funcEmpty.

private List<Base> funcEmpty(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.dstu2.model.BooleanType) Base(org.hl7.fhir.dstu2.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