Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[api] Modify YAML schema so that Swagger Codegen PHP Client works #7857

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions modules/api/docs/LorisRESTAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ of this reference a CandidateObject. A CandidateObject is a JSON object of the f
"Site" : Site,
"EDC" : "YYYY-MM-DD",
"DoB" : "YYYY-MM-DD",
"Sex" : "Male|Female"
"Sex" : "Male|Female|Other"
}
```

Expand Down Expand Up @@ -326,7 +326,7 @@ The body of the POST request should be a candidate key with a JSON object of the
"PSCID" : PSCID,
"EDC" : "YYYY-MM-DD",
"DoB" : "YYYY-MM-DD",
"Sex" : "Male|Female",
"Sex" : "Male|Female|Other",
"Site" : SiteName,
}
}
Expand All @@ -342,7 +342,7 @@ A response code of 201 Created will be returned on success, 409 Conflict if
the PSCID already exists, 403 Forbidden when the user is creating a candidate at
a site other than the list of sitenames the user is affiliated with, and a 400
Bad Request if any data provided is invalid (PSCID format, date format, sex
something other than Male|Female, invalid project name, invalid sitename, etc).
something other than Male|Female|Other, invalid project name, invalid sitename, etc).
A successful POST request will return a CandidateObject for the newly created
candidate.

Expand Down
8 changes: 4 additions & 4 deletions modules/api/docs/LorisRESTAPI_v0.0.4-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ of this reference a CandidateObject. A CandidateObject is a JSON object of the f
"Site" : Site,
"EDC" : "YYYY-MM-DD",
"DoB" : "YYYY-MM-DD",
"Sex" : "Male|Female"
"Sex" : "Male|Female|Other"
}
```

Expand Down Expand Up @@ -326,7 +326,7 @@ The body of the POST request should be a candidate key with a JSON object of the
"PSCID" : PSCID,
"EDC" : "YYYY-MM-DD",
"DoB" : "YYYY-MM-DD",
"Sex" : "Male|Female",
"Sex" : "Male|Female|Other",
"Site" : SiteName,
}
}
Expand All @@ -342,7 +342,7 @@ A response code of 201 Created will be returned on success, 409 Conflict if
the PSCID already exists, 403 Forbidden when the user is creating a candidate at
a site other than the list of sitenames the user is affiliated with, and a 400
Bad Request if any data provided is invalid (PSCID format, date format, sex
something other than Male|Female, invalid project name, invalid sitename, etc).
something other than Male|Female|Other, invalid project name, invalid sitename, etc).
A successful POST request will return a CandidateObject for the newly created
candidate.

