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);
}
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);
}
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));
}
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));
}
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;
}
Aggregations