100 lines
2.8 KiB
PHP
100 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Pacs;
|
|
|
|
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;
|
|
|
|
return new Client([
|
|
'base_uri' => $endpoint,
|
|
// 'base_uri' => config('pacs.api.endpoint'),
|
|
]);
|
|
}
|
|
|
|
public function getStudyStatistics(string $study_id): array
|
|
{
|
|
$response = $this->getClient()->get('/studies/' . $study_id . '/statistics');
|
|
|
|
return self::jsonify($response);
|
|
}
|
|
|
|
public function getServerStatistics(): array
|
|
{
|
|
$response = $this->getClient()->get('/statistics');
|
|
|
|
return self::jsonify($response);
|
|
}
|
|
|
|
public function getStudySeries(string $study_id): array
|
|
{
|
|
$response = $this->getClient()->get(self::studyPath($study_id, 'series?expand'));
|
|
|
|
return self::jsonify($response);
|
|
}
|
|
|
|
public function getStudyInstances(string $study_id): array
|
|
{
|
|
$response = $this->getClient()->get(self::studyPath($study_id, 'instances?expand'));
|
|
|
|
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
|
|
{
|
|
$query = [
|
|
'requested-tags' => implode(';', array_column(DicomTags::cases(), 'value')),
|
|
];
|
|
$response = $this->getClient()->get('/studies/' . $study_id . '?' . http_build_query($query));
|
|
|
|
return self::jsonify($response);
|
|
}
|
|
|
|
public function getStudies(): array
|
|
{
|
|
$query = [
|
|
'expand' => '1',
|
|
'requested-tags' => implode(';', array_column(DicomTags::cases(), 'value')),
|
|
];
|
|
$url = '/studies?' . http_build_query($query);
|
|
$response = $this->getClient()->get($url);
|
|
|
|
return self::jsonify($response);
|
|
}
|
|
|
|
public function getStudiesIds(): array
|
|
{
|
|
return json_decode($this->getClient()->get('/studies')->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
|
|
}
|
|
}
|