You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by pa...@apache.org on 2022/04/26 22:05:20 UTC

[beam] branch master updated: FhirIO: use .search() or .searchType instead of .setResourceType()

This is an automated email from the ASF dual-hosted git repository.

pabloem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 4a3d1ac20db FhirIO: use .search() or .searchType instead of .setResourceType()
     new 287cb9f2dca Merge pull request #17315 from [BEAM-14280] FhirIO: use .search() or .searchType() instead of SearchResourceRequest.setResourceType()
4a3d1ac20db is described below

commit 4a3d1ac20db3e90d72f26af5d1f720dcb3f88478
Author: msbukal@google.com <ms...@google.com>
AuthorDate: Thu Apr 7 16:44:59 2022 -0400

    FhirIO: use .search() or .searchType instead of .setResourceType()
    
    The .setResourceType(...) behaviour is unintended on the generated client library, and is potentially unstable.
---
 .../io/gcp/healthcare/HttpHealthcareApiClient.java | 25 ++++++++++++++++++----
 .../beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java | 16 +++++++++-----
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
index 1b09ff49d10..cb70069bfaf 100644
--- a/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
+++ b/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/healthcare/HttpHealthcareApiClient.java
@@ -26,8 +26,8 @@ import com.google.api.client.json.JsonFactory;
 import com.google.api.client.json.jackson2.JacksonFactory;
 import com.google.api.services.healthcare.v1.CloudHealthcare;
 import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores.Fhir.PatientEverything;
-import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores.Fhir.Search;
 import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.Hl7V2Stores.Messages;
+import com.google.api.services.healthcare.v1.CloudHealthcareRequest;
 import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
 import com.google.api.services.healthcare.v1.model.CreateMessageRequest;
 import com.google.api.services.healthcare.v1.model.DeidentifyConfig;
@@ -648,9 +648,26 @@ public class HttpHealthcareApiClient implements HealthcareApiClient, Serializabl
       @Nullable Map<String, Object> parameters,
       String pageToken)
       throws IOException {
-    SearchResourcesRequest request = new SearchResourcesRequest().setResourceType(resourceType);
-    Search search =
-        client.projects().locations().datasets().fhirStores().fhir().search(fhirStore, request);
+    CloudHealthcareRequest<HttpBody> search;
+    if (Strings.isNullOrEmpty(resourceType)) {
+      search =
+          client
+              .projects()
+              .locations()
+              .datasets()
+              .fhirStores()
+              .fhir()
+              .search(fhirStore, new SearchResourcesRequest());
+    } else {
+      search =
+          client
+              .projects()
+              .locations()
+              .datasets()
+              .fhirStores()
+              .fhir()
+              .searchType(fhirStore, resourceType, new SearchResourcesRequest());
+    }
     if (parameters != null && !parameters.isEmpty()) {
       parameters.forEach(search::set);
     }
diff --git a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java
index 7a56fd43fb5..682a7ce11f0 100644
--- a/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java
+++ b/sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/FhirIOSearchIT.java
@@ -29,8 +29,8 @@ import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import org.apache.beam.runners.direct.DirectOptions;
 import org.apache.beam.sdk.coders.ListCoder;
 import org.apache.beam.sdk.coders.StringUtf8Coder;
@@ -95,16 +95,22 @@ public class FhirIOSearchIT {
 
     JsonArray fhirResources =
         JsonParser.parseString(bundles.get(0)).getAsJsonObject().getAsJsonArray("entry");
-    HashMap<String, String> searchParameters = new HashMap<>();
-    searchParameters.put("_count", Integer.toString(50));
-    HashMap<String, List<Integer>> genericSearchParameters = new HashMap<>();
-    genericSearchParameters.put("_count", Arrays.asList(50));
+    Map<String, String> searchParameters = ImmutableMap.of("_count", "50");
+    Map<String, List<Integer>> genericSearchParameters =
+        ImmutableMap.of("_count", Arrays.asList(50));
+
+    // Include a non-resource type search.
+    input.add(FhirSearchParameter.of("", KEY, searchParameters));
+    genericParametersInput.add(FhirSearchParameter.of("", genericSearchParameters));
+
     int searches = 0;
     for (JsonElement resource : fhirResources) {
       String resourceType =
           resource.getAsJsonObject().getAsJsonObject("resource").get("resourceType").getAsString();
+
       input.add(FhirSearchParameter.of(resourceType, KEY, searchParameters));
       genericParametersInput.add(FhirSearchParameter.of(resourceType, genericSearchParameters));
+
       searches++;
       if (searches > MAX_NUM_OF_SEARCHES) {
         break;