Search in sources :

Example 96 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasCaseFacadeEjbTest method testSaveSharedPointOfEntryCaseWithInfrastructureName.

@Test
public void testSaveSharedPointOfEntryCaseWithInfrastructureName() throws SormasToSormasException, SormasToSormasValidationException {
    PersonDto person = createPersonDto(rdcf);
    CaseDataDto caze = CaseDataDto.build(person.toReference(), Disease.CORONAVIRUS);
    caze.setCaseOrigin(CaseOrigin.POINT_OF_ENTRY);
    caze.setResponsibleRegion(rdcf.region);
    caze.setResponsibleDistrict(rdcf.district);
    caze.setResponsibleCommunity(rdcf.community);
    caze.setPointOfEntry(rdcf.pointOfEntry);
    PortHealthInfoDto portHealthInfo = PortHealthInfoDto.build();
    portHealthInfo.setAirlineName("Test Airline");
    caze.setPortHealthInfo(portHealthInfo);
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
    shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
    CaseDataDto savedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
    assertThat(savedCase.getResponsibleRegion(), is(rdcf.region));
    assertThat(savedCase.getResponsibleDistrict(), is(rdcf.district));
    assertThat(savedCase.getResponsibleCommunity(), is(rdcf.community));
    assertThat(savedCase.getPointOfEntry(), is(rdcf.pointOfEntry));
    assertThat(savedCase.getPortHealthInfo().getAirlineName(), is("Test Airline"));
}
Also used : SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) PortHealthInfoDto(de.symeda.sormas.api.caze.porthealthinfo.PortHealthInfoDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 97 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class SormasToSormasCaseFacadeEjbTest method testSaveSharedCaseWithUnknownFacility.

@Test
public void testSaveSharedCaseWithUnknownFacility() throws SormasToSormasException, SormasToSormasValidationException {
    PersonDto person = createPersonDto(rdcf);
    person.setFirstName("James");
    person.setLastName("Smith");
    CaseDataDto caze = createRemoteCaseDto(rdcf, person);
    caze.setHealthFacility(new FacilityReferenceDto("unknown", "Unknown facility", "unknown"));
    SormasToSormasDto shareData = new SormasToSormasDto();
    shareData.setOriginInfo(createSormasToSormasOriginInfo(DEFAULT_SERVER_ID, false));
    shareData.setCases(Collections.singletonList(new SormasToSormasCaseDto(person, caze)));
    SormasToSormasEncryptedDataDto encryptedData = encryptShareData(shareData);
    getSormasToSormasCaseFacade().saveSharedEntities(encryptedData);
    CaseDataDto savedCase = getCaseFacade().getCaseDataByUuid(caze.getUuid());
    assertThat(savedCase, is(notNullValue()));
    assertThat(savedCase.getHealthFacility().getUuid(), is(FacilityDto.OTHER_FACILITY_UUID));
    assertThat(savedCase.getHealthFacilityDetails(), is("Unknown facility"));
}
Also used : SormasToSormasEncryptedDataDto(de.symeda.sormas.api.sormastosormas.SormasToSormasEncryptedDataDto) SormasToSormasDto(de.symeda.sormas.api.sormastosormas.SormasToSormasDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PersonDto(de.symeda.sormas.api.person.PersonDto) SormasToSormasCaseDto(de.symeda.sormas.api.sormastosormas.caze.SormasToSormasCaseDto) SormasToSormasTest(de.symeda.sormas.backend.sormastosormas.SormasToSormasTest) Test(org.junit.Test)

Example 98 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testCountAndGetIndexListWithAssociations.

/**
 * Test all {@link PersonAssociation} variants if they work. Also serves to review the generated SQL.
 */
@Test
public void testCountAndGetIndexListWithAssociations() {
    PersonFacade cut = getPersonFacade();
    Integer offset = null;
    Integer limit = null;
    List<SortProperty> sortProperties = null;
    RDCF rdcf = creator.createRDCF();
    UserDto user = creator.createUser(rdcf.region.getUuid(), null, null, null, "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    loginWith(user);
    // 1a. Test for all available PersonAssociations
    for (PersonAssociation pa : PersonAssociation.values()) {
        PersonCriteria criteria = new PersonCriteria().personAssociation(pa);
        assertThat("Failed for testing association on count: " + pa.name(), cut.count(criteria), equalTo(0L));
        assertThat(criteria.getPersonAssociation(), equalTo(pa));
        assertThat("Failed for testing association on getIndexList: " + pa.name(), cut.getIndexList(criteria, offset, limit, sortProperties), is(empty()));
        assertThat(criteria.getPersonAssociation(), equalTo(pa));
    }
    // 1b. Test that calling with "null" as criteria also works
    assertThat(cut.count(null), equalTo(0L));
    assertThat(cut.getIndexList(null, offset, limit, sortProperties), is(empty()));
    // 2. Test paging windows
    final PersonDto person1 = creator.createPerson("James", "Smith", Sex.MALE, 1920, 1, 1);
    final CaseDataDto case1 = creator.createCase(user.toReference(), person1.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    final PersonDto person2 = creator.createPerson("Maria", "Garcia", Sex.FEMALE, 1920, 1, 1);
    final ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), person2.toReference(), null, new Date(), new Date(), Disease.EVD, rdcf);
    // 2a. count
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.ALL)), equalTo(2L));
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CASE)), equalTo(1L));
    assertThat(cut.count(new PersonCriteria().personAssociation(PersonAssociation.CONTACT)), equalTo(1L));
    // 2b. getIndexList with all persons in the paging window
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    offset = 0;
    limit = 2;
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    offset = 0;
    limit = 1;
    assertPersonsFound(case1, contact2, cut, offset, limit, sortProperties);
    // 2c. getIndexList [PersonAssociation.ALL] with only the contact person in the paging window (default sorting by changeDate)
    offset = 1;
    limit = 2;
    assertPersonsFound(null, null, Arrays.asList(contact2.getPerson()), cut, offset, limit, sortProperties);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) PersonFacade(de.symeda.sormas.api.person.PersonFacade) UserDto(de.symeda.sormas.api.user.UserDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 99 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testGetFollowUpEndDatesCasesOnly.

@Test
public void testGetFollowUpEndDatesCasesOnly() {
    RDCFEntities rdcfEntities = creator.createRDCFEntities();
    UserDto user = creator.createUser(rdcfEntities, UserRole.REST_EXTERNAL_VISITS_USER);
    // Person without contact
    creator.createPerson();
    final PersonDto person1 = creator.createPerson();
    final PersonDto person2 = creator.createPerson();
    final CaseDataDto case11 = creator.createCase(user.toReference(), person1.toReference(), rdcfEntities);
    final CaseDataDto case12 = creator.createCase(user.toReference(), person1.toReference(), rdcfEntities);
    final CaseDataDto case2 = creator.createCase(user.toReference(), person2.toReference(), rdcfEntities);
    Date now = new Date();
    case11.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 41));
    case11.setOverwriteFollowUpUntil(true);
    case12.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 29));
    case12.setOverwriteFollowUpUntil(true);
    case2.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 21));
    case2.setOverwriteFollowUpUntil(true);
    case11.setFollowUpUntil(DateHelper.subtractDays(now, 20));
    case12.setFollowUpUntil(DateHelper.subtractDays(now, 8));
    case2.setFollowUpUntil(now);
    getCaseFacade().save(case11);
    getCaseFacade().save(case12);
    getCaseFacade().save(case2);
    List<PersonFollowUpEndDto> followUpEndDtos = getPersonFacade().getLatestFollowUpEndDates(null, false);
    assertThat(followUpEndDtos, hasSize(2));
    Optional<PersonFollowUpEndDto> result1 = followUpEndDtos.stream().filter(p -> p.getPersonUuid().equals(person1.getUuid())).findFirst();
    assertTrue(result1.isPresent());
    assertTrue(DateHelper.isSameDay(result1.get().getLatestFollowUpEndDate(), DateHelper.subtractDays(now, 8)));
    Optional<PersonFollowUpEndDto> result2 = followUpEndDtos.stream().filter(p -> p.getPersonUuid().equals(person2.getUuid())).findFirst();
    assertTrue(result2.isPresent());
    assertTrue(DateHelper.isSameDay(result2.get().getLatestFollowUpEndDate(), now));
    Date result3 = getPersonFacade().getLatestFollowUpEndDateByUuid(person1.getUuid());
    assertTrue(DateHelper.isSameDay(result3, DateHelper.subtractDays(now, 8)));
}
Also used : FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) Arrays(java.util.Arrays) Date(java.util.Date) PersonAssociation(de.symeda.sormas.api.person.PersonAssociation) Matchers.not(org.hamcrest.Matchers.not) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) PersonDto(de.symeda.sormas.api.person.PersonDto) EntityDto(de.symeda.sormas.api.EntityDto) PersonContext(de.symeda.sormas.api.person.PersonContext) UserRole(de.symeda.sormas.api.user.UserRole) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) PersonExportDto(de.symeda.sormas.api.person.PersonExportDto) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) InvestigationStatus(de.symeda.sormas.api.caze.InvestigationStatus) EventDto(de.symeda.sormas.api.event.EventDto) Collectors(java.util.stream.Collectors) PhoneNumberType(de.symeda.sormas.api.person.PhoneNumberType) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) ContactDto(de.symeda.sormas.api.contact.ContactDto) PersonContactDetailType(de.symeda.sormas.api.person.PersonContactDetailType) SymptomJournalStatus(de.symeda.sormas.api.person.SymptomJournalStatus) Optional(java.util.Optional) PersonSimilarityCriteria(de.symeda.sormas.api.person.PersonSimilarityCriteria) Matchers.is(org.hamcrest.Matchers.is) PersonIndexDto(de.symeda.sormas.api.person.PersonIndexDto) ExternalSurveillanceToolException(de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) DateHelper(de.symeda.sormas.api.utils.DateHelper) PersonFacade(de.symeda.sormas.api.person.PersonFacade) PersonContactDetailDto(de.symeda.sormas.api.person.PersonContactDetailDto) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) LocationDto(de.symeda.sormas.api.location.LocationDto) PersonCriteria(de.symeda.sormas.api.person.PersonCriteria) Matchers.empty(org.hamcrest.Matchers.empty) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserDto(de.symeda.sormas.api.user.UserDto) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SortProperty(de.symeda.sormas.api.utils.SortProperty) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) PresentCondition(de.symeda.sormas.api.person.PresentCondition) Assert.assertNull(org.junit.Assert.assertNull) Disease(de.symeda.sormas.api.Disease) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) Date(java.util.Date) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 100 with PersonDto

