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();
}
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)));
}
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());
}
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)));
}
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();
}
}
Aggregations