openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/VisitRepository.java
/**
     * This method syncs visit data asynchronously and uses the callback listener to propogate back the results.
     *
     * @see DefaultResponseCallback
     *
     * @param patient
     * @param callbackListener
     */
This method syncs visit data asynchronously and uses the callback listener to propogate back the results.

@param patient
@param callbackListener
This method syncs visit data asynchronously and uses the callback listener to propogate back the results . @param patient @param callbackListener
public void syncVisitsData(@NonNull final Patient patient, @Nullable final DefaultResponseCallback callbackListener) {
        Call<Results<Visit>> call = restApi.findVisitsByPatientUUID(patient.getUuid(), "custom:(uuid,location:ref,visitType:ref,startDatetime,stopDatetime,encounters:full)");
        call.enqueue(new Callback<Results<Visit>>() {
            @Override
            public void onResponse(@NonNull Call<Results<Visit>> call, @NonNull Response<Results<Visit>> response) {
                if (response.isSuccessful()) {
                    List<Visit> visits = response.body().getResults();
                    Observable.just(visits)
                        .flatMap(Observable::from)
                        .forEach(visit ->
                                visitDAO.saveOrUpdate(visit, patient.getId())
                                    .observeOn(AndroidSchedulers.mainThread())
                                    .subscribe(),
                            error -> error.printStackTrace()
                        );
                    if (callbackListener != null) {
                        callbackListener.onResponse();
                    }
                } else {
                    if (callbackListener != null) {
                        callbackListener.onErrorResponse(response.message());
                    }
                }
            }
            @Override
            public void onFailure(@NonNull Call<Results<Visit>> call, @NonNull Throwable t) {
                if (callbackListener != null) {
                    callbackListener.onErrorResponse(t.getMessage());
                }
            }
        });
    }
public void syncVisitsData ( @ NonNull final Patient patient , @ Nullable final DefaultResponseCallback callbackListener ) { Call < Results < Visit > > call = restApi . findVisitsByPatientUUID ( patient . getUuid ( ) , "custom:(uuid,location:ref,visitType:ref,startDatetime,stopDatetime,encounters:full)" ) ; call . enqueue ( new Callback < Results < Visit > > ( ) { @ Override public void onResponse ( @ NonNull Call < Results < Visit > > call , @ NonNull Response < Results < Visit > > response ) { if ( response . isSuccessful ( ) ) { List < Visit > visits = response . body ( ) . getResults ( ) ; Observable . just ( visits ) . flatMap ( Observable :: from ) . forEach ( visit -> visitDAO . saveOrUpdate ( visit , patient . getId ( ) ) . observeOn ( AndroidSchedulers . mainThread ( ) ) . subscribe ( ) , error -> error . printStackTrace ( ) ) ; if ( callbackListener != null ) { callbackListener . onResponse ( ) ; } } else { if ( callbackListener != null ) { callbackListener . onErrorResponse ( response . message ( ) ) ; } } } @ Override public void onFailure ( @ NonNull Call < Results < Visit > > call , @ NonNull Throwable t ) { if ( callbackListener != null ) { callbackListener . onErrorResponse ( t . getMessage ( ) ) ; } } } ) ; }
This method syncs visit data asynchronously and uses the callback listener to propogate back the results.
This method syncs visit data asynchronously and uses the callback listener to propogate back the results .