53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Pacs\Sync\Pipes;
|
|
|
|
use App\DAL\Studies;
|
|
use App\Services\AuditTrail\Activity;
|
|
use App\Services\AuditTrail\Category;
|
|
use App\Services\Pacs\Sync\StudiesSync;
|
|
use Closure;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final readonly class UpdateStudies
|
|
{
|
|
public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
|
{
|
|
foreach ($sync->getUpdateQueue() as $orthanc_uuid) {
|
|
$study = $sync->fetchStudyDetails($orthanc_uuid);
|
|
if ($study == null) {
|
|
continue;
|
|
}
|
|
|
|
$study_id = Studies::getStudyIdByOrthancUuid($orthanc_uuid);
|
|
if ($study_id === null) {
|
|
continue;
|
|
}
|
|
|
|
$payload = $sync->transformData($study);
|
|
if (empty($payload)) {
|
|
continue;
|
|
}
|
|
|
|
unset($payload['study']['orthanc_uuid']);
|
|
$payload['study']['updated_at'] = now();
|
|
DB::table('studies')->where('id', $study_id)->update($payload['study']);
|
|
|
|
if (! empty($payload['details'])) {
|
|
$payload['details']['updated_at'] = now();
|
|
DB::table('study_details')->where(compact('study_id'))->update($payload['details']);
|
|
}
|
|
|
|
audit()
|
|
->by(sync_agent_id())
|
|
->category(Category::SYSTEM)
|
|
->on($study_id)
|
|
->orthanc($orthanc_uuid)
|
|
->did(Activity::Study_Update)
|
|
->log(false);
|
|
}
|
|
|
|
return $next($sync);
|
|
}
|
|
}
|