use of org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions in project bunsen by cerner.
the class HapiCompositeConverter method fromHapi.
@Override
public Object fromHapi(Object input) {
IBase composite = (IBase) input;
Object[] values = new Object[children.size()];
int valueIndex = 0;
Iterator<StructureField<HapiConverter<T>>> schemaIterator = children.iterator();
if (composite instanceof IAnyResource) {
// Id element
StructureField<HapiConverter<T>> schemaEntry = schemaIterator.next();
values[0] = schemaEntry.result().fromHapi(((IAnyResource) composite).getIdElement());
valueIndex++;
// Meta element
schemaEntry = schemaIterator.next();
values[valueIndex] = schemaEntry.result().fromHapi(((IAnyResource) composite).getMeta());
valueIndex++;
}
Map<String, List> properties = fhirSupport.compositeValues(composite);
// Co-iterate with an index so we place the correct values into the corresponding locations.
for (; valueIndex < children.size(); ++valueIndex) {
StructureField<HapiConverter<T>> schemaEntry = schemaIterator.next();
String propertyName = schemaEntry.propertyName();
// Append the [x] suffix for choice properties.
if (schemaEntry.isChoice()) {
propertyName = propertyName + "[x]";
}
HapiConverter<T> converter = schemaEntry.result();
List propertyValues = properties.get(propertyName);
if (propertyValues != null && !propertyValues.isEmpty()) {
if (isMultiValued(converter.getDataType())) {
values[valueIndex] = schemaEntry.result().fromHapi(propertyValues);
} else {
values[valueIndex] = schemaEntry.result().fromHapi(propertyValues.get(0));
}
} else if (converter.extensionUrl() != null) {
// No corresponding property for the name, so see if it is an Extension or ModifierExtention
List<? extends IBaseExtension> extensions = schemaEntry.isModifier() ? ((IBaseHasModifierExtensions) composite).getModifierExtension() : ((IBaseHasExtensions) composite).getExtension();
for (IBaseExtension extension : extensions) {
if (extension.getUrl().equals(converter.extensionUrl())) {
values[valueIndex] = schemaEntry.result().fromHapi(extension);
}
}
} else if (converter instanceof MultiValueConverter && ((MultiValueConverter) converter).getElementConverter().extensionUrl() != null) {
final String extensionUrl = ((MultiValueConverter) converter).getElementConverter().extensionUrl();
List<? extends IBaseExtension> extensions = schemaEntry.isModifier() ? ((IBaseHasModifierExtensions) composite).getModifierExtension() : ((IBaseHasExtensions) composite).getExtension();
final List<? extends IBaseExtension> extensionList = extensions.stream().filter(extension -> extension.getUrl().equals(extensionUrl)).collect(Collectors.toList());
if (extensionList.size() > 0) {
values[valueIndex] = schemaEntry.result().fromHapi(extensionList);
}
}
}
return createComposite(values);
}
Aggregations