Skip to content

Commit

Permalink
Rebase errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave MacFarlane committed Oct 2, 2024
1 parent 0f800ec commit 57d2d10
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 27 deletions.
5 changes: 3 additions & 2 deletions modules/dataquery/php/query.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
return [];
}
$DB = $this->loris->getNewDatabaseConnection();
$DB->setBuffering(false);
$DB->setBuffering(false);

// Put candidates into a temporary table so that it can be used in a join
// clause. Directly using "c.CandID IN (candid1, candid2, candid3, etc)" is
Expand Down Expand Up @@ -631,7 +631,8 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
\ProjectID::singleton($row['SProjectID']),
\CenterID::singleton($row['SCenterID']),
)
);
);
}
}

// check the last candidate that wouldn't have entered the check in the
Expand Down
18 changes: 18 additions & 0 deletions modules/dicom_archive/test/dicom_archiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ class DicomArchiveTestIntegrationTest extends LorisIntegrationTest
static $display = '.table-header > div > div > div:nth-child(1)';
static $clearFilter = '.nav-tabs a';

/**
* Insert testing data into the database
*
* @return void
*/
function setUp(): void
{
parent::setUp();
}
/**
* Delete testing data from database
*
* @return void
*/
function tearDown(): void
{
parent::tearDown();
}
/**
* Tests that, when loading the dicom_archive module > viewDetails subtest, some
* text appears in the body.
Expand Down
99 changes: 99 additions & 0 deletions modules/instruments/php/instrumentqueryengine.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,105 @@ class InstrumentQueryEngine implements \LORIS\Data\Query\QueryEngine
return;
}

/**
* Filter out candidates which do not match a criteria
*
* @param array $values The values from the
* instrument
* @param array $candidmap CandID map from
* commentID=>candID
* commentID=>candID
* @param string $fieldname The field to compare
* @param \LORIS\Data\Query\Criteria $criteria The criteria which the field
* must match.
*
* @return \Traversable CandIDs that matched criteria
*/
private function _filtered(
$values,
$candidmap,
$fieldname,
$criteria
) : \Traversable {
foreach ($values as $inst) {
$value = $inst->getFieldValue($fieldname);

switch (get_class($criteria)) {
case \LORIS\Data\Query\Criteria\In::class:
foreach ($criteria->getValue() as $valuecandidate) {
if ($value == $valuecandidate) {
yield $candidmap[$inst->getCommentID()];
}
}
break;
case \LORIS\Data\Query\Criteria\LessThan::class:
if ($value !== null && $value < $criteria->getValue()) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\LessThanOrEqual::class:
if ($value !== null && $value <= $criteria->getValue()) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\Equal::class:
if ($value !== null && $value == $criteria->getValue()) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\NotEqual::class:
if ($value !== null && $value != $criteria->getValue()) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\GreaterThanOrEqual::class:
if ($value !== null && $value >= $criteria->getValue()) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\GreaterThan::class:
if ($value !== null && $value > $criteria->getValue()) {
yield $candidmap[$inst->getCommentID()];
}
break;

case \LORIS\Data\Query\Criteria\IsNull::class:
if ($value === null) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\NotNull::class:
if ($value !== null) {
yield $candidmap[$inst->getCommentID()];
}
break;

case \LORIS\Data\Query\Criteria\StartsWith::class:
if ($value !== null && strpos($value, $criteria->getValue()) === 0) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\EndsWith::class:
$critval = $criteria->getValue();
$matches = strrpos($value, $critval)
=== strlen($value)-strlen($critval);
if ($value !== null && $matches) {
yield $candidmap[$inst->getCommentID()];
}
break;
case \LORIS\Data\Query\Criteria\Substring::class:
if ($value !== null
&& strpos($value, $criteria->getValue()) !== false
) {
yield $candidmap[$inst->getCommentID()];
}
break;
default:
throw new \Exception("Unhandled operator: " . get_class($criteria));
}
}
}

/**
* Get list of visits that an instrument is valid at
*
Expand Down
25 changes: 0 additions & 25 deletions src/LorisInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,6 @@ public function getDatabaseConnection() : \Database
return $this->DB;
}

public function getNewDatabaseConnection() : \Database
{
$settings = \NDB_Factory::singleton()->settings();

// Pass the credentials in environment variables, so that they
// don't potentially show up in a stack trace if something goes
// wrong.
$dbname = $settings->dbName();
putenv("LORIS_{$dbname}_USERNAME=" . $settings->dbUserName());
putenv("LORIS_{$dbname}_PASSWORD=" . $settings->dbPassword());
putenv("LORIS_{$dbname}_HOST=" . $settings->dbHost());

$db = new \Database();
$db->connect(
$settings->dbName(),
true,
);

// Unset the variables now that they're no longer needed.
putenv("LORIS_{$dbname}_USERNAME=");
putenv("LORIS_{$dbname}_PASSWORD=");
putenv("LORIS_{$dbname}_HOST=");
return $db;
}

/**
* Return a new database connection to this LORIS instance.
*
Expand Down

0 comments on commit 57d2d10

Please sign in to comment.