Skip to content
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

[dictionary] Cohort Filter #9390

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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.cohorts,
},
},
];
return (
<FilterableDataTable
Expand Down
7 changes: 5 additions & 2 deletions modules/datadict/php/datadictrowprovisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ 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 tb.CohortID) AS cohorts
FROM parameter_type pt
LEFT JOIN parameter_type_override pto USING (Name)
LEFT JOIN test_battery tb ON pt.sourceFrom=tb.Test_name
WHERE pt.Queryable=1
",
GROUP BY pt.sourceFrom, pt.name, pt.sourceField,
description, description_status",
[]
);
}
Expand Down
8 changes: 7 additions & 1 deletion modules/datadict/php/fields.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ 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);
}
return new \LORIS\Http\Response\JSON\OK(
['sourceFrom' => \Utility::getAllInstruments()]
['sourceFrom' => \Utility::getAllInstruments(), 'cohorts' => $cohorts]
);
}
}
9 changes: 9 additions & 0 deletions modules/dictionary/jsx/dataDictIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@ class DataDictIndex extends Component {
show: false,
filter: null,
},
{
label: 'Cohorts',
show: false,
filter: {
name: 'Cohorts',
type: 'multiselect',
options: options.cohorts,
},
},
];
return (
<FilterableDataTable
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
21 changes: 20 additions & 1 deletion modules/dictionary/php/datadictrowprovisioner.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance
$status = 'Empty';
}

$cohorts = $DB->pselectCol(
"SELECT DISTINCT tb.CohortID FROM test_names tn
JOIN test_battery tb ON tn.Test_name=tb.Test_name
WHERE tn.Test_name=:tn
ORDER BY tb.CohortID",
['tn' => $cat->getName()]
);

$visits = $qe->getVisitList($cat, $item);
$dict[] = $this->getInstance(
$module,
Expand All @@ -77,6 +85,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance
$desc,
$status,
$visits,
$cohorts,
);
}
}
Expand All @@ -96,6 +105,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 +116,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,
);
}
}
7 changes: 7 additions & 0 deletions modules/dictionary/php/dictionary.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ 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);
}
return [
'modules' => $amodules,
'categories' => $this->categories,
'cohorts' => $cohorts
];
}

Expand Down
Loading