diff --git a/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php b/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php index 6629cd63b..135c9fafb 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php +++ b/src/Bundle/ChillPersonBundle/Actions/Upsert/Handler/PersonUpsertHandler.php @@ -16,7 +16,9 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Gender; use Chill\MainBundle\Entity\GenderEnum; use Chill\MainBundle\Repository\CenterRepositoryInterface; +use Chill\MainBundle\Repository\CountryRepository; use Chill\MainBundle\Repository\GenderRepository; +use Chill\MainBundle\Repository\LanguageRepository; use Chill\MainBundle\Repository\PostalCodeRepositoryInterface; use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Household\MembersEditorFactory; @@ -25,6 +27,7 @@ use Chill\PersonBundle\Repository\Identifier\PersonIdentifierDefinitionRepositor use Chill\PersonBundle\Repository\Identifier\PersonIdentifierRepository; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Identifier\PersonIdentifier; +use Chill\PersonBundle\Entity\PersonPhone; use Chill\PersonBundle\Actions\Upsert\UpsertMessage; use libphonenumber\NumberParseException; use Psr\Log\LoggerInterface; @@ -46,6 +49,8 @@ readonly class PersonUpsertHandler private MembersEditorFactory $membersEditorFactory, private PostalCodeRepositoryInterface $postalCodeRepository, private CenterRepositoryInterface $centerRepository, + private CountryRepository $countryRepository, + private LanguageRepository $languageRepository, private GenderRepository $genderRepository, private ClockInterface $clock, private \libphonenumber\PhoneNumberUtil $phoneNumberUtil, @@ -204,6 +209,63 @@ readonly class PersonUpsertHandler $person->setCenter($center); } + // Handle countryOfBirth + if (null !== $message->countryOfBirth) { + $country = $this->countryRepository->findOneBy(['countryCode' => $message->countryOfBirth]); + if (null !== $country) { + $person->setCountryOfBirth($country); + } else { + $this->logger->warning(self::LOG_PREFIX.'Country not found for code: '.$message->countryOfBirth); + } + } + + // Handle placeOfBirth + if (null !== $message->placeOfBirth) { + $person->setPlaceOfBirth($message->placeOfBirth); + } + + // Handle deathdate + if (null !== $message->deathdate) { + try { + $person->setDeathdate(new \DateTimeImmutable($message->deathdate)); + } catch (\Exception $e) { + $this->logger->error(self::LOG_PREFIX.'Could not parse deathdate: '.$message->deathdate, [ + 'exception' => $e->getTraceAsString(), + 'deathdate' => $message->deathdate, + ]); + } + } + + // Handle spokenLanguages + if (null !== $message->spokenLanguages && [] !== $message->spokenLanguages) { + foreach ($message->spokenLanguages as $languageCode) { + $language = $this->languageRepository->findOneBy(['id' => $languageCode]); + if (null !== $language) { + $person->addSpokenLanguage($language); + } else { + $this->logger->warning(self::LOG_PREFIX.'Language not found for code: '.$languageCode); + } + } + } + + // Handle otherPhoneNumbers + if (null !== $message->otherPhoneNumbers && [] !== $message->otherPhoneNumbers) { + foreach ($message->otherPhoneNumbers as $phoneNumber) { + try { + $parsedNumber = $this->phoneNumberUtil->parse($phoneNumber); + $personPhone = new PersonPhone(); + $personPhone->setPhonenumber($parsedNumber); + $person->addOtherPhoneNumber($personPhone); + $this->entityManager->persist($personPhone); + } catch (NumberParseException $e) { + $this->logger->warning(self::LOG_PREFIX.'Could not parse otherPhoneNumber', [ + 'exception' => $e->getTraceAsString(), + 'phoneNumber' => $phoneNumber, + ]); + } + } + } + // mobileNumber and phoneNumber if (null !== $message->phoneNumber) { try { diff --git a/src/Bundle/ChillPersonBundle/Actions/Upsert/UpsertMessage.php b/src/Bundle/ChillPersonBundle/Actions/Upsert/UpsertMessage.php index 09f95fd44..cf03c17ca 100644 --- a/src/Bundle/ChillPersonBundle/Actions/Upsert/UpsertMessage.php +++ b/src/Bundle/ChillPersonBundle/Actions/Upsert/UpsertMessage.php @@ -14,7 +14,7 @@ namespace Chill\PersonBundle\Actions\Upsert; class UpsertMessage { public string $externalId; - public string $moreExternalIds; + public ?array $moreExternalIds = []; public int $personIdentifierDefinitionId; public ?string $firstName = null; public ?string $lastName = null;