@Test public void downloadPatientsForCohorts_shouldDownloadAndReplaceCohortMembersAndPatients() throws CohortController.CohortDownloadException, CohortController.CohortReplaceException, PatientController.PatientSaveException, CohortController.CohortUpdateException, ProviderController.ProviderLoadException { String[] cohortUuids = new String[]{"uuid1", "uuid2"}; List<CohortData> cohortDataList = new ArrayList<CohortData>() {{ add(new CohortData() {{ addCohortMember(new CohortMember()); addPatient(new Patient()); }}); add(new CohortData() {{ addCohortMember(new CohortMember()); addPatient(new Patient()); }}); }}; when(cohortController.downloadCohortData(cohortUuids, null)).thenReturn(cohortDataList); when(cohortController.downloadRemovedCohortData(cohortUuids)).thenReturn(new ArrayList<CohortData>()); muzimaSyncService.downloadPatientsForCohorts(cohortUuids); verify(cohortController).downloadCohortData(cohortUuids, null ); verify(cohortController).addCohortMembers(cohortDataList.get(0).getCohortMembers()); verify(cohortController).addCohortMembers(cohortDataList.get(1).getCohortMembers()); verify(cohortController).downloadRemovedCohortData(cohortUuids); verify(cohortController).markAsUpToDate(cohortUuids); verify(cohortController).setSyncStatus(cohortUuids); verify(patientController).replacePatients(cohortDataList.get(0).getPatients()); verify(patientController).replacePatients(cohortDataList.get(1).getPatients()); verifyNoMoreInteractions(cohortController); }
public int[] downloadPatientsForCohorts(String[] cohortUuids) { int[] result = new int[4]; int patientCount = 0; try { long startDownloadCohortData = System.currentTimeMillis(); List<CohortData> cohortDataList = cohortController.downloadCohortData(cohortUuids, getDefaultLocation()); long endDownloadCohortData = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data download successful with " + cohortDataList.size() + " cohorts"); ArrayList<Patient> voidedPatients = new ArrayList<>(); List<Patient> cohortPatients; for (CohortData cohortData : cohortDataList) { cohortController.addCohortMembers(cohortData.getCohortMembers()); cohortPatients = cohortData.getPatients(); getVoidedPatients(voidedPatients, cohortPatients); cohortPatients.removeAll(voidedPatients); patientController.replacePatients(cohortPatients); patientCount += cohortData.getPatients().size(); } patientController.deletePatient(voidedPatients); long cohortMemberAndPatientReplaceTime = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data replaced"); Log.i(getClass().getSimpleName(), "Patients downloaded " + patientCount); Log.d(getClass().getSimpleName(), "In Downloading cohort data: " + (endDownloadCohortData - startDownloadCohortData) / 1000 + " sec\n" + "In Replacing cohort members and patients: " + (cohortMemberAndPatientReplaceTime - endDownloadCohortData) / 1000 + " sec"); result[0] = SUCCESS; result[1] = patientCount; result[2] = cohortDataList.size(); result[3] = voidedPatients.size(); downloadRemovedCohortMembershipData(cohortUuids); cohortController.markAsUpToDate(cohortUuids); cohortController.setSyncStatus(cohortUuids); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while downloading cohort data.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (CohortController.CohortReplaceException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing cohort data.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing patients.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientDeleteException e) { Log.e(getClass().getSimpleName(), "Exception thrown while deleting patients.", e); result[0] = SyncStatusConstants.DELETE_ERROR; } catch (CohortController.CohortUpdateException e) { Log.e(getClass().getSimpleName(), "Exception thrown while marking cohorts as updated.", e); result[0] = SyncStatusConstants.SAVE_ERROR; } return result; }
MuzimaSyncService { public int[] downloadPatientsForCohorts(String[] cohortUuids) { int[] result = new int[4]; int patientCount = 0; try { long startDownloadCohortData = System.currentTimeMillis(); List<CohortData> cohortDataList = cohortController.downloadCohortData(cohortUuids, getDefaultLocation()); long endDownloadCohortData = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data download successful with " + cohortDataList.size() + " cohorts"); ArrayList<Patient> voidedPatients = new ArrayList<>(); List<Patient> cohortPatients; for (CohortData cohortData : cohortDataList) { cohortController.addCohortMembers(cohortData.getCohortMembers()); cohortPatients = cohortData.getPatients(); getVoidedPatients(voidedPatients, cohortPatients); cohortPatients.removeAll(voidedPatients); patientController.replacePatients(cohortPatients); patientCount += cohortData.getPatients().size(); } patientController.deletePatient(voidedPatients); long cohortMemberAndPatientReplaceTime = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data replaced"); Log.i(getClass().getSimpleName(), "Patients downloaded " + patientCount); Log.d(getClass().getSimpleName(), "In Downloading cohort data: " + (endDownloadCohortData - startDownloadCohortData) / 1000 + " sec\n" + "In Replacing cohort members and patients: " + (cohortMemberAndPatientReplaceTime - endDownloadCohortData) / 1000 + " sec"); result[0] = SUCCESS; result[1] = patientCount; result[2] = cohortDataList.size(); result[3] = voidedPatients.size(); downloadRemovedCohortMembershipData(cohortUuids); cohortController.markAsUpToDate(cohortUuids); cohortController.setSyncStatus(cohortUuids); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while downloading cohort data.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (CohortController.CohortReplaceException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing cohort data.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing patients.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientDeleteException e) { Log.e(getClass().getSimpleName(), "Exception thrown while deleting patients.", e); result[0] = SyncStatusConstants.DELETE_ERROR; } catch (CohortController.CohortUpdateException e) { Log.e(getClass().getSimpleName(), "Exception thrown while marking cohorts as updated.", e); result[0] = SyncStatusConstants.SAVE_ERROR; } return result; } }
MuzimaSyncService { public int[] downloadPatientsForCohorts(String[] cohortUuids) { int[] result = new int[4]; int patientCount = 0; try { long startDownloadCohortData = System.currentTimeMillis(); List<CohortData> cohortDataList = cohortController.downloadCohortData(cohortUuids, getDefaultLocation()); long endDownloadCohortData = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data download successful with " + cohortDataList.size() + " cohorts"); ArrayList<Patient> voidedPatients = new ArrayList<>(); List<Patient> cohortPatients; for (CohortData cohortData : cohortDataList) { cohortController.addCohortMembers(cohortData.getCohortMembers()); cohortPatients = cohortData.getPatients(); getVoidedPatients(voidedPatients, cohortPatients); cohortPatients.removeAll(voidedPatients); patientController.replacePatients(cohortPatients); patientCount += cohortData.getPatients().size(); } patientController.deletePatient(voidedPatients); long cohortMemberAndPatientReplaceTime = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data replaced"); Log.i(getClass().getSimpleName(), "Patients downloaded " + patientCount); Log.d(getClass().getSimpleName(), "In Downloading cohort data: " + (endDownloadCohortData - startDownloadCohortData) / 1000 + " sec\n" + "In Replacing cohort members and patients: " + (cohortMemberAndPatientReplaceTime - endDownloadCohortData) / 1000 + " sec"); result[0] = SUCCESS; result[1] = patientCount; result[2] = cohortDataList.size(); result[3] = voidedPatients.size(); downloadRemovedCohortMembershipData(cohortUuids); cohortController.markAsUpToDate(cohortUuids); cohortController.setSyncStatus(cohortUuids); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while downloading cohort data.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (CohortController.CohortReplaceException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing cohort data.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing patients.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientDeleteException e) { Log.e(getClass().getSimpleName(), "Exception thrown while deleting patients.", e); result[0] = SyncStatusConstants.DELETE_ERROR; } catch (CohortController.CohortUpdateException e) { Log.e(getClass().getSimpleName(), "Exception thrown while marking cohorts as updated.", e); result[0] = SyncStatusConstants.SAVE_ERROR; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); }
MuzimaSyncService { public int[] downloadPatientsForCohorts(String[] cohortUuids) { int[] result = new int[4]; int patientCount = 0; try { long startDownloadCohortData = System.currentTimeMillis(); List<CohortData> cohortDataList = cohortController.downloadCohortData(cohortUuids, getDefaultLocation()); long endDownloadCohortData = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data download successful with " + cohortDataList.size() + " cohorts"); ArrayList<Patient> voidedPatients = new ArrayList<>(); List<Patient> cohortPatients; for (CohortData cohortData : cohortDataList) { cohortController.addCohortMembers(cohortData.getCohortMembers()); cohortPatients = cohortData.getPatients(); getVoidedPatients(voidedPatients, cohortPatients); cohortPatients.removeAll(voidedPatients); patientController.replacePatients(cohortPatients); patientCount += cohortData.getPatients().size(); } patientController.deletePatient(voidedPatients); long cohortMemberAndPatientReplaceTime = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data replaced"); Log.i(getClass().getSimpleName(), "Patients downloaded " + patientCount); Log.d(getClass().getSimpleName(), "In Downloading cohort data: " + (endDownloadCohortData - startDownloadCohortData) / 1000 + " sec\n" + "In Replacing cohort members and patients: " + (cohortMemberAndPatientReplaceTime - endDownloadCohortData) / 1000 + " sec"); result[0] = SUCCESS; result[1] = patientCount; result[2] = cohortDataList.size(); result[3] = voidedPatients.size(); downloadRemovedCohortMembershipData(cohortUuids); cohortController.markAsUpToDate(cohortUuids); cohortController.setSyncStatus(cohortUuids); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while downloading cohort data.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (CohortController.CohortReplaceException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing cohort data.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing patients.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientDeleteException e) { Log.e(getClass().getSimpleName(), "Exception thrown while deleting patients.", e); result[0] = SyncStatusConstants.DELETE_ERROR; } catch (CohortController.CohortUpdateException e) { Log.e(getClass().getSimpleName(), "Exception thrown while marking cohorts as updated.", e); result[0] = SyncStatusConstants.SAVE_ERROR; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); int authenticate(String[] credentials); int authenticate(String[] credentials, boolean isUpdatePasswordRequired); int[] downloadForms(); int[] downloadFormTemplatesAndRelatedMetadata(String[] formIds, boolean replaceExistingTemplates); int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates); int[] downloadLocations(String[] locationIds); int[] downloadProviders(String[] providerIds); int[] downloadConcepts(String[] conceptIds); int[] downloadCohorts(); int[] downloadCohorts(String[] cohortUuids); int[] downloadPatientsForCohortsWithUpdatesAvailable(); int[] downloadRemovedCohortMembershipData(String[] cohortUuids); int[] downloadPatientsForCohorts(String[] cohortUuids); int[] downloadPatients(String[] patientUUIDs); int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation); int[] downloadObservationsForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingObservations); int[] downloadEncountersForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingEncounters); int[] downloadEncountersForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingEncounters); int[] uploadAllCompletedForms(); void consolidatePatients(); List<FormData> getArchivedFormData(); int[] checkAndDeleteTemporaryDataForProcessedFormData(List<FormData> archivedFormData); List<String> getUuidsForAllPatientsFromLocalStorage(); List<Patient> updatePatientsNotPartOfCohorts(); int[] downloadNotifications(String receiverUuid); int[] downloadPatientReportHeaders(String patientUuid); int[] downloadAllPatientReportHeadersAndReports(); int[] downloadPatientReportsByUuid(String[] reportUuids); void downloadSetupConfigurations(); int[] downloadSetupConfigurationTemplate(String uuid); int[] downloadAndSaveUpdatedSetupConfigurationTemplate(String uuid); int[] updateSetupConfigurationTemplates(); int[] downloadSetting(String property); int[] downloadNewSettings(); void updateSettingsPreferences(List<MuzimaSetting> muzimaSettings); int[] downloadRelationshipsTypes(); int[] downloadRelationshipsForPatientsByPatientUUIDs(List<String> patientUuids); int[] downloadRelationshipsForPatientsByCohortUUIDs(String[] cohortUuids); String getDefaultLocation(); }
MuzimaSyncService { public int[] downloadPatientsForCohorts(String[] cohortUuids) { int[] result = new int[4]; int patientCount = 0; try { long startDownloadCohortData = System.currentTimeMillis(); List<CohortData> cohortDataList = cohortController.downloadCohortData(cohortUuids, getDefaultLocation()); long endDownloadCohortData = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data download successful with " + cohortDataList.size() + " cohorts"); ArrayList<Patient> voidedPatients = new ArrayList<>(); List<Patient> cohortPatients; for (CohortData cohortData : cohortDataList) { cohortController.addCohortMembers(cohortData.getCohortMembers()); cohortPatients = cohortData.getPatients(); getVoidedPatients(voidedPatients, cohortPatients); cohortPatients.removeAll(voidedPatients); patientController.replacePatients(cohortPatients); patientCount += cohortData.getPatients().size(); } patientController.deletePatient(voidedPatients); long cohortMemberAndPatientReplaceTime = System.currentTimeMillis(); Log.i(getClass().getSimpleName(), "Cohort data replaced"); Log.i(getClass().getSimpleName(), "Patients downloaded " + patientCount); Log.d(getClass().getSimpleName(), "In Downloading cohort data: " + (endDownloadCohortData - startDownloadCohortData) / 1000 + " sec\n" + "In Replacing cohort members and patients: " + (cohortMemberAndPatientReplaceTime - endDownloadCohortData) / 1000 + " sec"); result[0] = SUCCESS; result[1] = patientCount; result[2] = cohortDataList.size(); result[3] = voidedPatients.size(); downloadRemovedCohortMembershipData(cohortUuids); cohortController.markAsUpToDate(cohortUuids); cohortController.setSyncStatus(cohortUuids); } catch (CohortController.CohortDownloadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while downloading cohort data.", e); result[0] = SyncStatusConstants.DOWNLOAD_ERROR; } catch (CohortController.CohortReplaceException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing cohort data.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientSaveException e) { Log.e(getClass().getSimpleName(), "Exception thrown while replacing patients.", e); result[0] = SyncStatusConstants.REPLACE_ERROR; } catch (PatientController.PatientDeleteException e) { Log.e(getClass().getSimpleName(), "Exception thrown while deleting patients.", e); result[0] = SyncStatusConstants.DELETE_ERROR; } catch (CohortController.CohortUpdateException e) { Log.e(getClass().getSimpleName(), "Exception thrown while marking cohorts as updated.", e); result[0] = SyncStatusConstants.SAVE_ERROR; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); int authenticate(String[] credentials); int authenticate(String[] credentials, boolean isUpdatePasswordRequired); int[] downloadForms(); int[] downloadFormTemplatesAndRelatedMetadata(String[] formIds, boolean replaceExistingTemplates); int[] downloadFormTemplates(String[] formIds, boolean replaceExistingTemplates); int[] downloadLocations(String[] locationIds); int[] downloadProviders(String[] providerIds); int[] downloadConcepts(String[] conceptIds); int[] downloadCohorts(); int[] downloadCohorts(String[] cohortUuids); int[] downloadPatientsForCohortsWithUpdatesAvailable(); int[] downloadRemovedCohortMembershipData(String[] cohortUuids); int[] downloadPatientsForCohorts(String[] cohortUuids); int[] downloadPatients(String[] patientUUIDs); int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation); int[] downloadObservationsForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingObservations); int[] downloadEncountersForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingEncounters); int[] downloadEncountersForPatientsByPatientUUIDs(List<String> patientUuids, boolean replaceExistingEncounters); int[] uploadAllCompletedForms(); void consolidatePatients(); List<FormData> getArchivedFormData(); int[] checkAndDeleteTemporaryDataForProcessedFormData(List<FormData> archivedFormData); List<String> getUuidsForAllPatientsFromLocalStorage(); List<Patient> updatePatientsNotPartOfCohorts(); int[] downloadNotifications(String receiverUuid); int[] downloadPatientReportHeaders(String patientUuid); int[] downloadAllPatientReportHeadersAndReports(); int[] downloadPatientReportsByUuid(String[] reportUuids); void downloadSetupConfigurations(); int[] downloadSetupConfigurationTemplate(String uuid); int[] downloadAndSaveUpdatedSetupConfigurationTemplate(String uuid); int[] updateSetupConfigurationTemplates(); int[] downloadSetting(String property); int[] downloadNewSettings(); void updateSettingsPreferences(List<MuzimaSetting> muzimaSettings); int[] downloadRelationshipsTypes(); int[] downloadRelationshipsForPatientsByPatientUUIDs(List<String> patientUuids); int[] downloadRelationshipsForPatientsByCohortUUIDs(String[] cohortUuids); String getDefaultLocation();  }