Search in sources :

Example 1 with SimilarPersonDto

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

the class PersonService method toSimilarPersonDto.

private SimilarPersonDto toSimilarPersonDto(Person entity) {
    Integer approximateAge = entity.getApproximateAge();
    ApproximateAgeType approximateAgeType = entity.getApproximateAgeType();
    if (entity.getBirthdateYYYY() != null) {
        DataHelper.Pair<Integer, ApproximateAgeType> pair = ApproximateAgeType.ApproximateAgeHelper.getApproximateAge(entity.getBirthdateYYYY(), entity.getBirthdateMM(), entity.getBirthdateDD(), entity.getDeathDate());
        approximateAge = pair.getElement0();
        approximateAgeType = pair.getElement1();
    }
    SimilarPersonDto similarPersonDto = new SimilarPersonDto();
    similarPersonDto.setUuid(entity.getUuid());
    similarPersonDto.setFirstName(entity.getFirstName());
    similarPersonDto.setLastName(entity.getLastName());
    similarPersonDto.setNickname(entity.getNickname());
    similarPersonDto.setAgeAndBirthDate(PersonHelper.getAgeAndBirthdateString(approximateAge, approximateAgeType, entity.getBirthdateDD(), entity.getBirthdateMM(), entity.getBirthdateYYYY()));
    similarPersonDto.setSex(entity.getSex());
    similarPersonDto.setPresentCondition(entity.getPresentCondition());
    similarPersonDto.setPhone(entity.getPhone());
    similarPersonDto.setDistrictName(entity.getAddress().getDistrict() != null ? entity.getAddress().getDistrict().getName() : null);
    similarPersonDto.setCommunityName(entity.getAddress().getCommunity() != null ? entity.getAddress().getCommunity().getName() : null);
    similarPersonDto.setPostalCode(entity.getAddress().getPostalCode());
    similarPersonDto.setCity(entity.getAddress().getCity());
    similarPersonDto.setStreet(entity.getAddress().getStreet());
    similarPersonDto.setHouseNumber(entity.getAddress().getHouseNumber());
    similarPersonDto.setNationalHealthId(entity.getNationalHealthId());
    similarPersonDto.setPassportNumber(entity.getPassportNumber());
    return similarPersonDto;
}
Also used : ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) DataHelper(de.symeda.sormas.api.utils.DataHelper) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Example 2 with SimilarPersonDto

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

the class EventImporter method handlePersonSimilarity.

/**
 * Presents a popup window to the user that allows them to deal with detected potentially duplicate persons.
 * By passing the desired result to the resultConsumer, the importer decided how to proceed with the import process.
 */
protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
    currentUI.accessSynchronously(() -> {
        PersonSelectionField personSelect = new PersonSelectionField(newPerson, I18nProperties.getString(Strings.infoSelectOrCreatePersonForImport));
        personSelect.setWidth(1024, Unit.PIXELS);
        if (personSelect.hasMatches()) {
            final CommitDiscardWrapperComponent<PersonSelectionField> component = new CommitDiscardWrapperComponent<>(personSelect);
            component.addCommitListener(() -> {
                SimilarPersonDto person = personSelect.getValue();
                if (person == null) {
                    resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
                } else {
                    resultConsumer.accept(new PersonImportSimilarityResult(person, ImportSimilarityResultOption.PICK));
                }
            });
            component.addDiscardListener(() -> resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP)));
            personSelect.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
            Window window = VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreatePerson));
            window.addCloseListener(event -> resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP)));
            personSelect.selectBestMatch();
        } else {
            resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
        }
    });
}
Also used : Window(com.vaadin.ui.Window) PersonSelectionField(de.symeda.sormas.ui.person.PersonSelectionField) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Example 3 with SimilarPersonDto

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

the class PersonSelectionGrid method buildGrid.

