diff --git a/app/Http/Controllers/System/SyncOrthancController.php b/app/Http/Controllers/System/SyncOrthancController.php index 8cca62a..4cf4caa 100644 --- a/app/Http/Controllers/System/SyncOrthancController.php +++ b/app/Http/Controllers/System/SyncOrthancController.php @@ -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'); } diff --git a/app/Models/Facility.php b/app/Models/Facility.php index 03bbcd1..4744b03 100644 --- a/app/Models/Facility.php +++ b/app/Models/Facility.php @@ -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); diff --git a/app/Models/Institute.php b/app/Models/Institute.php index 47a007b..d080d4d 100644 --- a/app/Models/Institute.php +++ b/app/Models/Institute.php @@ -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 diff --git a/app/Models/OrthancHost.php b/app/Models/OrthancHost.php index b088392..8cb3d74 100644 --- a/app/Models/OrthancHost.php +++ b/app/Models/OrthancHost.php @@ -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); } diff --git a/app/Models/Traits/Active.php b/app/Models/Traits/Active.php new file mode 100644 index 0000000..3a4d0b5 --- /dev/null +++ b/app/Models/Traits/Active.php @@ -0,0 +1,23 @@ +where($this->getActiveColumnName(), '=', true); + } + + public function scopeInactive(Builder $query): Builder + { + return $query->where($this->getActiveColumnName(), '=', false); + } + + protected function getActiveColumnName(): string + { + return 'is_active'; + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 9d5ccdf..5b5df38 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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 */ 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, diff --git a/app/Services/Pacs/OrthancRestClient.php b/app/Services/Pacs/OrthancRestClient.php index 90d5478..a89419b 100644 --- a/app/Services/Pacs/OrthancRestClient.php +++ b/app/Services/Pacs/OrthancRestClient.php @@ -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([ diff --git a/app/Services/Pacs/Sync/StudiesSync.php b/app/Services/Pacs/Sync/StudiesSync.php index f505e6f..1cbea05 100644 --- a/app/Services/Pacs/Sync/StudiesSync.php +++ b/app/Services/Pacs/Sync/StudiesSync.php @@ -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, diff --git a/database/migrations/2024_12_27_060234_create_studies_table.php b/database/migrations/2024_12_27_060234_create_studies_table.php index 6df7070..320ca58 100644 --- a/database/migrations/2024_12_27_060234_create_studies_table.php +++ b/database/migrations/2024_12_27_060234_create_studies_table.php @@ -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);