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;
}
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));
}
});
}
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);
}
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);
}
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));
}
Aggregations