Loris icon indicating copy to clipboard operation
Loris copied to clipboard

Data Query Tool malfunction with multi-select elements of Json data Instrument

Open GabrielPelletier opened this issue 2 years ago • 1 comments

Describe the bug

The issue is twofold: a. When querying a multi-select field using the Data Query Tool, The output of the data query for this multi-select field is a concatenated string, without delimiters. For instance if "frontal" and "orbitofrontal" are both selected, the output is "frontalorbitofrontal" (see screenshot). b. When filtering by a multi-select field, nothing is returned when using the "=" operator for a multi-select field. For instance, "=" "frontal" doesn't return anything even though several entries are indeed = frontal (see screenshot).

note. These issues are for a multi-select fields of a Json Data instrument. I do not know whether this is specific to Json Data instruments, as I do not have multi-select fields in other instruments on MNCRR to test it out. note. These issues remain after updating the DQT to the newest version.

To Reproduce Steps to reproduce the behavior (attach screenshots if applicable):

  1. Login to MCNRR's front-end
  2. Set up a Data Query with a filter using a multi-select field of a Json data Instrument (e.g. INFOSHEETPATIENTS)
  3. Run Query
  4. See errors

What did you expect to happen? a. The selected items of a multi-select field should be somewhat divided in the output (e.g., comma, space) b. Filtering using the "=" operator should return all entries in which the value is identical to the argument, it returns none.

Browser Environment (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version 100.0.4896.75

Server Environment (if known):

  • LORIS Version: 23.0.10
  • Linux distribution and Version: CentOS 7
  • MySQL/MariaDB Version: 10.3.23-MariaDB

Screenshots :

The multi-select elements in question:

image

Query using "contains" image

Which returns: image

Query using "=" image

Which returns image

GabrielPelletier avatar Apr 08 '22 12:04 GabrielPelletier

The issue here was that the instruments in question did not define the SelectMultipleElement as indicated in the documentation (in all fairness the documentation is rather abstract and should be emphasized given the importance of this array) which was causing the multiselect field to save as an array in the JSON object since the instrument in question has jsonData=true. Because the instrument was able to save and load the data with no issue even without the SelectMultipleElement array this issue only appeared in the DQT when the couchDB is trying to display an array as a string directly in the table.

Short version, the data for the field looks like this "multiselectfield":["answer1","answer2"] instead of "multiselectfield":"answer1{@}answer2"

My recommendation here, in order to avoid data manipulation on a large-ish scale, was to leave the instruments as they are and instead implode the values array before exporting to couchdb in the export scripts by adding a code such as the one below to the CouchDB_Import_Instruments.php class below line 230

code to add:

foreach ($instrumentData as $field=>$value) {
    if (is_array($value)){
         $instrumentData[$field] = implode('{@}',$value);
    }
}

It worked as a temporary measure until we handle the multiselects more elegantly in LORIS

TBD

ridz1208 avatar Apr 21 '22 17:04 ridz1208