Search in sources :

Example 6 with Event

use of org.hisp.dhis.android.core.event.Event in project dhis2-android-sdk by dhis2.

the class TrackedEntityInstanceCallMockIntegrationShould method createTei.

private TrackedEntityInstance createTei(TrackedEntityInstance downloadedTei, Map<String, List<TrackedEntityAttributeValue>> attValues, List<Enrollment> downloadedEnrollmentsWithoutEvents, List<Event> downloadedEventsWithoutValues, Map<String, List<TrackedEntityDataValue>> downloadedValues) {
    Map<String, List<Event>> downloadedEvents = new HashMap<>();
    List<Enrollment> downloadedEnrollments = new ArrayList<>();
    for (Event event : downloadedEventsWithoutValues) {
        event = Event.create(event.uid(), event.enrollmentUid(), event.created(), event.lastUpdated(), event.createdAtClient(), event.lastUpdatedAtClient(), event.program(), event.programStage(), event.organisationUnit(), event.eventDate(), event.status(), event.coordinates(), event.completedDate(), event.dueDate(), event.deleted(), downloadedValues.get(event.uid()), event.attributeCategoryOptions(), event.attributeOptionCombo(), event.trackedEntityInstance());
        if (downloadedEvents.get(event.enrollmentUid()) == null) {
            downloadedEvents.put(event.enrollmentUid(), new ArrayList<Event>());
        }
        downloadedEvents.get(event.enrollmentUid()).add(event);
    }
    for (Enrollment enrollment : downloadedEnrollmentsWithoutEvents) {
        enrollment = Enrollment.create(enrollment.uid(), enrollment.created(), enrollment.lastUpdated(), enrollment.createdAtClient(), enrollment.lastUpdatedAtClient(), enrollment.organisationUnit(), enrollment.program(), enrollment.dateOfEnrollment(), enrollment.dateOfIncident(), enrollment.followUp(), enrollment.enrollmentStatus(), downloadedTei.uid(), enrollment.coordinate(), enrollment.deleted(), downloadedEvents.get(enrollment.uid()), enrollment.notes());
        downloadedEnrollments.add(enrollment);
    }
    List<Relationship> relationships = new ArrayList<>();
    if (downloadedTei.relationships() != null) {
        relationships = downloadedTei.relationships();
    }
    downloadedTei = TrackedEntityInstance.create(downloadedTei.uid(), downloadedTei.created(), downloadedTei.lastUpdated(), downloadedTei.createdAtClient(), downloadedTei.lastUpdatedAtClient(), downloadedTei.organisationUnit(), downloadedTei.trackedEntity(), downloadedTei.coordinates(), downloadedTei.featureType(), downloadedTei.deleted(), attValues.get(downloadedTei.uid()), relationships, downloadedEnrollments);
    return downloadedTei;
}
Also used : HashMap(java.util.HashMap) Relationship(org.hisp.dhis.android.core.relationship.Relationship) ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.android.core.enrollment.Enrollment) Event(org.hisp.dhis.android.core.event.Event) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with Event

use of org.hisp.dhis.android.core.event.Event in project dhis2-android-sdk by dhis2.

the class TrackedEntityInstanceCallMockIntegrationShould method removeDeletedData.

@NonNull
private TrackedEntityInstance removeDeletedData(TrackedEntityInstance trackedEntityInstance) {
    Map<String, List<Event>> expectedEvents = new HashMap<>();
    List<Enrollment> expectedEnrollments = new ArrayList<>();
    for (Enrollment enrollment : trackedEntityInstance.enrollments()) {
        for (Event event : enrollment.events()) {
            if (!event.deleted()) {
                if (expectedEvents.get(event.enrollmentUid()) == null) {
                    expectedEvents.put(event.enrollmentUid(), new ArrayList<Event>());
                }
                expectedEvents.get(event.enrollmentUid()).add(event);
            }
        }
        if (!enrollment.deleted()) {
            enrollment = Enrollment.create(enrollment.uid(), enrollment.created(), enrollment.lastUpdated(), enrollment.createdAtClient(), enrollment.lastUpdatedAtClient(), enrollment.organisationUnit(), enrollment.program(), enrollment.dateOfEnrollment(), enrollment.dateOfIncident(), enrollment.followUp(), enrollment.enrollmentStatus(), trackedEntityInstance.uid(), enrollment.coordinate(), enrollment.deleted(), expectedEvents.get(enrollment.uid()), enrollment.notes());
            expectedEnrollments.add(enrollment);
        }
    }
    trackedEntityInstance = TrackedEntityInstance.create(trackedEntityInstance.uid(), trackedEntityInstance.created(), trackedEntityInstance.lastUpdated(), trackedEntityInstance.createdAtClient(), trackedEntityInstance.lastUpdatedAtClient(), trackedEntityInstance.organisationUnit(), trackedEntityInstance.trackedEntity(), trackedEntityInstance.coordinates(), trackedEntityInstance.featureType(), trackedEntityInstance.deleted(), trackedEntityInstance.trackedEntityAttributeValues(), trackedEntityInstance.relationships(), expectedEnrollments);
    return trackedEntityInstance;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Enrollment(org.hisp.dhis.android.core.enrollment.Enrollment) Event(org.hisp.dhis.android.core.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) NonNull(android.support.annotation.NonNull)

Example 8 with Event

use of org.hisp.dhis.android.core.event.Event in project dhis2-android-sdk by dhis2.

the class TrackedEntityInstancePostCallRealIntegrationShould method getEventsFromDb.

private Event getEventsFromDb(String eventUid) {
    EventStoreImpl eventStore = new EventStoreImpl(databaseAdapter());
    Event event = null;
    List<Event> storedEvents = eventStore.queryAll();
    for (Event storedEvent : storedEvents) {
        if (storedEvent.uid().equals(eventUid)) {
            event = storedEvent;
        }
    }
    return event;
}
Also used : EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) Event(org.hisp.dhis.android.core.event.Event)

Aggregations

Event (org.hisp.dhis.android.core.event.Event)8 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Enrollment (org.hisp.dhis.android.core.enrollment.Enrollment)4 EventStoreImpl (org.hisp.dhis.android.core.event.EventStoreImpl)4 NonNull (android.support.annotation.NonNull)2 HashMap (java.util.HashMap)2 Relationship (org.hisp.dhis.android.core.relationship.Relationship)2 Test (org.junit.Test)2 Map (java.util.Map)1 EnrollmentStoreImpl (org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl)1 EventStore (org.hisp.dhis.android.core.event.EventStore)1 TrackedEntityAttributeValue (org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue)1 TrackedEntityDataValue (org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue)1 TrackedEntityDataValueStore (org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore)1 TrackedEntityDataValueStoreImpl (org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl)1 TrackedEntityInstance (org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance)1