@Test public void downloadObservationsForPatients_shouldDownloadObservationsForGiveCohortIdsAndSavedConcepts() throws PatientController.PatientLoadException, ObservationController.DownloadObservationException, ObservationController.ReplaceObservationException, ConceptController.ConceptFetchException, ObservationController.DeleteObservationException { String[] cohortUuids = new String[]{"uuid1", "uuid2"}; final Patient patient = new Patient() {{ setUuid("patient1"); }}; List<Patient> patients = new ArrayList<Patient>() {{ add(patient); }}; List<Observation> allObservations = new ArrayList<Observation>() {{ add(new Observation(){{setPerson(patient);}}); add(new Observation(){{setPerson(patient);}}); }}; when(patientController.getPatientsForCohorts(cohortUuids)).thenReturn(patients); when(muzimaApplication.getSharedPreferences(Constants.CONCEPT_PREF, android.content.Context.MODE_PRIVATE)).thenReturn(sharedPref); List<String> patientUuids = Collections.singletonList("patient1"); List<String> conceptUuids = asList("weight", "temp"); when(observationController.downloadObservationsByPatientUuidsAndConceptUuids(patientUuids, conceptUuids)) .thenReturn(allObservations); Concept conceptWeight = new Concept(); conceptWeight.setUuid("weight"); Concept conceptTemp = new Concept(); conceptTemp.setUuid("temp"); when(conceptController.getConcepts()).thenReturn(asList(conceptWeight, conceptTemp)); muzimaSyncService.downloadObservationsForPatientsByCohortUUIDs(cohortUuids,true); verify(observationController).downloadObservationsByPatientUuidsAndConceptUuids(patientUuids, conceptUuids); verify(observationController).deleteObservations(new ArrayList<Observation>()); verify(observationController).replaceObservations(allObservations); verifyNoMoreInteractions(observationController); }
public int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation) { int[] result = new int[4]; List<Patient> patients; try { patients = patientController.getPatientsForCohorts(cohortUuids); List<String> patientlist = new ArrayList(); for (Patient patient : patients) { patientlist.add(patient.getUuid()); } result = downloadObservationsForPatientsByPatientUUIDs(patientlist, replaceExistingObservation); if (result[0] != SUCCESS) { updateProgressDialog(muzimaApplication.getString(R.string.error_encounter_observation_download)); } } catch (PatientController.PatientLoadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while loading patients.", e); result[0] = SyncStatusConstants.LOAD_ERROR; } return result; }
MuzimaSyncService { public int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation) { int[] result = new int[4]; List<Patient> patients; try { patients = patientController.getPatientsForCohorts(cohortUuids); List<String> patientlist = new ArrayList(); for (Patient patient : patients) { patientlist.add(patient.getUuid()); } result = downloadObservationsForPatientsByPatientUUIDs(patientlist, replaceExistingObservation); if (result[0] != SUCCESS) { updateProgressDialog(muzimaApplication.getString(R.string.error_encounter_observation_download)); } } catch (PatientController.PatientLoadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while loading patients.", e); result[0] = SyncStatusConstants.LOAD_ERROR; } return result; } }
MuzimaSyncService { public int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation) { int[] result = new int[4]; List<Patient> patients; try { patients = patientController.getPatientsForCohorts(cohortUuids); List<String> patientlist = new ArrayList(); for (Patient patient : patients) { patientlist.add(patient.getUuid()); } result = downloadObservationsForPatientsByPatientUUIDs(patientlist, replaceExistingObservation); if (result[0] != SUCCESS) { updateProgressDialog(muzimaApplication.getString(R.string.error_encounter_observation_download)); } } catch (PatientController.PatientLoadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while loading patients.", e); result[0] = SyncStatusConstants.LOAD_ERROR; } return result; } MuzimaSyncService(MuzimaApplication muzimaContext); }
MuzimaSyncService { public int[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation) { int[] result = new int[4]; List<Patient> patients; try { patients = patientController.getPatientsForCohorts(cohortUuids); List<String> patientlist = new ArrayList(); for (Patient patient : patients) { patientlist.add(patient.getUuid()); } result = downloadObservationsForPatientsByPatientUUIDs(patientlist, replaceExistingObservation); if (result[0] != SUCCESS) { updateProgressDialog(muzimaApplication.getString(R.string.error_encounter_observation_download)); } } catch (PatientController.PatientLoadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while loading patients.", e); result[0] = SyncStatusConstants.LOAD_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[] downloadObservationsForPatientsByCohortUUIDs(String[] cohortUuids, boolean replaceExistingObservation) { int[] result = new int[4]; List<Patient> patients; try { patients = patientController.getPatientsForCohorts(cohortUuids); List<String> patientlist = new ArrayList(); for (Patient patient : patients) { patientlist.add(patient.getUuid()); } result = downloadObservationsForPatientsByPatientUUIDs(patientlist, replaceExistingObservation); if (result[0] != SUCCESS) { updateProgressDialog(muzimaApplication.getString(R.string.error_encounter_observation_download)); } } catch (PatientController.PatientLoadException e) { Log.e(getClass().getSimpleName(), "Exception thrown while loading patients.", e); result[0] = SyncStatusConstants.LOAD_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();  }