Using Variables
Variables are a powerful feature in your dashboard that allow you to create dynamic, flexible queries and display tailored data. Here’s how you can create and use variables effectively.
Creating a New Variable
To access the “Variables” section, go to the dashboard settings by clicking on the gear icon located above the panel view, at the top right, as shown below.
Once in the settings, navigate to the “Variables” tab and create a new variable. Variables can then be referenced in your queries similarly to macros, using the format $variable_name.
Types of Variables
Variables can come in different types (more information here), but we will focus on the 2 main types:
- Constant Variables
- Query Variables
Constant Variables
Constant variables are simple to use and helpful for predefined, fixed values. For example:
- You can create a constant named “Organization 1” and assign it the corresponding Organization ID.
- Another use for constant variables is to pass information via URL parameters (more details here).
Example
- If you create a constant named “PatientID” without an initial value, you can append it to the URL as &var-PatientID={{entity._id}}. This dynamically passes the current entity ID, allowing the dashboard to display data specific to a particular patient.
- Similarly, you can create a variable called “PatientCareGiver” and use &var-PatientCareGiver={{entity._caregiver.id}} to pass the caregiver’s ID , ensuring that the query shows data relevant only to that caregiver’s assigned patients.
Here’s an example of a query using these parameters:
SELECT OB."patientId", OB."br", OB."timestamp"
FROM "AnalyticsDB"."Observations_Patient_patient" AS OB
WHERE OB."patientId" = '$PatientID'
AND '$__biotUser(_id)' = '$PatientCareGiver'
Query Variables
Query Variables are defined by queries, which can make your dashboards more interactive and adaptable.
You can create a variable named “patient” that is populated by a query. This query returns a list of all patients available in your organization, displaying them in a dropdown list. To ensure clarity, concatenate the first and last names to create a single key for the list.
SELECT "_name.lastName" || ' ' || "_name.firstName" AS "__text", "_id" AS "__value"
FROM "AnalyticsDB"."Patient_patient"
WHERE "_ownerOrganization.id" = '$__biotUser(_ownerOrganization.id)'
Another benefit of query variables is the option to “Show on dashboard.”
Since this variable represents a list of data, it will appear in the top-left section of your dashboard. You can choose to display it as “Label and Value,” “Value Only,” or “None.” In this case, we will use the default setting of “Label and Value.”
This feature is useful if you want to view data for a specific patient in your organization. However, it requires a modification to the panel’s query. To illustrate, let’s revisit the previous heart rate example and modify the query:
SELECT OB."patientId", OB."heart_rate_1", OB."timestamp"
FROM "AnalyticsDB"."Observations_Patient_patient" AS OB,
"AnalyticsDB"."Patient_patient" AS PP,
"AnalyticsDB"."Clinician_caregiver" AS CC
WHERE PP."_caregiver.id" = '$__biotUser(_id)'
AND PP."_id" = OB."patientId"
AND CC."_id" = '$__biotUser(_id)'
AND "patientId" = '$patient'
By adding the condition AND "patientId" = '$patient', you can now display data for only one patient at a time, as shown below.
Updated 16 days ago