@Test public void downloadCohortsByPrefix_shouldDownloadAllCohortsForTheGivenPrefixes() throws IOException, CohortController.CohortDownloadException { List<String> cohortPrefixes = new ArrayList<String>() {{ add("Age"); add("age"); add("Encounter"); }}; Cohort cohort11 = new Cohort() {{ setUuid("uuid1"); setName("Age between 20 and 30"); }}; Cohort cohort12 = new Cohort() {{ setUuid("uuid1"); setName("Age between 20 and 30"); }}; Cohort cohort2 = new Cohort() {{ setUuid("uuid2"); setName("Patients with age over 65"); }}; Cohort cohort3 = new Cohort() {{ setUuid("uuid3"); setName("Encounter 1"); }}; Cohort cohort4 = new Cohort() {{ setUuid("uuid4"); setName("Encounter 2"); }}; ArrayList<Cohort> agePrefixedCohortList1 = new ArrayList<>(); agePrefixedCohortList1.add(cohort11); agePrefixedCohortList1.add(cohort2); ArrayList<Cohort> agePrefixedCohortList2 = new ArrayList<>(); agePrefixedCohortList2.add(cohort12); agePrefixedCohortList2.add(cohort2); ArrayList<Cohort> encounterPerfixedCohortList = new ArrayList<>(); encounterPerfixedCohortList.add(cohort3); encounterPerfixedCohortList.add(cohort4); when(cohortService.downloadCohortsByNameAndSyncDate(cohortPrefixes.get(0), mockDate, null, null)).thenReturn(agePrefixedCohortList1); when(cohortService.downloadCohortsByNameAndSyncDate(cohortPrefixes.get(1), anotherMockDate, null, null)).thenReturn(agePrefixedCohortList2); when(cohortService.downloadCohortsByNameAndSyncDate(cohortPrefixes.get(2), anotherMockDate, null, null)).thenReturn(encounterPerfixedCohortList); when(lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefixes.get(0))).thenReturn(anotherMockDate); when(lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefixes.get(1))).thenReturn(anotherMockDate); when(lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefixes.get(2))).thenReturn(anotherMockDate); when(lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS)).thenReturn(anotherMockDate); when(sntpService.getTimePerDeviceTimeZone()).thenReturn(mockDate); List<Cohort> downloadedCohorts = controller.downloadCohortsByPrefix(cohortPrefixes,null); assertThat(downloadedCohorts.size(), is(3)); assertTrue(downloadedCohorts.contains(cohort11)); assertTrue(downloadedCohorts.contains(cohort3)); assertTrue(downloadedCohorts.contains(cohort4)); }
public List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation) throws CohortDownloadException { Provider loggedInProvider = getLoggedInProvider(); List<Cohort> filteredCohorts = new ArrayList<>(); try { Date lastSyncDateOfCohort; LastSyncTime lastSyncTime; for (String cohortPrefix : cohortPrefixes) { lastSyncDateOfCohort = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefix); List<Cohort> cohorts = cohortService.downloadCohortsByNameAndSyncDate(cohortPrefix, lastSyncDateOfCohort, defaultLocation, loggedInProvider); List<Cohort> filteredCohortsForPrefix = filterCohortsByPrefix(cohorts, cohortPrefix); addUniqueCohorts(filteredCohorts, filteredCohortsForPrefix); lastSyncTime = new LastSyncTime(DOWNLOAD_COHORTS, sntpService.getTimePerDeviceTimeZone(), cohortPrefix); lastSyncTimeService.saveLastSyncTime(lastSyncTime); } } catch (IOException e) { throw new CohortDownloadException(e); } return filteredCohorts; }
CohortController { public List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation) throws CohortDownloadException { Provider loggedInProvider = getLoggedInProvider(); List<Cohort> filteredCohorts = new ArrayList<>(); try { Date lastSyncDateOfCohort; LastSyncTime lastSyncTime; for (String cohortPrefix : cohortPrefixes) { lastSyncDateOfCohort = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefix); List<Cohort> cohorts = cohortService.downloadCohortsByNameAndSyncDate(cohortPrefix, lastSyncDateOfCohort, defaultLocation, loggedInProvider); List<Cohort> filteredCohortsForPrefix = filterCohortsByPrefix(cohorts, cohortPrefix); addUniqueCohorts(filteredCohorts, filteredCohortsForPrefix); lastSyncTime = new LastSyncTime(DOWNLOAD_COHORTS, sntpService.getTimePerDeviceTimeZone(), cohortPrefix); lastSyncTimeService.saveLastSyncTime(lastSyncTime); } } catch (IOException e) { throw new CohortDownloadException(e); } return filteredCohorts; } }
CohortController { public List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation) throws CohortDownloadException { Provider loggedInProvider = getLoggedInProvider(); List<Cohort> filteredCohorts = new ArrayList<>(); try { Date lastSyncDateOfCohort; LastSyncTime lastSyncTime; for (String cohortPrefix : cohortPrefixes) { lastSyncDateOfCohort = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefix); List<Cohort> cohorts = cohortService.downloadCohortsByNameAndSyncDate(cohortPrefix, lastSyncDateOfCohort, defaultLocation, loggedInProvider); List<Cohort> filteredCohortsForPrefix = filterCohortsByPrefix(cohorts, cohortPrefix); addUniqueCohorts(filteredCohorts, filteredCohortsForPrefix); lastSyncTime = new LastSyncTime(DOWNLOAD_COHORTS, sntpService.getTimePerDeviceTimeZone(), cohortPrefix); lastSyncTimeService.saveLastSyncTime(lastSyncTime); } } catch (IOException e) { throw new CohortDownloadException(e); } return filteredCohorts; } CohortController(CohortService cohortService, LastSyncTimeService lastSyncTimeService, SntpService sntpService, MuzimaApplication muzimaApplication); }
CohortController { public List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation) throws CohortDownloadException { Provider loggedInProvider = getLoggedInProvider(); List<Cohort> filteredCohorts = new ArrayList<>(); try { Date lastSyncDateOfCohort; LastSyncTime lastSyncTime; for (String cohortPrefix : cohortPrefixes) { lastSyncDateOfCohort = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefix); List<Cohort> cohorts = cohortService.downloadCohortsByNameAndSyncDate(cohortPrefix, lastSyncDateOfCohort, defaultLocation, loggedInProvider); List<Cohort> filteredCohortsForPrefix = filterCohortsByPrefix(cohorts, cohortPrefix); addUniqueCohorts(filteredCohorts, filteredCohortsForPrefix); lastSyncTime = new LastSyncTime(DOWNLOAD_COHORTS, sntpService.getTimePerDeviceTimeZone(), cohortPrefix); lastSyncTimeService.saveLastSyncTime(lastSyncTime); } } catch (IOException e) { throw new CohortDownloadException(e); } return filteredCohorts; } CohortController(CohortService cohortService, LastSyncTimeService lastSyncTimeService, SntpService sntpService, MuzimaApplication muzimaApplication); String getDefaultLocation(); Provider getLoggedInProvider(); List<Cohort> getAllCohorts(); int countAllCohorts(); List<Cohort> downloadAllCohorts(String defaultLocation); List<CohortData> downloadCohortData(String[] cohortUuids, String defaulLocation); List<CohortData> downloadRemovedCohortData(String[] cohortUuids); CohortData downloadCohortDataByUuid(String uuid,String defaultLocation); CohortData downloadRemovedCohortDataByUuid(String uuid); List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation); void saveAllCohorts(List<Cohort> cohorts); void saveOrUpdateCohorts(List<Cohort> cohorts); void deleteAllCohorts(); void deleteCohorts(List<Cohort> cohorts); List<Cohort> getSyncedCohorts(); boolean isDownloaded(Cohort cohort); boolean isUpdateAvailable(); List<Cohort> getCohortsWithPendingUpdates(); void markAsUpToDate(String[] cohortUuids); void setSyncStatus(String[] cohortUuids); int countSyncedCohorts(); void deleteAllCohortMembers(String cohortUuid); void addCohortMembers(List<CohortMember> cohortMembers); int countCohortMembers(Cohort cohort); List<Cohort> downloadCohortByName(String name); List<Cohort> downloadCohortsByUuidList(String[] uuidList); List<CohortMember> getCohortMembershipByPatientUuid(String patientUuid); void deleteAllCohortMembers(List<Cohort> allCohorts); void deleteCohortMembers(List<CohortMember> cohortMembers); }
CohortController { public List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation) throws CohortDownloadException { Provider loggedInProvider = getLoggedInProvider(); List<Cohort> filteredCohorts = new ArrayList<>(); try { Date lastSyncDateOfCohort; LastSyncTime lastSyncTime; for (String cohortPrefix : cohortPrefixes) { lastSyncDateOfCohort = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_COHORTS, cohortPrefix); List<Cohort> cohorts = cohortService.downloadCohortsByNameAndSyncDate(cohortPrefix, lastSyncDateOfCohort, defaultLocation, loggedInProvider); List<Cohort> filteredCohortsForPrefix = filterCohortsByPrefix(cohorts, cohortPrefix); addUniqueCohorts(filteredCohorts, filteredCohortsForPrefix); lastSyncTime = new LastSyncTime(DOWNLOAD_COHORTS, sntpService.getTimePerDeviceTimeZone(), cohortPrefix); lastSyncTimeService.saveLastSyncTime(lastSyncTime); } } catch (IOException e) { throw new CohortDownloadException(e); } return filteredCohorts; } CohortController(CohortService cohortService, LastSyncTimeService lastSyncTimeService, SntpService sntpService, MuzimaApplication muzimaApplication); String getDefaultLocation(); Provider getLoggedInProvider(); List<Cohort> getAllCohorts(); int countAllCohorts(); List<Cohort> downloadAllCohorts(String defaultLocation); List<CohortData> downloadCohortData(String[] cohortUuids, String defaulLocation); List<CohortData> downloadRemovedCohortData(String[] cohortUuids); CohortData downloadCohortDataByUuid(String uuid,String defaultLocation); CohortData downloadRemovedCohortDataByUuid(String uuid); List<Cohort> downloadCohortsByPrefix(List<String> cohortPrefixes,String defaultLocation); void saveAllCohorts(List<Cohort> cohorts); void saveOrUpdateCohorts(List<Cohort> cohorts); void deleteAllCohorts(); void deleteCohorts(List<Cohort> cohorts); List<Cohort> getSyncedCohorts(); boolean isDownloaded(Cohort cohort); boolean isUpdateAvailable(); List<Cohort> getCohortsWithPendingUpdates(); void markAsUpToDate(String[] cohortUuids); void setSyncStatus(String[] cohortUuids); int countSyncedCohorts(); void deleteAllCohortMembers(String cohortUuid); void addCohortMembers(List<CohortMember> cohortMembers); int countCohortMembers(Cohort cohort); List<Cohort> downloadCohortByName(String name); List<Cohort> downloadCohortsByUuidList(String[] uuidList); List<CohortMember> getCohortMembershipByPatientUuid(String patientUuid); void deleteAllCohortMembers(List<Cohort> allCohorts); void deleteCohortMembers(List<CohortMember> cohortMembers);  }