For AI agents: the documentation index is at /docs/aidbox/llms.txt. A Markdown version of this page is available at /docs/aidbox/notebooks.md or by requesting it with the Accept: text/markdown header.
Aidbox Docs
All notebooks

GraphQL API

Description

21 cells · updated Jul 17, 2023

This is a read-only view. Responses shown were saved when the notebook was published — open it in your own Aidbox to run the cells against live data.

You can use GraphQL to query any data from Aidbox.

The simplest case is to get IDs and names of patients:

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PatientList(_count: 5) {
      id
      name {family, given}
    }
  }

You can use variables to customize the query, e. g.:

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PatientList(_count: $count) {
      id
      name {family, given}
    }
  }
variables:
  count: 3

You can also set a timeout for the query. The query below will fail if taken more than 10 seconds.

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql?timeout=10
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PatientList(_count: 5) {
      id
      name {family, given}
    }
  }

Reference fileds contain all the fields of a Aidbox references (id, resourceType, display, identifier) and a special resource field, that allows you to fetch the referred resource's fields using GraphQL fragments.

The example below fetches the list of patients with names and IDs of organizations they're managed by.

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PatientList {
      id
      name {
        given
      }
      managingOrganization {
        id
        resource {
          ... on Organization {
            name
            id
          }
        }
      }
    }
  }

Following reverse links (revincludes) can be achieved by using special fields, generated by Aidbox. Such fields have the following structure:

<sourceResourceType>_as_<pathToReference>

Note that, unlike FHIR revincludes, GraphQL ones use field path, not the parameter's name.

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PractitionerList {
      id
      name {
        given
      }
      careteams_as_participant_member {
        id
        name
      }
    }
  }

You can query single elements by id:

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    Patient(id: "pt-1") {
      id
      name {
        given
      }
    }
  }

You can query the changes history as follows:

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PractitionerHistory(id: "pr-1") {
      id
      name {
        given
      }
      meta {
        versionId
      }
    }
  }

You can perform searches with <resourceType>List query:

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PractitionerList(name:"John") {
      id
      name {
        given
      }
    }
  }

You can request a total count of matching results with the total_ field as follows:

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    PatientList(_count: 2) {
      id
      name {
        given
      }
      total_
    }
  }

Complex example

Multiple fragments

Get id of DeviceRequestList resource, add address of Organizations and Practitioners referenced in DeviceRequestList.requester.

REST Send Cells run only inside Aidbox. Use Run in Aidbox above to open this notebook in your own instance.
POST /$graphql
content-type: text/yaml
accept: text/yaml

query: |
  query {
    DeviceRequestList {
      id,
      requester {
        resourceType
        resource {
          ... on Organization {
            id,
            address {
              use
            }
          }
          ... on Practitioner {
            id,
            address {
              use
            }
          }
        }
      }
    }
  }