GraphQL API
Description
21 cells · updated Jul 17, 2023
You can use GraphQL to query any data from Aidbox.
The simplest case is to get IDs and names of patients:
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.:
POST /$graphql
content-type: text/yaml
accept: text/yaml
query: |
query {
PatientList(_count: $count) {
id
name {family, given}
}
}
variables:
count: 3You can also set a timeout for the query. The query below will fail if taken more than 10 seconds.
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.
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.
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:
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:
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:
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:
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.
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
}
}
}
}
}
}