Search in sources :

Example 1 with Event

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

the class TrackedEntityInstanceCallMockIntegrationShould method getDownloadedTei.

private TrackedEntityInstance getDownloadedTei(String teiUid) {
    TrackedEntityInstance downloadedTei;
    TrackedEntityAttributeValueStore teiAttributeValuesStore = new TrackedEntityAttributeValueStoreImpl(databaseAdapter());
    Map<String, List<TrackedEntityAttributeValue>> attValues = teiAttributeValuesStore.queryAll();
    TrackedEntityInstanceStoreImpl teiStore = new TrackedEntityInstanceStoreImpl(databaseAdapter());
    downloadedTei = teiStore.queryAll().get(teiUid);
    EnrollmentStoreImpl enrollmentStore = new EnrollmentStoreImpl(databaseAdapter());
    Map<String, List<Enrollment>> downloadedEnrollments = enrollmentStore.queryAll();
    EventStoreImpl eventStore = new EventStoreImpl(databaseAdapter());
    List<Event> downloadedEventsWithoutValues = eventStore.queryAll();
    TrackedEntityDataValueStoreImpl trackedEntityDataValue = new TrackedEntityDataValueStoreImpl(databaseAdapter());
    Map<String, List<TrackedEntityDataValue>> downloadedValues = trackedEntityDataValue.queryTrackedEntityDataValues();
    return createTei(downloadedTei, attValues, downloadedEnrollments.get(teiUid), downloadedEventsWithoutValues, downloadedValues);
}
Also used : EnrollmentStoreImpl(org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl) EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) Event(org.hisp.dhis.android.core.event.Event) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Event

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

the class TrackedEntityInstancePostCallRealIntegrationShould method pull_event_after_push_tracked_entity_instance_with_that_event.

/*
    * If you want run this test you need config the correct uids in the server side.
    * At this moment is necessary add into the "child programme" program the category combo : Implementing Partner
    * */
// @Test
public void pull_event_after_push_tracked_entity_instance_with_that_event() throws Exception {
    downloadMetadata();
    createDummyDataToPost(orgUnitUid, programUid, programStageUid, trackedEntityUid, coordinates, featureType, eventUid, enrollmentUid, trackedEntityInstanceUid, trackedEntityAttributeUid, dataElementUid);
    postTrackedEntityInstances();
    TrackedEntityInstance pushedTrackedEntityInstance = getTrackedEntityInstanceFromDB(trackedEntityInstanceUid);
    Enrollment pushedEnrollment = getEnrollmentsByTrackedEntityInstanceFromDb(trackedEntityInstanceUid);
    Event pushedEvent = getEventsFromDb(eventUid);
    d2.wipeDB().call();
    downloadMetadata();
    TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = TrackedEntityInstanceCallFactory.create(d2.retrofit(), databaseAdapter(), trackedEntityInstanceUid);
    trackedEntityInstanceEndPointCall.call();
    TrackedEntityInstance downloadedTrackedEntityInstance = getTrackedEntityInstanceFromDB(trackedEntityInstanceUid);
    Enrollment downloadedEnrollment = getEnrollmentsByTrackedEntityInstanceFromDb(trackedEntityInstanceUid);
    Event downloadedEvent = getEventsFromDb(eventUid);
    assertPushAndDownloadTrackedEntityInstances(pushedTrackedEntityInstance, pushedEnrollment, pushedEvent, downloadedTrackedEntityInstance, downloadedEnrollment, downloadedEvent);
}
Also used : Enrollment(org.hisp.dhis.android.core.enrollment.Enrollment) Event(org.hisp.dhis.android.core.event.Event)

Example 3 with Event

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

the class DataBaseMigrationShould method have_database_version_3_after_migration_from_database_with_content.

