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;
|
namespace App\Services\Pacs\Sync\Pipes;
|
||||||
|
|
||||||
|
use App\DAL\Studies;
|
||||||
use App\Services\AuditTrail\Activity;
|
use App\Services\AuditTrail\Activity;
|
||||||
use App\Services\AuditTrail\Category;
|
use App\Services\AuditTrail\Category;
|
||||||
use App\Services\Pacs\Sync\StudiesSync;
|
use App\Services\Pacs\Sync\StudiesSync;
|
||||||
@ -13,8 +14,8 @@
|
|||||||
public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
||||||
{
|
{
|
||||||
foreach ($sync->getArchiveQueue() as $orthanc_uuid) {
|
foreach ($sync->getArchiveQueue() as $orthanc_uuid) {
|
||||||
$row_id = DB::table('studies')->where(compact('orthanc_uuid'))->value('id');
|
$study_id = Studies::getStudyIdByOrthancUuid($orthanc_uuid);
|
||||||
if ($row_id === null) {
|
if ($study_id === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,12 +23,12 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
|||||||
'is_archived' => true,
|
'is_archived' => true,
|
||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
];
|
];
|
||||||
DB::table('studies')->find($row_id)->update($payload);
|
DB::table('studies')->where('id', $study_id)->update($payload);
|
||||||
|
|
||||||
audit()
|
audit()
|
||||||
->by(sync_agent_id())
|
->by(sync_agent_id())
|
||||||
->category(Category::SYSTEM)
|
->category(Category::SYSTEM)
|
||||||
->on($row_id)
|
->on($study_id)
|
||||||
->orthanc($orthanc_uuid)
|
->orthanc($orthanc_uuid)
|
||||||
->did(Activity::Study_Archived)
|
->did(Activity::Study_Archived)
|
||||||
->log(false);
|
->log(false);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Services\Pacs\Sync\Pipes;
|
namespace App\Services\Pacs\Sync\Pipes;
|
||||||
|
|
||||||
|
use App\DAL\Studies;
|
||||||
use App\Services\AuditTrail\Activity;
|
use App\Services\AuditTrail\Activity;
|
||||||
use App\Services\AuditTrail\Category;
|
use App\Services\AuditTrail\Category;
|
||||||
use App\Services\Pacs\Sync\StudiesSync;
|
use App\Services\Pacs\Sync\StudiesSync;
|
||||||
@ -17,7 +18,8 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
|||||||
if ($study == null) {
|
if ($study == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$study_id = DB::table('studies')->where(compact('orthanc_uuid'))->value('id');
|
|
||||||
|
$study_id = Studies::getStudyIdByOrthancUuid($orthanc_uuid);
|
||||||
if ($study_id === null) {
|
if ($study_id === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -25,7 +27,7 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync
|
|||||||
$payload = $sync->transformData($study);
|
$payload = $sync->transformData($study);
|
||||||
unset($payload['study']['orthanc_uuid']);
|
unset($payload['study']['orthanc_uuid']);
|
||||||
$payload['study']['updated_at'] = now();
|
$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'])) {
|
if (! empty($payload['details'])) {
|
||||||
$payload['details']['updated_at'] = now();
|
$payload['details']['updated_at'] = now();
|
||||||
|
@ -104,9 +104,6 @@ public function transformData(mixed $orthanc_src): array
|
|||||||
|
|
||||||
$study = [
|
$study = [
|
||||||
'orthanc_uuid' => strtolower($orthanc_src['ID']),
|
'orthanc_uuid' => strtolower($orthanc_src['ID']),
|
||||||
'is_locked' => false,
|
|
||||||
'is_active' => true,
|
|
||||||
|
|
||||||
'institution_name' => $inst_name,
|
'institution_name' => $inst_name,
|
||||||
'institute_id' => $inst_id,
|
'institute_id' => $inst_id,
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Enums\NameMatchModes;
|
use App\Models\Enums\NameMatchModes;
|
||||||
|
use App\Models\Facility;
|
||||||
use App\Models\Institute;
|
use App\Models\Institute;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
@ -12,7 +13,8 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('institute_names', function (Blueprint $table) {
|
Schema::create('institute_names', function (Blueprint $table) {
|
||||||
$table->id();
|
$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->string('name')->unique();
|
||||||
$table->unsignedTinyInteger('match_mode')->default(NameMatchModes::Exact->value);
|
$table->unsignedTinyInteger('match_mode')->default(NameMatchModes::Exact->value);
|
||||||
$table->unsignedTinyInteger('priority')->default(0);
|
$table->unsignedTinyInteger('priority')->default(0);
|
||||||
|
Loading…
Reference in New Issue
Block a user