Skip to content

Commit

Permalink
Add Project endpoint "Dicoms"
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 817b148
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Nov 9 15:17:49 2020 -0500

    adding comment about since parameter

commit f4892d6
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Nov 6 13:12:55 2020 -0500

    change classname in construct to include namespace

commit b4f7f60
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Nov 5 14:40:50 2020 -0500

    corrections

commit 65eefba
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Nov 5 00:12:31 2020 -0500

    fixing endpoint name

commit 226230e
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Nov 5 00:00:42 2020 -0500

    remove old files

commit cc79194
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 16:35:17 2020 -0500

    CHANGELOG was not updated

commit ec0f492
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 16:34:23 2020 -0500

    CHANGELOG was not updated

commit e8c4ad2
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 16:23:51 2020 -0500

    updating doc update

commit 6f34893
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 16:05:12 2020 -0500

    getting out of rebase hell and solving conflicts

commit 2350ea0
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 15:46:16 2020 -0500

    Revert "rollback to v1.x"

    This reverts commit d9db7d7.

commit 48fdddd
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 15:46:08 2020 -0500

    Revert "update"

    This reverts commit 211d96d.

commit 2fbf050
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 15:45:59 2020 -0500

    Revert "Revert "update""

    This reverts commit 0022745.

commit c1c90fc
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 15:45:33 2020 -0500

    Revert "removing change to travis"

    This reverts commit e7e4cb6.

commit e7e4cb6
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 15:39:04 2020 -0500

    removing change to travis

commit 0022745
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Nov 4 15:36:07 2020 -0500

    Revert "update"

    This reverts commit 0e89111.

commit 211d96d
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Nov 3 13:01:13 2020 -0500

    update

commit d9db7d7
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Nov 3 11:48:04 2020 -0500

    rollback to v1.x

commit f8aae97
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Nov 2 14:16:09 2020 -0500

    Changing classes names ProjectDicoms

commit 71203c1
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Nov 2 13:37:51 2020 -0500

    v0.0.4-dev not v0.0.4

commit e125284
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Oct 29 16:11:27 2020 -0400

    LorisApiAuthenticatedTest.php had unnecessary modifications

commit 92b9517
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Oct 29 16:09:58 2020 -0400

    LorisApiAuthenticatedTest.php had unnecessary modifications

commit 8c9df99
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Oct 29 11:31:21 2020 -0400

    Trying to readd newline at end of file because git complains

commit 2f9359a
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Oct 29 11:30:03 2020 -0400

    Trying to readd newline at end of file because git complains

commit ba45736
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Oct 29 10:32:18 2020 -0400

    fixing things

commit 2333bed
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Sep 18 12:17:30 2020 -0400

    correct integration test typo

commit 682e337
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Sep 18 11:11:22 2020 -0400

    [API] Corrects the tests for the new Projects Dicoms endpoint

commit 6dd799a
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Sep 4 15:12:43 2020 -0400

    Adds the integration tests for \Project Dicoms endpoint

commit d6ca120
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:47:57 2020 -0400

    [API] weird new file removed

commit d36d982
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:43:26 2020 -0400

    [API] Fix Travis again

commit d3bdd67
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Aug 3 15:29:55 2020 -0400

    [API] Changed toJSON to jsonSerialize and resored strict_types declaration

commit 4b70446
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Jun 29 13:30:08 2020 -0400

    [API] In \project dicoms endpoints: Corrected travis errors

commit 6606b4f
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 23 16:11:12 2020 -0400

    [API] Creation of endpoint /project/{project}/dicoms

commit 63be090
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 23 16:08:40 2020 -0400

    [API] Creation of endpoint /project/{project}/dicoms

commit 5f8c88d
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 17:56:07 2020 -0400

    [API] adds v0.0.4 in the supported versions of the /candidate dicom endpoint

commit 97ef8f6
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 16:27:15 2020 -0400

    [API] correct travis errors

commit 4a67189
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 15:24:01 2020 -0400

    [API] changes version in new spec document and removes other errors

commit fd87690
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 15:12:35 2020 -0400

    initial commit of transition to api v0.0.4

commit 002e090
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 14:58:08 2020 -0400

    initial commit of transition to api v0.0.4

commit a55b304
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 13:04:02 2020 -0400

    [API] Candidates are now filtered by allowed project ids

