Search in sources :

Example 26 with Function

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 && 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;
}
Also used : ExpressionNode(org.hl7.fhir.r4.model.ExpressionNode) PathEngineException(org.hl7.fhir.exceptions.PathEngineException)

Example 27 with Function

use of org.hl7.fhir.r5.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;
}
Also used : ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode)

Example 28 with Function

use of org.hl7.fhir.r5.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);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 29 with Function

use of org.hl7.fhir.r5.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;
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) ExpressionNode(org.hl7.fhir.r5.model.ExpressionNode) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r5.model.Base)

Example 30 with Function

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 && 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;
}
Also used : TypeDetails(org.hl7.fhir.r5.model.TypeDetails) ExpressionNode(org.hl7.fhir.r5.model.ExpressionNode)

Aggregations

Test (org.junit.jupiter.api.Test)17 List (java.util.List)8 FhirPath (au.csiro.pathling.fhirpath.FhirPath)7 Reference (org.hl7.fhir.r4.model.Reference)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 URI (java.net.URI)6 Row (org.apache.spark.sql.Row)6 Session (org.eclipse.jetty.websocket.api.Session)6 ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)6 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)6 IIdType (org.hl7.fhir.instance.model.api.IIdType)6 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)6 FhirReference (org.openmrs.module.fhir2.model.FhirReference)6 FhirTask (org.openmrs.module.fhir2.model.FhirTask)6 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)5 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)5 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)5 ArrayList (java.util.ArrayList)5