Search in sources :

Example 1 with FunctionRef

use of org.hl7.elm.r1.FunctionRef in project clinical_quality_language by cqframework.

the class FunctionRefInvocation method setResolution.

@Override
public void setResolution(OperatorResolution resolution) {
    super.setResolution(resolution);
    FunctionRef fr = (FunctionRef) expression;
    if (resolution.getLibraryName() != null && !resolution.getLibraryName().equals(fr.getLibraryName())) {
        fr.setLibraryName(resolution.getLibraryName());
    }
}
Also used : FunctionRef(org.hl7.elm.r1.FunctionRef)

Example 2 with FunctionRef

use of org.hl7.elm.r1.FunctionRef in project clinical_quality_language by cqframework.

the class ElmRequirementsContext method reportFunctionRef.

public void reportFunctionRef(FunctionRef functionRef) {
    CompiledLibrary targetLibrary = prepareLibraryVisit(getCurrentLibraryIdentifier(), functionRef.getLibraryName());
    try {
        List<DataType> signature;
        signature = new ArrayList<DataType>();
        for (TypeSpecifier ts : functionRef.getSignature()) {
            signature.add(typeResolver.resolveTypeSpecifier(ts));
        }
        // Signature sizes will only be different in the case that the signature is not present in the ELM, so needs to be constructed
        if (signature.size() != functionRef.getOperand().size()) {
            for (Expression e : functionRef.getOperand()) {
                if (e.getResultType() != null) {
                    signature.add(e.getResultType());
                } else if (e.getResultTypeName() != null) {
                    signature.add(typeResolver.resolveTypeName(e.getResultTypeName()));
                } else if (e.getResultTypeSpecifier() != null) {
                    signature.add(typeResolver.resolveTypeSpecifier(e.getResultTypeSpecifier()));
                } else {
                    // Signature could not be constructed, fall back to reporting all function defs
                    signature = null;
                    break;
                }
            }
        }
        Iterable<FunctionDef> fds = targetLibrary.resolveFunctionRef(functionRef.getName(), signature);
        for (FunctionDef fd : fds) {
            if (!visited.contains(fd)) {
                visitor.visitElement(fd, this);
            }
        }
    } finally {
        unprepareLibraryVisit(functionRef.getLibraryName());
    }
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) DataType(org.hl7.cql.model.DataType)

Example 3 with FunctionRef

use of org.hl7.elm.r1.FunctionRef in project clinical_quality_language by cqframework.

the class FunctionRefInvocation method setOperands.

@Override
public void setOperands(Iterable<Expression> operands) {
    List<Expression> expOperands = ((FunctionRef) expression).getOperand();
    expOperands.clear();
    for (Expression operand : operands) {
        expOperands.add(operand);
    }
}
Also used : Expression(org.hl7.elm.r1.Expression) FunctionRef(org.hl7.elm.r1.FunctionRef)

Example 4 with FunctionRef

use of org.hl7.elm.r1.FunctionRef in project quality-measure-and-cohort-service by Alvearie.

the class AnyColumnVisitor method visitFunctionRef.

@Override
public Object visitFunctionRef(FunctionRef elm, AnyColumnContext context) {
    if (AnyColumnFunctions.FUNCTION_NAMES.contains(elm.getName())) {
        if (elm.getOperand().size() == 2) {
            QName dataType = ((As) elm.getOperand().get(0)).getOperand().getResultTypeName();
            // TODO - validate that the first operand is a model object. We really should be doing that at the
            // method declaration level instead of Choice<Any>, but that will require the model
            // to have a base class that everything extends from.
            String columnMatchLogic = null;
            if (elm.getOperand().get(1) instanceof Literal) {
                columnMatchLogic = ((Literal) elm.getOperand().get(1)).getValue();
            } else {
                throw new IllegalArgumentException(String.format("Second argument to %s function at %s must be a literal", elm.getName(), elm.getLocator()));
            }
            StringMatcher matcher = null;
            if (elm.getName().equals(AnyColumnFunctions.FUNC_ANY_COLUMN)) {
                matcher = new PrefixStringMatcher(columnMatchLogic);
            } else if (elm.getName().equals(AnyColumnFunctions.FUNC_ANY_COLUMN_REGEX)) {
                matcher = new RegexStringMatcher(columnMatchLogic);
            } else {
                throw new IllegalArgumentException(String.format("Found declared, but unsupported AnyColumn function %s at %s", elm.getName(), elm.getLocator()));
            }
            context.reportAnyColumn(dataType, matcher);
        } else {
            throw new IllegalArgumentException(String.format("%s function at %s should have exactly two arguments", elm.getName(), elm.getLocator()));
        }
    }
    return super.visitFunctionRef(elm, context);
}
Also used : RegexStringMatcher(com.ibm.cohort.cql.util.RegexStringMatcher) QName(javax.xml.namespace.QName) Literal(org.hl7.elm.r1.Literal) StringMatcher(com.ibm.cohort.cql.util.StringMatcher) RegexStringMatcher(com.ibm.cohort.cql.util.RegexStringMatcher) PrefixStringMatcher(com.ibm.cohort.cql.util.PrefixStringMatcher) PrefixStringMatcher(com.ibm.cohort.cql.util.PrefixStringMatcher)

Aggregations

FunctionRef (org.hl7.elm.r1.FunctionRef)2 PrefixStringMatcher (com.ibm.cohort.cql.util.PrefixStringMatcher)1 RegexStringMatcher (com.ibm.cohort.cql.util.RegexStringMatcher)1 StringMatcher (com.ibm.cohort.cql.util.StringMatcher)1 QName (javax.xml.namespace.QName)1 CompiledLibrary (org.cqframework.cql.cql2elm.model.CompiledLibrary)1 DataType (org.hl7.cql.model.DataType)1 Expression (org.hl7.elm.r1.Expression)1 Literal (org.hl7.elm.r1.Literal)1