@Test public void shouldUpdateLastSyncTimeForObservation() throws Exception, ObservationController.DownloadObservationException { List<String> patientUuids = asList("PatientUuid1", "PatientUuid2"); List<String> conceptUuids = asList("ConceptUuid1", "ConceptUuid2"); Date currentDate = mock(Date.class); when(sntpService.getTimePerDeviceTimeZone()).thenReturn(currentDate); observationController.downloadObservationsByPatientUuidsAndConceptUuids(patientUuids, conceptUuids); ArgumentCaptor<LastSyncTime> argumentCaptor = ArgumentCaptor.forClass(LastSyncTime.class); verify(lastSyncTimeService).saveLastSyncTime(argumentCaptor.capture()); LastSyncTime savedLastSyncTime = argumentCaptor.getValue(); assertThat(savedLastSyncTime.getApiName(), is(DOWNLOAD_OBSERVATIONS)); assertThat(savedLastSyncTime.getLastSyncDate(), is(currentDate)); assertThat(savedLastSyncTime.getParamSignature(), is("PatientUuid1,PatientUuid2;ConceptUuid1,ConceptUuid2")); }
public List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids) throws DownloadObservationException { try { String paramSignature = buildParamSignature(patientUuids, conceptUuids); Date lastSyncTime = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_OBSERVATIONS, paramSignature); List<Observation> observations = new ArrayList<>(); if (hasExactCallBeenMadeBefore(lastSyncTime)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, lastSyncTime)); } else { LastSyncTime fullLastSyncTimeInfo = lastSyncTimeService.getFullLastSyncTimeInfoFor(DOWNLOAD_OBSERVATIONS); if (isFirstCallToDownloadObservationsEver(fullLastSyncTimeInfo)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, null)); } else { String[] parameterSplit = fullLastSyncTimeInfo.getParamSignature().split(UUID_TYPE_SEPARATOR, -1); List<String> knownPatientsUuid = asList(parameterSplit[0].split(UUID_SEPARATOR)); List<String> newPatientsUuids = getNewUuids(patientUuids, knownPatientsUuid); List<String> knownConceptsUuid = asList(parameterSplit[1].split(UUID_SEPARATOR)); List<String> newConceptsUuids = getNewUuids(conceptUuids, knownConceptsUuid); List<String> allConceptsUuids = getAllUuids(knownConceptsUuid, newConceptsUuids); List<String> allPatientsUuids = getAllUuids(knownPatientsUuid, newPatientsUuids); paramSignature = buildParamSignature(allPatientsUuids, allConceptsUuids); if(newPatientsUuids.size()!=0) { observations = observationService.downloadObservations(newPatientsUuids, allConceptsUuids, null); observations.addAll(observationService.downloadObservations(knownPatientsUuid, newConceptsUuids, null)); observations.addAll(observationService.downloadObservations(knownPatientsUuid, knownConceptsUuid, fullLastSyncTimeInfo.getLastSyncDate())); } else{ observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, fullLastSyncTimeInfo.getLastSyncDate())); } } } LastSyncTime newLastSyncTime = new LastSyncTime(DOWNLOAD_OBSERVATIONS, sntpService.getTimePerDeviceTimeZone(), paramSignature); lastSyncTimeService.saveLastSyncTime(newLastSyncTime); return observations; } catch (IOException e) { throw new DownloadObservationException(e); } }
ObservationController { public List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids) throws DownloadObservationException { try { String paramSignature = buildParamSignature(patientUuids, conceptUuids); Date lastSyncTime = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_OBSERVATIONS, paramSignature); List<Observation> observations = new ArrayList<>(); if (hasExactCallBeenMadeBefore(lastSyncTime)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, lastSyncTime)); } else { LastSyncTime fullLastSyncTimeInfo = lastSyncTimeService.getFullLastSyncTimeInfoFor(DOWNLOAD_OBSERVATIONS); if (isFirstCallToDownloadObservationsEver(fullLastSyncTimeInfo)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, null)); } else { String[] parameterSplit = fullLastSyncTimeInfo.getParamSignature().split(UUID_TYPE_SEPARATOR, -1); List<String> knownPatientsUuid = asList(parameterSplit[0].split(UUID_SEPARATOR)); List<String> newPatientsUuids = getNewUuids(patientUuids, knownPatientsUuid); List<String> knownConceptsUuid = asList(parameterSplit[1].split(UUID_SEPARATOR)); List<String> newConceptsUuids = getNewUuids(conceptUuids, knownConceptsUuid); List<String> allConceptsUuids = getAllUuids(knownConceptsUuid, newConceptsUuids); List<String> allPatientsUuids = getAllUuids(knownPatientsUuid, newPatientsUuids); paramSignature = buildParamSignature(allPatientsUuids, allConceptsUuids); if(newPatientsUuids.size()!=0) { observations = observationService.downloadObservations(newPatientsUuids, allConceptsUuids, null); observations.addAll(observationService.downloadObservations(knownPatientsUuid, newConceptsUuids, null)); observations.addAll(observationService.downloadObservations(knownPatientsUuid, knownConceptsUuid, fullLastSyncTimeInfo.getLastSyncDate())); } else{ observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, fullLastSyncTimeInfo.getLastSyncDate())); } } } LastSyncTime newLastSyncTime = new LastSyncTime(DOWNLOAD_OBSERVATIONS, sntpService.getTimePerDeviceTimeZone(), paramSignature); lastSyncTimeService.saveLastSyncTime(newLastSyncTime); return observations; } catch (IOException e) { throw new DownloadObservationException(e); } } }
ObservationController { public List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids) throws DownloadObservationException { try { String paramSignature = buildParamSignature(patientUuids, conceptUuids); Date lastSyncTime = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_OBSERVATIONS, paramSignature); List<Observation> observations = new ArrayList<>(); if (hasExactCallBeenMadeBefore(lastSyncTime)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, lastSyncTime)); } else { LastSyncTime fullLastSyncTimeInfo = lastSyncTimeService.getFullLastSyncTimeInfoFor(DOWNLOAD_OBSERVATIONS); if (isFirstCallToDownloadObservationsEver(fullLastSyncTimeInfo)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, null)); } else { String[] parameterSplit = fullLastSyncTimeInfo.getParamSignature().split(UUID_TYPE_SEPARATOR, -1); List<String> knownPatientsUuid = asList(parameterSplit[0].split(UUID_SEPARATOR)); List<String> newPatientsUuids = getNewUuids(patientUuids, knownPatientsUuid); List<String> knownConceptsUuid = asList(parameterSplit[1].split(UUID_SEPARATOR)); List<String> newConceptsUuids = getNewUuids(conceptUuids, knownConceptsUuid); List<String> allConceptsUuids = getAllUuids(knownConceptsUuid, newConceptsUuids); List<String> allPatientsUuids = getAllUuids(knownPatientsUuid, newPatientsUuids); paramSignature = buildParamSignature(allPatientsUuids, allConceptsUuids); if(newPatientsUuids.size()!=0) { observations = observationService.downloadObservations(newPatientsUuids, allConceptsUuids, null); observations.addAll(observationService.downloadObservations(knownPatientsUuid, newConceptsUuids, null)); observations.addAll(observationService.downloadObservations(knownPatientsUuid, knownConceptsUuid, fullLastSyncTimeInfo.getLastSyncDate())); } else{ observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, fullLastSyncTimeInfo.getLastSyncDate())); } } } LastSyncTime newLastSyncTime = new LastSyncTime(DOWNLOAD_OBSERVATIONS, sntpService.getTimePerDeviceTimeZone(), paramSignature); lastSyncTimeService.saveLastSyncTime(newLastSyncTime); return observations; } catch (IOException e) { throw new DownloadObservationException(e); } } ObservationController(ObservationService observationService, ConceptService conceptService,
                                 EncounterService encounterService, LastSyncTimeService lastSyncTimeService,
                                 SntpService sntpService); }
