ContactFacadeEjb implements ContactFacade { @Override public List<VisitSummaryExportDto> getVisitSummaryExportList(ContactCriteria contactCriteria, int first, int max, Language userLanguage) { final CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaQuery<VisitSummaryExportDto> cq = cb.createQuery(VisitSummaryExportDto.class); final Root<Contact> contactRoot = cq.from(Contact.class); final Join<Contact, Person> contactPerson = contactRoot.join(Contact.PERSON, JoinType.LEFT); cq.multiselect( contactRoot.get(Contact.UUID), contactRoot.get(Contact.ID), contactPerson.get(Person.FIRST_NAME), contactPerson.get(Person.LAST_NAME), cb.<Date> selectCase() .when(cb.isNotNull(contactRoot.get(Contact.LAST_CONTACT_DATE)), contactRoot.get(Contact.LAST_CONTACT_DATE)) .otherwise(contactRoot.get(Contact.REPORT_DATE_TIME)), contactRoot.get(Contact.FOLLOW_UP_UNTIL)); cq.where( AbstractAdoService.and( cb, listCriteriaBuilder.buildContactFilter(contactCriteria, cb, contactRoot, cq), cb.isNotEmpty(contactRoot.get(Contact.VISITS)))); cq.orderBy(cb.asc(contactRoot.get(Contact.REPORT_DATE_TIME))); List<VisitSummaryExportDto> visitSummaries = em.createQuery(cq).setFirstResult(first).setMaxResults(max).getResultList(); if (!visitSummaries.isEmpty()) { List<String> visitSummaryUuids = visitSummaries.stream().map(e -> e.getUuid()).collect(Collectors.toList()); CriteriaQuery<VisitSummaryExportDetails> visitsCq = cb.createQuery(VisitSummaryExportDetails.class); Root<Contact> visitsCqRoot = visitsCq.from(Contact.class); ContactJoins joins = new ContactJoins(visitsCqRoot); visitsCq.where( ContactService .and(cb, contactRoot.get(AbstractDomainObject.UUID).in(visitSummaryUuids), cb.isNotEmpty(visitsCqRoot.get(Contact.VISITS)))); visitsCq.multiselect( Stream .concat( Stream.of( visitsCqRoot.get(AbstractDomainObject.ID), joins.getVisits().get(Visit.VISIT_DATE_TIME), joins.getVisits().get(Visit.VISIT_STATUS), joins.getVisitSymptoms()), listCriteriaBuilder.getJurisdictionSelections(joins)) .collect(Collectors.toList())); visitsCq.orderBy(cb.asc(joins.getVisits().get(Visit.VISIT_DATE_TIME))); List<VisitSummaryExportDetails> visitSummaryDetails = em.createQuery(visitsCq).getResultList(); Map<Long, VisitSummaryExportDto> visitSummaryMap = visitSummaries.stream().collect(Collectors.toMap(VisitSummaryExportDto::getContactId, Function.identity())); Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight, I18nProperties.getCaption(Captions.inaccessibleValue)); visitSummaryDetails.forEach(v -> { SymptomsDto symptoms = SymptomsFacadeEjb.toDto(v.getSymptoms()); pseudonymizer .pseudonymizeDto(SymptomsDto.class, symptoms, contactJurisdictionChecker.isInJurisdictionOrOwned(v.getJurisdiction()), null); visitSummaryMap.get(v.getContactId()) .getVisitDetails() .add( new VisitSummaryExportDetailsDto( v.getVisitDateTime(), v.getVisitStatus(), SymptomsHelper.buildSymptomsHumanString(symptoms, true, userLanguage))); }); } return visitSummaries; }  @Override List<String> getAllActiveUuids(); @Override List<ContactDto> getAllActiveContactsAfter(Date date); @Override List<ContactDto> getByUuids(List<String> uuids); @Override List<String> getDeletedUuidsSince(Date since); @Override ContactDto getContactByUuid(String uuid); @Override Boolean isValidContactUuid(String uuid); @Override ContactReferenceDto getReferenceByUuid(String uuid); @Override ContactDto saveContact(ContactDto dto); @Override ContactDto saveContact(ContactDto dto, boolean handleChanges); @Override List<MapContactDto> getContactsForMap(
		RegionReferenceDto regionRef,
		DistrictReferenceDto districtRef,
		Disease disease,
		Date fromDate,
		Date toDate,
		List<MapCaseDto> mapCaseDtos); @Override void deleteContact(String contactUuid); @Override List<ContactExportDto> getExportList(ContactCriteria contactCriteria, int first, int max, Language userLanguage); @Override List<VisitSummaryExportDto> getVisitSummaryExportList(ContactCriteria contactCriteria, int first, int max, Language userLanguage); @Override long countMaximumFollowUpDays(ContactCriteria contactCriteria); @Override long count(ContactCriteria contactCriteria); @Override List<ContactFollowUpDto> getContactFollowUpList(
		ContactCriteria contactCriteria,
		Date referenceDate,
		int interval,
		Integer first,
		Integer max,
		List<SortProperty> sortProperties); @Override List<ContactIndexDto> getIndexList(ContactCriteria contactCriteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override List<ContactIndexDetailedDto> getIndexDetailedList(
		ContactCriteria contactCriteria,
		Integer first,
		Integer max,
		List<SortProperty> sortProperties); @Override int[] getContactCountsByCasesForDashboard(List<Long> contactIds); @Override int getNonSourceCaseCountForDashboard(List<String> caseUuids); Contact fromDto(@NotNull ContactDto source); @Override boolean isDeleted(String contactUuid); @Override List<DashboardContactDto> getContactsForDashboard(
		RegionReferenceDto regionRef,
		DistrictReferenceDto districtRef,
		Disease disease,
		Date from,
		Date to); @Override List<DashboardQuarantineDataDto> getQuarantineDataForDashBoard(
		RegionReferenceDto regionRef,
		DistrictReferenceDto districtRef,
		Disease disease,
		Date from,
		Date to); @Override Map<ContactStatus, Long> getNewContactCountPerStatus(ContactCriteria contactCriteria); @Override Map<ContactClassification, Long> getNewContactCountPerClassification(ContactCriteria contactCriteria); @Override Map<FollowUpStatus, Long> getNewContactCountPerFollowUpStatus(ContactCriteria contactCriteria); @Override int getFollowUpUntilCount(ContactCriteria contactCriteria); ContactDto convertToDto(Contact source, Pseudonymizer pseudonymizer); static ContactReferenceDto toReferenceDto(Contact source); static ContactDto toDto(Contact source); @RolesAllowed(UserRole._SYSTEM) @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) void generateContactFollowUpTasks(); @Override void validate(ContactDto contact); @Override List<SimilarContactDto> getMatchingContacts(ContactSimilarityCriteria criteria); @Override boolean exists(String uuid); @Override boolean isContactEditAllowed(String contactUuid);  }
