From e8af1813ca004735fd27f3c071345a82abb7ce9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Thu, 24 Oct 2024 07:58:07 +0100 Subject: [PATCH] fixes (#331) * fix: Undefined array key "suffix" * fix: ambiguous column aggregate * fix: data truncated for column 'initiator' --- app/Exports/Sheets/ReportStatisticSheet.php | 2 +- .../Nurse/GenerateStatisticReportJob.php | 4 +--- app/Reports/Queries/Child/C21.php | 5 +++++ app/Reports/Queries/General/G11.php | 5 +++++ app/Reports/Queries/General/G27.php | 5 +++++ app/Reports/Queries/General/G28.php | 5 +++++ app/Reports/Queries/Pregnant/P12.php | 5 +++++ app/Reports/Queries/ReportQuery.php | 12 +++++++++++ ...n_type_in_interventionable_cases_table.php | 20 +++++++++++++++++++ 9 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2024_10_24_074306_change_initiator_column_type_in_interventionable_cases_table.php diff --git a/app/Exports/Sheets/ReportStatisticSheet.php b/app/Exports/Sheets/ReportStatisticSheet.php index 003c9712..3bde1ea4 100644 --- a/app/Exports/Sheets/ReportStatisticSheet.php +++ b/app/Exports/Sheets/ReportStatisticSheet.php @@ -42,7 +42,7 @@ public function headings(): array ->map(function (array $column) { $label = $column['label']; - if (filled($column['suffix'])) { + if (filled(data_get($column, 'suffix'))) { $label .= "\n({$column['suffix']})"; } diff --git a/app/Jobs/GenerateReport/Standard/Nurse/GenerateStatisticReportJob.php b/app/Jobs/GenerateReport/Standard/Nurse/GenerateStatisticReportJob.php index 6cfe9cea..1e239192 100644 --- a/app/Jobs/GenerateReport/Standard/Nurse/GenerateStatisticReportJob.php +++ b/app/Jobs/GenerateReport/Standard/Nurse/GenerateStatisticReportJob.php @@ -22,9 +22,7 @@ public function generate(): void return [ $indicator->label() => [ - $reportQuery::build($this->report) - ->distinct('id') - ->count('id'), + $reportQuery::aggregate($this->report), ], ]; }), diff --git a/app/Reports/Queries/Child/C21.php b/app/Reports/Queries/Child/C21.php index 11ed2550..5608aa17 100644 --- a/app/Reports/Queries/Child/C21.php +++ b/app/Reports/Queries/Child/C21.php @@ -28,6 +28,11 @@ public static function dateColumn(): string return 'interventionable_individual_services.date'; } + public static function aggregateByColumn(): string + { + return 'interventions.id'; + } + public static function columns(): array { return [ diff --git a/app/Reports/Queries/General/G11.php b/app/Reports/Queries/General/G11.php index f5c7d8b1..fed6298a 100644 --- a/app/Reports/Queries/General/G11.php +++ b/app/Reports/Queries/General/G11.php @@ -29,6 +29,11 @@ public static function dateColumn(): string return 'interventionable_individual_services.date'; } + public static function aggregateByColumn(): string + { + return 'interventions.id'; + } + public static function columns(): array { return [ diff --git a/app/Reports/Queries/General/G27.php b/app/Reports/Queries/General/G27.php index 2dfa4f60..0b2580af 100644 --- a/app/Reports/Queries/General/G27.php +++ b/app/Reports/Queries/General/G27.php @@ -29,6 +29,11 @@ public static function dateColumn(): string return 'interventionable_individual_services.date'; } + public static function aggregateByColumn(): string + { + return 'interventions.id'; + } + public static function columns(): array { return [ diff --git a/app/Reports/Queries/General/G28.php b/app/Reports/Queries/General/G28.php index 8c1c838d..d839c57b 100644 --- a/app/Reports/Queries/General/G28.php +++ b/app/Reports/Queries/General/G28.php @@ -29,6 +29,11 @@ public static function dateColumn(): string return 'interventionable_individual_services.date'; } + public static function aggregateByColumn(): string + { + return 'interventions.id'; + } + public static function columns(): array { return [ diff --git a/app/Reports/Queries/Pregnant/P12.php b/app/Reports/Queries/Pregnant/P12.php index 44523580..899f4ae5 100644 --- a/app/Reports/Queries/Pregnant/P12.php +++ b/app/Reports/Queries/Pregnant/P12.php @@ -28,6 +28,11 @@ public static function dateColumn(): string return 'interventionable_individual_services.date'; } + public static function aggregateByColumn(): string + { + return 'interventions.id'; + } + public static function columns(): array { return [ diff --git a/app/Reports/Queries/ReportQuery.php b/app/Reports/Queries/ReportQuery.php index 03c6dd99..3f292ce7 100644 --- a/app/Reports/Queries/ReportQuery.php +++ b/app/Reports/Queries/ReportQuery.php @@ -18,6 +18,11 @@ public static function dateColumn(): string return 'beneficiaries.created_at'; } + public static function aggregateByColumn(): string + { + return 'id'; + } + public static function columns(): array { return [ @@ -83,4 +88,11 @@ public static function build(Report $report): Builder ->whereDate(static::dateColumn(), '>=', $report->date_from) ->whereDate(static::dateColumn(), '<=', $report->date_until); } + + public static function aggregate(Report $report): int + { + return static::build($report) + ->distinct(static::aggregateByColumn()) + ->count(static::aggregateByColumn()); + } } diff --git a/database/migrations/2024_10_24_074306_change_initiator_column_type_in_interventionable_cases_table.php b/database/migrations/2024_10_24_074306_change_initiator_column_type_in_interventionable_cases_table.php new file mode 100644 index 00000000..752d5ba0 --- /dev/null +++ b/database/migrations/2024_10_24_074306_change_initiator_column_type_in_interventionable_cases_table.php @@ -0,0 +1,20 @@ +string('initiator')->nullable()->change(); + }); + } +};