Skip to content

Commit

Permalink
Add xslx export with lab data for easier reviewing data in FAST
Browse files Browse the repository at this point in the history
  • Loading branch information
lsamshuijzen committed Jan 7, 2025
1 parent 705a35d commit e239aac
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app/Exports/LabExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Exports;

use App\Models\Laboratory;
use App\Models\MappingLog;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class LabExport implements FromCollection, WithHeadings, WithMapping
{

public function __construct()
{

}

/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return Laboratory::get();
}

public function headings(): array
{
return [
'fast_id',
'name',
'latitude',
'longitude'
];
}

public function map($laboratory): array
{
return [
$laboratory->fast_id,
$laboratory->name,
$laboratory->latitude,
$laboratory->longitude
];
}

}
7 changes: 7 additions & 0 deletions app/Http/Controllers/LabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
use App\Models\LaboratoryUpdateGroupFast;
use App\Jobs\ProcessLaboratoryUpdateGroupFast;
use App\Exports\epos\RegistryExport;
use App\Exports\LabExport;
use App\Jobs\ProcessFastVocabularyUpdate;
use App\Models\LaboratoryOrganization;
use App\Models\LaboratoryOrganizationUpdateGroupRor;
use App\Jobs\ProcessLaboratoryOrganizationUpdateGroupRor;
use App\Jobs\ProcessLaboratoryKeywordUpdateGroup;
use App\Models\Laboratory;
use Maatwebsite\Excel\Facades\Excel;

class LabController extends Controller
{
Expand All @@ -36,6 +38,11 @@ public function viewLabData()

return view('admin.laboratories', ['laboratories' => $laboratories]);
}

public function downloadLabData()
{
return Excel::download(new LabExport(), 'labs.xlsx');
}

public function updateFastData(Request $request)
{
Expand Down
2 changes: 2 additions & 0 deletions resources/views/admin/laboratories.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
@else
<p>No laboratories found</p>
@endif

<a href="{{ route('download-lab-data') }}" class="btn btn-primary">Download Excel file</a>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
Route::get('labs/update-organizations-data', [LabController::class, 'updateLaboratoryOrganizationsByROR'])->name('update-lab-organizations-data');
Route::get('labs/update-laboratory-keywords', [LabController::class, 'updateLaboratoryKeywords'])->name('update-laboratory-keywords');
Route::get('labs/registry-turtle', [LabController::class, 'registryTurtle'])->name('registry-turtle');
Route::get('labs/download', [LabController::class, 'downloadLabData'])->name('download-lab-data');

Route::post('/create-import', [HomeController::class, 'createImport'])->name('create-import');
Route::get('/imports', [HomeController::class, 'imports'])->name('imports');
Expand Down

0 comments on commit e239aac

Please sign in to comment.