Search in sources :

Example 1 with ExpressionNode

use of org.hl7.fhir.r5.model.ExpressionNode in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcDescendants.

private List<Base> funcDescendants(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    List<Base> current = new ArrayList<Base>();
    current.addAll(focus);
    List<Base> added = new ArrayList<Base>();
    boolean more = true;
    while (more) {
        added.clear();
        for (Base item : current) {
            getChildrenByName(item, "*", added);
        }
        more = !added.isEmpty();
        result.addAll(added);
        current.clear();
        current.addAll(added);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Base(org.hl7.fhir.dstu2.model.Base)

Example 2 with ExpressionNode

use of org.hl7.fhir.r5.model.ExpressionNode 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>();
    // R2 - can't use ElementUtil
    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)

Example 3 with ExpressionNode

use of org.hl7.fhir.r5.model.ExpressionNode in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcSubsetOf.

private List<Base> funcSubsetOf(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws PathEngineException {
    List<Base> target = execute(context, focus, exp.getParameters().get(0), true);
    boolean valid = true;
    for (Base item : focus) {
        boolean found = false;
        for (Base t : target) {
            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.dstu2.model.BooleanType) Base(org.hl7.fhir.dstu2.model.Base)

Example 4 with ExpressionNode

use of org.hl7.fhir.r5.model.ExpressionNode 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.dstu2.model.BooleanType) Base(org.hl7.fhir.dstu2.model.Base)

Example 5 with ExpressionNode

use of org.hl7.fhir.r5.model.ExpressionNode in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method execute.

private List<Base> execute(ExecutionContext context, List<Base> focus, ExpressionNode exp, boolean atEntry) throws PathEngineException {
    // System.out.println("Evaluate {'"+exp.toString()+"'} on "+focus.toString());
    List<Base> work = new ArrayList<Base>();
    switch(exp.getKind()) {
        case Name:
            if (atEntry && exp.getName().equals("$this"))
                work.add(context.getThisItem());
            else
                for (Base item : focus) {
                    List<Base> outcome = execute(context, item, exp, atEntry);
                    for (Base base : outcome) if (base != null)
                        work.add(base);
                }
            break;
        case Function:
            List<Base> work2 = evaluateFunction(context, focus, exp);
            work.addAll(work2);
            break;
        case Constant:
            Base b = processConstant(context, exp.getConstant());
            if (b != null)
                work.add(b);
            break;
        case Group:
            work2 = execute(context, focus, exp.getGroup(), atEntry);
            work.addAll(work2);
    }
    if (exp.getInner() != null)
        work = execute(context, work, exp.getInner(), false);
    if (exp.isProximal() && exp.getOperation() != null) {
        ExpressionNode next = exp.getOpNext();
        ExpressionNode last = exp;
        while (next != null) {
            List<Base> work2 = preOperate(work, last.getOperation());
            if (work2 != null)
                work = work2;
            else if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As) {
                work2 = executeTypeName(context, focus, next, false);
                work = operate(work, last.getOperation(), work2);
            } else {
                work2 = execute(context, focus, next, true);
                work = operate(work, last.getOperation(), work2);
            // System.out.println("Result of {'"+last.toString()+" "+last.getOperation().toCode()+" "+next.toString()+"'}: "+focus.toString());
            }
            last = next;
            next = next.getOpNext();
        }
    }
    // System.out.println("Result of {'"+exp.toString()+"'}: "+work.toString());
    return work;
}
Also used : ExpressionNode(org.hl7.fhir.dstu2.model.ExpressionNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Base(org.hl7.fhir.dstu2.model.Base)

Aggregations

ArrayList (java.util.ArrayList)190 Base (org.hl7.fhir.r4b.model.Base)68 Base (org.hl7.fhir.r5.model.Base)67 FHIRException (org.hl7.fhir.exceptions.FHIRException)52 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)49 UcumException (org.fhir.ucum.UcumException)31 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)29 NotImplementedException (org.apache.commons.lang3.NotImplementedException)25 Base (org.hl7.fhir.dstu2016may.model.Base)25 BigDecimal (java.math.BigDecimal)23 Base (org.hl7.fhir.dstu2.model.Base)21 ExpressionNode (org.hl7.fhir.r5.model.ExpressionNode)21 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)20 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)20 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)19 ExpressionNode (org.hl7.fhir.dstu2016may.model.ExpressionNode)18 ExpressionNode (org.hl7.fhir.dstu3.model.ExpressionNode)16 ExpressionNode (org.hl7.fhir.r4.model.ExpressionNode)16 List (java.util.List)15 BooleanType (org.hl7.fhir.r5.model.BooleanType)15