ObservationController { public List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids) throws DownloadObservationException { try { String paramSignature = buildParamSignature(patientUuids, conceptUuids); Date lastSyncTime = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_OBSERVATIONS, paramSignature); List<Observation> observations = new ArrayList<>(); if (hasExactCallBeenMadeBefore(lastSyncTime)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, lastSyncTime)); } else { LastSyncTime fullLastSyncTimeInfo = lastSyncTimeService.getFullLastSyncTimeInfoFor(DOWNLOAD_OBSERVATIONS); if (isFirstCallToDownloadObservationsEver(fullLastSyncTimeInfo)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, null)); } else { String[] parameterSplit = fullLastSyncTimeInfo.getParamSignature().split(UUID_TYPE_SEPARATOR, -1); List<String> knownPatientsUuid = asList(parameterSplit[0].split(UUID_SEPARATOR)); List<String> newPatientsUuids = getNewUuids(patientUuids, knownPatientsUuid); List<String> knownConceptsUuid = asList(parameterSplit[1].split(UUID_SEPARATOR)); List<String> newConceptsUuids = getNewUuids(conceptUuids, knownConceptsUuid); List<String> allConceptsUuids = getAllUuids(knownConceptsUuid, newConceptsUuids); List<String> allPatientsUuids = getAllUuids(knownPatientsUuid, newPatientsUuids); paramSignature = buildParamSignature(allPatientsUuids, allConceptsUuids); if(newPatientsUuids.size()!=0) { observations = observationService.downloadObservations(newPatientsUuids, allConceptsUuids, null); observations.addAll(observationService.downloadObservations(knownPatientsUuid, newConceptsUuids, null)); observations.addAll(observationService.downloadObservations(knownPatientsUuid, knownConceptsUuid, fullLastSyncTimeInfo.getLastSyncDate())); } else{ observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, fullLastSyncTimeInfo.getLastSyncDate())); } } } LastSyncTime newLastSyncTime = new LastSyncTime(DOWNLOAD_OBSERVATIONS, sntpService.getTimePerDeviceTimeZone(), paramSignature); lastSyncTimeService.saveLastSyncTime(newLastSyncTime); return observations; } catch (IOException e) { throw new DownloadObservationException(e); } } ObservationController(ObservationService observationService, ConceptService conceptService,
                                 EncounterService encounterService, LastSyncTimeService lastSyncTimeService,
                                 SntpService sntpService); Concepts getConceptWithObservations(String patientUuid); Concepts getConceptWithObservations(String patientUuid, String conceptUuid ); List<Observation> getObservationsByPatientuuidAndConceptId(String patientUuid,int conceptid); List<Observation> getObservationsByEncounterId(int encounterId); List<Observation> getObservationsByEncounterType(int encounterTypeId,String patientUuid); int getObservationsCountByPatient(String patientUuid); int getConceptColor(String uuid); void replaceObservations(List<Observation> allObservations); Concepts searchObservationsGroupedByConcepts(String term, String patientUuid); Encounters getEncountersWithObservations(String patientUuid); Encounters getObservationsByEncounterUuid(String encounterUuid); List<Observation> getObservationsByPatient(String patientUuid); Encounters searchObservationsGroupedByEncounter(String term, String patientUuid); List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids); void saveObservations(List<Observation> observations); void deleteObservations(List<Observation> observations); void deleteAllObservations(List<Concept> concepts); }
