Skip to content

Commit

Permalink
Merge branch 'main' into 2020_07_29_Data_entry_completion_status_flag…
Browse files Browse the repository at this point in the history
…_column
  • Loading branch information
CamilleBeau authored Dec 8, 2020
2 parents c812bb5 + f357300 commit a4594bf
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 124 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ requesting a new account and will be displayed in the User Accounts module (PR #
### Notes For Existing Projects
- After script `Set_Data_entry_completion_status_flag.php` is run, projects will need to go through existing instruments
and delete the `Data_entry_completion_status` column.
- New function Candidate::getSubjectForMostRecentVisit replaces Utility::getSubprojectIDUsingCandID, adding ability to determine which subproject a candidate belongs to given their most recent visit.
### Notes For Developers
- *Add item here*

Expand Down
2 changes: 1 addition & 1 deletion modules/create_timepoint/php/timepoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Timepoint extends \NDB_Page implements ETagCalculator
// List languages
$languages = \Utility::getLanguageList();
if (count($languages) > 1) {
array_unshift($languages, null);
$languages = [null] + $languages;
}
$values['languages'] = $languages;

Expand Down
17 changes: 6 additions & 11 deletions modules/instrument_list/php/instrument_list.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,13 @@ class Instrument_List extends \NDB_Menu_Filter
$battery = new \NDB_BVL_Battery;
$battery->selectBattery($this->timePoint->getSessionID());

$this->tpl_data['stage'] = \Utility::getStageUsingCandID(
$this->tpl_data['candID']
);
$this->tpl_data['subprojectID'] = \Utility::getSubprojectIDUsingCandID(
$this->tpl_data['stage'] = \Utility::getStageUsingCandID(
$this->tpl_data['candID']
);

// get the list of instruments
$listOfInstruments = $this->getBatteryInstrumentList(
$this->tpl_data['stage'],
$this->tpl_data['subprojectID']
$this->tpl_data['stage']
);

// display list of instruments
Expand Down Expand Up @@ -309,15 +305,14 @@ class Instrument_List extends \NDB_Menu_Filter
* Gets an associative array of instruments which are members of the current
* battery for instrument list module
*
* @param string $stage Either 'visit' or 'screening' - determines
* whether to register only screening instruments
* or visit instruments
* @param integer $SubprojectID The SubprojectID of that we want the battery for.
* @param string $stage Either 'visit' or 'screening' - determines
* whether to register only screening instruments
* or visit instruments
*
* @return array an associative array containing Test_name,
* Full_name, Sub_group, CommentID
*/
function getBatteryInstrumentList($stage=null, $SubprojectID=null)
function getBatteryInstrumentList($stage=null)
{
$DB = \Database::singleton();

Expand Down
29 changes: 28 additions & 1 deletion php/libraries/Candidate.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,35 @@ class Candidate implements \LORIS\StudyEntities\AccessibleResource

return $subprojList;
}

/**
* Returns the SubprojectID and subproject title of the candidate's last visit
* based on Date_visit
*
* @return array|null Array with values SubprojectID and title
* for the candidate's last visit or NULL if none exist
*/
public function getSubprojectForMostRecentVisit(): ?array
{
$factory = NDB_Factory::singleton();
$db = $factory->database();

$candID = $this->getCandID();
$query = "SELECT SubprojectID, title FROM session
LEFT JOIN subproject USING (SubprojectID)
WHERE CandID=:cid AND Date_visit IS NOT NULL
ORDER BY Date_visit DESC LIMIT 1";
$where = ['cid' => $candID];
$result = $db->pselect($query, $where);

if (empty($result)) {
return null;
}
return $result[0];
}

/**
* Returns first visit for a candidate based on Date_visit
* Returns first visit for a candidate based on VisitNo
*
* @return string The visit label for the candidate's first visit
*/
Expand Down
18 changes: 0 additions & 18 deletions php/libraries/Utility.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -586,24 +586,6 @@ class Utility
return $stage[0]['Current_stage'];
}

/**
* Looks up visit stage using candidate ID.
*
* @param string $Cand_id candidate ID
*
* @return int
* @throws DatabaseException
*/
static function getSubprojectIDUsingCandID(string $Cand_id): int
{
$factory = NDB_Factory::singleton();
$db = $factory->database();

$query = "select DISTINCT SubprojectID from session where CandID = :CandID";
$stage = $db->pselect($query, ['CandID' => $Cand_id]);
return intval($stage[0]['SubprojectID']);
}

/**
* Returns all the sourcefrom instruments from parameter_type
*
Expand Down
73 changes: 73 additions & 0 deletions test/unittests/CandidateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,79 @@ public function testGetValidSubprojectsReturnsEmptyArray(): void
$this->assertEquals($this->_candidate->getValidSubprojects(), []);
}

/**
* Test getSubprojectForMostRecentVisit returns most recent visit's label
*
* @covers Candidate::getSubprojectForMostRecentVisit
* @return void
*/
public function testGetSubprojectForMostRecentVisitReturnsMostRecentVisitLabel()
{
$subproject = [
[
'SubprojectID' => 1,
'title' => 'testSubproject'
]
];
$this->_dbMock->expects($this->once())
->method('pselectRow')
->willReturn($this->_candidateInfo);

$this->_candidate->select($this->_candidateInfo['CandID']);

$this->_dbMock->expects($this->any())
->method('pselect')
->with(
$this->stringContains(
"SELECT SubprojectID, title"
)
)
->willReturn(
$subproject
);

$expectedSubproject = [
'SubprojectID' => 1,
'title' => 'testSubproject'
];

$this->assertEquals(
$expectedSubproject,
$this->_candidate->getSubprojectForMostRecentVisit()
);
}

/**
* Test getSubprojectForMostRecentVisit returns null if there is
* no visit with a Date_visit
*
* @covers Candidate::getSubprojectForMostRecentVisit
* @return void
*/
public function testGetSubprojectForMostRecentVisitReturnsNull()
{
$subproject = [];
$this->_dbMock->expects($this->once())
->method('pselectRow')
->willReturn($this->_candidateInfo);

$this->_candidate->select($this->_candidateInfo['CandID']);

$this->_dbMock->expects($this->any())
->method('pselect')
->with(
$this->stringContains(
"SELECT SubprojectID, title"
)
)
->willReturn($subproject);

$this->assertEquals(
null,
$this->_candidate->getSubprojectForMostRecentVisit()
);
}

/**
* Test getFirstVisit returns first visit's label
*
Expand Down
42 changes: 21 additions & 21 deletions test/unittests/Database_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function testUpdateEscapesHTML()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['update']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['update']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
$stmt = $this->getMockBuilder('PDOStatement')->getMock();
Expand All @@ -199,7 +199,7 @@ function testUnsafeUpdateDoesntEscapeHTML()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['unsafeupdate']))
->onlyMethods($this->_getAllMethodsExcept(['unsafeupdate']))
->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
Expand All @@ -225,7 +225,7 @@ function testInsertEscapesHTML()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['insert']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['insert']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
$stmt = $this->getMockBuilder('PDOStatement')->getMock();
Expand All @@ -250,7 +250,7 @@ function testUnsafeInsertDoesntEscapeHTML()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['unsafeinsert']))
->onlyMethods($this->_getAllMethodsExcept(['unsafeinsert']))
->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
Expand Down Expand Up @@ -781,7 +781,7 @@ function testInsertOnDuplicateUpdateEscapesHTML()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods(
->onlyMethods(
$this->_getAllMethodsExcept(['insertOnDuplicateUpdate'])
)
->getMock();
Expand Down Expand Up @@ -812,7 +812,7 @@ function testUnsafeInsertOnDuplicateUpdateDoesntEscapeHTML()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods(
->onlyMethods(
$this->_getAllMethodsExcept(['unsafeInsertOnDuplicateUpdate'])
)
->getMock();
Expand Down Expand Up @@ -876,7 +876,7 @@ function testRun()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['run']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['run']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
$stmt = $this->getMockBuilder('PDOStatement')->getMock();
Expand All @@ -896,7 +896,7 @@ function testPrepare()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['prepare']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['prepare']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
$stmt = $this->getMockBuilder('PDOStatement')->getMock();
Expand Down Expand Up @@ -1013,7 +1013,7 @@ function testPselectCallsFunctions()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['pselect']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['pselect']))->getMock();

$stmt = $stub->prepare("SHOW TABLES");
$params = ['test' => 'test'];
Expand Down Expand Up @@ -1068,7 +1068,7 @@ function testPselectRowCallsPrepare()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['pselectRow']))
->onlyMethods($this->_getAllMethodsExcept(['pselectRow']))
->getMock();

$query = "SELECT ID, Name, Description, Visible FROM ConfigSettings";
Expand Down Expand Up @@ -1314,7 +1314,7 @@ function testInsertIgnore()
);
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['insertIgnore']))
->onlyMethods($this->_getAllMethodsExcept(['insertIgnore']))
->getMock();

$table = "ConfigSettings";
Expand Down Expand Up @@ -1580,7 +1580,7 @@ function testQuote()

$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['quote']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['quote']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();

Expand Down Expand Up @@ -1612,7 +1612,7 @@ function testInTransaction()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['inTransaction']))
->onlyMethods($this->_getAllMethodsExcept(['inTransaction']))
->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
Expand All @@ -1633,7 +1633,7 @@ function testBeginTransaction()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['beginTransaction']))
->onlyMethods($this->_getAllMethodsExcept(['beginTransaction']))
->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
Expand All @@ -1654,7 +1654,7 @@ function testBeginTransactionThrowsException()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['beginTransaction']))
->onlyMethods($this->_getAllMethodsExcept(['beginTransaction']))
->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
Expand All @@ -1674,7 +1674,7 @@ function testRollback()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['rollBack']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['rollBack']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();

Expand All @@ -1693,7 +1693,7 @@ function testRollbackThrowsException()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['rollBack']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['rollBack']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();

Expand All @@ -1712,7 +1712,7 @@ function testCommit()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['commit']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['commit']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();

Expand All @@ -1731,7 +1731,7 @@ function testCommitThrowsException()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['commit']))->getMock();
->onlyMethods($this->_getAllMethodsExcept(['commit']))->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();

Expand All @@ -1750,7 +1750,7 @@ function testIsConnectedNoPDO()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['isConnected']))
->onlyMethods($this->_getAllMethodsExcept(['isConnected']))
->getMock();

$val = $stub->isConnected();
Expand All @@ -1767,7 +1767,7 @@ function testIsConnectedWithPDO()
{
$this->_factory = NDB_Factory::singleton();
$stub = $this->getMockBuilder('FakeDatabase')
->addMethods($this->_getAllMethodsExcept(['isConnected']))
->onlyMethods($this->_getAllMethodsExcept(['isConnected']))
->getMock();

$stub->_PDO = $this->getMockBuilder('FakePDO')->getMock();
Expand Down
Loading

0 comments on commit a4594bf

Please sign in to comment.