use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.
the class CaseImporterTest method testImportAllCases.
@Test
public void testImportAllCases() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
TestDataCreator creator = new TestDataCreator();
TestDataCreator.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);
// Successful import of 5 cases
File csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_success.csv").toURI());
CaseImporterExtension caseImporter = new CaseImporterExtension(csvFile, true, user);
ImportResultStatus importResult = caseImporter.runImport();
assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
// Failed import of 5 cases because of errors
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_errors.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importResult);
assertEquals(5, getCaseFacade().count(null));
// Similarity: skip
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@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 CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.SKIP));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: pick
List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@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 CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
}
@Override
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new CaseImportSimilarityResult(null, input.getSimilarCases().get(0), ImportSimilarityResultOption.PICK));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: cancel
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@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 CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CANCEL));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.CANCELED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-5", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: override
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@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 CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
}
@Override
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new CaseImportSimilarityResult(null, input.getSimilarCases().get(0), ImportSimilarityResultOption.OVERRIDE));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: create -> fail because of duplicate epid number
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user) {
@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 CaseImportSimilarityResult(entries.get(0), null, ImportSimilarityResultOption.PICK));
}
@Override
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CREATE));
}
};
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importResult);
assertEquals(5, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Change epid number of the case in database to pass creation test
CaseDataDto caze = getCaseFacade().getAllActiveCasesAfter(null).get(4);
caze.setEpidNumber("ABC-DEF-GHI-19-99");
getCaseFacade().save(caze);
assertEquals("ABC-DEF-GHI-19-99", getCaseFacade().getAllActiveCasesAfter(null).get(4).getEpidNumber());
// Similarity: create -> pass
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_similarities.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(6, getCaseFacade().count(null));
assertEquals("ABC-DEF-GHI-19-10", getCaseFacade().getAllActiveCasesAfter(null).get(5).getEpidNumber());
// Successful import of a case with different infrastructure combinations
creator.createRDCF("R1", "D1", "C1", "F1");
creator.createRDCF("R2", "D2", "C2", "F2");
creator.createRDCF("R3", "D3", "C3", "F3");
csvFile = new File(getClass().getClassLoader().getResource("sormas_case_import_test_different_infrastructure.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(7, getCaseFacade().count(null));
// Successful import of 5 cases from a commented CSV file
csvFile = new File(getClass().getClassLoader().getResource("sormas_import_test_comment_success.csv").toURI());
caseImporter = new CaseImporterExtension(csvFile, true, user);
importResult = caseImporter.runImport();
assertEquals(caseImporter.stringBuilder.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(12, getCaseFacade().count(null));
}
use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantImporterTest method testImportEventParticipantSimilarityPick.
@Test
public void testImportEventParticipantSimilarityPick() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
EventParticipantFacadeEjbLocal eventParticipantFacade = getBean(EventParticipantFacadeEjbLocal.class);
RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
EventDto event = creator.createEvent(EventStatus.SIGNAL, "Title", "Description", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 2), new Date(), user.toReference(), user.toReference(), Disease.EVD);
EventReferenceDto eventRef = event.toReference();
PersonDto person = creator.createPerson("Günther", "Heinz");
creator.createCase(user.toReference(), person.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
// Person Similarity: pick
List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
File csvFile = new File(getClass().getClassLoader().getResource("sormas_eventparticipant_import_test_similarities.csv").toURI());
EventParticipantImporterExtension eventParticipantImporter = new EventParticipantImporterExtension(csvFile, user, event) {
@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 PersonImportSimilarityResult(entries.get(0), ImportSimilarityResultOption.PICK));
}
};
ImportResultStatus importResult = eventParticipantImporter.runImport();
EventParticipantIndexDto importedEventParticipant = eventParticipantFacade.getIndexList(new EventParticipantCriteria().withEvent(eventRef), null, null, null).get(0);
PersonDto importedPerson = getPersonFacade().getPersonByUuid(importedEventParticipant.getPersonUuid());
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(1, eventParticipantFacade.count(new EventParticipantCriteria().withEvent(eventRef)));
assertEquals(person.getUuid(), importedEventParticipant.getPersonUuid());
assertEquals(person.getFirstName(), importedPerson.getFirstName());
assertEquals(person.getLastName(), importedPerson.getLastName());
assertEquals(1, getPersonFacade().getAllUuids().size());
}
use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantImporterTest method testImportEventParticipantSimilarityPickEventParticipant.
@Test
public void testImportEventParticipantSimilarityPickEventParticipant() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
EventParticipantFacadeEjbLocal eventParticipantFacade = getBean(EventParticipantFacadeEjbLocal.class);
RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
EventDto event = creator.createEvent(EventStatus.SIGNAL, "Title", "Description", "First", "Name", "12345", TypeOfPlace.PUBLIC_PLACE, DateHelper.subtractDays(new Date(), 2), new Date(), user.toReference(), user.toReference(), Disease.EVD);
EventReferenceDto eventRef = event.toReference();
PersonDto person = creator.createPerson("Günther", "Heinz");
EventParticipantDto eventParticipant = creator.createEventParticipant(eventRef, person, "old desc", user.toReference());
// Person Similarity: pick event participant
List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
File csvFile = new File(getClass().getClassLoader().getResource("sormas_eventparticipant_import_test_similarities.csv").toURI());
EventParticipantImporterExtension eventParticipantImporter = new EventParticipantImporterExtension(csvFile, user, event) {
@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 PersonImportSimilarityResult(entries.get(0), ImportSimilarityResultOption.PICK));
}
};
ImportResultStatus importResult = eventParticipantImporter.runImport();
EventParticipantIndexDto importedEventParticipant = eventParticipantFacade.getIndexList(new EventParticipantCriteria().withEvent(eventRef), null, null, null).get(0);
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(1, eventParticipantFacade.count(new EventParticipantCriteria().withEvent(eventRef)));
assertEquals(person.getUuid(), importedEventParticipant.getPersonUuid());
assertEquals(eventParticipant.getUuid(), importedEventParticipant.getUuid());
assertEquals("description 1", importedEventParticipant.getInvolvementDescription());
assertEquals(1, getPersonFacade().getAllUuids().size());
}
use of de.symeda.sormas.api.person.PersonSimilarityCriteria in project SORMAS-Project by hzi-braunschweig.
the class EventImporterTest method testImportAllEvents.
@Test
public void testImportAllEvents() throws IOException, InvalidColumnException, InterruptedException, CsvValidationException, URISyntaxException {
TestDataCreator creator = new TestDataCreator();
TestDataCreator.RDCF rdcf = creator.createRDCF("Bourgogne-Franche-Comté", "Côte d'Or", "Dijon", "CHU Dijon Bourgogne");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
// Successful import of 5 cases
File csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_success.csv").toURI());
EventImporterExtension eventImporter = new EventImporterExtension(csvFile, true, user);
ImportResultStatus importResult = eventImporter.runImport();
assertEquals(eventImporter.errors.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(4, getEventFacade().count(null));
assertEquals(3, getPersonFacade().count(null));
List<EventDto> events = getEventFacade().getAllAfter(null);
Optional<EventDto> optionalEventWith2Participants = events.stream().filter(event -> "Event title with 2 participants".equals(event.getEventTitle())).findFirst();
assertTrue(optionalEventWith2Participants.isPresent());
optionalEventWith2Participants.ifPresent(event -> {
List<EventParticipantDto> participants = getEventParticipantFacade().getAllActiveEventParticipantsByEvent(event.getUuid());
assertEquals(2, participants.size());
});
// Similarity: skip
csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
eventImporter = new EventImporterExtension(csvFile, true, user) {
@Override
protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP));
}
};
importResult = eventImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(4, getEventFacade().count(null));
assertEquals(3, getPersonFacade().count(null));
// Similarity: pick
List<SimilarPersonDto> persons = FacadeProvider.getPersonFacade().getSimilarPersonDtos(new PersonSimilarityCriteria());
csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
eventImporter = new EventImporterExtension(csvFile, true, user) {
@Override
protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
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(new PersonImportSimilarityResult(entries.get(0), ImportSimilarityResultOption.PICK));
}
};
importResult = eventImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(6, getEventFacade().count(null));
assertEquals(3, getPersonFacade().count(null));
// Similarity: cancel
csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
eventImporter = new EventImporterExtension(csvFile, true, user) {
@Override
protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CANCEL));
}
};
importResult = eventImporter.runImport();
assertEquals(ImportResultStatus.CANCELED, importResult);
assertEquals(6, getEventFacade().count(null));
assertEquals(3, getPersonFacade().count(null));
// Similarity: create
csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_similarities.csv").toURI());
eventImporter = new EventImporterExtension(csvFile, true, user) {
@Override
protected void handlePersonSimilarity(PersonDto newPerson, Consumer<PersonImportSimilarityResult> resultConsumer) {
resultConsumer.accept(new PersonImportSimilarityResult(null, ImportSimilarityResultOption.CREATE));
}
};
importResult = eventImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(8, getEventFacade().count(null));
assertEquals(6, getPersonFacade().count(null));
// Successful import of 5 cases from a commented CSV file
csvFile = new File(getClass().getClassLoader().getResource("sormas_event_import_test_comment_success.csv").toURI());
eventImporter = new EventImporterExtension(csvFile, true, user);
importResult = eventImporter.runImport();
assertEquals(eventImporter.errors.toString(), ImportResultStatus.COMPLETED, importResult);
assertEquals(10, getEventFacade().count(null));
}
Aggregations