private static boolean payloadContainsNoPlaceholderReferences(FhirContext theCtx, IBaseResource theNewPayload) { List<ResourceReferenceInfo> refs = theCtx.newTerser().getAllResourceReferences(theNewPayload); for (ResourceReferenceInfo next : refs) { String ref = next.getResourceReference().getReferenceElement().getValue(); if (isBlank(ref)) { IBaseResource resource = next.getResourceReference().getResource(); if (resource != null) { ref = resource.getIdElement().getValue(); } } if (isNotBlank(ref)) { if (ref.startsWith("#")) { continue; } if (ref.startsWith("urn:uuid:")) { throw new AssertionError("Reference at " + next.getName() + " is invalid: " + ref); } } } return true; }
public static String parseContentTextIntoWords(FhirContext theContext, IBaseResource theResource) { StringBuilder retVal = new StringBuilder(); @SuppressWarnings("rawtypes") List<IPrimitiveType> childElements = theContext.newTerser().getAllPopulatedChildElementsOfType(theResource, IPrimitiveType.class); for (@SuppressWarnings("rawtypes") IPrimitiveType nextType : childElements) { if (nextType instanceof StringDt || nextType.getClass().getSimpleName().equals("StringType")) { String nextValue = nextType.getValueAsString(); if (isNotBlank(nextValue)) { retVal.append(nextValue.replace("\n", " ").replace("\r", " ")); retVal.append("\n"); } } } return retVal.toString(); }
public Object getSingleValueOrNull(IBase theTarget, String thePath) { Class<Object> wantedType = Object.class; return getSingleValueOrNull(theTarget, thePath, wantedType); }
/** * Returns values stored in an element identified by its path. The list of values is of * type <code>theWantedClass</code>. * * @param theResource The resource instance to be accessed. Must not be null. * @param thePath The path for the element to be accessed. * @param theWantedClass The desired class to be returned in a list. * @param <T> Type declared by <code>theWantedClass</code> * @return A list of values of type <code>theWantedClass</code>. */ public <T> List<T> getValues(IBaseResource theResource, String thePath, Class<T> theWantedClass) { RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource); List<String> parts = parsePath(def, thePath); return getValues(def, theResource, parts, theWantedClass); }
List<Object> parameters = t.getValues(theInput, "Parameters.parameter"); IPrimitiveType<?> nextNameDt = (IPrimitiveType<?>) t.getSingleValueOrNull((IBase) nextParameter, "name"); if (nextNameDt == null || nextNameDt.isEmpty()) { ourLog.warn("Ignoring input parameter with no value in Parameters.parameter.name in operation client invocation"); IBaseDatatype value = (IBaseDatatype) t.getSingleValueOrNull((IBase) nextParameter, "value[x]"); if (value == null) { continue;
extensionDts.add(createEmptyExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensions.add(createEmptyExtension((IBaseHasExtensions) theCurrentObj, extensionUrl)); extensions.add(createEmptyExtension((IBaseHasExtensions) theCurrentObj, extensionUrl)); for (T nextElement : values) { BaseRuntimeElementCompositeDefinition<?> nextChildDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition((Class<? extends IBase>) nextElement.getClass()); List<T> foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass, theCreate, theAddExtension); retVal.addAll(foundValues); extensionDts.add(createEmptyModifierExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyModifierExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensions.add(createEmptyModifierExtension((IBaseHasModifierExtensions) theCurrentObj, extensionUrl)); extensions.add(createEmptyModifierExtension((IBaseHasModifierExtensions) theCurrentObj, extensionUrl));
List<ResourceReferenceInfo> allRefs = terser.getAllResourceReferences(nextResource); for (ResourceReferenceInfo nextRef : allRefs) { IIdType nextId = nextRef.getResourceReference().getReferenceElement(); List<? extends IPrimitiveType<?>> allUris = terser.getAllPopulatedChildElementsOfType(nextResource, uriType); for (IPrimitiveType<?> nextRef : allUris) { if (nextRef instanceof IIdType) {
/** * Returns values stored in an element identified by its path. The list of values is of * type {@link Object}. * * @param theResource The resource instance to be accessed. Must not be null. * @param thePath The path for the element to be accessed. * @return A list of values of type {@link Object}. */ public List<Object> getValues(IBaseResource theResource, String thePath) { Class<Object> wantedClass = Object.class; return getValues(theResource, thePath, wantedClass); }
private BaseRuntimeChildDefinition getDefinition(BaseRuntimeElementCompositeDefinition<?> theCurrentDef, List<String> theSubList) { BaseRuntimeChildDefinition nextDef = theCurrentDef.getChildByNameOrThrowDataFormatException(theSubList.get(0)); if (theSubList.size() == 1) { return nextDef; } BaseRuntimeElementCompositeDefinition<?> cmp = (BaseRuntimeElementCompositeDefinition<?>) nextDef.getChildByName(theSubList.get(0)); return getDefinition(cmp, theSubList.subList(1, theSubList.size())); }
FhirTerser terser = myContext.newTerser(); IBase newTarget = targetTypeDef.newInstance(); terser.cloneInto((IBase) nextValue, newTarget, true); theMatchingParamValues.add(newTarget); continue;
List<ResourceReferenceInfo> allRefs = terser.getAllResourceReferences(nextResource); for (ResourceReferenceInfo nextRef : allRefs) { IIdType nextId = nextRef.getResourceReference().getReferenceElement(); List<? extends IPrimitiveType<?>> allUris = terser.getAllPopulatedChildElementsOfType(nextResource, uriType); for (IPrimitiveType<?> nextRef : allUris) { if (nextRef instanceof IIdType) {
/** * Returns values stored in an element identified by its path. The list of values is of * type <code>theWantedClass</code>. * * @param theResource The resource instance to be accessed. Must not be null. * @param thePath The path for the element to be accessed. * @param theWantedClass The desired class to be returned in a list. * @param theCreate When set to <code>true</code>, the terser will create a null-valued element where none exists. * @param <T> Type declared by <code>theWantedClass</code> * @return A list of values of type <code>theWantedClass</code>. */ public <T> List<T> getValues(IBaseResource theResource, String thePath, Class<T> theWantedClass, boolean theCreate) { RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource); List<String> parts = parsePath(def, thePath); return getValues(def, theResource, parts, theWantedClass, theCreate, false); }
/** * Returns values stored in an element identified by its path. The list of values is of * type {@link Object}. * * @param theResource The resource instance to be accessed. Must not be null. * @param thePath The path for the element to be accessed. * @param theCreate When set to <code>true</code>, the terser will create a null-valued element where none exists. * @return A list of values of type {@link Object}. */ public List<Object> getValues(IBaseResource theResource, String thePath, boolean theCreate) { Class<Object> wantedClass = Object.class; return getValues(theResource, thePath, wantedClass, theCreate); }
List<Object> parameters = t.getValues(theInput, "Parameters.parameter"); IPrimitiveType<?> nextNameDt = (IPrimitiveType<?>) t.getSingleValueOrNull((IBase) nextParameter, "name"); if (nextNameDt == null || nextNameDt.isEmpty()) { ourLog.warn("Ignoring input parameter with no value in Parameters.parameter.name in operation client invocation"); IBaseDatatype value = (IBaseDatatype) t.getSingleValueOrNull((IBase) nextParameter, "value[x]"); if (value == null) { continue;
extensionDts.add(createEmptyExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensions.add(createEmptyExtension((IBaseHasExtensions) theCurrentObj, extensionUrl)); extensions.add(createEmptyExtension((IBaseHasExtensions) theCurrentObj, extensionUrl)); for (T nextElement : values) { BaseRuntimeElementCompositeDefinition<?> nextChildDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition((Class<? extends IBase>) nextElement.getClass()); List<T> foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass, theCreate, theAddExtension); retVal.addAll(foundValues); extensionDts.add(createEmptyModifierExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyModifierExtensionDt((ISupportsUndeclaredExtensions) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensionDts.add(createEmptyExtensionDt((IBaseExtension) theCurrentObj, extensionUrl)); extensions.add(createEmptyModifierExtension((IBaseHasModifierExtensions) theCurrentObj, extensionUrl)); extensions.add(createEmptyModifierExtension((IBaseHasModifierExtensions) theCurrentObj, extensionUrl));
public BaseRuntimeChildDefinition getDefinition(Class<? extends IBaseResource> theResourceType, String thePath) { RuntimeResourceDefinition def = myContext.getResourceDefinition(theResourceType); BaseRuntimeElementCompositeDefinition<?> currentDef = def; List<String> parts = Arrays.asList(thePath.split("\\.")); List<String> subList = parts.subList(1, parts.size()); if (subList.size() < 1) { throw new ConfigurationException("Invalid path: " + thePath); } return getDefinition(currentDef, subList); }
cloneInto(nextValue, target, theIgnoreMissingFields);
for (ResourceReferenceInfo nextRef : ctx.newTerser().getAllResourceReferences(nextCandidateSource)) { String nextRefResourceType = nextRef.getResourceReference().getReferenceElement().getResourceType(); String nextRefIdPart = nextRef.getResourceReference().getReferenceElement().getIdPart();
static List<IBaseResource> toListOfResourcesAndExcludeContainer(IBaseResource theResponseObject, FhirContext fhirContext) { if (theResponseObject == null) { return Collections.emptyList(); } List<IBaseResource> retVal; boolean isContainer = false; if (theResponseObject instanceof IBaseBundle) { isContainer = true; } else if (theResponseObject instanceof IBaseParameters) { isContainer = true; } if (!isContainer) { return Collections.singletonList(theResponseObject); } retVal = fhirContext.newTerser().getAllPopulatedChildElementsOfType(theResponseObject, IBaseResource.class); // Exclude the container if (retVal.size() > 0 && retVal.get(0) == theResponseObject) { retVal = retVal.subList(1, retVal.size()); } return retVal; }
/** * Returns values stored in an element identified by its path. The list of values is of * type <code>theWantedClass</code>. * * @param theResource The resource instance to be accessed. Must not be null. * @param thePath The path for the element to be accessed. * @param theWantedClass The desired class to be returned in a list. * @param theCreate When set to <code>true</code>, the terser will create a null-valued element where none exists. * @param theAddExtension When set to <code>true</code>, the terser will add a null-valued extension where one or more such extensions already exist. * @param <T> Type declared by <code>theWantedClass</code> * @return A list of values of type <code>theWantedClass</code>. */ public <T> List<T> getValues(IBaseResource theResource, String thePath, Class<T> theWantedClass, boolean theCreate, boolean theAddExtension) { RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource); List<String> parts = parsePath(def, thePath); return getValues(def, theResource, parts, theWantedClass, theCreate, theAddExtension); }