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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations