PersonFacadeEjb implements PersonFacade { @Override public List<PersonNameDto> getMatchingNameDtos(UserReferenceDto userRef, PersonSimilarityCriteria criteria) { User user = userService.getByReferenceDto(userRef); if (user == null) { return Collections.emptyList(); } return new ArrayList<>(personService.getMatchingNameDtos(user, criteria)); }  @Override List<String> getAllUuids(); @Override List<PersonNameDto> getMatchingNameDtos(UserReferenceDto userRef, PersonSimilarityCriteria criteria); @Override List<SimilarPersonDto> getSimilarPersonsByUuids(List<String> personUuids); @Override Boolean isValidPersonUuid(String personUuid); @Override Map<Disease, Long> getDeathCountByDisease(CaseCriteria caseCriteria, boolean excludeSharedCases, boolean excludeCasesFromContacts); @Override List<PersonDto> getPersonsAfter(Date date); @Override List<PersonDto> getByUuids(List<String> uuids); @Override List<PersonDto> getDeathsBetween(Date fromDate, Date toDate, DistrictReferenceDto districtRef, Disease disease); @Override PersonReferenceDto getReferenceByUuid(String uuid); @Override PersonDto getPersonByUuid(String uuid); @Override JournalPersonDto getPersonForJournal(String Uuid); @Override PersonDto savePerson(PersonDto source); @Override void validate(PersonDto source); @Override List<PersonQuarantineEndDto> getLatestQuarantineEndDates(Date since); @Override List<PersonFollowUpEndDto> getLatestFollowUpEndDates(Date since, boolean forSymptomJournal); @Override Date getLatestFollowUpEndDateByUuid(String Uuid); @Override boolean setSymptomJournalStatus(String personUuid, SymptomJournalStatus status); void onPersonChanged(PersonDto existingPerson, Person newPerson); Person fillOrBuildEntity(@NotNull PersonDto source, Person target); PersonDto convertToDto(Person p, Pseudonymizer pseudonymizer, boolean inJurisdiction); static PersonReferenceDto toReferenceDto(Person entity); static SimilarPersonDto toSimilarPersonDto(Person entity); static PersonDto toDto(Person source);  }
@Test public void testGetMatchingNameDtos() { RDCFEntities rdcf = creator.createRDCFEntities(); UserDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_SUPERVISOR); PersonDto person1 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1); PersonDto person2 = creator.createPerson("James", "Smith", Sex.MALE, 1979, 5, 12); PersonDto person3 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 5); PersonDto person4 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, 12, 2); PersonDto person5 = creator.createPerson("Maria", "Garcia", null, 1984, 7, 12); PersonDto person6 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, null, null); PersonDto person7 = creator.createPerson("James", "Smith", Sex.MALE, null, null, null); CaseDataDto activeCase = creator.createCase(user.toReference(), person1.toReference(), rdcf); creator.createContact(user.toReference(), person2.toReference(), activeCase); EventDto activeEvent = creator.createEvent(user.toReference()); creator.createEventParticipant(activeEvent.toReference(), person3, user.toReference()); CaseDataDto inactiveCase = creator.createCase(user.toReference(), person5.toReference(), rdcf); creator.createContact(user.toReference(), person6.toReference(), inactiveCase); EventDto inactiveEvent = creator.createEvent(user.toReference()); creator.createEventParticipant(inactiveEvent.toReference(), person7, user.toReference()); getCaseFacade().archiveOrDearchiveCase(inactiveCase.getUuid(), true); getEventFacade().archiveOrDearchiveEvent(inactiveEvent.getUuid(), true); List<String> relevantNameUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), new PersonSimilarityCriteria()) .stream() .map(dto -> dto.getUuid()) .collect(Collectors.toList()); assertThat(relevantNameUuids, hasSize(3)); assertThat(relevantNameUuids, containsInAnyOrder(person1.getUuid(), person2.getUuid(), person3.getUuid())); creator.createCase(user.toReference(), person4.toReference(), rdcf); getCaseFacade().archiveOrDearchiveCase(inactiveCase.getUuid(), false); getEventFacade().archiveOrDearchiveEvent(inactiveEvent.getUuid(), false); PersonSimilarityCriteria criteria = new PersonSimilarityCriteria().sex(Sex.MALE).birthdateYYYY(1980).birthdateMM(1).birthdateDD(1); List<String> matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(2)); assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person7.getUuid())); criteria.birthdateMM(null).birthdateDD(null); matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(3)); assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid())); criteria.sex(Sex.FEMALE).birthdateYYYY(1984); matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(3)); assertThat(matchingUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid())); criteria.sex(null); matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(4)); assertThat(matchingUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid(), person7.getUuid())); final String passportNr = "passportNr"; final String otherPassportNr = "otherPassportNr"; final String healthId = "healthId"; final String otherHealthId = "otherHealthId"; PersonDto person8 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1, passportNr, healthId); PersonDto person9 = creator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1, null, otherHealthId); PersonDto person10 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1970, 1, 1, passportNr, null); PersonDto person11 = creator.createPerson("John", "Doe", Sex.MALE, 1970, 1, 1, otherPassportNr, null); creator.createCase(user.toReference(), person8.toReference(), rdcf); creator.createCase(user.toReference(), person9.toReference(), rdcf); creator.createCase(user.toReference(), person10.toReference(), rdcf); creator.createCase(user.toReference(), person11.toReference(), rdcf); criteria.sex(Sex.MALE).birthdateYYYY(1980); criteria.passportNumber(passportNr); matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(6)); assertThat( matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person8.getUuid(), person9.getUuid(), person10.getUuid())); criteria.nationalHealthId(healthId).passportNumber(null); matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(4)); assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person8.getUuid())); criteria.nationalHealthId(otherHealthId); matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(4)); assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person9.getUuid())); criteria.passportNumber(otherPassportNr); matchingUuids = getPersonFacade().getMatchingNameDtos(user.toReference(), criteria).stream().map(person -> person.getUuid()).collect(Collectors.toList()); assertThat(matchingUuids, hasSize(5)); assertThat(matchingUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid(), person9.getUuid(), person11.getUuid())); }