From 45dbe8b012339f86804ec6455d7b576f0c0c66a8 Mon Sep 17 00:00:00 2001 From: Levente Gal Date: Mon, 21 Oct 2024 13:47:46 +0300 Subject: [PATCH 1/2] #13168 Normalization of Automatic Processing for Name, Birthdate, and Address Matching --- .../AutomaticLabMessageProcessor.java | 16 +++++++++++++++ .../AutomaticLabMessageProcessorTest.java | 20 +++++++++++++++++++ 2 files changed, 36 insertions(+) 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..dd55f0c32cf 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 @@ -310,6 +310,26 @@ public void testProcessWithExistingPersonWithSameNationalHealthIdButDifferentDet assertThat(getPathogenTestFacade().getAllActiveUuids(), hasSize(0)); } + @Test + public void testProcessWithExistingPersonWithSameNationalHealthIdAndPersonDetailsNormalizedCheck() + throws ExecutionException, InterruptedException { + ExternalMessageDto externalMessage = createExternalMessage(m -> { + m.setPersonCity("person city"); + m.setPersonStreet("PERSON STREET, 12a"); + }); + + creator.createPerson("john", "DOÉ", Sex.MALE, p -> { + p.setNationalHealthId(externalMessage.getPersonNationalHealthId()); + p.getAddress().setCity(" PERSON city \n"); + 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)); + } + @Test public void testProcessWithExistingSimilarPerson() throws ExecutionException, InterruptedException { ExternalMessageDto externalMessage = createExternalMessage(m -> m.setPersonNationalHealthId(null)); From 8bb7730a15134a85c8ae7f0693c694a1ce040bf3 Mon Sep 17 00:00:00 2001 From: Levente Gal Date: Wed, 23 Oct 2024 10:48:15 +0300 Subject: [PATCH 2/2] #13168 Normalization of Automatic Processing for Name, Birthdate, and Address Matching - extended test --- .../AutomaticLabMessageProcessorTest.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 dd55f0c32cf..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; @@ -314,20 +315,23 @@ public void testProcessWithExistingPersonWithSameNationalHealthIdButDifferentDet public void testProcessWithExistingPersonWithSameNationalHealthIdAndPersonDetailsNormalizedCheck() throws ExecutionException, InterruptedException { ExternalMessageDto externalMessage = createExternalMessage(m -> { - m.setPersonCity("person city"); - m.setPersonStreet("PERSON STREET, 12a"); + m.setPersonFirstName("john vander"); + m.setPersonLastName("DOÉ"); + m.setPersonCity(" PERSON city \n"); + m.setPersonStreet(" person STREET 12A"); }); - creator.createPerson("john", "DOÉ", Sex.MALE, p -> { + creator.createPerson("John Van Der", "Doe", Sex.MALE, p -> { p.setNationalHealthId(externalMessage.getPersonNationalHealthId()); - p.getAddress().setCity(" PERSON city \n"); - p.getAddress().setStreet(" person STREET 12A"); + 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