From f6e84ea8011d329aa0ff7c25ab83e07981fdb77c Mon Sep 17 00:00:00 2001 From: Melih Aydogdu Date: Mon, 27 May 2024 09:37:55 +0200 Subject: [PATCH 1/3] search entry mode added to metadata of bundle entries --- .../java/ca/uhn/fhir/rest/client/impl/GenericClient.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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..ae0cd079306 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,9 +128,11 @@ 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; +import ca.uhn.fhir.util.bundle.SearchBundleEntryParts; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -594,6 +596,13 @@ public class GenericClient extends BaseClient implements IGenericClient { myCacheControlDirective, myCustomAcceptHeaderValue, myCustomHeaderValues); + + if (resp instanceof IBaseBundle) { + List searchBundleEntryParts = + BundleUtil.getSearchBundleEntryParts(getFhirContext(), (IBaseBundle) resp); + searchBundleEntryParts.forEach(searchBundleEntryPart -> ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put( + searchBundleEntryPart.getResource(), searchBundleEntryPart.getSearchMode())); + } return resp; } From f9a522e15809d85a71972b383cf4762b08368210 Mon Sep 17 00:00:00 2001 From: Melih Aydogdu Date: Mon, 27 May 2024 15:00:08 +0200 Subject: [PATCH 2/3] null check added --- .../java/ca/uhn/fhir/rest/client/impl/GenericClient.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 ae0cd079306..364a3283dda 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 @@ -600,8 +600,12 @@ public class GenericClient extends BaseClient implements IGenericClient { if (resp instanceof IBaseBundle) { List searchBundleEntryParts = BundleUtil.getSearchBundleEntryParts(getFhirContext(), (IBaseBundle) resp); - searchBundleEntryParts.forEach(searchBundleEntryPart -> ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put( - searchBundleEntryPart.getResource(), searchBundleEntryPart.getSearchMode())); + searchBundleEntryParts.forEach(searchBundleEntryPart -> { + IBaseResource resource = searchBundleEntryPart.getResource(); + if (resource != null) { + ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, searchBundleEntryPart.getSearchMode()); + } + }); } return resp; } From 38b5b12322863b05745000f5828b6fd5a7b1ee08 Mon Sep 17 00:00:00 2001 From: Melih Aydogdu Date: Mon, 27 May 2024 16:06:23 +0200 Subject: [PATCH 3/3] moved to search internal --- .../java/ca/uhn/fhir/util/BundleUtil.java | 11 +++++++++ .../fhir/rest/client/impl/GenericClient.java | 23 +++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) 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 f0872b62287..54be26ee52b 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; @@ -588,6 +589,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 fullUrlChildDef, BaseRuntimeChildDefinition resourceChildDef, 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 364a3283dda..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 @@ -132,7 +132,6 @@ import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.ICallable; import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.UrlUtil; -import ca.uhn.fhir.util.bundle.SearchBundleEntryParts; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -584,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, @@ -596,18 +595,6 @@ public class GenericClient extends BaseClient implements IGenericClient { myCacheControlDirective, myCustomAcceptHeaderValue, myCustomHeaderValues); - - if (resp instanceof IBaseBundle) { - List searchBundleEntryParts = - BundleUtil.getSearchBundleEntryParts(getFhirContext(), (IBaseBundle) resp); - searchBundleEntryParts.forEach(searchBundleEntryPart -> { - IBaseResource resource = searchBundleEntryPart.getResource(); - if (resource != null) { - ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(resource, searchBundleEntryPart.getSearchMode()); - } - }); - } - return resp; } protected IBaseResource parseResourceBody(String theResourceBody) { @@ -2211,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