diff --git a/sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessor.java b/sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessor.java index beaa4e0eb02..74f141f2b50 100644 --- a/sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessor.java +++ b/sormas-backend/src/main/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessor.java @@ -15,6 +15,7 @@ package de.symeda.sormas.backend.externalmessage.labmessage; +import java.text.Collator; import java.util.List; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -316,5 +317,20 @@ private boolean unsetOrMatches(T personValue, T messageValue) { return personValue.equals(messageValue); } + + private boolean unsetOrMatches(String personValue, String messageValue) { + if (personValue == null || messageValue == null) { + return true; + } + + Collator collator = Collator.getInstance(); + collator.setStrength(Collator.PRIMARY); + + return collator.compare(normalizatString(personValue), normalizatString(messageValue)) == 0; + } + + private String normalizatString(String string) { + return string.replaceAll("[\\s-,;:]", ""); + } } } diff --git a/sormas-backend/src/test/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessorTest.java b/sormas-backend/src/test/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessorTest.java index 0a0ba4d7f90..e3e22f325c7 100644 --- a/sormas-backend/src/test/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessorTest.java +++ b/sormas-backend/src/test/java/de/symeda/sormas/backend/externalmessage/labmessage/AutomaticLabMessageProcessorTest.java @@ -40,6 +40,7 @@ import de.symeda.sormas.api.externalmessage.processing.ExternalMessageProcessingResult; import de.symeda.sormas.api.infrastructure.facility.FacilityDto; import de.symeda.sormas.api.infrastructure.facility.FacilityType; +import de.symeda.sormas.api.person.PersonCriteria; import de.symeda.sormas.api.person.PersonDto; import de.symeda.sormas.api.person.Sex; import de.symeda.sormas.api.sample.PathogenTestDto; @@ -310,6 +311,29 @@ public void testProcessWithExistingPersonWithSameNationalHealthIdButDifferentDet assertThat(getPathogenTestFacade().getAllActiveUuids(), hasSize(0)); } + @Test + public void testProcessWithExistingPersonWithSameNationalHealthIdAndPersonDetailsNormalizedCheck() + throws ExecutionException, InterruptedException { + ExternalMessageDto externalMessage = createExternalMessage(m -> { + m.setPersonFirstName("john vander"); + m.setPersonLastName("DOÉ"); + m.setPersonCity(" PERSON city \n"); + m.setPersonStreet(" person STREET 12A"); + }); + + creator.createPerson("John Van Der", "Doe", Sex.MALE, p -> { + p.setNationalHealthId(externalMessage.getPersonNationalHealthId()); + p.getAddress().setCity("person city"); + p.getAddress().setStreet("PERSON STREET, 12a"); + }); + + ProcessingResult result = runFlow(externalMessage); + assertThat(result.getStatus(), is(DONE)); + assertThat(externalMessage.getStatus(), is(ExternalMessageStatus.PROCESSED)); + assertThat(getExternalMessageFacade().getByUuid(externalMessage.getUuid()).getStatus(), is(ExternalMessageStatus.PROCESSED)); + assertThat(getPersonFacade().count(new PersonCriteria()), is(1L)); + } + @Test public void testProcessWithExistingSimilarPerson() throws ExecutionException, InterruptedException { ExternalMessageDto externalMessage = createExternalMessage(m -> m.setPersonNationalHealthId(null));