diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java index 6801a25bfd6..84779865bf4 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/BundleUtil.java @@ -25,6 +25,7 @@ import ca.uhn.fhir.context.BaseRuntimeElementDefinition; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.i18n.Msg; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.api.PatchTypeEnum; @@ -595,6 +596,16 @@ public class BundleUtil { return retVal; } + public static void setSearchModeMetadata(FhirContext theContext, IBaseBundle theBundle) { + List searchBundleEntryParts = getSearchBundleEntryParts(theContext, theBundle); + searchBundleEntryParts.forEach(searchBundleEntryPart -> { + IBaseResource resource = searchBundleEntryPart.getResource(); + if (resource != null) { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, searchBundleEntryPart.getSearchMode()); + } + }); + } + private static SearchBundleEntryParts getSearchBundleEntryParts( BaseRuntimeChildDefinition theFullUrlChildDef, BaseRuntimeChildDefinition theResourceChildDef, diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java index 8b8e00f0d6c..38933276b58 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/GenericClient.java @@ -128,6 +128,7 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.NotModifiedException; +import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.ICallable; import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.UrlUtil; @@ -582,7 +583,7 @@ public class GenericClient extends BaseClient implements IGenericClient { myLastRequest = theInvocation.asHttpRequest(getServerBase(), theParams, getEncoding(), myPrettyPrint); } - Z resp = invokeClient( + return invokeClient( myContext, theHandler, theInvocation, @@ -594,7 +595,6 @@ public class GenericClient extends BaseClient implements IGenericClient { myCacheControlDirective, myCustomAcceptHeaderValue, myCustomHeaderValues); - return resp; } protected IBaseResource parseResourceBody(String theResourceBody) { @@ -2198,7 +2198,13 @@ public class GenericClient extends BaseClient implements IGenericClient { myContext, myResourceName, params, resourceId, myCompartmentName, mySearchStyle); } - return (OUTPUT) invoke(params, binding, invocation); + OUTPUT invoke = (OUTPUT) invoke(params, binding, invocation); + + if (invoke instanceof IBaseBundle) { + BundleUtil.setSearchModeMetadata(myContext, (IBaseBundle) invoke); + } + + return invoke; } @Override