Search in sources :

Example 26 with TypeInfo

use of org.hl7.fhir.core.generator.analysis.TypeInfo 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 27 with TypeInfo

use of org.hl7.fhir.core.generator.analysis.TypeInfo 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)

Example 28 with TypeInfo

use of org.hl7.fhir.core.generator.analysis.TypeInfo 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 29 with TypeInfo

use of org.hl7.fhir.core.generator.analysis.TypeInfo 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)

Example 30 with TypeInfo

use of org.hl7.fhir.core.generator.analysis.TypeInfo 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)

Aggregations

ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)22 ModelInfo (org.hl7.elm_modelinfo.r1.ModelInfo)9 Test (org.junit.Test)9 ClassInfo (org.hl7.elm_modelinfo.r1.ClassInfo)8 EnumInfo (org.hl7.fhir.core.generator.analysis.EnumInfo)5 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)5 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)5 ValueSet (org.hl7.fhir.r5.model.ValueSet)5 QName (javax.xml.namespace.QName)4 TypeInfo (org.hl7.fhir.core.generator.analysis.TypeInfo)4 ArrayList (java.util.ArrayList)3 TypeInfo (org.hl7.elm_modelinfo.r1.TypeInfo)3 File (java.io.File)2 ModelSpecifier (org.hl7.elm_modelinfo.r1.ModelSpecifier)2 ProfileUtilities (org.hl7.fhir.r5.conformance.ProfileUtilities)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ChoiceTypeSpecifier (org.hl7.elm_modelinfo.r1.ChoiceTypeSpecifier)1