ca.uhn.fhir.context.BaseRuntimeChildDefinition Java Examples

The following examples show how to use ca.uhn.fhir.context.BaseRuntimeChildDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MeasureOperationsProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
private void resolveReferences(Resource resource, Parameters parameters, Map<String, Resource> resourceMap) {
    List<IBase> values;
    for (BaseRuntimeChildDefinition child : this.measureResourceProvider.getContext().getResourceDefinition(resource).getChildren()) {
        values = child.getAccessor().getValues(resource);
        if (values == null || values.isEmpty()) {
            continue;
        }

        else if (values.get(0) instanceof Reference
                && ((Reference) values.get(0)).getReferenceElement().hasResourceType()
                && ((Reference) values.get(0)).getReferenceElement().hasIdPart()) {
            Resource fetchedResource = (Resource) registry
                    .getResourceDao(((Reference) values.get(0)).getReferenceElement().getResourceType())
                    .read(new IdType(((Reference) values.get(0)).getReferenceElement().getIdPart()));

            if (!resourceMap.containsKey(fetchedResource.getIdElement().getValue())) {
                parameters.addParameter(new Parameters.ParametersParameterComponent().setName("resource")
                        .setResource(fetchedResource));

                resourceMap.put(fetchedResource.getIdElement().getValue(), fetchedResource);
            }
        }
    }
}
 
Example #2
Source File: MeasureOperationsProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
private void resolveReferences(Resource resource, Parameters parameters, Map<String, Resource> resourceMap) {
    List<IBase> values;
    for (BaseRuntimeChildDefinition child : this.measureResourceProvider.getContext().getResourceDefinition(resource).getChildren()) {
        values = child.getAccessor().getValues(resource);
        if (values == null || values.isEmpty()) {
            continue;
        }

        else if (values.get(0) instanceof Reference
                && ((Reference) values.get(0)).getReferenceElement().hasResourceType()
                && ((Reference) values.get(0)).getReferenceElement().hasIdPart()) {
            Resource fetchedResource = (Resource) registry
                    .getResourceDao(((Reference) values.get(0)).getReferenceElement().getResourceType())
                    .read(new IdType(((Reference) values.get(0)).getReferenceElement().getIdPart()));

            if (!resourceMap.containsKey(fetchedResource.getIdElement().getValue())) {
                parameters.addParameter(new Parameters.ParametersParameterComponent().setName("resource")
                        .setResource(fetchedResource));

                resourceMap.put(fetchedResource.getIdElement().getValue(), fetchedResource);
            }
        }
    }
}
 
Example #3
Source File: FhirModelResolver.java    From cql_engine with Apache License 2.0 6 votes vote down vote up
public Object getContextPath(String contextType, String targetType) {
    if (targetType == null || contextType == null ) {
        return null;
    }

    if (contextType != null && !(contextType.equals("Unspecified") || contextType.equals("Population"))) {
        if (targetType != null && contextType.equals(targetType)) {
            return "id";
        }

        RuntimeResourceDefinition resourceDefinition = this.fhirContext.getResourceDefinition(targetType);
        Object theValue = this.createInstance(contextType);
        Class<? extends IBase> type = (Class<? extends IBase>)theValue.getClass();

        List<BaseRuntimeChildDefinition> children = resourceDefinition.getChildren();
        for (BaseRuntimeChildDefinition child : children) {

            String path = this.innerGetContextPath(child, type);
            if (path != null) {
                return path;
            }
        }
    }

    return null;
}
 
Example #4
Source File: HapiChoiceConverter.java    From bunsen with Apache License 2.0 6 votes vote down vote up
@Override
public void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object composite) {

  Iterator<Entry<String, HapiFieldSetter>> setterIterator =
      choiceFieldSetters.entrySet().iterator();

  // Co-iterate with an index so we place the correct values into the corresponding locations.
  for (int valueIndex = 0; valueIndex < choiceTypes.size(); ++valueIndex) {

    Map.Entry<String, HapiFieldSetter> setterEntry = setterIterator.next();

    if (getChild(composite, valueIndex) != null) {

      HapiFieldSetter setter = setterEntry.getValue();

      setter.setField(parentObject, fieldToSet, getChild(composite, valueIndex));

      // We set a non-null field for the choice type, so stop looking.
      break;
    }
  }
}
 
