Skip to content

[dictionary] Cohort Filter #9390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/datadict/jsx/dataDictIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ class DataDictIndex extends Component {
},
},
},
{
label: 'Cohorts',
show: true,
filter: {
name: 'Cohorts',
type: 'multiselect',
options: options.cohort,
},
},
];
return (
<FilterableDataTable
Expand Down
8 changes: 6 additions & 2 deletions modules/datadict/php/datadictrowprovisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ class DataDictRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner
WHEN COALESCE(pto.description,pt.description) = '' THEN 'Empty'
WHEN pto.name IS NOT NULL THEN 'Modified'
WHEN pto.name IS NULL THEN 'Unchanged'
END as description_status
END as description_status,
GROUP_CONCAT(DISTINCT c.title) AS Cohort
FROM parameter_type pt
LEFT JOIN parameter_type_override pto USING (Name)
LEFT JOIN test_battery tb ON pt.sourceFrom=tb.Test_name
LEFT JOIN cohort c ON tb.CohortID=c.CohortID
WHERE pt.Queryable=1
",
GROUP BY pt.sourceFrom, pt.name, pt.sourceField,
description, description_status",
[]
);
}
Expand Down
15 changes: 14 additions & 1 deletion modules/datadict/php/fields.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@ class Fields extends \NDB_Page
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$user = \NDB_Factory::singleton()->user();
$projects = $user->getProjectIDs();
$cohorts = [];
foreach ($projects AS $projectID) {
$cohorts = $cohorts + \Utility::getCohortList($projectID);
}
$cohort_options = [];
foreach (array_values($cohorts) as $name) {
$cohort_options[$name] = $name;
}
return new \LORIS\Http\Response\JSON\OK(
['sourceFrom' => \Utility::getAllInstruments()]
[
'sourceFrom' => \Utility::getAllInstruments(),
'cohort' => $cohort_options
]
);
}
}
14 changes: 7 additions & 7 deletions modules/dictionary/jsx/dataDictIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,13 @@ class DataDictIndex extends Component {
},
},
{
// We may or may not have an 8th column depending
// on type, which we need for formatting other columns.
// We don't show or display a filter because it's only
// valid for some data types.
label: 'Field Options',
show: false,
filter: null,
label: 'Cohorts',
show: true,
filter: {
name: 'Cohorts',
type: 'multiselect',
options: options.cohorts,
},
},
];
return (
Expand Down
7 changes: 6 additions & 1 deletion modules/dictionary/php/datadictrow.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DataDictRow implements \LORIS\Data\DataInstance,
protected string $desc;
protected string $status;
protected ?array $visits;
protected ?array $cohorts;

/**
* Construct a DataDictRow
Expand All @@ -31,6 +32,7 @@ class DataDictRow implements \LORIS\Data\DataInstance,
* @param string $desc The (possibly overridden) description
* @param string $descstatus The status of the description override
* @param ?string[] $visits List of visits for the item.
* @param ?string[] $cohorts List of cohorts for the item.
*/
public function __construct(
\Module $itemmodule,
Expand All @@ -39,13 +41,15 @@ class DataDictRow implements \LORIS\Data\DataInstance,
string $desc,
string $descstatus,
?array $visits,
?array $cohorts
) {
$this->itemmodule = $itemmodule;
$this->itemcategory = $cat;
$this->item = $item;
$this->desc = $desc;
$this->status = $descstatus;
$this->visits = $visits;
$this->cohorts = $cohorts;
}

/**
Expand All @@ -72,7 +76,8 @@ class DataDictRow implements \LORIS\Data\DataInstance,
$val['options'] = $itype->getOptions();
}
if ($scope->__toString() == "session") {
$val['visits'] = $this->visits;
$val['visits'] = $this->visits;
$val['cohorts'] = $this->cohorts;
}

return $val;
Expand Down
22 changes: 21 additions & 1 deletion modules/dictionary/php/datadictrowprovisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance
$status = 'Empty';
}

$cohorts = $DB->pselectCol(
"SELECT GROUP_CONCAT(DISTINCT c.title) FROM test_names tn
JOIN test_battery tb ON tn.Test_name=tb.Test_name
JOIN cohort c ON tb.CohortID=c.CohortID
WHERE tn.Test_name=:tn
ORDER BY c.title",
['tn' => $cat->getName()]
Comment on lines +73 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to not use group concats (lists should be lists, not strings with commas), but if that's what the rest of the code does I am willing to accept it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is what the rest of it was like so probably best to keep it the same

);

$visits = $qe->getVisitList($cat, $item);
$dict[] = $this->getInstance(
$module,
Expand All @@ -77,6 +86,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance
$desc,
$status,
$visits,
$cohorts,
);
}
}
Expand All @@ -96,6 +106,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance
* @param string $desc The overridden description of the item
* @param string $descstatus The status of the description override
* @param ?[]string $visits The visits for session scoped variables
* @param ?[]string $cohorts The cohorts for session scoped variables
*
* @return \LORIS\Data\DataInstance An instance representing this row.
*/
Expand All @@ -106,7 +117,16 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance
string $desc,
string $descstatus,
array $visits,
array $cohorts,
) : \LORIS\Data\DataInstance {
return new DataDictRow($module, $cat, $item, $desc, $descstatus, $visits);
return new DataDictRow(
$module,
$cat,
$item,
$desc,
$descstatus,
$visits,
$cohorts,
);
}
}
11 changes: 11 additions & 0 deletions modules/dictionary/php/dictionary.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ class Dictionary extends \DataFrameworkMenu
foreach ($this->modules as $module) {
$amodules[$module->getName()] = $module->getLongName();
}
$user = \NDB_Factory::singleton()->user();
$projects = $user->getProjectIDs();
$cohorts = [];
foreach ($projects AS $projectID) {
$cohorts = $cohorts + \Utility::getCohortList($projectID);
}
$cohort_options = [];
foreach (array_values($cohorts) as $name) {
$cohort_options[$name] = $name;
}
return [
'modules' => $amodules,
'categories' => $this->categories,
'cohorts' => $cohort_options
];
}

Expand Down
Loading