ObservationController { public List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids) throws DownloadObservationException { try { String paramSignature = buildParamSignature(patientUuids, conceptUuids); Date lastSyncTime = lastSyncTimeService.getLastSyncTimeFor(DOWNLOAD_OBSERVATIONS, paramSignature); List<Observation> observations = new ArrayList<>(); if (hasExactCallBeenMadeBefore(lastSyncTime)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, lastSyncTime)); } else { LastSyncTime fullLastSyncTimeInfo = lastSyncTimeService.getFullLastSyncTimeInfoFor(DOWNLOAD_OBSERVATIONS); if (isFirstCallToDownloadObservationsEver(fullLastSyncTimeInfo)) { observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, null)); } else { String[] parameterSplit = fullLastSyncTimeInfo.getParamSignature().split(UUID_TYPE_SEPARATOR, -1); List<String> knownPatientsUuid = asList(parameterSplit[0].split(UUID_SEPARATOR)); List<String> newPatientsUuids = getNewUuids(patientUuids, knownPatientsUuid); List<String> knownConceptsUuid = asList(parameterSplit[1].split(UUID_SEPARATOR)); List<String> newConceptsUuids = getNewUuids(conceptUuids, knownConceptsUuid); List<String> allConceptsUuids = getAllUuids(knownConceptsUuid, newConceptsUuids); List<String> allPatientsUuids = getAllUuids(knownPatientsUuid, newPatientsUuids); paramSignature = buildParamSignature(allPatientsUuids, allConceptsUuids); if(newPatientsUuids.size()!=0) { observations = observationService.downloadObservations(newPatientsUuids, allConceptsUuids, null); observations.addAll(observationService.downloadObservations(knownPatientsUuid, newConceptsUuids, null)); observations.addAll(observationService.downloadObservations(knownPatientsUuid, knownConceptsUuid, fullLastSyncTimeInfo.getLastSyncDate())); } else{ observations.addAll(observationService.downloadObservations(patientUuids, conceptUuids, fullLastSyncTimeInfo.getLastSyncDate())); } } } LastSyncTime newLastSyncTime = new LastSyncTime(DOWNLOAD_OBSERVATIONS, sntpService.getTimePerDeviceTimeZone(), paramSignature); lastSyncTimeService.saveLastSyncTime(newLastSyncTime); return observations; } catch (IOException e) { throw new DownloadObservationException(e); } } ObservationController(ObservationService observationService, ConceptService conceptService,
                                 EncounterService encounterService, LastSyncTimeService lastSyncTimeService,
                                 SntpService sntpService); Concepts getConceptWithObservations(String patientUuid); Concepts getConceptWithObservations(String patientUuid, String conceptUuid ); List<Observation> getObservationsByPatientuuidAndConceptId(String patientUuid,int conceptid); List<Observation> getObservationsByEncounterId(int encounterId); List<Observation> getObservationsByEncounterType(int encounterTypeId,String patientUuid); int getObservationsCountByPatient(String patientUuid); int getConceptColor(String uuid); void replaceObservations(List<Observation> allObservations); Concepts searchObservationsGroupedByConcepts(String term, String patientUuid); Encounters getEncountersWithObservations(String patientUuid); Encounters getObservationsByEncounterUuid(String encounterUuid); List<Observation> getObservationsByPatient(String patientUuid); Encounters searchObservationsGroupedByEncounter(String term, String patientUuid); List<Observation> downloadObservationsByPatientUuidsAndConceptUuids(List<String> patientUuids, List<String> conceptUuids); void saveObservations(List<Observation> observations); void deleteObservations(List<Observation> observations); void deleteAllObservations(List<Concept> concepts);  }