VisitFacadeEjb implements VisitFacade { private void updateContactVisitAssociations(VisitDto existingVisit, Visit visit) { if (existingVisit != null && existingVisit.getVisitDateTime() == visit.getVisitDateTime()) { return; } Set<Contact> contacts = contactService.getAllRelevantContacts(visit.getPerson(), visit.getDisease(), visit.getVisitDateTime()); visit.setContacts(contacts); for (Contact contact : contacts) { contact.getVisits().add(visit); } }  @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 testUpdateContactVisitAssociations() { UserDto user = creator.createUser(creator.createRDCFEntities(), UserRole.SURVEILLANCE_SUPERVISOR); PersonDto person = creator.createPerson(); ContactDto contact = creator.createContact(user.toReference(), person.toReference()); VisitDto visit = creator.createVisit(contact.getDisease(), person.toReference()); Visit visitEntity = getVisitService().getByUuid(visit.getUuid()); Contact contactEntity = getContactService().getByUuid(contact.getUuid()); assertThat(getContactService().getAllByVisit(visitEntity), hasSize(1)); visit.setVisitStatus(VisitStatus.UNCOOPERATIVE); getVisitFacade().saveVisit(visit); assertThat(getContactService().getAllByVisit(visitEntity), hasSize(1)); visit.setVisitDateTime(DateHelper.addDays(contact.getFollowUpUntil(), FollowUpLogic.ALLOWED_DATE_OFFSET + 1)); getVisitFacade().saveVisit(visit); assertThat(getContactService().getAllByVisit(visitEntity), empty()); visit.setVisitDateTime(new Date()); getVisitFacade().saveVisit(visit); assertThat(getContactService().getAllByVisit(visitEntity), hasSize(1)); creator.createVisit(contact.getDisease(), person.toReference()); assertThat(getVisitService().getAllByContact(contactEntity), hasSize(2)); creator.createVisit( contact.getDisease(), person.toReference(), DateHelper.subtractDays(contact.getReportDateTime(), FollowUpLogic.ALLOWED_DATE_OFFSET + 1)); assertThat(getVisitService().getAllByContact(contactEntity), hasSize(2)); PersonDto person2 = creator.createPerson(); creator.createVisit(contact.getDisease(), person2.toReference()); creator.createVisit(Disease.CSM, person.toReference()); assertThat(getVisitService().getAllByContact(contactEntity), hasSize(2)); }