Skip to content

Commit 9a7f31c

Browse files
[DQT] Fix visit list filtering in candidate matching (aces#10438)
## Description Fixes a bug where DQT filters did not apply visit list criteria when matching candidates. The `getCandidateMatches()` method was not passing the `$visitlist` parameter to `buildQueryFromCriteria()`, and the visit filtering logic in `buildQueryFromCriteria()` was incorrectly adding a duplicate session table join. ## Changes - **src/Data/Query/SQLQueryEngine.php**: - Pass `$visitlist` parameter to `buildQueryFromCriteria()` in `getCandidateMatches()` method - Remove duplicate session table join from `buildQueryFromCriteria()` - the session table is already joined by `getFieldNameFromDict()` when querying session-scoped fields - **modules/dataquery/php/query.class.inc**: Remove FIXME comment and simplify visit list assignment since functionality is now verified ## Testing Instructions 1. Navigate to the Data Query Tool 2. Select fields with session scope 3. Add a filter on a parameter and select only a subset of visits (e.g., only "V1" and "V2") 4. Run the query 5. Verify that results only include data from the specified visits 6. Compare with results when all visits are selected - should see different candidate counts ## Related Issues Resolves aces#10435
1 parent 70e76a5 commit 9a7f31c

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

modules/dataquery/php/query.class.inc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,7 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
761761
throw new \Exception("Unhandled operator: " . $crit['op']);
762762
}
763763

764-
// FIXME: Verify visits, test was done with candidate scope data
765-
$visitlist = null;
766-
if (isset($crit['visits'])) {
767-
$visitlist = $crit['visits'];
768-
}
764+
$visitlist = $crit['visits'] ?? null;
769765

770766
\Profiler::checkpoint("Calling engine get matches");
771767
$matches = $engine->getCandidateMatches($term, $visitlist);

modules/imaging_browser/php/queryengine.class.inc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine
375375
\LORIS\Data\Dictionary\DictionaryItem $item
376376
): string {
377377
if ($item->getName() == 'ScanDone') {
378-
$this->addTable('LEFT JOIN session s ON (s.CandidateID=c.ID)');
378+
$this->addTable(
379+
"LEFT JOIN session s "
380+
. "ON (s.CandidateID=c.ID AND s.Active='Y')"
381+
);
379382
return "CASE WHEN s.Scan_Done='Y' THEN true
380383
WHEN s.Scan_Done='N' THEN false
381384
ELSE NULL END";
@@ -392,7 +395,10 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine
392395
// $field = whatever's after the first underscore
393396
$field = substr($item->getName(), strpos($item->getName(), '_') + 1);
394397

395-
$this->addTable('LEFT JOIN session s ON (s.CandidateID=c.ID)');
398+
$this->addTable(
399+
"LEFT JOIN session s "
400+
. "ON (s.CandidateID=c.ID AND s.Active='Y')"
401+
);
396402
$this->addTable("LEFT JOIN files ON (s.ID=files.SessionID)");
397403

398404
if ($item instanceof LocationDictionaryItem) {
@@ -544,7 +550,10 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine
544550
|| $item instanceof MRICommentDictionaryItem
545551
|| $item instanceof MRIPredefinedCommentDictionaryItem
546552
) {
547-
$this->addTable('LEFT JOIN session s ON (s.CandidateID=c.ID)');
553+
$this->addTable(
554+
"LEFT JOIN session s "
555+
. "ON (s.CandidateID=c.ID AND s.Active='Y')"
556+
);
548557
$this->addTable("LEFT JOIN files ON (s.ID=files.SessionID)");
549558
return "SUBSTRING_INDEX(files.File, '/', -1)";
550559
}

src/Data/Query/SQLQueryEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function getCandidateMatches(
116116
$this->addWhereClause("c.Active='Y'");
117117
$prepbindings = [];
118118

119-
$this->buildQueryFromCriteria($term, $prepbindings);
119+
$this->buildQueryFromCriteria($term, $prepbindings, $visitlist);
120120

121121
$query = 'SELECT DISTINCT c.CandID FROM';
122122

0 commit comments

Comments
 (0)