Skip to content

Commit

Permalink
Merge branch 'Gaelo2' into GaelO2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
salimkanoun committed Jun 6, 2023
2 parents 92bbc19 + 4e0cc21 commit c674f03
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
6 changes: 5 additions & 1 deletion GaelO2/app/GaelO/Adapters/HttpClientAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function requestStreamResponseToFile(string $method, string $uri, $ressou
return new Psr7ResponseAdapter($response);
}

public function rowRequest(string $method, string $uri, $body, ?array $headers, $ressourceDestination = null): Psr7ResponseInterface
public function rowRequest(string $method, string $uri, $body, ?array $headers, $ressourceDestination = null, $httpErrors = true): Psr7ResponseInterface
{
$options = [];

Expand All @@ -147,6 +147,10 @@ public function rowRequest(string $method, string $uri, $body, ?array $headers,
$options['sink'] = $ressourceDestination;
}

if(!$httpErrors){
$options['http_errors'] = false;
}

$response = $this->client->request($method, $this->address . $uri, $options);
return new Psr7ResponseAdapter($response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function setAuthorizationToken(string $authorizationToken): void;

public function setBasicAuthentication(string $login, string $password): void;

public function rowRequest(string $method, string $uri, $body, ?array $headers): Psr7ResponseInterface;
public function rowRequest(string $method, string $uri, $body, ?array $headers, $ressourceDestination = null, $httpErrors = true): Psr7ResponseInterface;

/**
* Return array of PSR7 response adapter of multiple request, used to sent multiple files to an endpoint
Expand Down
2 changes: 1 addition & 1 deletion GaelO2/app/GaelO/Services/TusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(HttpClientInterface $httpClientInterface, FrameworkI

public function getFile(string $tusFileId) : string {

$downloadedFileName = tempnam(sys_get_temp_dir(), 'TusDicom');
$downloadedFileName = tempnam(sys_get_temp_dir(), 'TusDicom_');

$resource = fopen( $downloadedFileName, 'r+');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public function execute(CreateFileToFormFromTusRequest $createFileToFormFromTusR

$this->checkAuthorization($local, $validated, $reviewId, $visitId, $currentUserId, $studyName);

//Set Time Limit at 30min as operation could be really long
set_time_limit(1800);

$file = null;

//Several file, expected ziped dicom upload, unzip and merge in a single zipe
Expand Down Expand Up @@ -110,12 +113,14 @@ public function execute(CreateFileToFormFromTusRequest $createFileToFormFromTusR

$this->orthancService->setOrthancServer(false);
$orthancStudyImport = $this->orthancService->importDicomFolder($unzipedPath);
if ($expectedNumberOfInstances !== $orthancStudyImport->getNumberOfInstances()) {
$importedNumberOfInstances = $orthancStudyImport->getNumberOfInstances();
$importedOrthancStudyID = $orthancStudyImport->getStudyOrthancId();

if ($expectedNumberOfInstances !== $importedNumberOfInstances) {
$this->orthancService->deleteFromOrthanc("studies", $importedOrthancStudyID);
throw new GaelOValidateDicomException("Imported DICOM not matching announced number of Instances");
}

$importedOrthancStudyID = $orthancStudyImport->getStudyOrthancId();

$tempFileLocation = tempnam(ini_get('upload_tmp_dir'), 'TMPZIP_');
$this->orthancService->getZipStreamToFile([$importedOrthancStudyID], $tempFileLocation);
$file = $tempFileLocation;
Expand All @@ -124,8 +129,7 @@ public function execute(CreateFileToFormFromTusRequest $createFileToFormFromTusR
if (sizeof($tusIds) === 1) {
$file = $this->tusService->getFile($tusIds[0]);
$this->tusService->deleteFile($tusIds[0]);
}
else throw new GaelOBadRequestException("A single TUS Id is expected for non-DICOM upload");
} else throw new GaelOBadRequestException("A single TUS Id is expected for non-DICOM upload");
}

//Send file to associated file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function execute(ReverseProxyTusRequest $reverseProxyTusRequest, ReverseP

//Make query of TUS
$this->httpClientInterface->setUrl($this->frameworkInterface::getConfig(SettingsConstants::TUS_URL));
$response = $this->httpClientInterface->rowRequest($reverseProxyTusRequest->method, $reverseProxyTusRequest->url, $reverseProxyTusRequest->body, $headers);
$response = $this->httpClientInterface->rowRequest($reverseProxyTusRequest->method, $reverseProxyTusRequest->url, $reverseProxyTusRequest->body, $headers, null, false);

//Output response
$reverseProxyTusResponse->status = $response->getStatusCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,16 @@ public function execute(ValidateDicomUploadRequest $validateDicomUploadRequest,
$currentUserId = $validateDicomUploadRequest->currentUserId;
$visitId = $validateDicomUploadRequest->visitId;

$expectedNumberOfInstances = $validateDicomUploadRequest->numberOfInstances;
$originalOrthancId = $validateDicomUploadRequest->originalOrthancId;

$this->checkAuthorization($currentUserId, $visitId, $studyName, $visitContext);

//Make Visit as being upload processing
$this->visitService->updateUploadStatus(UploadStatusEnum::PROCESSING->value);

//Set Time Limit at 30min as operation could be really long
set_time_limit(1800);
//Create Temporary folder to work
$unzipedPath = Util::getUploadTemporaryFolder();

Expand All @@ -98,14 +103,14 @@ public function execute(ValidateDicomUploadRequest $validateDicomUploadRequest,
}
$this->orthancService->setOrthancServer(false);

$expectedNumberOfInstances = $validateDicomUploadRequest->numberOfInstances;

$orthancStudyImport = $this->orthancService->importDicomFolder($unzipedPath);
if ($expectedNumberOfInstances !== $orthancStudyImport->getNumberOfInstances()) {
throw new GaelOValidateDicomException("Imported DICOM not matching announced number of Instances");
}
$importedNumberOfInstances = $orthancStudyImport->getNumberOfInstances();
$importedOrthancStudyID = $orthancStudyImport->getStudyOrthancId();

if ($expectedNumberOfInstances !== $importedNumberOfInstances) {
$this->orthancService->deleteFromOrthanc("studies", $importedOrthancStudyID);
throw new GaelOValidateDicomException("Imported DICOM not matching announced number of Instances");
}

//Anonymize and store new anonymized study Orthanc ID
$anonymizedOrthancStudyID = $this->orthancService->anonymize(
Expand All @@ -130,7 +135,7 @@ public function execute(ValidateDicomUploadRequest $validateDicomUploadRequest,
$this->orthancService->setOrthancServer(true);

$statistics = $this->orthancService->getOrthancRessourcesStatistics('studies', $anonymizedOrthancStudyID);
if ($statistics['CountInstances'] !== $validateDicomUploadRequest->numberOfInstances) {
if ($statistics['CountInstances'] !== $expectedNumberOfInstances) {
throw new GaelOValidateDicomException("Error during Peer transfers");
}

Expand All @@ -140,7 +145,7 @@ public function execute(ValidateDicomUploadRequest $validateDicomUploadRequest,
$studyName,
$currentUserId,
$anonymizedOrthancStudyID,
$validateDicomUploadRequest->originalOrthancId
$originalOrthancId
);

$studyInstanceUID = $this->registerDicomStudyService->execute();
Expand Down

0 comments on commit c674f03

Please sign in to comment.