@Test
public void have_database_version_3_after_migration_from_database_with_content() throws IOException {
    // given
    final String finalEventScheme = "CREATE TABLE Event (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL " + "UNIQUE,enrollment TEXT, created TEXT,lastUpdated TEXT,createdAtClient " + "TEXT,lastUpdatedAtClient TEXT,status TEXT,latitude TEXT,longitude " + "TEXT,program TEXT NOT NULL,programStage TEXT NOT NULL,organisationUnit" + " TEXT NOT NULL,eventDate TEXT,completedDate TEXT,dueDate TEXT,state " + "TEXT, attributeCategoryOptions TEXT, attributeOptionCombo TEXT, " + "trackedEntityInstance TEXT, FOREIGN KEY (program) REFERENCES Program " + "(uid) ON DELETE CASCADE, FOREIGN KEY (programStage) REFERENCES " + "ProgramStage (uid) ON DELETE CASCADE,FOREIGN KEY (enrollment) " + "REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY " + "DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit " + "(uid) ON DELETE CASCADE)";
    final String finalTrackedEntityDataValueScheme = "CREATE TABLE TrackedEntityDataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,event" + " TEXT NOT NULL,dataElement TEXT NOT NULL,storedBy TEXT,value TEXT," + "created TEXT,lastUpdated TEXT,providedElsewhere INTEGER, FOREIGN KEY " + "(dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE,  FOREIGN" + " KEY (event) REFERENCES Event (uid) ON DELETE CASCADE)";
    initCoreDataBase(dbName, 2, realMigrationDir, databaseSqlVersion2_with_data);
    EventStore eventStore = new EventStoreImpl(databaseAdapter);
    List<Event> eventList = eventStore.queryAll();
    TrackedEntityDataValueStore trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter);
    Map<String, List<TrackedEntityDataValue>> listOfTrackedEntityDataValues = trackedEntityDataValueStore.queryTrackedEntityDataValues();
    // when
    initCoreDataBase(dbName, 3, realMigrationDir, "");
    eventStore = new EventStoreImpl(databaseAdapter);
    trackedEntityDataValueStore = new TrackedEntityDataValueStoreImpl(databaseAdapter);
    // then
    assertTrue(eventList.equals(eventStore.queryAll()));
    assertTrue(eventList.size() == 50);
    assertTrue(listOfTrackedEntityDataValues.equals(trackedEntityDataValueStore.queryTrackedEntityDataValues()));
    assertTrue(listOfTrackedEntityDataValues.size() == 50);
    assertTrue(listOfTrackedEntityDataValues.get(eventList.get(0).uid()).equals(listOfTrackedEntityDataValues.get(eventList.get(0).uid())));
    assertTrue(getSqlTableScheme(databaseAdapter, "Event").equals(finalEventScheme));
    assertTrue(getSqlTableScheme(databaseAdapter, "TrackedEntityDataValue").equals(finalTrackedEntityDataValueScheme));
}
Also used : TrackedEntityDataValueStore(org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore) EventStore(org.hisp.dhis.android.core.event.EventStore) EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) TrackedEntityDataValueStoreImpl(org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl) Event(org.hisp.dhis.android.core.event.Event) List(java.util.List) Test(org.junit.Test)

Example 4 with Event

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

the class SingleDataCallMockIntegrationShould method download_number_of_events_according_to_limit_by_org_unit.

@Test
public void download_number_of_events_according_to_limit_by_org_unit() throws Exception {
    int eventLimitByOrgUnit = 122;
    givenAMetadataInDatabase();
    dhis2MockServer.enqueueMockResponse("system_info.json");
    dhis2MockServer.enqueueMockResponse("events_1.json");
    dhis2MockServer.enqueueMockResponse("events_2.json");
    dhis2MockServer.enqueueMockResponse("events_3.json");
    d2.syncSingleData(eventLimitByOrgUnit).call();
    EventStoreImpl eventStore = new EventStoreImpl(databaseAdapter());
    List<Event> downloadedEvents = eventStore.querySingleEvents();
    assertThat(downloadedEvents.size(), is(eventLimitByOrgUnit));
}
Also used : EventStoreImpl(org.hisp.dhis.android.core.event.EventStoreImpl) Event(org.hisp.dhis.android.core.event.Event) Test(org.junit.Test)

Example 5 with Event

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

the class TrackedEntityInstancePostCall method queryDataToSync.

