Skip to content
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
2 changes: 1 addition & 1 deletion modules/behavioural_qc/php/behavioural.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Behavioural extends \NDB_Page implements ETagCalculator
ServerRequestInterface $request
) : array {
$user = $request->getAttribute('user');
$visit_array = \Utility::getVisitList();
$visit_array = $user->getVisits();
$userProjects = $user->getProjects();
$projects = [];
foreach ($userProjects as $project) {
Expand Down
55 changes: 3 additions & 52 deletions modules/candidate_list/php/candidate_list.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -70,58 +70,9 @@ class Candidate_List extends \DataFrameworkMenu
*/
function getFieldOptions() : array
{
$this->loris->getModule('candidate_parameters')->registerAutoloader();

// create user object
$factory = \NDB_Factory::singleton();
$user = $factory->user();
$config = $factory->config();

// get the list of visit labels
$visit_label_options = \Utility::getVisitList();

// get the list of sites available for the user
if ($user->hasPermission('access_all_profiles')) {
$list_of_sites = \Utility::getSiteList();
} else {
$list_of_sites = $user->getStudySites();
}
$site_options = [];
foreach (array_values($list_of_sites) as $name) {
$site_options[$name] = $name;
}

// get the list of projects
$list_of_projects = \Utility::getProjectList();
$project_options = [];
foreach (array_values($list_of_projects) as $name) {
$project_options[$name] = $name;
}

// get the list of cohorts
$list_of_cohorts = \Utility::getCohortList();
$cohort_options = [];
foreach (array_values($list_of_cohorts) as $name) {
$cohort_options[$name] = $name;
}

// get the list participant status options
$list_of_participant_status
= \Candidate::getParticipantStatusOptions();
$participant_status_options = [];
foreach (array_values($list_of_participant_status) as $name) {
$participant_status_options[$name] = $name;
}

return [
'visitlabel' => $visit_label_options,
'site' => $site_options,
'project' => $project_options,
'cohort' => $cohort_options,
'participantstatus' => $participant_status_options,
'useedc' => $config->getSetting("useEDC"),
'Sex' => \Utility::getSexList(),
];
// To modify the field options,
// you must edit getFieldOptions in options.class.inc
return [];
}

/**
Expand Down
7 changes: 4 additions & 3 deletions modules/candidate_list/php/options.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class Options extends \LORIS\Http\Endpoint
$user = $factory->user();
$config = $factory->config();

// get the list of visit labels
$visit_label_options = \Utility::getVisitList();
// get the list of visit labels that the user has access to
$visit_label_options = $user->getVisits();

// get the list of sites available for the user
if ($user->hasPermission('access_all_profiles')) {
Expand All @@ -62,7 +62,8 @@ class Options extends \LORIS\Http\Endpoint
}

// get the list of projects
$list_of_projects = \Utility::getProjectList();
// $list_of_projects = \Utility::getProjectList();
$list_of_projects = $user->getProjectNames();
$project_options = [];
foreach (array_values($list_of_projects) as $name) {
$project_options[$name] = $name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ class CandidateQueryEngine extends \LORIS\Data\Query\SQLQueryEngine
if ($item->getScope()->__toString() !== 'session') {
return [];
}
$user = \NDB_Factory::singleton()->user();

// Session scoped variables: VisitLabel, project, site, cohort
return array_keys(\Utility::getVisitList());
return array_keys($user->getVisits());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/dataquery/php/visitlist.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class VisitList extends \NDB_Page
protected $itemmodule;
protected $itemcategory;
protected $dictionaryitem;
protected $user;

/**
* {@inheritDoc}
Expand All @@ -28,9 +29,7 @@ class VisitList extends \NDB_Page
{
if ($this->dictionaryitem === null) {
return new \LORIS\Http\Response\JSON\OK(
[
'Visits' => array_values(\Utility::getVisitList()),
],
['Visits' => array_values($this->user->getVisits())],
);
}

Expand Down Expand Up @@ -62,6 +61,7 @@ class VisitList extends \NDB_Page
\User $user,
ServerRequestInterface $request,
) : void {
$this->user = $user;
$queryparams = $request->getQueryParams();
if (!isset($queryparams['module']) || !isset($queryparams['item'])) {
return;
Expand Down
2 changes: 1 addition & 1 deletion modules/dictionary/php/dictionary.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Dictionary extends \DataFrameworkMenu
$cohort_options[$name] = $name;
}
$visit_options = [];
foreach (\Utility::getVisitList() as $visit) {
foreach ($user->getVisits() as $visit) {
$visit_options[$visit] = $visit;
}
return [
Expand Down
17 changes: 17 additions & 0 deletions modules/dictionary/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ class Module extends \Module
$categories = [];

$categoryitems = [];

// Get the instruments that the user has access to based on their Projects
$userVisits = $user->getVisits();
$instruments = [];
foreach ($userVisits as $visitLabel => $_) {
$visitInstruments = \Utility::getVisitInstruments($visitLabel);
foreach ($visitInstruments as $testName => $fullName) {
if (!isset($instruments[$testName])) {
$instruments[$testName] = $fullName;
}
}
}
foreach ($modules as $module) {
if ($formodule !== null && $module->getName() !== $formodule) {
continue;
Expand All @@ -104,6 +116,11 @@ class Module extends \Module
$categories[$mname] = [];

foreach ($mdict as $cat) {
if ($mname === 'instruments'
&& !isset($instruments[$cat->getName()])
) {
continue;
}
$categories[$mname][$cat->getName()] = $cat->getDescription();
$categoryitems[] = [
'Module' => $module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Electrophysiology_Uploader extends \DataFrameworkMenu

return [
'sites' => $site_options,
'visitLabel' => \Utility::getVisitList(),
'visitLabel' => $user->getVisits(),
];
}

Expand Down
6 changes: 4 additions & 2 deletions modules/imaging_browser/php/queryengine.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,11 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine
return $visits;
}

// Fall back on all visits if something ends up getting
$user = \NDB_Factory::singleton()->user();

// Fall back on user visits if something ends up getting
// added that we can't derive the modality of.
return array_keys(\Utility::getVisitList());
return array_keys($user->getVisits());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/imaging_uploader/php/imaging_uploader.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class Imaging_Uploader extends \NDB_Menu_Filter_Form
'N' => 'No',
'Y' => 'Yes',
];
$visitlabels = \Utility::getVisitList();
$user = \NDB_Factory::singleton()->user();
$visitlabels = $user->getVisits();
// Fields used for selection filter and upload form
$this->addSelect('IsPhantom', 'Phantom Scans', $phantomOtions);
$this->addBasicText('candID', 'CandID');
Expand Down
3 changes: 3 additions & 0 deletions modules/instruments/php/instrumentqueryengine.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class InstrumentQueryEngine implements \LORIS\Data\Query\QueryEngine
if (isset($this->visitcache[$inst->getName()])) {
return $this->visitcache[$inst->getName()];
}
$user = \NDB_Factory::singleton()->user();
$user_visits = "('" . join("','", $user->getVisits()) . "')";

$DB = \NDB_Factory::singleton()->database();
$visits = $DB->pselectCol(
Expand All @@ -192,6 +194,7 @@ class InstrumentQueryEngine implements \LORIS\Data\Query\QueryEngine
JOIN session s ON (f.SessionID=s.ID)
JOIN candidate c ON (c.ID=s.CandidateID)
WHERE s.Active='Y' AND c.Active='Y' and tn.Test_name=:tn
AND s.Visit_Label IN $user_visits
ORDER BY s.Visit_label",
['tn' => $inst->getName()]
);
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion modules/statistics/php/stats_behavioural.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Stats_Behavioural extends \NDB_Form
}
$Visits = \Utility::getVisitList($currentProject);
} else {
$Visits = \Utility::getVisitList();
$Visits = $user->getVisits();
}

$this->tpl_data['Visits'] = $Visits ?? '';
Expand Down
3 changes: 2 additions & 1 deletion modules/statistics/php/stats_demographic.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class Stats_Demographic extends \NDB_Form
function setup()
{
parent::setup();
$visits = \Utility::getVisitList();
$user = \NDB_Factory::singleton()->user();
$visits = $user->getVisits();
$db = $this->loris->getDatabaseConnection();
//This boolean is for optional use by project if the demographics table
// queries any information from the mri_parameter_form table
Expand Down
34 changes: 33 additions & 1 deletion php/libraries/User.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class User extends UserPermissions implements
}

/**
* Get the user's sites' ID numbers
* Get the names of projects accessible to the user
*
* @return array
*/
Expand All @@ -341,6 +341,38 @@ class User extends UserPermissions implements
return explode(';', $projects);
}

/**
* Get the visits the User has access to
* through their projects and their cohorts.
*
* @return array of study visits in the format array('VL' => 'VL')
* where VL is the visit label
*/
public function getVisits(): array
Copy link
Collaborator

Choose a reason for hiding this comment

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

@skarya22 this is purely out of personal preference and not at all blocking:

I would use this opportunity to create a getVisits() function in the Project class which knows how to get the visits itself instead of doing these loops through projects...cohorts...visits.

That being said, the efficiency of the code below is basically one query per project per cohort, if you choose to add the function to the project class, you could choose to use getVisitsProjectCohort() from the VisitController class to make it an efficiency of one query per project. ORR if you choose not to create the Projec::getvisits() function you could use getVisitsProjectCohort() from the VisitController class here directly to make it an efficiency of just 1 query!

I'll leave it up to you

Copy link
Collaborator

Choose a reason for hiding this comment

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

{
$visit_labels = [];
$userProjectIDs = $this->getProjectIDs();

$factory = \NDB_Factory::singleton();
$DB = $factory->database();

// Get VisitController instance
$visitController = new \LORIS\VisitController($DB);
$allVisitsProjectCohort = $visitController->getVisitsProjectCohort();

foreach ($allVisitsProjectCohort as [$visit, $projectID]) {
// Check if user has access to this project
if (in_array(\ProjectID::singleton($projectID), $userProjectIDs)) {
$visitLabel = $visit->getName();
if (!in_array($visitLabel, $visit_labels)) {
$visit_labels[$visitLabel] = $visitLabel;
}
}
}

return $visit_labels;
}

/**
* Get the user's sites' ID numbers
*
Expand Down
6 changes: 3 additions & 3 deletions php/libraries/VisitController.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ class VisitController
return array_map(
function ($row) {
return [
new \LORIS\Visit($row['name'], $row['ID']),
new \LORIS\Visit($row['name'], $row['label']),
$row['project'], // will be modified to object when
$row['cohort'], // available
];
},
iterator_to_array(
$this->database->pselect(
'SELECT
v.VisitID as "ID",
v.VisitLabel as "label",
v.VisitName as "name",
psr.ProjectID as "project",
psr.CohortID as "cohort"
Expand All @@ -175,7 +175,7 @@ class VisitController
JOIN
project_cohort_rel psr
ON vps.ProjectCohortRelID = psr.ProjectCohortRelID
ORDER BY ID, project, cohort
ORDER BY label, project, cohort
',
[]
)
Expand Down
2 changes: 1 addition & 1 deletion raisinbread/RB_files/RB_test_names.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ INSERT INTO `test_names` (`ID`, `Test_name`, `Full_name`, `Sub_group`, `IsDirect
INSERT INTO `test_names` (`ID`, `Test_name`, `Full_name`, `Sub_group`, `IsDirectEntry`) VALUES (2,'bmi','BMI Calculator',1,1);
INSERT INTO `test_names` (`ID`, `Test_name`, `Full_name`, `Sub_group`, `IsDirectEntry`) VALUES (3,'medical_history','Medical History',1,1);
INSERT INTO `test_names` (`ID`, `Test_name`, `Full_name`, `Sub_group`, `IsDirectEntry`) VALUES (4,'mri_parameter_form','MRI Parameter Form',2,NULL);
INSERT INTO `test_names` (`ID`, `Test_name`, `Full_name`, `Sub_group`, `IsDirectEntry`) VALUES (6,'aosi','AOSI',1,NULL);
INSERT INTO `test_names` (`ID`, `Test_name`, `Full_name`, `Sub_group`, `IsDirectEntry`) VALUES (5,'aosi','AOSI',1,NULL);
UNLOCK TABLES;
SET FOREIGN_KEY_CHECKS=1;
Loading