use of com.cerner.bunsen.definitions.StructureField in project bunsen by cerner.
the class DefinitionToAvroVisitor method visitParentExtension.
@Override
public HapiConverter<Schema> visitParentExtension(String elementName, String extensionUrl, List<StructureField<HapiConverter<Schema>>> children) {
// Ignore extension fields that don't have declared content for now.
if (children.isEmpty()) {
return null;
}
String recordNamespace = DefinitionVisitorsUtil.namespaceFor(basePackage, extensionUrl);
String localPart = extensionUrl.substring(extensionUrl.lastIndexOf('/') + 1);
String[] parts = localPart.split("[-|_]");
String recordName = Arrays.stream(parts).map(part -> part.substring(0, 1).toUpperCase() + part.substring(1)).collect(Collectors.joining());
String fullName = recordNamespace + "." + recordName;
HapiConverter<Schema> converter = visitedConverters.get(fullName);
if (converter == null) {
List<Field> fields = children.stream().map(entry -> new Field(entry.fieldName(), nullable(entry.result().getDataType()), "Doc here", JsonProperties.NULL_VALUE)).collect(Collectors.toList());
Schema schema = Schema.createRecord(recordName, "Reference type.", recordNamespace, false, fields);
converter = new CompositeToAvroConverter(null, children, schema, fhirSupport, extensionUrl);
visitedConverters.put(fullName, converter);
}
return converter;
}
use of com.cerner.bunsen.definitions.StructureField in project bunsen by cerner.
the class DefinitionToAvroVisitor method visitContained.
@Override
public HapiConverter<Schema> visitContained(String elementPath, String elementTypeUrl, Map<String, StructureField<HapiConverter<Schema>>> contained) {
String recordName = DefinitionVisitorsUtil.recordNameFor(elementPath);
String recordNamespace = DefinitionVisitorsUtil.namespaceFor(basePackage, elementTypeUrl);
List<Field> fields = contained.values().stream().map(containedEntry -> {
String doc = "Field for FHIR property " + containedEntry.propertyName();
return new Field(containedEntry.fieldName(), nullable(containedEntry.result().getDataType()), doc, JsonProperties.NULL_VALUE);
}).collect(Collectors.toList());
Schema containerType = Schema.createArray(Schema.createRecord(recordName, "Structure for FHIR type contained", recordNamespace, false, fields));
return new HapiContainedToAvroConverter(contained, containerType);
}
use of com.cerner.bunsen.definitions.StructureField in project bunsen by cerner.
the class Stu3StructureDefinitions method extensionElementToFields.
private <T> List<StructureField<T>> extensionElementToFields(DefinitionVisitor<T> visitor, StructureDefinition rootDefinition, ElementDefinition element, List<ElementDefinition> definitions, Deque<QualifiedPath> stack) {
// FIXME: extension is a type rather than an external structure....
StructureDefinition definition = element.getTypeFirstRep().getProfile() != null ? (StructureDefinition) validationSupport.fetchStructureDefinition(context, element.getTypeFirstRep().getProfile()) : null;
List<StructureField<T>> extensions;
if (definition != null) {
if (shouldTerminateRecursive(visitor, new QualifiedPath(definition.getUrl(), element.getPath()), stack)) {
return Collections.emptyList();
} else {
List<ElementDefinition> extensionDefinitions = definition.getSnapshot().getElement();
ElementDefinition extensionRoot = extensionDefinitions.get(0);
extensions = visitExtensionDefinition(visitor, rootDefinition, element.getSliceName(), stack, definition.getUrl(), extensionDefinitions, extensionRoot);
}
} else {
if (element.getSliceName() == null) {
return Collections.emptyList();
}
extensions = visitExtensionDefinition(visitor, rootDefinition, element.getSliceName(), stack, element.getTypeFirstRep().getProfile(), definitions, element);
}
if (!element.getMax().equals("1") && extensions.size() > 0) {
// the nested extension element has max: *
return Collections.singletonList(StructureField.extension(extensions.get(0).fieldName(), extensions.get(0).extensionUrl(), extensions.get(0).isModifier(), visitor.visitMultiValued(extensions.get(0).fieldName(), extensions.get(0).result())));
} else {
return extensions;
}
}
use of com.cerner.bunsen.definitions.StructureField in project bunsen by cerner.
the class Stu3StructureDefinitions method transformRoot.
private <T> T transformRoot(DefinitionVisitor<T> visitor, StructureDefinition definition, List<StructureDefinition> containedDefinitions, Deque<QualifiedPath> stack) {
ElementDefinition definitionRootElement = definition.getSnapshot().getElementFirstRep();
List<ElementDefinition> definitions = definition.getSnapshot().getElement();
ElementDefinition root = definitions.get(0);
stack.push(new QualifiedPath(definition.getUrl(), definitionRootElement.getPath()));
List<StructureField<T>> childElements = transformChildren(visitor, definition, definitions, stack, root);
// If there are contained definitions, create a Resource Container StructureField
if (containedDefinitions.size() > 0) {
StructureField<T> containedElement = transformContained(visitor, definition, containedDefinitions, stack, root);
// Replace default StructureField with constructed Resource Container StructureField
childElements.set(5, containedElement);
}
stack.pop();
String rootName = elementName(root);
return visitor.visitComposite(rootName, rootName, rootName, definition.getUrl(), childElements);
}
use of com.cerner.bunsen.definitions.StructureField in project bunsen by cerner.
the class DefinitionToSparkVisitor method visitContained.
@Override
public HapiConverter visitContained(String elementPath, String elementTypeUrl, Map<String, StructureField<HapiConverter<DataType>>> contained) {
StructField[] fields = contained.values().stream().map(containedEntry -> new StructField(containedEntry.fieldName(), containedEntry.result().getDataType(), true, Metadata.empty())).toArray(StructField[]::new);
ArrayType container = new ArrayType(new StructType(fields), true);
return new HapiContainedToSparkConverter(contained, container);
}
Aggregations