Store healthcare data with client libraries
This page shows you how to use the Cloud Healthcare API and the Google API Client Libraries to complete the following tasks:
- Create a Cloud Healthcare API dataset.
- Create one of the following data stores inside the dataset:
- Digital Imaging and Communications in Medicine (DICOM) store
- Fast Healthcare Interoperability Resources (FHIR) store
- Health Level Seven International Version 2 (HL7v2) store
- Store and inspect a particular type of medical data in the DICOM, FHIR, or HL7v2 store.
If you're only interested in working with one type of data store, you can skip directly to that section of the quickstart after completing the steps in Before you begin and Create a dataset.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Healthcare API:
gcloud services enable healthcare.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/healthcare.datasetAdmin, roles/healthcare.fhirStoreAdmin, roles/healthcare.dicomStoreAdmin, roles/healthcare.hl7V2StoreAdmin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Cloud Healthcare API:
gcloud services enable healthcare.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/healthcare.datasetAdmin, roles/healthcare.fhirStoreAdmin, roles/healthcare.dicomStoreAdmin, roles/healthcare.hl7V2StoreAdmin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
Install the client libraries
The following samples show how to install the Google API Client Libraries:
Go
For information on configuring a Go development environment, see Setting up a Go development environment.
go get google.golang.org/api/healthcare/v1
Java
For information on configuring a Java development environment, see Setting up a Java development environment.
If you're using Maven, add the following
to your pom.xml
file using the version in the
https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/healthcare/v1/pom.xml
file.
For example, in the following configuration, replace VERSION
with the version in the file:
<dependencyManagement> <dependencies> <dependency> <groupId>com.google.cloud</groupId> <artifactId>libraries-bom</artifactId> <version>26.18.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.google.apis</groupId> <artifactId>google-api-services-healthcare</artifactId> <version>VERSION</version> </dependency> </dependencies>
Node.js
For information on configuring a Node.js development environment, see Setting up a Node.js development environment.
npm install @googleapis/healthcare
Python
For information on configuring a Python development environment, see Setting up a Python development environment.
# Use a virtual environment as shown in the Python development environment guide.
pip install --upgrade google-api-python-client
Create a dataset
Datasets contain data stores, and data stores contain healthcare data. To use the Cloud Healthcare API, you must create at least one dataset.
Run the following sample to create a dataset. You use this dataset throughout this quickstart.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset location
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To complete this quickstart, choose from one of the following sections:
Store and view a DICOM instance
This section shows how to complete the following tasks:
- Create a DICOM store.
- Store a DICOM instance in the DICOM store.
- View the DICOM instance's metadata.
The Cloud Healthcare API implements the DICOMweb standard to store and access medical imaging data.
Create a DICOM store
Before running the samples, uncomment and provide the following values if necessary:
DICOM stores exist inside datasets and hold DICOM instances. Run the following samples to create a DICOM store.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-dicom-store
for the DICOM store ID
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Store a DICOM instance
Download the sample DICOM instance file to your machine. The file contains a de-identified patient X-ray.
curl
curl -O https://cloud.google.com/healthcare-api/docs/resources/dicom_00000001_000.dcm
PowerShell
Invoke-WebRequest -Uri "https://cloud.google.com/healthcare-api/docs/resources/dicom_00000001_000.dcm" -OutFile $pwd/dicom_00000001_000.dcm
Run the following samples to store the DICOM instance. The samples assume you're running the code from the same directory where you downloaded the DICOM instance.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-dicom-store
for the DICOM store IDdicom_00000001_000.dcm
for the DICOM file name
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
View DICOM instance metadata
Run the following samples to view the instance metadata.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-dicom-store
for the DICOM store ID
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
After storing and viewing a DICOM instance in the Cloud Healthcare API, continue to Clean up to avoid incurring charges to your Google Cloud account for the resources used on this page.
For more information on working with DICOM data, see What's next.
Store and view FHIR resources
This section shows how to complete the following tasks:
- Create a FHIR store.
- Store a FHIR resource in the FHIR store.
- View the FHIR resource's data.
The Cloud Healthcare API implements the FHIR specification standard to store and access FHIR data.
Create a FHIR store
FHIR stores exist inside datasets and hold FHIR resources. Run the following samples to create a FHIR store.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-fhir-store
for the FHIR store ID
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Store a FHIR resource
Run the following samples to store a Patient resource.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-fhir-store
for the FHIR store ID
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
View FHIR resource contents
Run the following samples to view information about the Patient resource.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-fhir-store
for the FHIR store IDPatient
for the FHIR resource type
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
After storing and viewing a FHIR resource in the Cloud Healthcare API, continue to Clean up to avoid incurring charges to your Google Cloud account for the resources used in this page.
For more information on working with FHIR data, see What's next.
Store and view an HL7v2 message
This section shows how to complete the following tasks:
- Create an HL7v2 store.
- Store an HL7v2 message in the HL7v2 store.
- View the HL7v2 message's data.
The HL7v2 implementation in the Cloud Healthcare API aligns with the HL7v2 standard.
Create an HL7v2 store
HL7v2 stores exist inside datasets and hold HL7v2 messages. Run the following samples to create an HL7v2 store.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-hl7v2-store
for the HL7v2 store ID
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Create an HL7v2 message
Download the sample HL7v2 message file to your machine:
curl
curl -O https://cloud.google.com/healthcare-api/docs/resources/hl7v2-sample.json
PowerShell
Invoke-WebRequest -Uri "https://cloud.google.com/healthcare-api/docs/resources/hl7v2-sample.json" -OutFile $pwd/hl7v2-sample.json
The HL7v2 message contains the following basic information, where it is base-64 encoded in the
data
field of the sample file:MSH|^~\&|A|SEND_FACILITY|A|A|20180101000000||TYPE^A|20180101000000|T|0.0|||AA||00|ASCII EVN|A00|20180101040000 PID||14^111^^^^MRN|11111111^^^^MRN~1111111111^^^^ORGNMBR
Run the following samples to store the HL7v2 message. The samples assume you're running the code from the same directory where you downloaded the HL7v2 message.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-hl7v2-store
for the HL7v2 store IDhl7v2-sample.json
for the HL7v2 message file name
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
The output contains an HL7v2 message ID. You need this ID in the next section.
View HL7v2 message contents
Run the following samples to view the HL7v2 message contents.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset locationmy-hl7v2-store
for the HL7v2 store ID- the ID in the response when you stored the message for the HL7v2 message ID
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
After storing and viewing an HL7v2 message in the Cloud Healthcare API, continue to Clean up to avoid incurring charges to your Google Cloud account for the resources used in this page.
For more information on working with HL7v2 data, see What's next.
Clean up
To avoid incurring charges to your Google Cloud account for the resources used on this page, delete the Google Cloud project with the resources.
If you created a new project for this quickstart, follow the steps in Delete the project. Otherwise, follow the steps in Delete the dataset.
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
Delete the project
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID
Delete the dataset
If you no longer need the dataset created in this quickstart, you can delete it. Deleting a dataset permanently deletes the dataset and any FHIR, HL7v2, or DICOM stores it contains.
Before running the samples, uncomment and provide the following values if necessary:
- the ID of the Google Cloud project that you created or selected in Before you begin for the project ID
my-dataset
for the dataset IDus-central1
for the dataset location
Go
Before trying this sample, follow the Go setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Go API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Java API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Node.js API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Healthcare API quickstart using client libraries. For more information, see the Cloud Healthcare API Python API reference documentation.
To authenticate to Cloud Healthcare API, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
How did it go?
What's next
See the following sections for general information on the Cloud Healthcare API and how to perform the tasks in this quickstart using another interface:
- Read an overview of Cloud Healthcare API concepts
- Store healthcare data with
curl
or PowerShell - Store healthcare data with the Google Cloud console
- Store healthcare data with the gcloud CLI
DICOM
- Create and manage DICOM stores
- Connect a PACS to the Cloud Healthcare API
- Use the DICOMweb standard
- Import and export DICOM data using Cloud Storage
See the DICOM conformance statement for information on how the Cloud Healthcare API implements the DICOMweb standard.
FHIR
- Create and manage FHIR stores
- Create and manage FHIR resources
- Import and export FHIR data using Cloud Storage
See the FHIR conformance statement for information on how the Cloud Healthcare API implements the FHIR standard.