Skip to content

Commit

Permalink
revert breaking api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
maximemulder committed Sep 17, 2024
1 parent 9d1dd5a commit 65869da
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 192 deletions.
42 changes: 20 additions & 22 deletions modules/api/docs/LorisRESTAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,53 +798,51 @@ GET /candidates/$CandID/$VisitLabel/dicoms
```
A GET request to `/candidates/$CandID/$VisitLabel/dicoms` will return a JSON object of
all the DICOM archives which have been acquired for that visit. It will return an
object of the form:
all the DICOM archives (A.K.A. one DICOM archive per `StudyInstanceUID`) which have been
acquired for that visit. It will return an object of the form:
```js
{
"Meta" : {
"CandID" : $CandID,
"VisitLabel" : $VisitLabel,
"Visit" : $VisitLabel,
},
"DicomArchives" : [
"DicomTars" : [
{
"ArchiveName" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-abc123.tar",
"PatientName" : "DCM123_123456_V1",
"Tarname" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-abc123.tar",
"SeriesInfo" : [
{
"SeriesDescription" : "MPRAGE_ipat2",
"SeriesNumber" : 2,
"EchoTime" : 2.98,
"RepetitionTime" : 2300,
"InversionTime" : 900,
"SliceThickness" : 1,
"EchoTime" : "2.98",
"RepetitionTime" : "2300",
"InversionTime" : "900",
"SliceThickness" : "1",
"Modality" : "MR",
"SeriesUID" : "1.2.3.4.1107",
},
{
"SeriesDescription" : "BOLD Resting State",
"SeriesNumber" : 5,
"EchoTime" : 30,
"RepetitionTime" : 2100,
"EchoTime" : "30",
"RepetitionTime" : "2100",
"InversionTime" : NULL,
"SliceThickness" : 3.5,
"SliceThickness" : "3.5",
"Modality" : "MR",
"SeriesUID" : "3.4.5.6.1507",
}
]
},
{
"ArchiveName" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-def456.tar",
"PatientName" : "DCM456_654321_V1",
"Tarname" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-def456.tar",
"SeriesInfo" : [
{
"SeriesDescription" : "MPRAGE_ipat2",
"SeriesNumber" : 2,
"EchoTime" : 2.98,
"RepetitionTime" : 2300,
"InversionTime" : 900,
"SliceThickness" : 1,
"EchoTime" : "2.98",
"RepetitionTime" : "2300",
"InversionTime" : "900",
"SliceThickness" : "1",
"Modality" : "MR",
"SeriesUID" : "1.7.8.9.1296",
}
Expand Down Expand Up @@ -898,7 +896,7 @@ scanning session, and as retrieved from `/candidates/$CandID/$VisitLabel/dicoms`
To get a list of the processes and their status for a given DICOM study previously uploaded use the following:
```
GET /candidates/$CandID/$VisitLabel/dicoms/$Tarname/processes
GET /candidates/$CandID/$VisitLabel/dicoms/$TarName/processes
```
The response contains all `mri_upload` attempts with the specified `$tarname`. And for
Expand Down Expand Up @@ -933,7 +931,7 @@ To start an MRI upload process on a previously uploaded DICOM study, a POST requ
containing the `MriUploadID` attribute in the request body should be sent.
```
POST /candidates/$CandID/$VisitLabel/dicoms/$Tarname/processes
POST /candidates/$CandID/$VisitLabel/dicoms/$TarName/processes
```
The request body must contain:
Expand All @@ -949,7 +947,7 @@ Expected response: 202 Accepted with `Location` header pointing to the new proce
To obtain a specific process state, use the following:
```
GET /candidates/$CandID/$VisitLabel/dicoms/$Tarname/processes/$processid
GET /candidates/$CandID/$VisitLabel/dicoms/$TarName/processes/$ProcessID
```
Response shape:
Expand Down
44 changes: 22 additions & 22 deletions modules/api/docs/LorisRESTAPI_v0.0.4-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -834,53 +834,53 @@ GET /candidates/$CandID/$VisitLabel/dicoms
```
A GET request to `/candidates/$CandID/$VisitLabel/dicoms` will return a JSON object of
all the DICOM archives (A.K.A. one DICOM archive per `StudyInstanceUID`) which have been acquired for that visit. It will return an
object of the form:
all the DICOM archives (A.K.A. one DICOM archive per `StudyInstanceUID`) which have been
acquired for that visit. It will return an object of the form:
```js
{
"Meta" : {
"CandID" : $CandID,
"VisitLabel" : $VisitLabel,
"Visit" : $VisitLabel,
},
"DicomArchives" : [
"DicomTars" : [
{
"ArchiveName" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-abc123.tar",
"PatientName" : "DCM123_123456_V1",
"Tarname" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-abc123.tar",
"Patientname" : "DCM123_123456_V1",
"SeriesInfo" : [
{
"SeriesDescription" : "MPRAGE_ipat2",
"SeriesNumber" : 2,
"EchoTime" : 2.98,
"RepetitionTime" : 2300,
"InversionTime" : 900,
"SliceThickness" : 1,
"EchoTime" : "2.98",
"RepetitionTime" : "2300",
"InversionTime" : "900",
"SliceThickness" : "1",
"Modality" : "MR",
"SeriesUID" : "1.2.3.4.1107",
},
{
"SeriesDescription" : "BOLD Resting State",
"SeriesNumber" : 5,
"EchoTime" : 30,
"RepetitionTime" : 2100,
"EchoTime" : "30",
"RepetitionTime" : "2100",
"InversionTime" : NULL,
"SliceThickness" : 3.5,
"SliceThickness" : "3.5",
"Modality" : "MR",
"SeriesUID" : "3.4.5.6.1507",
}
]
},
{
"ArchiveName" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-def456.tar",
"PatientName" : "DCM456_654321_V1",
"Tarname" : "DCM_yyyy-mm-dd_ImagingUpload-hh-mm-def456.tar",
"Patientname" : "DCM456_654321_V1",
"SeriesInfo" : [
{
"SeriesDescription" : "MPRAGE_ipat2",
"SeriesNumber" : 2,
"EchoTime" : 2.98,
"RepetitionTime" : 2300,
"InversionTime" : 900,
"SliceThickness" : 1,
"EchoTime" : "2.98",
"RepetitionTime" : "2300",
"InversionTime" : "900",
"SliceThickness" : "1",
"Modality" : "MR",
"SeriesUID" : "1.7.8.9.1296",
}
Expand Down Expand Up @@ -934,7 +934,7 @@ scanning session, and as retrieved from `/candidates/$CandID/$VisitLabel/dicoms`
To get a list of the processes and their status for a given DICOM study previously uploaded use the following:
```
GET /candidates/$CandID/$VisitLabel/dicoms/$Tarname/processes
GET /candidates/$CandID/$VisitLabel/dicoms/$TarName/processes
```
The response contains all `mri_upload` attempts with the specified `$tarname`. And for
Expand Down Expand Up @@ -969,7 +969,7 @@ To start an MRI upload process on a previously uploaded DICOM study, a POST requ
containing the `MriUploadID` attribute in the request body should be sent.
```
POST /candidates/$CandID/$VisitLabel/dicoms/$Tarname/processes
POST /candidates/$CandID/$VisitLabel/dicoms/$TarName/processes
```
The request body must contain:
Expand All @@ -985,7 +985,7 @@ Expected response: 202 Accepted with `Location` header pointing to the new proce
To obtain a specific process state, use the following:
```
GET /candidates/$CandID/$VisitLabel/dicoms/$Tarname/processes/$processid
GET /candidates/$CandID/$VisitLabel/dicoms/$TarName/processes/$ProcessID
```
Response shape:
Expand Down
19 changes: 14 additions & 5 deletions modules/api/php/endpoints/candidate/visit/dicoms.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,20 @@ 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();
break;
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
24 changes: 13 additions & 11 deletions modules/api/php/views/visit/dicoms.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class Dicoms
/**
* Constructor which sets the instance variables based on the provided timepoint
*
* @param \Timepoint $timepoint The timepoint to represent
* @param array<int, DicomTarDTO> $dicoms An array of dicomtars
* @param \Timepoint $timepoint The timepoint to represent
* @param DicomTarDTO ...$dicoms An array of dicomtars
*/
public function __construct(\Timepoint $timepoint, array $dicoms)
public function __construct(\Timepoint $timepoint, DicomTarDTO ...$dicoms)
{
$this->_timepoint = $timepoint;
$this->_dicoms = $dicoms;
Expand All @@ -52,10 +52,12 @@ class Dicoms
private static function _formatDicomTars(DicomTarDTO $dicom): array
{
return [
'ArchiveName' => $dicom->getTarname(),
'PatientName' => $dicom->getPatientname(),
'SeriesInfo' => array_map(
[self::class, '_formatSeries'],
'Tarname' => $dicom->getTarname(),
'SeriesInfo' => array_map(
[
self::class,
'_formatSeries'
],
$dicom->getSeries()
),
];
Expand Down Expand Up @@ -91,8 +93,8 @@ class Dicoms
public function toArray(): array
{
$meta = [
'CandID' => $this->_timepoint->getCandID(),
'VisitLabel' => $this->_timepoint->getVisitLabel(),
'CandID' => $this->_timepoint->getCandID(),
'Visit' => $this->_timepoint->getVisitLabel(),
];

$dicomtars = array_map(
Expand All @@ -101,8 +103,8 @@ class Dicoms
);

return [
'Meta' => $meta,
'DicomArchives' => $dicomtars,
'Meta' => $meta,
'DicomTars' => $dicomtars,
];
}
}
Expand Down
111 changes: 111 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,111 @@
<?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::class,
'_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::class, '_formatDicomTars'],
$this->_dicoms
);

return [
'Meta' => $meta,
'DicomTars' => $dicomtars,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class MriUploadServerProcess extends AbstractServerProcess
$config =& \NDB_Config::singleton();
if (is_null($config)) {
throw new \RuntimeException(
"Cannot construct MriUploadTask: unable to instantiate
"Cannot construct MriUploadTask: unable to instantiate
configuration object"
);
}
Expand Down
Loading

0 comments on commit 65869da

Please sign in to comment.