Search for Patients with the patients Query
Welcome to the Semble GraphQL API how-to guide. In this guide, we'll walk you through the steps to find a patient using the patients
query.
The patients
query allows you to search for patients based on certain built in criteria such as first name, last name, email, date of birth. This query is paginated, meaning you can request a specific number of records at a time and also navigate through the records.
The patients
query looks like this:
patients(
search: String
pagination: Pagination
options: QueryOptions
): PatientData
Where PatientData
is:
type PatientData {
data: [Patient]
pageInfo: PageInfo
}
And Patient
is:
type Patient {
id: ID
title: String
status: String
firstName: String
lastName: String
fullName: String
dob: Date
gender: String
sex: String
email: String
googleClientId: String
paymentReference: String
phones: [Phone]
occupation: String
address: Address
membershipName: String
membershipStartDate: String
sharingToken: SharingToken
numbers: [PatientNumber]
customAttributes: [CustomAttribute]
communicationPreferences: CommunicationPreferences
relatedAccounts: [PatientRelationship]
bookings(start: Date!, end: Date!): [Booking]
invoices(start: Date!, end: Date!): [Invoice]
letters: [Letter]
labs: [Lab]
labels: [PatientLabel]
prescriptions(page: Int, pageSize: Int): PrescriptionData
records(page: Int, pageSize: Int): RecordData
patientDocuments(page: Int, pageSize: Int): PatientDocumentData
createdAt: Date
updatedAt: Date
accessGroups: [PatientAccessGroup]
comments: String
}
Step 1: Authenticate
Before making any requests, make sure you have a valid token. Refer to the Authentication section for more details.
Step 2: Construct Your Query
Construct a query to fetch patient
data. Here's an example where we fetch the first 10 patients with the first name "John":
- curl
- Javascript
- Python
curl -X POST https://open.semble.io/graphql \
-H "Content-Type: application/json" \
-H "x-token: yourtoken" \
-d '{
"query": "query findPatients($search: String, $pagination: Pagination) { patients(search: $search, pagination: $pagination) { data { id firstName lastName dob email } pageInfo { page pageSize hasMore } } }",
"variables": {"search": "John", "pagination": {"pageSize": 10, "page": 1}}
}'
const fetch = require('node-fetch');
const query = `
query findPatients($search: String, $pagination: Pagination) {
patients(search: $search, pagination: $pagination) {
data {
id
firstName
lastName
dob
email
}
pageInfo {
page
pageSize
hasMore
}
}
}
`;
const variables = {
search: 'John',
pagination: {
pageSize: 10,
page: 1,
},
};
fetch('https://open.semble.io/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-token': 'yourtoken',
},
body: JSON.stringify({ query, variables }),
})
.then((res) => res.json())
.then((res) => console.log(res.data));
import requests
import json
query = """
query findPatients($search: String, $pagination: Pagination) {
patients(search: $search, pagination: $pagination) {
data {
id
firstName
lastName
dob
email
}
pageInfo {
page
pageSize
hasMore
}
}
}
"""
variables = {
"search": "John",
"pagination": {
"pageSize": 10,
"page": 1
}
}
headers = {
'Content-Type': 'application/json',
'x-token': 'yourtoken',
}
response = requests.post(
'https://open.semble.io/graphql',
headers=headers,
data=json.dumps({"query": query, "variables": variables})
)
print(response.json())
In the query, we've specified that we want the id
, firstName
, lastName
, dob
, and email
for each patient. You can modify this to include any other fields you need from the Patient
type.
Conclusion
That's it! You've successfully used the patients
query to fetch patient data. Remember, you can refine your search using the search
argument, and control the amount of data you fetch at a time using pagination
. Happy querying!