This page explains how to create, update, patch, view, list, retrieve, and delete FHIR resources.
A FHIR resource can contain data about a patient, a device, an observation, and more. For a full list of FHIR resources, see the FHIR Resource Index ( DSTU2 , STU3 , R4 , or R5 ).
The REST samples on this page work with an R4 FHIR store, and are not guaranteed to work if you're using a DSTU2 or STU3 FHIR store. If you're using a DSTU2 or STU3 FHIR store, see the official FHIR documentation for information on how to convert the samples to the FHIR version you're using.
The Go, Java, Node.js, and Python samples work with an STU3 FHIR store.
Creating a FHIR resource
Before you can create FHIR resources, you need to create a FHIR store .
The REST and Python samples show how to create the following FHIR resources:
- A Patient ( DSTU2 , STU3 , R4 , and R5 ) resource
- An Encounter ( DSTU2 , STU3 , R4 , and R5 ) resource for the Patient
- An Observation ( DSTU2 , STU3 , R4 , and R5 ) resource for the Encounter
The samples for all other languages show how to create a generic FHIR resource.
For more information, see  projects.locations.datasets.fhirStores.fhir.create 
 
.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
Console
To upload FHIR resource(s) using JSON to a FHIR store, complete the following steps:
- In the Google Cloud console, go to the FHIR Viewer .
- In the FHIR Store drop-down list, select a dataset, and then select a FHIR store in the dataset.
- Click the Upload tab.
- In the text area, enter a valid FHIR resource in JSON format. The following is an example: { "name": [ { "use": "official", "family": "Smith", "given": [ "Darcy" ] } ], "gender": "female", "birthDate": "1970-01-01", "resourceType": "Patient" }
- Click Save . After upload completes, you can view the resources in FHIR Viewer. See Getting a FHIR resource .
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
Request JSON body:
{
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": [
        "Darcy"
      ]
    }
  ],
  "gender": "female",
  "birthDate": "1970-01-01",
  "resourceType": "Patient"
} 
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'
{
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": [
        "Darcy"
      ]
    }
  ],
  "gender": "female",
  "birthDate": "1970-01-01",
  "resourceType": "Patient"
}
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/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Patient"
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:
@'
{
  "name": [
    {
      "use": "official",
      "family": "Smith",
      "given": [
        "Darcy"
      ]
    }
  ],
  "gender": "female",
  "birthDate": "1970-01-01",
  "resourceType": "Patient"
}
'@  | 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/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Patient" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Go
Java
Node.js
Python
After creating the Patient resource, create an Encounter resource to describe an interaction between the patient and a practitioner.
In the PATIENT_ID field, substitute the ID from the response returned by the server when you created the Patient resource.
The following REST samples work with R4 FHIR stores. The Python sample works with STU3 FHIR stores.
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- PATIENT_ID : the response returned by the server when you created the Patient resource
Request JSON body:
{ "status": "finished", "class": { "system": "http://hl7.org/fhir/v3/ActCode", "code": "IMP", "display": "inpatient encounter" }, "reasonCode": [ { "text": "The patient had an abnormal heart rate. She was concerned about this." } ], "subject": { "reference": "Patient/ PATIENT_ID " }, "resourceType": "Encounter" }
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' { "status": "finished", "class": { "system": "http://hl7.org/fhir/v3/ActCode", "code": "IMP", "display": "inpatient encounter" }, "reasonCode": [ { "text": "The patient had an abnormal heart rate. She was concerned about this." } ], "subject": { "reference": "Patient/ PATIENT_ID " }, "resourceType": "Encounter" } 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/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Encounter"
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:
@' { "status": "finished", "class": { "system": "http://hl7.org/fhir/v3/ActCode", "code": "IMP", "display": "inpatient encounter" }, "reasonCode": [ { "text": "The patient had an abnormal heart rate. She was concerned about this." } ], "subject": { "reference": "Patient/ PATIENT_ID " }, "resourceType": "Encounter" } '@ | 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/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Encounter" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
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 creating the Encounter resource, create an Observation resource associated with the Encounter resource. The Observation resource provides a measurement of the patient's heart rate in beats per minute (BPM) ( 80 
in bpm 
).
The following REST samples work with R4 FHIR stores. The Python sample works with STU3 FHIR stores.
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- PATIENT_ID : the ID in the response returned by the server when you created the Patient resource
- ENCOUNTER_ID : the ID in the response returned by the server when you created the Encounter resource
Request JSON body:
{ "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": 80, "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } }
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' { "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": 80, "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } } 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/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation"
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:
@' { "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": 80, "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } } '@ | 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/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
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 .
Conditionally create a FHIR resource
The following curl 
sample shows how to use the  projects.locations.datasets.fhirStores.fhir.create 
 
method to conditionally create a FHIR resource. The method implements
the FHIR conditional create 
interaction ( DSTU2 
, STU3 
, R4 
, R5 
).
You can use conditional create to avoid creating duplicate FHIR resources. For example, each Patient resource in a FHIR server typically has a unique identifier, such as a medical record number (MRN). To create a new Patient resource and ensure no Patient resource with the same MRN exists, conditionally create the new resource using a search query. The Cloud Healthcare API creates the new resource only if there are no matches for the search query.
The server's response depends on how many resources matched the search query:
| Matches | HTTP response code | Behavior | 
|---|---|---|
|   
Zero | 201 CREATED | Creates the new resource. | 
|   
One | 200 OK | Doesn't create a new resource. | 
|   
More than one | 412 Precondition Failed | Doesn't create a new resource and returns a "search criteria are not selective enough"error. | 
To use the conditional create 
interaction instead of the create 
interaction,
specify an If-None-Exist 
HTTP header containing a FHIR search query 
in your request:
If-None-Exist: FHIR_SEARCH_QUERY 
 
In the Cloud Healthcare API v1, conditional operations exclusively use the identifier 
search parameter, if it exists for the FHIR resource type, to determine which FHIR
resources match a conditional search query.
REST
The following sample shows how to create an Observation resource using an If-None-Exist: identifier=my-code-system|ABC-12345 
HTTP header. The Cloud Healthcare API
creates the resource if and only if no existing Observation resource matches
the query identifier=my-code-system|ABC-12345 
.
curl -X POST \ -H "Authorization: Bearer $( gcloud auth print-access-token ) " \ -H "Content-Type: application/fhir+json" \ -H "If-None-Exist: identifier=my-code-system|ABC-12345" \ -d @request.json \ "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation"
The following sample output intentionally shows a failedrequest. To view the response from a successful request, see Creating a FHIR resource .
If multiple Observation resources match the query, the Cloud Healthcare API returns the following response, and the conditional create request fails:
  { 
  
 "issue" 
 : 
  
 [ 
  
 { 
  
 "code" 
 : 
  
 "conflict" 
 , 
  
 "details" 
 : 
  
 { 
  
 "text" 
 : 
  
 "ambiguous_query" 
  
 }, 
  
 "diagnostics" 
 : 
  
 "search criteria are not selective enough" 
 , 
  
 "severity" 
 : 
  
 "error" 
  
 } 
  
 ], 
  
 "resourceType" 
 : 
  
 "OperationOutcome" 
 } 
 
 
Updating a FHIR resource
The following samples show how to use the  projects.locations.datasets.fhirStores.fhir.update 
 
method to update a FHIR resource. The method implements the FHIR standard
update interaction
( DSTU2 
, STU3 
, R4 
,
and R5 
).
When you update a resource, you update the entire contents of the resource. This is in contrast to patching a resource , which updates only part of a resource.
If the FHIR store has  enableUpdateCreate 
 
set, the request is treated as an upsert (update or insert) that updates the
resource if it exists or inserts it using the ID specified the request if
it does not exist.
The request body must contain a JSON-encoded FHIR resource and the request
headers must contain Content-Type: application/fhir+json 
. The resource must
contain an id 
element having an identical value to the ID in the REST path of
the request.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
REST
The following samples show how to update the beats per minute (BPM) in an Observation resource.
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- OBSERVATION_ID : the Observation resource ID
- PATIENT_ID : the Patient resource ID
- ENCOUNTER_ID : the Encounter resource ID
- BPM_VALUE : the beats per minute (BPM) value in the updated Observation resource
Request JSON body:
{ "resourceType": "Observation", "id": " OBSERVATION_ID ", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": BPM_VALUE , "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } }
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' { "resourceType": "Observation", "id": " OBSERVATION_ID ", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": BPM_VALUE , "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } } EOF
Then execute the following command to send your REST request:
curl -X PUT \
-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 /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_ID "
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:
@' { "resourceType": "Observation", "id": " OBSERVATION_ID ", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": BPM_VALUE , "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } } '@ | 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 PUT `
-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 /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_ID " | Select-Object -Expand Content
APIs Explorer
Copy the request body and 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. Paste the request body in this tool, complete any other required fields, and click Execute .
You should receive a JSON response similar to the following:
Go
Node.js
Python
Conditionally updating a FHIR resource
The following samples show how to call the  projects.locations.datasets.fhirStores.fhir.conditionalUpdate 
 
method to update a FHIR resource that matches a search
query, rather than identifying the resource by its ID. The method implements the
FHIR standard conditional update interaction
( DSTU2 
, STU3 
, R4 
,
and R5 
).
A conditional update can only be applied to one FHIR resource at a time.
The response returned from the server depends on how many matches occur based on the search criteria:
- One match: The resource is successfully updated or an error is returned.
-  More than one match: The request
returns a 412 Precondition Failederror.
-  Zero matches with an id: If the search criteria identify zero matches, the supplied request body contains anid, and the FHIR store hasenableUpdateCreateset totrue, the FHIR resource is created with theidin the request body.
-  Zero matches without an id: If the search criteria identify zero matches and the supplied request body doesn't contain anid, the FHIR resource is created with a server-assigned ID as if the resource was created usingprojects.locations.datasets.fhirStores.fhir.create.
The request body must contain a JSON-encoded FHIR resource and the request
headers must contain Content-Type: application/fhir+json 
.
In the Cloud Healthcare API v1, conditional operations exclusively use the identifier 
search parameter, if it exists for the FHIR resource type, to determine which FHIR
resources match a conditional search query.
REST
The following sample shows how to send a PUT 
request using curl 
and
PowerShell to edit an Observation resource using the Observation's identifier
( ABC-12345 
in my-code-system 
). The Observation provides a measurement of a
patient's heartbeats per minute (BPM).
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- PATIENT_ID : the Patient resource ID
- ENCOUNTER_ID : the Encounter resource ID
- BPM_VALUE : the beats per minute (BPM) value in the Observation resource
Request JSON body:
{ "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": BPM_VALUE , "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } }
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' { "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": BPM_VALUE , "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } } EOF
Then execute the following command to send your REST request:
curl -X PUT \
-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 /fhirStores/ FHIR_STORE_ID /fhir/Observation?identifier=my-code-system|ABC-12345"
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:
@' { "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "identifier": [ { "system": "my-code-system", "value": "ABC-12345" } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "8867-4", "display": "Heart rate" } ] }, "valueQuantity": { "value": BPM_VALUE , "unit": "bpm" }, "encounter": { "reference": "Encounter/ ENCOUNTER_ID " } } '@ | 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 PUT `
-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 /fhirStores/ FHIR_STORE_ID /fhir/Observation?identifier=my-code-system|ABC-12345" | Select-Object -Expand Content
APIs Explorer
Copy the request body and 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. Paste the request body in this tool, complete any other required fields, and click Execute .
You should receive a JSON response similar to the following:
Patching a FHIR resource
The following samples show how to call the  projects.locations.datasets.fhirStores.fhir.patch 
 
