use of de.symeda.sormas.ui.importer.CaseImportSimilarityResult 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.ui.importer.CaseImportSimilarityResult in project SORMAS-Project by hzi-braunschweig.
the class CaseImporter method handleCaseSimilarity.
/**
* Presents a popup window to the user that allows them to deal with detected potentially duplicate cases.
* By passing the desired result to the resultConsumer, the importer decided how to proceed with the import process.
*/
protected void handleCaseSimilarity(CaseImportSimilarityInput input, Consumer<CaseImportSimilarityResult> resultConsumer) {
currentUI.accessSynchronously(() -> {
CasePickOrImportField pickOrImportField = new CasePickOrImportField(input.getCaze(), input.getPerson(), input.getSimilarCases());
pickOrImportField.setWidth(1024, Unit.PIXELS);
final CommitDiscardWrapperComponent<CasePickOrImportField> component = new CommitDiscardWrapperComponent<>(pickOrImportField);
component.addCommitListener(() -> {
CaseSelectionDto pickedCase = pickOrImportField.getValue();
if (pickedCase != null) {
if (pickOrImportField.isOverrideCase()) {
resultConsumer.accept(new CaseImportSimilarityResult(null, pickedCase, ImportSimilarityResultOption.OVERRIDE));
} else {
resultConsumer.accept(new CaseImportSimilarityResult(null, pickedCase, ImportSimilarityResultOption.PICK));
}
} else {
resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CREATE));
}
});
DiscardListener discardListener = () -> resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.CANCEL));
component.addDiscardListener(discardListener);
component.getDiscardButton().setCaption(I18nProperties.getCaption(Captions.actionCancel));
component.getCommitButton().setCaption(I18nProperties.getCaption(Captions.actionConfirm));
component.getCommitButton().setEnabled(false);
Button skipButton = ButtonHelper.createButton(Captions.actionSkip, e -> {
component.removeDiscardListener(discardListener);
component.discard();
resultConsumer.accept(new CaseImportSimilarityResult(null, null, ImportSimilarityResultOption.SKIP));
});
component.getButtonsPanel().addComponentAsFirst(skipButton);
pickOrImportField.setSelectionChangeCallback((commitAllowed) -> component.getCommitButton().setEnabled(commitAllowed));
VaadinUiUtil.showModalPopupWindow(component, I18nProperties.getString(Strings.headingPickOrCreateCase));
});
}
Aggregations