This commit is contained in:
Dr Masroor Ehsan 2025-01-10 15:19:19 +06:00
parent f5c59bbea2
commit ddb9edf013
9 changed files with 52 additions and 13 deletions

View File

@ -3,13 +3,16 @@
namespace App\Http\Controllers\System;
use App\Http\Controllers\Controller;
use App\Models\OrthancHost;
use App\Services\Pacs\Sync\StudiesSync;
class SyncOrthancController extends Controller
{
public function __invoke()
{
(new StudiesSync)->execute();
foreach (OrthancHost::active()->get() as $host) {
(new StudiesSync($host))->execute();
}
return redirect()->route('staff.worklist.index');
}

View File

@ -2,11 +2,14 @@
namespace App\Models;
use App\Models\Traits\Active;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Facility extends Model
{
use Active;
public function institute(): BelongsTo
{
return $this->belongsTo(Institute::class);

View File

@ -2,10 +2,12 @@
namespace App\Models;
use App\Models\Traits\Active;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Institute extends BaseModel
{
use Active;
use HasFactory;
protected function casts(): array

View File

@ -2,16 +2,19 @@
namespace App\Models;
use App\Models\Traits\Active;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class OrthancHost extends BaseModel
{
use Active;
public function institute(): BelongsTo
{
return $this->belongsTo(Institute::class);
}
public function facilty(): BelongsTo
public function facility(): BelongsTo
{
return $this->belongsTo(Facility::class);
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Models\Traits;
use Illuminate\Database\Eloquent\Builder;
trait Active
{
public function scopeActive(Builder $query): Builder
{
return $query->where($this->getActiveColumnName(), '=', true);
}
public function scopeInactive(Builder $query): Builder
{
return $query->where($this->getActiveColumnName(), '=', false);
}
protected function getActiveColumnName(): string
{
return 'is_active';
}
}

View File

@ -4,6 +4,7 @@
use App\Domain\ACL\Permission;
use App\Domain\ACL\Role;
use App\Models\Traits\Active;
use App\Models\Traits\HashableId;
use App\Services\UserService;
use Carbon\Carbon;
@ -21,11 +22,10 @@
class User extends Authenticatable
{
use Active;
use HasApiTokens;
/** @use HasFactory<UserFactory> */
use HasFactory;
use HashableId;
use HasProfilePhoto;
use HasRoles;
@ -77,11 +77,6 @@ class User extends Authenticatable
'last_seen',
];
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function isAdmin(): bool
{
return cache()->remember('user.is_admin:' . $this->id,

View File

@ -2,10 +2,13 @@
namespace App\Services\Pacs;
use App\Models\OrthancHost;
use GuzzleHttp\Client;
final class OrthancRestClient
{
public function __construct(private readonly OrthancHost $orthancHost) {}
public function getClient(): Client
{
return new Client([

View File

@ -4,6 +4,7 @@
use App\Domain\Study\Priority;
use App\Domain\Study\StudyLevelStatus;
use App\Models\OrthancHost;
use App\Services\Pacs\DicomUtils;
use App\Services\Pacs\InstituteMapper;
use App\Services\Pacs\OrthancRestClient;
@ -25,13 +26,18 @@ class StudiesSync
private OrthancRestClient $client;
public function __construct(?OrthancRestClient $client = null)
public function __construct(private readonly OrthancHost $orthancHost, ?OrthancRestClient $client = null)
{
$this->study_ids = collect();
$this->client = $client ?? new OrthancRestClient;
$this->client = $client ?? new OrthancRestClient($orthancHost);
$this->resetQueues();
}
public function getOrthancHost(): OrthancHost
{
return $this->orthancHost;
}
public function execute(): void
{
app(Pipeline::class)
@ -61,7 +67,7 @@ public function setStudyIds(array $study_ids): void
$this->study_ids = collect($study_ids);
}
public function resetQueues()
public function resetQueues(): void
{
$this->insert_queue = collect();
$this->update_queue = collect();
@ -107,6 +113,7 @@ public function transformData(mixed $orthanc_src): array
$patient_name = data_get($orthanc_src, 'PatientMainDicomTags.PatientName');
$study = [
'orthanc_host_id' => $this->orthancHost->id,
'orthanc_uuid' => strtolower($orthanc_src['ID']),
'institution_name' => $inst_name,
'institute_id' => $inst_id,

View File

@ -15,7 +15,7 @@ public function up(): void
Schema::create('studies', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(OrthancHost::class)->index();
$table->uuid('orthanc_uuid')->index();
$table->string('orthanc_uuid')->index();
$table->boolean('is_archived')->default(false);
$table->unsignedTinyInteger('priority')->default(Priority::Routine);