method to patch a FHIR resource. The method implements the FHIR standard patch
interaction
( DSTU2 
, STU3 
, R4 
,
and R5 
).
When you patch a resource, you update part of the resource by applying the operations specified in a JSON Patch document.
The request must contain a JSON patch document, and the request headers must
contain Content-Type: application/json-patch+json 
.
The following samples show how
to patch an Observation resource. The Observation of a patient's heartbeats per
minute (BPM) is updated using the replace 
patch operation.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- OBSERVATION_ID : the Observation resource ID
- BPM_VALUE : the beats per minute (BPM) value in the patched Observation resource
Request JSON body:
[ { "op": "replace", "path": "/valueQuantity/value", "value": BPM_VALUE } ]
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' [ { "op": "replace", "path": "/valueQuantity/value", "value": BPM_VALUE } ] EOF
Then execute the following command to send your REST request:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json-patch+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_ID "
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:
@' [ { "op": "replace", "path": "/valueQuantity/value", "value": BPM_VALUE } ] '@ | 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 PATCH `
-Headers $headers `
-ContentType: "application/json-patch+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_ID " | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Go
Java
Node.js
Python
Executing a PATCH 
request in a FHIR bundle
 
  
 You can a specify a PATCH 
request in a FHIR bundle (FHIR R4 only).
Executing PATCH 
request in a FHIR bundle lets you patch many
FHIR resources at once, rather than having to make individual patch requests
for each FHIR resource.
To make a PATCH 
request in a bundle, specify the following information in
a resource 
object in the request:
- A resourceTypefield set toBinary
- A contentTypefield set toapplication/json-patch+json
- The patch body encoded in base64
Ensure that the resource 
object looks like the following:
  "resource" 
 : 
  
 { 
  
 "resourceType" 
 : 
  
 "Binary" 
 , 
  
 "contentType" 
 : 
  
 "application/json-patch+json" 
 , 
  
 "data" 
 : 
  
 "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K" 
 } 
 
 
