use of org.hl7.fhir.r5.model.ExpressionNode.Function 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 {
TypeDetails result = new TypeDetails(null);
switch(exp.getKind()) {
case Name:
if (atEntry && exp.getName().equals("$this"))
result.update(context.getThisItem());
else if (atEntry && focus == null)
result.update(executeContextType(context, exp.getName()));
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.update(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.r5.model.ExpressionNode.Function in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method parseExpression.
private ExpressionNode parseExpression(FHIRLexer lexer, boolean proximal) throws FHIRLexerException {
ExpressionNode result = new ExpressionNode(lexer.nextId());
SourceLocation c = lexer.getCurrentStartLocation();
result.setStart(lexer.getCurrentLocation());
// special:
if (lexer.getCurrent().equals("-")) {
lexer.take();
lexer.setCurrent("-" + lexer.getCurrent());
}
if (lexer.getCurrent().equals("+")) {
lexer.take();
lexer.setCurrent("+" + lexer.getCurrent());
}
if (lexer.isConstant(false)) {
checkConstant(lexer.getCurrent(), lexer);
result.setConstant(lexer.take());
result.setKind(Kind.Constant);
result.setEnd(lexer.getCurrentLocation());
} else if ("(".equals(lexer.getCurrent())) {
lexer.next();
result.setKind(Kind.Group);
result.setGroup(parseExpression(lexer, true));
if (!")".equals(lexer.getCurrent()))
throw lexer.error("Found " + lexer.getCurrent() + " expecting a \")\"");
result.setEnd(lexer.getCurrentLocation());
lexer.next();
} else {
if (!lexer.isToken() && !lexer.getCurrent().startsWith("\""))
throw lexer.error("Found " + lexer.getCurrent() + " expecting a token name");
if (lexer.getCurrent().startsWith("\""))
result.setName(lexer.readConstant("Path Name"));
else
result.setName(lexer.take());
result.setEnd(lexer.getCurrentLocation());
if (!result.checkName())
throw lexer.error("Found " + result.getName() + " expecting a valid token name");
if ("(".equals(lexer.getCurrent())) {
Function f = Function.fromCode(result.getName());
FunctionDetails details = null;
if (f == null) {
if (hostServices != null)
details = hostServices.resolveFunction(result.getName());
if (details == null)
throw lexer.error("The name " + result.getName() + " is not a valid function name");
f = Function.Custom;
}
result.setKind(Kind.Function);
result.setFunction(f);
lexer.next();
while (!")".equals(lexer.getCurrent())) {
result.getParameters().add(parseExpression(lexer, true));
if (",".equals(lexer.getCurrent()))
lexer.next();
else if (!")".equals(lexer.getCurrent()))
throw lexer.error("The token " + lexer.getCurrent() + " is not expected here - either a \",\" or a \")\" expected");
}
result.setEnd(lexer.getCurrentLocation());
lexer.next();
checkParameters(lexer, c, result, details);
} else
result.setKind(Kind.Name);
}
ExpressionNode focus = result;
if ("[".equals(lexer.getCurrent())) {
lexer.next();
ExpressionNode item = new ExpressionNode(lexer.nextId());
item.setKind(Kind.Function);
item.setFunction(ExpressionNode.Function.Item);
item.getParameters().add(parseExpression(lexer, true));
if (!lexer.getCurrent().equals("]"))
throw lexer.error("The token " + lexer.getCurrent() + " is not expected here - a \"]\" expected");
lexer.next();
result.setInner(item);
focus = item;
}
if (".".equals(lexer.getCurrent())) {
lexer.next();
focus.setInner(parseExpression(lexer, false));
}
result.setProximal(proximal);
if (proximal) {
while (lexer.isOp()) {
focus.setOperation(ExpressionNode.Operation.fromCode(lexer.getCurrent()));
focus.setOpStart(lexer.getCurrentStartLocation());
focus.setOpEnd(lexer.getCurrentLocation());
lexer.next();
focus.setOpNext(parseExpression(lexer, false));
focus = focus.getOpNext();
}
result = organisePrecedence(lexer, result);
}
return result;
}
use of org.hl7.fhir.r5.model.ExpressionNode.Function in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeImmunizationImmunizationPerformerComponent.
protected void composeImmunizationImmunizationPerformerComponent(Complex parent, String parentType, String name, Immunization.ImmunizationPerformerComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "performer", name, element, index);
if (element.hasFunction())
composeCodeableConcept(t, "Immunization", "function", element.getFunction(), -1);
if (element.hasActor())
composeReference(t, "Immunization", "actor", element.getActor(), -1);
}
use of org.hl7.fhir.r5.model.ExpressionNode.Function in project org.hl7.fhir.core by hapifhir.
the class DataRenderer method makeExceptionXhtml.
public XhtmlNode makeExceptionXhtml(Exception e, String function) {
XhtmlNode xn;
xn = new XhtmlNode(NodeType.Element, "div");
XhtmlNode p = xn.para();
p.b().tx("Exception " + function + ": " + e.getMessage());
p.addComment(getStackTrace(e));
return xn;
}
Aggregations