VisitFacadeEjb implements VisitFacade { @Override public VisitDto getLastVisitByContact(ContactReferenceDto contactRef) { Contact contact = contactService.getByReferenceDto(contactRef); Pseudonymizer pseudonymizer = Pseudonymizer.getDefault(userService::hasRight); return convertToDto(contact.getVisits().stream().max(Comparator.comparing(Visit::getVisitDateTime)).orElse(null), pseudonymizer); }  @Override List<String> getAllActiveUuids(); @Override List<VisitDto> getAllActiveVisitsAfter(Date date); @Override List<VisitDto> getByUuids(List<String> uuids); @Override VisitDto getLastVisitByContact(ContactReferenceDto contactRef); @Override List<VisitDto> getVisitsByContactAndPeriod(ContactReferenceDto contactRef, Date begin, Date end); @Override VisitDto getLastVisitByCase(CaseReferenceDto caseRef); @Override VisitDto getVisitByUuid(String uuid); @Override VisitDto saveVisit(VisitDto dto); @Override ExternalVisitDto saveExternalVisit(final ExternalVisitDto dto); @Override void validate(VisitDto visit); @Override void deleteVisit(String visitUuid); @Override List<VisitIndexDto> getIndexList(VisitCriteria visitCriteria, Integer first, Integer max, List<SortProperty> sortProperties); @Override long count(VisitCriteria visitCriteria); @Override @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) List<VisitExportDto> getVisitsExportList(
		VisitCriteria visitCriteria,
		VisitExportType exportType,
		int first,
		int max,
		ExportConfigurationDto exportConfiguration); Visit fromDto(@NotNull VisitDto source); VisitDto convertToDto(Visit source, Pseudonymizer pseudonymizer); static VisitReferenceDto toReferenceDto(Visit source); static VisitDto toDto(Visit source);  }
@Test public void testGetLastVisitByContact() { UserDto user = creator.createUser(creator.createRDCFEntities(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR); PersonDto person = creator.createPerson(); ContactDto contact = creator.createContact(user.toReference(), person.toReference()); VisitDto visit = creator.createVisit(Disease.EVD, person.toReference(), new Date()); creator.createVisit(Disease.EVD, person.toReference(), DateHelper.subtractDays(new Date(), 1)); assertThat(getVisitFacade().getLastVisitByContact(contact.toReference()), is(visit)); }