Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 4, 2024
1 parent 7e2cef7 commit 531cbff
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 34 deletions.
10 changes: 10 additions & 0 deletions app/Contracts/Enums/HasQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Contracts\Enums;

interface HasQuery
{
public function class(): string;
}
3 changes: 2 additions & 1 deletion app/Enums/Report/Standard/Indicators/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace App\Enums\Report\Standard\Indicators;

use App\Concerns;
use App\Contracts\Enums\HasQuery;

enum Child: string
enum Child: string implements HasQuery
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
Expand Down
3 changes: 2 additions & 1 deletion app/Enums/Report/Standard/Indicators/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace App\Enums\Report\Standard\Indicators;

use App\Concerns;
use App\Contracts\Enums\HasQuery;

enum General: string
enum General: string implements HasQuery
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
Expand Down
3 changes: 2 additions & 1 deletion app/Enums/Report/Standard/Indicators/Pregnant.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace App\Enums\Report\Standard\Indicators;

use App\Concerns;
use App\Contracts\Enums\HasQuery;

enum Pregnant: string
enum Pregnant: string implements HasQuery
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
Expand Down
3 changes: 2 additions & 1 deletion app/Enums/Report/Standard/Indicators/RareDisease.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace App\Enums\Report\Standard\Indicators;

use App\Concerns;
use App\Contracts\Enums\HasQuery;

enum RareDisease: string
enum RareDisease: string implements HasQuery
{
use Concerns\Enums\Arrayable;
use Concerns\Enums\Comparable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,26 @@ protected function getTableColumns(): array
->extraHeaderAttributes(['class' => 'w-1'])
->sortable(),

BadgeColumn::make('status')
->label(__('report.column.status'))
->enum(Status::options())
->colors(Status::flipColors())
->extraHeaderAttributes(['class' => 'w-1']),

TextColumn::make('type')
->label(__('report.column.type'))
->enum(Type::options())
->extraHeaderAttributes(['class' => 'w-1']),

TextColumn::make('period')
->label(__('report.column.period'))
->extraHeaderAttributes(['class' => 'w-1']),

TextColumn::make('category')
->label(__('report.column.category'))
->enum(Category::options())
->description(function (Report $record) {
// return $record->category->description;
}),

BadgeColumn::make('status')
->label(__('report.column.status'))
->enum(Status::options())
->colors(Status::flipColors()),

TextColumn::make('period')
->label(__('report.column.period')),
->description(fn (Report $record) => $record->indicators()->map->label()->join(', '))
->wrap(),
];
}

Expand All @@ -64,6 +65,10 @@ protected function getTableFilters(): array
->label(__('report.column.type'))
->options(Type::options()),

SelectFilter::make('category')
->label(__('report.column.category'))
->options(Category::options()),

DateRangeFilter::make('date_between'),
];
}
Expand All @@ -86,9 +91,4 @@ protected function getDefaultTableSortDirection(): ?string
{
return 'desc';
}

// protected function getTablePollingInterval(): ?string
// {
// return '5s';
// }
}
19 changes: 5 additions & 14 deletions app/Jobs/GenerateStandardReportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace App\Jobs;

use App\Contracts\Enums\HasQuery;
use App\Enums\Report\Standard\Category;
use App\Enums\Report\Standard\Indicators\General;
use App\Enums\Report\Status;
use App\Enums\Report\Type;
use App\Models\Report;
Expand Down Expand Up @@ -79,14 +79,8 @@ function () {

protected function handleList(): void
{
$indicators = $this->indicators
->map(fn ($indicator) => $this->getCategory()->indicators()::from($indicator))
->reject(fn (BackedEnum $indicator) => ! class_exists($indicator->class()));

$this->report->indicators = $indicators->map->label();

$this->report->data = $indicators
->map(function (General $indicator) {
$this->report->data = $this->report->indicators()
->map(function (HasQuery $indicator) {
/** @var ReportQuery $reportQuery */
$reportQuery = $indicator->class();

Expand Down Expand Up @@ -128,14 +122,11 @@ protected function handleList(): void

protected function handleStatistic(): void
{
$indicators = collect($this->getCategory()->indicators()::cases())
->reject(fn (BackedEnum $indicator) => ! class_exists($indicator->class()));

$this->report->data = [
[
'title' => $this->getCategory()->label(),
'data' => $indicators
->mapWithKeys(function (BackedEnum $indicator) {
'data' => $this->getIndicators()
->mapWithKeys(function (HasQuery $indicator) {
/** @var ReportQuery $reportQuery */
$reportQuery = $indicator->class();

Expand Down
9 changes: 9 additions & 0 deletions app/Models/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Contracts\Enums\HasQuery;
use App\Enums\Report\Standard\Category;
use App\Enums\Report\Status;
use App\Enums\Report\Type;
Expand All @@ -14,6 +15,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

class Report extends Model
{
Expand Down Expand Up @@ -110,4 +112,11 @@ public function isFailed(): bool
{
return $this->status->is(Status::FAILED);
}

public function indicators(): Collection
{
return $this->indicators
->map(fn (string $indicator) => $this->category->indicators()::from($indicator))
->reject(fn (HasQuery $indicator) => ! class_exists($indicator->class()));
}
}

0 comments on commit 531cbff

Please sign in to comment.