Skip to content

Commit

Permalink
Merge pull request #707 from Pixilib/GaelO2-dev
Browse files Browse the repository at this point in the history
Add Azure storage, TmtvProcessing Service, improved coverage calculation
  • Loading branch information
salimkanoun authored Dec 24, 2023
2 parents 1172a2f + 2f921b1 commit 71e7c7b
Show file tree
Hide file tree
Showing 40 changed files with 1,082 additions and 811 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-stan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'

- name: 'Copy .env'
working-directory: ./GaelO2
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- GaelO2
- GaelO2-dev
- tmtv-inference
tags:
- '*'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'

- name: 'Copy .env'
working-directory: ./GaelO2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.phar
.VSCodeCounter/*

src/*
GaelO2/app/Console/Commands/RealysaTmtvInference.php
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM php:8.1.3-apache-bullseye
FROM php:8.2.13-apache-bullseye

ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0"
ENV TZ="UTC"

RUN apt-get update -qy && \
apt-get install -y --no-install-recommends apt-utils\
Expand All @@ -25,7 +26,7 @@ RUN apt-get update -qy && \
postgresql-client-13 && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pecl install pcov redis memcached-3.1.5
RUN pecl install pcov redis memcached
RUN docker-php-ext-install gd zip pdo pdo_mysql pdo_pgsql mbstring bcmath ctype fileinfo xml bz2 pcntl
RUN docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install opcache
Expand Down
5 changes: 5 additions & 0 deletions GaelO2/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ AZURE_SUBSCRIPTION_ID=''
AZURE_CONTAINER_GROUP=''
AZURE_RESOURCE_GROUP=''

FILESYSTEM_DISK='local'
AZURE_BLOB_DSN=''
AZURE_CONTAINER_NAME=''
AZURE_BLOB_PREFIX=''

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
Expand Down
12 changes: 9 additions & 3 deletions GaelO2/app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;
use DateTimeZone;

class Kernel extends ConsoleKernel
{
Expand Down Expand Up @@ -34,8 +35,8 @@ protected function schedule(Schedule $schedule)
$schedule->call(function () {
Log::info("Scheduler Probe");
})
->hourly()
->sentryMonitor('gaelo-scheduler');
->hourly()
->sentryMonitor('gaelo-scheduler');
}

/**
Expand All @@ -45,8 +46,13 @@ protected function schedule(Schedule $schedule)
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
$this->load(__DIR__ . '/Commands');

require base_path('routes/console.php');
}

protected function scheduleTimezone(): DateTimeZone|string|null
{
return 'UTC';
}
}
5 changes: 0 additions & 5 deletions GaelO2/app/GaelO/Adapters/JobAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\GaelO\Interfaces\Adapters\JobInterface;
use App\Jobs\JobQcReport;
use App\Jobs\JobRadiomicsReport;

class JobAdapter implements JobInterface
{
Expand All @@ -13,8 +12,4 @@ public function sendQcReportJob(int $visitId): void
JobQcReport::dispatch($visitId);
}

public function sendRadiomicsReport(int $visitId, ?int $behalfUserId, ?array $destinatorEmails): void
{
JobRadiomicsReport::dispatch($visitId, $behalfUserId, $destinatorEmails);
}
}
3 changes: 2 additions & 1 deletion GaelO2/app/GaelO/Adapters/MimeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\GaelO\Adapters;

use App\GaelO\Interfaces\Adapters\MimeInterface;
use Illuminate\Support\Facades\Log;
use League\MimeTypeDetection\ExtensionMimeTypeDetector;
use League\MimeTypeDetection\GeneratedExtensionToMimeTypeMap;

Expand All @@ -12,12 +11,14 @@ class MimeAdapter implements MimeInterface

public static function getExtensionsFromMime(string $mime): array
{
if ($mime === 'application/dicom') return ['dcm'];
$mimes = new ExtensionMimeTypeDetector();
return $mimes->lookupAllExtensions($mime);
}

public static function getMimeFromExtension(string $extension): string
{
if ($extension === 'dcm') return 'application/dicom';
$mimes = new GeneratedExtensionToMimeTypeMap();
return $mimes->lookupMimeType($extension);
}
Expand Down
10 changes: 10 additions & 0 deletions GaelO2/app/GaelO/Constants/Enums/ProcessingMaskEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\GaelO\Constants\Enums;

enum ProcessingMaskEnum: string
{
case RTSS = 'rtss';
case SEG = 'seg';
case NIFTI = 'nifti';
}
1 change: 0 additions & 1 deletion GaelO2/app/GaelO/Interfaces/Adapters/JobInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
interface JobInterface
{
public function sendQcReportJob(int $visitId) : void;
public function sendRadiomicsReport(int $visitId, ?int $behalfUserId, ?array $destinatorEmails) :void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getSeries(string $seriesInstanceUID, bool $withTrashed) : array

public function getRelatedVisitIdFromSeriesInstanceUID(array $seriesInstanceUID, bool $withTrashed) : array ;

public function getSeriesOrthancIDOfSeriesInstanceUID(array $seriesInstanceUID, bool $withTrashed) : array ;
public function getSeriesOrthancIDsOfSeriesInstanceUIDs(array $seriesInstanceUID, bool $withTrashed) : array ;

public function getDicomSeriesOfStudyInstanceUIDArray(array $studyInstanceUID, bool $withTrashed) : array ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function find($id) ;

public function delete($id) : void ;

public function createVisitGroup(String $studyName, String $name, String $modality) : void ;
public function createVisitGroup(String $studyName, String $name, String $modality) : array ;

public function hasVisitTypes(int $visitGroupId) : bool ;

Expand Down
2 changes: 1 addition & 1 deletion GaelO2/app/GaelO/Repositories/DicomSeriesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getRelatedVisitIdFromSeriesInstanceUID(array $seriesInstanceUID,
return $query->get()->pluck('dicomStudy.visit_id')->unique()->toArray();
}

public function getSeriesOrthancIDOfSeriesInstanceUID(array $seriesInstanceUID, bool $withTrashed): array
public function getSeriesOrthancIDsOfSeriesInstanceUIDs(array $seriesInstanceUID, bool $withTrashed): array
{
$query = $this->dicomSeriesModel
->whereIn('series_uid', $seriesInstanceUID)
Expand Down
3 changes: 2 additions & 1 deletion GaelO2/app/GaelO/Repositories/VisitGroupRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ public function delete($id): void
$this->visitGroupModel->findOrFail($id)->delete();
}

public function createVisitGroup(String $studyName, String $name, String $modality): void
public function createVisitGroup(String $studyName, String $name, String $modality): array
{

$visitGroup = new VisitGroup();
$visitGroup->name = $name;
$visitGroup->study_name = $studyName;
$visitGroup->modality = $modality;
$visitGroup->save();
return $visitGroup->toArray();
}

public function hasVisitTypes(int $visitGroupId): bool
Expand Down
2 changes: 1 addition & 1 deletion GaelO2/app/GaelO/Services/FormService/FormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function attachFile(array $reviewEntity, string $key, string $mimeType, s
return $filename;
}

public function removeFile(array $reviewEntity, string $key): void
public function deleteFile(array $reviewEntity, string $key): void
{
if (empty($reviewEntity['sent_files'][$key])) {
throw new GaelOBadRequestException('Non exisiting key file in review');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\GaelO\Constants\SettingsConstants;
use App\GaelO\Interfaces\Adapters\FrameworkInterface;
use App\GaelO\Interfaces\Adapters\HttpClientInterface;
use Illuminate\Support\Facades\Log;

class GaelOProcessingService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace App\GaelO\Services\GaelOProcessingService;

use App\GaelO\Constants\Enums\ProcessingMaskEnum;
use App\GaelO\Services\GaelOProcessingService\GaelOProcessingService;
use App\GaelO\Services\OrthancService;

class MaskProcessingService
{

private string $maskId;
private string $petId;
private string $petSeriesOrthancId;
private GaelOProcessingService $gaelOProcessingService;
private OrthancService $orthancService;

public function __construct(
OrthancService $orthancService,
GaelOProcessingService $gaelOProcessingService,
) {
$this->gaelOProcessingService = $gaelOProcessingService;
$this->orthancService = $orthancService;
$this->orthancService->setOrthancServer(true);
}

public function setMaskId(string $maskId)
{
$this->maskId = $maskId;
}

public function getMaskId(): string
{
return $this->maskId;
}

public function setPetId(string $petId, string $petSeriesOrthancId)
{
$this->petId = $petId;
$this->petSeriesOrthancId = $petSeriesOrthancId;
}

public function getMaskAs(ProcessingMaskEnum $type, ?string $orientation = null) : string
{
if ($type === ProcessingMaskEnum::NIFTI) {
$exportFile = $this->gaelOProcessingService->getMaskDicomOrientation($this->maskId, $orientation, true);
} else if ($type === ProcessingMaskEnum::RTSS) {
$rtssId = $this->gaelOProcessingService->createRtssFromMask($this->petSeriesOrthancId, $this->maskId);
$exportFile = $this->gaelOProcessingService->getRtss($rtssId);
//remove downloaded data from processing
$this->gaelOProcessingService->deleteRessource("rtss", $rtssId);
} else if ($type === ProcessingMaskEnum::SEG) {
$segId = $this->gaelOProcessingService->createSegFromMask($this->petSeriesOrthancId, $this->maskId);
$exportFile = $this->gaelOProcessingService->getSeg($segId);
//remove downloaded data from processing
$this->gaelOProcessingService->deleteRessource("seg", $segId);
}

return $exportFile;
}

public function getStatsOfMask(): array
{
return $this->gaelOProcessingService->getStatsMaskSeries($this->maskId, $this->petId);
}

public function fragmentMask(): MaskProcessingService
{
$fragmentedMaskId = $this->gaelOProcessingService->fragmentMask($this->petId, $this->maskId, true);
$maskProcessingService = new MaskProcessingService($this->orthancService, $this->gaelOProcessingService);
$maskProcessingService->setMaskId($fragmentedMaskId);
$maskProcessingService->setPetId($this->petId, $this->petSeriesOrthancId);
return $maskProcessingService;
}

public function thresholdMaskTo41(): MaskProcessingService
{
$threshold41MaskId = $this->gaelOProcessingService->thresholdMask($this->maskId, $this->petId, "41%");
$maskProcessingService = new MaskProcessingService($this->orthancService, $this->gaelOProcessingService);
$maskProcessingService->setMaskId($threshold41MaskId);
$maskProcessingService->setPetId($this->petId, $this->petSeriesOrthancId);
return $maskProcessingService;
}

public function createTepMaskMip(): string
{
$mipFragmentedPayload = ['maskId' => $this->maskId, 'delay' => 0.3, 'min' => 0, 'max' => 5, 'inverted' => true, 'orientation' => 'LPI'];
$mipMask = $this->gaelOProcessingService->createMIPForSeries($this->petId, $mipFragmentedPayload);
return $mipMask;
}
}
Loading

0 comments on commit 71e7c7b

Please sign in to comment.