wip
This commit is contained in:
parent
4c26b8a473
commit
3d6eb1543e
@ -8,8 +8,8 @@ enum StudyAccessFlags: int
|
||||
{
|
||||
use BitmaskFunctionality;
|
||||
|
||||
case None = 0;
|
||||
case ViewPatientInfo = 1;
|
||||
case ViewDicom = 1 << 1;
|
||||
case ViewReports = 1 << 2;
|
||||
case Forbidden = 0;
|
||||
case ViewPatientInfo = 1 << 1;
|
||||
case ViewDicom = 1 << 2;
|
||||
case ViewReports = 1 << 3;
|
||||
}
|
||||
|
@ -41,4 +41,9 @@ public function getStudies(): array
|
||||
|
||||
return json_decode($response->getBody()->getContents(), true);
|
||||
}
|
||||
|
||||
public function getStudiesIds(): array
|
||||
{
|
||||
return json_decode($this->getClient()->get('/studies')->getBody()->getContents(), true);
|
||||
}
|
||||
}
|
||||
|
@ -5,27 +5,95 @@
|
||||
use App\Models\Enums\StudyLevelStatus;
|
||||
use App\Models\Study;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
final class StudyImporter
|
||||
{
|
||||
private array $study_ids = [];
|
||||
|
||||
private array $insert_queue = [];
|
||||
|
||||
private array $update_queue = [];
|
||||
|
||||
private OrthancRestClient $client;
|
||||
|
||||
public function __construct(?OrthancRestClient $client = null)
|
||||
{
|
||||
$this->client = $client ?? new OrthancRestClient;
|
||||
}
|
||||
|
||||
public function import(array $studies): void
|
||||
{
|
||||
foreach ($studies as $study) {
|
||||
$orthanc_uid = strtolower($study['ID']);
|
||||
$row = Study::where(compact('orthanc_uid'))->first();
|
||||
if ($row != null) {
|
||||
if ($row->study_status < StudyLevelStatus::StudyArrived) {
|
||||
// todo: update study
|
||||
$this->importStudy($study);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
public function scanStudies()
|
||||
{
|
||||
$this->study_ids = $this->client->getStudiesIds();
|
||||
}
|
||||
|
||||
private function checkUpdate(string $orthanc_uid): void
|
||||
{
|
||||
$row = DB::table('studies')->where('orthanc_uid', $orthanc_uid)->first(['id', 'study_status']);
|
||||
|
||||
if ($row == null) {
|
||||
$this->insert_queue[] = $orthanc_uid;
|
||||
}
|
||||
|
||||
if ($row->study_status < StudyLevelStatus::StudyArrived->value) {
|
||||
$this->update_queue[$orthanc_uid] = $row->id;
|
||||
}
|
||||
}
|
||||
|
||||
public function filterStudies()
|
||||
{
|
||||
$this->insert_queue = [];
|
||||
$this->update_queue = [];
|
||||
foreach ($this->study_ids as $study_id) {
|
||||
$this->checkUpdate($study_id);
|
||||
}
|
||||
}
|
||||
|
||||
private function fetchStudyDetails(string $orthanc_uid): ?array
|
||||
{
|
||||
$study = $this->client->getStudyDetails($orthanc_uid);
|
||||
if ($study == null) {
|
||||
return null;
|
||||
}
|
||||
$stats = $this->client->getStudyStatistics($orthanc_uid);
|
||||
$study['Statistics'] = $stats;
|
||||
|
||||
return $study;
|
||||
}
|
||||
|
||||
public function importStudies()
|
||||
{
|
||||
foreach ($this->update_queue as $orthanc_uid => $row_id) {
|
||||
$study = $this->fetchStudyDetails($orthanc_uid);
|
||||
if ($study == null) {
|
||||
continue;
|
||||
}
|
||||
$this->updateStudy($row_id, $study);
|
||||
}
|
||||
|
||||
foreach ($this->insert_queue as $orthanc_uid) {
|
||||
$study = $this->fetchStudyDetails($orthanc_uid);
|
||||
if ($study == null) {
|
||||
continue;
|
||||
}
|
||||
$this->insertStudy($study);
|
||||
}
|
||||
}
|
||||
|
||||
private function prepareData(mixed $study): array
|
||||
{
|
||||
$inst_name = data_get($study, 'MainDicomTags.InstitutionName');
|
||||
$inst_id = InstituteMapper::map($inst_name);
|
||||
|
||||
$data = [
|
||||
'orthanc_uid' => $orthanc_uid,
|
||||
'orthanc_uid' => strtolower($study['ID']),
|
||||
'is_locked' => false,
|
||||
'is_active' => true,
|
||||
|
||||
@ -52,7 +120,9 @@ public function import(array $studies): void
|
||||
'manufacturer' => data_get($study, 'RequestedTags.Manufacturer'),
|
||||
'manufacturer_model_name' => data_get($study, 'RequestedTags.ManufacturerModelName'),
|
||||
|
||||
'series_count' => count($study['Series']),
|
||||
'image_count' => data_get($study, 'Statistics.CountInstances'),
|
||||
'series_count' => data_get($study, 'Statistics.CountSeries'),
|
||||
'disk_size' => data_get($study, 'Statistics.DiskSize'),
|
||||
];
|
||||
|
||||
if ($study['IsStable']) {
|
||||
@ -71,7 +141,20 @@ public function import(array $studies): void
|
||||
$descr = data_get($study, 'RequestedTags.AcquisitionDeviceProcessingDescription');
|
||||
}
|
||||
$data['study_description'] = trim($descr);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function updateStudy(int $row_id, mixed $study): void
|
||||
{
|
||||
$data = $this->prepareData($study);
|
||||
unset($data['orthanc_uid']);
|
||||
Study::where('id', $row_id)->update($data);
|
||||
}
|
||||
|
||||
public function insertStudy(mixed $study): void
|
||||
{
|
||||
$data = $this->prepareData($study);
|
||||
Study::create($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ public function up(): void
|
||||
$table->dateTime('receive_date');
|
||||
$table->dateTime('report_date')->nullable();
|
||||
$table->foreignIdFor(Institute::class)->constrained()->onDelete('cascade');
|
||||
$table->unsignedTinyInteger('study_status')->default(StudyLevelStatus::None->value);
|
||||
$table->unsignedTinyInteger('study_status')->default(StudyLevelStatus::Pending->value);
|
||||
$table->unsignedTinyInteger('report_status')->default(ReportStatus::Pending->value);
|
||||
|
||||
$table->unsignedSmallInteger('image_count')->nullable(0);
|
||||
$table->unsignedSmallInteger('image_count')->nullable();
|
||||
$table->unsignedSmallInteger('series_count')->nullable();
|
||||
$table->unsignedSmallInteger('disk_size')->nullable();
|
||||
|
||||
@ -54,7 +54,7 @@ public function up(): void
|
||||
$table->foreignIdFor(User::class, 'referring_physician_id')->nullable()->constrained()->onDelete('set null');
|
||||
$table->foreignIdFor(User::class, 'reading_physician_id')->nullable()->constrained()->onDelete('set null');
|
||||
|
||||
$table->unsignedTinyInteger('access_flags')->default(StudyAccessFlags::None->value);
|
||||
$table->unsignedTinyInteger('access_flags')->default(StudyAccessFlags::Forbidden->value);
|
||||
$table->string('access_password')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user