SQL on FHIR, published by HL7 International / FHIR Infrastructure. This guide is not an authorized publication; it is the continuous build for version 3.0.0-ballot built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/HL7/sql-on-fhir/ and changes regularly. See the Directory of published versions
This view acts on the QuestionnaireResponse resource to produce a table named "questionnaire_response_items".
The table contains the following columns:
| Name | Fhir Type | SQL Type | Collection |
|---|---|---|---|
| id | string | String | |
| questionnaire | string | String | |
| patient_id | string | String | |
| authored | dateTime | DateTime | |
| item_link_id | string | String | |
| item_text | string | String | |
| answer_value_string | string | String | |
| answer_value_integer | integer | Integer | |
| answer_value_boolean | boolean | Boolean | |
| answer_value_date | dateTime | DateTime |
Selection Rules:
| Item | Coll | Type | Description |
|---|---|---|---|
![]() | QuestionnaireResponse | ||
![]() ![]() | |||
![]() ![]() ![]() | getResourceKey()Unique questionnaire response identifier | ||
![]() ![]() ![]() | questionnaireCanonical URL of the questionnaire | ||
![]() ![]() ![]() | subject.getReferenceKey(Patient)Patient identifier | ||
![]() ![]() ![]() | authoredDate and time the response was authored | ||
![]() ![]() | |||
![]() ![]() ![]() | linkIdUnique identifier for this item within the questionnaire | ||
![]() ![]() ![]() | textQuestion text | ||
![]() ![]() ![]() | for each answer, or null | ||
![]() ![]() ![]() ![]() | value.ofType(string)String answer value | ||
![]() ![]() ![]() ![]() | value.ofType(integer)Integer answer value | ||
![]() ![]() ![]() ![]() | value.ofType(boolean)Boolean answer value | ||
![]() ![]() ![]() ![]() | value.ofType(date)Date answer value |
This will result in a "questionnaire_response_items" table that looks like this:
| id | questionnaire | patient_id | authored | item_link_id | item_text | answer_value_string | answer_value_integer | answer_value_boolean | answer_value_date |
| 32 | http://example.org/q/phq9 | 28 | 2024-03-15T10:30:00+10:00 | q1 | Little interest or pleasure in doing things | 2 | |||
| 32 | http://example.org/q/phq9 | 28 | 2024-03-15T10:30:00+10:00 | q2 | Feeling down, depressed, or hopeless | 1 | |||
| 33 | http://example.org/q/health-history | 29 | 2024-03-16T14:20:00+10:00 | demographics | Demographics | ||||
| 33 | http://example.org/q/health-history | 29 | 2024-03-16T14:20:00+10:00 | name | Full name | John Smith | |||
| 33 | http://example.org/q/health-history | 29 | 2024-03-16T14:20:00+10:00 | dob | Date of birth | 1980-05-22 | |||
| 33 | http://example.org/q/health-history | 29 | 2024-03-16T14:20:00+10:00 | conditions | Medical conditions | ||||
| 33 | http://example.org/q/health-history | 29 | 2024-03-16T14:20:00+10:00 | diabetes | Diabetes | 1 | |||
| 33 | http://example.org/q/health-history | 29 | 2024-03-16T14:20:00+10:00 | diabetes-type | Diabetes type | Type 2 | |||
| 33 | http://example.org/q/health-history | 29 | 2024-03-16T14:20:00+10:00 | hypertension | Hypertension | 0 |
Note how all items are flattened into a single table regardless of their nesting depth. The "demographics" and "conditions" items are group items (with no answer values), while items like "name", "dob", "diabetes", and "hypertension" are nested within those groups but appear as separate rows in the output. The "diabetes-type" item is nested under the answer to "diabetes" rather than under an item, and is reached through the answer.item path in repeat.