Search in sources :

Example 26 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 FHIRException {
    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);
            }
            last = next;
            next = next.getOpNext();
        }
    }
    return work;
}
Also used : ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base)

Example 27 with ExpressionNode

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

the class FHIRPathEngine method newGroup.

private ExpressionNode newGroup(FHIRLexer lexer, ExpressionNode next) {
    ExpressionNode result = new ExpressionNode(lexer.nextId());
    result.setKind(Kind.Group);
    result.setGroup(next);
    result.getGroup().setProximal(true);
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode)

Example 28 with ExpressionNode

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

the class FHIRPathEngine method funcDescendents.

private List<Base> funcDescendents(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    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) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base)

Example 29 with ExpressionNode

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

the class FHIRPathEngine method executeTypeName.

private List<Base> executeTypeName(ExecutionContext context, List<Base> focus, ExpressionNode next, boolean atEntry) {
    List<Base> result = new ArrayList<Base>();
    result.add(new StringType(next.getName()));
    return result;
}
Also used : StringType(org.hl7.fhir.dstu2016may.model.StringType) ArrayList(java.util.ArrayList) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.model.Base)

Example 30 with ExpressionNode

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

the class FHIRPathEngine method funcAs.

private List<Base> funcAs(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    List<Base> result = new ArrayList<Base>();
    String tn = exp.getParameters().get(0).getName();
    for (Base b : focus) if (b.hasType(tn))
        result.add(b);
    return result;
}
Also used : ArrayList(java.util.ArrayList) ParserBase(org.hl7.fhir.dstu2016may.metamodel.ParserBase) Base(org.hl7.fhir.dstu2016may.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