Search in sources :

Example 1 with PersonFollowUpEndDto

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

the class PersonFacadeEjb method getCaseLatestFollowUpEndDates.

private Stream<PersonFollowUpEndDto> getCaseLatestFollowUpEndDates(Date since, boolean forSymptomJournal) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<PersonFollowUpEndDto> cq = cb.createQuery(PersonFollowUpEndDto.class);
    Root<Case> caseRoot = cq.from(Case.class);
    Join<Case, Person> personJoin = caseRoot.join(Case.PERSON, JoinType.LEFT);
    Predicate filter = caseService.createUserFilter(cb, cq, caseRoot);
    if (since != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, caseService.createChangeDateFilter(cb, caseRoot, since));
    }
    if (forSymptomJournal) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(personJoin.get(Person.SYMPTOM_JOURNAL_STATUS), SymptomJournalStatus.ACCEPTED));
    }
    if (filter != null) {
        cq.where(filter);
    }
    final Date minDate = new Date(0);
    final Expression<Object> followUpStatusExpression = cb.selectCase().when(cb.equal(caseRoot.get(Case.FOLLOW_UP_STATUS), FollowUpStatus.CANCELED), cb.nullLiteral(Date.class)).otherwise(caseRoot.get(Case.FOLLOW_UP_UNTIL));
    cq.multiselect(personJoin.get(Person.UUID), followUpStatusExpression);
    cq.orderBy(cb.asc(personJoin.get(Person.UUID)), cb.desc(cb.coalesce(caseRoot.get(Case.FOLLOW_UP_UNTIL), minDate)));
    return em.createQuery(cq).getResultList().stream().distinct();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) Case(de.symeda.sormas.backend.caze.Case) Predicate(javax.persistence.criteria.Predicate)

Example 2 with PersonFollowUpEndDto

use of de.symeda.sormas.api.person.PersonFollowUpEndDto 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 3 with PersonFollowUpEndDto

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

the class PersonFacadeEjbTest method testGetFollowUpEndDatesContactsAndCases.

@Test
public void testGetFollowUpEndDatesContactsAndCases() {
    RDCFEntities rdcfEntities = creator.createRDCFEntities();
    UserDto user = creator.createUser(rdcfEntities, UserRole.REST_EXTERNAL_VISITS_USER);
    Date now = new Date();
    final PersonDto person1 = creator.createPerson();
    final PersonDto person2 = creator.createPerson();
    final PersonDto person3 = creator.createPerson();
    final PersonDto person4 = creator.createPerson();
    final ContactDto contact1 = creator.createContact(user.toReference(), person1.toReference(), DateHelper.subtractDays(now, 22));
    final ContactDto contact2 = creator.createContact(user.toReference(), person2.toReference(), DateHelper.subtractDays(now, 22));
    final ContactDto contact3 = creator.createContact(user.toReference(), person4.toReference());
    final ContactDto contact4 = creator.createContact(user.toReference(), person4.toReference(), DateHelper.subtractDays(now, 21));
    final CaseDataDto case1 = creator.createCase(user.toReference(), person1.toReference(), rdcfEntities);
    final CaseDataDto case2 = creator.createCase(user.toReference(), person2.toReference(), rdcfEntities);
    final CaseDataDto case3 = creator.createCase(user.toReference(), person2.toReference(), rdcfEntities);
    final CaseDataDto case4 = creator.createCase(user.toReference(), person3.toReference(), rdcfEntities);
    final CaseDataDto case5 = creator.createCase(user.toReference(), person3.toReference(), rdcfEntities);
    contact1.setOverwriteFollowUpUntil(true);
    contact2.setOverwriteFollowUpUntil(true);
    case1.setOverwriteFollowUpUntil(true);
    case1.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 23));
    case2.setOverwriteFollowUpUntil(true);
    case2.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 21));
    case3.setOverwriteFollowUpUntil(true);
    case3.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 23));
    case4.setOverwriteFollowUpUntil(true);
    case4.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 21));
    case5.setOverwriteFollowUpUntil(true);
    case5.getSymptoms().setOnsetDate(DateHelper.subtractDays(now, 21));
    contact3.setFollowUpStatus(FollowUpStatus.NO_FOLLOW_UP);
    contact3.setFollowUpUntil(null);
    contact4.setFollowUpStatus(FollowUpStatus.FOLLOW_UP);
    contact1.setFollowUpUntil(DateHelper.subtractDays(now, 1));
    case1.setFollowUpUntil(DateHelper.subtractDays(now, 2));
    contact2.setFollowUpUntil(DateHelper.subtractDays(now, 1));
    case2.setFollowUpUntil(now);
    case2.setFollowUpStatus(FollowUpStatus.CANCELED);
    case3.setFollowUpUntil(DateHelper.subtractDays(now, 2));
    case4.setFollowUpStatus(FollowUpStatus.CANCELED);
    case5.setFollowUpStatus(FollowUpStatus.CANCELED);
    contact4.setFollowUpUntil(now);
    getContactFacade().save(contact1);
    getContactFacade().save(contact2);
    getContactFacade().save(contact3);
    getContactFacade().save(contact4);
    getCaseFacade().save(case1);
    getCaseFacade().save(case2);
    getCaseFacade().save(case3);
    getCaseFacade().save(case4);
    getCaseFacade().save(case5);
    List<PersonFollowUpEndDto> followUpEndDtos = getPersonFacade().getLatestFollowUpEndDates(null, false);
    assertThat(followUpEndDtos, hasSize(4));
    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, 1)));
    Optional<PersonFollowUpEndDto> result2 = followUpEndDtos.stream().filter(p -> p.getPersonUuid().equals(person2.getUuid())).findFirst();
    assertTrue(result2.isPresent());
    assertNotNull(result2.get().getLatestFollowUpEndDate());
    assertTrue(DateHelper.isSameDay(result2.get().getLatestFollowUpEndDate(), DateHelper.subtractDays(now, 1)));
    Optional<PersonFollowUpEndDto> result3 = followUpEndDtos.stream().filter(p -> p.getPersonUuid().equals(person3.getUuid())).findFirst();
    assertTrue(result3.isPresent());
    assertNull(result3.get().getLatestFollowUpEndDate());
}
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) ContactDto(de.symeda.sormas.api.contact.ContactDto) Date(java.util.Date) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with PersonFollowUpEndDto

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