The following shows the patch body that was encoded to base64 in the data 
field:
  [ 
  
 { 
  
 "op" 
 : 
  
 "replace" 
 , 
  
 "path" 
 : 
  
 "/birthdate" 
 , 
  
 "value" 
 : 
  
 "1990-01-01" 
  
 } 
 ] 
 
 
The following samples show how to use a PATCH 
request in a bundle to patch
the Patient resource you created in Creating a FHIR resource 
to have a birthDate 
value of 1990-01-01 
:
Before using any of the request data, make the following replacements:
- PROJECT_ID : your Google Cloud project ID
- LOCATION : the location of the parent dataset
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- PATIENT_ID : the ID of an existing Patient resource
Request JSON body:
{ "type": "transaction", "resourceType": "Bundle", "entry": [ { "request": { "method": "PATCH", "url": "Patient/ PATIENT_ID " }, "resource": { "resourceType": "Binary", "contentType": "application/json-patch+json", "data": "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K" } } ] }
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' { "type": "transaction", "resourceType": "Bundle", "entry": [ { "request": { "method": "PATCH", "url": "Patient/ PATIENT_ID " }, "resource": { "resourceType": "Binary", "contentType": "application/json-patch+json", "data": "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K" } } ] } 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/fhir+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1beta1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir"
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:
@' { "type": "transaction", "resourceType": "Bundle", "entry": [ { "request": { "method": "PATCH", "url": "Patient/ PATIENT_ID " }, "resource": { "resourceType": "Binary", "contentType": "application/json-patch+json", "data": "WyB7ICJvcCI6ICJyZXBsYWNlIiwgInBhdGgiOiAiL2JpcnRoRGF0ZSIsICJ2YWx1ZSI6ICIxOTkwLTAxLTAxIiB9IF0K" } } ] } '@ | 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/fhir+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1beta1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Conditionally patching a FHIR resource
The following samples show how to call the  projects.locations.datasets.fhirStores.fhir.conditionalPatch 
 