use of de.symeda.sormas.api.person.PersonDto in project SORMAS-Project by hzi-braunschweig.

the class PersonFacadeEjbTest method testGetMostRelevantFollowUpStatusByUuid.

@Test
public void testGetMostRelevantFollowUpStatusByUuid() {
    RDCFEntities rdcfEntities = creator.createRDCFEntities();
    PersonDto person = creator.createPerson();
    UserDto user = creator.createUser(rdcfEntities, UserRole.REST_EXTERNAL_VISITS_USER);
    ContactDto contact1 = creator.createContact(user.toReference(), person.toReference());
    for (FollowUpStatus status : FollowUpStatus.values()) {
        contact1.setFollowUpStatus(status);
        getContactFacade().save(contact1);
        if (FollowUpStatus.COMPLETED.equals(status) || FollowUpStatus.NO_FOLLOW_UP.equals(status)) {
            // In this case the status is automatically updated to FOLLOW_UP, because the end of the follow up period has not yet been reached.
            assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
            continue;
        }
        assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(status));
    }
    ContactDto contact2 = creator.createContact(user.toReference(), person.toReference());
    CaseDataDto case1 = creator.createCase(user.toReference(), person.toReference(), rdcfEntities);
    updateFollowUpStatus(contact1, FollowUpStatus.FOLLOW_UP);
    for (FollowUpStatus status : FollowUpStatus.values()) {
        updateFollowUpStatus(case1, status);
        updateFollowUpStatus(contact2, status);
        // Other states must not interfere one with ongoing follow up
        assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
        updateFollowUpStatus(contact1, status);
        if (FollowUpStatus.COMPLETED.equals(status) || FollowUpStatus.NO_FOLLOW_UP.equals(status)) {
            // In this case the status is automatically updated to FOLLOW_UP, because the end of the follow up period has not yet been reached.
            assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
            updateFollowUpStatus(contact1, FollowUpStatus.FOLLOW_UP);
            continue;
        }
        // In that case one clear status can be calculated
        assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(status));
        updateFollowUpStatus(case1, FollowUpStatus.FOLLOW_UP);
        // Also ongoing case follow up must not be overwritten
        assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.FOLLOW_UP));
        updateFollowUpStatus(case1, status);
        updateFollowUpStatus(contact1, FollowUpStatus.FOLLOW_UP);
    }
    updateFollowUpStatus(contact1, FollowUpStatus.LOST);
    updateFollowUpStatus(contact2, FollowUpStatus.CANCELED);
    updateFollowUpStatus(case1, FollowUpStatus.LOST);
    assertThat(getPersonFacade().getMostRelevantFollowUpStatusByUuid(person.getUuid()), is(FollowUpStatus.NO_FOLLOW_UP));
}
Also used : RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) FollowUpStatus(de.symeda.sormas.api.contact.FollowUpStatus) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) JournalPersonDto(de.symeda.sormas.api.person.JournalPersonDto) UserDto(de.symeda.sormas.api.user.UserDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Aggregations

PersonDto (de.symeda.sormas.api.person.PersonDto)332 Test (org.junit.Test)241 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)178 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)171 Date (java.util.Date)165 UserDto (de.symeda.sormas.api.user.UserDto)152 ContactDto (de.symeda.sormas.api.contact.ContactDto)93 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 LocalDate (java.time.LocalDate)59 SampleDto (de.symeda.sormas.api.sample.SampleDto)54 UserReferenceDto (de.symeda.sormas.api.user.UserReferenceDto)51 EventDto (de.symeda.sormas.api.event.EventDto)45 SormasToSormasTest (de.symeda.sormas.backend.sormastosormas.SormasToSormasTest)43 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)39 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)38 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)37 Disease (de.symeda.sormas.api.Disease)36 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)36 ArrayList (java.util.ArrayList)35 List (java.util.List)32