Filter healthcare search

When you're querying healthcare data, you can use filters to refine your search responses. In a search request, you can provide filters to enforce criteria that include or exclude certain search responses.

For example, when you're searching over a single patient's data, the search request body must contain the following filter expression that specifies the patient ID:

"filter": "patient_id: ANY(\"PATIENT_ID\")"

This page shows you how to define filters for healthcare search.

Before you begin

Before you begin, do the following:

Define filters

Filters are specified in the filter field in the request body of the servingConfigs.search method.

The filter definition follows the filter expression syntax. In the filter expression, the literal can be any indexable field from the response to the search query. For example, if the response contains an Observation resource, the patient_id that the Observation resource references can be used as a filter literal.

The following sections show a few examples on how to construct filters.

Define a resource_datetime filter

This example shows you how to specify a filter for a search that includes only those resources that have a resource_datetime value later than the specified date and time value.

REST

curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://us-discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/us/collections/default_collection/dataStores/DATA_STORE_ID/servingConfigs/default_search:search" \
    -d '{
"query": "QUERY",
"filter": "patient_id: ANY(\"PATIENT_ID\") AND resource_datetime > \"DATE_TIME_VALUE,
"contentSearchSpec":{"snippetSpec":{"returnSnippet":true}}
}'

Replace the following:

  • PROJECT_ID: the ID of your Google Cloud project.
  • DATA_STORE_ID: the ID of the Vertex AI Search data store.
  • QUERY: the search query.
  • PATIENT_ID: the resource ID of the patient whose data you want to search.
  • DATE_TIME_VALUE: the value of the resource_datetime field that represents a date and time in the FHIR dateTime format. Some examples of this field are as follows:
    • To specify a date and time with a time zone separated by a T separator: 2022-08-05T01:00:00+00:00
    • To specify a date: 2022-08-05
    • To specify a month: 2022-08
    • To specify a year: 2022

Define a resource type filter

The following example shows how to construct a filter that uses an AND operator to first filter all Composition resources and then filter those whose date is later than a specified date and time.

"filter": "resource_type: ANY("Composition") AND Composition.date > "2022-08-05T01:00:00+00:00""

Define a FHIR resource filter

You can use a filter to check whether a FHIR resource is present in the Vertex AI Search data store. For example, you can search for a DocumentReference resource that has the ID 6112d1ac-c6bd-4755-d689-bfb71d59afc5 using the following filter.

"filter": "DocumentReference.id: ANY(\"6112d1ac-c6bd-4755-d689-bfb71d59afc5\")"