commit fe3cb93
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 10:34:35 2020 -0400

    [API] Add getProjectID to candidatesrow model

commit b192d15
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Oct 29 10:32:18 2020 -0400

    fixing things

commit 806e9b5
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Sep 18 12:35:46 2020 -0400

    Announce of the new version of the API in CHANGELOG.md

commit 9eb937e
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Sep 4 16:22:37 2020 -0400

    Addresses comment to clean code

commit fdef2d8
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Sep 2 14:15:28 2020 -0400

    [API] Fixes Travis checks in projectdicomsobject

commit 9c1cf05
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Sep 2 14:06:22 2020 -0400

    [API] Adds Projects \Dicoms endpoint to the specs and corrects FileName to be displayed

commit 51b1169
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Sep 2 13:55:30 2020 -0400

    Makes it available only in v0.0.4 and Path changed to filename

commit 83903b7
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 11:12:49 2020 -0400

    [API] Removes useless condition in _hasAccess function

commit 40afcfc
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Aug 25 15:07:15 2020 -0400

    [API] Adding checkign user permission

commit 3cd3a66
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Sun Aug 23 14:28:41 2020 -0400

    Solves Possibly zero references to use statement in travis

commit 0266890
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:53:54 2020 -0400

    [API] correct mistakes

commit 42a8d5f
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:47:57 2020 -0400

    [API] weird new file removed

commit 27c00c1
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:46:26 2020 -0400

    [API] weird new file removed

commit 9cd209d
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:43:26 2020 -0400

    [API] Fix Travis again

commit a961386
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:38:09 2020 -0400

    [API] Restroring useless declare(strict_types=1)

commit 069b167
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:33:35 2020 -0400

    [API] Remove useless stuff

commit 601a5e6
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Aug 21 17:16:25 2020 -0400

    [API] Project Dicoms endpoint works with ObjectProvisioner

commit 32d997f
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Thu Aug 20 02:34:15 2020 -0400

    [API] Chenged to ProjectDicomsObjectProvisioner

commit efedeef
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Aug 4 16:37:26 2020 -0400

    [API] redeclare strict types and simplify projectdicomsrowprovisioner

commit 39b4a26
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Aug 4 16:08:55 2020 -0400

    [API] redeclare strict types and simplify projectdicomsrowprovisioner

commit 756f93e
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Aug 3 15:29:55 2020 -0400

    [API] Changed toJSON to jsonSerialize and resored strict_types declaration

commit 93f2c1d
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Aug 3 14:10:58 2020 -0400

    [API] Corrections to pass Travis checks

commit 108121d
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Wed Jul 1 14:41:50 2020 -0400

    [API] Added information on tarchive

commit 6376f72
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 30 15:19:59 2020 -0400

    [API] Fix other typos

commit 5ac0b5b
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 30 15:16:42 2020 -0400

    [API] Fix other typos

commit 3c7c1e6
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 30 12:41:15 2020 -0400

    [API] added endpoints/project/dicoms.class.inc that was left behind

commit a50d83c
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Jun 29 13:30:08 2020 -0400

    [API] In \project dicoms endpoints: Corrected travis errors

commit 97beb63
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Mon Jun 29 11:53:03 2020 -0400

    [API] In \project dicoms endpoints: Corrected travis errors

commit 26ef029
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Fri Jun 26 20:05:06 2020 -0400

    [API] New Project /dicoms endpoint

commit 9c51213
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 23 16:11:12 2020 -0400

    [API] Creation of endpoint /project/{project}/dicoms

commit 8bdad92
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 23 16:10:52 2020 -0400

    [API] Creation of endpoint /project/{project}/dicoms

commit 7465fe3
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Jun 23 16:08:40 2020 -0400

    [API] Creation of endpoint /project/{project}/dicoms

commit cf758cd
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 13:04:02 2020 -0400

    [API] Candidates are now filtered by allowed project ids

commit c3ac7fa
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 10:53:09 2020 -0400

    [API] Adding UserProjectMatch to candidates endpoint

commit 1954102
Author: Simon Pelletier <simonjpelletier@gmail.com>
Date:   Tue Sep 1 10:34:35 2020 -0400

    [API] Add getProjectID to candidatesrow model
  • Loading branch information