method to patch a FHIR resource that matches a search query, rather than
identifying the resource by its ID. The method implements the FHIR standard
conditional patch interaction
( DSTU2 
, STU3 
, R4 
,
and R4 
).
A conditional patch can be applied to only one resource at
a time. If the search criteria identify more than one match, the request
returns a 412 Precondition Failed 
error. If the search criteria doesn't
identify any matches, the request returns a 404 Not Found 
error.
In the Cloud Healthcare API v1, conditional operations exclusively use the identifier 
search parameter, if it exists for the FHIR resource type, to determine which FHIR
resources match a conditional search query.
REST
The following samples show how to send a PATCH 
request
to edit an Observation resource if the Observation's identifier is ABC-12345 
in my-code-system 
.
The Observation of a patient's heartbeats per minute (BPM) is
updated using the replace 
patch operation.
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- BPM_VALUE : the beats per minute (BPM) value in the Observation resource
Request JSON body:
[ { "op": "replace", "path": "/valueQuantity/value", "value": BPM_VALUE } ]
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' [ { "op": "replace", "path": "/valueQuantity/value", "value": BPM_VALUE } ] EOF
Then execute the following command to send your REST request:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json-patch+json" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation?identifier=my-code-system|ABC-12345"
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:
@' [ { "op": "replace", "path": "/valueQuantity/value", "value": BPM_VALUE } ] '@ | 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 PATCH `
-Headers $headers `
-ContentType: "application/json-patch+json" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation?identifier=my-code-system|ABC-12345" | Select-Object -Expand Content
APIs Explorer
Copy the request body and 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. Paste the request body in this tool, complete any other required fields, and click Execute .
You should receive a JSON response similar to the following:
Getting a FHIR resource
The following samples show how to get the contents of a FHIR resource.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
Console
-  In the Google Cloud console, go to the FHIR viewerpage. 
-  In the FHIR Storedrop-down list, select a dataset, and then select a FHIR store in the dataset. 
-  To filter the list of resource types, search for the resource types that you want to display. 
-  Click the Resource Typefield. 
-  In the Propertiesdrop-down list that appears, select Resource Type. 
-  Enter a resource type. 
-  To search for another resource type, select ORfrom the Operatorsdrop-down list that appears, and then enter another resource type. 
-  In the list of resource types, select the resource type for the resource that you want to get the contents of. 
-  In the table of resources that appears, select or search for a resource. 
REST
The following samples show
how to use the  projects.locations.datasets.fhirStores.fhir.read 
 
