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));
}
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);
}
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()));
}
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();
}
}
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;
}
Aggregations