use of de.symeda.sormas.backend.contact.ContactFacadeEjb in project SORMAS-Project by hzi-braunschweig.
the class ContactImporterTest method testImportCaseContactsDifferentAddressTypes.
@Test
public void testImportCaseContactsDifferentAddressTypes() 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);
// import of 3 contacts with different address types
File csvFile = new File(getClass().getClassLoader().getResource("sormas_case_contact_import_test_address_types.csv").toURI());
ContactImporter contactImporter = new ContactImporterExtension(csvFile, user, caze);
ImportResultStatus importResult = contactImporter.runImport();
List<ContactDto> contacts = getContactFacade().getAllAfter(null);
assertEquals(3, contacts.size());
boolean foundOtto = false;
boolean foundOskar = false;
boolean foundOona = false;
for (ContactDto contact : contacts) {
PersonDto person = getPersonFacade().getPersonByUuid(contact.getPerson().getUuid());
if ("Otto".equals(person.getFirstName())) {
foundOtto = true;
assertTrue(CollectionUtils.isEmpty(person.getAddresses()));
assertEquals("131", person.getAddress().getHouseNumber());
}
if ("Oskar".equals(person.getFirstName())) {
foundOskar = true;
assertTrue(CollectionUtils.isEmpty(person.getAddresses()));
assertEquals("132", person.getAddress().getHouseNumber());
}
if ("Oona".equals(person.getFirstName())) {
foundOona = true;
assertTrue(person.getAddress().checkIsEmptyLocation());
assertEquals(1, person.getAddresses().size());
assertEquals("133", person.getAddresses().get(0).getHouseNumber());
}
}
assertTrue("Not all contacts found.", foundOtto && foundOskar && foundOona);
}
use of de.symeda.sormas.backend.contact.ContactFacadeEjb 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));
}
use of de.symeda.sormas.backend.contact.ContactFacadeEjb in project SORMAS-Project by hzi-braunschweig.
the class ContactImporterTest method testImportContacts.
@Test
public void testImportContacts() throws IOException, InvalidColumnException, InterruptedException, CsvException, 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);
// Try to import 3 contacts.
// 2 of them belong to a case that does not exist.
// 1 of those 2 still has enough details to be imported
File csvFile = new File(getClass().getClassLoader().getResource("sormas_contact_import_test.csv").toURI());
ContactImporter contactImporter = new ContactImporterExtension(csvFile, user, null);
ImportResultStatus importResult = contactImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED_WITH_ERRORS, importResult);
assertEquals(2, contactFacade.count(null));
PersonDto casePerson = creator.createPerson("John", "Smith");
CaseDataDto caze = creator.createCase(user.toReference(), casePerson.toReference(), Disease.EVD, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf, "ABCDEF-GHIJKL-MNOPQR");
csvFile = new File(getClass().getClassLoader().getResource("sormas_contact_import_test.csv").toURI());
contactImporter = new ContactImporterExtension(csvFile, user, null);
importResult = contactImporter.runImport();
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(5, contactFacade.count(null));
// 2 associated to the case
ContactCriteria contactCriteria = new ContactCriteria().caze(caze.toReference());
assertEquals(2, contactFacade.count(contactCriteria));
// should have the disease of the case
contactCriteria = new ContactCriteria().disease(Disease.EVD);
assertEquals(2, contactFacade.count(contactCriteria));
// the others have their defined disease
contactCriteria = new ContactCriteria().disease(Disease.CORONAVIRUS);
assertEquals(3, contactFacade.count(contactCriteria));
// Test import contacts from a commented CSV file
csvFile = new File(getClass().getClassLoader().getResource("sormas_contact_import_test_comment.csv").toURI());
contactImporter = new ContactImporterExtension(csvFile, user, null);
importResult = contactImporter.runImport();
InputStream errorStream = new ByteArrayInputStream(((ContactImporterExtension) contactImporter).stringBuilder.toString().getBytes(StandardCharsets.UTF_8));
List<String[]> errorRows = getCsvReader(errorStream).readAll();
if (errorRows.size() > 1) {
assertThat("Error during import: " + StringUtils.join(errorRows.get(1), ", "), errorRows, hasSize(0));
}
assertEquals(ImportResultStatus.COMPLETED, importResult);
assertEquals(8, contactFacade.count(null));
}
Aggregations