Example #5
Source File: DefinitionToAvroVisitor.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Override
public void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object element) {

  for (Object value: (Iterable) element) {

    Object hapiObject = elementToHapiConverter.toHapi(value);

    fieldToSet.getMutator().addValue(parentObject, (IBase) hapiObject);
  }
}
 
Example #6
Source File: FhirModelResolver.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
protected BaseRuntimeChildDefinition resolveChoiceProperty(BaseRuntimeElementCompositeDefinition<?> definition, String path) {
    for (Object child :  definition.getChildren()) {
        if (child instanceof RuntimeChildChoiceDefinition) {
            RuntimeChildChoiceDefinition choiceDefinition = (RuntimeChildChoiceDefinition) child;

            if (choiceDefinition.getElementName().startsWith(path)) {
                return choiceDefinition;
            }
        }
    }

    return null;
}
 
Example #7
Source File: HapiContainedConverter.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Override
public void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object object) {

  List<ContainerEntry> containedEntries = getContained(object);

  for (ContainerEntry containedEntry: containedEntries) {

    String containedElementType = containedEntry.getElementType();
    IBase resource = contained.get(containedElementType).toHapi(containedEntry.getElement());

    fieldToSet.getMutator().addValue(parentObject, resource);
  }
}
 
Example #8
Source File: PrimitiveConverter.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Override
public void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object object) {

  IPrimitiveType element = (IPrimitiveType) elementDefinition
      .newInstance(fieldToSet.getInstanceConstructorArguments());

  PrimitiveConverter.this.toHapi(object, element);

  fieldToSet.getMutator().setValue(parentObject, element);
}
 
Example #9
Source File: HapiCompositeConverter.java    From bunsen with Apache License 2.0 5 votes vote down vote up
@Override
public void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object sourceObject) {

  IBase fhirObject = toHapi(sourceObject);

  if (extensionUrl != null) {

    fieldToSet.getMutator().addValue(parentObject, fhirObject);

  } else {
    fieldToSet.getMutator().setValue(parentObject, fhirObject);
  }
}
 
Example #10
Source File: DefinitionToSparkVisitor.java    From bunsen with Apache License 2.0 4 votes vote down vote up
@Override
public void setField(IBase parentObject, BaseRuntimeChildDefinition fieldToSet,
    Object sparkObject) {}
 
Example #11
Source File: HapiCompositeConverter.java    From bunsen with Apache License 2.0 4 votes vote down vote up
@Override
public void setField(IBase parentObject, BaseRuntimeChildDefinition fieldToSet,
    Object sourceObject) {}
 
Example #12
Source File: DefinitionToAvroVisitor.java    From bunsen with Apache License 2.0 4 votes vote down vote up
@Override
public void setField(IBase parentObject, BaseRuntimeChildDefinition fieldToSet,
    Object sparkObject) {

}
 
