openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/AllergyRepository.java
/**
     * Delete allergy.
     *
     * @param restApi     the rest api
     * @param patientUuid the patient uuid
     * @param allergyUuid the allergy uuid
     * @param callback    the callback
     */
Delete allergy.
@param restApi     the rest api
@param patientUuid the patient uuid
@param allergyUuid the allergy uuid
@param callback    the callback
Delete allergy . @param restApi the rest api @param patientUuid the patient uuid @param allergyUuid the allergy uuid @param callback the callback
public void deleteAllergy(RestApi restApi, String patientUuid, String allergyUuid, DefaultResponseCallback callback) {
        if (NetworkUtils.isOnline()) {
            restApi.deleteAllergy(patientUuid, allergyUuid).enqueue(new Callback<ResponseBody>() {
                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    if (response.isSuccessful()) {
                        allergyRoomDAO.deleteAllergyByUUID(allergyUuid);
                        ToastUtil.success(OpenmrsAndroid.getInstance().getString(R.string.delete_allergy_success));
                        callback.onResponse();
                    }
                }
                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    callback.onErrorResponse(OpenmrsAndroid.getInstance().getString(R.string.delete_allergy_failure));
                }
            });
        } else {
            Data data = new Data.Builder()
                .putString(PATIENT_UUID, patientUuid)
                .putString(ALLERGY_UUID, allergyUuid)
                .build();
            allergyRoomDAO.deleteAllergyByUUID(allergyUuid);
            callback.onResponse();
            Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
            workManager.enqueue(new OneTimeWorkRequest.Builder(DeleteAllergyWorker.class).setConstraints(constraints).setInputData(data).build());
            ToastUtil.notify(OpenmrsAndroid.getInstance().getString(R.string.delete_allergy_offline));
        }
    }
public void deleteAllergy ( RestApi restApi , String patientUuid , String allergyUuid , DefaultResponseCallback callback ) { if ( NetworkUtils . isOnline ( ) ) { restApi . deleteAllergy ( patientUuid , allergyUuid ) . enqueue ( new Callback < ResponseBody > ( ) { @ Override public void onResponse ( Call < ResponseBody > call , Response < ResponseBody > response ) { if ( response . isSuccessful ( ) ) { allergyRoomDAO . deleteAllergyByUUID ( allergyUuid ) ; ToastUtil . success ( OpenmrsAndroid . getInstance ( ) . getString ( R . string . delete_allergy_success ) ) ; callback . onResponse ( ) ; } } @ Override public void onFailure ( Call < ResponseBody > call , Throwable t ) { callback . onErrorResponse ( OpenmrsAndroid . getInstance ( ) . getString ( R . string . delete_allergy_failure ) ) ; } } ) ; } else { Data data = new Data . Builder ( ) . putString ( PATIENT_UUID , patientUuid ) . putString ( ALLERGY_UUID , allergyUuid ) . build ( ) ; allergyRoomDAO . deleteAllergyByUUID ( allergyUuid ) ; callback . onResponse ( ) ; Constraints constraints = new Constraints . Builder ( ) . setRequiredNetworkType ( NetworkType . CONNECTED ) . build ( ) ; workManager . enqueue ( new OneTimeWorkRequest . Builder ( DeleteAllergyWorker . class ) . setConstraints ( constraints ) . setInputData ( data ) . build ( ) ) ; ToastUtil . notify ( OpenmrsAndroid . getInstance ( ) . getString ( R . string . delete_allergy_offline ) ) ; } }
Delete allergy.
Delete allergy .
// offline deletion // enqueue the work to workManager