Search in sources :

Example 46 with DataType

use of org.hl7.fhir.r5.model.DataType in project clinical_quality_language by cqframework.

the class GenericOperator method instantiate.

public InstantiationResult instantiate(Signature callSignature, Map<TypeParameter, DataType> parameters, OperatorMap operatorMap, ConversionMap conversionMap, boolean allowPromotionAndDemotion) {
    Map<TypeParameter, DataType> typeMap = new HashMap<>();
    for (TypeParameter p : typeParameters) {
        typeMap.put(p, null);
    }
    if (parameters != null) {
        for (Map.Entry<TypeParameter, DataType> entry : parameters.entrySet()) {
            typeMap.put(entry.getKey(), entry.getValue());
        }
    }
    InstantiationContextImpl context = new InstantiationContextImpl(typeMap, operatorMap, conversionMap, allowPromotionAndDemotion);
    Boolean instantiable = getSignature().isInstantiable(callSignature, context);
    if (instantiable) {
        Operator result = new Operator(getName(), getSignature().instantiate(context), getResultType().instantiate(context));
        result.setAccessLevel(getAccessLevel());
        result.setLibraryName(getLibraryName());
        return new InstantiationResult(this, result, context.getConversionScore());
    }
    return new InstantiationResult(this, null, context.getConversionScore());
}
Also used : TypeParameter(org.hl7.cql.model.TypeParameter) HashMap(java.util.HashMap) DataType(org.hl7.cql.model.DataType) Map(java.util.Map) HashMap(java.util.HashMap)

Example 47 with DataType

use of org.hl7.fhir.r5.model.DataType in project clinical_quality_language by cqframework.

the class OperatorEntry method expandChoices.

public List<Signature> expandChoices(Signature callSignature) {
    ArrayList<Signature> signatures = new ArrayList<Signature>();
    if (callSignature.containsChoices()) {
        ArrayList<ArrayList<DataType>> operandList = new ArrayList<ArrayList<DataType>>();
        for (DataType operand : callSignature.getOperandTypes()) {
            ArrayList<DataType> list = new ArrayList<DataType>();
            if (operand instanceof ChoiceType) {
                for (DataType type : ((ChoiceType) operand).getTypes()) {
                    list.add(type);
                }
            } else {
                list.add(operand);
            }
            operandList.add(list);
        }
        DataType[] result = new DataType[callSignature.getSize()];
        collectSignatures(operandList, result, 0, signatures);
    } else {
        signatures.add(callSignature);
    }
    return signatures;
}
Also used : ChoiceType(org.hl7.cql.model.ChoiceType) DataType(org.hl7.cql.model.DataType)

Example 48 with DataType

use of org.hl7.fhir.r5.model.DataType in project clinical_quality_language by cqframework.

the class TypeBuilder method dataTypeToQName.

public QName dataTypeToQName(DataType type) {
    if (type instanceof NamedType) {
        NamedType namedType = (NamedType) type;
        ModelInfo modelInfo = mr.getModel(namedType.getNamespace()).getModelInfo();
        return new QName(modelInfo.getTargetUrl() != null ? modelInfo.getTargetUrl() : modelInfo.getUrl(), namedType.getTarget() != null ? namedType.getTarget() : namedType.getSimpleName());
    }
    // ERROR:
    throw new IllegalArgumentException("A named type is required in this context.");
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) QName(javax.xml.namespace.QName)

Example 49 with DataType

use of org.hl7.fhir.r5.model.DataType in project clinical_quality_language by cqframework.

the class SystemLibraryHelper method add.

private static void add(CompiledLibrary systemLibrary, TypeBuilder tb, Operator operator) {
    // In the case that an operator is added directly, manufacture a FunctionDef so it can be referred to in ELM Analysis
    FunctionDef fd = new FunctionDef();
    fd.setName(operator.getName());
    int n = 0;
    for (DataType dataType : operator.getSignature().getOperandTypes()) {
        n++;
        OperandDef od = new OperandDef().withName(String.format("param%d", n));
        if (dataType instanceof NamedType) {
            od.setOperandType(tb.dataTypeToQName(dataType));
        } else {
            od.setOperandTypeSpecifier(tb.dataTypeToTypeSpecifier(dataType));
        }
        od.setResultType(dataType);
        fd.getOperand().add(od);
    }
    operator.setFunctionDef(fd);
    systemLibrary.add(fd, operator);
}
Also used : OperandDef(org.hl7.elm.r1.OperandDef) FunctionDef(org.hl7.elm.r1.FunctionDef)

Example 50 with DataType

use of org.hl7.fhir.r5.model.DataType in project cqf-ruler by DBCG.

the class JpaFhirRetrieveProvider method executeQuery.

protected List<IBaseResource> executeQuery(String dataType, SearchParameterMap map) {
    // TODO: Once HAPI breaks this out from the server dependencies
    // we can include it on its own.
    ca.uhn.fhir.jpa.searchparam.SearchParameterMap hapiMap = ca.uhn.fhir.jpa.searchparam.SearchParameterMap.newSynchronous();
    try {
        Method[] methods = hapiMap.getClass().getDeclaredMethods();
        List<Method> methodList = Arrays.asList(methods);
        List<Method> puts = methodList.stream().filter(x -> x.getName().equals("put")).collect(Collectors.toList());
        Method method = puts.get(0);
        method.setAccessible(true);
        for (Map.Entry<String, List<List<IQueryParameterType>>> entry : map.entrySet()) {
            method.invoke(hapiMap, entry.getKey(), entry.getValue());
        }
    } catch (Exception e) {
        logger.warn("Error converting search parameter map", e);
    }
    IBundleProvider bundleProvider = search(getClass(dataType), hapiMap, myRequestDetails);
    if (bundleProvider.isEmpty()) {
        return new ArrayList<>();
    }
    return bundleProvider.getAllResources();
}
Also used : Arrays(java.util.Arrays) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) SearchParamFhirRetrieveProvider(org.opencds.cqf.cql.engine.fhir.retrieve.SearchParamFhirRetrieveProvider) SearchParameterMap(org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) DaoRegistryUser(org.opencds.cqf.ruler.behavior.DaoRegistryUser) List(java.util.List) DaoRegistry(ca.uhn.fhir.jpa.api.dao.DaoRegistry) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Map(java.util.Map) SearchParameterResolver(org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterResolver) Method(java.lang.reflect.Method) Collections(java.util.Collections) IQueryParameterType(ca.uhn.fhir.model.api.IQueryParameterType) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ArrayList(java.util.ArrayList) List(java.util.List) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IQueryParameterType(ca.uhn.fhir.model.api.IQueryParameterType) SearchParameterMap(org.opencds.cqf.cql.engine.fhir.searchparam.SearchParameterMap) Map(java.util.Map)

Aggregations

DataType (org.hl7.fhir.r5.model.DataType)14 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)11 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 Collectors (java.util.stream.Collectors)6 DataType (org.hl7.cql.model.DataType)6 ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)6 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)6 ArrayList (java.util.ArrayList)5 StructType (org.apache.spark.sql.types.StructType)5 BooleanType (org.hl7.fhir.r5.model.BooleanType)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 Arrays (java.util.Arrays)4 QName (javax.xml.namespace.QName)4 DataType (org.hl7.fhir.r4b.model.DataType)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3