Search in sources :

Example 1 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class PersonSelectionField method addFilterForm.

protected void addFilterForm() {
    filterForm = new PersonSelectionFilterForm();
    final PersonSimilarityCriteria searchCriteria = new PersonSimilarityCriteria();
    if (referencePerson != null) {
        searchCriteria.setFirstName(referencePerson.getFirstName());
        searchCriteria.setLastName(referencePerson.getLastName());
    }
    filterForm.setValue(searchCriteria);
    filterForm.addApplyHandler((e) -> {
        if (filterForm.validateFields()) {
            personGrid.loadData(filterForm.getValue());
        }
    });
    filterForm.addResetHandler((e) -> filterForm.setValue(new PersonSimilarityCriteria()));
    mainLayout.addComponent(filterForm);
}
Also used : PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria)

Example 2 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class PersonSelectionField method initializeGrid.

/**
 * Load a grid of all persons similar to the given reference person.
 */
protected void initializeGrid() {
    defaultCriteria = new PersonSimilarityCriteria().firstName(referencePerson.getFirstName()).lastName(referencePerson.getLastName()).sex(referencePerson.getSex()).birthdateDD(referencePerson.getBirthdateDD()).birthdateMM(referencePerson.getBirthdateMM()).birthdateYYYY(referencePerson.getBirthdateYYYY()).passportNumber(referencePerson.getPassportNumber()).nationalHealthId(referencePerson.getNationalHealthId());
    personGrid = new PersonSelectionGrid();
    personGrid.addSelectionListener(e -> {
        if (e.getSelected().size() > 0) {
            rbCreatePerson.setValue(null);
        }
        if (selectionChangeCallback != null) {
            selectionChangeCallback.accept(!e.getSelected().isEmpty());
        }
    });
}
Also used : PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria)

Example 3 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class PersonDaoTest method getRelevantPersonNames.

@Test
public void getRelevantPersonNames() {
    Person person1 = TestEntityCreator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 1);
    Person person2 = TestEntityCreator.createPerson("James", "Smith", Sex.MALE, 1979, 5, 12);
    Person person3 = TestEntityCreator.createPerson("James", "Smith", Sex.MALE, 1980, 1, 5);
    Person person4 = TestEntityCreator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, 12, 2);
    Person person5 = TestEntityCreator.createPerson("Maria", "Garcia", null, 1984, 7, 12);
    Person person6 = TestEntityCreator.createPerson("Maria", "Garcia", Sex.FEMALE, 1984, null, null);
    Person person7 = TestEntityCreator.createPerson("James", "Smith", Sex.MALE, null, null, null);
    PersonSimilarityCriteria criteria = new PersonSimilarityCriteria().sex(Sex.MALE).birthdateYYYY(1980).birthdateMM(1).birthdateDD(1);
    List<String> matchingPersonUuids = DatabaseHelper.getPersonDao().getRelevantPersonNames(criteria).stream().map(PersonNameDto::getUuid).collect(Collectors.toList());
    assertThat(matchingPersonUuids, hasSize(2));
    assertThat(matchingPersonUuids, containsInAnyOrder(person1.getUuid(), person7.getUuid()));
    criteria.birthdateMM(null).birthdateDD(null);
    matchingPersonUuids = DatabaseHelper.getPersonDao().getRelevantPersonNames(criteria).stream().map(PersonNameDto::getUuid).collect(Collectors.toList());
    assertThat(matchingPersonUuids, hasSize(3));
    assertThat(matchingPersonUuids, containsInAnyOrder(person1.getUuid(), person3.getUuid(), person7.getUuid()));
    criteria.sex(Sex.FEMALE).birthdateYYYY(1984);
    matchingPersonUuids = DatabaseHelper.getPersonDao().getRelevantPersonNames(criteria).stream().map(PersonNameDto::getUuid).collect(Collectors.toList());
    assertThat(matchingPersonUuids, hasSize(3));
    assertThat(matchingPersonUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid()));
    criteria.sex(null);
    matchingPersonUuids = DatabaseHelper.getPersonDao().getRelevantPersonNames(criteria).stream().map(PersonNameDto::getUuid).collect(Collectors.toList());
    assertThat(matchingPersonUuids, hasSize(4));
    assertThat(matchingPersonUuids, containsInAnyOrder(person4.getUuid(), person5.getUuid(), person6.getUuid(), person7.getUuid()));
}
Also used : PersonNameDto(de.symeda.sormas.api.person.PersonNameDto) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) Test(org.junit.Test)

