use of org.hl7.fhir.r4b.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.r4b.model.ExpressionNode in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method parse.
// --- public API -------------------------------------------------------
/**
* Parse a path for later use using execute
*
* @param path
* @return
* @throws PathEngineException
* @throws Exception
*/
public ExpressionNode parse(String path) throws FHIRLexerException {
FHIRLexer lexer = new FHIRLexer(path);
if (lexer.done())
throw lexer.error("Path cannot be empty");
ExpressionNode result = parseExpression(lexer, true);
if (!lexer.done())
throw lexer.error("Premature ExpressionNode termination at unexpected token \"" + lexer.getCurrent() + "\"");
result.check();
return result;
}
use of org.hl7.fhir.r4b.model.ExpressionNode in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcSelect.
private List<Base> funcSelect(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws PathEngineException {
List<Base> result = new ArrayList<Base>();
List<Base> pc = new ArrayList<Base>();
for (Base item : focus) {
pc.clear();
pc.add(item);
result.addAll(execute(changeThis(context, item), pc, exp.getParameters().get(0), true));
}
return result;
}
use of org.hl7.fhir.r4b.model.ExpressionNode in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method executeType.
private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException {
// System.out.println("Evaluate {'"+exp.toString()+"'} on "+focus.toString());
TypeDetails result = new TypeDetails(null);
switch(exp.getKind()) {
case Name:
if (atEntry && exp.getName().equals("$this"))
result.update(context.getThisItem());
else {
for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry));
}
if (result.hasNoTypes())
throw new PathEngineException("The name " + exp.getName() + " is not valid for any of the possible types: " + focus.describe());
}
break;
case Function:
result.update(evaluateFunctionType(context, focus, exp));
break;
case Constant:
result.addType(readConstantType(context, exp.getConstant()));
break;
case Group:
result.update(executeType(context, focus, exp.getGroup(), atEntry));
}
exp.setTypes(result);
if (exp.getInner() != null) {
result = executeType(context, result, exp.getInner(), false);
}
if (exp.isProximal() && exp.getOperation() != null) {
ExpressionNode next = exp.getOpNext();
ExpressionNode last = exp;
while (next != null) {
TypeDetails work;
if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As)
work = executeTypeName(context, focus, next, atEntry);
else
work = executeType(context, focus, next, atEntry);
result = operateTypes(result, last.getOperation(), work);
last = next;
next = next.getOpNext();
}
exp.setOpTypes(result);
}
return result;
}
use of org.hl7.fhir.r4b.model.ExpressionNode in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method gatherPrecedence.
private ExpressionNode gatherPrecedence(FHIRLexer lexer, ExpressionNode start, EnumSet<Operation> ops) {
assert (start.isProximal());
// is there anything to do?
boolean work = false;
ExpressionNode focus = start.getOpNext();
if (ops.contains(start.getOperation())) {
while (focus != null && focus.getOperation() != null) {
work = work || !ops.contains(focus.getOperation());
focus = focus.getOpNext();
}
} else {
while (focus != null && focus.getOperation() != null) {
work = work || ops.contains(focus.getOperation());
focus = focus.getOpNext();
}
}
if (!work)
return start;
// entry point: tricky
ExpressionNode group;
if (ops.contains(start.getOperation())) {
group = newGroup(lexer, start);
group.setProximal(true);
focus = start;
start = group;
} else {
ExpressionNode node = start;
focus = node.getOpNext();
while (!ops.contains(focus.getOperation())) {
node = focus;
focus = focus.getOpNext();
}
group = newGroup(lexer, focus);
node.setOpNext(group);
}
// focus points at the group.group
do {
// run until we find the end of the sequence
while (ops.contains(focus.getOperation())) focus = focus.getOpNext();
if (focus.getOperation() != null) {
group.setOperation(focus.getOperation());
group.setOpNext(focus.getOpNext());
focus.setOperation(null);
focus.setOpNext(null);
// now look for another sequence, and start it
ExpressionNode node = group;
focus = group.getOpNext();
if (focus != null) {
while (focus == null && !ops.contains(focus.getOperation())) {
node = focus;
focus = focus.getOpNext();
}
if (focus != null) {
// && (focus.Operation in Ops) - must be true
group = newGroup(lexer, focus);
node.setOpNext(group);
}
}
}
} while (focus != null && focus.getOperation() != null);
return start;
}
Aggregations