use of de.symeda.sormas.api.contact.ContactIndexDetailedDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjb method getIndexDetailedList.
@Override
public List<ContactIndexDetailedDto> getIndexDetailedList(ContactCriteria contactCriteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaQuery<ContactIndexDetailedDto> query = listCriteriaBuilder.buildIndexDetailedCriteria(contactCriteria, sortProperties);
List<ContactIndexDetailedDto> dtos = QueryHelper.getResultList(em, query, first, max);
// Load event count and latest events info per contact
Map<String, List<ContactEventSummaryDetails>> eventSummaries = eventService.getEventSummaryDetailsByContacts(dtos.stream().map(ContactIndexDetailedDto::getUuid).collect(Collectors.toList())).stream().collect(Collectors.groupingBy(ContactEventSummaryDetails::getContactUuid, Collectors.toList()));
for (ContactIndexDetailedDto contact : dtos) {
List<ContactEventSummaryDetails> contactEvents = eventSummaries.getOrDefault(contact.getUuid(), Collections.emptyList());
contact.setEventCount((long) contactEvents.size());
contactEvents.stream().max(Comparator.comparing(ContactEventSummaryDetails::getEventDate)).ifPresent(eventSummary -> {
contact.setLatestEventId(eventSummary.getEventUuid());
contact.setLatestEventTitle(eventSummary.getEventTitle());
});
}
Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue));
User currentUser = userService.getCurrentUser();
pseudonymizer.pseudonymizeDtoCollection(ContactIndexDetailedDto.class, dtos, c -> c.getInJurisdiction(), (c, isInJurisdiction) -> {
pseudonymizer.pseudonymizeUser(userService.getByUuid(c.getReportingUser().getUuid()), currentUser, c::setReportingUser);
if (c.getCaze() != null) {
pseudonymizer.pseudonymizeDto(CaseReferenceDto.class, c.getCaze(), c.getCaseInJurisdiction(), null);
}
});
return dtos;
}
use of de.symeda.sormas.api.contact.ContactIndexDetailedDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbTest method testGetIndexDetailedList.
@Test
public void testGetIndexDetailedList() {
ContactCriteria contactCriteria = new ContactCriteria();
contactCriteria.setIncludeContactsFromOtherJurisdictions(true);
List<SortProperty> sortProperties = Collections.emptyList();
List<ContactIndexDetailedDto> result;
// 0. No data: empty list
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, is(empty()));
// Create needed structural data
RDCFEntities rdcf = creator.createRDCFEntities("Region", "District", "Community", "Facility");
UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
PersonDto cazePerson = creator.createPerson("Case", "Person");
CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
UserReferenceDto reportingUser = new UserReferenceDto(user.getUuid());
EventDto event1 = creator.createEvent(reportingUser, DateHelper.subtractDays(new Date(), 1));
EventDto event2 = creator.createEvent(reportingUser, new Date());
PersonDto contactPerson = creator.createPerson("Contact", "Person");
ContactDto contact1 = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null);
// 1a. one Contact without Event
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(0L));
assertNull(dto.getLatestEventId());
assertNull(dto.getLatestEventTitle());
assertThat(dto.getVisitCount(), equalTo(0));
}
// 1b. one Contact with one Event
creator.createEventParticipant(new EventReferenceDto(event1.getUuid()), contactPerson, reportingUser);
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(1L));
assertThat(dto.getLatestEventId(), equalTo(event1.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event1.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(0));
}
// 1c. one Contact with two Events, second is leading
creator.createEventParticipant(new EventReferenceDto(event2.getUuid()), contactPerson, reportingUser);
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(2L));
assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(0));
}
// 1d. one Contact with two Events and one visit
creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(2L));
assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(1));
}
// 1e. one Contact with two Events and three visits
creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
creator.createVisit(new PersonReferenceDto(contactPerson.getUuid()));
result = getContactFacade().getIndexDetailedList(contactCriteria, null, null, sortProperties);
assertThat(result, hasSize(1));
{
ContactIndexDetailedDto dto = result.get(0);
assertThat(dto.getUuid(), equalTo(contact1.getUuid()));
assertThat(dto.getEventCount(), equalTo(2L));
assertThat(dto.getLatestEventId(), equalTo(event2.getUuid()));
assertThat(dto.getLatestEventTitle(), equalTo(event2.getEventTitle()));
assertThat(dto.getVisitCount(), equalTo(3));
}
}
use of de.symeda.sormas.api.contact.ContactIndexDetailedDto in project SORMAS-Project by hzi-braunschweig.
the class ContactFacadeEjbPseudonymizationTest method testPseudonymizeIndexDetailedData.
@Test
public void testPseudonymizeIndexDetailedData() {
CaseDataDto caze = createCase(user1, rdcf1);
ContactDto contact1 = createContact(user2, caze, rdcf2);
// contact of case on other jurisdiction --> should be pseudonymized
ContactDto contact2 = creator.createContact(user1.toReference(), null, createPerson().toReference(), caze, new Date(), new Date(), Disease.CORONAVIRUS, rdcf2);
ContactCriteria contactCriteria = new ContactCriteria();
contactCriteria.setIncludeContactsFromOtherJurisdictions(true);
List<ContactIndexDetailedDto> indexList = getContactFacade().getIndexDetailedList(contactCriteria, null, null, Collections.emptyList());
ContactIndexDetailedDto index1 = indexList.stream().filter(c -> c.getUuid().equals(contact1.getUuid())).findFirst().get();
assertThat(index1.getFirstName(), is("James"));
assertThat(index1.getLastName(), is("Smith"));
assertThat(index1.getCaze().getFirstName(), is(is("Confidential")));
assertThat(index1.getCaze().getLastName(), is(is("Confidential")));
assertThat(index1.getReportingUser().getUuid(), is(user2.getUuid()));
ContactIndexDetailedDto index2 = indexList.stream().filter(c -> c.getUuid().equals(contact2.getUuid())).findFirst().get();
assertThat(index2.getFirstName(), is("Confidential"));
assertThat(index2.getLastName(), is("Confidential"));
assertThat(index2.getCaze().getFirstName(), is("Confidential"));
assertThat(index2.getCaze().getLastName(), is("Confidential"));
assertThat(index2.getReportingUser(), is(nullValue()));
}
use of de.symeda.sormas.api.contact.ContactIndexDetailedDto in project SORMAS-Project by hzi-braunschweig.
the class ContactGridDetailed method initColumns.
@Override
@SuppressWarnings("unchecked")
protected void initColumns() {
super.initColumns();
getColumn(ContactIndexDetailedDto.SEX).setWidth(80);
getColumn(ContactIndexDetailedDto.APPROXIMATE_AGE).setWidth(50);
getColumn(ContactIndexDetailedDto.DISTRICT_NAME).setWidth(150);
getColumn(ContactIndexDetailedDto.POSTAL_CODE).setWidth(100);
getColumn(ContactIndexDetailedDto.CITY).setWidth(150);
getColumn(ContactIndexDetailedDto.STREET).setWidth(150);
getColumn(ContactIndexDetailedDto.HOUSE_NUMBER).setWidth(50);
getColumn(ContactIndexDetailedDto.ADDITIONAL_INFORMATION).setWidth(200);
getColumn(ContactIndexDetailedDto.PHONE).setWidth(100);
((Column<ContactIndexDetailedDto, CaseReferenceDto>) getColumn(ContactIndexDetailedDto.CAZE)).setWidth(150).setRenderer(entry -> entry != null ? entry.getUuid() : null, new UuidRenderer());
getColumn(ContactIndexDetailedDto.REPORTING_USER).setWidth(150);
addItemClickListener(new ShowDetailsListener<>(ContactIndexDetailedDto.CAZE, false, e -> {
CaseReferenceDto caze = e.getCaze();
if (caze != null && caze.getUuid() != null) {
ControllerProvider.getCaseController().navigateToCase(caze.getUuid());
}
}));
getColumn(ContactIndexDetailedDto.LATEST_EVENT_ID).setWidth(80).setSortable(false);
getColumn(ContactIndexDetailedDto.LATEST_EVENT_TITLE).setWidth(150).setSortable(false);
((Column<ContactIndexDetailedDto, String>) getColumn(ContactIndexDetailedDto.LATEST_EVENT_ID)).setRenderer(new UuidRenderer());
addItemClickListener(new ShowDetailsListener<>(ContactIndexDetailedDto.LATEST_EVENT_ID, c -> ControllerProvider.getEventController().navigateToData(c.getLatestEventId())));
}
Aggregations