use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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;
}
Aggregations