Skip to content

Commit

Permalink
remove temporary upload if count dicom failure, prevent timout script
Browse files Browse the repository at this point in the history
  • Loading branch information
salimkanoun committed Jun 6, 2023
1 parent 7dfa8d4 commit 36f6665
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
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 @@ -56,10 +56,6 @@ public function execute(ValidateDicomUploadRequest $validateDicomUploadRequest,
{

try {

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

//Retrieve Visit Context
$this->visitService->setVisitId($validateDicomUploadRequest->visitId);
$visitContext = $this->visitService->getVisitContext();
Expand All @@ -81,6 +77,8 @@ public function execute(ValidateDicomUploadRequest $validateDicomUploadRequest,
//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 @@ -106,11 +104,13 @@ public function execute(ValidateDicomUploadRequest $validateDicomUploadRequest,
$this->orthancService->setOrthancServer(false);

$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 Down

0 comments on commit 36f6665

Please sign in to comment.