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

[Modules] Replace Module->getDataDictionary with Module QueryEngine dictionary. #8260

Merged
merged 6 commits into from
Jan 24, 2023
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
116 changes: 0 additions & 116 deletions modules/candidate_parameters/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
namespace LORIS\candidate_parameters;
use LORIS\candidate_profile\CandidateInfo;
use LORIS\candidate_profile\CandidateWidget;
use LORIS\Data\Scope;
use LORIS\Data\Cardinality;
use LORIS\Data\Dictionary\DictionaryItem;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -188,117 +185,4 @@ class Module extends \Module
}
return $entries;
}

/**
* Return a data dictionary of data types managed by this module.
* DictionaryItems are grouped into categories and a module may
* provide 0 or more categories of dictionaryitems.
*
* @param \LORIS\LorisInstance $loris The LORIS instance whose data
* dictionary should be retrieved.
*
* @return \LORIS\Data\Dictionary\Category[]
*/
public function getDataDictionary(\LORIS\LorisInstance $loris) : iterable
{
$candscope = new Scope(Scope::CANDIDATE);
$sesscope = new Scope(Scope::SESSION);

$ids = new \LORIS\Data\Dictionary\Category(
"Identifiers",
"Candidate Identifiers"
);

$ids = $ids->withItems(
[
new DictionaryItem(
"CandID",
"LORIS Candidate Identifier",
$candscope,
new \LORIS\Data\Types\IntegerType(999999),
new Cardinality(Cardinality::UNIQUE),
),
new DictionaryItem(
"PSCID",
"Project Candidate Identifier",
$candscope,
new \LORIS\Data\Types\StringType(255),
// PSCIDs aren't unique because scanners candidates
// share the same PSCID, but each candidate has
// a single PSCID..
new Cardinality(Cardinality::SINGLE),
),
]
);

$demographics = new \LORIS\Data\Dictionary\Category(
"Demographics",
"Candidate Demographics"
);
$demographics = $demographics->withItems(
[
new DictionaryItem(
"DoB",
"Date of Birth",
$candscope,
new \LORIS\Data\Types\DateType(),
new Cardinality(Cardinality::SINGLE),
),
new DictionaryItem(
"DoD",
"Date of Death",
$candscope,
new \LORIS\Data\Types\DateType(),
new Cardinality(Cardinality::OPTIONAL),
),
new DictionaryItem(
"Sex",
"Candidate's biological sex",
$candscope,
new \LORIS\Data\Types\Enumeration('Male', 'Female', 'Other'),
new Cardinality(Cardinality::SINGLE),
),
]
);

$meta = new \LORIS\Data\Dictionary\Category("Meta", "Other parameters");
$meta = $meta->withItems(
[
new DictionaryItem(
"VisitLabel",
"The study visit label",
$sesscope,
new \LORIS\Data\Types\StringType(255),
new Cardinality(Cardinality::UNIQUE),
),
new DictionaryItem(
"Project",
"The LORIS project to categorize this session",
$sesscope,
new \LORIS\Data\Types\Enumeration(
...array_values(\Utility::getProjectList())
),
new Cardinality(Cardinality::SINGLE),
),
new DictionaryItem(
"Cohort",
"The LORIS cohort used for battery selection",
$sesscope,
new \LORIS\Data\Types\Enumeration(
...array_values(\Utility::getCohortList())
),
new Cardinality(Cardinality::SINGLE),
),
new DictionaryItem(
"Site",
"The Site at which a visit occurred",
$sesscope,
new \LORIS\Data\Types\Enumeration(...\Utility::getSiteList()),
new Cardinality(Cardinality::SINGLE),
),
]
);

return [$ids, $demographics, $meta];
}
}
2 changes: 1 addition & 1 deletion modules/dictionary/php/fields.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Fields extends \NDB_Page
// Brute force finding the name since we don't know what module
// the dictionary item came from.
foreach ($modules as $module) {
$mdict = $module->getDataDictionary($this->loris);
$mdict = $module->getQueryEngine()->getDataDictionary();
foreach ($mdict as $cat) {
foreach ($cat->getItems() as $item) {
$iname = $cat->getName() . '_' . $item->getName();
Expand Down
2 changes: 1 addition & 1 deletion modules/dictionary/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Module extends \Module
continue;
}

$mdict = $module->getDataDictionary($this->loris);
$mdict = $module->getQueryEngine()->getDataDictionary();
$mname = $module->getName();

if (count($mdict) > 0) {
Expand Down
44 changes: 0 additions & 44 deletions modules/imaging_browser/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
namespace LORIS\imaging_browser;
use \LORIS\candidate_profile\CandidateWidget;

use \LORIS\Data\Dictionary\DictionaryItem;
use \LORIS\Data\Scope;
use \LORIS\Data\Cardinality;

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -125,44 +121,4 @@ class Module extends \Module
}
return [];
}

/**
* {@inheritDoc}
*
* @param \LORIS\LorisInstance $loris The Loris instance from which the
* data dictionary for this module
* should be retrieved.
*
* @return \LORIS\Data\Dictionary\Category[]
*/
public function getDataDictionary(\LORIS\LorisInstance $loris) : iterable
{
$scope = new Scope(Scope::SESSION);
$images = new \LORIS\Data\Dictionary\Category(
"Images",
"Image Acquisitions",
);
$items = [];

$scantypes = \Utility::getScanTypeList();
foreach ($scantypes as $ScanType) {
$items[] = new DictionaryItem(
$ScanType,
"$ScanType acquisition location",
$scope,
new \LORIS\Data\Types\URI(),
new Cardinality(Cardinality::MANY),
);
$items[] = new DictionaryItem(
$ScanType . "_QCStatus",
"Quality Control status for $ScanType acquisition",
$scope,
new \LORIS\Data\Types\Enumeration("Pass", "Fail"),
new Cardinality(Cardinality::MANY),
);
}
$images = $images->withItems($items);

return [$images];
}
}
30 changes: 0 additions & 30 deletions modules/instruments/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,5 @@ class Module extends \Module
}
return [];
}