ridz1208 committed Jul 6, 2021
1 parent 987f455 commit 8a68dfa
Show file tree
Hide file tree
Showing 6 changed files with 500 additions and 0 deletions.
41 changes: 41 additions & 0 deletions modules/api/docs/LorisRESTAPI_v0.0.4-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,47 @@ will return a JSON object of the form:
}
```
#### 2.1.6 Single project dicoms tar files
GET /projects/$ProjectName/dicoms
will return a JSON object of the form:
```js
{
"Dicoms": [
{
"Candidate": "587630",
"PSCID": "DCC090",
"Entity_type": "Human",
"Visit": "V1",
"Visit_date": "2018-04-20",
"CenterID": "1",
"Site": "Data Coordinating Center",
"date_acquired": "2018-04-20",
"date_first_archived": "2019-05-23 13:46:39",
"date_last_archived": "2019-05-23 13:46:39",
"tarchiveid": "27",
"DicomArchiveID": "1.2.840.113745.101000.1022000.39911.6153.5242769",
"Archive": "2018/DCM_2018-04-20_ImagingUpload-13-42-zcoZR0.tar",
"Source": "/tmp/ImagingUpload-13-42-zcoZR0",
"FileName": "DCM_2018-04-20_ImagingUpload-13-42-zcoZR0.tar"
},
...
]
}

```
It is possible to provide a GET parameter named `since` where the value need to be a date or datetime.
```
ex: 2016-08-09 or 2016-08-09 10:00:00 or 2016-08-09T10:00:00-05:00
```
We recommend using a format that includes timezone. The `since` parameter should be
passed like the following example:
```
https://demo.loris.ca/api/v0.0.4-dev/projects/pumpernickel/dicoms?2016-08-09T10:00:00-05:00
```
### 2.2 Instrument Forms
```
Expand Down
169 changes: 169 additions & 0 deletions modules/api/php/endpoints/project/dicoms.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
/**
* This implements the Dicoms page class under Project
*
* PHP Version 7
*
* @category API
* @package Loris
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris
*/
namespace LORIS\api\Endpoints\Project;

use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;
use \LORIS\api\Endpoint;

