public static List<String> getNamedParameterValuesAsString(FhirContext theCtx, IBaseParameters theParameters, String theParameterName) { Validate.notNull(theParameters, "theParameters must not be null"); RuntimeResourceDefinition resDef = theCtx.getResourceDefinition(theParameters.getClass()); BaseRuntimeChildDefinition parameterChild = resDef.getChildByName("parameter"); List<IBase> parameterReps = parameterChild.getAccessor().getValues(theParameters); List<String> retVal = new ArrayList<>(); for (IBase nextParameter : parameterReps) { BaseRuntimeElementCompositeDefinition<?> nextParameterDef = (BaseRuntimeElementCompositeDefinition<?>) theCtx.getElementDefinition(nextParameter.getClass()); BaseRuntimeChildDefinition nameChild = nextParameterDef.getChildByName("name"); List<IBase> nameValues = nameChild.getAccessor().getValues(nextParameter); Optional<? extends IPrimitiveType<?>> nameValue = nameValues .stream() .filter(t -> t instanceof IPrimitiveType<?>) .map(t -> ((IPrimitiveType<?>) t)) .findFirst(); if (!nameValue.isPresent() || !theParameterName.equals(nameValue.get().getValueAsString())) { continue; } BaseRuntimeChildDefinition valueChild = nextParameterDef.getChildByName("value[x]"); List<IBase> valueValues = valueChild.getAccessor().getValues(nextParameter); valueValues .stream() .filter(t->t instanceof IPrimitiveType<?>) .map(t->((IPrimitiveType<?>)t).getValueAsString()) .filter(StringUtils::isNotBlank) .forEach(retVal::add); } return retVal; }
BaseRuntimeElementCompositeDefinition<?> targetDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(theTarget.getClass()); List<BaseRuntimeChildDefinition> children = sourceDef.getChildren(); if (sourceDef instanceof RuntimeExtensionDtDefinition) { children = ((RuntimeExtensionDtDefinition) sourceDef).getChildrenIncludingUrl(); for (IBase nextValue : nextChild.getAccessor().getValues(theSource)) { String elementName = nextChild.getChildNameByDatatype(nextValue.getClass()); BaseRuntimeChildDefinition targetChild = targetDef.getChildByName(elementName); if (targetChild == null) { if (theIgnoreMissingFields) {
private void copyChildren(BaseRuntimeElementCompositeDefinition<?> theSourceDef, IBase theSource, BaseRuntimeElementCompositeDefinition<?> theTargetDef, IBase theTarget) { if (!theSource.isEmpty()) { List<BaseRuntimeChildDefinition> targetChildren = theTargetDef.getChildren(); List<RuntimeChildDeclaredExtensionDefinition> targetExts = theTargetDef.getExtensions(); BaseRuntimeChildDefinition sourceChildEquivalent = theSourceDef.getChildByNameOrThrowDataFormatException(elementName); if (sourceChildEquivalent == null) { continue;
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> orderToExtensionDef = new TreeMap<>(); scanCompositeElementForChildren(elementNames, orderToElementDef, orderToExtensionDef); BaseRuntimeChildDefinition nextChild = orderToElementDef.get(i); if (nextChild != null) { this.addChild(nextChild); this.addExtension((RuntimeChildDeclaredExtensionDefinition) nextExt);
private static IBase createParameterRepetition(FhirContext theContext, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem, String theName) { IBase parameter = paramChildElem.newInstance(); paramChild.getMutator().addValue(theTargetResource, parameter); IPrimitiveType<?> value; value = createString(theContext, theName); paramChildElem.getChildByName("name").getMutator().addValue(parameter, value); return parameter; }
for (BaseRuntimeChildDefinition nextChildDef : cdef.getChildren()) {
private static IBase createIssue(FhirContext theCtx, IBaseResource theOutcome) { RuntimeResourceDefinition ooDef = theCtx.getResourceDefinition(theOutcome); BaseRuntimeChildDefinition issueChild = ooDef.getChildByName("issue"); BaseRuntimeElementCompositeDefinition<?> issueElement = (BaseRuntimeElementCompositeDefinition<?>) issueChild.getChildByName("issue"); IBase issue = issueElement.newInstance(); issueChild.getMutator().addValue(theOutcome, issue); return issue; }
private Map<RuntimeChildDeclaredExtensionDefinition, String> scanForExtensions(Profile theProfile, BaseRuntimeElementDefinition<?> def, Map<RuntimeChildDeclaredExtensionDefinition, String> theExtensionDefToCode) { BaseRuntimeElementCompositeDefinition<?> cdef = ((BaseRuntimeElementCompositeDefinition<?>) def); for (RuntimeChildDeclaredExtensionDefinition nextChild : cdef.getExtensions()) { if (theExtensionDefToCode.containsKey(nextChild)) { continue;
@SuppressWarnings("unchecked") private void addParam(String theName, IBase theValue) { BaseRuntimeChildDefinition parameterChild = myParametersDef.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> parameterElem = (BaseRuntimeElementCompositeDefinition<?>) parameterChild.getChildByName("parameter"); IBase parameter = parameterElem.newInstance(); parameterChild.getMutator().addValue(myParameters, parameter); IPrimitiveType<String> name = (IPrimitiveType<String>) myContext.getElementDefinition("string").newInstance(); name.setValue(theName); parameterElem.getChildByName("name").getMutator().setValue(parameter, name); if (theValue instanceof IBaseDatatype) { BaseRuntimeElementDefinition<?> datatypeDef = myContext.getElementDefinition(theValue.getClass()); if (datatypeDef instanceof IRuntimeDatatypeDefinition) { Class<? extends IBaseDatatype> profileOf = ((IRuntimeDatatypeDefinition) datatypeDef).getProfileOf(); if (profileOf != null) { datatypeDef = myContext.getElementDefinition(profileOf); } } String childElementName = "value" + StringUtils.capitalize(datatypeDef.getName()); BaseRuntimeChildDefinition childByName = parameterElem.getChildByName(childElementName); childByName.getMutator().setValue(parameter, theValue); } else if (theValue instanceof IBaseResource) { parameterElem.getChildByName("resource").getMutator().setValue(parameter, theValue); } else { throw new IllegalArgumentException("Don't know how to handle parameter of type " + theValue.getClass()); } }
for (BaseRuntimeChildDefinition nextChildDef : cdef.getChildren()) {
TreeMap<Integer, BaseRuntimeDeclaredChildDefinition> orderToExtensionDef = new TreeMap<>(); scanCompositeElementForChildren(elementNames, orderToElementDef, orderToExtensionDef); BaseRuntimeChildDefinition nextChild = orderToElementDef.get(i); if (nextChild != null) { this.addChild(nextChild); this.addExtension((RuntimeChildDeclaredExtensionDefinition) nextExt);
private static IBase createIssue(FhirContext theCtx, IBaseResource theOutcome) { RuntimeResourceDefinition ooDef = theCtx.getResourceDefinition(theOutcome); BaseRuntimeChildDefinition issueChild = ooDef.getChildByName("issue"); BaseRuntimeElementCompositeDefinition<?> issueElement = (BaseRuntimeElementCompositeDefinition<?>) issueChild.getChildByName("issue"); IBase issue = issueElement.newInstance(); issueChild.getMutator().addValue(theOutcome, issue); return issue; }
private static void addClientParameter(FhirContext theContext, Object theValue, IBaseResource theTargetResource, BaseRuntimeChildDefinition paramChild, BaseRuntimeElementCompositeDefinition<?> paramChildElem, String theName) { if (theValue instanceof IBaseResource) { IBase parameter = createParameterRepetition(theContext, theTargetResource, paramChild, paramChildElem, theName); paramChildElem.getChildByName("resource").getMutator().addValue(parameter, (IBaseResource) theValue); } else if (theValue instanceof IBaseDatatype) { IBase parameter = createParameterRepetition(theContext, theTargetResource, paramChild, paramChildElem, theName); paramChildElem.getChildByName("value[x]").getMutator().addValue(parameter, (IBaseDatatype) theValue); } else if (theValue instanceof Collection) { Collection<?> collection = (Collection<?>) theValue; for (Object next : collection) { addClientParameter(theContext, next, theTargetResource, paramChild, paramChildElem, theName); } } else { throw new IllegalArgumentException("Don't know how to handle value of type " + theValue.getClass() + " for parameter " + theName); } }
@SuppressWarnings("unchecked") private T readHtmlResponse(InputStream theResponseInputStream) { RuntimeResourceDefinition resDef = getFhirContext().getResourceDefinition(myReturnType); IBaseResource instance = resDef.newInstance(); BaseRuntimeChildDefinition textChild = resDef.getChildByName("text"); BaseRuntimeElementCompositeDefinition<?> textElement = (BaseRuntimeElementCompositeDefinition<?>) textChild.getChildByName("text"); IBase textInstance = textElement.newInstance(); textChild.getMutator().addValue(instance, textInstance); BaseRuntimeChildDefinition divChild = textElement.getChildByName("div"); BaseRuntimeElementDefinition<?> divElement = divChild.getChildByName("div"); IPrimitiveType<?> divInstance = (IPrimitiveType<?>) divElement.newInstance(); try { divInstance.setValueAsString(IOUtils.toString(theResponseInputStream, Charsets.UTF_8)); } catch (Exception e) { throw new InvalidResponseException(400, "Failed to process HTML response from server: " + e.getMessage(), e); } divChild.getMutator().addValue(textInstance, divInstance); return (T) instance; }
BaseRuntimeElementCompositeDefinition<?> targetDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(theTarget.getClass()); List<BaseRuntimeChildDefinition> children = sourceDef.getChildren(); if (sourceDef instanceof RuntimeExtensionDtDefinition) { children = ((RuntimeExtensionDtDefinition) sourceDef).getChildrenIncludingUrl(); for (IBase nextValue : nextChild.getAccessor().getValues(theSource)) { String elementName = nextChild.getChildNameByDatatype(nextValue.getClass()); BaseRuntimeChildDefinition targetChild = targetDef.getChildByName(elementName); if (targetChild == null) { if (theIgnoreMissingFields) {
private void copyChildren(BaseRuntimeElementCompositeDefinition<?> theSourceDef, IBase theSource, BaseRuntimeElementCompositeDefinition<?> theTargetDef, IBase theTarget) { if (!theSource.isEmpty()) { List<BaseRuntimeChildDefinition> targetChildren = theTargetDef.getChildren(); List<RuntimeChildDeclaredExtensionDefinition> targetExts = theTargetDef.getExtensions(); BaseRuntimeChildDefinition sourceChildEquivalent = theSourceDef.getChildByNameOrThrowDataFormatException(elementName); if (sourceChildEquivalent == null) { continue;
for (BaseRuntimeChildDefinition nextChild : cdef.getChildren()) { if (nextChild instanceof RuntimeChildUndeclaredExtensionDefinition) { continue;
private void minimizeResource(IBaseResource theInput) { if (theInput instanceof IBaseBundle) { for (IBaseResource next : BundleUtil.toListOfResources(myCtx, (IBaseBundle) theInput)) { minimizeResource(next); } } BaseRuntimeElementCompositeDefinition<?> element = (BaseRuntimeElementCompositeDefinition) myCtx.getElementDefinition(theInput.getClass()); BaseRuntimeChildDefinition textElement = element.getChildByName("text"); if (textElement != null) { textElement.getMutator().setValue(theInput, null); } }
IBase parameter = paramChildElem.newInstance(); paramChild.getMutator().addValue(parameters, parameter); BaseRuntimeChildDefinition resourceElem = paramChildElem.getChildByName("resource"); resourceElem.getMutator().addValue(parameter, (IBase) retVal);
private static String getFirstIssueStringPart(FhirContext theCtx, IBaseOperationOutcome theOutcome, String name) { if (theOutcome == null) { return null; } RuntimeResourceDefinition ooDef = theCtx.getResourceDefinition(theOutcome); BaseRuntimeChildDefinition issueChild = ooDef.getChildByName("issue"); List<IBase> issues = issueChild.getAccessor().getValues(theOutcome); if (issues.isEmpty()) { return null; } IBase issue = issues.get(0); BaseRuntimeElementCompositeDefinition<?> issueElement = (BaseRuntimeElementCompositeDefinition<?>) theCtx.getElementDefinition(issue.getClass()); BaseRuntimeChildDefinition detailsChild = issueElement.getChildByName(name); List<IBase> details = detailsChild.getAccessor().getValues(issue); if (details.isEmpty()) { return null; } return ((IPrimitiveType<?>) details.get(0)).getValueAsString(); }