# Questionnaires

## Questionnaires

MOLGENIS offers a questionnaire module which can present a questionnaire to users. These questionnaires are defined in our [EMX format](https://molgenis.gitbook.io/molgenis/8.4/data-management/guide-emx). Each questionnaire can be filled in once, and generates one row of data in a table used to collect the questionnaires that where submitted.

## Minimal example

[download](https://github.com/molgenis/molgenis/tree/69869f19ac37b353e2b66fe65c6191a81f50d645/docs/data/simple-questionnaire.xlsx) simple questionnaire example. Import this xlsx file via the standard [import wizard](https://molgenis.gitbook.io/molgenis/8.4/data-management/guide-data-import)

The above example showcases a very simple questionnaire. It asks for your age, and if you are 18 or older the question "Do you have a drivers license" will appear.

To start creating your own questionnaire, you will need to have few fields specifically defined in your EMX in order for it to work

### EMX sheets

#### 'entities' sheet

| name               | description               | extends                | label               |
| ------------------ | ------------------------- | ---------------------- | ------------------- |
| questionnaire name | questionnaire description | **sys\_Questionnaire** | questionnaire label |

The questionnaire has to extend the sys\_Questionnaire table. This is an indicator for MOLGENIS to show this questionnaire in the list of all questionnaires.

### Visible expressions

The cool feature in the questionnaire module is that you can show certain questions based on the answer given on other questions. You do this by using the **Javascript Magma syntax** to create an expression inside the visible column (See driverslicence in the simple questionnaire example).

### Questionnaire timestamp on submit

MOLGENIS will automatically add a submit date for you when you submit a questionnaire. So keep in mind that you do not have to manually add a question relating to submit dates.

## Using Questionnaire data

You can access the questionnaire results through the data explorer. Go to the data explorer and look for the (in our case) Simple Questionnaire table.

This table contains the answers for all the users that filled in the questionnaire.

## Configure PDF report

After submitting a questionnaire users can download a PDF report of their data. All questions and answers that were provided will be presented nicely formatted in this report.\
This PDF report has an optional intro text and logo. To provide these, an extra attribute, with the name "report\_header" should be added to the questionnaire. This attribute should be of datatype "xref" with as refEntity a table that specifies the "intro" and "logo". To have the same logo and intro for each participant, use the defaultValue option to specify the data row in the config table. Example structure:

Attributes:

| name           | entity               | dataType | idAttribute | labelAttribute | defaultValue | refEntity            | label                                           | partOfAttribute |
| -------------- | -------------------- | -------- | ----------- | -------------- | ------------ | -------------------- | ----------------------------------------------- | --------------- |
| id             | demo\_report\_header | string   | TRUE        | TRUE           |              |                      |                                                 |                 |
| intro-en       | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| intro-nl       | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| intro-fr       | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| intro-de       | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| intro-es       | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| intro-it       | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| intro-pt       | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| logo           | demo\_report\_header | text     | FALSE       | FALSE          |              |                      |                                                 |                 |
| id             | demo\_questionnaire  | string   | AUTO        | FALSE          |              |                      |                                                 |                 |
| report\_header | demo\_questionnaire  | xref     | FALSE       | FALSE          |              | demo\_report\_header |                                                 |                 |
| questions      | demo\_questionnaire  | compound | FALSE       | FALSE          |              |                      |                                                 |                 |
| question1      | demo\_questionnaire  | bool     | FALSE       | FALSE          |              |                      | Do you think this questionnaire is quite small? | questions       |

The intro should be some text information about the PDF report. The logo should be a data URL (and therefore is of type text).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://molgenis.gitbook.io/molgenis/8.4/data-management/guide-questionnaire.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
