Skip to content

Commit df19da6

Browse files
authored
fix: update deprecated notificationconfig for healthcare api (#9523)
* fix: update deprecated notificationconfig for healthcare api * fix lint
1 parent 37004b9 commit df19da6

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

healthcare/v1/src/main/java/snippets/healthcare/fhir/FhirStorePatch.java

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import com.google.api.services.healthcare.v1.CloudHealthcare;
2525
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.FhirStores;
2626
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
27+
import com.google.api.services.healthcare.v1.model.FhirNotificationConfig;
2728
import com.google.api.services.healthcare.v1.model.FhirStore;
28-
import com.google.api.services.healthcare.v1.model.NotificationConfig;
2929
import com.google.auth.http.HttpCredentialsAdapter;
3030
import com.google.auth.oauth2.GoogleCredentials;
3131
import java.io.IOException;
@@ -38,51 +38,58 @@ public class FhirStorePatch {
3838

3939
public static void fhirStorePatch(String fhirStoreName, String pubsubTopic) throws IOException {
4040
// String fhirStoreName =
41-
// String.format(
42-
// FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");
41+
// String.format(
42+
// FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id",
43+
// "your-fhir-id");
4344
// String pubsubTopic = "projects/your-project-id/topics/your-pubsub-topic";
4445

4546
// Initialize the client, which will be used to interact with the service.
4647
CloudHealthcare client = createClient();
4748

4849
// Fetch the initial state of the FHIR store.
49-
FhirStores.Get getRequest =
50-
client.projects().locations().datasets().fhirStores().get(fhirStoreName);
50+
FhirStores.Get getRequest = client
51+
.projects()
52+
.locations()
53+
.datasets()
54+
.fhirStores()
55+
.get(fhirStoreName);
5156
FhirStore store = getRequest.execute();
5257

53-
// Update the FhirStore fields as needed as needed. For a full list of FhirStore fields, see:
58+
// Update the FhirStore fields as needed as needed. For a full list of FhirStore
59+
// fields, see:
5460
// https://cloud.google.com/healthcare/docs/reference/rest/v1/projects.locations.datasets.fhirStores#FhirStore
55-
store.setNotificationConfig(new NotificationConfig().setPubsubTopic(pubsubTopic));
61+
FhirNotificationConfig notificationConfig = new FhirNotificationConfig()
62+
.setPubsubTopic(pubsubTopic);
63+
store.setNotificationConfigs(Collections.singletonList(notificationConfig));
5664

5765
// Create request and configure any parameters.
58-
FhirStores.Patch request =
59-
client
60-
.projects()
61-
.locations()
62-
.datasets()
63-
.fhirStores()
64-
.patch(fhirStoreName, store)
65-
.setUpdateMask("notificationConfig");
66+
FhirStores.Patch request = client
67+
.projects()
68+
.locations()
69+
.datasets()
70+
.fhirStores()
71+
.patch(fhirStoreName, store)
72+
.setUpdateMask("notificationConfigs");
6673

6774
// Execute the request and process the results.
6875
store = request.execute();
69-
System.out.println("Fhir store patched: \n" + store.toPrettyString());
76+
System.out.println("FHIR store patched: \n" + store.toPrettyString());
7077
}
7178

7279
private static CloudHealthcare createClient() throws IOException {
7380
// Use Application Default Credentials (ADC) to authenticate the requests
74-
// For more information see https://cloud.google.com/docs/authentication/production
75-
GoogleCredentials credential =
76-
GoogleCredentials.getApplicationDefault()
77-
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
81+
// For more information see
82+
// https://cloud.google.com/docs/authentication/production
83+
GoogleCredentials credential = GoogleCredentials.getApplicationDefault()
84+
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
7885

79-
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
80-
HttpRequestInitializer requestInitializer =
81-
request -> {
82-
new HttpCredentialsAdapter(credential).initialize(request);
83-
request.setConnectTimeout(60000); // 1 minute connect timeout
84-
request.setReadTimeout(60000); // 1 minute read timeout
85-
};
86+
// Create a HttpRequestInitializer, which will provide a baseline configuration
87+
// to all requests.
88+
HttpRequestInitializer requestInitializer = request -> {
89+
new HttpCredentialsAdapter(credential).initialize(request);
90+
request.setConnectTimeout(60000); // 1 minute connect timeout
91+
request.setReadTimeout(60000); // 1 minute read timeout
92+
};
8693

8794
// Build the client for interacting with the service.
8895
return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)

healthcare/v1/src/test/java/snippets/healthcare/FhirStoreTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ public static void checkRequirements() {
7676
@BeforeClass
7777
public static void setUp() throws IOException {
7878
String datasetId = "dataset-" + UUID.randomUUID().toString().replaceAll("-", "_");
79-
datasetName =
80-
String.format("projects/%s/locations/%s/datasets/%s", PROJECT_ID, REGION_ID, datasetId);
79+
datasetName = String.format(
80+
"projects/%s/locations/%s/datasets/%s",
81+
PROJECT_ID,
82+
REGION_ID,
83+
datasetId);
8184
DatasetCreate.datasetCreate(PROJECT_ID, REGION_ID, datasetId);
8285
}
8386

@@ -159,7 +162,7 @@ public void test_FhirStorePatch() throws Exception {
159162
FhirStorePatch.fhirStorePatch(fhirStoreName, GCLOUD_PUBSUB_TOPIC);
160163

161164
String output = bout.toString();
162-
assertThat(output, containsString("Fhir store patched:"));
165+
assertThat(output, containsString("FHIR store patched:"));
163166
}
164167

165168
@Test

0 commit comments

Comments
 (0)