Running simple queries

FHIR data is accessed via search queries. Developers build and use these search queries all the time, either in code or via an API client program. The FHIR Search Query screen in Vanya is where you write, run and manage your queries. Vanya supports the following query types:

- Queries that use any number of official and custom search parameters and modifiers
- Querying by resource ID
- Querying a resource’s version history using the _history endpoint
- Queries that use the _include and _revinclude parameters

The first time you open Vanya, a default set of 5 queries will exist for you to run against any of the configured FHIR test servers. If you do not wish to use any of these queries, simply type your query into the input box on the Query screen and click “Send”.

All search queries must begin with a FHIR resource type.

A simple Encounter query


In the first example, we’re performing a search query to get the most recent Encounter resources with a status of “finished” and with a type of Emergency Room Admissions. We’re performing this query on the Vanya Test Server on Microsoft Azure that we pre-populated with some test data from Synthea. And we’re asking for 15 resources to be returned with each page of results.

Vanya search query

1. FHIR Search Query button
Opens the Query page in Vanya with the currently active server pre-selected in the server drop down list. The query input box will be empty when this page loads. This means you have a choice of writing and running a new query or selecting one of your saved queries to run.

2. FHIR server drop down list
A list of all the configured FHIR servers in Vanya. You can only run a search query against a FHIR server that you already configured. Learn how to add your server to Vanya here.

3. The FHIR query
This is the input box where you enter your FHIR query. Each query should begin with the resource type you want to run your query against. In the example above we’re running a query against the Encounter resource and we’ve added 4 parameters: status, type, _sort and _count. All allowed search parameters and search modifiers can be used.

4. The Send button
Sends the query to the FHIR server. If you are making a change to a saved query, that query will be updated with any changes when you click the Send button. Once the query runs, any resources returned will be rendered in the results grid. If any OperationOutcomes are returned they will appear above the results grid.

Query a resource by ID


If you know the logical ID of the resource you want to find, a simple query of RESOURCE_TYPE / ID will find it for you. There can only ever be one resource of the specified type with a particular logical ID. If the resource does not exist, most FHIR servers will return an OperationOutcome.

Query using the _history endpoint


The _history endpoint is an underused search query. Where supported it returns a list of all updates to a specified FHIR resource. The example below returns 5 versions of the same resource, sorted in reverse order with the most recent at the top. Vanya only displays updates that were created using a POST, PUT or PATCH request. Resource DELETE requests are not shown.

Vanya _history endpoint

1. The search query
A query that calls the _history endpoint for a specific Patient resource using the Patient’s logical ID.

2. The last updated date
The local time at which each version of that Patient resource was created.

3. The Patient’s name
An example illustrating the change to the patient’s name made between version 1 and version 2 of the resource.