Example 4 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testGetMatchingNameDtos.

@Test
public void testGetMatchingNameDtos() {
    RDCFEntities rdcf = creator.createRDCFEntities();
    UserDto user = creator.createUser(rdcf, UserRole.SURVEILLANCE_SUPERVISOR);
    // 1-3 = Active persons; 4 = Person without reference; 5-7 = Inactive persons
    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", Sex.UNKNOWN, 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().archive(inactiveCase.getUuid(), null);
    getEventFacade().archive(inactiveEvent.getUuid(), null);
    // Only persons that have active case, contact or event participant associations should be retrieved
    List<String> relevantNameUuids = getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria()).stream().map(dto -> dto.getUuid()).collect(Collectors.toList());
    assertThat(relevantNameUuids, hasSize(6));
    assertThat(relevantNameUuids, containsInAnyOrder(person1.getUuid(), person2.getUuid(), person3.getUuid(), person5.getUuid(), person6.getUuid(), person7.getUuid()));
    creator.createCase(user.toReference(), person4.toReference(), rdcf);
    getCaseFacade().dearchive(Collections.singletonList(inactiveCase.getUuid()), null);
    getEventFacade().dearchive(Collections.singletonList(inactiveEvent.getUuid()), null);
    PersonSimilarityCriteria criteria = new PersonSimilarityCriteria().sex(Sex.MALE).birthdateYYYY(1980).birthdateMM(1).birthdateDD(1);
    List<String> matchingUuids = getPersonFacade().getSimilarPersonDtos(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().getSimilarPersonDtos(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().getSimilarPersonDtos(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().getSimilarPersonDtos(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().getSimilarPersonDtos(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().getSimilarPersonDtos(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().getSimilarPersonDtos(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().getSimilarPersonDtos(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()));
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) Date(java.util.Date) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Matchers.not(org.hamcrest.Matchers.not) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) PersonDto(de.symeda.sormas.api.person.PersonDto) EntityDto(de.symeda.sormas.api.EntityDto) PersonContext(de.symeda.sormas.api.person.PersonContext) UserRole(de.symeda.sormas.api.user.UserRole) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) EventDto(de.symeda.sormas.api.event.EventDto) Collectors(java.util.stream.Collectors) PhoneNumberType(de.symeda.sormas.api.person.PhoneNumberType) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) SymptomJournalStatus(de.symeda.sormas.api.person.SymptomJournalStatus) Optional(java.util.Optional) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) Matchers.is(org.hamcrest.Matchers.is) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) PersonFacade(de.symeda.sormas.api.person.PersonFacade) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationDto(de.symeda.sormas.api.location.LocationDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) Matchers.empty(org.hamcrest.Matchers.empty) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserDto(de.symeda.sormas.api.user.UserDto) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SortProperty(de.symeda.sormas.api.utils.SortProperty) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Assert.assertNull(org.junit.Assert.assertNull) Disease(de.symeda.sormas.api.Disease) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 5 with PersonSimilarityCriteria

use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.

the class ContactImporterTest method testImportCaseContacts.