Expand Down Expand Up @@ -504,7 +504,7 @@ The format returned by a GET request is a JSON document of the form:
"Candidate" : $CandID,
"DDE" : boolean
},
"$InstrumentName" : {
"Data" : {
"FieldName1" : "Value1",
"FieldName2" : "Value2",
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,27 @@ class Instrument extends Endpoint implements \LORIS\Middleware\ETagCalculator
/**
* Handles a GET request
*
* @param ServerRequestInterface $request The incoming PSR7 request
*
* @return ResponseInterface The outgoing PSR7 response
*/
private function _handleGET() : ResponseInterface
private function _handleGET(ServerRequestInterface $request) : ResponseInterface
{
$body = (new \LORIS\api\Views\Visit\Instrument(
$this->_visit,
$this->_instrument
))->toArray();

$version = $request->getAttribute('LORIS-API-Version');
switch ($version) {
case 'v0.0.3':
$body = (new \LORIS\api\Views\Visit\Instrument(
$this->_visit,
$this->_instrument
))->toArray();
break;
default:
$body = (new \LORIS\api\Views\Visit\Instrument_0_0_4_Dev(
$this->_visit,
$this->_instrument
))->toArray();
}

return new \LORIS\Http\Response\JsonResponse(
$body
Expand Down Expand Up @@ -177,17 +190,21 @@ class Instrument extends Endpoint implements \LORIS\Middleware\ETagCalculator
}

try {
$instrumentname = $this->_instrument->testName;
$this->_instrument->clearInstrument();
$this->_instrument->_saveValues($data[$instrumentname]);
$version = $request->getAttribute('LORIS-API-Version');
if ($version == 'v0.0.3') {
$instrumentname = $this->_instrument->testName;
$this->_instrument->_saveValues($data[$instrumentname]);
} else {
$this->_instrument->_saveValues($data['Data']);
}
$this->_instrument->score();
$this->_instrument->updateRequiredElementsCompletedFlag();
} catch (\Throwable $e) {
error_log($e->getMessage());
return new \LORIS\Http\Response\JSON\InternalServerError();
}
return (new \LORIS\Http\Response())
->withStatus(204);
return (new \LORIS\Http\Response\JSON\NoContent());
}

/**
Expand Down Expand Up @@ -220,16 +237,20 @@ class Instrument extends Endpoint implements \LORIS\Middleware\ETagCalculator
}

try {
$instrumentname = $this->_instrument->testName;
$this->_instrument->_saveValues($data[$instrumentname]);
$version = $request->getAttribute('LORIS-API-Version');
if ($version == 'v0.0.3') {
$instrumentname = $this->_instrument->testName;
$this->_instrument->_saveValues($data[$instrumentname]);
} else {
$this->_instrument->_saveValues($data['Data']);
}
$this->_instrument->score();
$this->_instrument->updateRequiredElementsCompletedFlag();
} catch (\Throwable $e) {
error_log($e->getMessage());
return new \LORIS\Http\Response\JSON\InternalServerError();
}
return (new \LORIS\Http\Response())
->withStatus(204);
return (new \LORIS\Http\Response\JSON\NoContent());
}

/**
Expand Down
72 changes: 72 additions & 0 deletions modules/api/php/views/visit/instrument_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 <xavier.lecours@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris/
*/

namespace LORIS\api\Views\Visit;

/**
* Creates a representation of a visit intrument following the api response
* specifications.
*
* @category ApiViews
* @package Loris
* @author Xavier Lecours Boucher <xavier.lecours@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris/
*/

class Instrument_0_0_4_Dev
{
private $_timepoint;
private $_instrument;

/**
* Constructor which sets the instance variables based on the provided timepoint
* and instrument.
*
* @param \Timepoint $timepoint The timepoint to represent
* @param \NDB_BVL_Instrument $instrument The instrument.
*/
public function __construct(
\Timepoint $timepoint,
\NDB_BVL_Instrument $instrument
) {
$this->_timepoint = $timepoint;
$this->_instrument = $instrument;
}

/**
* Creates an serializable array of this object's data
*
* @return array
*/
public function toArray(): array
{
$instrumentname = $this->_instrument->testName;
$instrumentdata = $this->_instrument->getInstanceData();

$isDDE = strpos($instrumentdata['CommentID'], 'DDE_') === 0;

$meta = [
'Candidate' => $this->_timepoint->getCandID(),
'Visit' => $this->_timepoint->getVisitLabel(),
'DDE' => $isDDE,
'Instrument' => $instrumentname,
];

$instrument = ['Data' => $instrumentdata];

return array_merge(
['Meta' => $meta],
$instrument
);
}
}

46 changes: 11 additions & 35 deletions modules/api/static/schema-v0.0.4-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ paths:
- Images
summary: Get the qc values of an image
parameters:
- name: candid
- name: id
zaliqarosli marked this conversation as resolved.
Show resolved Hide resolved
in: path
description: The candidate identifier. Either PSCID or CandID.
required: true
Expand Down Expand Up @@ -1288,7 +1288,7 @@ paths:
- Dicoms
summary: List all dicoms for that timepoint
parameters:
- name: candid
- name: id
in: path
description: ID of the candidate. Either PSCID or CandID
required: true
Expand Down Expand Up @@ -1852,7 +1852,9 @@ components:
type: object
properties:
Candidates:
$ref: '#/components/schemas/Candidate'
type: array
items:
$ref: '#/components/schemas/Candidate'
Candidate:
type: object
properties:
Expand All @@ -1873,6 +1875,7 @@ components:
enum:
- Female
- Male
- Other
NewCandidate:
type: object
properties:
Expand Down Expand Up @@ -1944,8 +1947,10 @@ components:
properties:
Meta:
$ref: '#/components/schemas/InstrumentMeta'
$InstrumentShortName:
$ref: '#/components/schemas/InstrumentData'
Data:
type: object
additionalProperties:
type: string
InstrumentMeta:
type: object
properties:
Expand All @@ -1957,10 +1962,6 @@ components:
type: string
DDE:
type: boolean
InstrumentData:
type: object
additionalProperties:
type: string
InstrumentFlags:
type: object
properties:
Expand Down Expand Up @@ -2249,6 +2250,7 @@ components:
enum:
- Female
- Male
- Other
InstrumentFlags_Flags:
type: object
properties:
Expand Down Expand Up @@ -2471,19 +2473,6 @@ components:
type: string
EventFilePath:
type: string

VisitStage:
type: object
properties:
Date:
type: string
Status:
type: string
enum:
- Pass
- Failure
- Withdrawal
- In Progress
VisitPatchFields:
type: object
allOf:
Expand All @@ -2492,19 +2481,6 @@ components:
properties:
Stages:
$ref: '#/components/schemas/InstrumentVisit'

InstrumentVisit:
type: object
properties:
Visit:
$ref: '#/components/schemas/VisitStage'

Error:
type: object
properties:
error:
type: string

securitySchemes:
ApiKeyAuth:
type: apiKey
Expand Down
14 changes: 8 additions & 6 deletions modules/api/static/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,9 @@ components:
type: object
properties:
Candidates:
$ref: '#/components/schemas/Candidate'
type: array
xlecours marked this conversation as resolved.
Show resolved Hide resolved
items:
$ref: '#/components/schemas/Candidate'
Candidate:
type: object
properties:
Expand All @@ -1844,6 +1846,7 @@ components:
enum:
- Female
- Male
- Other
NewCandidate:
type: object
properties:
Expand Down Expand Up @@ -1916,7 +1919,9 @@ components:
Meta:
$ref: '#/components/schemas/InstrumentMeta'
$InstrumentShortName:
$ref: '#/components/schemas/InstrumentData'
type: object
additionalProperties:
type: string
InstrumentMeta:
type: object
properties:
Expand All @@ -1928,10 +1933,6 @@ components:
type: string
DDE:
type: boolean
InstrumentData:
type: object
additionalProperties:
type: string
InstrumentFlags:
type: object
properties:
Expand Down Expand Up @@ -2220,6 +2221,7 @@ components:
enum:
- Female
- Male
- Other
InstrumentFlags_Flags:
type: object
properties:
Expand Down
Loading