/**
* A class for handling the /projects/$projectname/dicoms endpoint.
*
* @category API
* @package Loris
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris
*/
class Dicoms extends Endpoint implements \LORIS\Middleware\ETagCalculator
{
/**
* A cache of the results of the endpoint, so that
* it doesn't need to be recalculated for the ETag and handler
*/
private $_cache;

/**
* The requested project
*/
private $_project;

/**
* Permission checks
*
* @param \User $user The requesting user
*
* @return boolean true if access is permitted
*/
private function _hasAccess(\User $user)
{
return $user->hasPermission('dicom_archive_view_allsites');
}

/**
* Contructor
*
* @param \Project $project The requested project
*/
public function __construct(\Project $project)
{
$this->_project = $project;
}

/**
* Return which methods are supported by this endpoint.
*
* @return array supported HTTP methods
*/
protected function allowedMethods() : array
{
return ['GET'];
}

/**
* Versions of the LORIS API which are supported by this
* endpoint.
*
* @return array a list of supported API versions.
*/
protected function supportedVersions() : array
{
return ["v0.0.4-dev"];
}

/**
* Handles a request that starts with /projects/$projectname/candidates
*
* @param ServerRequestInterface $request The incoming PSR7 request
*
* @return ResponseInterface The outgoing PSR7 response
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$user = $request->getAttribute('user');
if ($user instanceof \LORIS\AnonymousUser) {
return new \LORIS\Http\Response\JSON\Unauthorized();
}

if (!$this->_hasAccess($user)) {
return new \LORIS\Http\Response\JSON\Forbidden();
}

$pathparts = $request->getAttribute('pathparts');
if (count($pathparts) !== 0) {
return new \LORIS\Http\Response\JSON\NotFound();
}

switch ($request->getMethod()) {
case 'GET':
return $this->_handleGET($request);

case 'OPTIONS':
return (new \LORIS\Http\Response())
->withHeader('Allow', $this->allowedMethods());
default:
return new \LORIS\Http\Response\JSON\MethodNotAllowed(
$this->allowedMethods()
);
}
}

/**
* Create an array representation of this endpoint's reponse body
*
* @param ServerRequestInterface $request The incoming PSR7 request
*
* @return ResponseInterface The outgoing PSR7 response
*/
private function _handleGET(ServerRequestInterface $request): ResponseInterface
{
if (isset($this->_cache)) {
return $this->_cache;
}

try {
$datestring = $request->getQueryParams()['since'] ?? '1970-01-01';
$since = new \DateTime($datestring);
} catch (\Exception $e) {
return new \LORIS\Http\Response\JSON\BadRequest(
$e->getMessage()
);
}

$provisioner = new \LORIS\api\Provisioners\ProjectDicomsObjectProvisioner(
$this->_project,
$since,
'\LORIS\api\Models\ProjectDicoms'
);

$dicoms = iterator_to_array($provisioner->getAllInstances());

$this->_cache = new \LORIS\Http\Response\JsonResponse(
['Dicoms' => $dicoms]
);

return $this->_cache;
}

/**
* Implements the ETagCalculator interface
*
* @param ServerRequestInterface $request The PSR7 incoming request.
*
* @return string etag summarizing value of this request.
*/
public function ETag(ServerRequestInterface $request) : string
{
return md5(json_encode($this->_handleGET($request)->getBody()));
}
}
3 changes: 3 additions & 0 deletions modules/api/php/endpoints/project/project.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ class Project extends Endpoint implements \LORIS\Middleware\ETagCalculator
case 'recordings':
$handler = new Recordings($this->_project);
break;
case 'dicoms':
$handler = new Dicoms($this->_project);
break;
default:
return new \LORIS\Http\Response\JSON\NotFound();
}
Expand Down
36 changes: 36 additions & 0 deletions modules/api/php/models/projectdicoms.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types=1);
/**
* PHP Version 7
*
* @category API
* @package Loris
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/

namespace LORIS\api\Models;

/**
* A ProjectDicoms contains values from a Dicom file of a project.
*
* @category API
* @package Loris
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
class ProjectDicoms implements \LORIS\Data\DataInstance
{
/**
* Implements \LORIS\Data\DataInstance interface for this object.
*
* @return array the object data.
*/
public function jsonSerialize() : array
{
$obj = get_object_vars($this);
$obj['FileName'] = basename($obj['Archive']);
return $obj;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php declare(strict_types=1);
/**
* This file implements a data provisioner to get all dicoms of a project
* created since a given date.
*
* PHP Version 7
*
* @category API
* @package Loris
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/

namespace LORIS\api\Provisioners;

use \LORIS\Data\Provisioners\DBObjectProvisioner;
/**
* This file implements a data provisioner to get all dicoms of a project
* created since a given date.
*
* PHP Version 7
*
* @category API
* @package Loris
* @author Simon Pelletier <simon.pelletier@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
class ProjectDicomsObjectProvisioner extends DBObjectProvisioner
{
/**
* Create a ObjectProvisioner
*
* @param \Project $project The project from which dicoms are requested
* @param \DateTime $since The date from which dicoms are requested
* @param string $classname The class name of the returned objects
*/
function __construct(
\Project $project,
\DateTime $since,
string $classname='LORIS\api\Models\ProjectDicoms'
) {
parent::__construct(
'
SELECT
s.CandID as Candidate,
c.PSCID as PSCID,
c.Entity_type as Entity_type,
s.Visit_label as Visit,
s.Date_visit as Visit_date,
s.CenterID as CenterID,
p.Name as Site,
t.DateAcquired as date_acquired,
t.DateFirstArchived as date_first_archived,
t.DateLastArchived as date_last_archived,
t.TarchiveID as tarchiveid,
t.DicomArchiveID as DicomArchiveID,
t.ArchiveLocation as Archive,
t.SourceLocation as Source
FROM
tarchive t
LEFT JOIN session s
ON (t.SessionID = s.ID)
LEFT JOIN candidate c
ON (s.CandID = c.CandID)
LEFT JOIN psc p
ON (s.CenterID = p.CenterID)
LEFT JOIN Project project
ON (c.RegistrationProjectID = project.ProjectID)
WHERE
c.Active = \'Y\' AND
s.Active = \'Y\' AND
project.Name = :v_projectname AND
t.DateLastArchived > :v_time
ORDER BY t.DateLastArchived ASC; ',
[
'v_projectname' => $project->getName(),
'v_time' => $since->getTimestamp(),
],
$classname
);
}
}

Loading

0 comments on commit 8a68dfa

Please sign in to comment.