refx - orthanc_uuid, details, series
This commit is contained in:
parent
3c7d43542b
commit
bec5d3f488
@ -28,18 +28,18 @@ public function scanStudies()
|
||||
$this->study_ids = $this->client->getStudiesIds();
|
||||
}
|
||||
|
||||
private function checkUpdate(string $orthanc_uid): void
|
||||
private function checkUpdate(string $orthanc_uuid): void
|
||||
{
|
||||
$row = DB::table('studies')->where('orthanc_uid', $orthanc_uid)->first(['id', 'study_status']);
|
||||
$row = DB::table('studies')->where('orthanc_uuid', $orthanc_uuid)->first(['id', 'study_status']);
|
||||
|
||||
if ($row === null) {
|
||||
$this->insert_queue[] = $orthanc_uid;
|
||||
$this->insert_queue[] = $orthanc_uuid;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($row->study_status < StudyLevelStatus::StudyArrived->value) {
|
||||
$this->update_queue[$orthanc_uid] = $row->id;
|
||||
$this->update_queue[$orthanc_uuid] = $row->id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,16 +70,16 @@ private function fetchStudyDetails(string $orthanc_uid): ?array
|
||||
|
||||
public function importStudies()
|
||||
{
|
||||
foreach ($this->update_queue as $orthanc_uid => $row_id) {
|
||||
$study = $this->fetchStudyDetails($orthanc_uid);
|
||||
foreach ($this->update_queue as $orthanc_uuid => $row_id) {
|
||||
$study = $this->fetchStudyDetails($orthanc_uuid);
|
||||
if ($study == null) {
|
||||
continue;
|
||||
}
|
||||
$this->updateStudy($row_id, $study);
|
||||
}
|
||||
|
||||
foreach ($this->insert_queue as $orthanc_uid) {
|
||||
$study = $this->fetchStudyDetails($orthanc_uid);
|
||||
foreach ($this->insert_queue as $orthanc_uuid) {
|
||||
$study = $this->fetchStudyDetails($orthanc_uuid);
|
||||
if ($study == null) {
|
||||
continue;
|
||||
}
|
||||
@ -93,7 +93,7 @@ private function prepareData(mixed $orthanc_src): array
|
||||
$inst_id = InstituteMapper::map($inst_name);
|
||||
|
||||
$study = [
|
||||
'orthanc_uid' => strtolower($orthanc_src['ID']),
|
||||
'orthanc_uuid' => strtolower($orthanc_src['ID']),
|
||||
'is_locked' => false,
|
||||
'is_active' => true,
|
||||
|
||||
@ -137,18 +137,19 @@ private function prepareData(mixed $orthanc_src): array
|
||||
}
|
||||
$this->setValue($study, 'study_description', trim($descr));
|
||||
|
||||
$details = [
|
||||
$properties = [
|
||||
'software_versions' => data_get($study, 'RequestedTags.SoftwareVersions'),
|
||||
'station_name' => data_get($study, 'RequestedTags.StationName'),
|
||||
'operators_name' => data_get($study, 'RequestedTags.OperatorsName'),
|
||||
'manufacturer' => data_get($study, 'RequestedTags.Manufacturer'),
|
||||
'manufacturer_model_name' => data_get($study, 'RequestedTags.ManufacturerModelName'),
|
||||
];
|
||||
$properties = array_purge($properties);
|
||||
|
||||
$series = [];
|
||||
foreach (data_get($orthanc_src, 'Series', []) as $ser) {
|
||||
$params = [
|
||||
'orthanc_uid' => strtolower($ser['ID']),
|
||||
'orthanc_uuid' => strtolower($ser['ID']),
|
||||
'series_instance_uid' => data_get($ser, 'MainDicomTags.SeriesInstanceUID'),
|
||||
'series_date' => DicomUtils::dateTimeToCarbon($ser['MainDicomTags']['SeriesDate'], $ser['MainDicomTags']['SeriesTime']),
|
||||
'series_number' => data_get($ser, 'MainDicomTags.SeriesNumber'),
|
||||
@ -159,16 +160,23 @@ private function prepareData(mixed $orthanc_src): array
|
||||
'sequence_name' => data_get($ser, 'MainDicomTags.SequenceName'),
|
||||
];
|
||||
$params['num_instances'] = count(data_get($ser, 'Instances', []));
|
||||
$params = array_filter($params, fn ($v) => filled($v));
|
||||
$params = array_purge($params);
|
||||
if (! empty($params)) {
|
||||
$series[] = array_filter($params, fn ($v) => filled($v));
|
||||
$series[] = $params;
|
||||
}
|
||||
}
|
||||
|
||||
$study = array_filter($study, fn ($v) => filled($v));
|
||||
$details = array_filter($details, fn ($v) => filled($v));
|
||||
if (empty($series)) {
|
||||
$series = null;
|
||||
}
|
||||
if (empty($properties)) {
|
||||
$properties = null;
|
||||
}
|
||||
$details = compact('properties', 'series');
|
||||
$details = array_purge($details);
|
||||
$study = array_purge($study);
|
||||
|
||||
return compact('study', 'details', 'series');
|
||||
return compact('study', 'details');
|
||||
}
|
||||
|
||||
private function setValue(array &$array, string $key, mixed $value): void
|
||||
@ -181,7 +189,7 @@ private function setValue(array &$array, string $key, mixed $value): void
|
||||
private function updateStudy(int $row_id, mixed $study): void
|
||||
{
|
||||
$payload = $this->prepareData($study);
|
||||
unset($payload['study']['orthanc_uid']);
|
||||
unset($payload['study']['orthanc_uuid']);
|
||||
$payload['study']['updated_at'] = now();
|
||||
DB::table('studies')->where('id', $row_id)->update($payload['study']);
|
||||
|
||||
@ -189,13 +197,6 @@ private function updateStudy(int $row_id, mixed $study): void
|
||||
$payload['details']['updated_at'] = now();
|
||||
DB::table('study_details')->where('study_id', $row_id)->update($payload['details']);
|
||||
}
|
||||
|
||||
foreach ($payload['series'] as $series) {
|
||||
$series_guid = $series['orthanc_uid'];
|
||||
unset($series['orthanc_uid']);
|
||||
$series['updated_at'] = now();
|
||||
DB::table('study_series')->where('orthanc_uid', $series_guid)->update($series);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertStudy(mixed $study): void
|
||||
@ -204,11 +205,5 @@ private function insertStudy(mixed $study): void
|
||||
$row = Study::create($payload['study']);
|
||||
$payload['details']['study_id'] = $row->id;
|
||||
StudyDetails::create($payload['details']);
|
||||
|
||||
foreach ($payload['series'] as $series) {
|
||||
$series['study_id'] = $row->id;
|
||||
$series['created_at'] = now();
|
||||
DB::table('study_series')->insert($series);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,3 +22,10 @@ function audit(): ActivityLogger
|
||||
return app(ActivityLogger::class);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('array_purge')) {
|
||||
function array_purge(array $ary): array
|
||||
{
|
||||
return array_filter($ary, fn ($v) => filled($v));
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public function up(): void
|
||||
{
|
||||
Schema::create('studies', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('orthanc_uid')->unique();
|
||||
$table->string('orthanc_uuid')->unique();
|
||||
$table->boolean('is_archived')->default(false);
|
||||
$table->boolean('is_locked')->default(false);
|
||||
$table->unsignedTinyInteger('study_priority')->default(0);
|
||||
|
Loading…
Reference in New Issue
Block a user