Add supplementaryComments property to Motive entity, update fixtures and types

This commit is contained in:
Julien Fastré 2025-07-11 15:46:08 +02:00
parent c5e6122d2c
commit 2bd303bbbe
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
5 changed files with 120 additions and 44 deletions

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\TicketBundle\DataFixtures\ORM;
use Chill\TicketBundle\Entity\EmergencyStatusEnum;
use Chill\TicketBundle\Entity\Motive;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
@ -25,58 +26,73 @@ final class LoadMotives extends Fixture implements FixtureGroupInterface
public function load(ObjectManager $manager)
{
foreach (explode("\n", self::MOTIVES) as $label) {
if ('' === trim($label)) {
foreach (explode("\n", self::MOTIVES) as $row) {
if ('' === trim($row)) {
continue;
}
$data = str_getcsv($row);
if ('' === $data[0]) {
continue;
}
$motive = new Motive();
$motive->setLabel(['fr' => trim($label)]);
$motive->setLabel(['fr' => trim((string) $data[0])]);
$motive->setMakeTicketEmergency(match ($data[1]) {
'true' => EmergencyStatusEnum::YES,
'false' => EmergencyStatusEnum::NO,
default => throw new \UnexpectedValueException('Unexpected value'),
});
foreach (array_slice($data, 2) as $supplementaryComment) {
if ('' !== trim((string) $supplementaryComment)) {
$motive->addSupplementaryComment(['label' => trim((string) $supplementaryComment)]);
}
}
$manager->persist($motive);
}
$manager->flush();
}
private const MOTIVES = <<<'TXT'
Coordonnées
Horaire de passage
Retard de livraison
Erreur de livraison
Colis incomplet
MATLOC
Retard DASRI
Planning d'astreintes
Planning des tournées
Contrôle pompe
Changement de rendez-vous
Renseignement facturation/prestation
Décès patient
Demande de prise en charge
Information absence
Demande bulletin de situation
Difficultés accès logement
Déplacement inutile
Problème de prélèvement/de commande
Parc auto
Demande d'admission
Retrait de matériel au domicile
Comptes-rendus
Démarchage commercial
Demande de transport
Demande laboratoire
Demande admission
Suivi de prise en charge
Mauvaise adresse
Patient absent
Annulation
Colis perdu
Changement de rendez-vous
Coordination interservices
Problème de substitution produits
Problème ordonnance
Réclamations facture
Préparation urgente
TXT;
private const MOTIVES = <<<'CSV'
"Coordonnées",false,"Nouvelles coordonnées",
"Horaire de passage",false,
"Retard de livraison",false,
"Erreur de livraison",false,
"Colis incomplet",false,
"MATLOC",false,
"Retard DASRI",false,
"Planning d'astreintes",false,
"Planning des tournées",false,
"Contrôle pompe",true,
"Changement de rendez-vous",false,"Date du nouveau rendez-vous","Lieu du nouveau rendez-vous",
"Renseignement facturation/prestation",false,
"Décès patient",false,"Date et heures du décès","Autorisation préalable du médecin pour le décès",
"Demande de prise en charge",false,
"Information absence",false,
"Demande bulletin de situation",false,
"Difficultés accès logement",false,
"Déplacement inutile",false,
"Problème de prélèvement/de commande",false,
"Parc auto",false,
"Demande d'admission",false,
"Retrait de matériel au domicile",false,
"Comptes-rendus",false,
"Démarchage commercial",false,
"Demande de transport",false,
"Demande laboratoire",false,
"Demande admission",false,
"Suivi de prise en charge",false,
"Mauvaise adresse",false,
"Patient absent",false,
"Annulation",false,
"Colis perdu",false,
"Changement de rendez-vous",false,
"Coordination interservices",false,
"Problème de substitution produits",true,
"Problème ordonnance",false,
"Réclamations facture",false,"Numéro de facture concerné",
"Préparation urgente",true,
CSV;
}

View File

@ -37,6 +37,10 @@ class Motive
#[Serializer\Groups(['read'])]
private ?EmergencyStatusEnum $makeTicketEmergency = null;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['jsonb' => true, 'default' => '[]'])]
#[Serializer\Groups(['read'])]
private array $supplementaryComments = [];
public function isActive(): bool
{
return $this->active;
@ -76,4 +80,22 @@ class Motive
{
return null !== $this->makeTicketEmergency;
}
/**
* Get the supplementary comments.
*
* @return array<array{label: string}>
*/
public function getSupplementaryComments(): array
{
return $this->supplementaryComments;
}
/**
* @param array{label: string} $supplementaryComments
*/
public function addSupplementaryComment(array $supplementaryComments): void
{
$this->supplementaryComments[] = $supplementaryComments;
}
}

View File

@ -55,6 +55,9 @@ export interface Comment {
updatedBy: User | null;
updatedAt: DateTime | null;
deleted: boolean;
supplementaryComments: {
label: string;
};
}
export interface AddresseeHistory {

View File

@ -0,0 +1,33 @@
<?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\Migrations\Ticket;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250711131126 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add supplementaryComments property to Motive entity as JSONB type to store list of comments with label';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_ticket.motive ADD supplementaryComments JSONB DEFAULT \'[]\' NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_ticket.motive DROP supplementaryComments');
}
}

View File

@ -99,6 +99,8 @@ class ReplaceMotiveControllerTest extends KernelTestCase
$entityManager->flush()->shouldBeCalled();
$changeEmergencyCommandHandler = $this->prophesize(ChangeEmergencyStateCommandHandler::class);
$changeEmergencyCommandHandler->__invoke(Argument::any(), Argument::any())->shouldBeCalled()
->will(fn (array $args) => $args[0]);
$handler = new ReplaceMotiveCommandHandler(
new MockClock(),