Skip to content

Commit c8e880e

Browse files
committed
add mediator-specific services
1 parent ec98c4b commit c8e880e

4 files changed

Lines changed: 51 additions & 2 deletions

File tree

app/Imports/ServicesImport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public function collection(Collection $rows): void
2020
$this->importCategories($rows);
2121

2222
Service::upsert(
23-
$rows->map(fn (Collection $row) => [
23+
$rows->map(fn (Collection $row): array => [
2424
'code' => $row['code'],
2525
'name' => $this->normalize($row['name']),
2626
'category_id' => $this->categories->get($this->normalize($row['category'])),
2727
])->toArray(),
28-
'id'
28+
'code'
2929
);
3030
}
3131

app/Models/Service/Service.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ class Service extends Model implements Stringable
1818

1919
protected $casts = [
2020
'is_enabled' => 'boolean',
21+
'is_mediator_only' => 'boolean',
2122
];
2223

24+
public static function booted()
25+
{
26+
static::addGlobalScope('forCurrentUser', function (Builder $builder): void {
27+
if (auth()->user()?->isNurse()) {
28+
$builder->where('is_mediator_only', false);
29+
}
30+
});
31+
}
32+
2333
public function category(): BelongsTo
2434
{
2535
return $this->belongsTo(ServiceCategory::class);
10.9 KB
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\Imports\ServicesImport;
6+
use App\Models\Service\Service;
7+
use Illuminate\Database\Migrations\Migration;
8+
use Illuminate\Database\Schema\Blueprint;
9+
use Illuminate\Support\Facades\Schema;
10+
use Maatwebsite\Excel\Facades\Excel;
11+
12+
return new class extends Migration
13+
{
14+
/**
15+
* Run the migrations.
16+
*/
17+
public function up(): void
18+
{
19+
Schema::table('services', function (Blueprint $table) {
20+
$table->boolean('is_mediator_only')->default(false);
21+
22+
$table->unique('code');
23+
});
24+
25+
Excel::import(new ServicesImport, database_path('data/260630-mediator-services.xlsx'));
26+
27+
Service::query()
28+
->whereIn('code', [
29+
'SIO_02', 'SIO_03',
30+
'SES_15', 'SES_16', 'SES_17', 'SES_18',
31+
'SID_01', 'SID_02', 'SID_03',
32+
'SNF_12', 'SNF_13', 'SNF_14', 'SNF_15',
33+
'SSN_08', 'SSN_09', 'SSN_10', 'SSN_11', 'SSN_12', 'SSN_13', 'SSN_14',
34+
])
35+
->update([
36+
'is_mediator_only' => true,
37+
]);
38+
}
39+
};

0 commit comments

Comments
 (0)