openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/api/repository/VisitRepository.java
/**
     * Start visit.
     *
     * @param patient          the patient
     * @param callbackListener the callback listener
     */
Start visit.
@param patient          the patient
@param callbackListener the callback listener
Start visit . @param patient the patient @param callbackListener the callback listener
public void startVisit(final Patient patient, @Nullable final StartVisitResponseCallback callbackListener) {
        final Visit visit = new Visit();
        visit.setStartDatetime(DateUtils.convertTime(System.currentTimeMillis(), DateUtils.OPEN_MRS_REQUEST_FORMAT));
        visit.setPatient(patient);
        visit.setLocation(locationDAO.findLocationByName(OpenmrsAndroid.getLocation()));
        visit.setVisitType(new VisitType("", OpenmrsAndroid.getVisitTypeUUID()));
        Call<Visit> call = restApi.startVisit(visit);
        call.enqueue(new Callback<Visit>() {
            @Override
            public void onResponse(@NonNull Call<Visit> call, @NonNull Response<Visit> response) {
                if (response.isSuccessful()) {
                    Visit newVisit = response.body();
                    visitDAO.saveOrUpdate(newVisit, patient.getId())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(id -> {
                            if (callbackListener != null) {
                                callbackListener.onStartVisitResponse(id);
                            }
                        });
                } else {
                    if (callbackListener != null) {
                        callbackListener.onErrorResponse(response.message());
                    }
                }
            }
            @Override
            public void onFailure(@NonNull Call<Visit> call, @NonNull Throwable t) {
                if (callbackListener != null) {
                    callbackListener.onErrorResponse(t.getMessage());
                }
            }
        });
    }
public void startVisit ( final Patient patient , @ Nullable final StartVisitResponseCallback callbackListener ) { final Visit visit = new Visit ( ) ; visit . setStartDatetime ( DateUtils . convertTime ( System . currentTimeMillis ( ) , DateUtils . OPEN_MRS_REQUEST_FORMAT ) ) ; visit . setPatient ( patient ) ; visit . setLocation ( locationDAO . findLocationByName ( OpenmrsAndroid . getLocation ( ) ) ) ; visit . setVisitType ( new VisitType ( "" , OpenmrsAndroid . getVisitTypeUUID ( ) ) ) ; Call < Visit > call = restApi . startVisit ( visit ) ; call . enqueue ( new Callback < Visit > ( ) { @ Override public void onResponse ( @ NonNull Call < Visit > call , @ NonNull Response < Visit > response ) { if ( response . isSuccessful ( ) ) { Visit newVisit = response . body ( ) ; visitDAO . saveOrUpdate ( newVisit , patient . getId ( ) ) . observeOn ( AndroidSchedulers . mainThread ( ) ) . subscribe ( id -> { if ( callbackListener != null ) { callbackListener . onStartVisitResponse ( id ) ; } } ) ; } else { if ( callbackListener != null ) { callbackListener . onErrorResponse ( response . message ( ) ) ; } } } @ Override public void onFailure ( @ NonNull Call < Visit > call , @ NonNull Throwable t ) { if ( callbackListener != null ) { callbackListener . onErrorResponse ( t . getMessage ( ) ) ; } } } ) ; }
Start visit.
Start visit .