From e5c06ce3715b53dbae3916aa19a821cf230ad790 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 25 May 2023 10:40:41 +0300 Subject: [PATCH 1/2] Avoiding TypeError or wrong CPR code of the child --- .../ServiceplatformenCPRExtended.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php index 28f60fc..bfd91c9 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php @@ -122,13 +122,20 @@ public function lookup($cpr, $allowCprTestModeReplace = TRUE) { $relationship->barn = [$relationship->barn]; } - foreach ($relationship->barn as $child) { - $childCprResult = $this->lookup($child->personnummer, FALSE); - - $children[] = [ - 'cpr' => $childCprResult->getCpr(), - 'name' => $childCprResult->getName(), + foreach ($relationship->barn as $relationshipChild) { + // Sometimes CPR lookup can return no results, creating child without + // name. + $child = [ + 'cpr' => $relationshipChild->personnummer, + 'name' => '', ]; + + $childCprResult = $this->lookup($relationshipChild->personnummer, FALSE); + if ($childCprResult->isSuccessful()) { + $child['name'] = $childCprResult->getName(); + } + + $children[] = $child; } } $cprResult->setChildren($children); From ae8cb5aa53b24f94aa1643ea8135a9b4dcbd8bb1 Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Thu, 1 Jun 2023 11:27:57 +0300 Subject: [PATCH 2/2] OS-53 CPR full address --- .../ServiceplatformenCPRExtended.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php index bfd91c9..3c20f03 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php @@ -111,7 +111,23 @@ public function lookup($cpr, $allowCprTestModeReplace = TRUE) { $cprResult->setPostalCode($address->aktuelAdresse->postnummer ?? ''); $cprResult->setCity($address->aktuelAdresse->postdistrikt ?? ''); $cprResult->setMunicipalityCode($address->aktuelAdresse->kommunekode ?? ''); - $cprResult->setAddress($address->aktuelAdresse->standardadresse ?? ''); + + // Composing full address in one line. + $address = $cprResult->getStreet(); + if ($cprResult->getHouseNr()) { + $address .= ' ' . $cprResult->getHouseNr(); + } + if ($cprResult->getFloor()) { + $address .= ' ' . $cprResult->getFloor(); + } + if ($cprResult->getApartmentNr()) { + $address .= ' ' . $cprResult->getApartmentNr(); + } + if ($cprResult->getPostalCode() && $cprResult->getCity()) { + $address .= ', ' . $cprResult->getPostalCode() . ' ' . $cprResult->getCity(); + } + + $cprResult->setAddress($address ?? ''); } $relationship = $result['relationer'];