public static IBaseReference getSecurityContext(FhirContext theCtx, IBaseBinary theBinary) { RuntimeResourceDefinition def = theCtx.getResourceDefinition("Binary"); BaseRuntimeChildDefinition child = def.getChildByName("securityContext"); IBaseReference retVal = null; if (child != null) { List<IBase> values = child.getAccessor().getValues(theBinary); if (values.size() > 0) { retVal = (IBaseReference) values.get(0); } } return retVal; }
public static List<String> getBaseAsStrings(FhirContext theContext, IBaseResource theResource) { Validate.notNull(theContext, "theContext must not be null"); Validate.notNull(theResource, "theResource must not be null"); RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource); BaseRuntimeChildDefinition base = def.getChildByName("base"); List<IBase> baseValues = base.getAccessor().getValues(theResource); List<String> retVal = new ArrayList<>(); for (IBase next : baseValues) { IPrimitiveType<?> nextPrimitive = (IPrimitiveType<?>) next; retVal.add(nextPrimitive.getValueAsString()); } return retVal; }
/** * Returns true if the given OperationOutcome has 1 or more Operation.issue repetitions */ public static boolean hasIssues(FhirContext theCtx, IBaseOperationOutcome theOutcome) { if (theOutcome == null) { return false; } RuntimeResourceDefinition ooDef = theCtx.getResourceDefinition(theOutcome); BaseRuntimeChildDefinition issueChild = ooDef.getChildByName("issue"); return issueChild.getAccessor().getValues(theOutcome).size() > 0; }
public static String getBundleType(FhirContext theContext, IBaseBundle theBundle) { RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle); BaseRuntimeChildDefinition entryChild = def.getChildByName("type"); List<IBase> entries = entryChild.getAccessor().getValues(theBundle); if (entries.size() > 0) { IPrimitiveType<?> typeElement = (IPrimitiveType<?>) entries.get(0); return typeElement.getValueAsString(); } return null; }
public static Integer getTotal(FhirContext theContext, IBaseBundle theBundle) { RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle); BaseRuntimeChildDefinition entryChild = def.getChildByName("total"); List<IBase> entries = entryChild.getAccessor().getValues(theBundle); if (entries.size() > 0) { IPrimitiveType<Number> typeElement = (IPrimitiveType<Number>) entries.get(0); if (typeElement != null && typeElement.getValue() != null) { return typeElement.getValue().intValue(); } } return null; }
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; }
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(); }
/** * Extract all of the resources of a given type from a given bundle */ @SuppressWarnings("unchecked") public static <T extends IBaseResource> List<T> toListOfResourcesOfType(FhirContext theContext, IBaseBundle theBundle, Class<T> theTypeToInclude) { List<T> retVal = new ArrayList<>(); RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle); BaseRuntimeChildDefinition entryChild = def.getChildByName("entry"); List<IBase> entries = entryChild.getAccessor().getValues(theBundle); BaseRuntimeElementCompositeDefinition<?> entryChildElem = (BaseRuntimeElementCompositeDefinition<?>) entryChild.getChildByName("entry"); BaseRuntimeChildDefinition resourceChild = entryChildElem.getChildByName("resource"); for (IBase nextEntry : entries) { for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) { if (theTypeToInclude != null && !theTypeToInclude.isAssignableFrom(next.getClass())) { continue; } retVal.add((T) next); } } return retVal; }
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle); BaseRuntimeChildDefinition entryChild = def.getChildByName("entry"); List<IBase> entries = entryChild.getAccessor().getValues(theBundle); IBaseResource resource = null; for (IBase nextEntryValue : requestChild.getAccessor().getValues(nextEntry)) { for (IBase nextUrlValue : urlChild.getAccessor().getValues(nextEntryValue)) { url = ((IPrimitiveType<String>)nextUrlValue).getValue(); for (IBase nextValue : resourceChild.getAccessor().getValues(nextEntry)) { resource = (IBaseResource) nextValue;
private <T extends IBaseBundle> IGetPageTyped<T> nextOrPrevious(String theWantRel, T theBundle) { RuntimeResourceDefinition def = myContext.getResourceDefinition(theBundle); List<IBase> links = def.getChildByName("link").getAccessor().getValues(theBundle); if (links == null || links.isEmpty()) { throw new IllegalArgumentException(myContext.getLocalizer().getMessage(GenericClient.class, "noPagingLinkFoundInBundle", theWantRel)); } for (IBase nextLink : links) { BaseRuntimeElementCompositeDefinition linkDef = (BaseRuntimeElementCompositeDefinition) myContext.getElementDefinition(nextLink.getClass()); List<IBase> rel = linkDef.getChildByName("relation").getAccessor().getValues(nextLink); if (rel == null || rel.isEmpty()) { continue; } String relation = ((IPrimitiveType<?>) rel.get(0)).getValueAsString(); if (theWantRel.equals(relation) || (theWantRel == PREVIOUS && PREV.equals(relation))) { List<IBase> urls = linkDef.getChildByName("url").getAccessor().getValues(nextLink); if (urls == null || urls.isEmpty()) { continue; } String url = ((IPrimitiveType<?>) urls.get(0)).getValueAsString(); if (isBlank(url)) { continue; } return (IGetPageTyped<T>) byUrl(url).andReturnBundle(theBundle.getClass()); } } throw new IllegalArgumentException(myContext.getLocalizer().getMessage(GenericClient.class, "noPagingLinkFoundInBundle", theWantRel)); }
BaseRuntimeChildDefinition resourceChild = paramChildElem.getChildByName("resource"); IAccessor paramChildAccessor = paramChild.getAccessor(); List<IBase> values = paramChildAccessor.getValues(requestContents); for (IBase nextParameter : values) { matchingParamValues.add(nextParameter); } else { List<IBase> paramValues = valueChild.getAccessor().getValues(nextParameter); List<IBase> paramResources = resourceChild.getAccessor().getValues(nextParameter); if (paramValues != null && paramValues.size() > 0) { tryToAddValues(paramValues, matchingParamValues);
RuntimeResourceDefinition def = theContext.getResourceDefinition(theBundle); BaseRuntimeChildDefinition entryChild = def.getChildByName("link"); List<IBase> links = entryChild.getAccessor().getValues(theBundle); for (IBase nextLink : links) { BaseRuntimeElementCompositeDefinition relDef = (BaseRuntimeElementCompositeDefinition) theContext.getElementDefinition(nextLink.getClass()); BaseRuntimeChildDefinition relChild = relDef.getChildByName("relation"); List<IBase> relValues = relChild.getAccessor().getValues(nextLink); for (IBase next : relValues) { IPrimitiveType<?> nextValue = (IPrimitiveType<?>)next; List<IBase> values = urlChild.getAccessor().getValues(nextLink); for (IBase nextUrl : values) { IPrimitiveType<?> nextValue = (IPrimitiveType<?>)nextUrl;
List<IBase> entries = entryChild.getAccessor().getValues(theBundle); RequestTypeEnum requestType = null; for (IBase next : resourceChild.getAccessor().getValues(nextEntry)) { resource = (IBaseResource) next; for (IBase nextRequest : requestChild.getAccessor().getValues(nextEntry)) { for (IBase nextUrl : urlChild.getAccessor().getValues(nextRequest)) { url = ((IPrimitiveType<?>)nextUrl).getValueAsString(); for (IBase nextUrl : methodChild.getAccessor().getValues(nextRequest)) { String methodString = ((IPrimitiveType<?>)nextUrl).getValueAsString(); if (isNotBlank(methodString)) {
} else { BaseRuntimeChildDefinition metaChild = myFhirContext.getResourceDefinition(myResourceType).getChildByName("meta"); List<IBase> metaValues = metaChild.getAccessor().getValues(theResource); if (metaValues.size() > 0) { IBase meta = metaValues.get(0); BaseRuntimeElementCompositeDefinition<?> metaDef = (BaseRuntimeElementCompositeDefinition<?>) myFhirContext.getElementDefinition(meta.getClass()); BaseRuntimeChildDefinition versionIdDef = metaDef.getChildByName("versionId"); List<IBase> versionIdValues = versionIdDef.getAccessor().getValues(meta); if (versionIdValues.size() > 0) { IPrimitiveType<?> versionId = (IPrimitiveType<?>) versionIdValues.get(0);
private static void populatePrimitiveValue(FhirContext theContext, IBaseResource theSubscription, String theChildName, String theValue) { RuntimeResourceDefinition def = theContext.getResourceDefinition(theSubscription); Validate.isTrue(def.getName().equals("Subscription"), "theResource is not a subscription"); BaseRuntimeChildDefinition statusChild = def.getChildByName(theChildName); List<IBase> entries = statusChild.getAccessor().getValues(theSubscription); IPrimitiveType<?> instance; if (entries.size() == 0) { BaseRuntimeElementDefinition<?> statusElement = statusChild.getChildByName(theChildName); instance = (IPrimitiveType<?>) statusElement.newInstance(statusChild.getInstanceConstructorArguments()); statusChild.getMutator().addValue(theSubscription, instance); } else { instance = (IPrimitiveType<?>) entries.get(0); } instance.setValueAsString(theValue); }
for (IBase nextValue : nextChild.getAccessor().getValues(theSource)) { String elementName = nextChild.getChildNameByDatatype(nextValue.getClass()); BaseRuntimeChildDefinition targetChild = targetDef.getChildByName(elementName);
@SuppressWarnings("unchecked") @Override public T invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType); if (respType == null) { throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseInputStream); } IParser parser = respType.newParser(myContext); RuntimeResourceDefinition type = myContext.getResourceDefinition("Parameters"); IBaseResource retVal = parser.parseResource(type.getImplementingClass(), theResponseInputStream); BaseRuntimeChildDefinition paramChild = type.getChildByName("parameter"); BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter"); List<IBase> parameter = paramChild.getAccessor().getValues(retVal); if (parameter == null || parameter.isEmpty()) { return (T) myContext.getElementDefinition(myType).newInstance(); } IBase param = parameter.get(0); List<IBase> meta = paramChildElem.getChildByName("value[x]").getAccessor().getValues(param); if (meta.isEmpty()) { return (T) myContext.getElementDefinition(myType).newInstance(); } return (T) meta.get(0); } }
for (BaseRuntimeChildDefinition nextChildDef : cdef.getChildren()) { List<IBase> values = nextChildDef.getAccessor().getValues(theElement); if (values == null || values.isEmpty()) { continue;
List<IBase> entries = entryChild.getAccessor().getValues(retVal); if (entries != null) { for (IBase nextEntry : entries) { List<IBase> fullUrl = fullUrlChild.getAccessor().getValues(nextEntry); if (fullUrl != null && !fullUrl.isEmpty()) { IPrimitiveType<?> value = (IPrimitiveType<?>) fullUrl.get(0); if (value.isEmpty() == false) { List<IBase> entryResources = entryDef.getChildByName("resource").getAccessor().getValues(nextEntry); if (entryResources != null && entryResources.size() > 0) { IBaseResource res = (IBaseResource) entryResources.get(0);
List<? extends IBase> sourceValues = sourceChildEquivalent.getAccessor().getValues(theSource); for (IBase nextElement : sourceValues) { boolean handled = false;