wip
This commit is contained in:
parent
2e2b30cc13
commit
6e53c98925
18
app/DAL/Studies.php
Normal file
18
app/DAL/Studies.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL;
|
||||
|
||||
use Cache;
|
||||
use DB;
|
||||
|
||||
final readonly class Studies
|
||||
{
|
||||
public static function getStudyIdByOrthancUuid(string $orthanc_uuid): ?int
|
||||
{
|
||||
return Cache::remember("studies.orthanc_uuid.{$orthanc_uuid}",
|
||||
now()->addHours(1),
|
||||
fn () => DB::table('studies')
|
||||
->where('orthanc_uuid', strtolower($orthanc_uuid))
|
||||
->value('id'));
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
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;
|
||||
@ -13,8 +14,8 @@
|
||||
public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
||||
{
|
||||
foreach ($sync->getArchiveQueue() as $orthanc_uuid) {
|
||||
$row_id = DB::table('studies')->where(compact('orthanc_uuid'))->value('id');
|
||||
if ($row_id === null) {
|
||||
$study_id = Studies::getStudyIdByOrthancUuid($orthanc_uuid);
|
||||
if ($study_id === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -22,12 +23,12 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
||||
'is_archived' => true,
|
||||
'updated_at' => now(),
|
||||
];
|
||||
DB::table('studies')->find($row_id)->update($payload);
|
||||
DB::table('studies')->where('id', $study_id)->update($payload);
|
||||
|
||||
audit()
|
||||
->by(sync_agent_id())
|
||||
->category(Category::SYSTEM)
|
||||
->on($row_id)
|
||||
->on($study_id)
|
||||
->orthanc($orthanc_uuid)
|
||||
->did(Activity::Study_Archived)
|
||||
->log(false);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
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;
|
||||
@ -17,7 +18,8 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
||||
if ($study == null) {
|
||||
continue;
|
||||
}
|
||||
$study_id = DB::table('studies')->where(compact('orthanc_uuid'))->value('id');
|
||||
|
||||
$study_id = Studies::getStudyIdByOrthancUuid($orthanc_uuid);
|
||||
if ($study_id === null) {
|
||||
continue;
|
||||
}
|
||||
@ -25,7 +27,7 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
||||
$payload = $sync->transformData($study);
|
||||
unset($payload['study']['orthanc_uuid']);
|
||||
$payload['study']['updated_at'] = now();
|
||||
DB::table('studies')->find($study_id)->update($payload['study']);
|
||||
DB::table('studies')->where('id', $study_id)->update($payload['study']);
|
||||
|
||||
if (! empty($payload['details'])) {
|
||||
$payload['details']['updated_at'] = now();
|
||||
|
@ -104,9 +104,6 @@ public function transformData(mixed $orthanc_src): array
|
||||
|
||||
$study = [
|
||||
'orthanc_uuid' => strtolower($orthanc_src['ID']),
|
||||
'is_locked' => false,
|
||||
'is_active' => true,
|
||||
|
||||
'institution_name' => $inst_name,
|
||||
'institute_id' => $inst_id,
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Enums\NameMatchModes;
|
||||
use App\Models\Facility;
|
||||
use App\Models\Institute;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@ -12,7 +13,8 @@ public function up(): void
|
||||
{
|
||||
Schema::create('institute_names', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(Institute::class)->constrained()->onDelete('CASCADE');
|
||||
$table->foreignIdFor(Institute::class)->constrained()->cascadeOnDelete();
|
||||
$table->foreignIdFor(Facility::class)->nullable()->constrained()->cascadeOnDelete();
|
||||
$table->string('name')->unique();
|
||||
$table->unsignedTinyInteger('match_mode')->default(NameMatchModes::Exact->value);
|
||||
$table->unsignedTinyInteger('priority')->default(0);
|
||||
|
Loading…
Reference in New Issue
Block a user