@NonNull
private List<TrackedEntityInstance> queryDataToSync() {
    Map<String, List<TrackedEntityDataValue>> dataValueMap = trackedEntityDataValueStore.queryTrackedEntityDataValues(Boolean.FALSE);
    Map<String, List<Event>> eventMap = eventStore.queryEventsAttachedToEnrollmentToPost();
    Map<String, List<Enrollment>> enrollmentMap = enrollmentStore.query();
    Map<String, List<TrackedEntityAttributeValue>> attributeValueMap = trackedEntityAttributeValueStore.query();
    Map<String, TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceStore.queryToPost();
    List<TrackedEntityInstance> trackedEntityInstancesRecreated = new ArrayList<>();
    List<Relationship> relationshipRecreated = new ArrayList<>();
    // EMPTY LISTS TO REPLACE NULL VALUES SO THAT API DOESN'T BREAK.
    List<TrackedEntityAttributeValue> emptyAttributeValueList = new ArrayList<>();
    for (Map.Entry<String, TrackedEntityInstance> teiUid : trackedEntityInstances.entrySet()) {
        List<Enrollment> enrollmentsRecreated = new ArrayList<>();
        List<Enrollment> enrollments = enrollmentMap.get(teiUid.getKey());
        // if enrollments is not null, then they exist for this tracked entity instance
        if (enrollments != null) {
            List<Event> eventRecreated = new ArrayList<>();
            // building enrollment
            int enrollmentSize = enrollments.size();
            for (int i = 0; i < enrollmentSize; i++) {
                Enrollment enrollment = enrollments.get(i);
                // building events for enrollment
                List<Event> eventsForEnrollment = eventMap.get(enrollment.uid());
                // if eventsForEnrollment is not null, then they exist for this enrollment
                if (eventsForEnrollment != null) {
                    int eventSize = eventsForEnrollment.size();
                    for (int j = 0; j < eventSize; j++) {
                        Event event = eventsForEnrollment.get(j);
                        List<TrackedEntityDataValue> dataValuesForEvent = dataValueMap.get(event.uid());
                        eventRecreated.add(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(), dataValuesForEvent, event.attributeCategoryOptions(), event.attributeOptionCombo(), event.trackedEntityInstance()));
                    }
                }
                // TODO recreate with notes
                enrollmentsRecreated.add(Enrollment.create(enrollment.uid(), enrollment.created(), enrollment.lastUpdated(), enrollment.createdAtClient(), enrollment.lastUpdatedAtClient(), enrollment.organisationUnit(), enrollment.program(), enrollment.dateOfEnrollment(), enrollment.dateOfIncident(), enrollment.followUp(), enrollment.enrollmentStatus(), enrollment.trackedEntityInstance(), enrollment.coordinate(), enrollment.deleted(), eventRecreated, null));
            }
        }
        // Building TEI WITHOUT (new ArrayList) relationships
        List<TrackedEntityAttributeValue> attributeValues = attributeValueMap.get(teiUid.getKey());
        // Then we need to set it to empty arrayList so that API doesn't break
        if (attributeValues == null) {
            attributeValues = emptyAttributeValueList;
        }
        TrackedEntityInstance trackedEntityInstance = trackedEntityInstances.get(teiUid.getKey());
        trackedEntityInstancesRecreated.add(TrackedEntityInstance.create(trackedEntityInstance.uid(), trackedEntityInstance.created(), trackedEntityInstance.lastUpdated(), trackedEntityInstance.createdAtClient(), trackedEntityInstance.lastUpdatedAtClient(), trackedEntityInstance.organisationUnit(), trackedEntityInstance.trackedEntity(), trackedEntityInstance.coordinates(), trackedEntityInstance.featureType(), trackedEntityInstance.deleted(), attributeValues, relationshipRecreated, enrollmentsRecreated));
    }
    return trackedEntityInstancesRecreated;
}
Also used : TrackedEntityAttributeValue(org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue) ArrayList(java.util.ArrayList) TrackedEntityDataValue(org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue) TrackedEntityInstance(org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance) Relationship(org.hisp.dhis.android.core.relationship.Relationship) Enrollment(org.hisp.dhis.android.core.enrollment.Enrollment) Event(org.hisp.dhis.android.core.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) NonNull(android.support.annotation.NonNull)

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