method to get the details of the Observation resource
created in a previous section.
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- OBSERVATION_ID : the Observation resource ID
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 /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_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 /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_ID " | Select-Object -Expand Content
APIs 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 .
You should receive a JSON response similar to the following:
Go
Java
Node.js
Python
Get all Encounter resource details
The following samples show how to to view details about an Encounter resource and all resources related to the Encounter.
The method implements the FHIR extended operation Encounter-everything 
defined in the following FHIR versions:
REST
Use the  projects.locations.datasets.fhirStores.fhir.Encounter-everything 
 
method.
Before using any of the request data, make the following replacements:
-  PROJECT_ID: the ID of your Google Cloud project
-  LOCATION: the dataset location
-  DATASET_ID: the dataset ID
-  FHIR_STORE_ID: the FHIR store ID
-  ENCOUNTER_ID: the Encounter resource ID
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/v1beta1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Encounter/ ENCOUNTER_ID /\$everything"
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/v1beta1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Encounter/ ENCOUNTER_ID /\$everything" | Select-Object -Expand Content
c427ce3e-7677-400e-bc06-33a8cecfdd77 
, which is a synthetic resource in the  gs://gcp-public-data--synthea-fhir-data-10-patients/fhir_r4_ndjson/ 
 
public Cloud Storage bucket.  
Getting all patient compartment resources
The following samples show how to get all resources associated with a
particular patient compartment
( DSTU2 
, STU3 
, R4 
,
and R5 
).
For more information, see  projects.locations.datasets.fhirStores.fhir.Patient-everything 
 
