openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/PatientRepository.java
/**
     * Update patient.
     *
     * @param patient          the patient
     * @param callbackListener the callback listener
     */
Update patient.
@param patient          the patient
@param callbackListener the callback listener
Update patient . @param patient the patient @param callbackListener the callback listener
public void updatePatient(final Patient patient, @Nullable final DefaultResponseCallback callbackListener) {
        PatientDtoUpdate patientDto = patient.getUpdatedPatientDto();
        if (NetworkUtils.isOnline()) {
            Call<PatientDto> call = restApi.updatePatient(patientDto, patient.getUuid(), "full");
            call.enqueue(new Callback<PatientDto>() {
                @Override
                public void onResponse(@NonNull Call<PatientDto> call, @NonNull Response<PatientDto> response) {
                    if (response.isSuccessful()) {
                        PatientDto patientDto = response.body();
                        patient.setBirthdate(patientDto.getPerson().getBirthdate());
                        patient.setUuid(patient.getUuid());
                        if (patient.getPhoto() != null) {
                            uploadPatientPhoto(patient);
                        }
                        patientDAO.updatePatient(patient.getId(), patient);
                        ToastUtil.success("Patient " + patient.getPerson().getName().getNameString() + " Updated");
                        if (callbackListener != null) {
                            callbackListener.onResponse();
                        }
                    } else {
                        ToastUtil.error(
                                "Patient " + patient.getPerson().getName().getNameString() + " cannot be updated due to server error will retry sync " + response.message());
                        if (callbackListener != null) {
                            callbackListener.onErrorResponse(response.message());
                        }
                    }
                }
                @Override
                public void onFailure(@NonNull Call<PatientDto> call, @NonNull Throwable t) {
                    ToastUtil.notify("Patient[ " + patient.getId() + " ] cannot be synced due to request error" + t.toString());
                    if (callbackListener != null) {
                        callbackListener.onErrorResponse(t.getMessage());
                    }
                }
            });
        } else {
            patientDAO.updatePatient(patient.getId(), patient);
            Data data = new Data.Builder().putString("_id", patient.getId().toString()).build();
            Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();
            workManager.enqueue(new OneTimeWorkRequest.Builder(UpdatePatientWorker.class).setConstraints(constraints).setInputData(data).build());
            ToastUtil.notify(context.getString(R.string.offline_mode_patient_data_saved_locally_notification_message));
            if (callbackListener != null) {
                callbackListener.onResponse();
            }
        }
    }
public void updatePatient ( final Patient patient , @ Nullable final DefaultResponseCallback callbackListener ) { PatientDtoUpdate patientDto = patient . getUpdatedPatientDto ( ) ; if ( NetworkUtils . isOnline ( ) ) { Call < PatientDto > call = restApi . updatePatient ( patientDto , patient . getUuid ( ) , "full" ) ; call . enqueue ( new Callback < PatientDto > ( ) { @ Override public void onResponse ( @ NonNull Call < PatientDto > call , @ NonNull Response < PatientDto > response ) { if ( response . isSuccessful ( ) ) { PatientDto patientDto = response . body ( ) ; patient . setBirthdate ( patientDto . getPerson ( ) . getBirthdate ( ) ) ; patient . setUuid ( patient . getUuid ( ) ) ; if ( patient . getPhoto ( ) != null ) { uploadPatientPhoto ( patient ) ; } patientDAO . updatePatient ( patient . getId ( ) , patient ) ; ToastUtil . success ( "Patient " + patient . getPerson ( ) . getName ( ) . getNameString ( ) + " Updated" ) ; if ( callbackListener != null ) { callbackListener . onResponse ( ) ; } } else { ToastUtil . error ( "Patient " + patient . getPerson ( ) . getName ( ) . getNameString ( ) + " cannot be updated due to server error will retry sync " + response . message ( ) ) ; if ( callbackListener != null ) { callbackListener . onErrorResponse ( response . message ( ) ) ; } } } @ Override public void onFailure ( @ NonNull Call < PatientDto > call , @ NonNull Throwable t ) { ToastUtil . notify ( "Patient[ " + patient . getId ( ) + " ] cannot be synced due to request error" + t . toString ( ) ) ; if ( callbackListener != null ) { callbackListener . onErrorResponse ( t . getMessage ( ) ) ; } } } ) ; } else { patientDAO . updatePatient ( patient . getId ( ) , patient ) ; Data data = new Data . Builder ( ) . putString ( "_id" , patient . getId ( ) . toString ( ) ) . build ( ) ; Constraints constraints = new Constraints . Builder ( ) . setRequiredNetworkType ( NetworkType . CONNECTED ) . build ( ) ; workManager . enqueue ( new OneTimeWorkRequest . Builder ( UpdatePatientWorker . class ) . setConstraints ( constraints ) . setInputData ( data ) . build ( ) ) ; ToastUtil . notify ( context . getString ( R . string . offline_mode_patient_data_saved_locally_notification_message ) ) ; if ( callbackListener != null ) { callbackListener . onResponse ( ) ; } } }
Update patient.
Update patient .