Building reports using SQL on FHIR
This article provides a step-by-step guide to building a report using Aidbox Forms and SQL on FHIR.
Overview
The SQL on FHIR specification allows users to create flat views of their resources in a simple, straightforward way and use it for performing analysis or building reports.
In our case, we will focus on the QuestionnaireResponse that references the Vitals Signs Record Form to show how it works.
Example of the Vitals Signs Record Form (Questionnaire):
Example of the completed Vitals Signs Record Form (QuestionnaireResponse):
Incoming Data
Vitals Sign Test Form - url http://forms.aidbox.io/questionnaire/vitals-sign-test-form
Data Fields in QuestionnaireResponse:
Visit Date - linkID:
vd
Blood Pressure - linkID:
blood_pr
Group containing these fields - linkID:
group_1
Patient id -
morgan
Purpose
To build a report of how blood pressure changes from visit to visit for a specific patient.
Flow
Create ViewDefinition for QuestionnaireResponse of Vitals Signs Test Form using ViewDefinition Designer
POST ViewDefinition resource in Aidbox
Create AidboxQuery for this ViewDefinition
Use
$query
endpoint to get the required data for reporting
1. Create ViewDefinition for QuestionnaireResponse of Vitals Signs Test Form using ViewDefinition Designer
SQL on FHIR utilizes ViewDefinition resources to describe the structure of flat views. To create a ViewDefinition resource for a specific QuestionnaireResponse follow these steps:
Sign in to the ViewDefinition Designer
Connect to your current instance on the Settings page (if your instance is in Aidbox cloud)
Go to the View Definition page and click on the +ViewDefinition button to create a new resource or import an existing resource.
Example of ViewDefinition for the QuestionnaireResponses of Vitals Signs Test Form in which we filter data of two fields:
Once you have created and tested the new resource (ViewDefinition), click the save button and the resource will be saved to your Aidbox instance.
2. POST ViewDefinition resource in Aidbox
There are two options for saving the ViewDefinition resource in the Aidbox instance:
Click the save button on View Definition Designer to save the resource to your Aidbox instance connected to View Definition Designer.
Copy the JSON file from View Definition Designer and POST it in Aidbox.
Once saved, the corresponding flat view will be created in the database in the sof
schema (e.g., sof.vs_test
).
3. Create AidboxQuery for this ViewDefinition
Create an AidboxQuery resource for the ViewDefinition parameterized by a patient to turn your SQL query into a REST Endpoint.
Example:
4. Use $query
endpoint to get the required data
$query
endpoint to get the required dataAfter creating the AidboxQuery, you can use it to fetch the data.
Example:
Where
pid - patient id
vs_test - AidboxQuery id
This approach allows you to flatten nested FHIR resources (QuestionnaireResponse) and use them to build reports and analytics more easily.
Last updated