Example #13
Source File: FhirModelResolver.java    From cql_engine with Apache License 2.0 4 votes vote down vote up
@Override
public void setValue(Object target, String path, Object value) {
    if (target == null) {
        return;
    }

    if (target instanceof IBaseEnumeration && path.equals("value")) {
        ((IBaseEnumeration)target).setValueAsString((String)value);
        return;
    }

    IBase base = (IBase) target;
    BaseRuntimeElementCompositeDefinition<?> definition;
    if (base instanceof IPrimitiveType) {
        ((IPrimitiveType) target).setValue(fromJavaPrimitive(value, base));
        return;
    }
    else {
        definition = resolveRuntimeDefinition(base);
    }

    BaseRuntimeChildDefinition child = definition.getChildByName(path);
    if (child == null) {
        child = resolveChoiceProperty(definition, path);
    }

    if (child == null) {
        throw new DataProviderException(String.format("Unable to resolve path %s.", path));
    }

    try {
        if (value instanceof Iterable) {
            for (Object val : (Iterable<?>) value) {
                child.getMutator().addValue(base, (IBase) fromJavaPrimitive(val, base));
            }
        }
        else {
            child.getMutator().setValue(base, (IBase) fromJavaPrimitive(value, base));
        }
    } catch (IllegalArgumentException le) {
        if (value.getClass().getSimpleName().equals("Quantity")) {
            try {
                value = this.castToSimpleQuantity((BaseType) value);
            } catch (FHIRException e) {
                throw new InvalidCast("Unable to cast Quantity to SimpleQuantity");
            }
            child.getMutator().setValue(base, (IBase) fromJavaPrimitive(value, base));
        }
        else {
            throw new DataProviderException(String.format("Configuration error encountered: %s", le.getMessage()));
        }
    }
}
 
Example #14
Source File: FhirModelResolver.java    From cql_engine with Apache License 2.0 4 votes vote down vote up
protected Object resolveProperty(Object target, String path) {
    if (target == null) {
        return null;
    }

    if (target instanceof IBaseEnumeration && path.equals("value")) {
        return ((IBaseEnumeration) target).getValueAsString();
    }


    // TODO: Consider using getResourceType everywhere?
    if (target instanceof IAnyResource && this.getResourceType((ResourceType) target).equals(path)) {
        return target;
    }

    IBase base = (IBase) target;
    BaseRuntimeElementCompositeDefinition<?> definition;
    if (base instanceof IPrimitiveType) {
        return toJavaPrimitive(path.equals("value") ? ((IPrimitiveType<?>) target).getValue() : target, base);
    }
    else {
        definition = resolveRuntimeDefinition(base);
    }

    BaseRuntimeChildDefinition child = definition.getChildByName(path);
    if (child == null) {
        child = resolveChoiceProperty(definition, path);
    }

    if (child == null) {
        return null;
    }

    List<IBase> values = child.getAccessor().getValues(base);

    if (values == null || values.isEmpty()) {
        return null;
    }

    if (child instanceof RuntimeChildChoiceDefinition && !child.getElementName().equalsIgnoreCase(path)) {
        if (!values.get(0).getClass().getSimpleName().equalsIgnoreCase(child.getChildByName(path).getImplementingClass().getSimpleName()))
        {
            return null;
        }
    }

    return toJavaPrimitive(child.getMax() < 1 ? values : values.get(0), base);
}
 
Example #15
Source File: StringToHapiSetter.java    From bunsen with Apache License 2.0 4 votes vote down vote up
@Override
public void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object sparkObject) {
  fieldToSet.getMutator().setValue(parentObject, toHapi(sparkObject));
}
 
Example #16
Source File: LeafExtensionConverter.java    From bunsen with Apache License 2.0 3 votes vote down vote up
@Override
public void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object sparkObject) {

  IBase hapiObject = valuetoHapiConverter.toHapi(sparkObject);

  IBaseExtension extension = (IBaseExtension) elementDefinition.newInstance(extensionUrl);

  extension.setValue((IBaseDatatype) hapiObject);

  fieldToSet.getMutator().addValue(parentObject, extension);
}
 
Example #17
Source File: HapiConverter.java    From bunsen with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the value to the corresponding field on a FHIR object.
 *
 * @param parentObject the composite object getting its field set
 * @param fieldToSet the runtime definition of the field to set.
 * @param value the value to be converted and set on the FHIR object.
 */
void setField(IBase parentObject,
    BaseRuntimeChildDefinition fieldToSet,
    Object value);
 
Example #18
Source File: NoOpConverter.java    From bunsen with Apache License 2.0 2 votes vote down vote up
@Override
public void setField(IBase parentObject, BaseRuntimeChildDefinition fieldToSet, Object value) {

}