Skip to content

Commit

Permalink
[API] Added features for dicoms : PatientName and images: isPhantom (a…
Browse files Browse the repository at this point in the history
…ces#6899)

Patientname is added to dicoms endpoint view and IsPhantom is added to images endpoint view.
  • Loading branch information
spell00 authored and AlexandraLivadas committed Jun 29, 2021
1 parent 9ec7bed commit b34fdef
Show file tree
Hide file tree
Showing 11 changed files with 239 additions and 13 deletions.
3 changes: 3 additions & 0 deletions modules/api/docs/LorisRESTAPI_v0.0.4-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ the form:
"OutputType" : "native",
"Filename" : "abc.mnc",
"AcquisitionType" : "t1w/t2w/etc",
"IsPhantom" : "true|false",
}, /* More files */]
}
```
Expand Down Expand Up @@ -810,6 +811,7 @@ object of the form:
[
{
"Tarname" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-abc123.tar",
"Patientname" : "DCM123_123456_V1",
"SeriesInfo" :
[{
"SeriesDescription" : "MPRAGE_ipat2",
Expand All @@ -834,6 +836,7 @@ object of the form:
},
{
"Tarname" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-def456.tar",
"Patientname" : "DCM456_654321_V1",
"SeriesInfo" :
[{
"SeriesDescription" : "MPRAGE_ipat2",
Expand Down
18 changes: 13 additions & 5 deletions modules/api/php/endpoints/candidate/visit/dicoms.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,19 @@ class Dicoms extends Endpoint implements \LORIS\Middleware\ETagCalculator
$request->getAttribute('user')
);

$view = (new \LORIS\api\Views\Visit\Dicoms(
$this->_visit,
...$dicomtars
))->toArray();

$version = $request->getAttribute('LORIS-API-Version');
switch($version) {
case "v0.0.3":
$view = (new \LORIS\api\Views\Visit\Dicoms(
$this->_visit,
...$dicomtars
))->toArray();
default:
$view = (new \LORIS\api\Views\Visit\Dicoms_0_0_4_Dev(
$this->_visit,
...$dicomtars
))->toArray();
}
$this->_cache = new \LORIS\Http\Response\JsonResponse($view);

return $this->_cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ class Channels extends Endpoint implements \LORIS\Middleware\ETagCalculator
{
return md5(json_encode($this->_handleGET($request)->getBody()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ class Metadata extends Endpoint implements \LORIS\Middleware\ETagCalculator
{
return md5(json_encode($this->_handleGET($request)->getBody()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,4 @@ class Recording extends Endpoint implements \LORIS\Middleware\ETagCalculator

return md5(json_encode($signature));
}
}
}
18 changes: 14 additions & 4 deletions modules/api/php/endpoints/candidate/visit/images.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,20 @@ class Images extends Endpoint implements \LORIS\Middleware\ETagCalculator
$request->getAttribute('user')
);

$view = (new \LORIS\api\Views\Visit\Images(
$this->_visit,
...$images
))->toArray();
$version = $request->getAttribute('LORIS-API-Version');
switch($version) {
case 'v0.0.3':
$view = (new \LORIS\api\Views\Visit\Images(
$this->_visit,
...$images
))->toArray();

default:
$view = (new \LORIS\api\Views\Visit\Images_0_0_4_Dev(
$this->_visit,
...$images
))->toArray();
}

$this->_cache = new \LORIS\Http\Response\JsonResponse($view);

Expand Down
2 changes: 1 addition & 1 deletion modules/api/php/endpoints/project/recordings.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ class Recordings extends Endpoint implements \LORIS\Middleware\ETagCalculator
{
return md5(json_encode($this->_handleGET($request)->getBody()));
}
}
}
112 changes: 112 additions & 0 deletions modules/api/php/views/visit/dicoms_0_0_4_dev.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php declare(strict_types=1);
/**
* PHP Version 7
*
* @category ApiViews
* @package Loris
* @author Xavier Lecours Boucher <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/

namespace LORIS\api\Views\Visit;

use \LORIS\Data\Models\DicomTarDTO;
use \LORIS\Data\Models\DicomSeriesDTO;
/**
* Creates a representation of a visit dicoms following the api response
* specifications.
*
* @category ApiViews
* @package Loris
* @author Xavier Lecours Boucher <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/

class Dicoms_0_0_4_Dev
{
private $_timepoint;
private $_dicoms;

/**
* Constructor which sets the instance variables based on the provided timepoint
*
* @param \Timepoint $timepoint The timepoint to represent
* @param DicomTarDTO ...$dicoms An array of dicomtars
*/
public function __construct(\Timepoint $timepoint, DicomTarDTO ...$dicoms)
{
$this->_timepoint = $timepoint;
$this->_dicoms = $dicoms;
}

/**
* This is a mapper function that formats a dicomtar following the
* API specifications.
*
* @param DicomTarDTO $dicom The dicomtar to format.
*
* @return array
*/
private static function _formatDicomTars(DicomTarDTO $dicom): array
{
return [
'Tarname' => $dicom->getTarname(),
'Patientname' => $dicom->getPatientname(),
'SeriesInfo' => array_map(
[
'self',
'_formatSeries'
],
$dicom->getSeries()
),
];
}

/**
* This is a mapper function that formats a dicom series following the
* API specifications.
*
* @param DicomSeriesDTO $series The series to format.
*
* @return array
*/
private static function _formatSeries(DicomSeriesDTO $series): array
{
return [
'SeriesDescription' => $series->getSeriesDescription(),
'SeriesNumber' => $series->getSeriesNumber(),
'EchoTime' => $series->getEchotime(),
'RepetitionTime' => $series->getRepetitiontime(),
'InversionTime' => $series->getInversiontime(),
'SliceThickness' => $series->getSlicethickness(),
'Modality' => $series->getModality(),
'SeriesUID' => $series->getSeriesuid(),
];
}

/**
* Creates an serializable array of this object's data
*
* @return array
*/
public function toArray(): array
{
$meta = [
'CandID' => $this->_timepoint->getCandID(),
'Visit' => $this->_timepoint->getVisitLabel(),
];

$dicomtars = array_map(
'self::_formatDicomTars',
$this->_dicoms
);

return [
'Meta' => $meta,
'DicomTars' => $dicomtars,
];
}
}

72 changes: 72 additions & 0 deletions modules/api/php/views/visit/images_0_0_4_dev.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php declare(strict_types=1);
/**
* PHP Version 7
*
* @category ApiViews
* @package Loris
* @author Xavier Lecours Boucher <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/

namespace LORIS\api\Views\Visit;

use \LORIS\Data\Models\ImageDTO;
/**
* Creates a representation of a visit images following the api response
* specifications.
*
* @category ApiViews
* @package Loris
* @author Xavier Lecours Boucher <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/

class Images_0_0_4_Dev
{
private $_timepoint;
private $_images;

/**
* Constructor which sets the instance variables based on the provided timepoint
*
* @param \Timepoint $timepoint The timepoint to represent
* @param ImageDTO ...$images An array of images
*/
public function __construct(\Timepoint $timepoint, ImageDTO ...$images)
{
$this->_timepoint = $timepoint;
$this->_images = $images;
}

/**
* Creates an serializable array of this object's data
*
* @return array
*/
public function toArray(): array
{
$meta = [
'CandID' => $this->_timepoint->getCandID(),
'Visit' => $this->_timepoint->getVisitLabel(),
];

$imagesdata = array_map(
function ($image) {
return [
'OutputType' => $image->getOutputType(),
'Filename' => $image->getFilename(),
'AcquisitionType' => $image->getAcquisitionprotocol(),
'IsPhantom' => $image->isPhantom(),
];
},
$this->_images
);

return [
'Meta' => $meta,
'Files' => $imagesdata,
];
}
}
16 changes: 16 additions & 0 deletions raisinbread/test/api/LorisApiDicomsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public function testGetCandidatesCandidVisitDicoms(): void
),
'array'
);
$this->assertSame(
gettype(
$dicomArray['DicomTars']['0']['Tarname']
),
'string'
);
$this->assertSame(
gettype(
$dicomArray['DicomTars']['0']['Patientname']
),
'string'
);
$this->assertSame(
gettype(
$dicomArray['DicomTars']['0']['SeriesInfo']['0']
Expand Down Expand Up @@ -150,6 +162,10 @@ public function testGetCandidatesCandidVisitDicoms(): void
'Tarname',
$dicomArray['DicomTars']['0']
);
$this->assertArrayHasKey(
'Patientname',
$dicomArray['DicomTars']['0']
);

$this->assertArrayHasKey(
'SeriesInfo',
Expand Down
5 changes: 5 additions & 0 deletions raisinbread/test/api/LorisApiImagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function testGetCandidatesCandidVisitImages(): void
gettype($imagesArray['Files']['0']['AcquisitionType']),
'string'
);
$this->assertSame(
gettype($imagesArray['Files']['0']['IsPhantom']),
'boolean'
);

$this->assertArrayHasKey('Meta', $imagesArray);
$this->assertArrayHasKey('CandID', $imagesArray['Meta']);
Expand All @@ -75,6 +79,7 @@ public function testGetCandidatesCandidVisitImages(): void
$this->assertArrayHasKey('OutputType', $imagesArray['Files']['0']);
$this->assertArrayHasKey('Filename', $imagesArray['Files']['0']);
$this->assertArrayHasKey('AcquisitionType', $imagesArray['Files']['0']);
$this->assertArrayHasKey('IsPhantom', $imagesArray['Files']['0']);
}

/**
Expand Down

0 comments on commit b34fdef

Please sign in to comment.