ContactFacadeEjb implements ContactFacade { @Override public int getNonSourceCaseCountForDashboard(List<String> caseUuids) { if (CollectionUtils.isEmpty(caseUuids)) { return 0; } Query query = em.createNativeQuery( String.format( "SELECT DISTINCT count(case1_.id) FROM contact AS contact0_ LEFT OUTER JOIN cases AS case1_ ON (contact0_.%s_id = case1_.id) WHERE case1_.%s IN (%s)", Contact.RESULTING_CASE.toLowerCase(), Case.UUID, QueryHelper.concatStrings(caseUuids))); BigInteger count = (BigInteger) query.getSingleResult(); return count.intValue(); }  @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 testGetNonSourceCaseCountForDashboard() { ContactFacade cut = getBean(ContactFacadeEjbLocal.class); RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility"); UserDto user = creator .createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR); PersonDto person = creator.createPerson("Case", "Person"); Disease disease = Disease.OTHER; CaseDataDto caseWithoutContact = creator.createCase( user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf); assertThat(cut.getNonSourceCaseCountForDashboard(Collections.singletonList(caseWithoutContact.getUuid())), equalTo(0)); ContactDto contact = creator.createContact(user.toReference(), person.toReference(), disease); CaseDataDto caseWithContact = creator.createCase( user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf); contact.setResultingCase(caseWithContact.toReference()); contact = getContactFacade().saveContact(contact); assertThat(cut.getNonSourceCaseCountForDashboard(Arrays.asList(caseWithoutContact.getUuid(), caseWithContact.getUuid())), equalTo(1)); { CaseDataDto caseWithoutContact2 = creator.createCase( user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf); ContactDto contact2 = creator.createContact(user.toReference(), person.toReference(), disease); CaseDataDto caseWithContact2 = creator.createCase( user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf); contact2.setResultingCase(caseWithContact2.toReference()); contact2 = getContactFacade().saveContact(contact2); ContactDto contact3 = creator.createContact(user.toReference(), person.toReference(), disease); CaseDataDto caseWithContact3 = creator.createCase( user.toReference(), person.toReference(), disease, CaseClassification.CONFIRMED, InvestigationStatus.PENDING, new Date(), rdcf); contact3.setResultingCase(caseWithContact3.toReference()); contact3 = getContactFacade().saveContact(contact3); assertThat( cut.getNonSourceCaseCountForDashboard( Arrays.asList( caseWithoutContact.getUuid(), caseWithContact.getUuid(), caseWithoutContact2.getUuid(), caseWithContact2.getUuid(), caseWithContact3.getUuid())), equalTo(3)); } }
@Test public void testGetNonSourceCaseCountForDashboardVariousInClauseCount() { ContactFacade cut = getBean(ContactFacadeEjbLocal.class); assertThat(cut.getNonSourceCaseCountForDashboard(Collections.emptyList()), equalTo(0)); assertThat(cut.getNonSourceCaseCountForDashboard(null), equalTo(0)); assertThat(cut.getNonSourceCaseCountForDashboard(Collections.singletonList(DataHelper.createUuid())), equalTo(0)); assertThat(cut.getNonSourceCaseCountForDashboard(Arrays.asList(DataHelper.createUuid(), DataHelper.createUuid())), equalTo(0)); assertThat( cut.getNonSourceCaseCountForDashboard(Arrays.asList(DataHelper.createUuid(), DataHelper.createUuid(), DataHelper.createUuid())), equalTo(0)); assertThat(cut.getNonSourceCaseCountForDashboard(TestDataCreator.createValuesList(1_000, i -> DataHelper.createUuid())), equalTo(0)); assertThat(cut.getNonSourceCaseCountForDashboard(TestDataCreator.createValuesList(100_000, i -> DataHelper.createUuid())), equalTo(0)); }