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

Add CenterID class to LORIS #7359

Merged
merged 33 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6b20c5e
Replace more method_exists checks with instanceof checks
driusan Feb 15, 2021
8be9c0d
Add CenterID class and begin using it
driusan Feb 12, 2021
179eb8f
Update signatures in User class and start fixing
driusan Feb 12, 2021
94ef37e
Update interfaces signatures
driusan Feb 15, 2021
c6aa546
Fix type errors identified by phan
driusan Feb 15, 2021
8eb0226
Fix CenterIDs for User
driusan Feb 15, 2021
417cd0b
phpcs
driusan Feb 15, 2021
d8c2e79
More phan errors after rebase
driusan Feb 26, 2021
216f61c
phpcs
driusan Feb 26, 2021
c168a00
Add missing file
driusan Feb 26, 2021
cb7471a
try to fix some tests
driusan Feb 26, 2021
1f76581
more unit tests
driusan Feb 26, 2021
9af04a7
more
driusan Feb 26, 2021
2c825e3
more test fixing
driusan Mar 17, 2021
f7c9aa1
Maybe fix?
driusan Mar 22, 2021
f651a01
Fix typo in comment
driusan Mar 22, 2021
198d704
Try interpolating instead of casting string
driusan Mar 22, 2021
6e80dd9
dump some info for debugging
driusan Mar 22, 2021
a72fe10
Add RegistrationCenterID case
driusan Mar 24, 2021
c7c1bed
Unused variable and remove debugging var_dumps
driusan Mar 24, 2021
95a6ac5
Fix double construction of CenterID object
driusan Mar 24, 2021
4563876
Add debugging statements to failing test
driusan Mar 24, 2021
cce14da
Dump function call output
driusan Mar 24, 2021
0ac4e12
output the booleans too
driusan Mar 24, 2021
5ebda59
add onlyMethods
driusan Mar 24, 2021
4e434c6
Remove extra debugging calls
driusan Mar 24, 2021
8db1449
Fix an API endpoint
driusan Mar 24, 2021
7fa8318
Fix timepoint accessibility check
driusan Mar 24, 2021
d7b8072
Fix more API integration tests
driusan Mar 24, 2021
4a4ac28
phpcs
driusan Mar 24, 2021
1e4d42f
Fix candidate creation when user has multiple sites
driusan Apr 26, 2021
645367b
Handle both tarchive rows that have a session and that do not
driusan Apr 28, 2021
f6f512d
phpcs
driusan Apr 28, 2021
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
11 changes: 9 additions & 2 deletions modules/api/php/endpoints/candidate/visit/visit.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator
'Project',
];
$diff = array_diff($requiredfields, array_keys($visitinfo));

