Search in sources :

Example 1 with EventParticipantFacadeEjbLocal

use of de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal 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());
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) ArrayList(java.util.ArrayList) 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) Consumer(java.util.function.Consumer) UI(com.vaadin.ui.UI) BiFunction(java.util.function.BiFunction) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) EventParticipantIndexDto(de.symeda.sormas.api.event.EventParticipantIndexDto) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) File(java.io.File) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 2 with EventParticipantFacadeEjbLocal

use of de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantImporterTest method testImportEventParticipantSimilarityCreate.

@Test
public void testImportEventParticipantSimilarityCreate() 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", "Heinze");
    creator.createCase(user.toReference(), person.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    // Person Similarity: create
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_eventparticipant_import_test_similarities.csv").toURI());
    EventParticipantImporterExtension eventParticipantImporter = new EventParticipantImporterExtension(csvFile, user, event);
    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)));
    assertNotEquals(person.getUuid(), importedEventParticipant.getPersonUuid());
    assertEquals(2, getPersonFacade().getAllUuids().size());
}
Also used : RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) EventDto(de.symeda.sormas.api.event.EventDto) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) EventParticipantIndexDto(de.symeda.sormas.api.event.EventParticipantIndexDto) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) File(java.io.File) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 3 with EventParticipantFacadeEjbLocal

use of de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantImporterTest method testImportEventParticipantDifferentAddressTypes.

@Test
public void testImportEventParticipantDifferentAddressTypes() 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();
    // import of 3 event participants with different address types
    File csvFile = new File(getClass().getClassLoader().getResource("sormas_eventparticipant_import_test_address_types.csv").toURI());
    EventParticipantImporterExtension eventParticipantImporter = new EventParticipantImporterExtension(csvFile, user, event);
    ImportResultStatus importResult = eventParticipantImporter.runImport();
    List<EventParticipantDto> eventParticipants = getEventParticipantFacade().getByEventUuids(Collections.singletonList(eventRef.getUuid()));
    assertEquals(3, eventParticipants.size());
    boolean foundOtto = false;
    boolean foundOskar = false;
    boolean foundOona = false;
    for (EventParticipantDto eventParticipant : eventParticipants) {
        PersonDto person = eventParticipant.getPerson();
        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 eventparticipants found.", foundOtto && foundOskar && foundOona);
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) Date(java.util.Date) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) File(java.io.File) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 4 with EventParticipantFacadeEjbLocal

use of de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal 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());
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) ArrayList(java.util.ArrayList) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) 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) Consumer(java.util.function.Consumer) UI(com.vaadin.ui.UI) BiFunction(java.util.function.BiFunction) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) EventParticipantIndexDto(de.symeda.sormas.api.event.EventParticipantIndexDto) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) File(java.io.File) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Example 5 with EventParticipantFacadeEjbLocal

use of de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal in project SORMAS-Project by hzi-braunschweig.

the class EventParticipantImporterTest method testImportEventParticipantSimilaritySkip.

@Test
public void testImportEventParticipantSimilaritySkip() 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();
    // Person Similarity: create
    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) {
            resultConsumer.accept((T) new PersonImportSimilarityResult(null, ImportSimilarityResultOption.SKIP));
        }
    };
    ImportResultStatus importResult = eventParticipantImporter.runImport();
    assertEquals(ImportResultStatus.COMPLETED, importResult);
    assertEquals(0, eventParticipantFacade.count(new EventParticipantCriteria().withEvent(eventRef)));
    assertEquals(0, getPersonFacade().getAllUuids().size());
}
Also used : PersonDto(de.symeda.sormas.api.person.PersonDto) SimilarPersonDto(de.symeda.sormas.api.person.SimilarPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) EventDto(de.symeda.sormas.api.event.EventDto) Date(java.util.Date) RDCF(de.symeda.sormas.ui.TestDataCreator.RDCF) Consumer(java.util.function.Consumer) UI(com.vaadin.ui.UI) BiFunction(java.util.function.BiFunction) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) EventParticipantFacadeEjbLocal(de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal) ImportResultStatus(de.symeda.sormas.ui.importer.ImportResultStatus) EventParticipantCriteria(de.symeda.sormas.api.event.EventParticipantCriteria) File(java.io.File) PersonImportSimilarityResult(de.symeda.sormas.ui.importer.PersonImportSimilarityResult) AbstractBeanTest(de.symeda.sormas.ui.AbstractBeanTest) Test(org.junit.Test)

Aggregations

EventDto (de.symeda.sormas.api.event.EventDto)7 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)7 UserDto (de.symeda.sormas.api.user.UserDto)7 EventParticipantFacadeEjbLocal (de.symeda.sormas.backend.event.EventParticipantFacadeEjb.EventParticipantFacadeEjbLocal)7 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)7 RDCF (de.symeda.sormas.ui.TestDataCreator.RDCF)7 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)7 File (java.io.File)7 Date (java.util.Date)7 Test (org.junit.Test)7 EventParticipantCriteria (de.symeda.sormas.api.event.EventParticipantCriteria)6 PersonDto (de.symeda.sormas.api.person.PersonDto)5 SimilarPersonDto (de.symeda.sormas.api.person.SimilarPersonDto)5 UI (com.vaadin.ui.UI)3 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)3 EventParticipantIndexDto (de.symeda.sormas.api.event.EventParticipantIndexDto)3 PersonImportSimilarityResult (de.symeda.sormas.ui.importer.PersonImportSimilarityResult)3 BiFunction (java.util.function.BiFunction)3 Consumer (java.util.function.Consumer)3 PersonSimilarityCriteria (de.symeda.sormas.api.person.PersonSimilarityCriteria)2