the class PersonFacadeEjbTest method testGetFollowUpEndDatesContactsOnly.

@Test
public /*
	 * If you need to change this test to make it pass, you probably changed the behaviour of the ExternalVisitsResource.
	 * Please note that other system used alongside with SORMAS are depending on this, so that their developers must be notified of any
	 * relevant API changes some time before they go into any test and productive system. Please inform the SORMAS core development team at
	 * https://gitter.im/SORMAS-Project!
	 */
void testGetFollowUpEndDatesContactsOnly() {
    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 ContactDto contact11 = creator.createContact(user.toReference(), person1.toReference(), DateHelper.subtractDays(new Date(), 41));
    final ContactDto contact12 = creator.createContact(user.toReference(), person1.toReference(), DateHelper.subtractDays(new Date(), 29));
    final ContactDto contact2 = creator.createContact(user.toReference(), person2.toReference(), DateHelper.subtractDays(new Date(), 21));
    contact11.setOverwriteFollowUpUntil(true);
    contact12.setOverwriteFollowUpUntil(true);
    contact2.setOverwriteFollowUpUntil(true);
    Date now = new Date();
    contact11.setFollowUpUntil(DateHelper.subtractDays(now, 20));
    contact12.setFollowUpUntil(DateHelper.subtractDays(now, 8));
    contact2.setFollowUpUntil(now);
    getContactFacade().save(contact11);
    getContactFacade().save(contact12);
    getContactFacade().save(contact2);
    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) 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) Date(java.util.Date) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 5 with PersonFollowUpEndDto

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

the class PersonFacadeEjb method getContactLatestFollowUpEndDate.

private Date getContactLatestFollowUpEndDate(String uuid) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<PersonFollowUpEndDto> cq = cb.createQuery(PersonFollowUpEndDto.class);
    Root<Contact> contactRoot = cq.from(Contact.class);
    Join<Contact, Person> personJoin = contactRoot.join(Contact.PERSON, JoinType.LEFT);
    Predicate filter = contactService.createUserFilter(cb, cq, contactRoot);
    filter = CriteriaBuilderHelper.and(cb, filter, cb.notEqual(contactRoot.get(Contact.FOLLOW_UP_STATUS), FollowUpStatus.CANCELED));
    filter = CriteriaBuilderHelper.and(cb, filter, cb.notEqual(contactRoot.get(Contact.FOLLOW_UP_STATUS), FollowUpStatus.NO_FOLLOW_UP));
    filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(contactRoot.get(Contact.DELETED), false));
    if (uuid != null) {
        filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(personJoin.get(Person.UUID), uuid));
    }
    if (filter != null) {
        cq.where(filter);
    }
    cq.multiselect(personJoin.get(Person.UUID), contactRoot.get(Contact.FOLLOW_UP_UNTIL));
    cq.orderBy(cb.desc(contactRoot.get(Contact.FOLLOW_UP_UNTIL)));
    List<PersonFollowUpEndDto> results = em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
    if (results.isEmpty()) {
        return null;
    } else {
        return results.get(0).getLatestFollowUpEndDate();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PersonFollowUpEndDto(de.symeda.sormas.api.person.PersonFollowUpEndDto) Contact(de.symeda.sormas.backend.contact.Contact) Predicate(javax.persistence.criteria.Predicate)

Aggregations

PersonFollowUpEndDto (de.symeda.sormas.api.person.PersonFollowUpEndDto)7 Date (java.util.Date)5 Disease (de.symeda.sormas.api.Disease)3 EntityDto (de.symeda.sormas.api.EntityDto)3 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)3 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)3 InvestigationStatus (de.symeda.sormas.api.caze.InvestigationStatus)3 ContactDto (de.symeda.sormas.api.contact.ContactDto)3 FollowUpStatus (de.symeda.sormas.api.contact.FollowUpStatus)3 EventDto (de.symeda.sormas.api.event.EventDto)3 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)3 ExternalSurveillanceToolException (de.symeda.sormas.api.externalsurveillancetool.ExternalSurveillanceToolException)3 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)3 LocationDto (de.symeda.sormas.api.location.LocationDto)3 JournalPersonDto (de.symeda.sormas.api.person.JournalPersonDto)3 PersonAssociation (de.symeda.sormas.api.person.PersonAssociation)3 PersonContactDetailDto (de.symeda.sormas.api.person.PersonContactDetailDto)3 PersonContactDetailType (de.symeda.sormas.api.person.PersonContactDetailType)3 PersonContext (de.symeda.sormas.api.person.PersonContext)3 PersonCriteria (de.symeda.sormas.api.person.PersonCriteria)3