openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/PatientRepository.java
/**
     * Download patient photo by uuid simple promise.
     *
     * @param uuid the uuid
     * @return the simple promise
     */
Download patient photo by uuid simple promise.
@param uuid the uuid
@return the simple promise
Download patient photo by uuid simple promise . @param uuid the uuid @return the simple promise
public SimplePromise<Bitmap> downloadPatientPhotoByUuid(String uuid) {
        final SimpleDeferredObject<Bitmap> deferredObject = new SimpleDeferredObject<>();
        Call<ResponseBody> call = restApi.downloadPatientPhoto(uuid);
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> response) {
                InputStream inputStream;
                if (response.isSuccessful()) {
                    inputStream = response.body().byteStream();
                    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                        logger.e(e.getMessage());
                    }
                    deferredObject.resolve(bitmap);
                } else {
                    Throwable throwable = new Throwable(response.message());
                    deferredObject.reject(throwable);
                }
            }
            @Override
            public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
                deferredObject.reject(t);
            }
        });
        return deferredObject.promise();
    }
public SimplePromise < Bitmap > downloadPatientPhotoByUuid ( String uuid ) { final SimpleDeferredObject < Bitmap > deferredObject = new SimpleDeferredObject < > ( ) ; Call < ResponseBody > call = restApi . downloadPatientPhoto ( uuid ) ; call . enqueue ( new Callback < ResponseBody > ( ) { @ Override public void onResponse ( @ NonNull Call < ResponseBody > call , @ NonNull Response < ResponseBody > response ) { InputStream inputStream ; if ( response . isSuccessful ( ) ) { inputStream = response . body ( ) . byteStream ( ) ; Bitmap bitmap = BitmapFactory . decodeStream ( inputStream ) ; try { inputStream . close ( ) ; } catch ( IOException e ) { logger . e ( e . getMessage ( ) ) ; } deferredObject . resolve ( bitmap ) ; } else { Throwable throwable = new Throwable ( response . message ( ) ) ; deferredObject . reject ( throwable ) ; } } @ Override public void onFailure ( @ NonNull Call < ResponseBody > call , @ NonNull Throwable t ) { deferredObject . reject ( t ) ; } } ) ; return deferredObject . promise ( ) ; }
Download patient photo by uuid simple promise.
Download patient photo by uuid simple promise .