[export] add a grouping of accompanying period by opening and closing date

This commit is contained in:
Julien Fastré 2023-10-18 11:46:15 +02:00
parent c7bd60a106
commit f799fe0649
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
9 changed files with 354 additions and 1 deletions

View File

@ -0,0 +1,6 @@
kind: Feature
body: '[export] Add a filter "grouping accompanying period by opening date" and "trouping
accompanying period by closing date"'
time: 2023-10-18T11:38:25.80362952+02:00
custom:
Issue: "172"

View File

@ -73,7 +73,6 @@ class DateAggregator implements AggregatorInterface
'choices' => self::CHOICES,
'multiple' => false,
'expanded' => true,
'empty_data' => self::DEFAULT_CHOICE,
]);
}

View File

@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Enum\DateGroupingChoiceEnum;
use Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators\ClosingDateAggregatorTest;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @see ClosingDateAggregatorTest
*/
final readonly class ClosingDateAggregator implements AggregatorInterface
{
private const PREFIX = 'acp_closing_date_agg';
public function buildForm(FormBuilderInterface $builder): void
{
$builder->add('frequency', ChoiceType::class, [
'choices' => array_combine(
array_map(fn (DateGroupingChoiceEnum $c) => 'export.enum.frequency.'.$c->value, DateGroupingChoiceEnum::cases()),
array_map(fn (DateGroupingChoiceEnum $c) => $c->value, DateGroupingChoiceEnum::cases()),
),
'label' => 'export.aggregator.course.by_closing_date.frequency',
'multiple' => false,
'expanded' => true,
]);
}
public function getFormDefaultData(): array
{
return [
'frequency' => 'year',
];
}
public function getLabels($key, array $values, mixed $data)
{
return function (null|string $value): string {
if ('_header' === $value) {
return 'export.aggregator.course.by_closing_date.header';
}
return (string) $value;
};
}
public function getQueryKeys($data)
{
return [self::PREFIX.'_closing_date'];
}
public function getTitle()
{
return 'export.aggregator.course.by_closing_date.title';
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$p = self::PREFIX;
$qb->addSelect(sprintf("TO_CHAR(acp.closingDate, '%s') AS {$p}_closing_date", $data['frequency']));
$qb->addGroupBy("{$p}_closing_date");
$qb->addOrderBy("{$p}_closing_date", 'DESC');
}
public function applyOn()
{
return Declarations::ACP_TYPE;
}
}

View File

@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Export\Enum\DateGroupingChoiceEnum;
use Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators\OpeningDateAggregatorTest;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @see OpeningDateAggregatorTest
*/
final readonly class OpeningDateAggregator implements AggregatorInterface
{
private const PREFIX = 'acp_opening_date_agg';
public function buildForm(FormBuilderInterface $builder): void
{
$builder->add('frequency', ChoiceType::class, [
'choices' => array_combine(
array_map(fn (DateGroupingChoiceEnum $c) => 'export.enum.frequency.'.$c->value, DateGroupingChoiceEnum::cases()),
array_map(fn (DateGroupingChoiceEnum $c) => $c->value, DateGroupingChoiceEnum::cases()),
),
'label' => 'export.aggregator.course.by_opening_date.frequency',
'multiple' => false,
'expanded' => true,
]);
}
public function getFormDefaultData(): array
{
return [
'frequency' => 'year',
];
}
public function getLabels($key, array $values, mixed $data)
{
return function (null|string $value): string {
if ('_header' === $value) {
return 'export.aggregator.course.by_opening_date.header';
}
return (string) $value;
};
}
public function getQueryKeys($data)
{
return [self::PREFIX.'_opening_date'];
}
public function getTitle()
{
return 'export.aggregator.course.by_opening_date.title';
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$p = self::PREFIX;
$qb->addSelect(sprintf("TO_CHAR(acp.openingDate, '%s') AS {$p}_opening_date", $data['frequency']));
$qb->addGroupBy("{$p}_opening_date");
$qb->addOrderBy("{$p}_opening_date", 'DESC');
}
public function applyOn()
{
return Declarations::ACP_TYPE;
}
}

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Export\Enum;
enum DateGroupingChoiceEnum: string
{
case MONTH = 'YYYY-MM';
case WEEK = 'YYYY-IW';
case YEAR = 'YYYY';
}

View File

@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ClosingDateAggregator;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class ClosingDateAggregatorTest extends AbstractAggregatorTest
{
private static ClosingDateAggregator $closingDateAggregator;
private static EntityManagerInterface $entityManager;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::bootKernel();
self::$closingDateAggregator = self::$container->get(ClosingDateAggregator::class);
self::$entityManager = self::$container->get(EntityManagerInterface::class);
}
public function getAggregator()
{
return self::$closingDateAggregator;
}
public function getFormData()
{
yield ['frequency' => 'YYYY'];
yield ['frequency' => 'YYYY-MM'];
yield ['frequency' => 'YYYY-IV'];
}
public function getQueryBuilders()
{
self::bootKernel();
self::$entityManager = self::$container->get(EntityManagerInterface::class);
$data = [
self::$entityManager->createQueryBuilder()
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp'),
];
self::ensureKernelShutdown();
return $data;
}
}

View File

@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\OpeningDateAggregator;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class OpeningDateAggregatorTest extends AbstractAggregatorTest
{
private static OpeningDateAggregator $openingDateAggregator;
private static EntityManagerInterface $entityManager;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::bootKernel();
self::$openingDateAggregator = self::$container->get(OpeningDateAggregator::class);
self::$entityManager = self::$container->get(EntityManagerInterface::class);
}
public function getAggregator()
{
return self::$openingDateAggregator;
}
public function getFormData()
{
yield ['frequency' => 'YYYY'];
yield ['frequency' => 'YYYY-MM'];
yield ['frequency' => 'YYYY-IV'];
}
public function getQueryBuilders()
{
self::bootKernel();
self::$entityManager = self::$container->get(EntityManagerInterface::class);
$data = [
self::$entityManager->createQueryBuilder()
->select('count(acp.id)')
->from(AccompanyingPeriod::class, 'acp'),
];
self::ensureKernelShutdown();
return $data;
}
}

View File

@ -251,3 +251,11 @@ services:
Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ScopeWorkingOnCourseAggregator:
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_scope_working_on_course_aggregator }
Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\OpeningDateAggregator:
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_opening_date_aggregator }
Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ClosingDateAggregator:
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_closing_date_aggregator }

View File

@ -981,6 +981,11 @@ notification:
personId: Identifiant de l'usager
export:
enum:
frequency:
YYYY-IW: par semaine
YYYY-MM: par mois
YYYY: par année
export:
acp_stats:
avg_duration: Moyenne de la durée de participation de chaque usager concerné
@ -1037,6 +1042,14 @@ export:
Calc date: Date de calcul du service de l'intervenant
by_scope:
Group course by scope: Grouper les parcours par service
by_opening_date:
title: Grouper les parcours par date d'ouverture
frequency: Intervalle de regroupement
header: Date d'ouverture des parcours (période)
by_closing_date:
title: Grouper les parcours par date de cloture
frequency: Intervalle de regroupement
header: Date de cloture des parcours (période)
course_work:
by_treating_agent: