Search in sources :

Example 1 with EventFlow

use of org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow in project pictureapp by EyeSeeTea.

the class PushDhisSDKDataSource method getEventUidToBePushed.

@NonNull
private Set<String> getEventUidToBePushed() {
    final Set<String> eventUids = new HashSet<>();
    final Set<String> sendingEventUids = new HashSet<>();
    List<Survey> surveys = Survey.getAllSendingSurveys();
    for (Survey survey : surveys) {
        sendingEventUids.add(survey.getEventUid());
    }
    List<EventFlow> eventsFlows = SdkQueries.getEvents();
    Log.d(TAG, "Size of events " + eventsFlows.size() + "size of surveys" + sendingEventUids.size());
    if (sendingEventUids.size() != eventsFlows.size()) {
        Log.d(TAG, "Error in size of events");
    }
    for (EventFlow eventFlow : eventsFlows) {
        if (eventFlow.getEventDate() != null && sendingEventUids.contains(eventFlow.getUId())) {
            eventUids.add(eventFlow.getUId());
        } else {
            Log.d(TAG, "Error pushing events. The event uid: " + eventFlow.getUId() + "haven't eventDate or is not listed to send");
        }
    }
    Log.d(TAG, "Size of valid events " + eventsFlows.size());
    return eventUids;
}
Also used : Survey(org.eyeseetea.malariacare.data.database.model.Survey) EventFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow) HashSet(java.util.HashSet) NonNull(android.support.annotation.NonNull)

Example 2 with EventFlow

use of org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow in project pictureapp by EyeSeeTea.

the class SurveyChecker method getEvents.

public static List<EventExtended> getEvents(JsonNode jsonNode) {
    TypeReference<List<Event>> typeRef = new TypeReference<List<Event>>() {
    };
    List<Event> events;
    try {
        if (jsonNode.has("events")) {
            ObjectMapper objectMapper = new ObjectMapper().registerModule(new JodaModule());
            events = objectMapper.readValue(jsonNode.get("events").traverse(), typeRef);
        } else {
            events = new ArrayList<>();
        }
    } catch (IOException e) {
        events = new ArrayList<>();
        e.printStackTrace();
    }
    List<EventExtended> eventExtendedList = new ArrayList<>();
    for (Event event : events) {
        EventFlow eventFlow = EventFlow.MAPPER.mapToDatabaseEntity(event);
        EventExtended eventExtended = new EventExtended(eventFlow);
        if (event.getDataValues() != null && event.getDataValues().size() > 0) {
            List<TrackedEntityDataValueFlow> trackedEntityDataValueFlows = TrackedEntityDataValueFlow.MAPPER.mapToDatabaseEntities(event.getDataValues());
            eventExtended.setDataValuesInMemory(trackedEntityDataValueFlows);
        }
        eventExtendedList.add(eventExtended);
    }
    return eventExtendedList;
}
Also used : EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) EventFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) TrackedEntityDataValueFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.TrackedEntityDataValueFlow) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Event(org.hisp.dhis.client.sdk.models.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

EventFlow (org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow)2 NonNull (android.support.annotation.NonNull)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Survey (org.eyeseetea.malariacare.data.database.model.Survey)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1 TrackedEntityDataValueFlow (org.hisp.dhis.client.sdk.android.api.persistence.flow.TrackedEntityDataValueFlow)1 Event (org.hisp.dhis.client.sdk.models.event.Event)1