Search in sources :

Example 1 with ContactIndexDetailedDto

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;
}
Also used : Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) User(de.symeda.sormas.backend.user.User) ContactLogic(de.symeda.sormas.api.contact.ContactLogic) ContactEventSummaryDetails(de.symeda.sormas.backend.event.ContactEventSummaryDetails) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto)

Example 2 with ContactIndexDetailedDto

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));
    }
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) EventDto(de.symeda.sormas.api.event.EventDto) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) Date(java.util.Date) LocalDate(java.time.LocalDate) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) EventReferenceDto(de.symeda.sormas.api.event.EventReferenceDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) MapContactDto(de.symeda.sormas.api.contact.MapContactDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with ContactIndexDetailedDto

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()));
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) ContactDto(de.symeda.sormas.api.contact.ContactDto) SimilarContactDto(de.symeda.sormas.api.contact.SimilarContactDto) ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) Date(java.util.Date) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with ContactIndexDetailedDto

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())));
}
Also used : ContactCriteria(de.symeda.sormas.api.contact.ContactCriteria) UuidRenderer(de.symeda.sormas.ui.utils.UuidRenderer) FacadeProvider(de.symeda.sormas.api.FacadeProvider) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) SortProperty(de.symeda.sormas.api.utils.SortProperty) Collectors(java.util.stream.Collectors) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) ShowDetailsListener(de.symeda.sormas.ui.utils.ShowDetailsListener) List(java.util.List) Stream(java.util.stream.Stream) ViewConfiguration(de.symeda.sormas.ui.utils.ViewConfiguration) View(com.vaadin.navigator.View) UuidRenderer(de.symeda.sormas.ui.utils.UuidRenderer) ContactIndexDetailedDto(de.symeda.sormas.api.contact.ContactIndexDetailedDto) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto)

Aggregations

ContactIndexDetailedDto (de.symeda.sormas.api.contact.ContactIndexDetailedDto)4 ContactCriteria (de.symeda.sormas.api.contact.ContactCriteria)3 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 ContactDto (de.symeda.sormas.api.contact.ContactDto)2 SimilarContactDto (de.symeda.sormas.api.contact.SimilarContactDto)2 SortProperty (de.symeda.sormas.api.utils.SortProperty)2 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 Date (java.util.Date)2 List (java.util.List)2 Test (org.junit.Test)2 View (com.vaadin.navigator.View)1 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 CaseReferenceDto (de.symeda.sormas.api.caze.CaseReferenceDto)1 ContactLogic (de.symeda.sormas.api.contact.ContactLogic)1 MapContactDto (de.symeda.sormas.api.contact.MapContactDto)1 EventDto (de.symeda.sormas.api.event.EventDto)1 EventReferenceDto (de.symeda.sormas.api.event.EventReferenceDto)1 PersonDto (de.symeda.sormas.api.person.PersonDto)1 PersonReferenceDto (de.symeda.sormas.api.person.PersonReferenceDto)1 UserDto (de.symeda.sormas.api.user.UserDto)1