@Test public void testGetVisitSummaryExportList() { 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); String userUuid = user.getUuid(); PersonDto cazePerson = creator.createPerson("Case", "Person"); CaseDataDto caze = creator.createCase( user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf); PersonDto contactPerson = creator.createPerson("Contact", "Person"); ContactDto contact = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null); ContactDto contact2 = creator.createContact(user.toReference(), user.toReference(), contactPerson.toReference(), caze, new Date(), new Date(), null); VisitDto visit11 = creator.createVisit(caze.getDisease(), contactPerson.toReference(), new Date(), VisitStatus.COOPERATIVE); visit11.getSymptoms().setAbdominalPain(SymptomState.YES); getVisitFacade().saveVisit(visit11); VisitDto visit12 = creator.createVisit(caze.getDisease(), contactPerson.toReference(), DateHelper.subtractDays(new Date(), 1), VisitStatus.COOPERATIVE); visit12.getSymptoms().setChestPain(SymptomState.YES); getVisitFacade().saveVisit(visit12); PersonDto contactPersonWithoutFollowUp = creator.createPerson(); creator.createContact(user.toReference(), contactPersonWithoutFollowUp.toReference()); PersonDto contactPerson2 = creator.createPerson("Contact2", "Person2"); ContactDto contact3 = creator.createContact(user.toReference(), user.toReference(), contactPerson2.toReference(), caze, new Date(), null, null); VisitDto visit21 = creator.createVisit(caze.getDisease(), contactPerson2.toReference(), new Date(), VisitStatus.COOPERATIVE); visit21.getSymptoms().setBackache(SymptomState.YES); getVisitFacade().saveVisit(visit21); final List<VisitSummaryExportDto> results = getContactFacade().getVisitSummaryExportList(null, 0, 100, Language.EN); assertNotNull(results); assertEquals(3, results.size()); final VisitSummaryExportDto exportDto1 = results.get(0); assertEquals("Contact", exportDto1.getFirstName()); assertEquals("Person", exportDto1.getLastName()); assertEquals(contact.getUuid(), exportDto1.getUuid()); final List<VisitSummaryExportDetailsDto> visitDetails = exportDto1.getVisitDetails(); assertNotNull(visitDetails); assertEquals(2, visitDetails.size()); final VisitSummaryExportDetailsDto visitDetail11 = visitDetails.get(0); assertEquals(VisitStatus.COOPERATIVE, visitDetail11.getVisitStatus()); assertNotNull(visitDetail11.getVisitDateTime()); assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.CHEST_PAIN), visitDetail11.getSymptoms()); final VisitSummaryExportDetailsDto visitDetail12 = visitDetails.get(1); assertEquals(VisitStatus.COOPERATIVE, visitDetail12.getVisitStatus()); assertNotNull(visitDetail12.getVisitDateTime()); assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ABDOMINAL_PAIN), visitDetail12.getSymptoms()); final VisitSummaryExportDto exportDto2 = results.get(1); assertEquals("Contact", exportDto2.getFirstName()); assertEquals("Person", exportDto2.getLastName()); assertEquals(contact2.getUuid(), exportDto2.getUuid()); final List<VisitSummaryExportDetailsDto> visitDetails2 = exportDto1.getVisitDetails(); assertNotNull(visitDetails2); assertEquals(2, visitDetails2.size()); final VisitSummaryExportDetailsDto visitDetail21 = visitDetails2.get(0); assertEquals(VisitStatus.COOPERATIVE, visitDetail21.getVisitStatus()); assertNotNull(visitDetail21.getVisitDateTime()); assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.CHEST_PAIN), visitDetail21.getSymptoms()); final VisitSummaryExportDetailsDto visitDetail22 = visitDetails2.get(1); assertEquals(VisitStatus.COOPERATIVE, visitDetail22.getVisitStatus()); assertNotNull(visitDetail22.getVisitDateTime()); assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ABDOMINAL_PAIN), visitDetail22.getSymptoms()); final VisitSummaryExportDto exportDto3 = results.get(2); assertEquals("Contact2", exportDto3.getFirstName()); assertEquals("Person2", exportDto3.getLastName()); assertEquals(contact3.getUuid(), exportDto3.getUuid()); final List<VisitSummaryExportDetailsDto> visitDetails3 = exportDto3.getVisitDetails(); assertNotNull(visitDetails3); assertEquals(1, visitDetails3.size()); final VisitSummaryExportDetailsDto visitDetail31 = visitDetails3.get(0); assertEquals(VisitStatus.COOPERATIVE, visitDetail31.getVisitStatus()); assertNotNull(visitDetail31.getVisitDateTime()); assertEquals(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.BACKACHE), visitDetail31.getSymptoms()); }