Search in sources :

Example 1 with ContactFacadeEjb

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);
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) Date(java.util.Date) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) ContactDto(de.symeda.sormas.api.contact.ContactDto) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 2 with ContactFacadeEjb

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));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) Date(java.util.Date) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) UI(com.vaadin.ui.UI) ContactImportSimilarityResult(de.symeda.sormas.ui.importer.ContactImportSimilarityResult) ImportSimilarityResultOption(de.symeda.sormas.ui.importer.ImportSimilarityResultOption) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 3 with ContactFacadeEjb

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));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UserDto(de.symeda.sormas.api.user.UserDto) ContactFacadeEjb(de.symeda.sormas.backend.contact.ContactFacadeEjb) Date(java.util.Date) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) ByteArrayInputStream(java.io.ByteArrayInputStream) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Aggregations

CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)3 PersonDto (de.symeda.sormas.api.person.PersonDto)3 SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)3 UserDto (de.symeda.sormas.api.user.UserDto)3 ContactFacadeEjb (de.symeda.sormas.backend.contact.ContactFacadeEjb)3 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)3 RDCF (de.symeda.sormas.ui.TestDataCreator.RDCF)3 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)3 File (java.io.File)3 Date (java.util.Date)3 Test (org.junit.Test)3 UI (com.vaadin.ui.UI)1 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)1 ContactDto (de.symeda.sormas.api.contact.ContactDto)1 PersonSimilarityCriteria (de.symeda.sormas.api.person.PersonSimilarityCriteria)1 ContactImportSimilarityResult (de.symeda.sormas.ui.importer.ContactImportSimilarityResult)1 ImportSimilarityResultOption (de.symeda.sormas.ui.importer.ImportSimilarityResultOption)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1