Skip to content

Commit c38f1c1

Browse files
authored
Add CenterID class to LORIS (#7359)
This adds a new CenterID class and updates it throughout LORIS.
1 parent 8568d0d commit c38f1c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+349
-213
lines changed

modules/api/php/endpoints/candidate/visit/visit.class.inc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator
198198
'Project',
199199
];
200200
$diff = array_diff($requiredfields, array_keys($visitinfo));
201+
201202
if (!empty($diff)) {
202203
return new \LORIS\Http\Response\JSON\BadRequest(
203204
'Field(s) missing: ' . implode(', ', $diff)
@@ -226,13 +227,19 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator
226227

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

229-
if (!in_array($centerid, $user->getCenterIDs())) {
230+
if ($centerid === false
231+
|| !in_array(new \CenterID("$centerid"), $user->getCenterIDs())
232+
) {
230233
return new \LORIS\Http\Response\JSON\Forbidden(
231-
"You can't create or modify candidates visit for the site " .
234+
"You can't create or modify candidates visit for the site " .
232235
$centerid
233236
);
234237
}
235238

239+
// \Utility::getSiteList key was a string. Now that the
240+
// validation is done, convert to an object.
241+
$centerid = new \CenterID("$centerid");
242+
236243
$subprojectid = array_search(
237244
$visitinfo['Battery'],
238245
\Utility::getSubprojectList()

modules/api/php/endpoints/candidates.class.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Candidates extends Endpoint implements \LORIS\Middleware\ETagCalculator
187187
$usersites = $user->getSiteNames();
188188
if (!in_array($data['Candidate']['Site'], $usersites)) {
189189
return new \LORIS\Http\Response\JSON\Forbidden(
190-
'You are not affiliated with the candidate`s site'
190+
"You are not affiliated with the candidate's site"
191191
);
192192
}
193193

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

210210
try {
211211
$candid = \Candidate::createNew(
212-
$centerid,
212+
new \CenterID("$centerid"),
213213
$data['Candidate']['DoB'],
214214
$data['Candidate']['EDC'],
215215
$sex,

modules/api/php/models/candidatesrow.class.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CandidatesRow implements \LORIS\Data\DataInstance,
3131
private $_edc;
3232
private $_dob;
3333
private $_sex;
34-
private $_centerid;
34+
private \CenterID $_centerid;
3535

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

5656
/**
@@ -78,14 +78,14 @@ class CandidatesRow implements \LORIS\Data\DataInstance,
7878
* Returns the CenterID for this row, for filters such as
7979
* \LORIS\Data\Filters\UserSiteMatch to match against.
8080
*
81-
* @return integer The CenterID
81+
* @return \CenterID The CenterID
8282
*/
83-
public function getCenterID(): int
83+
public function getCenterID(): \CenterID
8484
{
8585
if ($this->_centerid === null) {
8686
throw new \Exception('CenterID is null');
8787
}
88-
return intval($this->_centerid);
88+
return $this->_centerid;
8989
}
9090

9191
/**

modules/api/php/models/projectimagesrow.class.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ProjectImagesRow implements \LORIS\Data\DataInstance,
2828
private $_entitytype;
2929
private $_visitlabel;
3030
private $_visitdate;
31-
private $_centerid;
31+
private \CenterID $_centerid;
3232
private $_centername;
3333
private $_filename;
3434
private $_inserttime;
@@ -48,7 +48,7 @@ class ProjectImagesRow implements \LORIS\Data\DataInstance,
4848
$this->_entitytype = $row['Entity_type'] ?? null;
4949
$this->_visitlabel = $row['Visit'] ?? null;
5050
$this->_visitdate = $row['Visit_date'] ?? null;
51-
$this->_centerid = $row['CenterID'] ?? null;
51+
$this->_centerid = new \CenterID($row['CenterID']);
5252
$this->_centername = $row['Site'] ?? null;
5353
$this->_filename = $row['File'] ?? null;
5454
$this->_inserttime = $row['InsertTime'] ?? null;
@@ -89,11 +89,11 @@ class ProjectImagesRow implements \LORIS\Data\DataInstance,
8989
* Returns the CenterID for this row, for filters such as
9090
* \LORIS\Data\Filters\UserSiteMatch to match again.
9191
*
92-
* @return integer The CenterID
92+
* @return \CenterID
9393
*/
94-
public function getCenterID(): int
94+
public function getCenterID(): \CenterID
9595
{
96-
return intval($this->_centerid);
96+
return $this->_centerid;
9797
}
9898

9999
/**

modules/candidate_list/php/candidatelistrow.class.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CandidateListRow implements \LORIS\Data\DataInstance,
2929
\LORIS\StudyEntities\SiteHaver
3030
{
3131
protected $DBRow;
32-
protected $CenterID;
32+
protected \CenterID $CenterID;
3333
protected $ProjectID;
3434

3535
/**
@@ -38,10 +38,10 @@ class CandidateListRow implements \LORIS\Data\DataInstance,
3838
* @param array $row The row (in the same format as
3939
* \Database::pselectRow
4040
* returns.)
41-
* @param integer $cid The centerID affiliated with this row.
41+
* @param \CenterID $cid The centerID affiliated with this row.
4242
* @param \ProjectID $pid The projectID affiliated with this row.
4343
*/
44-
public function __construct(array $row, int $cid, \ProjectID $pid)
44+
public function __construct(array $row, \CenterID $cid, \ProjectID $pid)
4545
{
4646
$this->DBRow = $row;
4747
$this->CenterID = $cid;
@@ -62,9 +62,9 @@ class CandidateListRow implements \LORIS\Data\DataInstance,
6262
* Returns the CenterID for this row, for filters such as
6363
* \LORIS\Data\Filters\UserSiteMatch to match again.
6464
*
65-
* @return integer The CenterID
65+
* @return \CenterID
6666
*/
67-
public function getCenterID(): int
67+
public function getCenterID(): \CenterID
6868
{
6969
return $this->CenterID;
7070
}

modules/candidate_list/php/candidatelistrowprovisioner.class.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CandidateListRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisio
9595
// user's sites, but for now this maintains the previous
9696
// behaviour of requiring the registration site to match
9797
// one of the user's sites.
98-
$cid = (int) $row['RegistrationCenterID'];
98+
$cid = new \CenterID($row['RegistrationCenterID']);
9999
$pid = new \ProjectID($row['RegistrationProjectID']);
100100
unset($row['RegistrationCenterID']);
101101
unset($row['RegistrationProjectID']);

modules/create_timepoint/php/timepoint.class.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class Timepoint extends \NDB_Page implements ETagCalculator
183183
if ($num_sites == 1) {
184184
$site = \Site::singleton($user_list_of_sites[0]);
185185
} else if ($num_sites > 1) {
186-
$site = \Site::singleton(intval($values['psc']));
186+
$site = \Site::singleton(new \CenterID(($values['psc'])));
187187
}
188188

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

257257
// validate site entered
258-
$site = (int) $values['psc'];
258+
$site = !empty($values['psc']) ? new \CenterID($values['psc']) : null;
259+
259260
$user_list_of_sites = $user->getCenterIDs();
260261
$num_sites = count($user_list_of_sites);
261262
$conflict = [];

modules/dicom_archive/php/dicomarchiveanonymizer.class.inc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,11 @@ class DICOMArchiveAnonymizer implements Mapper
5050
$config = \NDB_Config::singleton()->getSetting("imaging_modules");
5151
}
5252

53-
if (!$resource instanceof \LORIS\StudyEntities\SiteHaver) {
54-
throw new \LorisException(
55-
"Mapper requires a resource type with getCenterID"
56-
);
57-
}
5853
$newrow = json_decode(json_encode($resource), true);
5954
if (!is_array($newrow)) {
6055
throw new \Exception("Error converting DataInstance to array");
6156
}
6257

63-
$cid = $resource->getCenterID();
64-
6558
// escape any forward slashes
6659
$pNameRegex = preg_replace(
6760
'/\//',
@@ -103,6 +96,12 @@ class DICOMArchiveAnonymizer implements Mapper
10396
if (!preg_match("/$pIDRegex/", $newrow['patientID'] ?? '')) {
10497
$newrow['patientID'] = 'INVALID - HIDDEN';
10598
}
106-
return new DICOMArchiveRow($newrow, $cid);
99+
100+
if (!$resource instanceof \LORIS\StudyEntities\SiteHaver) {
101+
return new DICOMArchiveRowWithoutSession($newrow);
102+
} else {
103+
$cid = $resource->getCenterID();
104+
return new DICOMArchiveRowWithSession($newrow, $cid);
105+
}
107106
}
108107
}

modules/dicom_archive/php/dicomarchiverowprovisioner.class.inc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ class DicomArchiveRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvision
7272
*/
7373
public function getInstance($row) : \LORIS\Data\DataInstance
7474
{
75-
$cid = (int) $row['CenterID'];
75+
if ($row['CenterID'] !== null) {
76+
$cid = new \CenterID($row['CenterID']);
7677
unset($row['CenterID']);
77-
return new DICOMArchiveRow($row, $cid);
78+
return new DICOMArchiveRowWithSession($row, $cid);
79+
}
80+
unset($row['CenterID']);
81+
return new DICOMArchiveRowWithoutSession($row);
7882
}
7983
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* This class implements a data Instance which represents a single
4+
* row in the dicom archive menu table.
5+
*
6+
* PHP Version 7
7+
*
8+
* @category Behavioural
9+
* @package Main
10+
* @subpackage Imaging
11+
* @author Dave MacFarlane <david.macfarlane2@mcgill.ca>
12+
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
13+
* @link https://www.github.com/aces/Loris/
14+
*/
15+
16+
namespace LORIS\dicom_archive;
17+
18+
/**
19+
* A DICOMArchiveRow represents a row in the DICOM Archive menu table.
20+
*
21+
* @category Behavioural
22+
* @package Main
23+
* @subpackage Imaging
24+
* @author Dave MacFarlane <david.macfarlane2@mcgill.ca>
25+
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
26+
* @link https://www.github.com/aces/Loris/
27+
*/
28+
class DICOMArchiveRowWithoutSession implements \LORIS\Data\DataInstance
29+
{
30+
protected $DBRow;
31+
32+
/**
33+
* Create a new DICOMArchiveRow without a session.
34+
*
35+
* Session-less DICOMArchiveRows do not have CenterIDs to be filtered
36+
* by.
37+
*
38+
* @param array $row The row (in the same format as \Database::pselectRow
39+
* returns)
40+
*/
41+
public function __construct(array $row)
42+
{
43+
$this->DBRow = $row;
44+
}
45+
46+
/**
47+
* Implements \LORIS\Data\DataInstance interface for this row.
48+
*
49+
* @return array which can be serialized by json_encode()
50+
*/
51+
public function jsonSerialize() : array
52+
{
53+
return $this->DBRow;
54+
}
55+
}

0 commit comments

Comments
 (0)