.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
curl
To get the resources in a patient compartment, make a GET 
request and
specify the following information:
- The name of the parent dataset
- The name of the FHIR store
- The patient's ID
- An access token
The following sample shows a GET 
request using curl 
:
curl -X GET \ -H "Authorization: Bearer $( gcloud auth application-default print-access-token ) " \ "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Patient/ PATIENT_ID /\$everything"
If the request is successful, the server returns a response similar to the following sample in JSON format:
{ "entry": [ { "resource": { "birthDate": "1970-01-01", "gender": "female", "id": " PATIENT_ID ", "name": [ { "family": "Smith", "given": [ "Darcy" ], "use": "official" } ], "resourceType": "Patient" } }, { "resource": { "class": { "code": "IMP", "display": "inpatient encounter", "system": "http://hl7.org/fhir/v3/ActCode" }, "id": " ENCOUNTER_ID ", "reasonCode": [ { "text": "The patient had an abnormal heart rate. She was concerned about this." } ], "resourceType": "Encounter", "status": "finished", "subject": { "reference": "Patient/ PATIENT_ID " } } }, { "resource": { "encounter": { "reference": "Encounter/ ENCOUNTER_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "id": " OBSERVATION_ID ", "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "valueQuantity": { "unit": "bpm", "value": BPM_VALUE } } } ], "resourceType": "Bundle", "type": "searchset" }
PowerShell
To get the resources in a patient compartment, make a GET 
request and
specify the following information:
- The name of the parent dataset
- The name of the FHIR store
- The patient's ID
- An access token
The following sample shows a GET 
request using PowerShell:
$cred = gcloud auth application-default print-access-token $headers = @ { Authorization = "Bearer $cred " } Invoke-RestMethod ` -Method Get ` -Headers $headers ` -Uri 'https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Patient/ RESOURCE_ID /$everything' | ConvertTo-Json
If the request is successful, the server returns a response similar to the following sample in JSON format:
{ "entry": [ { "resource": { "birthDate": "1970-01-01", "gender": "female", "id": " PATIENT_ID ", "name": [ { "family": "Smith", "given": [ "Darcy" ], "use": "official" } ], "resourceType": "Patient" } }, { "resource": { "class": { "code": "IMP", "display": "inpatient encounter", "system": "http://hl7.org/fhir/v3/ActCode" }, "id": " ENCOUNTER_ID ", "reasonCode": [ { "text": "The patient had an abnormal heart rate. She was concerned about this." } ], "resourceType": "Encounter", "status": "finished", "subject": { "reference": "Patient/ PATIENT_ID " } } }, { "resource": { "encounter": { "reference": "Encounter/ ENCOUNTER_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "id": " OBSERVATION_ID ", "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "valueQuantity": { "unit": "bpm", "value": BPM_VALUE } } } ], "resourceType": "Bundle", "type": "searchset" }
Go
Java
Node.js
Python
Getting patient compartment resources filtered by type or date
The following samples show how to get all resources associated with a
particular patient compartment (R4) 
filtered by a list of types and since a specified date and time.
For more information, see  projects.locations.datasets.fhirStores.fhir.Patient-everything 
 
.
The following REST samples work with R4 FHIR stores.
curl
To get the resources in a patient compartment of a specified type and since
a specified date, make a GET 
request and specify the following information:
- The name of the parent dataset
- The name of the FHIR store
- The patient's ID
- A query string containing a comma-separated resource type list and starting date
- An access token
The following sample shows a GET 
request using curl 
:
curl -X GET \ -H "Authorization: Bearer $( gcloud auth application-default print-access-token ) " \ "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Patient/ PATIENT_ID /\$everything?_type= RESOURCE_TYPES &_since= DATE "
If the request is successful, the server returns any resources that match the specified criteria in JSON format.
PowerShell
To get the resources in a patient compartment of a specified type and since
a specified date, make a GET 
request and specify the following information:
- The name of the parent dataset
- The name of the FHIR store
- The patient's ID
- A query string containing a comma-separated resource type list and starting date
- An access token
The following sample shows a GET 
request using PowerShell:
$cred = gcloud auth application-default print-access-token $headers = @ { Authorization = "Bearer $cred " } Invoke-RestMethod ` -Method Get ` -Headers $headers ` -Uri 'https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Patient/ RESOURCE_ID /$everything?_type= RESOURCE_TYPES &_since= DATE ' | ConvertTo-Json
If the request is successful, the server returns any resources that match the specified criteria in JSON format.
Listing FHIR resource versions
You can list the historical versions of a FHIR resource, including the current version and any deleted versions. This lets you do the following:
- Track changes to patient records, medications, or care plans.
- If a FHIR resource contains incorrect data, you can view historical versions to determine when the incorrect data was entered and recover the correct information.
- Ensure regulatory compliance by providing complete audit trails.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
Console
-  In the Google Cloud console, go to the FHIR viewerpage. 
-  In the FHIR storemenu, select a dataset, and then select a FHIR store in the dataset. 
-  To filter the list of FHIR resource types, search for the resource types that you want to display. 
-  Click the Resource typefield. 
-  In the Propertiesdrop-down list that appears, select Resource Type. 
-  Enter a FHIR resource type. 
-  In the list of FHIR resource types, select a resource type. 
-  In the table of FHIR resources that appears, select or search for a resource. 
-  To view and compare historical versions of the FHIR resource, click the Overviewtab, and then do the following: - To view historical versions of the FHIR resource, in the same row as Version ID, click View historical versions. In the Select a resource versionpane, select the version, and then click Confirm. The data in the version is populated in the Overview, Elements, and JSONtabs.
- To compare two versions of the FHIR resource, in the same row as Version ID, click Compare resource versions. In the Select resource versions to comparepane, select two resource versions, and then click Confirm. The two resource versions are displayed in a diff view, with the first version you selected on the left-hand side and the second version on the right-hand side.
 
REST
Use the  projects.locations.datasets.fhirStores.fhir.history 
 
method.
Before using any of the request data, make the following replacements:
-  PROJECT_ID: the ID of your Google Cloud project
-  LOCATION: the dataset location
-  DATASET_ID: the FHIR store's parent dataset
-  FHIR_STORE_ID: the FHIR store ID
-  RESOURCE_TYPE: the FHIR resource type
-  RESOURCE_ID: the FHIR resource ID
To send your request, choose one of these options:
curl
The following samples show how to list all versions of an Observation resource. The Observation was updated once after its original creation to change the patient's heartbeats per minute (BPM).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 /fhirStores/ FHIR_STORE_ID /fhir/ RESOURCE_TYPE / RESOURCE_ID /_history"
PowerShell
The following samples show how to list all versions of an Observation resource. The Observation was updated once after its original creation to change the patient's heartbeats per minute (BPM).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 /fhirStores/ FHIR_STORE_ID /fhir/ RESOURCE_TYPE / RESOURCE_ID /_history" | Select-Object -Expand Content
{ "entry": [ { "resource": { "effectiveDateTime": "2020-01-01T00:00:00+00:00", "id": " OBSERVATION_ID ", "meta": { "lastUpdated": "2020-01-02T00:00:00+00:00", "versionId": "MTU0MTE5MDk5Mzk2ODcyODAwMA" }, "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "valueQuantity": { "unit": "bpm", "value": 85 } } }, { "resource": { "encounter": { "reference": "Encounter/ ENCOUNTER_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "id": " OBSERVATION_ID ", "meta": { "lastUpdated": "2020-01-01T00:00:00+00:00", "versionId": "MTU0MTE5MDg4MTY0MzQ3MjAwMA" }, "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "valueQuantity": { "unit": "bpm", "value": 75 } } } ], "resourceType": "Bundle", "type": "history" }
Go
Java
Node.js
Python
Retrieving a FHIR resource version
The following samples show how to retrieve a specific version of a FHIR resource.
To find a specific version, you can list the versions of the FHIR resource 
and then view information for that version. The version ID is contained in the "versionId" 
field. For example, see the following JSON body where the
version IDs for the Observation resource
in Listing FHIR resource versions 
are highlighted:
{ "entry": [ { "resource": { "effectiveDateTime": "2020-01-01T00:00:00+00:00", "id": " OBSERVATION_ID ", "meta": { "lastUpdated": "2020-01-02T00:00:00+00:00", "versionId": "MTU0MTE5MDk5Mzk2ODcyODAwMA"}, ... { "resource": { "encounter": { "reference": "Encounter/ ENCOUNTER_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "id": " OBSERVATION_ID ", "meta": { "lastUpdated": "2020-01-01T00:00:00+00:00", "versionId": "MTU0MTE5MDg4MTY0MzQ3MjAwMA"}, ... }
The following samples use the resources created in Creating a FHIR resource and show how to view an Observation resource. The REST samples work with R4 FHIR stores. The Go, Node.js, and Python samples work with STU3 FHIR stores.
Console
-  In the Google Cloud console, go to the FHIR viewerpage. 
-  In the FHIR storemenu, select a dataset, and then select a FHIR store in the dataset. 
-  To filter the list of FHIR resource types, search for the resource types that you want to display. 
-  Click the Resource typefield. 
-  In the Propertiesdrop-down list that appears, select Resource Type. 
-  Enter a FHIR resource type. 
-  In the list of FHIR resource types, select a resource type. 
-  In the table of FHIR resources that appears, select or search for a resource. 
-  To view a specific version of the FHIR resource, do the following: - Click the Overviewtab.
- In the same row as Version ID, click View historical versions.
- In the Select a resource versionpane, select the version, and then click Confirm. The data in the version is populated in the Overview, Elements, and JSONtabs.
 
REST
Use the  projects.locations.datasets.fhirStores.fhir.vread 
 
method.
Before using any of the request data, make the following replacements:
-  PROJECT_ID: the ID of your Google Cloud project
-  LOCATION: the dataset location
-  DATASET_ID: the FHIR store's parent dataset
-  FHIR_STORE_ID: the FHIR store ID
-  RESOURCE_TYPE: the FHIR resource type
-  RESOURCE_ID: the FHIR resource ID
-  RESOURCE_VERSION: the FHIR resource version
To send your request, choose one of these options:
curl
The following samples show how to list all versions of an Observation resource. The Observation was updated once after its original creation to change the patient's heartbeats per minute (BPM).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 /fhirStores/ FHIR_STORE_ID /fhir/ RESOURCE_TYPE / RESOURCE_ID /_history/ RESOURCE_VERSION "
PowerShell
The following samples show how to list all versions of an Observation resource. The Observation was updated once after its original creation to change the patient's heartbeats per minute (BPM).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 /fhirStores/ FHIR_STORE_ID /fhir/ RESOURCE_TYPE / RESOURCE_ID /_history/ RESOURCE_VERSION " | Select-Object -Expand Content
{ "encounter": { "reference": "Encounter/ ENCOUNTER_ID " }, "effectiveDateTime": "2020-01-01T00:00:00+00:00", "id": " OBSERVATION_ID ", "meta": { "lastUpdated": "2020-01-01T00:00:00+00:00", "versionId": "MTU0MTE5MDg4MTY0MzQ3MjAwMA" }, "resourceType": "Observation", "status": "final", "subject": { "reference": "Patient/ PATIENT_ID " }, "valueQuantity": { "unit": "bpm", "value": 75 } }
Go
Java
Node.js
Python
Deleting a FHIR resource
The following samples show how to call the  projects.locations.datasets.fhirStores.fhir.delete 
 
method to delete an Observation FHIR resource.
Regardless of whether the operation succeeds or fails, the server returns a 200 OK 
HTTP status code. To check that the resource was successfully
deleted, search for 
or get 
the resource and see if it exists.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID : the ID of your Google Cloud project
- LOCATION : the dataset location
- DATASET_ID : the FHIR store's parent dataset
- FHIR_STORE_ID : the FHIR store ID
- OBSERVATION_ID : the Observation resource ID
To send your request, choose one of these options:
curl
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_ID "
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation/ OBSERVATION_ID " | Select-Object -Expand Content
APIs 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 .
You should receive a JSON response similar to the following:
Go
Java
Node.js
Python
Conditionally delete a FHIR resource
In the Cloud Healthcare API v1, conditional operations exclusively use the identifier 
search parameter, if it exists for the FHIR resource type, to determine which FHIR
resources match a conditional search query.
A FHIR resource matches the query ?identifier=my-code-system|ABC-12345 
if and only if the resource's identifier.system 
is my-code-system 
and its identifier.value 
is ABC-12345 
. If a FHIR resource
matches the query, the Cloud Healthcare API deletes the resource.
If the query uses the identifier 
search parameter and
matches multiple FHIR resources, the Cloud Healthcare API returns a "412 - Condition not selective enough" 
error.
To individually delete the resources, follow these steps:
- Search for each resource to get its unique server-assigned ID.
- Individually delete each resource using the ID.
The following samples show how to conditionally delete a FHIR resource that matches a search query,
rather than identifying the FHIR resource by its ID.
The search query matches and deletes an Observation resource using the
Observation's identifier ( ABC-12345 
in my-code-system 
).
REST
Use the  projects.locations.datasets.fhirStores.fhir.conditionalDelete 
 
method.
Before using any of the request data, make the following replacements:
-  PROJECT_ID: the ID of your Google Cloud project
-  LOCATION: the dataset location
-  DATASET_ID: the FHIR store's parent dataset
-  FHIR_STORE_ID: the FHIR store ID
To send your request, choose one of these options:
curl
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation?identifier=my-code-system|ABC-12345"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/Observation?identifier=my-code-system|ABC-12345" | Select-Object -Expand Content
APIs 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 .
You should receive a successful status code (2xx) and an empty response.
Delete historical versions of a FHIR resource
The following samples show how to delete all historical versions of a FHIR
resource using the  projects.locations.datasets.fhirStores.fhir.Resource-purge 
 
method.
Calling the projects.locations.datasets.fhirStores.fhir.Resource-purge 
method is limited to users (callers) with the  roles/healthcare.fhirStoreAdmin 
 
role; users with the roles/healthcare.fhirResourceEditor 
role cannot
call the method. To permit a caller to delete historical versions of a FHIR
resource, either:
- Make sure that the caller has the roles/healthcare.fhirStoreAdminrole.
- Create a custom IAM role 
with the  healthcare.fhirResources.purgepermission and assign the role to the caller.
The samples use the resources created in Creating a FHIR resource and show how to delete the historical versions of an Observation resource.
The following REST samples work with R4 FHIR stores. The Go, Java, Node.js, and Python samples work with STU3 FHIR stores.
REST
Use the  projects.locations.datasets.fhirStores.fhir.Resource-purge 
 
method.
Before using any of the request data, make the following replacements:
-  PROJECT_ID: the ID of your Google Cloud project
-  LOCATION: the dataset location
-  DATASET_ID: the FHIR store's parent dataset
-  FHIR_STORE_ID: the FHIR store ID
-  RESOURCE_TYPE: the FHIR resource type
-  RESOURCE_ID: the FHIR resource ID
To send your request, choose one of these options:
curl
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/ RESOURCE_TYPE / RESOURCE_ID /$purge"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://healthcare.googleapis.com/v1/projects/ PROJECT_ID /locations/ LOCATION /datasets/ DATASET_ID /fhirStores/ FHIR_STORE_ID /fhir/ RESOURCE_TYPE / RESOURCE_ID /$purge" | Select-Object -Expand Content
You should receive a successful status code (2xx) and an empty response.

