Search in sources :

Example 1 with RuntimeElemContainedResourceList

use of ca.uhn.fhir.context.RuntimeElemContainedResourceList 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);
}
Also used : IBaseHasExtensions(org.hl7.fhir.instance.model.api.IBaseHasExtensions) IBaseHasModifierExtensions(org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions) Iterator(java.util.Iterator) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) IBase(org.hl7.fhir.instance.model.api.IBase) RuntimeElemContainedResourceList(ca.uhn.fhir.context.RuntimeElemContainedResourceList) IBaseExtension(org.hl7.fhir.instance.model.api.IBaseExtension) Collectors(java.util.stream.Collectors) IAnyResource(org.hl7.fhir.instance.model.api.IAnyResource) List(java.util.List) BaseRuntimeChildDefinition(ca.uhn.fhir.context.BaseRuntimeChildDefinition) Map(java.util.Map) BaseRuntimeElementCompositeDefinition(ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) RuntimeElemContainedResourceList(ca.uhn.fhir.context.RuntimeElemContainedResourceList) BaseRuntimeElementCompositeDefinition(ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition) BaseRuntimeChildDefinition(ca.uhn.fhir.context.BaseRuntimeChildDefinition)

Aggregations

BaseRuntimeChildDefinition (ca.uhn.fhir.context.BaseRuntimeChildDefinition)1 BaseRuntimeElementCompositeDefinition (ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition)1 BaseRuntimeElementDefinition (ca.uhn.fhir.context.BaseRuntimeElementDefinition)1 RuntimeElemContainedResourceList (ca.uhn.fhir.context.RuntimeElemContainedResourceList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 IAnyResource (org.hl7.fhir.instance.model.api.IAnyResource)1 IBase (org.hl7.fhir.instance.model.api.IBase)1 IBaseExtension (org.hl7.fhir.instance.model.api.IBaseExtension)1 IBaseHasExtensions (org.hl7.fhir.instance.model.api.IBaseHasExtensions)1 IBaseHasModifierExtensions (org.hl7.fhir.instance.model.api.IBaseHasModifierExtensions)1