/**
* Return the data dictionary for all instruments installed on a LORIS
* instance.
*
* @param \LORIS\LorisInstance $loris The loris instance whose dictionary
* should be retrieved
*
* @return \LORIS\Data\Dictionary\Category[]
*/
public function getDataDictionary(\LORIS\LorisInstance $loris) : iterable
{
$tests = array_keys(\Utility::getAllInstruments());

$dict = [];
foreach ($tests as $testname) {
try {
$inst = \NDB_BVL_Instrument::factory($loris, $testname, "", "");
$cat = new \LORIS\Data\Dictionary\Category(
$testname,
$inst->getFullName()
);
$fields = $inst->getDataDictionary();
$dict[] = $cat->withItems($fields);
} catch (\LorisException $e) {
error_log($e);
}
}
return $dict;
}
}

14 changes: 5 additions & 9 deletions php/libraries/Module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -507,17 +507,13 @@ abstract class Module extends \LORIS\Router\PrefixRouter
}

/**
* Return a data dictionary of data types managed by this module.
* DictionaryItems are grouped into categories and a module may
* provide 0 or more categories of dictionaryitems.
* Gets the QueryEngine to be used for querying against this module's
* data.
*
* @param \LORIS\LorisInstance $loris The LORIS instance whose data
* dictionary should be retrieved.
*
* @return \LORIS\Data\Dictionary\Category[]
* @return \LORIS\Data\Query\QueryEngine
*/
public function getDataDictionary(\LORIS\LorisInstance $loris) : iterable
public function getQueryEngine() : \LORIS\Data\Query\QueryEngine
{
return [];
return new \LORIS\Data\Query\NullQueryEngine();
}
}
58 changes: 58 additions & 0 deletions src/Data/Query/NullQueryEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php declare(strict_types=1);
namespace LORIS\Data\Query;

use \LORIS\Data\Dictionary\DictionaryItem;
use \LORIS\Data\DataInstance;

/**
* A NullQueryEngine implements the LORIS QueryEngine interface
* in a way that doesn't do anything. It has no dictionary, matches
* no candidates, and returns no data.
*
* This is a default QueryEngine for modules that have not otherwise
* configured their own QueryEngine to query their data.
*/
class NullQueryEngine implements QueryEngine
{
/**
* {@inheritDoc}
*
* @return \LORIS\Data\Dictionary\Category[]
*/
public function getDataDictionary() : iterable
{
return [];
}

/**
* {@inheritDoc}
*/
public function getCandidateMatches(QueryTerm $criteria, ?array $visitlist = null) : iterable
{
return [];
}

/**
* {@inheritDoc}
*
* @param DictionaryItem[] $items Data points to retrieve
* @param iterable $candidates Candidates to retrieve data for
* @param ?string[] $visits Visit labels to restrict data to
*
* @return iterable<string, DataInstance>
*/
public function getCandidateData(array $items, iterable $candidates, ?array $visitlist) : iterable
{
return [];
}

/**
* {@inheritDoc}
*/
public function getVisitList(
\LORIS\Data\Dictionary\Category $inst,
\LORIS\Data\Dictionary\DictionaryItem $item
) : iterable {
return [];
}
}
2 changes: 1 addition & 1 deletion src/Data/Query/QueryEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getCandidateMatches(
* @param CandID[] $candidates Candidates to retrieve data for
* @param ?string[] $visits Visit labels to restrict data to
*
* @return DataInstance[]
* @return iterable<string, DataInstance>
*/
public function getCandidateData(array $items, iterable $candidates, ?array $visitlist) : iterable;

Expand Down