use of org.hl7.fhir.r4b.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 && exp.getName().equals("$total"))
result.update(anything(CollectionStatus.UNORDERED));
else if (atEntry && focus == null)
result.update(executeContextType(context, exp.getName(), exp));
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(), exp.getStart(), exp.toString());
}
break;
case Function:
result.update(evaluateFunctionType(context, focus, exp));
break;
case Unary:
result.addType("integer");
break;
case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp));
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, exp);
last = next;
next = next.getOpNext();
}
exp.setOpTypes(result);
}
return result;
}
use of org.hl7.fhir.r4b.model.ExpressionNode.Function 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 {
// 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;
}
use of org.hl7.fhir.r4b.model.ExpressionNode.Function in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeChargeItemChargeItemPerformerComponent.
protected void composeChargeItemChargeItemPerformerComponent(Complex parent, String parentType, String name, ChargeItem.ChargeItemPerformerComponent 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, "ChargeItem", "function", element.getFunction(), -1);
if (element.hasActor())
composeReference(t, "ChargeItem", "actor", element.getActor(), -1);
}
use of org.hl7.fhir.r4b.model.ExpressionNode.Function 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 {
// System.out.println("Evaluate {'"+exp.toString()+"'} on "+focus.toString());
List<Base> work = new ArrayList<Base>();
switch(exp.getKind()) {
case Unary:
work.add(new IntegerType(0));
break;
case Name:
if (atEntry && exp.getName().equals("$this")) {
work.add(context.getThisItem());
} else if (atEntry && exp.getName().equals("$total")) {
work.addAll(context.getTotal());
} else if (atEntry && exp.getName().equals("$index")) {
work.add(context.getIndex());
} 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:
work.addAll(resolveConstant(context, exp.getConstant(), false, exp));
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(), exp);
if (work2 != null) {
work = work2;
} else if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As) {
work2 = executeTypeName(context, focus, next, false);
work = operate(context, work, last.getOperation(), work2, last);
} else {
work2 = execute(context, focus, next, true);
work = operate(context, work, last.getOperation(), work2, last);
// 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;
}
use of org.hl7.fhir.r4b.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 && exp.getName().equals("$total")) {
result.update(anything(CollectionStatus.UNORDERED));
} else if (atEntry && exp.getName().equals("$index")) {
result.addType(TypeDetails.FP_Integer);
} else if (atEntry && focus == null) {
result.update(executeContextType(context, exp.getName(), exp));
} else {
for (String s : focus.getTypes()) {
result.update(executeType(s, exp, atEntry));
}
if (result.hasNoTypes()) {
throw makeException(exp, I18nConstants.FHIRPATH_UNKNOWN_NAME, exp.getName(), focus.describe());
}
}
break;
case Function:
result.update(evaluateFunctionType(context, focus, exp));
break;
case Unary:
result.addType(TypeDetails.FP_Integer);
result.addType(TypeDetails.FP_Decimal);
result.addType(TypeDetails.FP_Quantity);
break;
case Constant:
result.update(resolveConstantType(context, exp.getConstant(), exp));
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);
last = next;
next = next.getOpNext();
}
exp.setOpTypes(result);
}
return result;
}
Aggregations