Skip to content

Commit 68f0f41

Browse files
committed
command to import legacy descriptions
1 parent e176daa commit 68f0f41

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use App\Modules\Group\Models\Group;
7+
use App\Modules\ExpertPanel\Models\ExpertPanel;
8+
use App\Modules\Group\Events\GroupDescriptionUpdated;
9+
use Illuminate\Support\Facades\Http;
10+
11+
class ImportLegacyWebsiteDescriptions extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'fixup:import-legacy-website-descriptions';
19+
20+
/**
21+
* The console command description.
22+
*
23+
* @var string
24+
*/
25+
protected $description = 'Get the (pre-Feb-2025) website descriptions from the old website and import them into group->description fields.';
26+
27+
/**
28+
* Execute the console command.
29+
*/
30+
public function handle()
31+
{
32+
$vcep_json = Http::get('https://clinicalgenome.org/data-pull/vceps/')->json();
33+
foreach ($vcep_json as $vcep) {
34+
$ep = ExpertPanel::findByAffiliationId($vcep['affiliation_id']);
35+
if (!$ep) {
36+
info('Expert Panel not found for ' . $vcep['affiliation_id']);
37+
continue;
38+
}
39+
if (!$ep->group->description) {
40+
$ep->group->description = $vcep['description'];
41+
event(new GroupDescriptionUpdated($ep->group, $vcep['description'], null));
42+
$ep->group->save();
43+
info('Imported group description for ' . $ep->group->name);
44+
} else {
45+
info('Group description already set for ' . $ep->group->name);
46+
}
47+
}
48+
49+
$gcep_json = Http::get('https://clinicalgenome.org/data-pull/gceps/')->json();
50+
foreach ($gcep_json as $gcep) {
51+
$ep = ExpertPanel::findByAffiliationId($gcep['affiliation_id']);
52+
if (!$ep) {
53+
info('Expert Panel not found for ' . $gcep['affiliation_id']);
54+
continue;
55+
}
56+
if (!$ep->group->description) {
57+
$ep->group->description = $gcep['description'];
58+
event(new GroupDescriptionUpdated($ep->group, $gcep['description'], null));
59+
$ep->group->save();
60+
info('Imported group description for ' . $ep->group->name);
61+
} else {
62+
info('Group description already set for ' . $ep->group->name);
63+
}
64+
}
65+
66+
$cdwg_json = Http::get('https://clinicalgenome.org/data-pull/cwdgs/')->json(); // NOTE: misspelled endpoint!
67+
foreach ($cdwg_json as $cdwg) {
68+
$group = Group::where('name', substr($cdwg['title'], 0, -5))->first(); // need to remove " CDWG" from the end of remote name
69+
if (!$group) {
70+
info('Group not found for ' . $cdwg['title']);
71+
continue;
72+
}
73+
if (!$group->description) {
74+
$group->description = $cdwg['description'];
75+
event(new GroupDescriptionUpdated($group, $cdwg['description'], null));
76+
$group->save();
77+
info('Imported group description for ' . $group->name);
78+
} else {
79+
info('Group description already set for ' . $group->name);
80+
}
81+
}
82+
83+
$wg_json = Http::get('https://clinicalgenome.org/data-pull/wgs/')->json();
84+
foreach ($wg_json as $wg) {
85+
$group = Group::where('name', $wg['title'])->first();
86+
if (!$group) {
87+
info('Group not found for ' . $wg['title']);
88+
continue;
89+
}
90+
if (!$group->description) {
91+
$group->description = $wg['description'];
92+
event(new GroupDescriptionUpdated($group, $wg['description'], null));
93+
$group->save();
94+
info('Imported group description for ' . $group->name);
95+
} else {
96+
info('Group description already set for ' . $group->name);
97+
}
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)