Skip to content

View Configuration Questionnaire

Santam Chakraborty edited this page Jul 25, 2023 · 1 revision

In order to ensure that patients see the questionnaires that they are supposed to see we have two essential options.

  • Create a page which is dedicated for the project - however patients needs then to know which page they will have to go to.
  • Create a single page with all questionnaires but patients see the questionnaire they are supposed to answer. This option is the best option as then all patients can be redirected to this page after they login and thereby ensure that there is minimal time wasted searching for the questionnaires.

Note that using the Webform Access module we will ensure that patients are unable to answer the questionnaires (Webform Nodes technically). This bit of configuration is to ensure they are unable to see the questionnaires that they are not supposed to answer in the page created.

Views

One of the most powerful modules available in Drupal is views which allows users to create arbitrary lists of contents that display them in various manners. In this section we will create a View that displays all content types that are of the type "Webform Node".

image

  • We choose to diplay certain fields like the title, body and link to the content. Project name and View result counter are kept hidden.
  • We show the list as an unformatted list of fields
  • We have asked it filter the list of content by the Type = Webform and if it is published.

If we do this we will get a list of all webform nodes available on the site. There are couple of problems which we solve using the Advanced settings in the Views:

image

  1. When translations are available for Webform Nodes then the same content appears as many times as there are the languages (if 3 languages 3 times). In order to restrict this diplay we go to the query settings section and ensure that distinct option is ticked. This will remove the duplicates of the same webform node in different languages. image

  2. Users are able to see all questionnaires available. Here we use the magic of the Drupal views relationships and contextual filters. In the relationships (will start out blank) we first add the relationship called project name (this is the field that is created in the Webform node). Once we do this we will be able to reference this project to the project that we have designated at the user account. This creates a SQL joint relating the project field in the webform node to the project field in the user account. Once this relationship is created we will then see the same questionnaire again starts duplicating (this is due to the nature of the relationship we just made).

image

  1. Use contextual filters now to restrict the list to only the content that has the project as the logged in user. This bit of magic relies on the Views module again. What we do is we add a contextual filter for the user (user ID) and when the filter is not in the URL we provide the default value to the filter that is user ID from the logged in user.

image

What happens in the background is this - when displaying the page, views creates a query that queries all webform nodes which are published. It then uses the distinct command to ensure only a single language is displayed. Then it relates the project name in the webform node to the user project name and finally filters the list to show only those webforms which belong to the project to patient. This users who do not have a link to a project will see a blank page.

A final bit of access control is given to ensure that the page is just visible to the patients and no one else. image

To understand this see the screenshot below:

pat1 who belong to the ICONG project is able to see a single questionnaire called ICONG questionnaire.

image

pat2 who belongs to the PARITY 2 project is able to see a PARITY2: XeQLS questionnaire only.

image

For test_pt, we have chosen that the preferred language is Hindi and the patient belongs to the PARITY 2 study therefore the patient only sees the PARITY2:XeQLS questionnaire but only in hindi

image

Finaly test_pt2 is a part of the ICONG study and reads bengali. Therefore is able to see only the ICON-G questionnaire in bengali.

image

Clone this wiki locally