-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Healthcare API snippets. (#1612)
* Add Healthcare API DICOMweb search studies by tag * Use client library. * Fix FhirStoreTests failures * Remove unnecessary .dcm file and variables. * Fix DicomStoreTests failures * Make bucket name in tests an environment variable. * Make bucket name in tests an environment variable. * Fix lint, make Storage bucket hard-coded again
- Loading branch information
Showing
4 changed files
with
100 additions
and
18 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
healthcare/v1beta1/src/main/java/snippets/healthcare/dicom/DicomWebSearchStudies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package snippets.healthcare.dicom; | ||
|
||
// [START healthcare_dicomweb_search_studies] | ||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; | ||
import com.google.api.client.http.HttpRequestInitializer; | ||
import com.google.api.client.http.HttpResponse; | ||
import com.google.api.client.http.javanet.NetHttpTransport; | ||
import com.google.api.client.json.JsonFactory; | ||
import com.google.api.client.json.jackson2.JacksonFactory; | ||
import com.google.api.services.healthcare.v1beta1.CloudHealthcare; | ||
import com.google.api.services.healthcare.v1beta1.CloudHealthcare.Projects.Locations.Datasets.DicomStores; | ||
import com.google.api.services.healthcare.v1beta1.CloudHealthcareScopes; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
public class DicomWebSearchStudies { | ||
private static final JsonFactory JSON_FACTORY = new JacksonFactory(); | ||
private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport(); | ||
|
||
public static void dicomWebSearchStudies(String dicomStoreName) throws IOException { | ||
// String dicomStoreName = | ||
// String.format( | ||
// DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id"); | ||
|
||
// Initialize the client, which will be used to interact with the service. | ||
CloudHealthcare client = createClient(); | ||
|
||
DicomStores.SearchForStudies request = | ||
client | ||
.projects() | ||
.locations() | ||
.datasets() | ||
.dicomStores() | ||
.searchForStudies(dicomStoreName, "studies") | ||
// Refine your search by appending DICOM tags to the | ||
// request in the form of query parameters. This sample | ||
// searches for studies containing a patient's name. | ||
.set("PatientName", "Sally Zhang"); | ||
|
||
// Execute the request and process the results. | ||
HttpResponse response = request.executeUnparsed(); | ||
System.out.println("Studies found: \n" + response.toString()); | ||
} | ||
|
||
private static CloudHealthcare createClient() throws IOException { | ||
// Use Application Default Credentials (ADC) to authenticate the requests | ||
// For more information see https://cloud.google.com/docs/authentication/production | ||
GoogleCredential credential = | ||
GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY) | ||
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM)); | ||
|
||
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests. | ||
HttpRequestInitializer requestInitializer = | ||
request -> { | ||
credential.initialize(request); | ||
request.setConnectTimeout(60000); // 1 minute connect timeout | ||
request.setReadTimeout(60000); // 1 minute read timeout | ||
}; | ||
|
||
// Build the client for interacting with the service. | ||
return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer) | ||
.setApplicationName("your-application-name") | ||
.build(); | ||
} | ||
} | ||
// [END healthcare_dicomweb_search_studies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters