From 3eb06e20a0b1d33b5ecd2f28564b90818f729ced Mon Sep 17 00:00:00 2001 From: Dr Masroor Ehsan Date: Thu, 23 Jan 2025 14:25:02 +0600 Subject: [PATCH] orthanc --- app/Services/Pacs/OrthancRestClient.php | 35 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/app/Services/Pacs/OrthancRestClient.php b/app/Services/Pacs/OrthancRestClient.php index 7435726..ea392d0 100644 --- a/app/Services/Pacs/OrthancRestClient.php +++ b/app/Services/Pacs/OrthancRestClient.php @@ -3,6 +3,7 @@ namespace App\Services\Pacs; use App\Models\DicomServer; +use App\Services\StudyRouter\RawDicomTags; use GuzzleHttp\Client; use Psr\Http\Message\ResponseInterface; @@ -10,14 +11,19 @@ final class OrthancRestClient { public function __construct(private readonly DicomServer $orthancHost) {} - private static function studyPath(string $study_id, ?string $sub = null): string + private static function relativePath(string $study_id, ?string $child = null, array $query = [], string $parent = 'studies'): string { - $parts = ['studies', ltrim($study_id, '/')]; - if (filled($sub)) { - $parts[] = ltrim($sub, '/'); + $parts = [$parent, ltrim($study_id, '/')]; + if (filled($child)) { + $parts[] = ltrim($child, '/'); } - return implode('/', $parts); + $path = implode('/', $parts); + if (! empty($query)) { + $path .= '?' . http_build_query($query); + } + + return $path; } private static function jsonify(ResponseInterface $response, bool $associative = true): mixed @@ -51,21 +57,21 @@ public function getServerStatistics(): array public function getStudySeries(string $study_id): array { - $response = $this->getClient()->get(self::studyPath($study_id, 'series?expand')); + $response = $this->getClient()->get(self::relativePath($study_id, 'series', ['expand' => 1])); return self::jsonify($response); } public function getStudyInstances(string $study_id): array { - $response = $this->getClient()->get(self::studyPath($study_id, 'instances?expand')); + $response = $this->getClient()->get(self::relativePath($study_id, 'instances', ['expand' => 1])); return self::jsonify($response); } public function getStudyInstancesList(string $study_id): array { - $response = $this->getClient()->get(self::studyPath($study_id, 'instances?expand=0')); + $response = $this->getClient()->get(self::relativePath($study_id, 'instances', ['expand' => 0])); return self::jsonify($response); } @@ -75,7 +81,18 @@ public function getStudyDetails(string $study_id): array $query = [ 'requested-tags' => implode(';', array_column(DicomTags::cases(), 'value')), ]; - $response = $this->getClient()->get('/studies/' . $study_id . '?' . http_build_query($query)); + $response = $this->getClient()->get(self::relativePath($study_id, null, $query)); + + return self::jsonify($response); + } + + public function getInstanceDetails(string $instance_id, bool $rawTags = false): array + { + $query = $rawTags ? [ + 'requested-tags' => implode(';', array_column(RawDicomTags::cases(), 'value')), + 'short' => 1, + ] : []; + $response = $this->getClient()->get(self::relativePath($instance_id, null, $query, 'instances')); return self::jsonify($response); }