ContactFacadeEjb implements ContactFacade { private void updateContactVisitAssociations(ContactDto existingContact, Contact contact) { if (existingContact != null && existingContact.getReportDateTime() == contact.getReportDateTime() && existingContact.getLastContactDate() == contact.getLastContactDate() && existingContact.getFollowUpUntil() == contact.getFollowUpUntil() && existingContact.getDisease() == contact.getDisease()) { return; } if (existingContact != null) { for (Visit visit : contact.getVisits()) { visit.getContacts().remove(contact); } } Date contactStartDate = ContactLogic.getStartDate(contact.getLastContactDate(), contact.getReportDateTime()); for (Visit visit : visitService.getAllRelevantVisits( contact.getPerson(), contact.getDisease(), contactStartDate, contact.getFollowUpUntil() != null ? contact.getFollowUpUntil() : contactStartDate)) { contact.getVisits().add(visit); visit.getContacts().add(contact); } }  @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 testUpdateContactVisitAssociations() { UserDto user = creator.createUser(creator.createRDCFEntities(), UserRole.SURVEILLANCE_SUPERVISOR); PersonDto person = creator.createPerson(); VisitDto visit = creator.createVisit(Disease.EVD, person.toReference()); ContactDto contact = creator.createContact(user.toReference(), person.toReference()); Contact contactEntity = getContactService().getByUuid(contact.getUuid()); Visit visitEntity = getVisitService().getByUuid(visit.getUuid()); assertThat(getVisitService().getAllByContact(contactEntity), hasSize(1)); contact.setDescription("Description"); getContactFacade().saveContact(contact); assertThat(getVisitService().getAllByContact(contactEntity), hasSize(1)); contact.setReportDateTime(DateHelper.addDays(visit.getVisitDateTime(), FollowUpLogic.ALLOWED_DATE_OFFSET + 20)); getContactFacade().saveContact(contact); assertThat(getVisitService().getAllByContact(contactEntity), empty()); contact.setReportDateTime(new Date()); getContactFacade().saveContact(contact); assertThat(getVisitService().getAllByContact(contactEntity), hasSize(1)); ContactDto contact2 = creator.createContact(user.toReference(), person.toReference()); assertThat(getContactService().getAllByVisit(visitEntity), hasSize(2)); creator.createContact( user.toReference(), person.toReference(), DateHelper.addDays(visit.getVisitDateTime(), FollowUpLogic.ALLOWED_DATE_OFFSET + 1)); assertThat(getContactService().getAllByVisit(visitEntity), hasSize(2)); PersonDto person2 = creator.createPerson(); creator.createContact(user.toReference(), person2.toReference()); creator.createContact(user.toReference(), person.toReference(), Disease.CSM); assertThat(getContactService().getAllByVisit(visitEntity), hasSize(2)); contact2.setDisease(Disease.CSM); getContactFacade().saveContact(contact2); assertThat(getContactService().getAllByVisit(visitEntity), hasSize(1)); }