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