Skip to content

Commit 42df115

Browse files
authored
Add Healthcare samples for Dataset operations. (GoogleCloudPlatform#1372)
* Add Healthcare samples for Dataset operations.
1 parent 788979d commit 42df115

File tree

70 files changed

+6896
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+6896
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
$cred = gcloud auth print-access-token
16+
$headers = @{ Authorization = "Bearer $cred" }
17+
18+
Invoke-RestMethod `
19+
-Method Get `
20+
-Headers $headers `
21+
-ContentType: "application/json; charset=utf-8" `
22+
-Uri "https://healthcare.googleapis.com/v1alpha1/projects/dzlier-work/locations/us-central1/datasets/dataset-13c3/dicomStores/dicom-store-13c3/dicomWeb/instances"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
curl -X GET \
16+
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
17+
-H "Content-Type: application/dicom+json; charset=utf-8" \
18+
"https://healthcare.googleapis.com/v1beta1/projects/dzlier-work/locations/us-central1/datasets/dataset-13c3/dicomStores/dicom-store-13c3/dicomWeb/instances"

healthcare/v1beta1/pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.google.samples</groupId>
7+
<artifactId>healthcare-samples</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<!--
12+
The parent pom defines common style checks and testing strategies for our samples.
13+
Removing or replacing it should not affect the execution of the samples in anyway.
14+
-->
15+
<parent>
16+
<groupId>com.google.cloud.samples</groupId>
17+
<artifactId>shared-configuration</artifactId>
18+
<version>1.0.10</version>
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<maven.compiler.target>1.8</maven.compiler.target>
24+
<maven.compiler.source>1.8</maven.compiler.source>
25+
</properties>
26+
27+
<prerequisites>
28+
<maven>3.5</maven>
29+
</prerequisites>
30+
31+
<dependencies>
32+
<!-- [START dependencies] -->
33+
<dependency>
34+
<groupId>com.google.apis</groupId>
35+
<artifactId>google-api-services-healthcare</artifactId>
36+
<version>v1beta1-rev20190420-1.28.0</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.google.api-client</groupId>
40+
<artifactId>google-api-client</artifactId>
41+
<version>1.28.0</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.google.cloud</groupId>
45+
<artifactId>google-cloud-core</artifactId>
46+
<version>1.71.0</version>
47+
<scope>compile</scope>
48+
</dependency>
49+
<!-- [END dependencies] -->
50+
51+
<!-- Test dependencies -->
52+
<dependency>
53+
<groupId>com.google.truth</groupId>
54+
<artifactId>truth</artifactId>
55+
<version>0.44</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>junit</groupId>
60+
<artifactId>junit</artifactId>
61+
<version>4.12</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.apache.httpcomponents</groupId>
65+
<artifactId>httpmime</artifactId>
66+
<version>4.5.8</version>
67+
</dependency>
68+
</dependencies>
69+
</project>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package snippets.healthcare.datasets;
18+
19+
// [START healthcare_create_dataset]
20+
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
21+
import com.google.api.client.http.HttpHeaders;
22+
import com.google.api.client.http.HttpRequestInitializer;
23+
import com.google.api.client.http.javanet.NetHttpTransport;
24+
import com.google.api.client.json.JsonFactory;
25+
import com.google.api.client.json.jackson2.JacksonFactory;
26+
import com.google.api.services.healthcare.v1beta1.CloudHealthcare;
27+
import com.google.api.services.healthcare.v1beta1.CloudHealthcare.Projects.Locations.Datasets;
28+
import com.google.api.services.healthcare.v1beta1.CloudHealthcareScopes;
29+
import com.google.api.services.healthcare.v1beta1.model.Dataset;
30+
import com.google.api.services.healthcare.v1beta1.model.Operation;
31+
import java.io.IOException;
32+
import java.util.Collections;
33+
34+
public class DatasetCreate {
35+
private static final String DATASET_NAME = "projects/%s/locations/%s/datasets/%s";
36+
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
37+
private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
38+
39+
public static void datasetCreate(String projectId, String regionId, String datasetId)
40+
throws IOException {
41+
// String projectId = "your-project-id";
42+
// String regionId = "us-central1";
43+
// String datasetId = "your-dataset-id";
44+
45+
// Initialize the client, which will be used to interact with the service.
46+
CloudHealthcare client = createClient();
47+
48+
// Configure the dataset to be created.
49+
Dataset dataset = new Dataset();
50+
dataset.setTimeZone("America/Chicago");
51+
52+
// Create request and configure any parameters.
53+
String parentName = String.format("projects/%s/locations/%s", projectId, regionId);
54+
Datasets.Create request = client.projects().locations().datasets().create(parentName, dataset);
55+
request.setDatasetId(datasetId);
56+
57+
// Execute the request, wait for the operation to complete, and process the results.
58+
try {
59+
Operation operation = request.execute();
60+
System.out.println(operation.toPrettyString());
61+
while (operation.getDone() == null || !operation.getDone()) {
62+
// Update the status of the operation with another request.
63+
Thread.sleep(500); // Pause for 500ms between requests.
64+
operation =
65+
client
66+
.projects()
67+
.locations()
68+
.datasets()
69+
.operations()
70+
.get(operation.getName())
71+
.execute();
72+
}
73+
System.out.println("Dataset created. Response content: " + operation.getResponse());
74+
} catch (Exception ex) {
75+
System.out.printf("Error during request execution: %s\n", ex.toString());
76+
ex.printStackTrace(System.out);
77+
}
78+
}
79+
80+
private static CloudHealthcare createClient() throws IOException {
81+
// Use Application Default Credentials (ADC) to authenticate the requests
82+
// For more information see https://cloud.google.com/docs/authentication/production
83+
GoogleCredential credential =
84+
GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
85+
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
86+
87+
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
88+
HttpRequestInitializer requestInitializer =
89+
request -> {
90+
credential.initialize(request);
91+
request.setHeaders(new HttpHeaders().set("X-GFE-SSL", "yes"));
92+
request.setConnectTimeout(60000); // 1 minute connect timeout
93+
request.setReadTimeout(60000); // 1 minute read timeout
94+
};
95+
96+
// Build the client for interacting with the service.
97+
return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
98+
.setApplicationName("your-application-name")
99+
.build();
100+
}
101+
}
102+
// [END healthcare_create_dataset]
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package snippets.healthcare.datasets;
18+
19+
// [START healthcare_deidentify_dataset]
20+
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
21+
import com.google.api.client.http.HttpHeaders;
22+
import com.google.api.client.http.HttpRequestInitializer;
23+
import com.google.api.client.http.javanet.NetHttpTransport;
24+
import com.google.api.client.json.JsonFactory;
25+
import com.google.api.client.json.jackson2.JacksonFactory;
26+
import com.google.api.services.healthcare.v1beta1.CloudHealthcare;
27+
import com.google.api.services.healthcare.v1beta1.CloudHealthcare.Projects.Locations.Datasets;
28+
import com.google.api.services.healthcare.v1beta1.CloudHealthcareScopes;
29+
import com.google.api.services.healthcare.v1beta1.model.DeidentifyConfig;
30+
import com.google.api.services.healthcare.v1beta1.model.DeidentifyDatasetRequest;
31+
import com.google.api.services.healthcare.v1beta1.model.DicomConfig;
32+
import com.google.api.services.healthcare.v1beta1.model.Operation;
33+
import com.google.api.services.healthcare.v1beta1.model.TagFilterList;
34+
import java.io.IOException;
35+
import java.util.Arrays;
36+
import java.util.Collections;
37+
38+
public class DatasetDeIdentify {
39+
private static final String DATASET_NAME = "projects/%s/locations/%s/datasets/%s";
40+
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
41+
private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();
42+
43+
public static void datasetDeIdentify(String srcDatasetName, String destDatasetName)
44+
throws IOException {
45+
// String srcDatasetName =
46+
// String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-src-dataset-id");
47+
// String destDatasetName =
48+
// String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dest-dataset-id");
49+
50+
// Initialize the client, which will be used to interact with the service.
51+
CloudHealthcare client = createClient();
52+
53+
// Configure what information needs to be De-Identified.
54+
// For more information on de-identifying using tags, please see the following:
55+
// https://cloud.google.com/healthcare/docs/how-tos/dicom-deidentify#de-identification_using_tags
56+
TagFilterList tags = new TagFilterList().setTags(Arrays.asList("PatientID"));
57+
DicomConfig dicomConfig = new DicomConfig().setKeepList(tags);
58+
DeidentifyConfig config = new DeidentifyConfig().setDicom(dicomConfig);
59+
60+
// Create the de-identify request and configure any parameters.
61+
DeidentifyDatasetRequest deidentifyRequest =
62+
new DeidentifyDatasetRequest().setDestinationDataset(destDatasetName).setConfig(config);
63+
Datasets.Deidentify request =
64+
client.projects().locations().datasets().deidentify(srcDatasetName, deidentifyRequest);
65+
66+
// Execute the request, wait for the operation to complete, and process the results.
67+
try {
68+
Operation operation = request.execute();
69+
while (operation.getDone() == null || !operation.getDone()) {
70+
// Update the status of the operation with another request.
71+
Thread.sleep(500); // Pause for 500ms between requests.
72+
operation =
73+
client
74+
.projects()
75+
.locations()
76+
.datasets()
77+
.operations()
78+
.get(operation.getName())
79+
.execute();
80+
}
81+
System.out.println(
82+
"De-identified Dataset created. Response content: " + operation.getResponse());
83+
} catch (Exception ex) {
84+
System.out.printf("Error during request execution: %s", ex.toString());
85+
ex.printStackTrace(System.out);
86+
}
87+
}
88+
89+
private static CloudHealthcare createClient() throws IOException {
90+
// Use Application Default Credentials (ADC) to authenticate the requests
91+
// For more information see https://cloud.google.com/docs/authentication/production
92+
GoogleCredential credential =
93+
GoogleCredential.getApplicationDefault(HTTP_TRANSPORT, JSON_FACTORY)
94+
.createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));
95+
96+
// Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
97+
HttpRequestInitializer requestInitializer =
98+
request -> {
99+
credential.initialize(request);
100+
request.setHeaders(new HttpHeaders().set("X-GFE-SSL", "yes"));
101+
request.setConnectTimeout(60000); // 1 minute connect timeout
102+
request.setReadTimeout(60000); // 1 minute read timeout
103+
};
104+
105+
// Build the client for interacting with the service.
106+
return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
107+
.setApplicationName("your-application-name")
108+
.build();
109+
}
110+
}
111+
// [END healthcare_deidentify_dataset]

0 commit comments

Comments
 (0)