use of ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition in project bunsen by cerner.
the class FhirEncoders method of.
/**
* Returns an encoder for the given FHIR resource.
*
* @param type the type of the resource to encode.
* @param <T> the type of the resource to be encoded.
* @return an encoder for the resource.
*/
public <T extends IBaseResource> ExpressionEncoder<T> of(Class<T> type) {
BaseRuntimeElementCompositeDefinition definition = context.getResourceDefinition(type);
synchronized (encoderCache) {
ExpressionEncoder<T> encoder = encoderCache.get(type);
if (encoder == null) {
encoder = (ExpressionEncoder<T>) EncoderBuilder.of(definition, context, new SchemaConverter(context));
encoderCache.put(type, encoder);
}
return encoder;
}
}
use of ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition in project pathling by aehrc.
the class ElementDefinition method getChildElement.
/**
* Returns the child element of this element with the specified name.
*
* @param name The name of the child element
* @return A new ElementDefinition describing the child
*/
@Nonnull
public Optional<ElementDefinition> getChildElement(@Nonnull final String name) {
if (elementDefinition.isPresent() && elementDefinition.get() instanceof BaseRuntimeElementCompositeDefinition) {
final BaseRuntimeElementCompositeDefinition compositeDefinition = (BaseRuntimeElementCompositeDefinition) elementDefinition.get();
final BaseRuntimeChildDefinition newChild = compositeDefinition.getChildByName(name);
if (newChild == null) {
return Optional.empty();
}
return Optional.of(ElementDefinition.build(newChild, name));
} else {
return Optional.empty();
}
}
use of ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition in project bunsen by cerner.
the class HapiCompositeConverter method toHapiConverter.
@Override
public HapiFieldSetter toHapiConverter(BaseRuntimeElementDefinition... elementDefinitions) {
BaseRuntimeElementDefinition elementDefinition = elementDefinitions[0];
// explicitly from the root
if (elementDefinition instanceof RuntimeElemContainedResourceList) {
return NOOP_FIELD_SETTER;
}
if (!(elementDefinition instanceof BaseRuntimeElementCompositeDefinition)) {
throw new IllegalArgumentException("Composite converter must be given a " + "single composite element, received: " + elementDefinition.getName());
}
BaseRuntimeElementCompositeDefinition compositeDefinition = (BaseRuntimeElementCompositeDefinition) elementDefinition;
List<StructureField<HapiFieldSetter>> toHapiChildren = children.stream().map(child -> {
HapiFieldSetter childConverter;
if ("contained".equals(child.propertyName())) {
// Handle contained resources.
HapiFieldSetter containedFieldSetter = NOOP_FIELD_SETTER;
if (elementDefinitions.length > 1) {
BaseRuntimeElementDefinition containedDefinition = compositeDefinition.getChildByName("contained").getChildByName("contained");
BaseRuntimeElementDefinition[] containedDefinitions = new BaseRuntimeElementDefinition[elementDefinitions.length];
containedDefinitions[0] = containedDefinition;
System.arraycopy(elementDefinitions, 1, containedDefinitions, 1, containedDefinitions.length - 1);
containedFieldSetter = child.result().toHapiConverter(containedDefinitions);
}
return new StructureField<>("contained", "contained", null, false, false, containedFieldSetter);
} else if (child.extensionUrl() != null) {
// Handle extensions.
BaseRuntimeChildDefinition childDefinition = compositeDefinition.getChildByName("extension");
childConverter = child.result().toHapiConverter(childDefinition.getChildByName("extension"));
} else {
String propertyName = child.propertyName();
// Append the [x] suffix for choice properties.
if (child.isChoice()) {
propertyName = propertyName + "[x]";
}
BaseRuntimeChildDefinition childDefinition = compositeDefinition.getChildByName(propertyName);
BaseRuntimeElementDefinition[] childElementDefinitions;
if (child.isChoice()) {
int childCount = childDefinition.getValidChildNames().size();
childElementDefinitions = new BaseRuntimeElementDefinition[childCount];
int index = 0;
for (String childName : childDefinition.getValidChildNames()) {
childDefinition.getChildByName(childName);
childElementDefinitions[index++] = childDefinition.getChildByName(childName);
}
} else {
childElementDefinitions = new BaseRuntimeElementDefinition[] { childDefinition.getChildByName(propertyName) };
}
childConverter = child.result().toHapiConverter(childElementDefinitions);
}
return new StructureField<>(child.propertyName(), child.fieldName(), child.extensionUrl(), child.isModifier(), child.isChoice(), childConverter);
}).collect(Collectors.toList());
return new CompositeFieldSetter(compositeDefinition, toHapiChildren);
}
Aggregations