Search in sources :

Example 21 with ModelInfo

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

the class ModelUtilsTest method testGetBaseTypeNameNamespacePrefixNotFound.

@Test
public void testGetBaseTypeNameNamespacePrefixNotFound() {
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setVersion("1.1.1");
    modelInfo.setUrl("urn:oid:Dummy");
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("Other.BaseType");
    IllegalArgumentException iex = assertThrows(IllegalArgumentException.class, () -> ModelUtils.getBaseTypeName(modelInfo, typeInfo));
    assertTrue(iex.getMessage(), iex.getMessage().contains("Other"));
    assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getName()));
    assertTrue(iex.getMessage(), iex.getMessage().contains(modelInfo.getVersion()));
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

Example 22 with ModelInfo

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

the class DataTypeRequirementsProcessor method addToChildTypes.

protected <T> void addToChildTypes(Map<String, VersionedIdentifier> models, Map<QName, Set<T>> valuesByDataType) {
    for (Map.Entry<String, VersionedIdentifier> modelData : models.entrySet()) {
        Map<QName, TypeNode> typeMap = typeMapByModelUri.computeIfAbsent(modelData.getKey(), key -> {
            ModelInfo modelInfo = modelManager.resolveModel(modelData.getValue()).getModelInfo();
            return ModelUtils.buildTypeMap(modelInfo);
        });
        // Create a temporary set and then merge later to avoid concurrent modification
        Map<QName, Set<T>> newValues = new HashMap<>();
        for (Map.Entry<QName, Set<T>> paths : valuesByDataType.entrySet()) {
            Set<QName> names = getDescendants(typeMap, paths.getKey());
            for (QName name : names) {
                Set<T> childValues = newValues.computeIfAbsent(name, key -> new HashSet<>());
                childValues.addAll(paths.getValue());
            }
        }
        for (Map.Entry<QName, Set<T>> entry : newValues.entrySet()) {
            valuesByDataType.merge(entry.getKey(), entry.getValue(), (oldSet, newSet) -> {
                oldSet.addAll(newSet);
                return oldSet;
            });
        }
    }
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) VersionedIdentifier(org.hl7.elm.r1.VersionedIdentifier) TypeNode(com.ibm.cohort.cql.spark.optimizer.ModelUtils.TypeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with ModelInfo

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

the class ModelUtils method buildTypeMap.

public static Map<QName, TypeNode> buildTypeMap(ModelInfo modelInfo) {
    Map<QName, TypeNode> typeMap = new HashMap<>();
    for (TypeInfo typeInfo : modelInfo.getTypeInfo()) {
        if (typeInfo instanceof ClassInfo) {
            ClassInfo classInfo = (ClassInfo) typeInfo;
            QName qname = new QName(modelInfo.getUrl(), classInfo.getName());
            TypeNode node = typeMap.computeIfAbsent(qname, key -> new TypeNode(key));
            if (typeInfo.getBaseType() != null) {
                QName baseQName = getBaseTypeName(modelInfo, typeInfo);
                if (baseQName != null && baseQName.getNamespaceURI().equals(modelInfo.getUrl())) {
                    TypeNode parentNode = typeMap.computeIfAbsent(baseQName, key -> new TypeNode(key));
                    parentNode.getChildTypes().add(node);
                    node.getParentTypes().add(parentNode);
                }
            }
        }
    }
    return typeMap;
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) TypeInfo(org.hl7.elm_modelinfo.r1.TypeInfo) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo)

Example 24 with ModelInfo

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

the class CustomModelInfoProvider method addModel.

public void addModel(Reader modelInfoXML) {
    ModelInfo modelInfo = JAXB.unmarshal(modelInfoXML, ModelInfo.class);
    addModel(modelInfo);
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo)

Example 25 with ModelInfo

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

the class CustomModelInfoProvider method addModel.

public void addModel(File modelInfoXML) {
    ModelInfo modelInfo = JAXB.unmarshal(modelInfoXML, ModelInfo.class);
    addModel(modelInfo);
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo)

Aggregations

ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)25 Test (org.junit.Test)13 ClassInfo (org.hl7.elm_modelinfo.r1.ClassInfo)12 QName (javax.xml.namespace.QName)11 File (java.io.File)7 Map (java.util.Map)5 TypeNode (com.ibm.cohort.cql.spark.optimizer.ModelUtils.TypeNode)4 IOException (java.io.IOException)4 Collection (java.util.Collection)4 Collectors (java.util.stream.Collectors)4 VersionedIdentifier (org.hl7.elm.r1.VersionedIdentifier)4 ModelSpecifier (org.hl7.elm_modelinfo.r1.ModelSpecifier)4 TypeInfo (org.hl7.elm_modelinfo.r1.TypeInfo)4 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 CqlEvaluationRequest (com.ibm.cohort.cql.evaluation.CqlEvaluationRequest)2 CqlEvaluationRequests (com.ibm.cohort.cql.evaluation.CqlEvaluationRequests)2