diff --git a/.changes/unreleased/Feature-20240207-114629.yaml b/.changes/unreleased/Feature-20240207-114629.yaml new file mode 100644 index 000000000..813d14ba7 --- /dev/null +++ b/.changes/unreleased/Feature-20240207-114629.yaml @@ -0,0 +1,5 @@ +kind: Feature +body: 'Export: add filter for courses not linked to a reference address' +time: 2024-02-07T11:46:29.491027007+01:00 +custom: + Issue: "243" diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/NotAssociatedWithAReferenceAddressFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/NotAssociatedWithAReferenceAddressFilter.php new file mode 100644 index 000000000..72197234c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/NotAssociatedWithAReferenceAddressFilter.php @@ -0,0 +1,99 @@ +add('date_calc', PickRollingDateType::class, [ + 'label' => 'export.filter.course.not_having_address_reference.adress_at', + ]); + } + + public function getFormDefaultData(): array + { + return [ + 'date_calc' => new RollingDate(RollingDate::T_TODAY), + ]; + } + + public function describeAction($data, $format = 'string') + { + return [ + 'exports.filter.course.not_having_address_reference.describe', + [ + 'date_calc' => $this->rollingDateConverter->convert($data['date_calc']), + ], + ]; + } + + public function addRole(): ?string + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $k = 'acp_not_associated_ref_filter'; + + $qb + ->leftJoin( + 'acp.locationHistories', + $k, + Join::WITH, + "{$k}.period = acp AND {$k}.startDate <= :{$k}_date_calc AND ({$k}.endDate IS NULL OR {$k}.endDate > :{$k}_date_calc)" + ) + ->leftJoin( + PersonHouseholdAddress::class, + "{$k}_p_address", + Join::WITH, + "{$k}.personLocation = {$k}_p_address.person AND {$k}_p_address.validFrom <= :{$k}_date_calc AND ({$k}_p_address.validTo IS NULL OR {$k}_p_address.validTo > :{$k}_date_calc)" + ) + ->join( + Address::class, + "{$k}_address", + Join::WITH, + "{$k}_address.id = COALESCE(IDENTITY({$k}_p_address.address), IDENTITY({$k}.addressLocation))" + ) + ; + + $qb->andWhere("{$k}_address.addressReference IS NULL"); + $qb->setParameter("{$k}_date_calc", $this->rollingDateConverter->convert($data['date_calc'])); + } + + public function applyOn() + { + return Declarations::ACP_TYPE; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/NotAssociatedWithAReferenceAddressFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/NotAssociatedWithAReferenceAddressFilterTest.php new file mode 100644 index 000000000..c71088159 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/NotAssociatedWithAReferenceAddressFilterTest.php @@ -0,0 +1,66 @@ + new RollingDate(RollingDate::T_TODAY)], + ]; + } + + public function getQueryBuilders() + { + self::bootKernel(); + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->select('acp.id') + ->from(AccompanyingPeriod::class, 'acp'), + ]; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index c869a4494..38b5d5041 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -147,6 +147,10 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_info_within_filter } + Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\NotAssociatedWithAReferenceAddressFilter: + tags: + - { name: chill.export_filter, alias: accompanyingcourse_not_having_addr_reference_filter } + ## Aggregators chill.person.export.aggregator_referrer_scope: class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ScopeAggregator diff --git a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml index a8d2080fb..af85b2217 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml @@ -140,6 +140,11 @@ exports: by_treating_agent: Filtered by treating agent at date: >- Les agents traitant au { agent_at, date, medium }, seulement {agents} + course: + not_having_address_reference: + describe: >- + Uniquement les parcours qui ne sont pas localisés à une adresse de référence, à la date du {date_calc, date, medium} + 'total persons matching the search pattern': >- { total, plural, =0 {Aucun usager ne correspond aux termes de recherche} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 3e8a73956..ec6036950 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1153,6 +1153,9 @@ export: 'Filtered by participations during period: between %dateafter% and %datebefore%': 'Filtré par personne concerné par un parcours dans la periode entre: %dateafter% et %datebefore%' course: + not_having_address_reference: + title: Filtrer les parcours non localisés à une adresse de réference + adress_at: Adresse à la date du having_info_within_interval: title: Filtrer les parcours ayant reçu une intervention entre deux dates start_date: Début de la période