This page describes how to export HL7v2 messages from an HL7v2 store to Cloud Storage. You can bulk export HL7v2 messages to Cloud Storage for downstream processing.
Before you begin
See Export HL7v2 messages from Cloud Storage for the roles you must grant to the Cloud Healthcare Service Agent service account.
Export HL7v2 messages to Cloud Storage
The Cloud Healthcare API exports each HL7v2 message as a
line in an NDJSON .ndjson
file. The HL7v2 messages are ordered
chronologically by their sendTime
value.
Export to a Cloud Storage bucket or folder, rather than an object, because the Cloud Healthcare API might create multiple NDJSON files when there are many HL7v2 messages.
If you export to a Cloud Storage folder that doesn't exist, the folder is created.
Console
To export HL7v2 messages to Cloud Storage, complete the following steps:
In the Google Cloud console, go to the Datasets page.
Click the dataset that contains the HL7v2 store from which you are exporting HL7v2 messages.
In the list of data stores, choose Export from the Actions list for the HL7v2 store.
The Export HL7v2 messages page appears.
In the Project list, select a Cloud Storage project.
In the Location list, select a Cloud Storage bucket.
Click Export to export HL7v2 instances to the defined location in Cloud Storage.
- To track the status of the operation, click the Operations tab. After the operation
completes, the following indications appear:
- The Long-running operation status section has a green check mark under the OK heading.
- The Overview section has a green check mark and an OK indicator in the same row as the operation ID.
Export HL7v2 messages to Cloud Storage using filters
By default, exporting HL7v2 messages to Cloud Storage includes all HL7v2
messages in an HL7v2 store and all fields in each Message
object.
You can filter the exported HL7v2 messages as follows:
- Use filters to export a subset of HL7v2 messages that match a filter criteria. For more information, see Export a subset of HL7v2 messages using a filter.
- Use the
MessageView
object to select the fields in eachMessage
to export. For more information, see Export HL7v2 messages byMessage
field.
Export a subset of HL7v2 messages using a filter
You can use the following fields in your filter criteria:
You can specify the following filter parameters as your filter criteria in the filter
field. To learn the filter
syntax and construct queries, see
Query strings.
message_type
: from the MSH.9.1 field. For example,NOT message_type = "ADT"
.send_date
: theYYYY-MM-DD
date the message was sent from the MSH.7 segment, specified in the time zone of the dataset. For example,send_date < "2017-01-02"
.send_time
: the timestamp when the message was sent. This parameter is from the MSH.7 segment of the message. This parameter uses the RFC 3339 time format for comparisons. For example,send_time < "2017-01-02T00:00:00-05:00"
.create_time
: the timestamp when the message was created in the Cloud Healthcare API, using the RFC 3339 time format for comparisons. For example:create_time < "2017-01-02T00:00:00-05:00"
.send_facility
: the care center that the message came from, from the MSH.4 segment. For example,send_facility = "ABC"
.
The following samples show how to specify a filter to only export HL7v2 messages
of type ADT
.
REST
Use the
hl7V2Stores.export
method to export the HL7v2 messages:Before using any of the request data, make the following replacements:
PROJECT_ID
: the ID of your Google Cloud projectLOCATION
: the dataset locationDATASET_ID
: the HL7v2 store's parent datasetHL7V2_STORE_ID
: the HL7v2 store IDCLOUD_STORAGE_LOCATION
: the name of a Cloud Storage bucket or folder where exported HL7v2 messages are written
Request JSON body:
{ "gcsDestination": { "uriPrefix": "gs://CLOUD_STORAGE_LOCATION" }, "filter": "message_type = \"ADT\"" }
To send your request, choose one of these options:
curl
Save the request body in a file named
request.json
. Run the following command in the terminal to create or overwrite this file in the current directory:cat > request.json << 'EOF' { "gcsDestination": { "uriPrefix": "gs://CLOUD_STORAGE_LOCATION" }, "filter": "message_type = \"ADT\"" } EOF
Then execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID:export"PowerShell
Save the request body in a file named
request.json
. Run the following command in the terminal to create or overwrite this file in the current directory:@' { "gcsDestination": { "uriPrefix": "gs://CLOUD_STORAGE_LOCATION" }, "filter": "message_type = \"ADT\"" } '@ | Out-File -FilePath request.json -Encoding utf8
Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID:export" | Select-Object -Expand ContentOPERATION_ID
. You need this value in the next step.Use the
projects.locations.datasets.operations.get
method to get the status of the long-running operation.Before using any of the request data, make the following replacements:
PROJECT_ID
: the ID of your Google Cloud projectDATASET_ID
: the dataset IDLOCATION
: the dataset locationOPERATION_ID
: the ID returned from the long-running operation
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID"PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID" | Select-Object -Expand ContentAPIs Explorer
Open the method reference page. The APIs Explorer panel opens on the right side of the page. You can interact with this tool to send requests. Complete any required fields and click Execute.
"done": true
, the long-running operation has finished.
Export HL7v2 messages by Message
field
In the Cloud Healthcare API, HL7v2 messages are stored in Message
resources. You can use the MessageView
enum to determine which fields in the Message
resource are included in
each exported HL7v2 message.
The following samples show how to use the
BASIC
value in MessageView
to only include the name
field in the exported HL7v2 messages.
REST
Use the
hl7V2Stores.export
method to export the HL7v2 messages:Before using any of the request data, make the following replacements:
PROJECT_ID
: the ID of your Google Cloud projectLOCATION
: the dataset locationDATASET_ID
: the HL7v2 store's parent datasetHL7V2_STORE_ID
: the HL7v2 store IDCLOUD_STORAGE_LOCATION
: the name of a Cloud Storage bucket or folder where exported HL7v2 messages are written
Request JSON body:
{ "gcsDestination": { "uriPrefix": "gs://CLOUD_STORAGE_LOCATION", "messageView": "BASIC" } }
To send your request, choose one of these options:
curl
Save the request body in a file named
request.json
. Run the following command in the terminal to create or overwrite this file in the current directory:cat > request.json << 'EOF' { "gcsDestination": { "uriPrefix": "gs://CLOUD_STORAGE_LOCATION", "messageView": "BASIC" } } EOF
Then execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID:export"PowerShell
Save the request body in a file named
request.json
. Run the following command in the terminal to create or overwrite this file in the current directory:@' { "gcsDestination": { "uriPrefix": "gs://CLOUD_STORAGE_LOCATION", "messageView": "BASIC" } } '@ | Out-File -FilePath request.json -Encoding utf8
Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID:export" | Select-Object -Expand ContentOPERATION_ID
. You need this value in the next step.Use the
projects.locations.datasets.operations.get
method to get the status of the long-running operation.Before using any of the request data, make the following replacements:
PROJECT_ID
: the ID of your Google Cloud projectDATASET_ID
: the dataset IDLOCATION
: the dataset locationOPERATION_ID
: the ID returned from the long-running operation
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID"PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/operations/OPERATION_ID" | Select-Object -Expand ContentAPIs Explorer
Open the method reference page. The APIs Explorer panel opens on the right side of the page. You can interact with this tool to send requests. Complete any required fields and click Execute.
"done": true
, the long-running operation has finished.
Troubleshoot HL7v2 export requests
If errors occur while exporting HL7v2 messages, the errors are logged to Cloud Logging. For more information, see Viewing error logs in Cloud Logging.
If a long-running operation returns an error, see Troubleshooting long-running operations.