if (!empty($diff)) {
return new \LORIS\Http\Response\JSON\BadRequest(
'Field(s) missing: ' . implode(', ', $diff)
Expand Down Expand Up @@ -226,13 +227,19 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator

$centerid = array_search($visitinfo['Site'], \Utility::getSiteList());

if (!in_array($centerid, $user->getCenterIDs())) {
if ($centerid === false
|| !in_array(new \CenterID("$centerid"), $user->getCenterIDs())
) {
return new \LORIS\Http\Response\JSON\Forbidden(
"You can't create or modify candidates visit for the site " .
"You can't create or modify candidates visit for the site " .
$centerid
);
}

// \Utility::getSiteList key was a string. Now that the
// validation is done, convert to an object.
$centerid = new \CenterID("$centerid");

$subprojectid = array_search(
$visitinfo['Battery'],
\Utility::getSubprojectList()
Expand Down
4 changes: 2 additions & 2 deletions modules/api/php/endpoints/candidates.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Candidates extends Endpoint implements \LORIS\Middleware\ETagCalculator
$usersites = $user->getSiteNames();
if (!in_array($data['Candidate']['Site'], $usersites)) {
return new \LORIS\Http\Response\JSON\Forbidden(
'You are not affiliated with the candidate`s site'
"You are not affiliated with the candidate's site"
);
}

Expand All @@ -209,7 +209,7 @@ class Candidates extends Endpoint implements \LORIS\Middleware\ETagCalculator

try {
$candid = \Candidate::createNew(
$centerid,
new \CenterID("$centerid"),
$data['Candidate']['DoB'],
$data['Candidate']['EDC'],
$sex,
Expand Down
10 changes: 5 additions & 5 deletions modules/api/php/models/candidatesrow.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CandidatesRow implements \LORIS\Data\DataInstance,
private $_edc;
private $_dob;
private $_sex;
private $_centerid;
private \CenterID $_centerid;

/**
* Create a new CandidatesRow.
Expand All @@ -50,7 +50,7 @@ class CandidatesRow implements \LORIS\Data\DataInstance,
$this->_edc = $row['EDC'] ?? null;
$this->_dob = $row['DoB'] ?? null;
$this->_sex = $row['Sex'] ?? null;
$this->_centerid = $row['CenterID'] ?? null;
$this->_centerid = new \CenterID($row['CenterID']);
}

/**
Expand Down Expand Up @@ -78,14 +78,14 @@ class CandidatesRow implements \LORIS\Data\DataInstance,
* Returns the CenterID for this row, for filters such as
* \LORIS\Data\Filters\UserSiteMatch to match against.
*
* @return integer The CenterID
* @return \CenterID The CenterID
*/
public function getCenterID(): int
public function getCenterID(): \CenterID
{
if ($this->_centerid === null) {
throw new \Exception('CenterID is null');
}
return intval($this->_centerid);
return $this->_centerid;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions modules/api/php/models/projectimagesrow.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ProjectImagesRow implements \LORIS\Data\DataInstance,
private $_entitytype;
private $_visitlabel;
private $_visitdate;
private $_centerid;
private \CenterID $_centerid;
private $_centername;
private $_filename;
private $_inserttime;
Expand All @@ -48,7 +48,7 @@ class ProjectImagesRow implements \LORIS\Data\DataInstance,
$this->_entitytype = $row['Entity_type'] ?? null;
$this->_visitlabel = $row['Visit'] ?? null;
$this->_visitdate = $row['Visit_date'] ?? null;
$this->_centerid = $row['CenterID'] ?? null;
$this->_centerid = new \CenterID($row['CenterID']);
$this->_centername = $row['Site'] ?? null;
$this->_filename = $row['File'] ?? null;
$this->_inserttime = $row['InsertTime'] ?? null;
Expand Down Expand Up @@ -89,11 +89,11 @@ class ProjectImagesRow implements \LORIS\Data\DataInstance,
* Returns the CenterID for this row, for filters such as
* \LORIS\Data\Filters\UserSiteMatch to match again.
*
* @return integer The CenterID
* @return \CenterID
*/
public function getCenterID(): int
public function getCenterID(): \CenterID
{
return intval($this->_centerid);
return $this->_centerid;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions modules/candidate_list/php/candidatelistrow.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CandidateListRow implements \LORIS\Data\DataInstance,
\LORIS\StudyEntities\SiteHaver
{
protected $DBRow;
protected $CenterID;
protected \CenterID $CenterID;
protected $ProjectID;

/**
Expand All @@ -38,10 +38,10 @@ class CandidateListRow implements \LORIS\Data\DataInstance,
* @param array $row The row (in the same format as
* \Database::pselectRow
* returns.)
* @param integer $cid The centerID affiliated with this row.
* @param \CenterID $cid The centerID affiliated with this row.
* @param \ProjectID $pid The projectID affiliated with this row.
*/
public function __construct(array $row, int $cid, \ProjectID $pid)
public function __construct(array $row, \CenterID $cid, \ProjectID $pid)
{
$this->DBRow = $row;
$this->CenterID = $cid;
Expand All @@ -62,9 +62,9 @@ class CandidateListRow implements \LORIS\Data\DataInstance,
* Returns the CenterID for this row, for filters such as
* \LORIS\Data\Filters\UserSiteMatch to match again.
*
* @return integer The CenterID
* @return \CenterID
*/
public function getCenterID(): int
public function getCenterID(): \CenterID
{
return $this->CenterID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CandidateListRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisio
// user's sites, but for now this maintains the previous
// behaviour of requiring the registration site to match
// one of the user's sites.
$cid = (int) $row['RegistrationCenterID'];
$cid = new \CenterID($row['RegistrationCenterID']);
$pid = new \ProjectID($row['RegistrationProjectID']);
unset($row['RegistrationCenterID']);
unset($row['RegistrationProjectID']);
Expand Down
5 changes: 3 additions & 2 deletions modules/create_timepoint/php/timepoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Timepoint extends \NDB_Page implements ETagCalculator
if ($num_sites == 1) {
$site = \Site::singleton($user_list_of_sites[0]);
} else if ($num_sites > 1) {
$site = \Site::singleton(intval($values['psc']));
$site = \Site::singleton(new \CenterID(($values['psc'])));
}

// Project
Expand Down Expand Up @@ -255,7 +255,8 @@ class Timepoint extends \NDB_Page implements ETagCalculator
null : $values['psc'];

// validate site entered
$site = (int) $values['psc'];
$site = !empty($values['psc']) ? new \CenterID($values['psc']) : null;

$user_list_of_sites = $user->getCenterIDs();
$num_sites = count($user_list_of_sites);
$conflict = [];
Expand Down
15 changes: 7 additions & 8 deletions modules/dicom_archive/php/dicomarchiveanonymizer.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,11 @@ class DICOMArchiveAnonymizer implements Mapper
$config = \NDB_Config::singleton()->getSetting("imaging_modules");
}

if (!$resource instanceof \LORIS\StudyEntities\SiteHaver) {
throw new \LorisException(
"Mapper requires a resource type with getCenterID"
);
}
$newrow = json_decode(json_encode($resource), true);
if (!is_array($newrow)) {
throw new \Exception("Error converting DataInstance to array");
}

$cid = $resource->getCenterID();

// escape any forward slashes
$pNameRegex = preg_replace(
'/\//',
Expand Down Expand Up @@ -103,6 +96,12 @@ class DICOMArchiveAnonymizer implements Mapper
if (!preg_match("/$pIDRegex/", $newrow['patientID'] ?? '')) {
$newrow['patientID'] = 'INVALID - HIDDEN';
}
return new DICOMArchiveRow($newrow, $cid);

if (!$resource instanceof \LORIS\StudyEntities\SiteHaver) {
return new DICOMArchiveRowWithoutSession($newrow);
} else {
$cid = $resource->getCenterID();
return new DICOMArchiveRowWithSession($newrow, $cid);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ class DicomArchiveRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvision
*/
public function getInstance($row) : \LORIS\Data\DataInstance
{
$cid = (int) $row['CenterID'];
if ($row['CenterID'] !== null) {
$cid = new \CenterID($row['CenterID']);
unset($row['CenterID']);
return new DICOMArchiveRow($row, $cid);
return new DICOMArchiveRowWithSession($row, $cid);
}
unset($row['CenterID']);
return new DICOMArchiveRowWithoutSession($row);
}
}
55 changes: 55 additions & 0 deletions modules/dicom_archive/php/dicomarchiverowwithoutsession.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* This class implements a data Instance which represents a single
* row in the dicom archive menu table.
*
* PHP Version 7
*
* @category Behavioural
* @package Main
* @subpackage Imaging
* @author Dave MacFarlane <david.macfarlane2@mcgill.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/

namespace LORIS\dicom_archive;

/**
* A DICOMArchiveRow represents a row in the DICOM Archive menu table.
*
* @category Behavioural
* @package Main
* @subpackage Imaging
* @author Dave MacFarlane <david.macfarlane2@mcgill.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
class DICOMArchiveRowWithoutSession implements \LORIS\Data\DataInstance
{
protected $DBRow;

/**
* Create a new DICOMArchiveRow without a session.
*
* Session-less DICOMArchiveRows do not have CenterIDs to be filtered
* by.
*
* @param array $row The row (in the same format as \Database::pselectRow
* returns)
*/
public function __construct(array $row)
{
$this->DBRow = $row;
}

/**
* Implements \LORIS\Data\DataInstance interface for this row.
*
* @return array which can be serialized by json_encode()
*/
public function jsonSerialize() : array
{
return $this->DBRow;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@ namespace LORIS\dicom_archive;
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
class DICOMArchiveRow implements \LORIS\Data\DataInstance,
class DICOMArchiveRowWithSession implements \LORIS\Data\DataInstance,
\LORIS\StudyEntities\SiteHaver
{
protected $DBRow;
protected $CenterID;

/**
* Create a new DICOMArchiveRow
* Create a new DICOMArchiveRowWithSession.
*
* @param array $row The row (in the same format as \Database::pselectRow
* returns
* @param integer $cid The centerID affiliated with this row.
* This DataInstance type represents rows that have a session associated
* with them (and hence are able to return a CenterID for the row.)
*
* @param array $row The row (in the same format as \Database::pselectRow
* returns)
* @param \CenterID $cid The centerID affiliated with this row.
*/
public function __construct(array $row, $cid)
public function __construct(array $row, \CenterID $cid)
{
$this->DBRow = $row;
$this->CenterID = $cid;
Expand All @@ -58,9 +61,9 @@ class DICOMArchiveRow implements \LORIS\Data\DataInstance,
* Returns the CenterID for this row, for filters such as
* \LORIS\Data\Filters\UserSiteMatch to match again.
*
* @return integer The CenterID
* @return \CenterID
*/
public function getCenterID() : int
public function getCenterID() : \CenterID
{
return $this->CenterID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class ElectrophysiologyBrowserRow implements \LORIS\Data\DataInstance,
*
* @param array $row The row (in the same format as
* \Database::pselectRow returns
* @param integer $cid The centerID affiliated with this row.
* @param \CenterID $cid The centerID affiliated with this row.
* @param \ProjectID $pid The projectID affiliated with this row.
*/
public function __construct(array $row, int $cid, \ProjectID $pid)
public function __construct(array $row, \CenterID $cid, \ProjectID $pid)
{
$this->DBRow = $row;
$this->CenterID = $cid;
Expand All @@ -62,9 +62,9 @@ class ElectrophysiologyBrowserRow implements \LORIS\Data\DataInstance,
* Returns the CenterID for this row, for filters such as
* \LORIS\Data\Filters\UserSiteMatch to match again.
*
* @return integer The CenterID
* @return \CenterID
*/
public function getCenterID(): int
public function getCenterID(): \CenterID
{
return $this->CenterID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ElectrophysiologyBrowserRowProvisioner
*/
public function getInstance($row) : \LORIS\Data\DataInstance
{
$cid = (int )$row['CenterID'];
$cid = new \CenterID($row['CenterID']);
$pid = new \ProjectID($row['ProjectID']);
unset($row['CenterID']);
unset($row['ProjectID']);
Expand Down
16 changes: 8 additions & 8 deletions modules/imaging_browser/php/imagingbrowserrow.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class ImagingBrowserRow implements \LORIS\Data\DataInstance,
\LORIS\StudyEntities\SiteHaver
{
protected $DBRow;
protected $CenterID;
protected \CenterID $CenterID;
protected $ProjectID;

/**
* Create a new ImagingBrowserRow
*
* @param array $row The row (in the same format as \Database::pselectRow
* returns
* @param integer $cid The centerID affiliated with this row.
* @param integer $pid The projectID affiliated with this row.
* @param array $row The row (in the same format as \Database::pselectRow
* returns
* @param \CenterID $cid The centerID affiliated with this row.
* @param integer $pid The projectID affiliated with this row.
*/
public function __construct(array $row, int $cid, int $pid)
public function __construct(array $row, \CenterID $cid, int $pid)
{
$this->DBRow = $row;
$this->CenterID = $cid;
Expand All @@ -61,9 +61,9 @@ class ImagingBrowserRow implements \LORIS\Data\DataInstance,
* Returns the CenterID for this row, for filters such as
* \LORIS\Data\Filters\UserSiteMatch to match again.
*
* @return integer The CenterID
* @return \CenterID
*/
public function getCenterID(): int
public function getCenterID(): \CenterID
{
return $this->CenterID;
}
Expand Down
Loading