Search in sources :

Example 1 with TypeSpecifier

use of org.hl7.elm_modelinfo.r1.TypeSpecifier 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 2 with TypeSpecifier

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

the class ElmUtils method getModelTypeNames.

public static Set<QName> getModelTypeNames(Expression expression) {
    Set<QName> modelTypeNames = new HashSet<>();
    if (expression.getResultTypeName() != null) {
        modelTypeNames.add(expression.getResultTypeName());
    } else {
        TypeSpecifier resultTypeSpecifier = expression.getResultTypeSpecifier();
        if (resultTypeSpecifier != null) {
            Set<QName> specifierModelTypeNames = getModelTypeNames(resultTypeSpecifier);
            modelTypeNames.addAll(specifierModelTypeNames);
        } else {
            // This is normal for something like a ConceptRef
            LOG.debug("Could not resolve model type name for expression of type {}", expression.getClass().getSimpleName());
        // throw new IllegalArgumentException("Could not resolve model type name for expression " + expression.getLocator());
        }
    }
    return modelTypeNames;
}
Also used : QName(javax.xml.namespace.QName) NamedTypeSpecifier(org.hl7.elm.r1.NamedTypeSpecifier) ChoiceTypeSpecifier(org.hl7.elm.r1.ChoiceTypeSpecifier) ListTypeSpecifier(org.hl7.elm.r1.ListTypeSpecifier) TupleTypeSpecifier(org.hl7.elm.r1.TupleTypeSpecifier) TypeSpecifier(org.hl7.elm.r1.TypeSpecifier) IntervalTypeSpecifier(org.hl7.elm.r1.IntervalTypeSpecifier) HashSet(java.util.HashSet)

Example 3 with TypeSpecifier

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

the class ModelUtils method getChoiceTypeNames.

public static Collection<String> getChoiceTypeNames(TypeInfo typeInfo) {
    if (typeInfo != null && typeInfo.getBaseTypeSpecifier() != null && (typeInfo.getBaseTypeSpecifier() instanceof ChoiceTypeSpecifier)) {
        List<String> choiceTypes = new ArrayList<>();
        ChoiceTypeSpecifier choiceType = (ChoiceTypeSpecifier) typeInfo.getBaseTypeSpecifier();
        for (TypeSpecifier typeSpecifier : choiceType.getChoice()) {
            if (typeSpecifier instanceof NamedTypeSpecifier) {
                String typeName = ((NamedTypeSpecifier) typeSpecifier).getName();
                choiceTypes.add(typeName);
            }
        }
        return choiceTypes;
    } else {
        return Collections.emptyList();
    }
}
Also used : NamedTypeSpecifier(org.hl7.elm_modelinfo.r1.NamedTypeSpecifier) ArrayList(java.util.ArrayList) NamedTypeSpecifier(org.hl7.elm_modelinfo.r1.NamedTypeSpecifier) ChoiceTypeSpecifier(org.hl7.elm_modelinfo.r1.ChoiceTypeSpecifier) TypeSpecifier(org.hl7.elm_modelinfo.r1.TypeSpecifier) ChoiceTypeSpecifier(org.hl7.elm_modelinfo.r1.ChoiceTypeSpecifier)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 CompiledLibrary (org.cqframework.cql.cql2elm.model.CompiledLibrary)1 DataType (org.hl7.cql.model.DataType)1 ChoiceTypeSpecifier (org.hl7.elm.r1.ChoiceTypeSpecifier)1 IntervalTypeSpecifier (org.hl7.elm.r1.IntervalTypeSpecifier)1 ListTypeSpecifier (org.hl7.elm.r1.ListTypeSpecifier)1 NamedTypeSpecifier (org.hl7.elm.r1.NamedTypeSpecifier)1 TupleTypeSpecifier (org.hl7.elm.r1.TupleTypeSpecifier)1 TypeSpecifier (org.hl7.elm.r1.TypeSpecifier)1 ChoiceTypeSpecifier (org.hl7.elm_modelinfo.r1.ChoiceTypeSpecifier)1 NamedTypeSpecifier (org.hl7.elm_modelinfo.r1.NamedTypeSpecifier)1 TypeSpecifier (org.hl7.elm_modelinfo.r1.TypeSpecifier)1