---
{
  "title": "Aidbox Becomes the First FHIR Server to Pass All SQL-on-FHIR Tests",
  "description": "Aidbox just became the first FHIR server to pass all SQL-on-FHIR tests — thanks to full support for the repeat element. This update lets engineers query deeply nested FHIR structures like QuestionnaireResponse.item with a single, elegant definition.",
  "date": "2025-11-06",
  "author": "Aleksandr Kislitsyn",
  "reading-time": "3 minutes",
  "tags": [
    "SQL on FHIR",
    "Aidbox"
  ]
}
---
We’ve recently added support for the 
[
repeat element
](https://build.fhir.org/ig/FHIR/sql-on-fhir-v2/StructureDefinition-ViewDefinition-definitions.html#diff_ViewDefinition.select.repeat) 
from the 
[
SQL-on-FHIR Specification
](https://build.fhir.org/ig/FHIR/sql-on-fhir-v2/index.html) —making Aidbox the first FHIR server to passing all tests from the 
[
SQL-on-FHIR test suite
](https://sql-on-fhir.org/extra/impls.html).

![SQL-on-FHIR test suite results](image-1.avif)

This milestone reflects our ongoing work to make structured clinical data easier to query, analyze, and reuse — without complex transformations or custom logic. SQL-on-FHIR bridges the gap between FHIR’s flexible data model and the simplicity of SQL, enabling healthcare teams to unlock insights directly from their FHIR data.

## What is the repeat Element and How It Works?

The select.repeat allows you to specify a list of [FHIRPath](/articles/unlocking-fhirpath-power-a-deep-dive-into-static-type-analysis-for-robust-tooling) expressions, each of them defines a path to traverse a FHIR resource recursively. Aidbox then automatically follows each path to any depth, collecting the results from all levels.

In simple terms, it helps flatten complex, deeply nested healthcare data into an easy-to-query table — saving hours of manual setup and data preparation.

For instance, a [
FHIR QuestionnaireResponse
](https://build.fhir.org/questionnaireresponse.html) resource may contain sections, questions, and follow-up items organized hierarchically. Each item element can include other item elements of the same type — and those can include additional ones, forming a recursive structure with any level of nesting.

Consider the following example:


```javascript
{
 "resourceType": "QuestionnaireResponse",
 "status": "amended",
 "id": "qr1",
 "item": [
  {
   "linkId": "1",
   "text": "Group 1",
   "item": [
    {
     "linkId": "1.1",
     "text": "Question 1.1",
     "answer": [
      {
       "valueString": "Answer 1.1",
       "item": [
        {
         "linkId": "1.1.1",
         "text": "Follow-up to 1.1"
        }
       ]
      }
     ]
    },
    {
     "linkId": "1.2",
     "text": "Question 1.2",
     "item": [
      {
       "linkId": "1.2.1",
       "text": "Question 1.2.1"
      }
     ]
    }
   ]
  },
  {
   "linkId": "2",
   "text": "Group 2"
  }
 ]
}
```


Instead of having a separate `forEach` element for each level of nesting, you can use `repeat` to traverse the entire structure recursively, and extract all the `item` elements at once:

ViewDefinition:


```javascript
{
  "resource": "QuestionnaireResponse",
  "status": "active",
  "select": [
    {
      "column": [
        {
          "name": "id",
          "path": "id",
          "type": "id"
        }
      ]
    },
    {
      "repeat": [
        "item"
      ],
      "column": [
        {
          "name": "linkId",
          "path": "linkId",
          "type": "string"
        },
        {
          "name": "text",
          "path": "text",
          "type": "string"
        }
      ]
    }
  ]
}
```


Result of running this ViewDefinition will be a table with the following columns:

| id | linkId | text |
| --- | --- | --- |
| qr1 | 1 | Group 1 |
| qr1 | 1.1 | Question 1.1 |
| qr1 | 1.2 | Question 1.2 |
| qr1 | 1.2.1 | Question 1.2.1 |
| qr1 | 2 | Group 2 |

## Try it yourself
You can try it yourself by running a new Aidbox instance by following the instructions in the [Run Aidbox locally](https://www.health-samurai.io/docs/aidbox/getting-started/run-aidbox-locally) guide.

See also: [SQL on FHIR Validation](/blog/sql-on-fhir-validation) and [Introducing $materialize: SQL interface for FHIR data](/blog/introducing-materialize-sql-interface-for-fhir-data).
