Skip to content

Commit

Permalink
fix: vulnerabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 28, 2024
1 parent 9020670 commit a126d86
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/Reports/Queries/Pregnant/P03.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class P03 extends ReportQuery
{
/**
* Sum beneficiari with Gravidă adultă (VGR_04) OR Minoră gravidă (VGR_01); Femeie însărcinată care a efectuat consultaţii prenatale (VGR_98).
* Sum beneficiari with Gravidă adultă (VGR_04) OR Minoră gravidă (VGR_01); Femeie însărcinată care a efectuat consultaţii prenatale (VGR_96).
*/
public static function query(): Builder
{
Expand All @@ -22,7 +22,7 @@ public static function query(): Builder
$query->whereJsonOverlaps('properties', ['VGR_04', 'VGR_01']);
})
->whereHasCatagraphyRelation(Catagraphy::class, function (QueryBuilder $query) {
$query->whereJsonContains('properties->attributes->cat_preg', 'VGR_98');
$query->whereJsonContains('properties->attributes->cat_preg', 'VGR_96');
});
}
}
Binary file added database/data/241028-vulnerabilities.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('vulnerabilities', function (Blueprint $table) {
$table->boolean('is_valid')
->virtualAs(<<<'SQL'
CASE
WHEN id LIKE '%\\_9_' THEN 0
ELSE 1
END
SQL)
->change();
});
}
};
60 changes: 60 additions & 0 deletions database/migrations/2024_10_28_132539_update_vulnerabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

use App\Imports\VulnerabilitiesImport;
use App\Models\Activity;
use App\Models\Catagraphy;
use Carbon\Carbon;
use Illuminate\Database\Migrations\Migration;
use Maatwebsite\Excel\Facades\Excel;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Excel::import(new VulnerabilitiesImport, database_path('data/241028-vulnerabilities.xlsx'));

$cutoffDate = Carbon::parse('2024-10-24 00:00:00');

$callback = fn (string $preg) => $preg === 'VGR_98' ? 'VGR_96' : $preg;

// Catagraphy
// updated_at >= 2024-10-24 00:00:00
// cat_preg VGR_98 => VGR_96
Catagraphy::query()
->whereDate('updated_at', '>=', $cutoffDate)
->whereJsonContains('cat_preg', 'VGR_98')
->get()
->each(function (Catagraphy $catagraphy) use ($callback) {
$catagraphy->timestamps = false;

$catagraphy->updateQuietly([
'cat_preg' => collect($catagraphy->cat_preg)
->map($callback)
->all(),
]);
});

// Activity log `vulnerabilities`
// created_at >= 2024-10-24 00:00:00
// VGR_98 => VGR_96
Activity::query()
->where('created_at', '>=', $cutoffDate)
->where('log_name', 'vulnerabilities')
->whereJsonContains('properties', 'VGR_98')
->get()
->each(function (Activity $activity) use ($callback) {
$activity->timestamps = false;

$activity->updateQuietly([
'properties' => $activity->properties
->map($callback)
->all(),
]);
});
}
};

0 comments on commit a126d86

Please sign in to comment.