@Test
public void testImportCaseContacts() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
    ContactFacadeEjb contactFacade = getBean(ContactFacadeEjbLocal.class);
    RDCF rdcf = creator.createRDCF("Abia", "Umuahia North", "Urban Ward 2", "Anelechi Hospital");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto casePerson = creator.createPerson("John", "Smith");
    CaseDataDto caze = creator.createCase(user.toReference(), casePerson.toReference(), Disease.CORONAVIRUS, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf);
    // Successful import of 5 case contacts
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_case_contact_import_test_success.csv").toURI());
    ContactImporter contactImporter = new ContactImporterExtension(csvFile, user, caze);
    ImportResultStatus importResult = contactImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(5, contactFacade.count(null));
    // Person Similarity: pick
    List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
    csvFile = new File(getClass().getClassLoader().getResource("sormas_case_contact_import_test_similarities.csv").toURI());
    contactImporter = new ContactImporterExtension(csvFile, user, caze) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            List<SimilarPersonDto> entries = new ArrayList<>();
            for (SimilarPersonDto person : persons) {
                if (PersonHelper.areNamesSimilar(newPerson.getFirstName(), newPerson.getLastName(), person.getFirstName(), person.getLastName(), null)) {
                    entries.add(person);
                }
            }
            resultConsumer.accept((T) new ContactImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
        }
    };
    importResult = contactImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(6, contactFacade.count(null));
    assertEquals(6, getPersonFacade().getAllUuids().size());
    // Person Similarity: skip
    csvFile = new File(getClass().getClassLoader().getResource("sormas_case_contact_import_test_similarities.csv").toURI());
    contactImporter = new ContactImporterExtension(csvFile, user, caze) {

        @Override
        protected <T extends PersonImportSimilarityResult> void handlePersonSimilarity(PersonDto newPerson, Consumer<T> resultConsumer, BiFunction<SimilarPersonDto, ImportSimilarityResultOption, T> createSimilarityResult, String infoText, UI currentUI) {
            resultConsumer.accept((T) new ContactImportSimilarityResult(null, null, ImportSimilarityResultOption.SKIP));
        }
    };
    importResult = contactImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(6, contactFacade.count(null));
    assertEquals(6, getPersonFacade().getAllUuids().size());
    // Person Similarity: create
    csvFile = new File(getClass().getClassLoader().getResource("sormas_case_contact_import_test_similarities.csv").toURI());
    contactImporter = new ContactImporterExtension(csvFile, user, caze);
    importResult = contactImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(7, contactFacade.count(null));
    assertEquals(7, getPersonFacade().getAllUuids().size());
    // Test import contacts from a commented CSV file
    // Successful import of 5 case contacts
    csvFile = new File(getClass().getClassLoader().getResource("sormas_case_contact_import_test_comment_success.csv").toURI());
    contactImporter = new ContactImporterExtension(csvFile, user, caze);
    importResult = contactImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(12, contactFacade.count(null));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) Date(java.util.Date) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) UI(com.vaadin.ui.UI) ContactImportSimilarityResult(de.symeda.sormas.ui.importer.ContactImportSimilarityResult) ImportSimilarityResultOption(de.symeda.sormas.ui.importer.ImportSimilarityResultOption) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Aggregations

PersonSimilarityCriteria (de.symeda.sormas.api.person.PersonSimilarityCriteria)9 Test (org.junit.Test)7 PersonDto (de.symeda.sormas.api.person.PersonDto)6 UserDto (de.symeda.sormas.api.user.UserDto)6 SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)5 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)5 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 UI (com.vaadin.ui.UI)4 EventDto (de.symeda.sormas.api.event.EventDto)4 Date (java.util.Date)4 List (java.util.List)4 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)3 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)3 RDCF (de.symeda.sormas.ui.TestDataCreator.RDCF)3 ImportSimilarityResultOption (de.symeda.sormas.ui.importer.ImportSimilarityResultOption)3 PersonImportSimilarityResult (de.symeda.sormas.ui.importer.PersonImportSimilarityResult)3 Consumer (java.util.function.Consumer)3 EventParticipantCriteria (de.symeda.sormas.api.event.EventParticipantCriteria)2