private void buildGrid() {
    setSizeFull();
    setSelectionMode(SelectionMode.SINGLE);
    setHeightMode(HeightMode.ROW);
    BeanItemContainer<SimilarPersonDto> container = new BeanItemContainer<>(SimilarPersonDto.class);
    GeneratedPropertyContainer generatedContainer = new GeneratedPropertyContainer(container);
    setContainerDataSource(generatedContainer);
    setColumns(SimilarPersonDto.class, Arrays.asList(SimilarPersonDto.FIRST_NAME, SimilarPersonDto.LAST_NAME, SimilarPersonDto.NICKNAME, SimilarPersonDto.AGE_AND_BIRTH_DATE, SimilarPersonDto.SEX, SimilarPersonDto.PRESENT_CONDITION, SimilarPersonDto.PHONE, SimilarPersonDto.DISTRICT_NAME, SimilarPersonDto.COMMUNITY_NAME, SimilarPersonDto.POSTAL_CODE, SimilarPersonDto.CITY, SimilarPersonDto.STREET, SimilarPersonDto.HOUSE_NUMBER, SimilarPersonDto.NATIONAL_HEALTH_ID, SimilarPersonDto.PASSPORT_NUMBER));
    for (Column column : getColumns()) {
        String propertyId = column.getPropertyId().toString();
        String i18nPrefix = SimilarPersonDto.getI18nPrefix(propertyId);
        column.setHeaderCaption(I18nProperties.getPrefixCaption(i18nPrefix, propertyId, column.getHeaderCaption()));
    }
    getColumn(SimilarPersonDto.FIRST_NAME).setMinimumWidth(150);
    getColumn(SimilarPersonDto.LAST_NAME).setMinimumWidth(150);
}
Also used : GeneratedPropertyContainer(com.vaadin.v7.data.util.GeneratedPropertyContainer) BeanItemContainer(com.vaadin.v7.data.util.BeanItemContainer) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Example 4 with SimilarPersonDto

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

the class PersonDependentEditForm method createPersonSearchButton.

protected Button createPersonSearchButton(String personSearchLoc) {
    return ButtonHelper.createIconButtonWithCaption(personSearchLoc, StringUtils.EMPTY, VaadinIcons.SEARCH, clickEvent -> {
        VaadinIcons icon = (VaadinIcons) clickEvent.getButton().getIcon();
        if (icon == VaadinIcons.SEARCH) {
            PersonSearchField personSearchField = new PersonSearchField(null, I18nProperties.getString(Strings.infoSearchPerson));
            personSearchField.setWidth(1280, Unit.PIXELS);
            final CommitDiscardWrapperComponent<PersonSearchField> component = new CommitDiscardWrapperComponent<>(personSearchField);
            component.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
            component.getCommitButton().setEnabled(false);
            component.addCommitListener(() -> {
                SimilarPersonDto pickedPerson = personSearchField.getValue();
                if (pickedPerson != null) {
                    // add consumer
                    searchedPerson = FacadeProvider.getPersonFacade().getPersonByUuid(pickedPerson.getUuid());
                    setPerson(searchedPerson);
                    enablePersonFields(false);
                    clickEvent.getButton().setIcon(VaadinIcons.CLOSE);
                }
            });
            personSearchField.setSelectionChangeCallback((commitAllowed) -> {
                component.getCommitButton().setEnabled(commitAllowed);
            });
            VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingSelectPerson));
        } else {
            searchedPerson = null;
            setPerson(searchedPerson);
            enablePersonFields(true);
            clickEvent.getButton().setIcon(VaadinIcons.SEARCH);
        }
    }, CssStyles.FORCE_CAPTION);
}
Also used : PersonSearchField(de.symeda.sormas.ui.person.PersonSearchField) VaadinIcons(com.vaadin.icons.VaadinIcons) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto)

Example 5 with SimilarPersonDto

use of de.symeda.sormas.api.person.SimilarPersonDto 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

SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)12 PersonDto (de.symeda.sormas.api.person.PersonDto)7 UserDto (de.symeda.sormas.api.user.UserDto)6 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)6 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)6 File (java.io.File)6 Test (org.junit.Test)6 UI (com.vaadin.ui.UI)5 PersonSimilarityCriteria (de.symeda.sormas.api.person.PersonSimilarityCriteria)5 PersonImportSimilarityResult (de.symeda.sormas.ui.importer.PersonImportSimilarityResult)5 ArrayList (java.util.ArrayList)5 EventDto (de.symeda.sormas.api.event.EventDto)4 RDCF (de.symeda.sormas.ui.TestDataCreator.RDCF)4 Date (java.util.Date)4 Consumer (java.util.function.Consumer)4 EventParticipantCriteria (de.symeda.sormas.api.event.EventParticipantCriteria)3 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)3 EventParticipantFacadeEjbLocal (de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal)3 ImportSimilarityResultOption (de.symeda.sormas.ui.importer.ImportSimilarityResultOption)3 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)3