diff --git a/app/Services/Pacs/OrthancRestClient.php b/app/Services/Pacs/OrthancRestClient.php index 67525fb..7435726 100644 --- a/app/Services/Pacs/OrthancRestClient.php +++ b/app/Services/Pacs/OrthancRestClient.php @@ -4,11 +4,27 @@ use App\Models\DicomServer; use GuzzleHttp\Client; +use Psr\Http\Message\ResponseInterface; final class OrthancRestClient { public function __construct(private readonly DicomServer $orthancHost) {} + private static function studyPath(string $study_id, ?string $sub = null): string + { + $parts = ['studies', ltrim($study_id, '/')]; + if (filled($sub)) { + $parts[] = ltrim($sub, '/'); + } + + return implode('/', $parts); + } + + private static function jsonify(ResponseInterface $response, bool $associative = true): mixed + { + return json_decode($response->getBody()->getContents(), $associative, 512, JSON_THROW_ON_ERROR); + } + public function getClient(): Client { $endpoint = $this->orthancHost->rest_api_endpoint; @@ -23,38 +39,35 @@ public function getStudyStatistics(string $study_id): array { $response = $this->getClient()->get('/studies/' . $study_id . '/statistics'); - return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + return self::jsonify($response); } public function getServerStatistics(): array { $response = $this->getClient()->get('/statistics'); - return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); - } - - private static function studyPath(string $study_id, ?string $sub = null): string - { - $parts = ['studies', ltrim($study_id, '/')]; - if (filled($sub)) { - $parts[] = ltrim($sub, '/'); - } - - return implode('/', $parts); + return self::jsonify($response); } public function getStudySeries(string $study_id): array { $response = $this->getClient()->get(self::studyPath($study_id, 'series?expand')); - return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + return self::jsonify($response); } public function getStudyInstances(string $study_id): array { $response = $this->getClient()->get(self::studyPath($study_id, 'instances?expand')); - return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + return self::jsonify($response); + } + + public function getStudyInstancesList(string $study_id): array + { + $response = $this->getClient()->get(self::studyPath($study_id, 'instances?expand=0')); + + return self::jsonify($response); } public function getStudyDetails(string $study_id): array @@ -64,7 +77,7 @@ public function getStudyDetails(string $study_id): array ]; $response = $this->getClient()->get('/studies/' . $study_id . '?' . http_build_query($query)); - return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + return self::jsonify($response); } public function getStudies(): array @@ -76,7 +89,7 @@ public function getStudies(): array $url = '/studies?' . http_build_query($query); $response = $this->getClient()->get($url); - return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR); + return self::jsonify($response); } public function getStudiesIds(): array