Search in sources :

Example 1 with OrganisationUnit

use of org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit in project pictureapp by EyeSeeTea.

the class PullDhisSDKDataSource method pullData.

public void pullData(PullFilters pullFilters, List<OrganisationUnit> organisationUnits, IDataSourceCallback<List<Event>> callback) {
    boolean isNetworkAvailable = isNetworkAvailable();
    if (!isNetworkAvailable) {
        callback.onError(new NetworkException());
    } else {
        try {
            List<Event> events = new ArrayList<>();
            for (OrganisationUnit organisationUnit : organisationUnits) {
                Scheduler pullEventsThread = Schedulers.newThread();
                EventFilters eventFilters = new EventFilters();
                eventFilters.setStartDate(pullFilters.getStartDate());
                eventFilters.setEndDate(pullFilters.getEndDate());
                eventFilters.setMaxEvents(pullFilters.getMaxEvents());
                eventFilters.setOrganisationUnitUId(organisationUnit.getUId());
                mPullDhisSDKDataSourceStrategy.setEventFilters(eventFilters);
                List<Event> eventsByOrgUnit = D2.events().pull(eventFilters).subscribeOn(pullEventsThread).observeOn(pullEventsThread).toBlocking().single();
                events.addAll(eventsByOrgUnit);
            }
            callback.onSuccess(events);
        } catch (Exception e) {
            callback.onError(e);
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit) Scheduler(rx.Scheduler) ArrayList(java.util.ArrayList) Event(org.hisp.dhis.client.sdk.models.event.Event) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) NetworkException(org.eyeseetea.malariacare.domain.exception.NetworkException) EventFilters(org.hisp.dhis.client.sdk.core.event.EventFilters)

Example 2 with OrganisationUnit

use of org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit in project pictureapp by EyeSeeTea.

the class SdkPullController method getProgramAndOrganisationUnit.

/**
     * This method gets a organisation unit and program for each program(with organisation units)
     * and removes it(it removes the organisation unit and the program without organisation units)
     */
private static ProgramAndOrganisationUnitDict getProgramAndOrganisationUnit() {
    if (sdkPrograms == null || sdkPrograms.size() == 0 || programsAndOrganisationUnits == null || programsAndOrganisationUnits.size() == 0) {
        return null;
    }
    List<OrganisationUnit> organisationUnits = programsAndOrganisationUnits.get(sdkPrograms.get(0));
    OrganisationUnit localOrganisationUnit = null;
    if (organisationUnits == null || organisationUnits.size() == 0) {
        programsAndOrganisationUnits.remove(sdkPrograms.get(0));
        if (programsAndOrganisationUnits.size() == 0) {
            return null;
        } else {
            organisationUnits = programsAndOrganisationUnits.get(sdkPrograms.get(0));
        }
    }
    localOrganisationUnit = organisationUnits.get(0);
    organisationUnits.remove(0);
    return new ProgramAndOrganisationUnitDict(sdkPrograms.get(0), localOrganisationUnit);
}
Also used : OrganisationUnit(org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit)

Example 3 with OrganisationUnit

use of org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit in project pictureapp by EyeSeeTea.

the class SdkPullController method getOrganisationUnits.

/**
     * Pull the OrganisationUnits (not work at this moment)
     */
//// FIXME: 16/11/2016  this method is throwing a timeout exception in dev server.
public static void getOrganisationUnits() {
    Set<String> organisationUnitUid = new HashSet<String>();
    for (org.hisp.dhis.client.sdk.models.program.Program program : sdkPrograms) {
        for (OrganisationUnit organisationUnit : program.getOrganisationUnits()) {
            organisationUnitUid.add(organisationUnit.getUId());
        }
    }
    if (organisationUnitUid.size() == 0) {
        return;
    }
    Observable<List<OrganisationUnit>> organisationUnitObservable2 = D2.organisationUnits().pull(organisationUnitUid);
    organisationUnitObservable2.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<OrganisationUnit>>() {

        @Override
        public void call(List<OrganisationUnit> organisationUnits) {
            Log.e(TAG, "OrganisationUnit: Done");
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            errorOnPull = true;
            throwable.printStackTrace();
            Log.e(TAG, "OrganisationUnit: " + throwable.getLocalizedMessage());
            showException("Error pulling OrganisationUnit: ");
        }
    });
}
Also used : OrganisationUnit(org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

OrganisationUnit (org.hisp.dhis.client.sdk.models.organisationunit.OrganisationUnit)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 NetworkException (org.eyeseetea.malariacare.domain.exception.NetworkException)1 EventFilters (org.hisp.dhis.client.sdk.core.event.EventFilters)1 Event (org.hisp.dhis.client.sdk.models.event.Event)1 Scheduler (rx.Scheduler)1