Search in sources :

Example 16 with ModelInfo

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

the class ModelUtilsTest method testGetBaseTypeNameInvalidNamespacePrefix.

@Test
public void testGetBaseTypeNameInvalidNamespacePrefix() {
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setVersion("2.1.3");
    modelInfo.setUrl("urn:oid:Dummy");
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("System.Child.BaseType");
    IllegalArgumentException iex = assertThrows(IllegalArgumentException.class, () -> ModelUtils.getBaseTypeName(modelInfo, typeInfo));
    assertTrue(iex.getMessage().contains("System.Child.BaseType"));
    assertTrue(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 17 with ModelInfo

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

the class ModelUtilsTest method testGetBaseTypeWithoutBaseType.

@Test
public void testGetBaseTypeWithoutBaseType() {
    ModelInfo modelInfo = new ModelInfo();
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    assertNull(ModelUtils.getBaseTypeName(modelInfo, typeInfo));
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

Example 18 with ModelInfo

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

the class ModelUtilsTest method loadFromClasspath.

protected ModelInfo loadFromClasspath(String resourcePath) throws IOException {
    ModelInfo modelInfo;
    try (InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(resourcePath)) {
        assertNotNull("Classpath resource not found", is);
        modelInfo = JAXB.unmarshal(is, ModelInfo.class);
    }
    return modelInfo;
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) InputStream(java.io.InputStream)

Example 19 with ModelInfo

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

the class ModelUtilsTest method testFHIR401Model.

@Test
public void testFHIR401Model() throws Exception {
    ModelInfo modelInfo = loadFromClasspath("org/hl7/fhir/fhir-modelinfo-4.0.1.xml");
    Map<QName, TypeNode> typeMap = ModelUtils.buildTypeMap(modelInfo);
    assertEquals(931, typeMap.size());
    TypeNode node = typeMap.get(new QName(modelInfo.getUrl(), "MoneyQuantity"));
    assertNotNull(node);
    assertEquals("Missing parent type", 1, node.getParentTypes().size());
    assertEquals("Quantity", node.getParentTypes().iterator().next().getTypeName().getLocalPart());
    node = typeMap.get(new QName(modelInfo.getUrl(), "Quantity"));
    assertNotNull(node);
    assertEquals(6, node.getChildTypes().size());
    assertEquals(1, node.getChildTypes().stream().filter(n -> n.getTypeName().getLocalPart().equals("MoneyQuantity")).collect(Collectors.counting()).longValue());
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) Arrays(java.util.Arrays) TypeInfo(org.hl7.elm_modelinfo.r1.TypeInfo) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertThrows(org.junit.Assert.assertThrows) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Collectors(java.util.stream.Collectors) File(java.io.File) Assert.assertThat(org.junit.Assert.assertThat) HashSet(java.util.HashSet) Assert.assertNull(org.junit.Assert.assertNull) TypeNode(com.ibm.cohort.cql.spark.optimizer.ModelUtils.TypeNode) Map(java.util.Map) QName(javax.xml.namespace.QName) JAXB(javax.xml.bind.JAXB) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ModelSpecifier(org.hl7.elm_modelinfo.r1.ModelSpecifier) ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) QName(javax.xml.namespace.QName) TypeNode(com.ibm.cohort.cql.spark.optimizer.ModelUtils.TypeNode) Test(org.junit.Test)

Example 20 with ModelInfo

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

the class ModelUtilsTest method testGetBaseTypeNameIncludedNamespacePrefixValid.

@Test
public void testGetBaseTypeNameIncludedNamespacePrefixValid() {
    ModelSpecifier otherModel = new ModelSpecifier().withName("Other").withVersion("1.2.3").withUrl("urn:oid:Other");
    ModelInfo modelInfo = new ModelInfo();
    modelInfo.setName("Dummy");
    modelInfo.setUrl("urn:oid:Dummy");
    modelInfo.getRequiredModelInfo().add(otherModel);
    ClassInfo typeInfo = new ClassInfo();
    typeInfo.setName("MyType");
    typeInfo.setBaseType("Other.BaseType");
    QName qname = ModelUtils.getBaseTypeName(modelInfo, typeInfo);
    assertEquals(new QName(otherModel.getUrl(), "BaseType"), qname);
}
Also used : ModelInfo(org.hl7.elm_modelinfo.r1.ModelInfo) ModelSpecifier(org.hl7.elm_modelinfo.r1.ModelSpecifier) QName(javax.xml.namespace.QName) ClassInfo(org.hl7.elm_modelinfo.r1.ClassInfo) Test(org.junit.Test)

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