diff --git a/build.gradle b/build.gradle index 2ab2b4b74b..6b8adc659c 100644 --- a/build.gradle +++ b/build.gradle @@ -54,8 +54,8 @@ ext { buildToolsVersion: "25.0.2", minSdkVersion : 15, targetSdkVersion : 25, - versionCode : 751, - versionName : "0.7.5.1-SNAPSHOT" + versionCode : 90, + versionName : "0.9-SNAPSHOT" ] libraries = [ diff --git a/core/build.gradle b/core/build.gradle index 0ad8b6120a..e0c57f4113 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -108,6 +108,13 @@ dependencies { compile "com.squareup.retrofit2:retrofit:${libraries.retrofit}" compile "com.squareup.retrofit2:converter-jackson:${libraries.retrofit}" + // Apache libraries + compile group: 'org.apache.commons', name: 'commons-jexl', version: '2.1.1' + compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4' + + // Joda time + compile group: 'joda-time', name: 'joda-time', version: '2.9.9' + // Extension which generates mappers for work with cursor and content values compile "com.gabrielittner.auto.value:auto-value-cursor-annotations:${libraries.autovaluecursor}" annotationProcessor "com.gabrielittner.auto.value:auto-value-cursor:${libraries.autovaluecursor}" diff --git a/core/src/androidTest/assets/data_sets_with_access.json b/core/src/androidTest/assets/data_sets_with_access.json deleted file mode 100644 index ad43f324a4..0000000000 --- a/core/src/androidTest/assets/data_sets_with_access.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "dataSets": [ - { - "id": "lyLU2wR22tC", - "access": { - "data": { - "read": true - } - } - } - ] -} \ No newline at end of file diff --git a/core/src/androidTest/assets/programs_with_access.json b/core/src/androidTest/assets/programs_with_access.json deleted file mode 100644 index c552dd098f..0000000000 --- a/core/src/androidTest/assets/programs_with_access.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "programs": [ - { - "id": "lxAQ7Zs9VYR", - "access": { - "data": { - "read": true - } - } - } - ] -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java index 818ccdbaf1..d4ecb63948 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/LogoutCallMockIntegrationShould.java @@ -166,11 +166,8 @@ public void complete_login_and_sync_metadata_successfully_after_logout() } private void givenALoginInDatabase() throws Exception { - dhis2MockServer.enqueueMockResponse("login.json", new Date()); - dhis2MockServer.enqueueMockResponse("system_info.json", new Date()); - + dhis2MockServer.enqueueLoginResponses(); Response response = d2.logIn("user", "password").call(); - assertThat(response.isSuccessful(), is(true)); } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java index 8f14d06e14..d5f84769d3 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/TeisCallRealIntegrationShould.java @@ -3,10 +3,13 @@ import org.hisp.dhis.android.core.common.D2Factory; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.server.RealServerMother; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; import org.hisp.dhis.android.core.user.User; import org.junit.Before; +import org.junit.Test; import java.io.IOException; +import java.util.List; import retrofit2.Response; @@ -33,7 +36,8 @@ public void download_tracked_entity_instances() throws Exception { Response metadataResponse = d2.syncMetaData().call(); assertThat(metadataResponse.isSuccessful()).isTrue(); - Response teiResponse = d2.downloadTrackedEntityInstances(5).call(); - assertThat(teiResponse.isSuccessful()).isTrue(); + List trackedEntityInstances = + d2.downloadTrackedEntityInstances(5, false).call(); + assertThat(trackedEntityInstances.size() == 5).isTrue(); } -} +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.java new file mode 100644 index 0000000000..ce86df016e --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/TrackedEntityInstanceQueryAndDownloadRealIntegrationShould.java @@ -0,0 +1,67 @@ +package org.hisp.dhis.android.core; + +import org.hisp.dhis.android.core.common.D2Factory; +import org.hisp.dhis.android.core.data.api.OuMode; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.data.server.RealServerMother; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; +import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQuery; +import org.hisp.dhis.android.core.user.User; +import org.junit.Before; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import retrofit2.Response; + +import static com.google.common.truth.Truth.assertThat; + +public class TrackedEntityInstanceQueryAndDownloadRealIntegrationShould extends AbsStoreTestCase { + private D2 d2; + private TrackedEntityInstanceQuery.Builder queryBuilder; + + @Before + @Override + public void setUp() throws IOException { + super.setUp(); + + d2 = D2Factory.create(RealServerMother.url, databaseAdapter()); + + + List orgUnits = new ArrayList<>(); + orgUnits.add("O6uvpzGd5pu"); + + queryBuilder = TrackedEntityInstanceQuery.builder() + .paging(true).page(1).pageSize(50) + .orgUnits(orgUnits).orgUnitMode(OuMode.ACCESSIBLE); + } + + //@Test + public void query_and_download_tracked_entity_instances() throws Exception { + login(); + + d2.syncMetaData().call(); + + TrackedEntityInstanceQuery query = queryBuilder.build(); + List queriedTeis = d2.queryTrackedEntityInstances(query).call(); + assertThat(queriedTeis).isNotEmpty(); + + Set uids = new HashSet<>(queriedTeis.size()); + + for(TrackedEntityInstance tei: queriedTeis) { + uids.add(tei.uid()); + } + + List downloadedTeis = d2.downloadTrackedEntityInstancesByUid(uids).call(); + assertThat(queriedTeis.size()).isEqualTo(downloadedTeis.size()); + } + + private void login() throws Exception { + d2.logout().call(); + Response loginResponse = d2.logIn("android", "Android123").call(); + assertThat(loginResponse.isSuccessful()).isTrue(); + } +} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java index 76a2b1c277..c999420391 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/TrackerDataCallMockIntegrationShould.java @@ -27,8 +27,6 @@ import java.util.List; import java.util.Map; -import retrofit2.Response; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsNull.notNullValue; @@ -38,9 +36,9 @@ public class TrackerDataCallMockIntegrationShould extends AbsStoreTestCase { private Dhis2MockServer dhis2MockServer; private D2 d2; - TrackedEntityInstanceStore trackedEntityInstanceStore; - ResourceStore resourceStore; - EnrollmentStore enrollmentStore; + private TrackedEntityInstanceStore trackedEntityInstanceStore; + private ResourceStore resourceStore; + private EnrollmentStore enrollmentStore; @Override @Before @@ -70,9 +68,9 @@ public void not_download_tracked_entity_instances_if_does_not_exists_nothing_in_ givenAMetadataInDatabase(); - Response response = d2.syncTrackerData().call(); + d2.syncTrackerData().call(); - verifyHaveNotSynchronized(response, Collections.EMPTY_LIST); + verifyHaveNotSynchronized(Collections.EMPTY_LIST); } @Test @@ -84,9 +82,9 @@ public void not_download_tracked_entity_instances_if_does_not_exists_synced_in_d TrackedEntityInstance toPostTrackedEntityInstance = givenAToPostTrackedEntityInstanceInDatabase(); - Response response = d2.syncTrackerData().call(); + d2.syncTrackerData().call(); - verifyHaveNotSynchronized(response, Arrays.asList(toPostTrackedEntityInstance)); + verifyHaveNotSynchronized(Arrays.asList(toPostTrackedEntityInstance)); } @Test @@ -102,10 +100,9 @@ public void only_download_synced_tracked_entity_instance_that_exists_in_database dhis2MockServer.enqueueMockResponse("tracked_entity_instance.json"); - Response response = d2.syncTrackerData().call(); + d2.syncTrackerData().call(); - verifyHaveSynchronized(response, - Arrays.asList(syncedTrackedEntityInstance), + verifyHaveSynchronized(Arrays.asList(syncedTrackedEntityInstance), Arrays.asList(toPostTrackedEntityInstance)); } @@ -114,20 +111,18 @@ public void download_all_synced_tracked_entity_instances_that_exists_in_database throws Exception { givenAMetadataInDatabase(); - List trackedEntityInstances = - givenASyncedTrackedEntityInstancesInDatabase(); + List trackedEntityInstances = givenASyncedTrackedEntityInstancesInDatabase(); dhis2MockServer.enqueueMockResponse("tracked_entity_instance.json"); dhis2MockServer.enqueueMockResponse("tracked_entity_instance_2.json"); - Response response = d2.syncTrackerData().call(); + d2.syncTrackerData().call(); - verifyHaveSynchronized(response, trackedEntityInstances, Collections.EMPTY_LIST); + verifyHaveSynchronized(trackedEntityInstances, Collections.EMPTY_LIST); } - private void verifyHaveSynchronized(Response response, - List syncedExpected, - List toPostExpected) { + private void verifyHaveSynchronized(List syncedExpected, + List toPostExpected) { Map toPostInDatabase = trackedEntityInstanceStore.queryToPost(); @@ -140,7 +135,6 @@ private void verifyHaveSynchronized(Response response, Map> enrollmentsMap = enrollmentStore.queryAll(); - assertThat(response.isSuccessful(), is(true)); assertThat(syncedInDatabase.size(), is(syncedExpected.size())); assertThat(lastUpdated, is(nullValue())); assertThat(toPostInDatabase.size(), is(toPostExpected.size())); @@ -156,7 +150,7 @@ private void verifyHaveSynchronized(Response response, } } - private void verifyHaveNotSynchronized(Response response, + private void verifyHaveNotSynchronized( List expectedToPost) { Map inDatabaseToPost = @@ -168,7 +162,6 @@ private void verifyHaveNotSynchronized(Response response, String lastUpdated = resourceStore.getLastUpdated( ResourceModel.Type.TRACKED_ENTITY_INSTANCE); - assertThat(response, is(nullValue())); assertThat(inDatabaseSynced.size(), is(0)); assertThat(lastUpdated, is(nullValue())); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/constant/ConstantModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/constant/ConstantModelShould.java index c9055a0f26..bbc6b36c89 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/constant/ConstantModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/constant/ConstantModelShould.java @@ -28,82 +28,51 @@ package org.hisp.dhis.android.core.constant; -import android.content.ContentValues; -import android.database.MatrixCursor; +import android.database.Cursor; import android.support.test.runner.AndroidJUnit4; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.IdentifiableModelAbstractShould; import org.hisp.dhis.android.core.constant.ConstantModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Date; +import java.util.Arrays; +import java.util.List; import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.fillIdentifiableModelProperties; @RunWith(AndroidJUnit4.class) -public class ConstantModelShould { - - private static final Long ID = 11L; - private static final String UID = "test_uid"; - private static final String CODE = "test_code"; - private static final String NAME = "test_name"; - private static final String DISPLAY_NAME = "test_display_name"; - private static final String VALUE = "0.18"; - - private final Date date; - private final String dateString; +public class ConstantModelShould extends IdentifiableModelAbstractShould { public ConstantModelShould() { - this.date = new Date(); - this.dateString = BaseIdentifiableObject.DATE_FORMAT.format(date); + super(new Columns().all(), 7); } - @Test - public void create_model_when_created_from_database_cursor() { - MatrixCursor cursor = new MatrixCursor(new String[]{ - Columns.ID, Columns.UID, Columns.CODE, Columns.NAME, - Columns.DISPLAY_NAME, Columns.CREATED, Columns.LAST_UPDATED, Columns.VALUE - }); - cursor.addRow(new Object[]{ID, UID, CODE, NAME, DISPLAY_NAME, dateString, dateString, VALUE}); - cursor.moveToFirst(); + @Override + protected ConstantModel buildModel() { + ConstantModel.Builder builder = ConstantModel.builder(); + fillIdentifiableModelProperties(builder); + builder.value("0.18"); + return builder.build(); + } - ConstantModel model = ConstantModel.create(cursor); - cursor.close(); + @Override + protected ConstantModel cursorToModel(Cursor cursor) { + return ConstantModel.create(cursor); + } - assertThat(model.id()).isEqualTo(ID); - assertThat(model.uid()).isEqualTo(UID); - assertThat(model.code()).isEqualTo(CODE); - assertThat(model.name()).isEqualTo(NAME); - assertThat(model.displayName()).isEqualTo(DISPLAY_NAME); - assertThat(model.created()).isEqualTo(date); - assertThat(model.lastUpdated()).isEqualTo(date); - assertThat(model.value()).isEqualTo(VALUE); + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getIdentifiableModelAsObjectArray(model), model.value()); } @Test - public void create_content_values_when_created_from_builder() { - ConstantModel model = ConstantModel.builder() - .id(ID) - .uid(UID) - .code(CODE) - .name(NAME) - .displayName(DISPLAY_NAME) - .created(date) - .lastUpdated(date) - .value(VALUE) - .build(); - - ContentValues contentValues = model.toContentValues(); - - assertThat(contentValues.getAsLong(Columns.ID)).isEqualTo(ID); - assertThat(contentValues.getAsString(Columns.UID)).isEqualTo(UID); - assertThat(contentValues.getAsString(Columns.CODE)).isEqualTo(CODE); - assertThat(contentValues.getAsString(Columns.NAME)).isEqualTo(NAME); - assertThat(contentValues.getAsString(Columns.DISPLAY_NAME)).isEqualTo(DISPLAY_NAME); - assertThat(contentValues.getAsString(Columns.CREATED)).isEqualTo(dateString); - assertThat(contentValues.getAsString(Columns.LAST_UPDATED)).isEqualTo(dateString); - assertThat(contentValues.getAsString(Columns.VALUE)).isEqualTo(VALUE); // Undeprecated in later versions of Truth + public void have_extra_legend_model_columns() { + List columnsList = Arrays.asList(columns); + assertThat(columnsList.contains(Columns.VALUE)).isEqualTo(true); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/constant/ConstantStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/constant/ConstantStoreShould.java deleted file mode 100644 index 8da969b423..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/constant/ConstantStoreShould.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2017, University of Oslo - * - * All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.constant; - -import android.database.Cursor; - -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.util.Date; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; - -public class ConstantStoreShould extends AbsStoreTestCase { - - private ConstantStore store; - - private static final String UID = "test_uid"; - private static final String CODE = "test_code"; - private static final String NAME = "test_name"; - private static final String DISPLAY_NAME = "test_display_name"; - private static final Date CREATED = new java.util.Date(); - private static final Date LAST_UPDATED = new java.util.Date(); - private static final String VALUE = "0.18"; - - private static final String[] CONSTANT_PROJECTION = { - ConstantModel.Columns.UID, ConstantModel.Columns.CODE, ConstantModel.Columns.NAME, ConstantModel.Columns.DISPLAY_NAME, - ConstantModel.Columns.CREATED, ConstantModel.Columns.LAST_UPDATED, ConstantModel.Columns.VALUE - }; - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - store = new ConstantStoreImpl(databaseAdapter()); - } - - @Test - public void persist_row_in_database_when_insert() { - long rowId = store.insert(UID, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, VALUE); - Cursor cursor = database().query(ConstantModel.TABLE, CONSTANT_PROJECTION, null, null, null, null, null); - - assertThat(rowId).isNotEqualTo(-1L); // Checks that the insert was successful (row ID would otherwise be -1) - - assertThatCursor(cursor).hasRow(UID, CODE, NAME, DISPLAY_NAME, BaseIdentifiableObject.DATE_FORMAT.format(CREATED), BaseIdentifiableObject.DATE_FORMAT.format(LAST_UPDATED), VALUE); - assertThatCursor(cursor).isExhausted(); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_insert_null_uid() { - store.insert(null, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, VALUE); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java index 6d420ded31..b290885024 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/database/migrations/DataBaseMigrationShould.java @@ -1,78 +1,33 @@ package org.hisp.dhis.android.core.data.database.migrations; -import static org.hamcrest.CoreMatchers.is; -import static org.hisp.dhis.android.core.data.database.SqliteCheckerUtility.ifTableExist; -import static org.hisp.dhis.android.core.data.database.SqliteCheckerUtility.ifValueExist; -import static org.hisp.dhis.android.core.data.database.SqliteCheckerUtility.isFieldExist; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; -import org.hisp.dhis.android.core.D2; -import org.hisp.dhis.android.core.category.CategoryCategoryComboLinkModel; -import org.hisp.dhis.android.core.category.CategoryCategoryOptionLinkModel; -import org.hisp.dhis.android.core.category.CategoryComboModel; -import org.hisp.dhis.android.core.category.CategoryModel; -import org.hisp.dhis.android.core.category.CategoryOptionComboModel; -import org.hisp.dhis.android.core.category.CategoryOptionModel; -import org.hisp.dhis.android.core.configuration.ConfigurationModel; -import org.hisp.dhis.android.core.data.api.BasicAuthenticatorFactory; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.DbOpenHelper; import org.hisp.dhis.android.core.data.database.SqLiteDatabaseAdapter; -import org.hisp.dhis.android.core.dataelement.DataElementModel; -import org.hisp.dhis.android.core.event.Event; -import org.hisp.dhis.android.core.event.EventModel; -import org.hisp.dhis.android.core.event.EventStore; -import org.hisp.dhis.android.core.event.EventStoreImpl; -import org.hisp.dhis.android.core.program.ProgramModel; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValueModel; import org.hisp.dhis.android.core.user.UserModel; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import okhttp3.OkHttpClient; -import okhttp3.mockwebserver.MockWebServer; +import static org.hamcrest.CoreMatchers.is; +import static org.hisp.dhis.android.core.data.database.SqliteCheckerUtility.ifTableExist; +import static org.junit.Assert.assertThat; @RunWith(AndroidJUnit4.class) public class DataBaseMigrationShould { - private MockWebServer mockWebServer; - - private D2 d2; private DatabaseAdapter databaseAdapter; - DbOpenHelper dbOpenHelper; - - public static final String realMigrationDir = "migrations/real_migrations"; - public static final String fakeDataDir = "migrations/fake_data"; - public static final String exampleMigrationsDir = "migrations/example_migrations"; - public static final String databaseSqlVersion1 = "db_version_1.sql"; - public static final String databaseSqlVersion2_with_data = "db_version_2_with_data.sql"; - public static final String databaseSqlVersion2 = "db_version_2.sql"; - public static final String databaseSqlVersionLast = "db_version_" + DbOpenHelper.VERSION + ".sql"; - static String dbName= null; + private DbOpenHelper dbOpenHelper; + private String dbName = null; private SQLiteDatabase databaseInMemory; @Before - public void deleteDB(){ - mockWebServer = new MockWebServer(); - try { - mockWebServer.start(); - } catch (IOException e) { - e.printStackTrace(); - } - if(dbName!=null) { + public void deleteDB() { + if (dbName != null) { InstrumentationRegistry.getContext().deleteDatabase(dbName); } dbOpenHelper = null; @@ -80,219 +35,35 @@ public void deleteDB(){ } @After - public void tearDown() throws Exception { - if(dbName!=null) { + public void tearDown() { + if (dbName != null) { InstrumentationRegistry.getContext().deleteDatabase(dbName); } } @Test - public void have_user_table_after_first_migration() throws IOException { - initCoreDataBase(dbName, 1, exampleMigrationsDir, databaseSqlVersion1); + public void have_user_table_after_migration_1() { + initCoreDataBase(1); assertThat(ifTableExist(UserModel.TABLE, databaseAdapter), is(true)); } @Test - public void have_category_table_after_first_migration() throws IOException { - initCoreDataBase(dbName, 1, realMigrationDir, databaseSqlVersion1); - initCoreDataBase(dbName, 2, realMigrationDir, ""); - assertVersion2MigrationChanges(databaseAdapter); - } - - @Test - public void have_categoryCombo_columns_after_first_migration() throws IOException { - initCoreDataBase(dbName, 1, realMigrationDir, databaseSqlVersion1); - initCoreDataBase(dbName, 2, realMigrationDir, ""); - assertThat(isFieldExist(DataElementModel.TABLE, DataElementModel.Columns.CATEGORY_COMBO, databaseAdapter), is(true)); - assertThat(isFieldExist(ProgramModel.TABLE, ProgramModel.Columns.CATEGORY_COMBO, databaseAdapter), is(true)); - } - - @Test - public void have_categoryCombo_columns_after_create_version_2_or_newer() throws IOException { - buildD2(initCoreDataBase(dbName, DbOpenHelper.VERSION, realMigrationDir, databaseSqlVersionLast)); - assertVersion2MigrationChanges(d2.databaseAdapter()); - } - - @Test - public void have_categoryCombo_columns_after_create_last_version() throws IOException { - buildD2(initCoreDataBase(dbName, 2, realMigrationDir, "")); - assertThat(isFieldExist(DataElementModel.TABLE, DataElementModel.Columns.CATEGORY_COMBO, d2.databaseAdapter()), is(true)); - assertThat(isFieldExist(ProgramModel.TABLE, ProgramModel.Columns.CATEGORY_COMBO, d2.databaseAdapter()), is(true)); - } - - @Test - public void have_new_column_when_up_migration_add_column() throws IOException { - initCoreDataBase(dbName, 1, exampleMigrationsDir, databaseSqlVersion1); - initCoreDataBase(dbName, 3, exampleMigrationsDir, ""); - assertThat(isFieldExist(UserModel.TABLE, "testColumn", databaseAdapter), is(true)); - } - - @Test - public void have_new_value_when_seed_migration_add_row() { - initCoreDataBase(dbName, 1, exampleMigrationsDir, databaseSqlVersion1); - initCoreDataBase(dbName, 3, exampleMigrationsDir, ""); - assertThat(isFieldExist(UserModel.TABLE, "testColumn", databaseAdapter), is(true)); - assertThat(ifTableExist("TestTable", databaseAdapter), is(true)); - assertThat(ifValueExist("TestTable", "testColumn","1", databaseAdapter), is(true)); - } - - @Test - public void have_database_version_3_after_migration_from_1() { - //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, 1, realMigrationDir, databaseSqlVersion1); - //when - initCoreDataBase(dbName, 3, realMigrationDir, ""); - - //then - assertTrue(getSqlTableScheme(databaseAdapter, "Event").equals(finalEventScheme)); - assertTrue(getSqlTableScheme(databaseAdapter, "TrackedEntityDataValue").equals( - finalTrackedEntityDataValueScheme)); - } - - @Test - public void have_database_version_3_after_migration_from_2() { - //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); - //when - initCoreDataBase(dbName, 3, realMigrationDir, ""); - //then - assertTrue(getSqlTableScheme(databaseAdapter, "Event").equals(finalEventScheme)); - assertTrue(getSqlTableScheme(databaseAdapter, "TrackedEntityDataValue").equals( - finalTrackedEntityDataValueScheme)); - } - - @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 eventList = eventStore.queryAll(); - TrackedEntityDataValueStore trackedEntityDataValueStore = - new TrackedEntityDataValueStoreImpl(databaseAdapter); - Map> 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)); - + public void not_have_tracked_entity_attribute_reserved_value_table_after_migration_1() { + initCoreDataBase(1); + assertThat(ifTableExist(TrackedEntityAttributeReservedValueModel.TABLE, databaseAdapter), is(false)); } @Test - public void not_have_category_table_after_downgrade_with_database_version_2() throws IOException { - initCoreDataBase(dbName, 2, realMigrationDir, databaseSqlVersion2); - initCoreDataBase(dbName, 1, realMigrationDir, ""); - //TODO remove this tables in 2.yaml drop - //assertThat(ifTableExist(CategoryModel.TABLE, databaseAdapter), is(false)); - //assertThat(ifTableExist(CategoryOptionModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryOptionComboModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryComboModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryCategoryComboLinkModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryCategoryOptionLinkModel.TABLE, databaseAdapter), is(false)); + public void have_tracked_entity_attribute_reserved_value_table_after_first_migration_2() { + initCoreDataBase(2); + assertThat(ifTableExist(TrackedEntityAttributeReservedValueModel.TABLE, databaseAdapter), is(true)); } - @Test - public void not_have_category_table_after_downgrade_with_real_sql_database() throws - IOException { - initCoreDataBase(dbName, 2, realMigrationDir, ""); - initCoreDataBase(dbName, 1, realMigrationDir, ""); - //TODO remove Category and CategoryOption tables in 2.yaml drop migration - //assertThat(ifTableExist(CategoryModel.TABLE, databaseAdapter), is(false)); - //assertThat(ifTableExist(CategoryOptionModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryComboModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryOptionComboModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryCategoryComboLinkModel.TABLE, databaseAdapter), is(false)); - assertThat(ifTableExist(CategoryCategoryOptionLinkModel.TABLE, databaseAdapter), is(false)); - } - - @Test - public synchronized void have_dropped_table_when_down_migration_drop_table() { - initCoreDataBase(dbName, 1, exampleMigrationsDir, databaseSqlVersion1); - initCoreDataBase(dbName, 3, exampleMigrationsDir, databaseSqlVersion1); - initCoreDataBase(dbName, 1, exampleMigrationsDir, ""); - assertThat(isFieldExist(UserModel.TABLE, "testColumn", databaseAdapter), is(true)); - assertThat(ifTableExist("TestTable", databaseAdapter), is(false)); - } - - public DatabaseAdapter initCoreDataBase(String dbName, int databaseVersion, String testPath, - String databaseSqlVersion) { + public DatabaseAdapter initCoreDataBase(int databaseVersion) { if (databaseAdapter == null) { dbOpenHelper = new DbOpenHelper( InstrumentationRegistry.getTargetContext().getApplicationContext() - , dbName, databaseVersion, testPath, databaseSqlVersion); + , dbName, databaseVersion); databaseAdapter = new SqLiteDatabaseAdapter(dbOpenHelper); databaseInMemory = ((SqLiteDatabaseAdapter) databaseAdapter).database(); } else if (dbName == null) { @@ -308,42 +79,4 @@ public DatabaseAdapter initCoreDataBase(String dbName, int databaseVersion, Stri } return databaseAdapter; } - - private void buildD2(DatabaseAdapter databaseAdapter) { - ConfigurationModel config = ConfigurationModel.builder() - .serverUrl(mockWebServer.url("/")) - .build(); - d2 = new D2.Builder() - .configuration(config) - .okHttpClient(new OkHttpClient.Builder() - .addInterceptor(BasicAuthenticatorFactory.create(databaseAdapter)) - .build()) - .databaseAdapter(databaseAdapter).build(); - } - - private void assertVersion2MigrationChanges(DatabaseAdapter databaseAdapter) { - assertThat(ifTableExist(CategoryModel.TABLE, databaseAdapter), is(true)); - assertThat(ifTableExist(CategoryComboModel.TABLE, databaseAdapter), is(true)); - assertThat(ifTableExist(CategoryOptionComboModel.TABLE, databaseAdapter), is(true)); - assertThat(ifTableExist(CategoryOptionModel.TABLE, databaseAdapter), is(true)); - assertThat(ifTableExist(CategoryCategoryComboLinkModel.TABLE, databaseAdapter), is(true)); - assertThat(ifTableExist(CategoryCategoryOptionLinkModel.TABLE, databaseAdapter), is(true)); - assertThat(isFieldExist(ProgramModel.TABLE, ProgramModel.Columns.CATEGORY_COMBO, databaseAdapter), is(true)); - assertThat(isFieldExist(DataElementModel.TABLE, DataElementModel.Columns.CATEGORY_COMBO, databaseAdapter), is(true)); - assertThat(isFieldExist(EventModel.TABLE, EventModel.Columns.ATTRIBUTE_CATEGORY_OPTIONS, databaseAdapter), is(true)); - assertThat(isFieldExist(EventModel.TABLE, EventModel.Columns.ATTRIBUTE_OPTION_COMBO, databaseAdapter), is(true)); - assertThat(isFieldExist(EventModel.TABLE, EventModel.Columns.TRACKED_ENTITY_INSTANCE, databaseAdapter), is(true)); - } - - - private String getSqlTableScheme(DatabaseAdapter databaseAdapter, String table) { - String scheme; - Cursor cursor = databaseAdapter.query( - "SELECT sql FROM sqlite_master WHERE type='table' and name='" + table + "';"); - cursor.moveToFirst(); - scheme = cursor.getString(0); - cursor.close(); - return scheme; - } - } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java index 8fd769dc2e..686d2c8a6d 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/data/server/RealServerMother.java @@ -1,7 +1,7 @@ package org.hisp.dhis.android.core.data.server; public class RealServerMother { - public static String url = "https://play.dhis2.org/android-current/api/"; + public static String url = "https://play.dhis2.org/2.29/api/"; public static String user = "android"; public static String password = "Android123"; } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java deleted file mode 100644 index 9d7be0ccd3..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCallRealIntegrationShould.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.hisp.dhis.android.core.dataset; - -import android.support.test.runner.AndroidJUnit4; - -import org.hisp.dhis.android.core.D2; -import org.hisp.dhis.android.core.calls.Call; -import org.hisp.dhis.android.core.common.D2Factory; -import org.hisp.dhis.android.core.common.GenericCallData; -import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.IOException; -import java.util.Date; - -import retrofit2.Response; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(AndroidJUnit4.class) -public class DataSetAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { - private D2 d2; - private Call>> dataSetAccessCall; - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - d2 = D2Factory.create("https://play.dhis2.org/android-current/api/", databaseAdapter()); - dataSetAccessCall = createCall(); - } - - private Call>> createCall() { - GenericCallData data = GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date()); - - return DataSetAccessEndpointCall.FACTORY.create(data); - } - - @Test - public void download_data_sets() throws Exception { - if (!d2.isUserLoggedIn().call()) { - retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); - assertThat(loginResponse.isSuccessful()).isTrue(); - } - - retrofit2.Response dataSetResponse = dataSetAccessCall.call(); - assertThat(dataSetResponse.isSuccessful()).isTrue(); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java index ae21d9c46b..0605ded92f 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCallRealIntegrationShould.java @@ -14,8 +14,6 @@ import java.io.IOException; import java.util.Date; -import java.util.HashSet; -import java.util.Set; import retrofit2.Response; @@ -40,14 +38,7 @@ public void setUp() throws IOException { private Call>> createCall() { GenericCallData data = GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date()); - - Set uids = new HashSet<>(); - - uids.add("BfMAe6Itzgt"); - uids.add("Lpw6GcnTrmS"); - uids.add("TuL8IOPzpHh"); - - return DataSetEndpointCall.FACTORY.create(data, uids); + return DataSetEndpointCall.FACTORY.create(data); } // @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java index 4725822cff..c4335e06e2 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallMockIntegrationShould.java @@ -47,7 +47,6 @@ import org.hisp.dhis.android.core.program.ProgramModel; import org.hisp.dhis.android.core.resource.ResourceModel; import org.hisp.dhis.android.core.user.User; -import org.hisp.dhis.android.core.user.UserCredentials; import org.hisp.dhis.android.core.user.UserModel; import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; import org.junit.After; @@ -115,20 +114,11 @@ public void setUp() throws IOException { List organisationUnits = Collections.singletonList(OrganisationUnit.create("O6uvpzGd5pu", null, null, null, null, null, null, null, null, null, null, "/ImspTQPwCqd/O6uvpzGd5pu", null, null, null, null, null, null, false)); - UserCredentials userCredentials = UserCredentials.create("credentials_uid", "code", "name", null, null, - null, null, null, null); //dependencies for the OrganisationUnitCall: OrganisationUnitService organisationUnitService = d2.retrofit().create(OrganisationUnitService.class); // Create a user with the root as assigned organisation unit (for the test): - User user = User.create("user_uid", "code", "name", "display_name", new Date(), new Date(), "birthday", - "education", "gender", "job_title", "surname", "firstName", "introduction", "employer", "interests", - "languages", "email", "phoneNumber", "nationality", - userCredentials, - organisationUnits, - organisationUnits, - organisationUnits, - false); + User user = User.builder().uid("user_uid").organisationUnits(organisationUnits).build(); ContentValues userContentValues = new ContentValues(); userContentValues.put(UserModel.Columns.ID, "user_uid"); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java deleted file mode 100644 index 711776a7d1..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCallRealIntegrationShould.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.hisp.dhis.android.core.program; - -import android.support.test.runner.AndroidJUnit4; - -import org.hisp.dhis.android.core.D2; -import org.hisp.dhis.android.core.calls.Call; -import org.hisp.dhis.android.core.common.D2Factory; -import org.hisp.dhis.android.core.common.GenericCallData; -import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.IOException; -import java.util.Date; - -import retrofit2.Response; - -import static com.google.common.truth.Truth.assertThat; - -@RunWith(AndroidJUnit4.class) -public class ProgramAccessEndpointCallRealIntegrationShould extends AbsStoreTestCase { - private D2 d2; - private Call>> programAccessCall; - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - d2 = D2Factory.create("https://play.dhis2.org/android-current/api/", databaseAdapter()); - programAccessCall = createCall(); - } - - private Call>> createCall() { - GenericCallData data = GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date()); - return ProgramAccessEndpointCall.FACTORY.create(data); - } - - @Test - public void download_programs() throws Exception { - if (!d2.isUserLoggedIn().call()) { - retrofit2.Response loginResponse = d2.logIn("android", "Android123").call(); - assertThat(loginResponse.isSuccessful()).isTrue(); - } - - retrofit2.Response programResponse = programAccessCall.call(); - assertThat(programResponse.isSuccessful()).isTrue(); - } -} diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramEndpointCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramEndpointCallMockIntegrationShould.java index a85173e461..3b08c56578 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramEndpointCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramEndpointCallMockIntegrationShould.java @@ -56,8 +56,6 @@ import java.io.IOException; import java.util.Date; -import java.util.HashSet; -import java.util.Set; import retrofit2.Response; @@ -117,10 +115,6 @@ public void setUp() throws IOException { objectMapper.setDateFormat(BaseIdentifiableObject.DATE_FORMAT.raw()); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - Set uids = new HashSet<>(); - uids.add("uid1"); - uids.add("uids2"); - ContentValues categoryCombo = CreateCategoryComboUtils.create(1L, "nM3u9s5a52V"); database().insert(CategoryComboModel.TABLE, null, categoryCombo); @@ -132,7 +126,7 @@ public void setUp() throws IOException { database().insert(TrackedEntityTypeModel.TABLE, null, trackedEntityType); programEndpointCall = ProgramEndpointCall.FACTORY.create( - GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date()), uids); + GenericCallData.create(databaseAdapter(), d2.retrofit(), new Date())); } @Test diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorModelShould.java index 0902a0f62a..99cabdefe8 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorModelShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorModelShould.java @@ -28,131 +28,75 @@ package org.hisp.dhis.android.core.program; -import android.content.ContentValues; -import android.database.MatrixCursor; +import android.database.Cursor; import android.support.test.runner.AndroidJUnit4; -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.NameableModelAbstractShould; import org.hisp.dhis.android.core.program.ProgramIndicatorModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; import org.junit.Test; import org.junit.runner.RunWith; -import java.util.Date; +import java.util.Arrays; +import java.util.List; import static com.google.common.truth.Truth.assertThat; import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.fillNameableModelProperties; @RunWith(AndroidJUnit4.class) -public class ProgramIndicatorModelShould { - private static final long ID = 11L; - private static final String UID = "test_uid"; - private static final String CODE = "test_code"; - private static final String NAME = "test_name"; - private static final String DISPLAY_NAME = "test_display_name"; - private static final String SHORT_NAME = "test_short_name"; - private static final String DISPLAY_SHORT_NAME = "test_display_short_name"; - private static final String DESCRIPTION = "test_description"; - private static final String DISPLAY_DESCRIPTION = "test_display_description"; +public class ProgramIndicatorModelShould extends NameableModelAbstractShould { private static final Boolean DISPLAY_IN_FORM = true; private static final String EXPRESSION = "test_expression"; private static final String DIMENSION_ITEM = "test_dimension_item"; private static final String FILTER = "test_filter"; private static final Integer DECIMALS = 3; - - private final Date date; - private final String dateString; + private static final String PROGRAM = "program_uid"; public ProgramIndicatorModelShould() { - this.date = new Date(); - this.dateString = BaseIdentifiableObject.DATE_FORMAT.format(date); + super(new ProgramIndicatorModel.Columns().all(), 16); } - @Test - public void create_model_when_created_from_database_cursor() { - MatrixCursor cursor = new MatrixCursor(new String[]{ - Columns.ID, - Columns.UID, - Columns.CODE, - Columns.NAME, - Columns.DISPLAY_NAME, - Columns.CREATED, - Columns.LAST_UPDATED, - Columns.SHORT_NAME, - Columns.DISPLAY_SHORT_NAME, - Columns.DESCRIPTION, - Columns.DISPLAY_DESCRIPTION, - Columns.DISPLAY_IN_FORM, - Columns.EXPRESSION, - Columns.DIMENSION_ITEM, - Columns.FILTER, - Columns.DECIMALS - }); - cursor.addRow(new Object[]{ - ID, UID, CODE, NAME, DISPLAY_NAME, dateString, dateString, - SHORT_NAME, DISPLAY_SHORT_NAME, DESCRIPTION, DISPLAY_DESCRIPTION, - toInteger(DISPLAY_IN_FORM), EXPRESSION, - DIMENSION_ITEM, FILTER, DECIMALS - }); - cursor.moveToFirst(); - - ProgramIndicatorModel model = ProgramIndicatorModel.create(cursor); - cursor.close(); - - assertThat(model.id()).isEqualTo(ID); - assertThat(model.uid()).isEqualTo(UID); - assertThat(model.code()).isEqualTo(CODE); - assertThat(model.name()).isEqualTo(NAME); - assertThat(model.displayName()).isEqualTo(DISPLAY_NAME); - assertThat(model.created()).isEqualTo(date); - assertThat(model.lastUpdated()).isEqualTo(date); - assertThat(model.shortName()).isEqualTo(SHORT_NAME); - assertThat(model.displayShortName()).isEqualTo(DISPLAY_SHORT_NAME); - assertThat(model.description()).isEqualTo(DESCRIPTION); - assertThat(model.displayDescription()).isEqualTo(DISPLAY_DESCRIPTION); - assertThat(model.displayInForm()).isEqualTo(DISPLAY_IN_FORM); - assertThat(model.expression()).isEqualTo(EXPRESSION); - assertThat(model.dimensionItem()).isEqualTo(DIMENSION_ITEM); - assertThat(model.filter()).isEqualTo(FILTER); - assertThat(model.decimals()).isEqualTo(DECIMALS); - } - - @Test - public void create_content_values_when_created_from_builder() { - ProgramIndicatorModel model = ProgramIndicatorModel.builder() - .id(ID) - .uid(UID) - .code(CODE) - .name(NAME) - .displayName(DISPLAY_NAME) - .created(date) - .lastUpdated(date) - .shortName(SHORT_NAME) - .displayShortName(DISPLAY_SHORT_NAME) - .description(DESCRIPTION) - .displayDescription(DISPLAY_DESCRIPTION) + @Override + protected ProgramIndicatorModel buildModel() { + ProgramIndicatorModel.Builder programIndicatorModelBuilder = ProgramIndicatorModel.builder(); + fillNameableModelProperties(programIndicatorModelBuilder); + programIndicatorModelBuilder .displayInForm(DISPLAY_IN_FORM) .expression(EXPRESSION) .dimensionItem(DIMENSION_ITEM) .filter(FILTER) .decimals(DECIMALS) - .build(); - ContentValues contentValues = model.toContentValues(); + .program(PROGRAM); + return programIndicatorModelBuilder.build(); + } + + @Override + protected ProgramIndicatorModel cursorToModel(Cursor cursor) { + return ProgramIndicatorModel.create(cursor); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getNameableModelAsObjectArray(model), + toInteger(model.displayInForm()), + model.expression(), + model.dimensionItem(), + model.filter(), + model.decimals(), + model.program()); + } + + @Test + public void have_extra_data_set_model_columns() { + List columnsList = Arrays.asList(columns); - assertThat(contentValues.getAsLong(Columns.ID)).isEqualTo(ID); - assertThat(contentValues.getAsString(Columns.UID)).isEqualTo(UID); - assertThat(contentValues.getAsString(Columns.CODE)).isEqualTo(CODE); - assertThat(contentValues.getAsString(Columns.NAME)).isEqualTo(NAME); - assertThat(contentValues.getAsString(Columns.DISPLAY_NAME)).isEqualTo(DISPLAY_NAME); - assertThat(contentValues.getAsString(Columns.CREATED)).isEqualTo(dateString); - assertThat(contentValues.getAsString(Columns.LAST_UPDATED)).isEqualTo(dateString); - assertThat(contentValues.getAsString(Columns.SHORT_NAME)).isEqualTo(SHORT_NAME); - assertThat(contentValues.getAsString(Columns.DISPLAY_SHORT_NAME)).isEqualTo(DISPLAY_SHORT_NAME); - assertThat(contentValues.getAsString(Columns.DESCRIPTION)).isEqualTo(DESCRIPTION); - assertThat(contentValues.getAsString(Columns.DISPLAY_DESCRIPTION)).isEqualTo(DISPLAY_DESCRIPTION); - assertThat(contentValues.getAsBoolean(Columns.DISPLAY_IN_FORM)).isEqualTo(DISPLAY_IN_FORM); - assertThat(contentValues.getAsString(Columns.EXPRESSION)).isEqualTo(EXPRESSION); - assertThat(contentValues.getAsString(Columns.DIMENSION_ITEM)).isEqualTo(DIMENSION_ITEM); - assertThat(contentValues.getAsString(Columns.FILTER)).isEqualTo(FILTER); - assertThat(contentValues.getAsInteger(Columns.DECIMALS)).isEqualTo(DECIMALS); + assertThat(columnsList.contains(Columns.DISPLAY_IN_FORM)).isEqualTo(true); + assertThat(columnsList.contains(Columns.EXPRESSION)).isEqualTo(true); + assertThat(columnsList.contains(Columns.DIMENSION_ITEM)).isEqualTo(true); + assertThat(columnsList.contains(Columns.FILTER)).isEqualTo(true); + assertThat(columnsList.contains(Columns.DECIMALS)).isEqualTo(true); + assertThat(columnsList.contains(Columns.PROGRAM)).isEqualTo(true); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorStoreShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorStoreShould.java deleted file mode 100644 index 016ba83eaa..0000000000 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramIndicatorStoreShould.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (c) 2017, University of Oslo - * - * All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.program; - -import android.content.ContentValues; -import android.database.Cursor; -import android.support.test.runner.AndroidJUnit4; - -import org.hisp.dhis.android.core.common.BaseIdentifiableObject; -import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; -import org.hisp.dhis.android.core.program.ProgramIndicatorModel.Columns; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.IOException; -import java.text.ParseException; -import java.util.Date; - -import static com.google.common.truth.Truth.assertThat; -import static org.hisp.dhis.android.core.AndroidTestUtils.toInteger; -import static org.hisp.dhis.android.core.data.database.CursorAssert.assertThatCursor; - -@RunWith(AndroidJUnit4.class) -public class ProgramIndicatorStoreShould extends AbsStoreTestCase { - private static final String UID = "test_uid"; - private static final String CODE = "test_code"; - private static final String NAME = "test_name"; - private static final String DISPLAY_NAME = "test_display_name"; - private static final Date CREATED = new Date(); - private static final Date LAST_UPDATED = CREATED; - private static final String SHORT_NAME = "test_short_name"; - private static final String DISPLAY_SHORT_NAME = "test_display_short_name"; - private static final String DESCRIPTION = "test_description"; - private static final String DISPLAY_DESCRIPTION = "test_display_description"; - private static final Boolean DISPLAY_IN_FORM = true; - private static final String EXPRESSION = "test_expression"; - private static final String DIMENSION_ITEM = "test_dimension_item"; - private static final String FILTER = "test_filter"; - private static final String PROGRAM = "test_program"; - private static final Integer DECIMALS = 3; - - public static final String[] PROGRAM_INDICATOR_PROJECTION = { - Columns.UID, - Columns.CODE, - Columns.NAME, - Columns.DISPLAY_NAME, - Columns.CREATED, - Columns.LAST_UPDATED, - Columns.SHORT_NAME, - Columns.DISPLAY_SHORT_NAME, - Columns.DESCRIPTION, - Columns.DISPLAY_DESCRIPTION, - Columns.DISPLAY_IN_FORM, - Columns.EXPRESSION, - Columns.DIMENSION_ITEM, - Columns.FILTER, - Columns.DECIMALS, - Columns.PROGRAM - }; - - private ProgramIndicatorStore store; - - @Before - @Override - public void setUp() throws IOException { - super.setUp(); - - store = new ProgramIndicatorStoreImpl(databaseAdapter()); - } - - @Test - public void persist_row_in_data_base_when_insert() throws ParseException { - ContentValues program = CreateProgramUtils.create(1L, PROGRAM, null, null, null); - database().insert(ProgramModel.TABLE, null, program); - - long rowId = store.insert( - UID, - CODE, - NAME, - DISPLAY_NAME, - CREATED, - LAST_UPDATED, - SHORT_NAME, - DISPLAY_SHORT_NAME, - DESCRIPTION, - DISPLAY_DESCRIPTION, - DISPLAY_IN_FORM, - EXPRESSION, - DIMENSION_ITEM, - FILTER, - DECIMALS, - PROGRAM - ); - - Cursor cursor = database().query(ProgramIndicatorModel.TABLE, - PROGRAM_INDICATOR_PROJECTION, null, null, null, null, null); - - assertThat(rowId).isEqualTo(1L); - assertThatCursor(cursor) - .hasRow( - UID, - CODE, - NAME, - DISPLAY_NAME, - BaseIdentifiableObject.DATE_FORMAT.format(CREATED), - BaseIdentifiableObject.DATE_FORMAT.format(LAST_UPDATED), - SHORT_NAME, - DISPLAY_SHORT_NAME, - DESCRIPTION, - DISPLAY_DESCRIPTION, - toInteger(DISPLAY_IN_FORM), - EXPRESSION, - DIMENSION_ITEM, - FILTER, - DECIMALS, - PROGRAM) - .isExhausted(); - } - - // ToDo: consider introducing conflict resolution strategy - - @Test - public void update_program_indicator_in_data_base_when_update() throws Exception { - ContentValues program = CreateProgramUtils.create(1L, PROGRAM, null, null, null); - database().insert(ProgramModel.TABLE, null, program); - - ContentValues programIndicator = new ContentValues(); - programIndicator.put(Columns.UID, UID); - programIndicator.put(Columns.DECIMALS, DECIMALS); - programIndicator.put(Columns.DISPLAY_IN_FORM, DISPLAY_IN_FORM); - programIndicator.put(Columns.PROGRAM, PROGRAM); - database().insert(ProgramIndicatorModel.TABLE, null, programIndicator); - - String[] projection = {Columns.UID, Columns.DECIMALS, Columns.DISPLAY_IN_FORM}; - Cursor cursor = database().query(ProgramIndicatorModel.TABLE, projection, null, null, null, null, null); - - assertThatCursor(cursor).hasRow(UID, DECIMALS, 1); // DISPLAY_IN_FORM == Boolean.TRUE == 1 in database - int updatedDecimals = 5; - boolean updatedDisplayInForm = Boolean.FALSE; // Boolean.FALSE == 0 in database - - // update the program indicator - int update = store.update(UID, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, - SHORT_NAME, DISPLAY_SHORT_NAME, DESCRIPTION, DISPLAY_DESCRIPTION, updatedDisplayInForm, EXPRESSION, - DIMENSION_ITEM, FILTER, updatedDecimals, PROGRAM, UID); - - // check that store returns 1 after successful update - assertThat(update).isEqualTo(1); - - cursor = database().query(ProgramIndicatorModel.TABLE, projection, null, null, null, null, null); - - assertThatCursor(cursor).hasRow(UID, updatedDecimals, 0); // 0 == Boolean.FALSE - } - - @Test - public void delete_program_indicator_in_data_base_when_delete() throws Exception { - ContentValues program = CreateProgramUtils.create(1L, PROGRAM, null, null, null); - database().insert(ProgramModel.TABLE, null, program); - - ContentValues programIndicator = new ContentValues(); - programIndicator.put(Columns.UID, UID); - programIndicator.put(Columns.PROGRAM, PROGRAM); - database().insert(ProgramIndicatorModel.TABLE, null, programIndicator); - - String[] projection = {Columns.UID}; - - Cursor cursor = database().query(ProgramIndicatorModel.TABLE, projection, null, null, null, null, null); - // check that program indicator was successfully inserted into database - assertThatCursor(cursor).hasRow(UID); - - // delete the program indicator - int delete = store.delete(UID); - - // check that store returns 1 when successfully deleting - assertThat(delete).isEqualTo(1); - - cursor = database().query(ProgramIndicatorModel.TABLE, projection, null, null, null, null, null); - - // check that program indicator is deleted in database - assertThatCursor(cursor).isExhausted(); - - } - - @Test - public void delete_program_indicator_when_delete_program() throws Exception { - - ContentValues program = CreateProgramUtils.create(1L, PROGRAM, null, null, null); - database().insert(ProgramModel.TABLE, null, program); - - ContentValues programIndicator = new ContentValues(); - programIndicator.put(Columns.UID, UID); - programIndicator.put(Columns.PROGRAM, PROGRAM); - database().insert(ProgramIndicatorModel.TABLE, null, programIndicator); - - String[] projection = {Columns.UID}; - - Cursor cursor = database().query(ProgramIndicatorModel.TABLE, projection, null, null, null, null, null); - - // check that program indicator was successfully inserted into database - assertThatCursor(cursor).hasRow(UID); - - database().delete(ProgramModel.TABLE, ProgramModel.Columns.UID + " =?", new String[]{PROGRAM}); - - cursor = database().query(ProgramIndicatorModel.TABLE, projection, null, null, null, null, null); - - // check that program indicator was deleted on cascade from program - assertThatCursor(cursor).isExhausted(); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_insert_null_uid() { - store.insert(null, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, SHORT_NAME, DISPLAY_SHORT_NAME, - DESCRIPTION, DISPLAY_DESCRIPTION, DISPLAY_IN_FORM, EXPRESSION, DIMENSION_ITEM, FILTER, DECIMALS, - PROGRAM); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_insert_null_program() { - store.insert(UID, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, SHORT_NAME, DISPLAY_SHORT_NAME, - DESCRIPTION, DISPLAY_DESCRIPTION, DISPLAY_IN_FORM, EXPRESSION, DIMENSION_ITEM, FILTER, DECIMALS, - null); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_uid() { - store.update(null, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, SHORT_NAME, DISPLAY_SHORT_NAME, - DESCRIPTION, DISPLAY_DESCRIPTION, DISPLAY_IN_FORM, EXPRESSION, DIMENSION_ITEM, FILTER, DECIMALS, - PROGRAM, UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_null_program() { - store.update(UID, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, SHORT_NAME, DISPLAY_SHORT_NAME, - DESCRIPTION, DISPLAY_DESCRIPTION, DISPLAY_IN_FORM, EXPRESSION, DIMENSION_ITEM, FILTER, DECIMALS, - null, UID); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_update_with_null_in_where_program_indicator_uid_field() { - store.update(UID, CODE, NAME, DISPLAY_NAME, CREATED, LAST_UPDATED, SHORT_NAME, DISPLAY_SHORT_NAME, - DESCRIPTION, DISPLAY_DESCRIPTION, DISPLAY_IN_FORM, EXPRESSION, DIMENSION_ITEM, FILTER, DECIMALS, - PROGRAM, null); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_when_delete_null_uid() { - store.delete(null); - } -} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelShould.java new file mode 100644 index 0000000000..c2f8766398 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelShould.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import android.database.Cursor; +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.LinkModelAbstractShould; +import org.hisp.dhis.android.core.program.ProgramSectionAttributeLinkModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class ProgramSectionAttributeLinkModelShould extends + LinkModelAbstractShould { + + public ProgramSectionAttributeLinkModelShould() { + super(new Columns().all(), 2); + } + + @Override + protected ProgramSectionAttributeLinkModel buildModel() { + return ProgramSectionAttributeLinkModel.builder() + .programSection("program_section_uid") + .attribute("attribute_uid") + .build(); + } + + @Override + protected ProgramSectionAttributeLinkModel cursorToModel(Cursor cursor) { + return ProgramSectionAttributeLinkModel.create(cursor); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getModelAsObjectArray(model), + model.programSection(), model.attribute()); + } + + @Test + public void have_data_set_organisation_unit_model_columns() { + List columnsList = Arrays.asList(new Columns().all()); + + assertThat(columnsList.contains(Columns.PROGRAM_SECTION)).isEqualTo(true); + assertThat(columnsList.contains(Columns.ATTRIBUTE)).isEqualTo(true); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramSectionModelShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramSectionModelShould.java new file mode 100644 index 0000000000..882418e014 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/program/ProgramSectionModelShould.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import android.database.Cursor; +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.IdentifiableModelAbstractShould; +import org.hisp.dhis.android.core.program.ProgramSectionModel.Columns; +import org.hisp.dhis.android.core.utils.ColumnsArrayUtils; +import org.hisp.dhis.android.core.utils.Utils; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Arrays; +import java.util.List; + +import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.fillIdentifiableModelProperties; + +@RunWith(AndroidJUnit4.class) +public class ProgramSectionModelShould extends IdentifiableModelAbstractShould { + + public ProgramSectionModelShould() { + super(new Columns().all(), 10); + } + + @Override + protected ProgramSectionModel buildModel() { + ProgramSectionModel.Builder programSectionModelBuilder = ProgramSectionModel.builder(); + fillIdentifiableModelProperties(programSectionModelBuilder); + programSectionModelBuilder + .description("description") + .program("program_uid") + .sortOrder(1) + .formName("form_name"); + return programSectionModelBuilder.build(); + } + + @Override + protected ProgramSectionModel cursorToModel(Cursor cursor) { + return ProgramSectionModel.create(cursor); + } + + @Override + protected Object[] getModelAsObjectArray() { + return Utils.appendInNewArray(ColumnsArrayUtils.getIdentifiableModelAsObjectArray(model), + model.description(), + model.program(), + model.sortOrder(), + model.formName()); + } + + @Test + public void have_extra_program_section_model_columns() { + List columnsList = Arrays.asList(columns); + + assertThat(columnsList.contains(Columns.DESCRIPTION)).isEqualTo(true); + assertThat(columnsList.contains(Columns.SORT_ORDER)).isEqualTo(true); + assertThat(columnsList.contains(Columns.PROGRAM)).isEqualTo(true); + assertThat(columnsList.contains(Columns.FORM_NAME)).isEqualTo(true); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerShould.java index bb010e8300..e33b113d85 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManagerShould.java @@ -32,6 +32,7 @@ import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.common.D2Factory; import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; @@ -44,6 +45,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -53,6 +55,7 @@ @RunWith(JUnit4.class) public class TrackedEntityAttributeReservedValueManagerShould extends AbsStoreTestCase { + private TrackedEntityAttributeReservedValueStoreInterface store; private String organisationUnitUid = "org_unit_uid"; private String ownerUid1 = "xs8A6tQJY0s"; private D2 d2; @@ -67,7 +70,12 @@ public void setUp() throws IOException { login(); - manager = TrackedEntityAttributeReservedValueManager.create(databaseAdapter(), d2.retrofit()); + store = TrackedEntityAttributeReservedValueStore.create(databaseAdapter()); + IdentifiableObjectStore organisationUnitStore = + OrganisationUnitStore.create(databaseAdapter()); + + manager = new TrackedEntityAttributeReservedValueManager(databaseAdapter(), d2.retrofit(), + store, organisationUnitStore); GenericHandler handler = TrackedEntityAttributeReservedValueHandler.create(databaseAdapter()); @@ -83,23 +91,23 @@ public void setUp() throws IOException { trackedEntityAttributeReservedValues.add(reservedValue2); trackedEntityAttributeReservedValues.add(reservedValue3); - OrganisationUnitModel organisationUnit = OrganisationUnitModel.builder() + OrganisationUnitModel organisationUnit = OrganisationUnitModel.builder() .uid(organisationUnitUid).code("org_unit_code").build(); - OrganisationUnitStore.create(databaseAdapter()).insert(organisationUnit); + organisationUnitStore.insert(organisationUnit); handler.handleMany(trackedEntityAttributeReservedValues, new TrackedEntityAttributeReservedValueModelBuilder(organisationUnit)); } @Test - public void get_one_reserved_value() throws Exception { + public void get_one_reserved_value() { String value1 = manager.getValue(ownerUid1, organisationUnitUid); assertThat(value1, is("value1")); } @Test - public void get_two_reserved_value() throws Exception { + public void get_two_reserved_value() { String value1 = manager.getValue(ownerUid1, organisationUnitUid); String value2 = manager.getValue(ownerUid1, organisationUnitUid); String value3 = manager.getValue(ownerUid1, organisationUnitUid); @@ -110,31 +118,25 @@ public void get_two_reserved_value() throws Exception { } @Test - public void get_reserved_values() throws Exception { - List reservedValueModels = - manager.getReservedValues(ownerUid1, organisationUnitUid); - - assertThat(reservedValueModels.size(), is(3)); + public void get_reserved_values() { + assertThat(selectAll().size(), is(3)); } @Test - public void reserve_100_new_values_and_take_one() throws Exception { + public void reserve_100_new_values_and_take_one() { manager.getValue(ownerUid1, organisationUnitUid); - List reservedValueModels = - manager.getReservedValues(ownerUid1, organisationUnitUid); - - assertThat(reservedValueModels.size(), is(99)); + assertThat(selectAll().size(), is(99)); } @Test - public void have_98_values_after_sync_and_take_two() throws Exception { + public void have_98_values_after_sync_and_take_two() { manager.getValue(ownerUid1, organisationUnitUid); manager.getValue(ownerUid1, organisationUnitUid); + assertThat(selectAll().size(), is(98)); + } - List reservedValueModels = - manager.getReservedValues(ownerUid1, organisationUnitUid); - - assertThat(reservedValueModels.size(), is(98)); + private Set selectAll() { + return store.selectAll(TrackedEntityAttributeReservedValueModel.factory); } private void login() { diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStoreIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStoreIntegrationShould.java new file mode 100644 index 0000000000..280f2e3192 --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStoreIntegrationShould.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.trackedentity; + +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.IOException; +import java.util.Date; +import java.util.Set; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.parseDate; + +@RunWith(JUnit4.class) +public class TrackedEntityAttributeReservedValueStoreIntegrationShould extends AbsStoreTestCase { + + private TrackedEntityAttributeReservedValueModel expiredValue; + private TrackedEntityAttributeReservedValueModel notExpiredValue; + + private Date serverDate; + private final String orgUnitUid = "orgu1"; + private final String ownerUid = "owUid"; + + // object to test + private TrackedEntityAttributeReservedValueStoreInterface store; + private IdentifiableObjectStore organisationUnitStore; + + @Before + public void setUp() throws IOException { + super.setUp(); + store = TrackedEntityAttributeReservedValueStore.create(databaseAdapter()); + + serverDate = parseDate("2018-05-13T12:35:36.743"); + Date expiredDate = parseDate("2018-05-12T12:35:36.743"); + Date notExpiredDate = parseDate("2018-05-17T12:35:36.743"); + + OrganisationUnitModel organisationUnit = OrganisationUnitModel.builder().uid(orgUnitUid).build(); + organisationUnitStore = OrganisationUnitStore.create(databaseAdapter()); + organisationUnitStore.insert(organisationUnit); + + TrackedEntityAttributeReservedValueModel.Builder builder = TrackedEntityAttributeReservedValueModel.builder() + .ownerObject("owObj") + .ownerUid(ownerUid) + .key("key") + .organisationUnit(orgUnitUid) + .created(new Date()); + + expiredValue = builder.expiryDate(expiredDate).value("v1").build(); + notExpiredValue = builder.expiryDate(notExpiredDate).value("v2").build(); + } + + @After + public void tearDown() throws IOException { + store.delete(); + organisationUnitStore.delete(); + super.tearDown(); + } + + @Test + public void delete_expired_reserved_values() { + store.insert(expiredValue); + store.deleteExpired(serverDate); + storeContains(expiredValue, false); + } + + @Test + public void not_delete_not_expired_reserved_values() { + store.insert(notExpiredValue); + store.deleteExpired(serverDate); + storeContains(notExpiredValue, true); + } + + @Test + public void pop_inserted_value() { + store.insert(notExpiredValue); + TrackedEntityAttributeReservedValueModel returnedValue = store.popOne(ownerUid, orgUnitUid); + assertThat(returnedValue.value(), is(notExpiredValue.value())); + } + + @Test + public void leave_store_empty_after_pop_only_value() { + store.insert(notExpiredValue); + TrackedEntityAttributeReservedValueModel value = store.popOne(ownerUid, orgUnitUid); + storeContains(value, false); + } + + private void storeContains(TrackedEntityAttributeReservedValueModel value, Boolean contains) { + Set values + = store.selectAll(TrackedEntityAttributeReservedValueModel.factory); + assertThat(values.contains(value), is(contains)); + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java index 87ee422206..75075b28e5 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallMockIntegrationShould.java @@ -4,8 +4,10 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.calls.Call; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.common.D2Factory; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; @@ -57,13 +59,13 @@ public void download_tracked_entity_instance_enrollments_and_events() throws Exc givenAMetadataInDatabase(); - TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = - TrackedEntityInstanceEndPointCall.create( - d2.databaseAdapter(), d2.retrofit(), teiUid); + Call> trackedEntityInstanceByUidEndPointCall = + TrackedEntityInstanceListDownloadAndPersistCall.create( + d2.databaseAdapter(), d2.retrofit(), Lists.newArrayList(teiUid)); dhis2MockServer.enqueueMockResponse("tracked_entity_instance.json"); - trackedEntityInstanceEndPointCall.call(); + trackedEntityInstanceByUidEndPointCall.call(); verifyDownloadedTrackedEntityInstance("tracked_entity_instance.json", teiUid); } @@ -75,22 +77,22 @@ public void remove_data_removed_in_server_after_second_download() givenAMetadataInDatabase(); - TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = - TrackedEntityInstanceEndPointCall.create( - d2.databaseAdapter(), d2.retrofit(), teiUid); + Call> trackedEntityInstanceByUidEndPointCall = + TrackedEntityInstanceListDownloadAndPersistCall.create( + d2.databaseAdapter(), d2.retrofit(), Lists.newArrayList(teiUid)); dhis2MockServer.enqueueMockResponse("tracked_entity_instance.json"); - trackedEntityInstanceEndPointCall.call(); + trackedEntityInstanceByUidEndPointCall.call(); - trackedEntityInstanceEndPointCall = - TrackedEntityInstanceEndPointCall.create( - databaseAdapter(), d2.retrofit(), teiUid); + trackedEntityInstanceByUidEndPointCall = + TrackedEntityInstanceListDownloadAndPersistCall.create( + databaseAdapter(), d2.retrofit(), Lists.newArrayList(teiUid)); dhis2MockServer.enqueueMockResponse("tracked_entity_instance_with_removed_data.json"); - trackedEntityInstanceEndPointCall.call(); + trackedEntityInstanceByUidEndPointCall.call(); verifyDownloadedTrackedEntityInstance("tracked_entity_instance_with_removed_data.json", teiUid); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java index 38c4634a84..0eebf58e08 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceCallRealIntegrationShould.java @@ -1,14 +1,17 @@ package org.hisp.dhis.android.core.trackedentity; +import com.google.common.collect.Lists; import com.google.common.truth.Truth; import org.hisp.dhis.android.core.D2; +import org.hisp.dhis.android.core.calls.Call; import org.hisp.dhis.android.core.common.D2Factory; import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; import org.hisp.dhis.android.core.data.server.RealServerMother; import org.junit.Before; import java.io.IOException; +import java.util.List; public class TrackedEntityInstanceCallRealIntegrationShould extends AbsStoreTestCase { @@ -36,12 +39,11 @@ public void download_tei_enrollments_and_events() throws Exception { response = d2.syncMetaData().call(); Truth.assertThat(response.isSuccessful()).isTrue(); - TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = - TrackedEntityInstanceEndPointCall.create( - d2.databaseAdapter(), d2.retrofit(), "IaxoagO9899"); + Call> trackedEntityInstanceByUidEndPointCall = + d2.downloadTrackedEntityInstancesByUid(Lists.newArrayList("IaxoagO9899")); - response = trackedEntityInstanceEndPointCall.call(); + List teiResponse = trackedEntityInstanceByUidEndPointCall.call(); - Truth.assertThat(response.isSuccessful()).isTrue(); + Truth.assertThat(teiResponse.isEmpty()).isFalse(); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstancePostCallRealIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstancePostCallRealIntegrationShould.java index 00aa63c87a..3be6ea681c 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstancePostCallRealIntegrationShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstancePostCallRealIntegrationShould.java @@ -2,6 +2,8 @@ import android.support.test.runner.AndroidJUnit4; +import com.google.common.collect.Lists; + import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.calls.Call; import org.hisp.dhis.android.core.common.D2Factory; @@ -168,11 +170,11 @@ public void pull_event_after_push_tracked_entity_instance_with_that_event() thro downloadMetadata(); - TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = - TrackedEntityInstanceEndPointCall.create( - d2.databaseAdapter(), d2.retrofit(), trackedEntityInstanceUid); + Call> trackedEntityInstanceByUidEndPointCall = + TrackedEntityInstanceListDownloadAndPersistCall.create( + d2.databaseAdapter(), d2.retrofit(), Lists.newArrayList(trackedEntityInstanceUid)); - trackedEntityInstanceEndPointCall.call(); + trackedEntityInstanceByUidEndPointCall.call(); TrackedEntityInstance downloadedTrackedEntityInstance = getTrackedEntityInstanceFromDB(trackedEntityInstanceUid); Enrollment downloadedEnrollment = getEnrollmentsByTrackedEntityInstanceFromDb(trackedEntityInstanceUid); @@ -186,7 +188,7 @@ public void pull_event_after_push_tracked_entity_instance_with_that_event() thro //@Test public void post_a_tei() throws Exception { downloadMetadata(); - d2.downloadTrackedEntityInstances(4).call(); + d2.downloadTrackedEntityInstances(4, true).call(); TrackedEntityInstance tei = trackedEntityInstanceStore.queryAll().values().iterator().next(); @@ -202,9 +204,9 @@ public void post_a_tei() throws Exception { d2.wipeDB().call(); downloadMetadata(); - Response response = d2.downloadTrackedEntityInstance(newUid).call(); + List response = d2.downloadTrackedEntityInstancesByUid(Lists.newArrayList(newUid)).call(); - TrackedEntityInstance updatedTei = response.body(); + TrackedEntityInstance updatedTei = response.get(0); assertThat(updatedTei.featureType()).isEqualTo(featureType); } @@ -212,7 +214,7 @@ public void post_a_tei() throws Exception { //@Test public void post_more_than_one_tei() throws Exception { downloadMetadata(); - d2.downloadTrackedEntityInstances(4).call(); + d2.downloadTrackedEntityInstances(4, true).call(); TrackedEntityInstance tei = trackedEntityInstanceStore.queryAll().values().iterator().next(); @@ -227,15 +229,15 @@ public void post_more_than_one_tei() throws Exception { d2.wipeDB().call(); downloadMetadata(); - Response response = d2.downloadTrackedEntityInstance(newUid1).call(); + List teiList = d2.downloadTrackedEntityInstancesByUid(Lists.newArrayList(newUid1)).call(); - assertThat(response.isSuccessful()).isTrue(); + assertThat(teiList.size() == 1).isTrue(); } //@Test public void post_new_relationship_to_client_created_tei() throws Exception { downloadMetadata(); - d2.downloadTrackedEntityInstances(5).call(); + d2.downloadTrackedEntityInstances(5, true).call(); TrackedEntityInstance teiA = trackedEntityInstanceStore.queryAll().values().iterator().next(); String relationshipTypeUid = relationshipTypeStore.selectAll(RelationshipTypeModel.factory) @@ -260,11 +262,11 @@ public void post_new_relationship_to_client_created_tei() throws Exception { d2.wipeDB().call(); downloadMetadata(); - Response responseTeiA = d2.downloadTrackedEntityInstance(teiA.uid()).call(); - assertThat(responseTeiA.isSuccessful()).isTrue(); + List responseTeiA = d2.downloadTrackedEntityInstancesByUid(Lists.newArrayList(teiA.uid())).call(); + assertThat(responseTeiA.size() == 1).isTrue(); - Response responseTeiB = d2.downloadTrackedEntityInstance(teiBUid).call(); - assertThat(responseTeiB.isSuccessful()).isTrue(); + List responseTeiB = d2.downloadTrackedEntityInstancesByUid(Lists.newArrayList(teiBUid)).call(); + assertThat(responseTeiB.size() == 1).isTrue(); Set relationships = relationShipStore.selectAll(RelationshipModel.factory); assertThat(relationships).contains(relationshipModel); diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelsShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelsShould.java index f559acbd62..690bd89ab9 100644 --- a/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelsShould.java +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelsShould.java @@ -37,6 +37,7 @@ import org.junit.runner.RunWith; import static com.google.common.truth.Truth.assertThat; +import static org.hisp.dhis.android.core.AndroidTestUtils.toBoolean; @RunWith(AndroidJUnit4.class) public class UserOrganisationUnitLinkModelsShould { @@ -44,13 +45,14 @@ public class UserOrganisationUnitLinkModelsShould { private static final String USER = "test_user_uid"; private static final String ORGANISATION_UNIT = "test_organisation_unit_uid"; private static final String ORGANISATION_UNIT_SCOPE = "test_organisation_unit_scope"; + private static final Integer ROOT = 1; @Test public void create_model_when_created_from_database_cursor() { MatrixCursor cursor = new MatrixCursor(new String[]{ - Columns.ID, Columns.USER, Columns.ORGANISATION_UNIT, Columns.ORGANISATION_UNIT_SCOPE + Columns.ID, Columns.USER, Columns.ORGANISATION_UNIT, Columns.ORGANISATION_UNIT_SCOPE, Columns.ROOT }); - cursor.addRow(new Object[]{ID, USER, ORGANISATION_UNIT, ORGANISATION_UNIT_SCOPE}); + cursor.addRow(new Object[]{ID, USER, ORGANISATION_UNIT, ORGANISATION_UNIT_SCOPE, ROOT}); cursor.moveToFirst(); UserOrganisationUnitLinkModel model = UserOrganisationUnitLinkModel.create(cursor); @@ -59,6 +61,7 @@ public void create_model_when_created_from_database_cursor() { assertThat(model.id()).isEqualTo(ID); assertThat(model.user()).isEqualTo(USER); assertThat(model.organisationUnit()).isEqualTo(ORGANISATION_UNIT); + assertThat(model.root()).isEqualTo(toBoolean(ROOT)); } @Test @@ -68,6 +71,7 @@ public void create_content_values_when_created_from_builder() { .user(USER) .organisationUnit(ORGANISATION_UNIT) .organisationUnitScope(ORGANISATION_UNIT_SCOPE) + .root(toBoolean(ROOT)) .build(); ContentValues contentValues = model.toContentValues(); @@ -75,5 +79,6 @@ public void create_content_values_when_created_from_builder() { assertThat(contentValues.getAsString(Columns.USER)).isEqualTo(USER); assertThat(contentValues.getAsString(Columns.ORGANISATION_UNIT)).isEqualTo(ORGANISATION_UNIT); assertThat(contentValues.getAsString(Columns.ORGANISATION_UNIT_SCOPE)).isEqualTo(ORGANISATION_UNIT_SCOPE); + assertThat(contentValues.getAsBoolean(Columns.ROOT)).isEqualTo(toBoolean(ROOT)); } } diff --git a/core/src/androidTest/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngineIntegrationShould.java b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngineIntegrationShould.java new file mode 100644 index 0000000000..4086eec2bf --- /dev/null +++ b/core/src/androidTest/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngineIntegrationShould.java @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.utils.services; + +import android.support.test.runner.AndroidJUnit4; + +import org.hisp.dhis.android.core.common.FormType; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ValueType; +import org.hisp.dhis.android.core.data.database.AbsStoreTestCase; +import org.hisp.dhis.android.core.dataelement.DataElementModel; +import org.hisp.dhis.android.core.dataelement.DataElementStore; +import org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl; +import org.hisp.dhis.android.core.event.EventStoreImpl; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; +import org.hisp.dhis.android.core.program.ProgramIndicatorModel; +import org.hisp.dhis.android.core.program.ProgramIndicatorStore; +import org.hisp.dhis.android.core.program.ProgramModel; +import org.hisp.dhis.android.core.program.ProgramStageModel; +import org.hisp.dhis.android.core.program.ProgramStageStore; +import org.hisp.dhis.android.core.program.ProgramStore; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeStoreImpl; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueStoreImpl; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceStore; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceStoreImpl; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeStoreImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import static com.google.common.truth.Truth.assertThat; + +@RunWith(AndroidJUnit4.class) +public class ProgramIndicatorEngineIntegrationShould extends AbsStoreTestCase { + + private String teiUid = "H87GEVeG3JH"; + private String enrollmentUid = "la16vwCoFM8"; + private String event1 = "gphKB0UjOrX"; + private String event2 = "EAZOUgr2Ksv"; + + private String dataElement1 = "ddaBs9lgZyP"; + private String dataElement2 = "Kb9hZ428FyH"; + private String attribute1 = "Kmtdopp5GC1"; + private String programIndicatorUid = "rg3JkCv0skl"; + + // Auxiliary variables + private String orgunitUid = "orgunit_uid"; + private String teiTypeUid = "tei_type_uid"; + private String programUid = "program_uid"; + private String programStage1 = "iM4svLr2hlO"; + private String programStage2 = "RXFTSe1oefv"; + + private ProgramIndicatorEngine programIndicatorEngine; + + @Override + @Before + public void setUp() throws IOException { + super.setUp(); + + programIndicatorEngine = ProgramIndicatorEngine.create(databaseAdapter()); + + OrganisationUnitModel orgunit = OrganisationUnitModel.builder().uid(orgunitUid).build(); + OrganisationUnitStore.create(databaseAdapter()).insert(orgunit); + + new TrackedEntityTypeStoreImpl(databaseAdapter()).insert(teiTypeUid, null, null, null, null, null, + null, null,null, null); + + TrackedEntityInstanceStore teiStore = new TrackedEntityInstanceStoreImpl(databaseAdapter()); + teiStore.insert(teiUid, new Date(), new Date(), null, null, orgunitUid, teiTypeUid, null, null, + null); + + ProgramModel program = ProgramModel.builder().uid(programUid).build(); + ProgramStore.create(databaseAdapter()).insert(program); + + ProgramStageModel stage1 = ProgramStageModel.builder().uid(programStage1).program(programUid) + .formType(FormType.CUSTOM).build(); + ProgramStageModel stage2 = ProgramStageModel.builder().uid(programStage2).program(programUid) + .formType(FormType.CUSTOM).build(); + + IdentifiableObjectStore programStageStore = ProgramStageStore.create(databaseAdapter()); + programStageStore.insert(stage1); + programStageStore.insert(stage2); + + DataElementModel de1 = DataElementModel.builder().uid(dataElement1).valueType(ValueType.NUMBER).build(); + DataElementModel de2 = DataElementModel.builder().uid(dataElement2).valueType(ValueType.NUMBER).build(); + IdentifiableObjectStore dataElementStore = DataElementStore.create(databaseAdapter()); + dataElementStore.insert(de1); + dataElementStore.insert(de2); + + new TrackedEntityAttributeStoreImpl(databaseAdapter()).insert(attribute1,null,null,null,null,null,null, + null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null); + + } + + @Test + public void evaluate_single_dataelement() { + createEnrollment(null,null); + createEvent(event1, programStage1, new Date()); + insertTrackedEntityDataValue(event1, dataElement1, "4"); + + setProgramIndicatorExpression(de(programStage1,dataElement1)); + + String result = programIndicatorEngine.getProgramIndicatorValue(enrollmentUid, event1, programIndicatorUid); + + assertThat(result).isEqualTo("4"); + } + + @Test + public void evaluate_addition_two_dataelement() { + createEnrollment(null, null); + createEvent(event1, programStage1, null); + insertTrackedEntityDataValue(event1, dataElement1, "5"); + insertTrackedEntityDataValue(event1, dataElement2, "3"); + + setProgramIndicatorExpression(de(programStage1,dataElement1) + " * " + de(programStage1,dataElement2)); + + String result = programIndicatorEngine.getProgramIndicatorValue(enrollmentUid, event1, programIndicatorUid); + + assertThat(result).isEqualTo("15"); + } + + @Test + public void evaluate_operation_several_stages() { + createEnrollment(null, null); + createEvent(event1, programStage1, null); + createEvent(event2, programStage2, null); + + insertTrackedEntityDataValue(event1, dataElement1, "5"); + insertTrackedEntityDataValue(event2, dataElement2, "1.5"); + insertTrackedEntityAttributeValue(attribute1, "2"); + + setProgramIndicatorExpression("(" + de(programStage1,dataElement1) + " + " + de(programStage2,dataElement2) + + ") / " + att(attribute1)); + + String resultWithoutEvent = programIndicatorEngine.getProgramIndicatorValue(enrollmentUid, null, + programIndicatorUid); + String resultWithEvent = programIndicatorEngine.getProgramIndicatorValue(enrollmentUid, event1, + programIndicatorUid); + + assertThat(resultWithoutEvent).isEqualTo("3.25"); + assertThat(resultWithEvent).isEqualTo("3.25"); + } + + @Test + public void evaluate_expression_with_d2_functions() { + createEnrollment(null, null); + createEvent(event1, programStage1, null); + insertTrackedEntityDataValue(event1, dataElement1, "4.8"); + insertTrackedEntityDataValue(event1, dataElement2, "3"); + + setProgramIndicatorExpression("d2:round(" + de(programStage1,dataElement1) + ") * " + + de(programStage1, dataElement2)); + + String result = programIndicatorEngine.getProgramIndicatorValue(enrollmentUid, event1, programIndicatorUid); + + assertThat(result).isEqualTo("15"); + } + + @Test + public void evaluate_d2_functions_with_dates() throws ParseException { + Date enrollmentDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2018-05-05T00:00:00.000"); + Date eventDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2018-05-21T00:00:00.000"); + + createEnrollment(enrollmentDate, null); + createEvent(event1, programStage1, eventDate); + + setProgramIndicatorExpression("d2:daysBetween(V{enrollment_date}, V{event_date})"); + + String result = programIndicatorEngine.getProgramIndicatorValue(enrollmentUid, event1, programIndicatorUid); + + assertThat(result).isEqualTo("16"); + } + + private void createEnrollment(Date enrollmentDate, Date incidentDate) { + new EnrollmentStoreImpl(databaseAdapter()).insert(enrollmentUid,null,null,null,null,orgunitUid, + programUid,enrollmentDate,incidentDate,null,null,teiUid,null,null,null); + } + + private void createEvent(String eventUid, String programStageUid, Date eventDate) { + new EventStoreImpl(databaseAdapter()).insert(eventUid,enrollmentUid,null,null,null,null,null,null,null, + programUid,programStageUid,orgunitUid,eventDate,null,null,null,null,null,null); + } + + private void setProgramIndicatorExpression(String expression) { + ProgramIndicatorModel programIndicator = ProgramIndicatorModel.builder().uid(programIndicatorUid) + .program(programUid).expression(expression).build(); + ProgramIndicatorStore.create(databaseAdapter()).insert(programIndicator); + } + + private void insertTrackedEntityDataValue(String eventUid, String dataElementUid, String value) { + new TrackedEntityDataValueStoreImpl(databaseAdapter()).insert(eventUid,null,null,dataElementUid,null, + value,null); + } + + private void insertTrackedEntityAttributeValue(String attributeUid, String value) { + new TrackedEntityAttributeValueStoreImpl(databaseAdapter()).insert(value,null,null,attributeUid,teiUid); + } + + private String de(String programStageUid, String dataElementUid) { + return "#{" + programStageUid + "." + dataElementUid + "}"; + } + + private String att(String attributeUid) { + return "A{" + attributeUid + "}"; + } +} diff --git a/core/src/androidTest/resources/db_version_1.sql b/core/src/androidTest/resources/db_version_1.sql deleted file mode 100644 index 5ceff059fc..0000000000 --- a/core/src/androidTest/resources/db_version_1.sql +++ /dev/null @@ -1,34 +0,0 @@ -CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_10.sql b/core/src/androidTest/resources/db_version_10.sql deleted file mode 100644 index 1d53cda3f3..0000000000 --- a/core/src/androidTest/resources/db_version_10.sql +++ /dev/null @@ -1,51 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_11.sql b/core/src/androidTest/resources/db_version_11.sql deleted file mode 100644 index 5696a77dd0..0000000000 --- a/core/src/androidTest/resources/db_version_11.sql +++ /dev/null @@ -1,51 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_12.sql b/core/src/androidTest/resources/db_version_12.sql deleted file mode 100644 index 29c378f968..0000000000 --- a/core/src/androidTest/resources/db_version_12.sql +++ /dev/null @@ -1,51 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_13.sql b/core/src/androidTest/resources/db_version_13.sql deleted file mode 100644 index b741f33778..0000000000 --- a/core/src/androidTest/resources/db_version_13.sql +++ /dev/null @@ -1,51 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_14.sql b/core/src/androidTest/resources/db_version_14.sql deleted file mode 100644 index d628c82694..0000000000 --- a/core/src/androidTest/resources/db_version_14.sql +++ /dev/null @@ -1,51 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_15.sql b/core/src/androidTest/resources/db_version_15.sql deleted file mode 100644 index 08e9f47668..0000000000 --- a/core/src/androidTest/resources/db_version_15.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_16.sql b/core/src/androidTest/resources/db_version_16.sql deleted file mode 100644 index 2253ee541e..0000000000 --- a/core/src/androidTest/resources/db_version_16.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_17.sql b/core/src/androidTest/resources/db_version_17.sql deleted file mode 100644 index b23b79b09a..0000000000 --- a/core/src/androidTest/resources/db_version_17.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_18.sql b/core/src/androidTest/resources/db_version_18.sql deleted file mode 100644 index 41f9b1f3aa..0000000000 --- a/core/src/androidTest/resources/db_version_18.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, expiryDays INTEGER, completeEventsExpiryDays INTEGER, expiryPeriodType TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_19.sql b/core/src/androidTest/resources/db_version_19.sql deleted file mode 100644 index eb4a956198..0000000000 --- a/core/src/androidTest/resources/db_version_19.sql +++ /dev/null @@ -1,54 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, expiryDays INTEGER, completeEventsExpiryDays INTEGER, expiryPeriodType TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, remindCompleted INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_2.sql b/core/src/androidTest/resources/db_version_2.sql deleted file mode 100644 index fa6b2af021..0000000000 --- a/core/src/androidTest/resources/db_version_2.sql +++ /dev/null @@ -1,41 +0,0 @@ -CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_20.sql b/core/src/androidTest/resources/db_version_20.sql deleted file mode 100644 index 7368e0fe4b..0000000000 --- a/core/src/androidTest/resources/db_version_20.sql +++ /dev/null @@ -1,55 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, expiryDays INTEGER, completeEventsExpiryDays INTEGER, expiryPeriodType TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, remindCompleted INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); -CREATE TABLE SystemSetting (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT,value TEXT, UNIQUE (key)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_21.sql b/core/src/androidTest/resources/db_version_21.sql deleted file mode 100644 index 318af21212..0000000000 --- a/core/src/androidTest/resources/db_version_21.sql +++ /dev/null @@ -1,56 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, expiryDays INTEGER, completeEventsExpiryDays INTEGER, expiryPeriodType TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, remindCompleted INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); -CREATE TABLE SystemSetting (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT,value TEXT, UNIQUE (key)); -CREATE TABLE TrackedEntityAttributeReservedValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, ownerObject TEXT,ownerUid TEXT,key TEXT,value TEXT,created TEXT,expiryDate TEXT,organisationUnit TEXT); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_22.sql b/core/src/androidTest/resources/db_version_22.sql deleted file mode 100644 index 17c4d2c0bc..0000000000 --- a/core/src/androidTest/resources/db_version_22.sql +++ /dev/null @@ -1,56 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, expiryDays INTEGER, completeEventsExpiryDays INTEGER, expiryPeriodType TEXT, minAttributesRequiredToSearch INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, remindCompleted INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); -CREATE TABLE SystemSetting (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT,value TEXT, UNIQUE (key)); -CREATE TABLE TrackedEntityAttributeReservedValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, ownerObject TEXT,ownerUid TEXT,key TEXT,value TEXT,created TEXT,expiryDate TEXT,organisationUnit TEXT); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_23.sql b/core/src/androidTest/resources/db_version_23.sql deleted file mode 100644 index cf9362ff27..0000000000 --- a/core/src/androidTest/resources/db_version_23.sql +++ /dev/null @@ -1,56 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL,searchable INTEGER, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, expiryDays INTEGER, completeEventsExpiryDays INTEGER, expiryPeriodType TEXT, minAttributesRequiredToSearch INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, remindCompleted INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); -CREATE TABLE SystemSetting (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT,value TEXT, UNIQUE (key)); -CREATE TABLE TrackedEntityAttributeReservedValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, ownerObject TEXT,ownerUid TEXT,key TEXT,value TEXT,created TEXT,expiryDate TEXT,organisationUnit TEXT); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_24.sql b/core/src/androidTest/resources/db_version_24.sql deleted file mode 100644 index 2c9a721dd4..0000000000 --- a/core/src/androidTest/resources/db_version_24.sql +++ /dev/null @@ -1,56 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT, lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL,searchable INTEGER, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT, accessDataWrite INTEGER, expiryDays INTEGER, completeEventsExpiryDays INTEGER, expiryPeriodType TEXT, minAttributesRequiredToSearch INTEGER, maxTeiCountToReturn INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); -CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER, remindCompleted INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); -CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); -CREATE TABLE SystemSetting (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT,value TEXT, UNIQUE (key)); -CREATE TABLE TrackedEntityAttributeReservedValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, ownerObject TEXT,ownerUid TEXT,key TEXT,value TEXT,created TEXT,expiryDate TEXT,organisationUnit TEXT); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_2_with_data.sql b/core/src/androidTest/resources/db_version_2_with_data.sql deleted file mode 100644 index 52bba96eab..0000000000 --- a/core/src/androidTest/resources/db_version_2_with_data.sql +++ /dev/null @@ -1,1379 +0,0 @@ -BEGIN TRANSACTION; -CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); -INSERT INTO `UserRoleProgramLink` VALUES (1,'Ufph3mGRmMo','uy2gU8kT1jF'); -INSERT INTO `UserRoleProgramLink` VALUES (2,'Ufph3mGRmMo','q04UBOqq3rp'); -INSERT INTO `UserRoleProgramLink` VALUES (3,'Ufph3mGRmMo','VBqh0ynB2wv'); -INSERT INTO `UserRoleProgramLink` VALUES (4,'Ufph3mGRmMo','eBAyeGv0exc'); -INSERT INTO `UserRoleProgramLink` VALUES (5,'Ufph3mGRmMo','kla3mAPgvCH'); -INSERT INTO `UserRoleProgramLink` VALUES (6,'Ufph3mGRmMo','lxAQ7Zs9VYR'); -INSERT INTO `UserRoleProgramLink` VALUES (7,'Ufph3mGRmMo','IpHINAT79UW'); -INSERT INTO `UserRoleProgramLink` VALUES (8,'Ufph3mGRmMo','ur1Edk5Oe2n'); -INSERT INTO `UserRoleProgramLink` VALUES (9,'Ufph3mGRmMo','WSGAb5XwJ3Y'); -INSERT INTO `UserRoleProgramLink` VALUES (10,'Ufph3mGRmMo','fDd25txQckK'); -INSERT INTO `UserRoleProgramLink` VALUES (11,'cUlTcejWree','ur1Edk5Oe2n'); -INSERT INTO `UserRoleProgramLink` VALUES (12,'DRdaVRtwmG5','eBAyeGv0exc'); -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -INSERT INTO `UserRole` VALUES (1,'Ufph3mGRmMo',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `UserRole` VALUES (2,'Euq3XfEIEbx',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `UserRole` VALUES (3,'cUlTcejWree',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `UserRole` VALUES (4,'DRdaVRtwmG5',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `UserRole` VALUES (5,'jRWSNIHdKww',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `UserRole` VALUES (6,'txB7vu1w2Pr',NULL,NULL,NULL,NULL,NULL); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -INSERT INTO `UserOrganisationUnit` VALUES (1,'DXyJmlo9rge','DiszpKrYNg8','SCOPE_DATA_CAPTURE'); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -INSERT INTO `UserCredentials` VALUES (1,'M0fCOxtkURr','android','John Barnes','John Barnes','2015-03-31T13:31:09.206','2017-11-29T11:45:37.250','android','DXyJmlo9rge'); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -INSERT INTO `User` VALUES (1,'DXyJmlo9rge',NULL,'John Barnes','John Barnes','2015-03-31T13:31:09.324','2016-04-06T00:05:57.495',NULL,NULL,NULL,NULL,'Barnes','John',NULL,NULL,NULL,NULL,'john@hmail.com',NULL,NULL); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `TrackedEntityDataValue` VALUES (1,'V1CerIi3sdL','ebaJjqltK5N',NULL,'1','2015-02-28T12:05:00.000','2015-02-28T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (2,'V1CerIi3sdL','bx6fsa0t90x',NULL,'false','2015-02-28T12:05:00.000','2015-02-28T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (3,'V1CerIi3sdL','wQLfBvPrXqq',NULL,'NVP only','2015-02-28T12:05:00.000','2015-02-28T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (4,'V1CerIi3sdL','a3kGcGDCuk6',NULL,'11','2015-02-28T12:05:00.000','2015-02-28T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (5,'V1CerIi3sdL','UXz7xuGCEhU',NULL,'3843','2015-02-28T12:05:00.000','2015-02-28T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (6,'V1CerIi3sdL','X8zyunlgUfM',NULL,'Replacement','2015-02-28T12:05:00.000','2015-02-28T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (7,'fxprDvpLa7Y','wpKRnvM14KO','admin','TB+ not on treatment','2016-04-20T17:23:43.559','2016-04-20T17:23:43.559',0); -INSERT INTO `TrackedEntityDataValue` VALUES (8,'fxprDvpLa7Y','lNNb3truQoi','admin','IPT 3','2016-04-20T17:23:42.481','2016-04-20T17:23:42.481',0); -INSERT INTO `TrackedEntityDataValue` VALUES (9,'fxprDvpLa7Y','gAbD3uDVHHh','admin','2nd','2016-04-20T17:23:41.250','2016-04-20T17:23:41.250',0); -INSERT INTO `TrackedEntityDataValue` VALUES (10,'fxprDvpLa7Y','g9eOBujte1U','admin','4','2016-04-20T17:23:24.090','2016-04-20T17:23:24.090',0); -INSERT INTO `TrackedEntityDataValue` VALUES (11,'fxprDvpLa7Y','UXz7xuGCEhU','admin','67132','2016-04-20T17:23:37.648','2016-04-20T17:23:37.648',0); -INSERT INTO `TrackedEntityDataValue` VALUES (12,'fxprDvpLa7Y','KVQpGEjHluk','admin','23','2016-04-20T17:23:39.817','2016-04-20T17:23:39.818',0); -INSERT INTO `TrackedEntityDataValue` VALUES (13,'fxprDvpLa7Y','xjTklbpY6oG','admin','34','2016-04-20T17:23:40.422','2016-04-20T17:23:40.422',0); -INSERT INTO `TrackedEntityDataValue` VALUES (14,'fxprDvpLa7Y','NALlPhMmMTQ','admin','AZT/3TC/NVP - 1','2016-04-20T17:23:46.243','2016-04-20T17:23:46.243',0); -INSERT INTO `TrackedEntityDataValue` VALUES (15,'fxprDvpLa7Y','EzMxXuVww2z','admin','Fe','2016-04-20T17:23:45.021','2016-04-20T17:23:45.021',0); -INSERT INTO `TrackedEntityDataValue` VALUES (16,'kNpCKARLVHd','ihOp58eRcG3','admin','Yes','2016-04-20T17:23:19.792','2016-04-20T17:23:19.792',0); -INSERT INTO `TrackedEntityDataValue` VALUES (17,'kNpCKARLVHd','jkKCVlLRsFD','admin','TRR','2016-04-20T17:23:14.578','2016-04-20T17:23:14.578',0); -INSERT INTO `TrackedEntityDataValue` VALUES (18,'kNpCKARLVHd','DWcWXE0xO2b','admin','SS-Suspicious malignancy','2016-04-20T17:23:12.936','2016-04-20T17:23:12.936',0); -INSERT INTO `TrackedEntityDataValue` VALUES (19,'kNpCKARLVHd','DBFcMGod0Wy','admin','2 - Oral: Microgynon','2016-04-20T17:23:09.280','2016-04-20T17:23:09.280',0); -INSERT INTO `TrackedEntityDataValue` VALUES (20,'kNpCKARLVHd','thO0LN2i2OJ','admin','SS-Suspicious abnormalies','2016-04-20T17:23:11.109','2016-04-20T17:23:11.109',0); -INSERT INTO `TrackedEntityDataValue` VALUES (21,'kNpCKARLVHd','SMo8UtuSF5p','admin','TRRK','2016-04-20T17:23:16.161','2016-04-20T17:23:16.161',0); -INSERT INTO `TrackedEntityDataValue` VALUES (22,'kNpCKARLVHd','L9G6ZtxbfjG','admin','Alive','2016-04-20T17:23:21.292','2016-04-20T17:23:21.292',0); -INSERT INTO `TrackedEntityDataValue` VALUES (23,'kNpCKARLVHd','EzMxXuVww2z','admin','Folic','2016-04-20T17:23:17.781','2016-04-20T17:23:17.781',0); -INSERT INTO `TrackedEntityDataValue` VALUES (24,'FyJ0jgAARNX','H6uSAMO5WLD','admin','At risk','2016-04-20T16:23:54.973','2016-04-20T16:23:54.974',0); -INSERT INTO `TrackedEntityDataValue` VALUES (25,'FyJ0jgAARNX','UXz7xuGCEhU','admin','2350','2016-04-20T16:24:45.607','2016-04-20T16:24:52.972',0); -INSERT INTO `TrackedEntityDataValue` VALUES (26,'FyJ0jgAARNX','a3kGcGDCuk6','admin','7','2016-04-20T16:23:43.380','2016-04-20T16:26:40.328',0); -INSERT INTO `TrackedEntityDataValue` VALUES (27,'FyJ0jgAARNX','ebaJjqltK5N','admin','3','2016-04-20T16:27:08.154','2016-04-20T16:27:12.023',0); -INSERT INTO `TrackedEntityDataValue` VALUES (28,'BijwU5PwIMh','HmkXnHJxcD1',NULL,'Relapse','2015-01-20T13:11:24.264','2015-01-20T13:11:24.264',0); -INSERT INTO `TrackedEntityDataValue` VALUES (29,'BijwU5PwIMh','D7m8vpzxHDJ',NULL,'P+','2015-01-20T13:11:23.240','2015-01-20T13:11:23.240',0); -INSERT INTO `TrackedEntityDataValue` VALUES (30,'qgaHGxGEI56','HmkXnHJxcD1',NULL,'Failure','2015-01-20T13:09:13.353','2015-01-20T13:09:13.353',0); -INSERT INTO `TrackedEntityDataValue` VALUES (31,'qgaHGxGEI56','D7m8vpzxHDJ',NULL,'P+','2015-01-20T13:09:11.997','2015-01-20T13:09:11.997',0); -INSERT INTO `TrackedEntityDataValue` VALUES (32,'qf2qpuzVOki','H6uSAMO5WLD',NULL,'','2015-09-14T21:29:11.705','2015-09-14T21:29:11.705',0); -INSERT INTO `TrackedEntityDataValue` VALUES (33,'qf2qpuzVOki','X8zyunlgUfM',NULL,'Mixed','2014-07-06T12:05:00.000','2014-07-06T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (34,'qf2qpuzVOki','bx6fsa0t90x',NULL,'false','2014-07-06T12:05:00.000','2014-07-06T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (35,'qf2qpuzVOki','wQLfBvPrXqq',NULL,'Others','2014-07-06T12:05:00.000','2014-07-06T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (36,'qf2qpuzVOki','UXz7xuGCEhU',NULL,'36282','2014-07-06T12:05:00.000','2014-07-06T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (37,'qf2qpuzVOki','a3kGcGDCuk6','system','3','2014-07-06T12:05:00.000','2016-01-15T00:50:38.277',0); -INSERT INTO `TrackedEntityDataValue` VALUES (38,'qf2qpuzVOki','ebaJjqltK5N',NULL,'2','2014-07-06T12:05:00.000','2014-07-06T12:05:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (39,'qf2qpuzVOki','uf3svrmp8Oj','system','csAhQpsk419','2016-01-15T18:14:34.455','2016-01-15T18:14:34.456',0); -INSERT INTO `TrackedEntityDataValue` VALUES (40,'KrsbTnx097t','X8zyunlgUfM',NULL,'Exclusive','2014-11-16T12:54:13.919','2014-11-16T12:54:13.919',0); -INSERT INTO `TrackedEntityDataValue` VALUES (41,'KrsbTnx097t','cYGaxwK615G',NULL,'Negative','2014-11-16T12:54:17.951','2014-11-16T12:54:17.951',0); -INSERT INTO `TrackedEntityDataValue` VALUES (42,'KrsbTnx097t','HLmTEmupdX0',NULL,'No','2014-11-16T12:54:17.285','2014-11-16T12:54:17.285',0); -INSERT INTO `TrackedEntityDataValue` VALUES (43,'KrsbTnx097t','pOe0ogW4OWd',NULL,'2','2014-11-16T12:54:16.669','2014-11-16T12:54:16.669',0); -INSERT INTO `TrackedEntityDataValue` VALUES (44,'KrsbTnx097t','ebaJjqltK5N',NULL,'1','2014-11-16T12:54:15.350','2014-11-16T12:54:15.350',0); -INSERT INTO `TrackedEntityDataValue` VALUES (45,'KrsbTnx097t','bx6fsa0t90x',NULL,'No','2014-11-16T12:54:14.581','2014-11-16T12:54:14.581',0); -INSERT INTO `TrackedEntityDataValue` VALUES (46,'KrsbTnx097t','GQY2lXrypjO',NULL,'4321','2014-11-16T12:54:12.717','2014-11-16T12:54:12.717',0); -INSERT INTO `TrackedEntityDataValue` VALUES (47,'KrsbTnx097t','BeynU4L6VCQ',NULL,'No','2014-11-16T12:54:20.644','2014-11-16T12:54:20.644',0); -INSERT INTO `TrackedEntityDataValue` VALUES (48,'KrsbTnx097t','aei1xRjSU2l',NULL,'Unknown','2014-11-16T12:54:20.045','2014-11-16T12:54:20.045',0); -INSERT INTO `TrackedEntityDataValue` VALUES (49,'KrsbTnx097t','sj3j9Hwc7so',NULL,'TDF/3TC/NVP - 1','2014-11-16T12:54:19.310','2014-11-16T12:54:19.310',0); -INSERT INTO `TrackedEntityDataValue` VALUES (50,'KrsbTnx097t','hDZbpskhqDd',NULL,'PCR','2014-11-16T12:54:18.603','2014-11-16T12:54:18.603',0); -INSERT INTO `TrackedEntityDataValue` VALUES (51,'V9HVjkqcUcg','X8zyunlgUfM',NULL,'Replacement','2014-11-16T12:53:57.409','2014-11-16T12:53:57.409',0); -INSERT INTO `TrackedEntityDataValue` VALUES (52,'V9HVjkqcUcg','ebaJjqltK5N',NULL,'1','2014-11-16T12:53:56.045','2014-11-16T12:53:56.045',0); -INSERT INTO `TrackedEntityDataValue` VALUES (53,'V9HVjkqcUcg','bx6fsa0t90x',NULL,'Yes','2014-11-16T12:53:55.182','2014-11-16T12:53:55.182',0); -INSERT INTO `TrackedEntityDataValue` VALUES (54,'V9HVjkqcUcg','wQLfBvPrXqq',NULL,'NVP only','2014-11-16T12:53:53.955','2014-11-16T12:53:53.955',0); -INSERT INTO `TrackedEntityDataValue` VALUES (55,'V9HVjkqcUcg','UXz7xuGCEhU',NULL,'3212','2014-11-16T12:53:52.812','2014-11-16T12:53:52.812',0); -INSERT INTO `TrackedEntityDataValue` VALUES (56,'V9HVjkqcUcg','a3kGcGDCuk6',NULL,'8','2014-11-16T12:53:50.228','2014-11-16T12:53:50.228',0); -INSERT INTO `TrackedEntityDataValue` VALUES (57,'vF0YkkC3JD3','sj3j9Hwc7so',NULL,'TDF/3TC/EFV - 1','2014-11-16T12:26:30.686','2014-11-16T12:26:30.686',0); -INSERT INTO `TrackedEntityDataValue` VALUES (58,'vF0YkkC3JD3','X8zyunlgUfM',NULL,'Replacement','2014-11-16T12:26:17.263','2014-11-16T12:26:17.263',0); -INSERT INTO `TrackedEntityDataValue` VALUES (59,'vF0YkkC3JD3','bx6fsa0t90x',NULL,'Yes','2014-11-16T12:26:17.972','2014-11-16T12:26:17.972',0); -INSERT INTO `TrackedEntityDataValue` VALUES (60,'vF0YkkC3JD3','ebaJjqltK5N',NULL,'1','2014-11-16T12:26:18.782','2014-11-16T12:26:18.782',0); -INSERT INTO `TrackedEntityDataValue` VALUES (61,'vF0YkkC3JD3','GQY2lXrypjO',NULL,'2341','2014-11-16T12:26:15.310','2014-11-16T12:26:15.310',0); -INSERT INTO `TrackedEntityDataValue` VALUES (62,'vF0YkkC3JD3','pOe0ogW4OWd',NULL,'2','2014-11-16T12:26:19.482','2014-11-16T12:26:19.482',0); -INSERT INTO `TrackedEntityDataValue` VALUES (63,'vF0YkkC3JD3','HLmTEmupdX0',NULL,'No','2014-11-16T12:26:20.746','2014-11-16T12:26:20.746',0); -INSERT INTO `TrackedEntityDataValue` VALUES (64,'vF0YkkC3JD3','cYGaxwK615G',NULL,'Positive','2014-11-16T12:26:21.807','2014-11-16T12:26:21.807',0); -INSERT INTO `TrackedEntityDataValue` VALUES (65,'vF0YkkC3JD3','BeynU4L6VCQ',NULL,'Unknown','2014-11-16T12:26:32.419','2014-11-16T12:26:32.419',0); -INSERT INTO `TrackedEntityDataValue` VALUES (66,'vF0YkkC3JD3','aei1xRjSU2l',NULL,'No','2014-11-16T12:26:31.642','2014-11-16T12:26:31.642',0); -INSERT INTO `TrackedEntityDataValue` VALUES (67,'vF0YkkC3JD3','hDZbpskhqDd',NULL,'Rapid','2014-11-16T12:26:23.724','2014-11-16T12:26:23.724',0); -INSERT INTO `TrackedEntityDataValue` VALUES (68,'nN7gGLW5Akv','wQLfBvPrXqq',NULL,'Others','2014-11-16T12:25:50.749','2014-11-16T12:25:50.749',0); -INSERT INTO `TrackedEntityDataValue` VALUES (69,'nN7gGLW5Akv','X8zyunlgUfM',NULL,'Replacement','2014-11-16T12:25:53.119','2014-11-16T12:25:53.119',0); -INSERT INTO `TrackedEntityDataValue` VALUES (70,'nN7gGLW5Akv','ebaJjqltK5N',NULL,'1','2014-11-16T12:25:52.416','2014-11-16T12:25:52.416',0); -INSERT INTO `TrackedEntityDataValue` VALUES (71,'nN7gGLW5Akv','bx6fsa0t90x',NULL,'No','2014-11-16T12:25:51.662','2014-11-16T12:25:51.662',0); -INSERT INTO `TrackedEntityDataValue` VALUES (72,'nN7gGLW5Akv','UXz7xuGCEhU',NULL,'2313','2014-11-16T12:25:49.243','2014-11-16T12:25:49.243',0); -INSERT INTO `TrackedEntityDataValue` VALUES (73,'nN7gGLW5Akv','a3kGcGDCuk6',NULL,'8','2014-11-16T12:25:46.981','2014-11-16T12:25:46.981',0); -INSERT INTO `TrackedEntityDataValue` VALUES (74,'XGLkLlOXgmE','a3kGcGDCuk6',NULL,'10','2014-11-16T11:38:36.538','2014-11-16T11:38:36.538',0); -INSERT INTO `TrackedEntityDataValue` VALUES (75,'XGLkLlOXgmE','X8zyunlgUfM',NULL,'Replacement','2014-11-16T11:38:45.001','2014-11-16T11:38:45.001',0); -INSERT INTO `TrackedEntityDataValue` VALUES (76,'XGLkLlOXgmE','ebaJjqltK5N',NULL,'1','2014-11-16T11:38:43.615','2014-11-16T11:38:43.615',0); -INSERT INTO `TrackedEntityDataValue` VALUES (77,'XGLkLlOXgmE','bx6fsa0t90x',NULL,'No','2014-11-16T11:38:42.852','2014-11-16T11:38:42.852',0); -INSERT INTO `TrackedEntityDataValue` VALUES (78,'XGLkLlOXgmE','wQLfBvPrXqq',NULL,'NVP only','2014-11-16T11:38:42.067','2014-11-16T11:38:42.067',0); -INSERT INTO `TrackedEntityDataValue` VALUES (79,'XGLkLlOXgmE','UXz7xuGCEhU',NULL,'3243','2014-11-16T11:38:41.180','2014-11-16T11:38:41.180',0); -INSERT INTO `TrackedEntityDataValue` VALUES (80,'YHMjNgw3yQZ','UXz7xuGCEhU',NULL,'4210','2014-11-15T21:22:39.207','2014-11-15T21:22:39.207',0); -INSERT INTO `TrackedEntityDataValue` VALUES (81,'YHMjNgw3yQZ','X8zyunlgUfM',NULL,'Exclusive','2014-11-15T21:22:42.885','2014-11-15T21:22:42.885',0); -INSERT INTO `TrackedEntityDataValue` VALUES (82,'YHMjNgw3yQZ','ebaJjqltK5N',NULL,'1','2014-11-15T21:22:41.955','2014-11-15T21:22:41.955',0); -INSERT INTO `TrackedEntityDataValue` VALUES (83,'YHMjNgw3yQZ','bx6fsa0t90x',NULL,'No','2014-11-15T21:22:41.154','2014-11-15T21:22:41.154',0); -INSERT INTO `TrackedEntityDataValue` VALUES (84,'YHMjNgw3yQZ','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T21:22:40.394','2014-11-15T21:22:40.394',0); -INSERT INTO `TrackedEntityDataValue` VALUES (85,'YHMjNgw3yQZ','a3kGcGDCuk6',NULL,'10','2014-11-15T21:22:36.527','2014-11-15T21:22:36.527',0); -INSERT INTO `TrackedEntityDataValue` VALUES (86,'DJgiFfCU0zu','ebaJjqltK5N',NULL,'1','2014-11-15T21:20:18.307','2014-11-15T21:20:18.307',0); -INSERT INTO `TrackedEntityDataValue` VALUES (87,'DJgiFfCU0zu','a3kGcGDCuk6',NULL,'8','2014-11-15T21:20:12.396','2014-11-15T21:20:12.396',0); -INSERT INTO `TrackedEntityDataValue` VALUES (88,'DJgiFfCU0zu','UXz7xuGCEhU',NULL,'4201','2014-11-15T21:20:15.944','2014-11-15T21:20:15.944',0); -INSERT INTO `TrackedEntityDataValue` VALUES (89,'DJgiFfCU0zu','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T21:20:16.883','2014-11-15T21:20:16.883',0); -INSERT INTO `TrackedEntityDataValue` VALUES (90,'DJgiFfCU0zu','bx6fsa0t90x',NULL,'No','2014-11-15T21:20:17.608','2014-11-15T21:20:17.608',0); -INSERT INTO `TrackedEntityDataValue` VALUES (91,'DJgiFfCU0zu','X8zyunlgUfM',NULL,'Replacement','2014-11-15T21:20:19.514','2014-11-15T21:20:19.514',0); -INSERT INTO `TrackedEntityDataValue` VALUES (92,'IeOweNjLXxv','X8zyunlgUfM',NULL,'Replacement','2014-11-15T21:19:27.343','2014-11-15T21:19:27.343',0); -INSERT INTO `TrackedEntityDataValue` VALUES (93,'IeOweNjLXxv','bx6fsa0t90x',NULL,'No','2014-11-15T21:19:24.851','2014-11-15T21:19:24.851',0); -INSERT INTO `TrackedEntityDataValue` VALUES (94,'IeOweNjLXxv','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T21:19:24.174','2014-11-15T21:19:24.174',0); -INSERT INTO `TrackedEntityDataValue` VALUES (95,'IeOweNjLXxv','UXz7xuGCEhU',NULL,'3200','2014-11-15T21:19:23.021','2014-11-15T21:19:23.021',0); -INSERT INTO `TrackedEntityDataValue` VALUES (96,'IeOweNjLXxv','a3kGcGDCuk6',NULL,'8','2014-11-15T21:19:20.648','2014-11-15T21:19:20.648',0); -INSERT INTO `TrackedEntityDataValue` VALUES (97,'IeOweNjLXxv','ebaJjqltK5N',NULL,'1','2014-11-15T21:19:25.454','2014-11-15T21:19:25.454',0); -INSERT INTO `TrackedEntityDataValue` VALUES (98,'vdbUbSCFVYS','HLmTEmupdX0',NULL,'Yes','2014-11-15T19:56:20.845','2014-11-15T19:56:20.845',0); -INSERT INTO `TrackedEntityDataValue` VALUES (99,'vdbUbSCFVYS','cYGaxwK615G',NULL,'Negative','2014-11-15T19:56:21.727','2014-11-15T19:56:21.727',0); -INSERT INTO `TrackedEntityDataValue` VALUES (100,'vdbUbSCFVYS','hDZbpskhqDd',NULL,'Rapid','2014-11-15T19:56:22.407','2014-11-15T19:56:22.407',0); -INSERT INTO `TrackedEntityDataValue` VALUES (101,'vdbUbSCFVYS','sj3j9Hwc7so',NULL,'TDF/3TC/NVP - 1','2014-11-15T19:56:23.328','2014-11-15T19:56:23.328',0); -INSERT INTO `TrackedEntityDataValue` VALUES (102,'vdbUbSCFVYS','aei1xRjSU2l',NULL,'Unknown','2014-11-15T19:56:24.313','2014-11-15T19:56:24.313',0); -INSERT INTO `TrackedEntityDataValue` VALUES (103,'vdbUbSCFVYS','BeynU4L6VCQ',NULL,'Yes','2014-11-15T19:56:25.006','2014-11-15T19:56:25.006',0); -INSERT INTO `TrackedEntityDataValue` VALUES (104,'vdbUbSCFVYS','pOe0ogW4OWd',NULL,'2','2014-11-15T19:56:17.997','2014-11-15T19:56:17.997',0); -INSERT INTO `TrackedEntityDataValue` VALUES (105,'vdbUbSCFVYS','ebaJjqltK5N',NULL,'1','2014-11-15T19:56:16.288','2014-11-15T19:56:16.288',0); -INSERT INTO `TrackedEntityDataValue` VALUES (106,'vdbUbSCFVYS','bx6fsa0t90x',NULL,'Yes','2014-11-15T19:56:15.429','2014-11-15T19:56:15.429',0); -INSERT INTO `TrackedEntityDataValue` VALUES (107,'vdbUbSCFVYS','X8zyunlgUfM',NULL,'Exclusive','2014-11-15T19:56:14.590','2014-11-15T19:56:14.590',0); -INSERT INTO `TrackedEntityDataValue` VALUES (108,'vdbUbSCFVYS','GQY2lXrypjO',NULL,'3212','2014-11-15T19:56:11.839','2014-11-15T19:56:11.839',0); -INSERT INTO `TrackedEntityDataValue` VALUES (109,'DhwJD1gzgOZ','a3kGcGDCuk6',NULL,'5','2014-11-15T19:51:24.125','2014-11-15T19:51:24.125',0); -INSERT INTO `TrackedEntityDataValue` VALUES (110,'DhwJD1gzgOZ','X8zyunlgUfM',NULL,'Replacement','2014-11-15T19:51:30.834','2014-11-15T19:51:30.834',0); -INSERT INTO `TrackedEntityDataValue` VALUES (111,'DhwJD1gzgOZ','ebaJjqltK5N',NULL,'1','2014-11-15T19:51:30.073','2014-11-15T19:51:30.073',0); -INSERT INTO `TrackedEntityDataValue` VALUES (112,'DhwJD1gzgOZ','bx6fsa0t90x',NULL,'No','2014-11-15T19:51:29.411','2014-11-15T19:51:29.411',0); -INSERT INTO `TrackedEntityDataValue` VALUES (113,'DhwJD1gzgOZ','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T19:51:28.473','2014-11-15T19:51:28.473',0); -INSERT INTO `TrackedEntityDataValue` VALUES (114,'DhwJD1gzgOZ','UXz7xuGCEhU',NULL,'3201','2014-11-15T19:51:27.287','2014-11-15T19:51:27.287',0); -INSERT INTO `TrackedEntityDataValue` VALUES (115,'XvVI1eVrqxj','UXz7xuGCEhU',NULL,'3401','2014-11-15T19:14:00.804','2014-11-15T19:14:00.804',0); -INSERT INTO `TrackedEntityDataValue` VALUES (116,'XvVI1eVrqxj','a3kGcGDCuk6',NULL,'8','2014-11-15T19:13:57.673','2014-11-15T19:13:57.673',0); -INSERT INTO `TrackedEntityDataValue` VALUES (117,'XvVI1eVrqxj','X8zyunlgUfM',NULL,'Replacement','2014-11-15T19:14:05.185','2014-11-15T19:14:05.185',0); -INSERT INTO `TrackedEntityDataValue` VALUES (118,'XvVI1eVrqxj','ebaJjqltK5N',NULL,'1','2014-11-15T19:14:03.819','2014-11-15T19:14:03.819',0); -INSERT INTO `TrackedEntityDataValue` VALUES (119,'XvVI1eVrqxj','bx6fsa0t90x',NULL,'Yes','2014-11-15T19:14:02.921','2014-11-15T19:14:02.921',0); -INSERT INTO `TrackedEntityDataValue` VALUES (120,'XvVI1eVrqxj','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T19:14:01.783','2014-11-15T19:14:01.783',0); -INSERT INTO `TrackedEntityDataValue` VALUES (121,'q0Hcikut16c','bx6fsa0t90x',NULL,'No','2014-11-15T19:12:44.180','2014-11-15T19:12:44.180',0); -INSERT INTO `TrackedEntityDataValue` VALUES (122,'q0Hcikut16c','a3kGcGDCuk6',NULL,'5','2014-11-15T19:12:38.576','2014-11-15T19:12:38.576',0); -INSERT INTO `TrackedEntityDataValue` VALUES (123,'q0Hcikut16c','UXz7xuGCEhU',NULL,'4201','2014-11-15T19:12:42.149','2014-11-15T19:12:42.149',0); -INSERT INTO `TrackedEntityDataValue` VALUES (124,'q0Hcikut16c','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T19:12:43.385','2014-11-15T19:12:43.385',0); -INSERT INTO `TrackedEntityDataValue` VALUES (125,'q0Hcikut16c','ebaJjqltK5N',NULL,'1','2014-11-15T19:12:44.943','2014-11-15T19:12:44.943',0); -INSERT INTO `TrackedEntityDataValue` VALUES (126,'q0Hcikut16c','X8zyunlgUfM',NULL,'Replacement','2014-11-15T19:12:45.863','2014-11-15T19:12:45.863',0); -INSERT INTO `TrackedEntityDataValue` VALUES (127,'ea2QqDBbvMX','X8zyunlgUfM',NULL,'Replacement','2014-11-15T19:11:30.088','2014-11-15T19:11:30.088',0); -INSERT INTO `TrackedEntityDataValue` VALUES (128,'ea2QqDBbvMX','ebaJjqltK5N',NULL,'2','2014-11-15T19:11:29.018','2014-11-15T19:11:29.018',0); -INSERT INTO `TrackedEntityDataValue` VALUES (129,'ea2QqDBbvMX','bx6fsa0t90x',NULL,'Yes','2014-11-15T19:11:28.148','2014-11-15T19:11:28.148',0); -INSERT INTO `TrackedEntityDataValue` VALUES (130,'ea2QqDBbvMX','a3kGcGDCuk6',NULL,'5','2014-11-15T19:11:22.476','2014-11-15T19:11:22.476',0); -INSERT INTO `TrackedEntityDataValue` VALUES (131,'ea2QqDBbvMX','wQLfBvPrXqq',NULL,'Others','2014-11-15T19:11:27.329','2014-11-15T19:11:27.329',0); -INSERT INTO `TrackedEntityDataValue` VALUES (132,'ea2QqDBbvMX','UXz7xuGCEhU',NULL,'3500','2014-11-15T19:11:25.977','2014-11-15T19:11:25.977',0); -INSERT INTO `TrackedEntityDataValue` VALUES (133,'qIb7Lu0YDi9','GQY2lXrypjO',NULL,'3500','2014-11-15T18:01:19.175','2014-11-15T18:01:19.175',0); -INSERT INTO `TrackedEntityDataValue` VALUES (134,'qIb7Lu0YDi9','HLmTEmupdX0',NULL,'No','2014-11-15T18:01:26.528','2014-11-15T18:01:26.528',0); -INSERT INTO `TrackedEntityDataValue` VALUES (135,'qIb7Lu0YDi9','pOe0ogW4OWd',NULL,'2','2014-11-15T18:01:25.822','2014-11-15T18:01:25.822',0); -INSERT INTO `TrackedEntityDataValue` VALUES (136,'qIb7Lu0YDi9','ebaJjqltK5N',NULL,'1','2014-11-15T18:01:24.928','2014-11-15T18:01:24.928',0); -INSERT INTO `TrackedEntityDataValue` VALUES (137,'qIb7Lu0YDi9','BeynU4L6VCQ',NULL,'No','2014-11-15T18:01:31.198','2014-11-15T18:01:31.198',0); -INSERT INTO `TrackedEntityDataValue` VALUES (138,'qIb7Lu0YDi9','aei1xRjSU2l',NULL,'No','2014-11-15T18:01:30.553','2014-11-15T18:01:30.553',0); -INSERT INTO `TrackedEntityDataValue` VALUES (139,'qIb7Lu0YDi9','sj3j9Hwc7so',NULL,'TDF/3TC/NVP - 1','2014-11-15T18:01:29.722','2014-11-15T18:01:29.722',0); -INSERT INTO `TrackedEntityDataValue` VALUES (140,'qIb7Lu0YDi9','hDZbpskhqDd',NULL,'PCR','2014-11-15T18:01:28.534','2014-11-15T18:01:28.534',0); -INSERT INTO `TrackedEntityDataValue` VALUES (141,'qIb7Lu0YDi9','bx6fsa0t90x',NULL,'Yes','2014-11-15T18:01:23.966','2014-11-15T18:01:23.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (142,'qIb7Lu0YDi9','X8zyunlgUfM',NULL,'Exclusive','2014-11-15T18:01:21.215','2014-11-15T18:01:21.215',0); -INSERT INTO `TrackedEntityDataValue` VALUES (143,'qIb7Lu0YDi9','cYGaxwK615G',NULL,'Positive','2014-11-15T18:01:27.654','2014-11-15T18:01:27.654',0); -INSERT INTO `TrackedEntityDataValue` VALUES (144,'aO0gvKzIj1k','UXz7xuGCEhU',NULL,'3002','2014-11-15T18:01:01.768','2014-11-15T18:01:01.768',0); -INSERT INTO `TrackedEntityDataValue` VALUES (145,'aO0gvKzIj1k','a3kGcGDCuk6',NULL,'8','2014-11-15T18:00:58.345','2014-11-15T18:00:58.345',0); -INSERT INTO `TrackedEntityDataValue` VALUES (146,'aO0gvKzIj1k','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T18:01:03.459','2014-11-15T18:01:03.459',0); -INSERT INTO `TrackedEntityDataValue` VALUES (147,'aO0gvKzIj1k','bx6fsa0t90x',NULL,'Yes','2014-11-15T18:01:04.174','2014-11-15T18:01:04.174',0); -INSERT INTO `TrackedEntityDataValue` VALUES (148,'aO0gvKzIj1k','ebaJjqltK5N',NULL,'1','2014-11-15T18:01:04.962','2014-11-15T18:01:04.962',0); -INSERT INTO `TrackedEntityDataValue` VALUES (149,'aO0gvKzIj1k','X8zyunlgUfM',NULL,'Replacement','2014-11-15T18:01:06.439','2014-11-15T18:01:06.439',0); -INSERT INTO `TrackedEntityDataValue` VALUES (150,'zQg7E7SWhKY','cYGaxwK615G',NULL,'Negative','2014-11-15T18:00:13.728','2014-11-15T18:00:13.728',0); -INSERT INTO `TrackedEntityDataValue` VALUES (151,'zQg7E7SWhKY','sj3j9Hwc7so',NULL,'TDF/3TC/NVP - 1','2014-11-15T18:00:15.474','2014-11-15T18:00:15.474',0); -INSERT INTO `TrackedEntityDataValue` VALUES (152,'zQg7E7SWhKY','aei1xRjSU2l',NULL,'Unknown','2014-11-15T18:00:16.678','2014-11-15T18:00:16.678',0); -INSERT INTO `TrackedEntityDataValue` VALUES (153,'zQg7E7SWhKY','BeynU4L6VCQ',NULL,'Yes','2014-11-15T18:00:17.306','2014-11-15T18:00:17.306',0); -INSERT INTO `TrackedEntityDataValue` VALUES (154,'zQg7E7SWhKY','GQY2lXrypjO',NULL,'3200','2014-11-15T18:00:03.938','2014-11-15T18:00:03.938',0); -INSERT INTO `TrackedEntityDataValue` VALUES (155,'zQg7E7SWhKY','X8zyunlgUfM',NULL,'Exclusive','2014-11-15T18:00:07.093','2014-11-15T18:00:07.093',0); -INSERT INTO `TrackedEntityDataValue` VALUES (156,'zQg7E7SWhKY','bx6fsa0t90x',NULL,'Yes','2014-11-15T18:00:08.425','2014-11-15T18:00:08.425',0); -INSERT INTO `TrackedEntityDataValue` VALUES (157,'zQg7E7SWhKY','ebaJjqltK5N',NULL,'1','2014-11-15T18:00:09.590','2014-11-15T18:00:09.590',0); -INSERT INTO `TrackedEntityDataValue` VALUES (158,'zQg7E7SWhKY','pOe0ogW4OWd',NULL,'3','2014-11-15T18:00:10.496','2014-11-15T18:00:10.496',0); -INSERT INTO `TrackedEntityDataValue` VALUES (159,'zQg7E7SWhKY','HLmTEmupdX0',NULL,'No','2014-11-15T18:00:11.979','2014-11-15T18:00:11.979',0); -INSERT INTO `TrackedEntityDataValue` VALUES (160,'zQg7E7SWhKY','hDZbpskhqDd',NULL,'Rapid','2014-11-15T18:00:14.538','2014-11-15T18:00:14.538',0); -INSERT INTO `TrackedEntityDataValue` VALUES (161,'LctNSYpfdh0','X8zyunlgUfM',NULL,'Mixed','2014-11-15T17:59:48.548','2014-11-15T17:59:48.548',0); -INSERT INTO `TrackedEntityDataValue` VALUES (162,'LctNSYpfdh0','a3kGcGDCuk6',NULL,'8','2014-11-15T17:56:58.714','2014-11-15T17:56:58.714',0); -INSERT INTO `TrackedEntityDataValue` VALUES (163,'LctNSYpfdh0','UXz7xuGCEhU',NULL,'3000','2014-11-15T17:58:12.476','2014-11-15T17:58:12.476',0); -INSERT INTO `TrackedEntityDataValue` VALUES (164,'LctNSYpfdh0','wQLfBvPrXqq',NULL,'NVP only','2014-11-15T17:59:45.730','2014-11-15T17:59:45.730',0); -INSERT INTO `TrackedEntityDataValue` VALUES (165,'LctNSYpfdh0','bx6fsa0t90x',NULL,'No','2014-11-15T17:59:46.741','2014-11-15T17:59:46.741',0); -INSERT INTO `TrackedEntityDataValue` VALUES (166,'LctNSYpfdh0','ebaJjqltK5N',NULL,'1','2014-11-15T17:59:47.571','2014-11-15T17:59:47.571',0); -INSERT INTO `TrackedEntityDataValue` VALUES (167,'TgJUhG6P6TJ','oZg33kd9taw','admin','Male','2014-11-15T14:55:24.011','2014-11-15T14:55:24.011',0); -INSERT INTO `TrackedEntityDataValue` VALUES (168,'TgJUhG6P6TJ','qrur9Dvnyt5','admin','22','2014-11-15T14:55:24.011','2014-11-15T14:55:24.011',0); -INSERT INTO `TrackedEntityDataValue` VALUES (169,'sYRVmmHJu9k','qrur9Dvnyt5','admin','22','2014-11-15T14:55:23.887','2014-11-15T14:55:23.887',0); -INSERT INTO `TrackedEntityDataValue` VALUES (170,'sYRVmmHJu9k','msodh3rEMJa','admin','2013-05-18','2014-11-15T14:55:23.887','2014-11-15T14:55:23.887',0); -INSERT INTO `TrackedEntityDataValue` VALUES (171,'sYRVmmHJu9k','oZg33kd9taw','admin','Male','2014-11-15T14:55:23.887','2014-11-15T14:55:23.887',0); -INSERT INTO `TrackedEntityDataValue` VALUES (172,'sXjvyAhSGsx','oZg33kd9taw','admin','Male','2014-11-15T14:55:23.860','2014-11-15T14:55:23.860',0); -INSERT INTO `TrackedEntityDataValue` VALUES (173,'sXjvyAhSGsx','qrur9Dvnyt5','admin','22','2014-11-15T14:55:23.860','2014-11-15T14:55:23.860',0); -INSERT INTO `TrackedEntityDataValue` VALUES (174,'sG5GMkjDHX4','fWIAEtYVEGk','imported','MODDISCH','2014-11-15T14:55:23.828','2014-11-15T14:55:23.828',0); -INSERT INTO `TrackedEntityDataValue` VALUES (175,'sG5GMkjDHX4','oZg33kd9taw','admin','Female','2014-11-15T14:55:23.828','2014-11-15T14:55:23.828',0); -INSERT INTO `TrackedEntityDataValue` VALUES (176,'sG5GMkjDHX4','eMyVanycQSC','imported','2012-05-29','2014-11-15T14:55:23.828','2014-11-15T14:55:23.828',0); -INSERT INTO `TrackedEntityDataValue` VALUES (177,'sG5GMkjDHX4','qrur9Dvnyt5','admin','26','2014-11-15T14:55:23.828','2014-11-15T14:55:23.828',0); -INSERT INTO `TrackedEntityDataValue` VALUES (178,'sG5GMkjDHX4','vV9UWAZohSf','imported','21','2014-11-15T14:55:23.828','2014-11-15T14:55:23.828',0); -INSERT INTO `TrackedEntityDataValue` VALUES (179,'sG5GMkjDHX4','GieVkTxp4HH','imported','149','2014-11-15T14:55:23.828','2014-11-15T14:55:23.828',0); -INSERT INTO `TrackedEntityDataValue` VALUES (180,'sG5GMkjDHX4','K6uUAvq500H','imported','B54','2014-11-15T14:55:23.828','2014-11-15T14:55:23.828',0); -INSERT INTO `TrackedEntityDataValue` VALUES (181,'sfUiGQXxGHY','msodh3rEMJa','admin','2013-05-18','2014-11-15T14:55:23.779','2014-11-15T14:55:23.779',0); -INSERT INTO `TrackedEntityDataValue` VALUES (182,'sfUiGQXxGHY','qrur9Dvnyt5','admin','22','2014-11-15T14:55:23.779','2014-11-15T14:55:23.779',0); -INSERT INTO `TrackedEntityDataValue` VALUES (183,'sfUiGQXxGHY','oZg33kd9taw','admin','Male','2014-11-15T14:55:23.779','2014-11-15T14:55:23.779',0); -INSERT INTO `TrackedEntityDataValue` VALUES (184,'S3Ed7pz0Qss','qrur9Dvnyt5','admin','26','2014-11-15T14:55:23.742','2014-11-15T14:55:23.742',0); -INSERT INTO `TrackedEntityDataValue` VALUES (185,'S3Ed7pz0Qss','K6uUAvq500H','imported','B54','2014-11-15T14:55:23.742','2014-11-15T14:55:23.742',0); -INSERT INTO `TrackedEntityDataValue` VALUES (186,'S3Ed7pz0Qss','GieVkTxp4HH','imported','129','2014-11-15T14:55:23.742','2014-11-15T14:55:23.742',0); -INSERT INTO `TrackedEntityDataValue` VALUES (187,'S3Ed7pz0Qss','vV9UWAZohSf','imported','21','2014-11-15T14:55:23.742','2014-11-15T14:55:23.742',0); -INSERT INTO `TrackedEntityDataValue` VALUES (188,'S3Ed7pz0Qss','oZg33kd9taw','admin','Female','2014-11-15T14:55:23.742','2014-11-15T14:55:23.742',0); -INSERT INTO `TrackedEntityDataValue` VALUES (189,'S3Ed7pz0Qss','fWIAEtYVEGk','imported','MODDISCH','2014-11-15T14:55:23.742','2014-11-15T14:55:23.742',0); -INSERT INTO `TrackedEntityDataValue` VALUES (190,'Ro8zY5sqPqo','fWIAEtYVEGk','imported','MODDISCH','2014-11-15T14:55:23.707','2014-11-15T14:55:23.707',0); -INSERT INTO `TrackedEntityDataValue` VALUES (191,'Ro8zY5sqPqo','K6uUAvq500H','imported','J988','2014-11-15T14:55:23.706','2014-11-15T14:55:23.706',0); -INSERT INTO `TrackedEntityDataValue` VALUES (192,'Ro8zY5sqPqo','GieVkTxp4HH','imported','120','2014-11-15T14:55:23.707','2014-11-15T14:55:23.707',0); -INSERT INTO `TrackedEntityDataValue` VALUES (193,'Ro8zY5sqPqo','vV9UWAZohSf','imported','35','2014-11-15T14:55:23.707','2014-11-15T14:55:23.707',0); -INSERT INTO `TrackedEntityDataValue` VALUES (194,'Ro8zY5sqPqo','oZg33kd9taw','admin','Female','2014-11-15T14:55:23.706','2014-11-15T14:55:23.706',0); -INSERT INTO `TrackedEntityDataValue` VALUES (195,'Ro8zY5sqPqo','qrur9Dvnyt5','admin','26','2014-11-15T14:55:23.707','2014-11-15T14:55:23.707',0); -INSERT INTO `TrackedEntityDataValue` VALUES (196,'Ro8zY5sqPqo','msodh3rEMJa','imported','2012-01-07','2014-11-15T14:55:23.706','2014-11-15T14:55:23.706',0); -INSERT INTO `TrackedEntityDataValue` VALUES (197,'Ro8zY5sqPqo','eMyVanycQSC','imported','2012-01-05','2014-11-15T14:55:23.706','2014-11-15T14:55:23.706',0); -INSERT INTO `TrackedEntityDataValue` VALUES (198,'qIrQx5zCh92','oZg33kd9taw','admin','Male','2014-11-15T14:55:23.673','2014-11-15T14:55:23.673',0); -INSERT INTO `TrackedEntityDataValue` VALUES (199,'qIrQx5zCh92','qrur9Dvnyt5','admin','22','2014-11-15T14:55:23.673','2014-11-15T14:55:23.673',0); -INSERT INTO `TrackedEntityDataValue` VALUES (200,'OCjUpTL9hFo','qrur9Dvnyt5','system','19','2014-11-15T14:55:23.568','2014-11-15T14:55:23.568',0); -INSERT INTO `TrackedEntityDataValue` VALUES (201,'OCjUpTL9hFo','K6uUAvq500H','system','D100','2014-11-15T14:55:23.568','2014-11-15T14:55:23.568',0); -INSERT INTO `TrackedEntityDataValue` VALUES (202,'OCjUpTL9hFo','GieVkTxp4HH','system','108','2014-11-15T14:55:23.567','2014-11-15T14:55:23.567',0); -INSERT INTO `TrackedEntityDataValue` VALUES (203,'OCjUpTL9hFo','vV9UWAZohSf','system','30','2014-11-15T14:55:23.567','2014-11-15T14:55:23.567',0); -INSERT INTO `TrackedEntityDataValue` VALUES (204,'OCjUpTL9hFo','msodh3rEMJa','system','2013-11-04','2014-11-15T14:55:23.567','2014-11-15T14:55:23.567',0); -INSERT INTO `TrackedEntityDataValue` VALUES (205,'OCjUpTL9hFo','eMyVanycQSC','system','2013-11-04','2014-11-15T14:55:23.568','2014-11-15T14:55:23.568',0); -INSERT INTO `TrackedEntityDataValue` VALUES (206,'OCjUpTL9hFo','oZg33kd9taw','system','Female','2014-11-15T14:55:23.568','2014-11-15T14:55:23.568',0); -INSERT INTO `TrackedEntityDataValue` VALUES (207,'OCjUpTL9hFo','fWIAEtYVEGk','system','MODDISCH','2014-11-15T14:55:23.567','2014-11-15T14:55:23.567',0); -INSERT INTO `TrackedEntityDataValue` VALUES (208,'o5gLo6FlAe4','oZg33kd9taw','admin','Female','2014-11-15T14:55:23.503','2014-11-15T14:55:23.503',0); -INSERT INTO `TrackedEntityDataValue` VALUES (209,'o5gLo6FlAe4','qrur9Dvnyt5','admin','26','2014-11-15T14:55:23.503','2014-11-15T14:55:23.503',0); -INSERT INTO `TrackedEntityDataValue` VALUES (210,'NkvkOpBjkkH','qrur9Dvnyt5','admin','26','2014-11-15T14:55:23.475','2014-11-15T14:55:23.475',0); -INSERT INTO `TrackedEntityDataValue` VALUES (211,'NkvkOpBjkkH','oZg33kd9taw','admin','Female','2014-11-15T14:55:23.476','2014-11-15T14:55:23.476',0); -INSERT INTO `TrackedEntityDataValue` VALUES (212,'j0jx4um8pMX','GieVkTxp4HH','imported','172','2014-11-15T14:55:23.228','2014-11-15T14:55:23.228',0); -INSERT INTO `TrackedEntityDataValue` VALUES (213,'j0jx4um8pMX','K6uUAvq500H','imported','B54','2014-11-15T14:55:23.228','2014-11-15T14:55:23.228',0); -INSERT INTO `TrackedEntityDataValue` VALUES (214,'j0jx4um8pMX','vV9UWAZohSf','imported','54','2014-11-15T14:55:23.228','2014-11-15T14:55:23.228',0); -INSERT INTO `TrackedEntityDataValue` VALUES (215,'j0jx4um8pMX','oZg33kd9taw','admin','Female','2014-11-15T14:55:23.228','2014-11-15T14:55:23.228',0); -INSERT INTO `TrackedEntityDataValue` VALUES (216,'j0jx4um8pMX','qrur9Dvnyt5','admin','26','2014-11-15T14:55:23.228','2014-11-15T14:55:23.228',0); -INSERT INTO `TrackedEntityDataValue` VALUES (217,'j0jx4um8pMX','eMyVanycQSC','imported','2012-05-01','2014-11-15T14:55:23.229','2014-11-15T14:55:23.229',0); -INSERT INTO `TrackedEntityDataValue` VALUES (218,'j0jx4um8pMX','fWIAEtYVEGk','imported','MODDISCH','2014-11-15T14:55:23.228','2014-11-15T14:55:23.228',0); -INSERT INTO `TrackedEntityDataValue` VALUES (219,'IfN2uN0PPgW','qrur9Dvnyt5','system','23','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (220,'IfN2uN0PPgW','K6uUAvq500H','system','A001','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (221,'IfN2uN0PPgW','GieVkTxp4HH','system','142','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (222,'IfN2uN0PPgW','vV9UWAZohSf','system','51','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (223,'IfN2uN0PPgW','fWIAEtYVEGk','system','MODDISCH','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (224,'IfN2uN0PPgW','msodh3rEMJa','system','2013-11-05','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (225,'IfN2uN0PPgW','eMyVanycQSC','system','2013-11-04','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (226,'IfN2uN0PPgW','oZg33kd9taw','system','Female','2014-11-15T14:55:23.145','2014-11-15T14:55:23.145',0); -INSERT INTO `TrackedEntityDataValue` VALUES (227,'HUBOSWKAWoU','oZg33kd9taw','system','Male','2014-11-15T14:55:23.051','2014-11-15T14:55:23.051',0); -INSERT INTO `TrackedEntityDataValue` VALUES (228,'HUBOSWKAWoU','K6uUAvq500H','system','C108','2014-11-15T14:55:23.051','2014-11-15T14:55:23.051',0); -INSERT INTO `TrackedEntityDataValue` VALUES (229,'HUBOSWKAWoU','GieVkTxp4HH','system','109','2014-11-15T14:55:23.051','2014-11-15T14:55:23.051',0); -INSERT INTO `TrackedEntityDataValue` VALUES (230,'HUBOSWKAWoU','vV9UWAZohSf','system','34','2014-11-15T14:55:23.051','2014-11-15T14:55:23.051',0); -INSERT INTO `TrackedEntityDataValue` VALUES (231,'HUBOSWKAWoU','fWIAEtYVEGk','system','MODDISCH','2014-11-15T14:55:23.051','2014-11-15T14:55:23.051',0); -INSERT INTO `TrackedEntityDataValue` VALUES (232,'HUBOSWKAWoU','msodh3rEMJa','system','2013-11-05','2014-11-15T14:55:23.052','2014-11-15T14:55:23.052',0); -INSERT INTO `TrackedEntityDataValue` VALUES (233,'HUBOSWKAWoU','eMyVanycQSC','system','2013-11-04','2014-11-15T14:55:23.051','2014-11-15T14:55:23.051',0); -INSERT INTO `TrackedEntityDataValue` VALUES (234,'HUBOSWKAWoU','qrur9Dvnyt5','system','23','2014-11-15T14:55:23.052','2014-11-15T14:55:23.052',0); -INSERT INTO `TrackedEntityDataValue` VALUES (235,'hnaWBxMw5j3','qrur9Dvnyt5','system','16','2014-11-15T14:55:23.007','2014-11-15T14:55:23.007',0); -INSERT INTO `TrackedEntityDataValue` VALUES (236,'hnaWBxMw5j3','K6uUAvq500H','system','A00','2014-11-15T14:55:23.007','2014-11-15T14:55:23.007',0); -INSERT INTO `TrackedEntityDataValue` VALUES (237,'hnaWBxMw5j3','GieVkTxp4HH','system','140','2014-11-15T14:55:23.007','2014-11-15T14:55:23.007',0); -INSERT INTO `TrackedEntityDataValue` VALUES (238,'hnaWBxMw5j3','vV9UWAZohSf','system','24','2014-11-15T14:55:23.007','2014-11-15T14:55:23.007',0); -INSERT INTO `TrackedEntityDataValue` VALUES (239,'hnaWBxMw5j3','msodh3rEMJa','system','2013-05-31','2014-11-15T14:55:23.006','2014-11-15T14:55:23.006',0); -INSERT INTO `TrackedEntityDataValue` VALUES (240,'hnaWBxMw5j3','eMyVanycQSC','system','2013-05-01','2014-11-15T14:55:23.007','2014-11-15T14:55:23.007',0); -INSERT INTO `TrackedEntityDataValue` VALUES (241,'hnaWBxMw5j3','oZg33kd9taw','system','Female','2014-11-15T14:55:23.007','2014-11-15T14:55:23.007',0); -INSERT INTO `TrackedEntityDataValue` VALUES (242,'hnaWBxMw5j3','fWIAEtYVEGk','system','MODDISCH','2014-11-15T14:55:23.007','2014-11-15T14:55:23.007',0); -INSERT INTO `TrackedEntityDataValue` VALUES (243,'hjuhPUlUIdk','oZg33kd9taw','system','Female','2014-11-15T14:55:22.966','2014-11-15T14:55:22.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (244,'hjuhPUlUIdk','K6uUAvq500H','system','A00','2014-11-15T14:55:22.966','2014-11-15T14:55:22.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (245,'hjuhPUlUIdk','GieVkTxp4HH','system','133','2014-11-15T14:55:22.966','2014-11-15T14:55:22.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (246,'hjuhPUlUIdk','vV9UWAZohSf','system','79','2014-11-15T14:55:22.966','2014-11-15T14:55:22.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (247,'hjuhPUlUIdk','fWIAEtYVEGk','system','MODTRANS','2014-11-15T14:55:22.966','2014-11-15T14:55:22.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (248,'hjuhPUlUIdk','msodh3rEMJa','system','2014-01-09','2014-11-15T14:55:22.966','2014-11-15T14:55:22.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (249,'hjuhPUlUIdk','eMyVanycQSC','system','2014-01-08','2014-11-15T14:55:22.965','2014-11-15T14:55:22.965',0); -INSERT INTO `TrackedEntityDataValue` VALUES (250,'hjuhPUlUIdk','qrur9Dvnyt5','system','23','2014-11-15T14:55:22.966','2014-11-15T14:55:22.966',0); -INSERT INTO `TrackedEntityDataValue` VALUES (251,'GFR73Oyo9bV','oZg33kd9taw','system','Male','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (252,'GFR73Oyo9bV','K6uUAvq500H','system','A000','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (253,'GFR73Oyo9bV','GieVkTxp4HH','system','131','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (254,'GFR73Oyo9bV','vV9UWAZohSf','system','54','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (255,'GFR73Oyo9bV','fWIAEtYVEGk','system','MODTRANS','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (256,'GFR73Oyo9bV','eMyVanycQSC','system','2014-01-01','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (257,'GFR73Oyo9bV','msodh3rEMJa','system','2014-01-08','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (258,'GFR73Oyo9bV','qrur9Dvnyt5','system','12','2014-11-15T14:55:22.824','2014-11-15T14:55:22.824',0); -INSERT INTO `TrackedEntityDataValue` VALUES (259,'yWJCccgH2rQ','K6uUAvq500H','system','B16','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (260,'yWJCccgH2rQ','GieVkTxp4HH','system','103','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (261,'yWJCccgH2rQ','vV9UWAZohSf','system','43','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (262,'yWJCccgH2rQ','msodh3rEMJa','system','2013-11-05','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (263,'yWJCccgH2rQ','eMyVanycQSC','system','2013-11-04','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (264,'yWJCccgH2rQ','oZg33kd9taw','system','Male','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (265,'yWJCccgH2rQ','qrur9Dvnyt5','system','18','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (266,'yWJCccgH2rQ','fWIAEtYVEGk','system','MODDISCH','2013-11-05T00:00:00.000','2013-11-05T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (267,'Yp0oC0Yb9hR','msodh3rEMJa','admin','2013-05-18','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (268,'Yp0oC0Yb9hR','oZg33kd9taw','admin','Male','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (269,'Yp0oC0Yb9hR','qrur9Dvnyt5','admin','22','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (270,'XgDqOaJrbut','msodh3rEMJa','admin','2013-05-18','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (271,'XgDqOaJrbut','oZg33kd9taw','admin','Male','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (272,'XgDqOaJrbut','qrur9Dvnyt5','admin','23','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (273,'YhVgcj1vXN6','msodh3rEMJa','admin','2013-05-18','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (274,'YhVgcj1vXN6','oZg33kd9taw','admin','Male','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (275,'YhVgcj1vXN6','qrur9Dvnyt5','admin','22','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (276,'xqaqOyXIrKI','msodh3rEMJa','admin','2013-05-18','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (277,'xqaqOyXIrKI','oZg33kd9taw','admin','Male','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (278,'xqaqOyXIrKI','qrur9Dvnyt5','admin','22','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (279,'xVIGJUcxIeK','oZg33kd9taw','admin','Male','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (280,'xVIGJUcxIeK','qrur9Dvnyt5','admin','22','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (281,'XivskH4atI0','oZg33kd9taw','admin','Male','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (282,'XivskH4atI0','qrur9Dvnyt5','admin','22','2013-05-30T00:00:00.000','2013-05-30T00:00:00.000',0); -INSERT INTO `TrackedEntityDataValue` VALUES (283,'oosW4rSH7CM','GQY2lXrypjO','system','1233','2014-01-09T19:43:48.852','2014-01-09T19:43:48.852',0); -INSERT INTO `TrackedEntityDataValue` VALUES (284,'oosW4rSH7CM','HLmTEmupdX0','system','Yes','2014-01-09T19:43:55.769','2014-01-09T19:43:55.769',0); -INSERT INTO `TrackedEntityDataValue` VALUES (285,'oosW4rSH7CM','pOe0ogW4OWd','system','3','2014-01-09T19:43:54.313','2014-01-09T19:43:54.313',0); -INSERT INTO `TrackedEntityDataValue` VALUES (286,'oosW4rSH7CM','ebaJjqltK5N','system','0','2014-01-09T19:43:53.042','2014-01-09T19:43:53.042',0); -INSERT INTO `TrackedEntityDataValue` VALUES (287,'oosW4rSH7CM','bx6fsa0t90x','system','No','2014-01-09T19:43:52.094','2014-01-09T19:43:52.094',0); -INSERT INTO `TrackedEntityDataValue` VALUES (288,'oosW4rSH7CM','X8zyunlgUfM','system','Exclusive','2014-01-09T19:43:51.035','2014-01-09T19:43:51.035',0); -INSERT INTO `TrackedEntityDataValue` VALUES (289,'oosW4rSH7CM','OuJ6sgPyAbC','system','123','2014-01-09T19:44:01.609','2014-01-09T19:44:01.609',0); -INSERT INTO `TrackedEntityDataValue` VALUES (290,'oosW4rSH7CM','BeynU4L6VCQ','system','Yes','2014-01-09T19:44:00.360','2014-01-09T19:44:00.360',0); -INSERT INTO `TrackedEntityDataValue` VALUES (291,'oosW4rSH7CM','aei1xRjSU2l','system','Yes','2014-01-09T19:43:59.631','2014-01-09T19:43:59.631',0); -INSERT INTO `TrackedEntityDataValue` VALUES (292,'oosW4rSH7CM','sj3j9Hwc7so','system','NVP Only','2014-01-09T19:43:58.885','2014-01-09T19:43:58.885',0); -INSERT INTO `TrackedEntityDataValue` VALUES (293,'oosW4rSH7CM','hDZbpskhqDd','system','Rapid','2014-01-09T19:43:57.628','2014-01-09T19:43:57.628',0); -INSERT INTO `TrackedEntityDataValue` VALUES (294,'oosW4rSH7CM','cYGaxwK615G','system','Negative','2014-01-09T19:43:56.714','2014-01-09T19:43:56.714',0); -INSERT INTO `TrackedEntityDataValue` VALUES (295,'LKQXmteRtvQ','wQLfBvPrXqq','system','NVP only','2014-01-09T19:43:32.622','2014-01-09T19:43:32.622',0); -INSERT INTO `TrackedEntityDataValue` VALUES (296,'LKQXmteRtvQ','X8zyunlgUfM','system','Exclusive','2014-01-09T19:43:39.387','2014-01-09T19:43:39.387',0); -INSERT INTO `TrackedEntityDataValue` VALUES (297,'LKQXmteRtvQ','UXz7xuGCEhU','system','1232','2014-01-09T19:43:31.292','2014-01-09T19:43:31.292',0); -INSERT INTO `TrackedEntityDataValue` VALUES (298,'LKQXmteRtvQ','bx6fsa0t90x','system','No','2014-01-09T19:43:33.675','2014-01-09T19:43:33.675',0); -INSERT INTO `TrackedEntityDataValue` VALUES (299,'LKQXmteRtvQ','a3kGcGDCuk6','system','123','2014-01-09T19:43:28.902','2014-01-09T19:43:28.902',0); -INSERT INTO `TrackedEntityDataValue` VALUES (300,'LKQXmteRtvQ','ebaJjqltK5N','system','1','2014-01-09T19:43:37.984','2014-01-09T19:43:37.984',0); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `TrackedEntityAttribute` VALUES (1,'w75KJ2mc4zz','MMD_PER_NAM','First name','First name','2014-06-06T20:41:25.233','2015-10-20T13:57:00.939','First name','First name','First name','First name','',1,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,1,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (2,'zDhUuAYrxNC',NULL,'Last name','Last name','2015-04-14T10:21:48.043','2015-10-20T13:57:00.944','Last name','Last name','Last name','Last name','',2,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,1,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (3,'cejWyOfXge6',NULL,'Gender','Gender','2014-01-09T19:12:46.526','2015-10-20T13:57:01.028','Gender','Gender','Gender','Gender','',0,'pC3N9N77UmT','TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (4,'NDXw0cluzSw',NULL,'Email','Email','2013-11-12T00:50:56.600','2015-10-20T13:57:00.957','Email','Email','Email address','Email address','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (5,'iESIqZ0R0R0',NULL,'Date of birth','Date of birth','2014-01-09T19:12:46.579','2015-10-20T13:57:01.004','Date of birth','Date of birth','Date of birth','Date of birth','',0,NULL,'DATE',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (6,'VqEFza8wbwA','MMD_PER_ADR1','Address','Address','2014-06-06T20:37:25.949','2015-10-20T13:57:01.025','Address','Address','Country','Country','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (7,'OvY4VVhSDeJ',NULL,'Weight in kg','Weight in kg','2013-11-12T00:50:38.858','2015-10-20T13:57:00.986','Weight in kg','Weight in kg','Weight in kg','Weight in kg','',0,NULL,'NUMBER',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (8,'lw1SqmMlnfh','Height in cm','Height in cm','Height in cm','2014-03-21T19:40:13.778','2015-10-20T13:57:00.988','Height in cm','Height in cm','Height in cm','Height in cm','',0,NULL,'NUMBER',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (9,'DODgdr5Oo2v','Provider ID','Provider ID','Provider ID','2014-04-30T13:08:16.538','2015-10-20T13:57:00.975','Provider ID','Provider ID','Provider ID','Provider ID','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,1,0); -INSERT INTO `TrackedEntityAttribute` VALUES (10,'xs8A6tQJY0s',NULL,'TB identifier','TB identifier','2016-08-04T11:49:18.330','2016-08-05T19:42:42.929','TB identifier','TB identifier',NULL,NULL,'##########',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,1,0,0,1,0); -INSERT INTO `TrackedEntityAttribute` VALUES (11,'spFvx9FndA4',NULL,'Age','Age','2014-01-09T19:12:46.582','2017-01-26T19:36:22.158','Age','Age','Age','Age','',0,NULL,'AGE',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (12,'FO4sWYJ64LQ','City','City','City','2015-04-14T10:22:53.831','2015-10-20T13:57:01.018','City','City','City','City','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (13,'GUOBQt5K2WI','State','State','State','2014-03-26T13:32:59.308','2015-10-20T13:57:00.992','State','State','State','State','',0,NULL,'NUMBER',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (14,'n9nUvfpTsxQ','Zip code','Zip code','Zip code','2014-03-26T13:33:10.320','2015-10-20T13:57:00.990','Zip code','Zip code','Zip code','Zip code','',0,NULL,'NUMBER',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (15,'P2cwLGskgxn',NULL,'Phone number','Phone number','2014-01-09T19:12:46.584','2015-10-20T13:57:00.980','Phone number','Phone number','Phone number','Phone number','',0,NULL,'PHONE_NUMBER',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (16,'G7vUx908SwP',NULL,'Residence location','Residence location','2016-04-20T17:10:32.155','2016-04-20T17:10:32.155','Residence location','Residence location',NULL,NULL,'',0,NULL,'COORDINATE',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (17,'o9odfev2Ty5','Mother maiden name','Mother maiden name','Mother maiden name','2014-03-26T13:33:31.581','2015-10-20T13:57:00.960','Mother maiden name','Mother maiden name','Mother maiden name','Mother maiden name','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (18,'AuPLng5hLbE','National identifier','National identifier','National identifier','2014-03-26T13:34:16.735','2015-10-20T13:57:00.947','National identifier','National identifier','National identifier','National identifier','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,1,0); -INSERT INTO `TrackedEntityAttribute` VALUES (19,'A4xFHyieXys','Occupation','Occupation','Occupation','2014-03-26T13:35:44.409','2015-10-20T13:57:00.966','Occupation','Occupation','Occupation','Occupation','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (20,'kyIzQsj96BD','Company','Company','Company','2014-03-26T13:35:50.778','2015-10-20T13:57:00.950','Company','Company','Company','Company','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (21,'ruQQnf6rswq',NULL,'TB number','TB number','2014-01-09T19:12:46.551','2016-08-04T11:48:56.928','TB number','TB number','TB number','TB number','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (22,'VHfUeXpawmE','Vehicle','Vehicle','Vehicle','2014-03-26T13:35:59.015','2015-10-20T13:57:00.952','Vehicle','Vehicle','Vehicle','Vehicle','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (23,'H9IlTX2X6SL','Blood type','Blood type','Blood type','2014-03-26T13:36:10.664','2015-10-20T13:57:00.955','Blood type','Blood type','Blood type','Blood type','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (24,'Qo571yj6Zcn','Latitude','Latitude','Latitude','2014-03-26T13:36:32.778','2015-10-20T13:57:00.971','Latitude','Latitude','Latitude','Latitude','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (25,'RG7uGl4w5Jq','Longitude','Longitude','Longitude','2014-03-26T13:36:37.936','2015-10-20T13:57:00.962','Longitude','Longitude','Longitude','Longitude','',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (26,'lZGmxYbs97q','MMD_PER_ID','Unique ID','Unique ID','2014-06-06T20:42:44.229','2015-10-20T13:57:01.009','Unique identifier','Unique identifier','Unique identiifer','Unique identiifer','',0,NULL,'NUMBER',NULL,'SEARCH_ORG_UNITS',1,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (27,'ZcBPrXKahq2',NULL,'Postal code','Postal code','2015-04-14T10:22:41.205','2015-10-20T13:57:01.020','Postal code','Postal code',NULL,NULL,'',0,NULL,'TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (28,'Agywv2JGwuq','MMD_PER_MOB','Mobile number','Mobile number','2014-06-06T20:41:52.848','2015-10-20T13:57:01.015','Mobile number','Mobile number','Mobile number','Mobile number','',0,NULL,'PHONE_NUMBER',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (29,'KmEUg2hHEtx',NULL,'Email address','Email address','2015-04-14T10:23:13.574','2015-10-20T13:57:01.012','Email address','Email address',NULL,NULL,'',0,NULL,'EMAIL',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (30,'gHGyrwKPzej','MMD_PER_DOB','Birth date','Birth date','2014-06-06T20:37:58.928','2015-10-20T13:57:01.006','Birth date','Birth date','Birth date','Birth date','',0,NULL,'DATE',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -INSERT INTO `TrackedEntityAttribute` VALUES (31,'ciq2USN94oJ','MMD_PER_STA','Civil status','Civil status','2014-06-06T20:39:14.328','2015-10-20T13:57:01.031','Civil status','Civil status','Civil status','Civil status','',0,'xjA5E9MimMU','TEXT',NULL,'SEARCH_ORG_UNITS',0,0,0,0,0,0,0); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -INSERT INTO `TrackedEntity` VALUES (1,'nEenWmSyUEp',NULL,'Person','Person','2014-08-20T12:28:56.409','2015-10-14T13:36:53.063',NULL,NULL,'Person','Person'); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -INSERT INTO `SystemInfo` VALUES (1,'2017-11-29T11:27:46.935','yyyy-mm-dd','2.28','https://play.dhis2.org/android-current'); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -INSERT INTO `Resource` VALUES (1,'SYSTEM_INFO','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (2,'USER','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (3,'ORGANISATION_UNIT','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (4,'CATEGORY','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (5,'CATEGORY_COMBO','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (6,'PROGRAM','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (7,'TRACKED_ENTITY','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (8,'OPTION_SET','2017-11-29T11:27:46.935'); -INSERT INTO `Resource` VALUES (9,'EVENT','2018-01-31T21:16:50.335'); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -INSERT INTO `RelationshipType` VALUES (1,'V2kkHafqs8G',NULL,'Mother-Child','Mother-Child','2013-09-19T15:17:41.000','2014-04-14T13:53:20.166','Child','Mother'); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (1,'l2T72XzBCLd',NULL,'Child Programme First name','Child Programme First name','2017-01-26T19:39:33.347','2017-01-26T19:39:33.347',NULL,'Child Programme First name',NULL,NULL,0,'w75KJ2mc4zz',0,1,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (2,'XmRd2ZDjWhF',NULL,'Child Programme Last name','Child Programme Last name','2017-01-26T19:39:33.350','2017-01-26T19:39:33.350',NULL,'Child Programme Last name',NULL,NULL,0,'zDhUuAYrxNC',0,1,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (3,'pWEEfUJUjej',NULL,'Child Programme Gender','Child Programme Gender','2017-01-26T19:39:33.352','2017-01-26T19:39:33.352',NULL,'Child Programme Gender',NULL,NULL,0,'cejWyOfXge6',0,0,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (4,'CgwB73TbuLC',NULL,'MNCH / PNC (Adult Woman) First name','MNCH / PNC (Adult Woman) First name','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'MNCH / PNC (Adult Woman) First name',NULL,NULL,1,'w75KJ2mc4zz',0,1,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (5,'r5BFLb7DBUz',NULL,'MNCH / PNC (Adult Woman) Last name','MNCH / PNC (Adult Woman) Last name','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'MNCH / PNC (Adult Woman) Last name',NULL,NULL,1,'zDhUuAYrxNC',0,1,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (6,'mPsilazxAOu',NULL,'MNCH / PNC (Adult Woman) Email','MNCH / PNC (Adult Woman) Email','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'MNCH / PNC (Adult Woman) Email',NULL,NULL,0,'NDXw0cluzSw',0,0,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (7,'sd5NKcg1Uwq',NULL,'MNCH / PNC (Adult Woman) Date of birth','MNCH / PNC (Adult Woman) Date of birth','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'MNCH / PNC (Adult Woman) Date of birth',NULL,NULL,1,'iESIqZ0R0R0',0,1,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (8,'Lotas0ChPeK',NULL,'MNCH / PNC (Adult Woman) Address','MNCH / PNC (Adult Woman) Address','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'MNCH / PNC (Adult Woman) Address',NULL,NULL,0,'VqEFza8wbwA',0,0,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (9,'w5kSMQxp0Tc',NULL,'MNCH / PNC (Adult Woman) Weight in kg','MNCH / PNC (Adult Woman) Weight in kg','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'MNCH / PNC (Adult Woman) Weight in kg',NULL,NULL,0,'OvY4VVhSDeJ',0,0,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (10,'hLznDk07IWe',NULL,'MNCH / PNC (Adult Woman) Height in cm','MNCH / PNC (Adult Woman) Height in cm','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'MNCH / PNC (Adult Woman) Height in cm',NULL,NULL,0,'lw1SqmMlnfh',0,0,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (11,'I2xjItuS8mC',NULL,'Provider Follow-up and Support Tool Provider ID','Provider Follow-up and Support Tool Provider ID','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'Provider Follow-up and Support Tool Provider ID',NULL,NULL,1,'DODgdr5Oo2v',0,1,NULL,'fDd25txQckK'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (12,'Vm2jhfaCOnM',NULL,'Provider Follow-up and Support Tool First name','Provider Follow-up and Support Tool First name','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'Provider Follow-up and Support Tool First name',NULL,NULL,1,'w75KJ2mc4zz',0,1,NULL,'fDd25txQckK'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (13,'LhNLZNtUGLL',NULL,'Provider Follow-up and Support Tool Last name','Provider Follow-up and Support Tool Last name','2015-12-13T11:48:00.000','2015-12-13T11:48:00.000',NULL,'Provider Follow-up and Support Tool Last name',NULL,NULL,1,'zDhUuAYrxNC',0,1,NULL,'fDd25txQckK'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (14,'dbzpQYr5G2g',NULL,'TB program First name','TB program First name','2017-01-26T19:40:15.541','2017-01-26T19:40:15.541',NULL,'TB program First name',NULL,NULL,1,'w75KJ2mc4zz',0,1,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (15,'aQQTyeGoWm4',NULL,'TB program Last name','TB program Last name','2017-01-26T19:40:15.544','2017-01-26T19:40:15.544',NULL,'TB program Last name',NULL,NULL,1,'zDhUuAYrxNC',0,1,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (16,'lxo3ITSkcpt',NULL,'TB program Gender','TB program Gender','2017-01-26T19:40:15.546','2017-01-26T19:40:15.546',NULL,'TB program Gender',NULL,NULL,1,'cejWyOfXge6',0,1,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (17,'GR4zW73HT79',NULL,'TB program TB identifier','TB program TB identifier','2017-01-26T19:40:15.548','2017-01-26T19:40:15.548',NULL,'TB program TB identifier',NULL,NULL,0,'xs8A6tQJY0s',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (18,'PGZlGGBOO4j',NULL,'TB program Age','TB program Age','2017-01-26T19:40:15.551','2017-01-26T19:40:15.551',NULL,'TB program Age',NULL,NULL,0,'spFvx9FndA4',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (19,'odf8gHjnhGj',NULL,'TB program Address','TB program Address','2017-01-26T19:40:15.553','2017-01-26T19:40:15.553',NULL,'TB program Address',NULL,NULL,0,'VqEFza8wbwA',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (20,'Yfr1DS1YtNL',NULL,'TB program City','TB program City','2017-01-26T19:40:15.555','2017-01-26T19:40:15.555',NULL,'TB program City',NULL,NULL,0,'FO4sWYJ64LQ',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (21,'ffqeDZkgKCD',NULL,'TB program State','TB program State','2017-01-26T19:40:15.557','2017-01-26T19:40:15.557',NULL,'TB program State',NULL,NULL,0,'GUOBQt5K2WI',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (22,'chAQUt2jsUi',NULL,'TB program Zip code','TB program Zip code','2017-01-26T19:40:15.560','2017-01-26T19:40:15.560',NULL,'TB program Zip code',NULL,NULL,0,'n9nUvfpTsxQ',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (23,'KpapVdLYwXD',NULL,'TB program Email','TB program Email','2017-01-26T19:40:15.562','2017-01-26T19:40:15.562',NULL,'TB program Email',NULL,NULL,0,'NDXw0cluzSw',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (24,'Ad9A7Pf5pry',NULL,'TB program Phone number','TB program Phone number','2017-01-26T19:40:15.564','2017-01-26T19:40:15.564',NULL,'TB program Phone number',NULL,NULL,0,'P2cwLGskgxn',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (25,'DqreLcEVCYv',NULL,'TB program Residence location','TB program Residence location','2017-01-26T19:40:15.570','2017-01-26T19:40:15.570',NULL,'TB program Residence location',NULL,NULL,0,'G7vUx908SwP',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (26,'RZmb75hD73J',NULL,'TB program Mother maiden name','TB program Mother maiden name','2017-01-26T19:40:15.573','2017-01-26T19:40:15.573',NULL,'TB program Mother maiden name',NULL,NULL,0,'o9odfev2Ty5',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (27,'hipFUFnM7Y1',NULL,'TB program National identifier','TB program National identifier','2017-01-26T19:40:15.584','2017-01-26T19:40:15.584',NULL,'TB program National identifier',NULL,NULL,0,'AuPLng5hLbE',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (28,'eq13y2ch8Kc',NULL,'TB program Occupation','TB program Occupation','2017-01-26T19:40:15.587','2017-01-26T19:40:15.587',NULL,'TB program Occupation',NULL,NULL,0,'A4xFHyieXys',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (29,'ArpIjJ4Hld6',NULL,'TB program Company','TB program Company','2017-01-26T19:40:15.589','2017-01-26T19:40:15.589',NULL,'TB program Company',NULL,NULL,0,'kyIzQsj96BD',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (30,'VgbDpzsb2yA',NULL,'TB program TB number','TB program TB number','2017-01-26T19:40:15.593','2017-01-26T19:40:15.593',NULL,'TB program TB number',NULL,NULL,0,'ruQQnf6rswq',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (31,'LWNWXVYSJcf',NULL,'TB program Vehicle','TB program Vehicle','2017-01-26T19:40:15.597','2017-01-26T19:40:15.597',NULL,'TB program Vehicle',NULL,NULL,0,'VHfUeXpawmE',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (32,'fsIgRyUb3yW',NULL,'TB program Blood type','TB program Blood type','2017-01-26T19:40:15.601','2017-01-26T19:40:15.601',NULL,'TB program Blood type',NULL,NULL,0,'H9IlTX2X6SL',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (33,'b52uwD0sqot',NULL,'TB program Weight in kg','TB program Weight in kg','2017-01-26T19:40:15.604','2017-01-26T19:40:15.604',NULL,'TB program Weight in kg',NULL,NULL,0,'OvY4VVhSDeJ',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (34,'wTgg4NwzyEl',NULL,'TB program Height in cm','TB program Height in cm','2017-01-26T19:40:15.607','2017-01-26T19:40:15.607',NULL,'TB program Height in cm',NULL,NULL,0,'lw1SqmMlnfh',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (35,'kzGKffQzuTp',NULL,'TB program Latitude','TB program Latitude','2017-01-26T19:40:15.610','2017-01-26T19:40:15.610',NULL,'TB program Latitude',NULL,NULL,0,'Qo571yj6Zcn',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (36,'SeTHbsPy5gH',NULL,'TB program Longitude','TB program Longitude','2017-01-26T19:40:15.612','2017-01-26T19:40:15.612',NULL,'TB program Longitude',NULL,NULL,0,'RG7uGl4w5Jq',0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (37,'VoW7cRhAP9T',NULL,'WHO RMNCH Tracker Unique ID','WHO RMNCH Tracker Unique ID','2017-05-22T22:30:55.379','2017-05-22T22:30:55.379',NULL,'WHO RMNCH Tracker Unique identifier',NULL,NULL,1,'lZGmxYbs97q',0,1,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (38,'s1i8imwtAqy',NULL,'WHO RMNCH Tracker First name','WHO RMNCH Tracker First name','2017-05-22T22:30:55.384','2017-05-22T22:30:55.384',NULL,'WHO RMNCH Tracker First name',NULL,NULL,1,'w75KJ2mc4zz',0,1,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (39,'DHqjJj8dHVE',NULL,'WHO RMNCH Tracker Last name','WHO RMNCH Tracker Last name','2017-05-22T22:30:55.387','2017-05-22T22:30:55.387',NULL,'WHO RMNCH Tracker Last name',NULL,NULL,1,'zDhUuAYrxNC',0,1,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (40,'HVFO5SnfSKP',NULL,'WHO RMNCH Tracker Address','WHO RMNCH Tracker Address','2017-05-22T22:30:55.389','2017-05-22T22:30:55.389',NULL,'WHO RMNCH Tracker Address',NULL,NULL,0,'VqEFza8wbwA',0,0,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (41,'au8a2AkgSkB',NULL,'WHO RMNCH Tracker Postal code','WHO RMNCH Tracker Postal code','2017-05-22T22:30:55.394','2017-05-22T22:30:55.394',NULL,'WHO RMNCH Tracker Postal code',NULL,NULL,0,'ZcBPrXKahq2',0,0,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (42,'ZO8AXsN4cZh',NULL,'WHO RMNCH Tracker City','WHO RMNCH Tracker City','2017-05-22T22:30:55.397','2017-05-22T22:30:55.397',NULL,'WHO RMNCH Tracker City',NULL,NULL,0,'FO4sWYJ64LQ',0,0,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (43,'XygbdsClyg5',NULL,'WHO RMNCH Tracker Mobile number','WHO RMNCH Tracker Mobile number','2017-05-22T22:30:55.399','2017-05-22T22:30:55.399',NULL,'WHO RMNCH Tracker Mobile number',NULL,NULL,0,'Agywv2JGwuq',0,1,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (44,'uAc2H7o9Y0z',NULL,'WHO RMNCH Tracker Email address','WHO RMNCH Tracker Email address','2017-05-22T22:30:55.401','2017-05-22T22:30:55.401',NULL,'WHO RMNCH Tracker Email address',NULL,NULL,0,'KmEUg2hHEtx',0,1,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (45,'TkzhnIQGFdV',NULL,'WHO RMNCH Tracker Birth date','WHO RMNCH Tracker Birth date','2017-05-22T22:30:55.404','2017-05-22T22:30:55.404',NULL,'WHO RMNCH Tracker Birth date',NULL,NULL,1,'gHGyrwKPzej',0,0,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramTrackedEntityAttribute` VALUES (46,'ItIljP9pyO2',NULL,'WHO RMNCH Tracker Civil status','WHO RMNCH Tracker Civil status','2017-05-22T22:30:55.406','2017-05-22T22:30:55.406',NULL,'WHO RMNCH Tracker Civil status',NULL,NULL,0,'ciq2USN94oJ',0,0,NULL,'WSGAb5XwJ3Y'); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -INSERT INTO `ProgramStageSectionProgramIndicatorLinkTable` VALUES (1,'d7ZILSbPgYh','x7PaHGvgWY2'); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `ProgramStageSection` VALUES (1,'d7ZILSbPgYh',NULL,'Patient details','Patient details','2015-03-31T11:44:17.363','2016-12-06T18:17:16.625',0,'Zj7UnCAulEk'); -INSERT INTO `ProgramStageSection` VALUES (2,'OeSqs7pkKqI',NULL,'Admission details','Admission details','2015-03-31T11:57:11.440','2016-12-06T18:17:16.634',1,'Zj7UnCAulEk'); -INSERT INTO `ProgramStageSection` VALUES (3,'dyPWAIyTII4',NULL,'Personal','Personal','2017-05-22T16:34:38.407','2017-05-22T16:34:38.407',0,'kO3z4Dhc038'); -INSERT INTO `ProgramStageSection` VALUES (4,'EzhVeTS7vx4',NULL,'Pre-existing conditions','Pre-existing conditions','2015-04-14T13:45:04.703','2017-05-22T22:27:13.278',1,'WZbXY0S00lP'); -INSERT INTO `ProgramStageSection` VALUES (5,'SyzhZewrUHP',NULL,'Current pregnancy','Current pregnancy','2014-06-11T16:18:19.000','2017-05-22T22:27:33.650',2,'WZbXY0S00lP'); -INSERT INTO `ProgramStageSection` VALUES (6,'AyWdV7K24Ih',NULL,'Lab/testing','Lab/testing','2014-06-11T16:18:19.000','2017-05-22T22:27:13.288',3,'WZbXY0S00lP'); -INSERT INTO `ProgramStageSection` VALUES (7,'tR4D0m1d5A5',NULL,'Management','Management','2015-01-15T14:25:41.161','2017-05-22T22:27:13.292',4,'WZbXY0S00lP'); -INSERT INTO `ProgramStageSection` VALUES (8,'bbjzL5gp0NZ',NULL,'Care at Birth','Care at Birth','2015-01-26T13:14:09.957','2015-10-14T13:37:29.904',0,'PFDfvmGpsR3'); -INSERT INTO `ProgramStageSection` VALUES (9,'ehgw1raICOm',NULL,'Current Visit','Current Visit','2015-01-26T13:43:48.083','2015-10-14T13:37:30.552',0,'bbKtnxRZKEP'); -INSERT INTO `ProgramStageSection` VALUES (10,'zp6Z3kiwzeP',NULL,'Lab','Lab','2015-01-26T13:46:02.599','2015-10-14T13:37:29.660',1,'bbKtnxRZKEP'); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `ProgramStageDataElement` VALUES (1,'eM6beRIqUnM',NULL,NULL,NULL,'2016-04-12T15:34:04.913','2016-04-12T15:34:04.913',0,0,0,0,0,'sWoqcoByYmD','dBwrot7S420','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (2,'ZD8pd21Dt4i',NULL,NULL,NULL,'2016-04-12T15:34:04.920','2016-04-12T15:34:04.920',0,0,0,1,0,'Ok9OQpitjQr','dBwrot7S420','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (3,'QgGD234oA8i',NULL,NULL,NULL,'2016-04-12T15:34:04.924','2016-04-12T15:34:04.924',0,0,0,2,0,'vANAXwtLwcT','dBwrot7S420','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (4,'LBNxoXdMnkv',NULL,NULL,NULL,'2015-03-31T09:53:05.015','2016-01-15T18:13:49.600',0,0,0,0,0,'a3kGcGDCuk6','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (5,'yYMGxXpfl0Z',NULL,NULL,NULL,'2015-08-07T14:46:19.073','2016-01-15T18:13:49.612',0,0,0,1,0,'H6uSAMO5WLD','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (6,'u2FvnCDCBcD',NULL,NULL,NULL,'2015-03-31T09:53:05.049','2016-01-15T18:13:49.621',0,0,0,2,0,'UXz7xuGCEhU','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (7,'XLFc6tTftb5',NULL,NULL,NULL,'2015-03-31T09:53:05.084','2016-01-15T18:13:49.625',0,0,0,3,0,'wQLfBvPrXqq','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (8,'p8eX3rSkKN0',NULL,NULL,NULL,'2015-03-31T09:53:05.109','2016-01-15T18:13:49.630',0,0,0,4,0,'bx6fsa0t90x','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (9,'O4dwFWakvGO',NULL,NULL,NULL,'2015-03-31T09:53:05.136','2016-01-15T18:13:49.635',0,0,0,5,0,'ebaJjqltK5N','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (10,'xtjAxBGQNNV',NULL,NULL,NULL,'2015-03-31T09:53:05.159','2016-01-15T18:13:49.638',0,0,0,6,0,'X8zyunlgUfM','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (11,'JYyXbTmBBls',NULL,NULL,NULL,'2016-01-15T18:13:49.641','2016-01-15T18:13:49.641',0,0,0,7,0,'uf3svrmp8Oj','A03MvHHogjR',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (12,'ztoQtbuXzsI',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.340',0,0,1,0,0,'GQY2lXrypjO','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (13,'vdc1saaN2ma',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.354',0,0,1,1,0,'X8zyunlgUfM','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (14,'Vpx18GqyLcK',NULL,NULL,NULL,'2015-08-06T13:42:22.491','2015-08-06T20:16:48.366',0,0,1,2,0,'FqlgKAG8HOu','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (15,'WlYechRHVo3',NULL,NULL,NULL,'2015-08-06T13:42:22.499','2015-08-06T20:16:48.376',0,0,1,3,0,'vTUhAUZFoys','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (16,'WucAVPYvcEO',NULL,NULL,NULL,'2015-08-06T13:42:22.504','2015-08-06T20:16:48.385',0,0,1,4,0,'rxBfISxXS2U','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (17,'EL5dr5x0WbZ',NULL,NULL,NULL,'2015-08-06T14:04:45.215','2015-08-06T20:16:48.394',0,0,0,5,0,'lNNb3truQoi','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (18,'IpPWDRlHJSe',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.402',0,0,1,6,0,'pOe0ogW4OWd','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (19,'xSTVGEIbarb',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.408',0,0,1,7,0,'HLmTEmupdX0','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (20,'YCO2FVT0wXL',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.416',0,0,1,8,0,'cYGaxwK615G','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (21,'VlOvjLKnoyw',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.423',0,0,1,9,0,'hDZbpskhqDd','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (22,'rqmcdr07fxQ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.433',0,0,0,10,0,'sj3j9Hwc7so','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (23,'LfgZNmadu4W',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.444',0,0,0,11,0,'aei1xRjSU2l','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (24,'sfYk4rKw18B',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.452',0,0,0,12,0,'BeynU4L6VCQ','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (25,'LiV2YoatDud',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-08-06T20:16:48.460',0,0,0,13,0,'OuJ6sgPyAbC','ZzYYXq4fJie',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (26,'pseYtz4Cv4Z',NULL,NULL,NULL,'2015-10-20T12:06:32.523','2015-10-20T12:06:32.523',1,0,0,0,0,'b6dOUjAarHD','aNLq9ZYoy9W',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (27,'k3UtueCsbPL',NULL,NULL,NULL,'2015-10-20T12:06:32.529','2015-10-20T12:06:32.529',1,0,0,1,0,'W7aC8jLASW8','aNLq9ZYoy9W',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (28,'jsXm1UDAdB5',NULL,NULL,NULL,'2015-10-20T12:06:32.533','2015-10-20T12:06:32.533',1,0,0,2,0,'fqnXmRYo5Cz','aNLq9ZYoy9W',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (29,'qXjCTdTXuPk',NULL,NULL,NULL,'2015-10-20T12:06:32.537','2015-10-20T12:06:32.537',1,0,0,3,0,'HrJmqlBqTFG','aNLq9ZYoy9W',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (30,'peDlV6C5Njn',NULL,NULL,NULL,'2015-10-20T12:06:32.540','2015-10-20T12:06:32.540',0,0,0,4,0,'Qz3kfeKgLgL','aNLq9ZYoy9W',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (31,'E59xi0fxhC6',NULL,NULL,NULL,'2015-10-20T12:06:32.544','2015-10-20T12:06:32.545',0,0,0,5,0,'UwCXONyUtGs','aNLq9ZYoy9W',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (32,'WDC4fnUaqph',NULL,NULL,NULL,'2015-10-20T12:06:32.548','2015-10-20T12:06:32.548',0,0,0,6,0,'HyJL2Lt37jN','aNLq9ZYoy9W',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (33,'apYCBRwEc44',NULL,NULL,NULL,'2015-03-31T09:54:21.819','2015-03-31T09:54:21.819',1,1,0,0,0,'f3Rn9XPEQuv','pSllsjpfLH2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (34,'OOGft1qHHnN',NULL,NULL,NULL,'2015-03-31T09:54:21.828','2015-03-31T09:54:21.829',1,1,0,1,0,'Dv7iIitX44Y','pSllsjpfLH2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (35,'ulVsVS36Zpm',NULL,NULL,NULL,'2015-03-31T09:54:21.839','2015-03-31T09:54:21.839',1,1,0,2,0,'UuL3eX8KJHY','pSllsjpfLH2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (36,'o5M0cNMVKY3',NULL,NULL,NULL,'2015-03-31T09:54:21.850','2015-03-31T09:54:21.850',0,1,0,3,0,'deQEw93Vr4j','pSllsjpfLH2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (37,'cLhp2K7tqAP',NULL,NULL,NULL,'2015-03-31T09:54:21.858','2015-03-31T09:54:21.859',0,1,0,4,0,'DvrjjquRrvF','pSllsjpfLH2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (38,'BAZe68syer0',NULL,NULL,NULL,'2015-03-31T09:54:21.868','2015-03-31T09:54:21.868',0,1,0,5,0,'lsJCUffec9h','pSllsjpfLH2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (39,'ZTVqbspTBTk',NULL,NULL,NULL,'2015-03-31T09:55:25.175','2016-12-06T18:17:16.343',0,0,0,0,0,'oZg33kd9taw','Zj7UnCAulEk','d7ZILSbPgYh'); -INSERT INTO `ProgramStageDataElement` VALUES (40,'MJnJYCPq377',NULL,NULL,NULL,'2015-08-09T16:00:51.128','2016-12-06T18:17:16.383',0,0,0,1,0,'SWfdB5lX0fk','Zj7UnCAulEk','d7ZILSbPgYh'); -INSERT INTO `ProgramStageDataElement` VALUES (41,'U7UQstNzMiI',NULL,NULL,NULL,'2015-03-31T09:55:25.154','2016-12-06T18:17:16.404',1,0,0,2,0,'qrur9Dvnyt5','Zj7UnCAulEk','d7ZILSbPgYh'); -INSERT INTO `ProgramStageDataElement` VALUES (42,'Nyjwu5GXSvV',NULL,NULL,NULL,'2015-03-31T10:31:18.830','2016-12-06T18:17:16.417',0,0,0,3,0,'GieVkTxp4HH','Zj7UnCAulEk','d7ZILSbPgYh'); -INSERT INTO `ProgramStageDataElement` VALUES (43,'bPlFJ7hAYs2',NULL,NULL,NULL,'2015-03-31T10:31:18.843','2016-12-06T18:17:16.431',0,0,0,4,0,'vV9UWAZohSf','Zj7UnCAulEk','d7ZILSbPgYh'); -INSERT INTO `ProgramStageDataElement` VALUES (44,'U5phA4vXbuu',NULL,NULL,NULL,'2015-03-31T09:55:25.195','2016-12-06T18:17:16.446',0,1,0,5,0,'eMyVanycQSC','Zj7UnCAulEk','OeSqs7pkKqI'); -INSERT INTO `ProgramStageDataElement` VALUES (45,'sLWaK95sqv1',NULL,NULL,NULL,'2015-03-31T09:55:25.215','2016-12-06T18:17:16.458',0,1,0,6,0,'msodh3rEMJa','Zj7UnCAulEk','OeSqs7pkKqI'); -INSERT INTO `ProgramStageDataElement` VALUES (46,'SPNGa73BhVI',NULL,NULL,NULL,'2016-10-11T18:34:29.520','2016-12-06T18:17:16.472',0,0,0,7,0,'S33cRBsnXPo','Zj7UnCAulEk','OeSqs7pkKqI'); -INSERT INTO `ProgramStageDataElement` VALUES (47,'m9sA2brtZ6g',NULL,NULL,NULL,'2015-03-31T09:55:25.233','2016-12-06T18:17:16.483',1,1,0,8,0,'fWIAEtYVEGk','Zj7UnCAulEk','OeSqs7pkKqI'); -INSERT INTO `ProgramStageDataElement` VALUES (48,'aBAx8ehHOdf',NULL,NULL,NULL,'2015-03-31T09:55:25.250','2016-12-06T18:17:16.495',1,1,0,9,0,'K6uUAvq500H','Zj7UnCAulEk','OeSqs7pkKqI'); -INSERT INTO `ProgramStageDataElement` VALUES (49,'Q6GdogoCHw0',NULL,NULL,NULL,'2016-01-15T18:14:08.644','2016-12-06T18:17:16.507',0,0,0,10,0,'ulD2zW0TIy2','Zj7UnCAulEk','OeSqs7pkKqI'); -INSERT INTO `ProgramStageDataElement` VALUES (50,'lSc08eDBP7e',NULL,NULL,NULL,'2016-12-06T18:17:16.519','2016-12-06T18:17:16.520',0,0,0,11,0,'F3ogKBuviRA','Zj7UnCAulEk',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (51,'d9wIqlzSMgE',NULL,NULL,NULL,'2016-04-01T15:07:12.695','2016-12-06T16:37:46.077',1,1,0,0,0,'qrur9Dvnyt5','pTo4uMt3xur',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (52,'FKHaErzkvEF',NULL,NULL,NULL,'2016-04-01T15:07:12.723','2016-12-06T16:37:46.104',1,1,0,1,0,'oZg33kd9taw','pTo4uMt3xur',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (53,'Zrem1VAqA8r',NULL,NULL,NULL,'2016-12-06T16:37:46.115','2016-12-06T16:37:46.116',0,0,0,2,0,'F3ogKBuviRA','pTo4uMt3xur',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (54,'HeeZMH31tvr',NULL,NULL,NULL,'2017-05-22T16:34:38.358','2017-05-22T18:37:40.673',0,1,0,0,0,'oZg33kd9taw','kO3z4Dhc038',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (55,'mCq2m9M6JQS',NULL,NULL,NULL,'2017-05-22T16:34:38.357','2017-05-22T18:37:40.667',0,0,0,2,0,'hKZh1et5n7v','kO3z4Dhc038',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (56,'Zm3ARjxYXm8',NULL,NULL,NULL,'2017-05-22T16:34:38.357','2017-05-22T18:37:40.671',0,0,0,3,0,'O7OiONht8T3','kO3z4Dhc038',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (57,'EQCf1l2Mdr8',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,0,0,'UXz7xuGCEhU','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (58,'muxw4SGzUwJ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,1,0,'utliJZmDeeC','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (59,'KWybjio9UZT',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,2,0,'KVQpGEjHluk','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (60,'ejm0g2hwHHc',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,3,0,'jkKCVlLRsFD','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (61,'yvV3txhSCyc',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,4,0,'SMo8UtuSF5p','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (62,'fzQrjBpbwQD',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,5,0,'XorIxxprsOp','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (63,'BbvkNf9PCxX',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,6,0,'DRGELgdyWk9','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (64,'MbdCfd4HaMQ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,7,0,'NALlPhMmMTQ','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (65,'SBn4XCFRbyT',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,8,0,'wpKRnvM14KO','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (66,'F0PZ4nZ86vo',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,9,0,'xjTklbpY6oG','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (67,'gFBRqVFh60H',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,10,0,'r0VOslrt2RP','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (68,'ljAoyjH4GYA',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,11,0,'gAbD3uDVHHh','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (69,'MAdsNY2gOlv',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,12,0,'lNNb3truQoi','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (70,'IpVUTCDdlGW',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,13,0,'sMspMpbvDYI','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (71,'psBtdqepNVM',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,14,0,'pB5sL7Ts4fb','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (72,'UzB6pZxZ2Rb',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,15,0,'EzMxXuVww2z','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (73,'FQZEMbBVabW',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,16,0,'OuJ6sgPyAbC','eaDHS084uMp',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (74,'m0lZFjCZ08n',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,1,0,0,0,'g9eOBujte1U','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (75,'pcdzQgqNzYP',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,1,0,'UXz7xuGCEhU','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (76,'YlZAiQqPeHO',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,2,0,'KVQpGEjHluk','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (77,'YnMUzDAphTt',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,3,0,'xjTklbpY6oG','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (78,'nccY8f4F1eA',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,4,0,'gAbD3uDVHHh','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (79,'ksXT6JnEPES',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,5,0,'lNNb3truQoi','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (80,'KngScvhxBX2',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,6,0,'EzMxXuVww2z','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (81,'BVLr48zsS93',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,7,0,'wpKRnvM14KO','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (82,'IkDSvw8mBAt',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,8,0,'NALlPhMmMTQ','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (83,'SBWpw6EpCxP',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,9,0,'XorIxxprsOp','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (84,'SviJxzvUUYI',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,10,0,'OuJ6sgPyAbC','grIfo3oOf4Y',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (85,'NFadPMdDxJW',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,0,0,'DRGELgdyWk9','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (86,'lRpE5yQbZw1',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,1,0,'XorIxxprsOp','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (87,'EW1Cy41FZZt',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,2,0,'fIy3fOtkbdS','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (88,'NTYyBdQ7Hh5',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,1,0,3,0,'uxRgo9bGWhX','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (89,'Lpn8Qfkpb1O',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,4,0,'gvrK6CxWTcp','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (90,'f0VLYFLGvir',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,5,0,'jkKCVlLRsFD','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (91,'LusCbQBnuOJ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,6,0,'SMo8UtuSF5p','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (92,'DC6iORIoIX3',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,7,0,'NALlPhMmMTQ','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (93,'ixo44itSBxt',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,8,0,'Rbv6wcblbxe','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (94,'X55rKErRarA',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,9,0,'PuakB9BOtIV','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (95,'FFcDgBjcot2',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',NULL,0,0,10,0,'tLn2UVJJ9kO','Xgk8Wvl0jHr',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (96,'JpROjiTg8b3',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,0,0,'DBFcMGod0Wy','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (97,'YaSVuthoSsk',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,1,0,'thO0LN2i2OJ','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (98,'aw8V8I72bIm',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,2,0,'DWcWXE0xO2b','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (99,'qSFlJONC58W',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,3,0,'UXz7xuGCEhU','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (100,'aBP0GFi4Xwy',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,4,0,'jkKCVlLRsFD','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (101,'SfkOR89XOOF',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,5,0,'SMo8UtuSF5p','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (102,'UZ3pj5bbrMv',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,6,0,'EzMxXuVww2z','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (103,'A9kkpVDBFTn',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,7,0,'HLmTEmupdX0','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (104,'xOjJrGq5A4d',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,8,0,'ihOp58eRcG3','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (105,'W49VoPPaIbc',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,9,0,'L9G6ZtxbfjG','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (106,'nOaElgsPkH5',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,10,0,'OuJ6sgPyAbC','oRySG82BKE6',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (107,'xwYIobDLdqi',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,0,0,'qpQinIDQ6Uy','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (108,'mUHdk51SqTq',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,1,0,'zNXca47AaTh','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (109,'dx6CT1WClL9',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,2,0,'fQMBEt42CSl','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (110,'FulbqM9KWqS',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,3,0,'PfSefJQpg5g','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (111,'hSJ0TyWkyrF',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,4,0,'f2MduVqwPXO','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (112,'N73tJpnCk4O',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,5,0,'GXNUsigphqK','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (113,'UzrKKYEv3Ro',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,6,0,'ROEGWNaasDP','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (114,'nw8pj4oOY86',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,7,0,'Lh9x3J6EF0g','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (115,'hAFY8wNVrXA',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,8,0,'BLNHqFdGFRv','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (116,'hKcCWh8PWXL',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,9,0,'Y35b9mKPwgz','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (117,'tHEkPtszkaL',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,10,0,'CtpjtJOlix1','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (118,'xUKPOSVf2xj',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,11,0,'Kdj9bEhmtER','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (119,'TZ5yPQdMuKg',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,12,0,'bTWjEduOv4P','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (120,'GDpn4SY6zUP',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,13,0,'qlzHqClWAsG','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (121,'Jns1RtRwm2q',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,14,0,'D795f7Ftl5Z','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (122,'dnfoo7btZ3K',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,15,0,'msiehvzdkh0','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (123,'kM2ugI3YrcZ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,16,0,'qv3Ivgr7qA8','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (124,'fnEAA95SVtE',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,17,0,'OjGY9phCVkF','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (125,'zeczWhj79Pn',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,18,0,'hFbuuBkjut3','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (126,'WW9MnXW2XXT',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,19,0,'kSDiqFhUP8P','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (127,'ZhrqleJFoMB',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,20,0,'zJer0XIW5fV','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (128,'NFyx6Io5BXf',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,21,0,'zF6StgsGthD','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (129,'azteNYm4GwP',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,22,0,'DgluqT5CbIp','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (130,'Hkuzvp53S0e',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,23,0,'OKN6ZG1z7pq','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (131,'eS8RJTSkXbO',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,24,0,'ZpvFqxRhFuP','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (132,'xkFCVTDqgCq',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,25,0,'Q6vysZzUoPl','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (133,'BAvoFqwaPMF',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,26,0,'ogBU5CfbAUZ','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (134,'lU6R2U98oTy',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,27,0,'z8Ay2GaaqpC','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (135,'EMwL8rl8wJy',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,28,0,'lJSMLN5WRDF','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (136,'HKwZkS2FWh7',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,29,0,'dGdEEpNb7GW','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (137,'Ss4zxke5h1S',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,30,0,'uHkibfGqtXg','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (138,'V3cj8DUJ6xM',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,31,0,'HpC2iqyoMR8','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (139,'QFQP9oBbb1H',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,32,0,'fgPOFbi37BM','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (140,'Fax5ZzjAn8D',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,33,0,'VDxTE7l7sc7','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (141,'D0iScNbG4aa',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,34,0,'Ws36Dp6gHA1','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (142,'OSM7mCrTuOZ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,35,0,'KRJeVOPBy6t','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (143,'LOTmQwQlMRO',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,36,0,'IgkWhfPryqt','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (144,'IoFdSnX1IjY',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,37,0,'Q5725FPinzH','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (145,'fqtlHG5EzFl',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,38,0,'ihgI4dDwUQT','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (146,'UOsO6G7s9rJ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,39,0,'AVC7oJYrZrk','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (147,'iZjHoDmf37i',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,40,0,'WMhpzP6czRF','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (148,'HnI9cLn7Mlz',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,41,0,'ZhGKg3ssbmX','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (149,'KI7fMLC3X5s',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,42,0,'UoRMWhj2YIy','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (150,'mk08KKnbjFk',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,43,0,'pharIEKZNo0','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (151,'BMWs8ymMHnj',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,44,0,'IZSvH4lOb1h','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (152,'srPYYGCX2ge',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,45,0,'DcsUXIcK8IJ','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (153,'qkNkFFRRWiJ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,46,0,'rxTX7yNs8Ph','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (154,'YaY5uWVxmwk',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,47,0,'ypvDEOvkjTx','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (155,'iqiiu4v5IFY',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,48,0,'SayYGlKyPCa','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (156,'sd2pXMDGYfi',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,49,0,'ASvofuem7Oa','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (157,'YbewRRHkkgW',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,50,0,'M3H9NEMuBix','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (158,'dKE85LYxIlw',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,51,0,'hca8vQ6jEST','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (159,'YnGlzJglzHx',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,52,0,'SKh80FGIVKI','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (160,'xnIgb7vcg2z',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,53,0,'MUOpAoXRVX9','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (161,'v1tzHhfh5oU',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,54,0,'bCBiRLqLjQl','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (162,'vcNoiXiQSs1',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,55,0,'vsKP6aojcqL','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (163,'FUcfx2JCVqZ',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,56,0,'njV5usO9oNl','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (164,'Pgj5K0pbNQl',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,57,0,'t9NU3SqPvcN','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (165,'k4OrSBc0nnd',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,58,0,'zff1i2Iwk8S','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (166,'dr53EvNkLBX',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,59,0,'PKBFrGgUy26','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (167,'gEQqD3ocd7b',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,60,0,'pWpQ69deqiv','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (168,'J7ylCvdC3E0',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,61,0,'QKujt9JlJfn','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (169,'StkABAf5B6s',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,62,0,'JSovKG6FZNW','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (170,'VQgGl5tYodI',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,63,0,'cOXBak6pilm','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (171,'lS4IJhaGzuj',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,64,0,'wqH05wytdJH','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (172,'kMbrVQvz4E8',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,65,0,'yqiAt2vL2Oe','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (173,'nwCCbGcnJ3A',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,66,0,'Ef3ueStqxJj','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (174,'mnDZ79PgMAa',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,67,0,'gtYt3KpQpW8','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (175,'cSJkPYaosr9',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,68,0,'suMqFd2seuA','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (176,'xaNxIT4LINX',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,69,0,'GFDKf2idXLV','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (177,'Cn6Pbktr4bl',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,70,0,'e4EMaGSEyV9','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (178,'B0tujBctFmI',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,71,0,'Mnkodq2wzlV','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (179,'F02lfaz8VWp',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,72,0,'LDEqL9GokCM','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (180,'CdNetDekNqn',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,73,0,'uYrt6Rjh0q2','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (181,'fsS1l7nolRo',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2015-03-27T16:27:19.000',0,0,0,74,0,'lsPerCow7QG','lST1OZ5BDJ2',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (182,'qR2egL2KtTM',NULL,NULL,NULL,'2016-06-28T13:31:51.241','2016-06-28T13:32:28.098',1,0,0,0,0,'Vk1tzSQxvOR','EPEcjy3FWmI',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (183,'HrG7IqvQTD2',NULL,NULL,NULL,'2016-06-28T13:31:51.249','2016-06-28T13:32:28.104',1,0,0,1,0,'fCXKBdc27Bt','EPEcjy3FWmI',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (184,'arbdqOvEnzX',NULL,NULL,NULL,'2016-06-28T13:31:51.255','2016-06-28T13:32:28.111',1,0,0,2,0,'lJTx9EZ1dk1','EPEcjy3FWmI',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (185,'SaQx4xuiZmK',NULL,NULL,NULL,'2016-06-28T13:31:51.265','2016-06-28T13:32:28.123',1,0,0,3,0,'fTZFU8cWvb3','EPEcjy3FWmI',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (186,'B8QMTAvNsxo',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2016-08-03T23:44:30.643',1,1,0,0,0,'D7m8vpzxHDJ','ZkbAXlQUYJG',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (187,'JLAHBFusdG9',NULL,NULL,NULL,'2015-03-27T16:27:19.000','2016-08-03T23:44:30.650',1,1,0,1,0,'HmkXnHJxcD1','ZkbAXlQUYJG',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (188,'jTZ6zYHeHKF',NULL,NULL,NULL,'2016-08-03T18:16:57.292','2016-08-03T23:44:30.656',0,0,0,2,0,'lpHeSOA8GUV','ZkbAXlQUYJG',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (189,'c0OuJrOpVH3',NULL,NULL,NULL,'2016-08-03T18:32:16.084','2016-08-03T23:44:30.663',0,0,0,3,0,'vAzDOljIN1o','ZkbAXlQUYJG',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (190,'KrKLhQjL9pE',NULL,NULL,NULL,'2016-08-03T22:56:17.380','2016-08-03T23:44:30.669',0,0,0,4,0,'zJbnrm3kUAk','ZkbAXlQUYJG',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (191,'ScqGrQzkwIk',NULL,NULL,NULL,'2016-08-03T22:56:17.389','2016-08-03T23:44:30.675',0,0,0,5,0,'P6hgV2tSIvi','ZkbAXlQUYJG',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (192,'n8M9233hN1r',NULL,NULL,NULL,'2016-08-03T22:56:17.397','2016-08-03T23:44:30.682',0,0,0,6,0,'U5ubm6PPYrM','ZkbAXlQUYJG',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (193,'bAsS6lOFzuC',NULL,NULL,NULL,'2016-06-28T12:56:59.849','2016-06-28T13:32:34.791',1,1,0,0,0,'yLIPuJHRgey','jdRD35YwbRH',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (194,'rdOzDJuEnHf',NULL,NULL,NULL,'2016-06-28T12:56:59.858','2016-06-28T13:32:34.801',1,1,0,1,0,'zocHNQIQBIN','jdRD35YwbRH',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (195,'tDb3kAS2den',NULL,NULL,NULL,'2015-05-05T19:58:52.420','2015-10-14T14:16:39.316',0,0,0,0,0,'mrVkW9h2Rdp','PUZaKR0Jh2k',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (196,'dcHGCS0QH13',NULL,NULL,NULL,'2015-05-05T19:58:52.436','2015-10-14T14:16:39.321',0,0,0,1,0,'W4zW3aPyS0G','PUZaKR0Jh2k',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (197,'obvi08Ai3oc',NULL,NULL,NULL,'2015-05-06T05:28:29.380','2015-10-14T14:16:39.325',0,0,0,2,0,'iwNXUX6KYX0','PUZaKR0Jh2k',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (198,'B4wvzM3LjKK',NULL,NULL,NULL,'2015-05-06T05:28:29.386','2015-10-14T14:16:39.330',0,0,0,3,0,'wqpUVEeJR3D','PUZaKR0Jh2k',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (199,'YbQZc0y95le',NULL,NULL,NULL,'2015-05-11T12:05:58.671','2015-10-14T14:16:39.334',0,0,0,4,0,'suhLG4CrzUw','PUZaKR0Jh2k',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (200,'EGWCwGM96dT',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.933',0,0,0,0,0,'OhcR0fpFcWa','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (201,'uyyj97BeMmE',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.944',0,0,0,1,0,'cKBSkBB3Mt4','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (202,'gIy1U1aff97',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.952',0,0,0,2,0,'nhW3SZX9JaN','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (203,'wCqqrBfHYqJ',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.959',0,0,0,3,0,'PKZPVfAJfHD','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (204,'HUXFO64Cxza',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.967',0,0,0,4,0,'Itl05OEupgQ','WZbXY0S00lP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (205,'r84tSFsFYAy',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.975',0,0,0,5,1,'YKXci7Sm0Zq','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (206,'wLKvNV5UIoy',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.982',0,0,0,6,0,'MHW5v2Iljtw','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (207,'WDFqsG1jfNa',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.989',0,0,0,7,0,'r3BqzOPxAjp','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (208,'snQr1L0E7XX',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:12.996',0,0,0,8,0,'dyYdfamSY2Z','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (209,'nfMHqASCtJU',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.003',0,0,0,9,0,'w7enwqzx90I','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (210,'yhhImS7SoZg',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.010',0,0,0,10,0,'rHgrmXfa57b','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (211,'C4saFfl0uvE',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.017',0,0,0,11,0,'EyfTU3ibMmJ','WZbXY0S00lP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (212,'E7oqZxeNntZ',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.026',0,0,0,12,0,'vPdXnmGWzfy','WZbXY0S00lP','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (213,'viNxXA7PMRI',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.032',0,0,0,13,0,'X8HbdaoS9LN','WZbXY0S00lP','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (214,'cOGgqOgPoa7',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.039',0,0,0,14,0,'vANAXwtLwcT','WZbXY0S00lP','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (215,'gRZhkHc5Q3X',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.046',0,0,0,15,0,'w4ky6EkVahL','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (216,'Fm7kU34UcS2',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.052',0,0,0,16,0,'OSuxnldV4Ug','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (217,'Alu9Hhx5OyH',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.059',0,0,0,17,0,'PN6HcGjTraL','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (218,'ts1hInlK4LC',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.066',0,0,0,18,0,'dpiyZz8bkVE','WZbXY0S00lP','AyWdV7K24Ih'); -INSERT INTO `ProgramStageDataElement` VALUES (219,'txhGsGd1tZo',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.073',0,0,0,19,0,'a7XjFEuZuKE','WZbXY0S00lP','AyWdV7K24Ih'); -INSERT INTO `ProgramStageDataElement` VALUES (220,'EpMis6Hs6Uh',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.081',0,0,0,20,0,'vTEkiy8F3yj','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (221,'uZgK8dBdegT',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.088',0,0,0,21,0,'AAaJGnWR5js','WZbXY0S00lP','AyWdV7K24Ih'); -INSERT INTO `ProgramStageDataElement` VALUES (222,'pVApaCHxicy',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.095',0,0,0,22,0,'ytV9rX4ADnn','WZbXY0S00lP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (223,'D6rlep2HmGn',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.102',0,0,0,23,0,'Ok9OQpitjQr','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (224,'XK5MZLqNYe6',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.109',0,0,0,24,0,'sWoqcoByYmD','WZbXY0S00lP','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (225,'mVXfCxpPnsD',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.116',0,0,0,25,0,'M4HEOoEFTAT','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (226,'usK0EWtT4ln',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.124',0,0,0,26,0,'lcaG1Pnh27I','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (227,'BPvfe7tRXZZ',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.132',0,0,0,27,1,'DecmCMPDPdS','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (228,'Z2r7zcBDunt',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.139',0,0,0,28,0,'RxVNLSeTjto','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (229,'CQB9BBwSgG4',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.146',0,0,0,29,0,'nB4Ui3ckmUi','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (230,'WjeYpwukcGl',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.154',0,0,0,30,0,'Kb6kZzUCJi1','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (231,'HEKMmkrBAxU',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.162',0,0,0,31,0,'jRo4KlnCKeX','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (232,'jMn5XBOJ9l1',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.169',0,0,0,32,0,'Js57E09s9fh','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (233,'VS27fOegoW9',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.181',0,0,0,33,0,'QFX1FLWBwtq','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (234,'xi2hglccXlY',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.188',0,0,0,34,0,'E6QaDtrQP5e','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (235,'BNQVUtlcdy2',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.195',0,0,0,35,0,'dpOtt7HUQXa','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (236,'DWNC8PpEE5G',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.201',0,0,0,36,0,'VSmOcdK3v7y','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (237,'gEIbDsHxOvu',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.206',0,0,0,37,0,'ZbDPeYzWsh2','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (238,'EE9dM2yMZzV',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.212',0,0,0,38,0,'zk4Eui7Jhtr','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (239,'nulj70bzXLU',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.218',0,0,0,39,0,'de0FEHSIoxh','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (240,'MCx53bBHc7y',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.225',0,0,0,40,0,'UQ2Zo8CruPB','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (241,'TqR5PFLjlk2',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.230',0,0,0,41,0,'zzGNbeMnTd6','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (242,'R0L1DFWHhdi',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.236',0,0,0,42,0,'Q1x1HIhuwFN','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (243,'MKj2FBg9K7K',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.242',0,0,0,43,0,'VFffa31SKjH','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (244,'gVTQvk0dMy1',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.247',0,0,0,44,0,'sdchiIXIcCf','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (245,'I4tnUL6tfNO',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.252',0,0,0,45,0,'xPTngRLQTnu','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (246,'jBH4SrtbyWm',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:27:13.258',0,0,0,46,0,'Mh7nK8UKoZP','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (247,'sMmmcf2nW5A',NULL,NULL,NULL,'2015-04-14T13:49:23.370','2017-05-22T22:27:13.263',0,0,0,47,0,'fNnOPQj83jz','WZbXY0S00lP','EzhVeTS7vx4'); -INSERT INTO `ProgramStageDataElement` VALUES (248,'pLvFWjUMOY4',NULL,NULL,NULL,'2015-05-11T13:37:45.902','2017-05-22T22:27:13.268',0,0,0,48,0,'NPZPVg2rVh4','WZbXY0S00lP','tR4D0m1d5A5'); -INSERT INTO `ProgramStageDataElement` VALUES (249,'aHYF0TyPIZA',NULL,NULL,NULL,'2017-05-22T22:27:13.273','2017-05-22T22:27:13.273',0,0,0,49,0,'roKuXYfw1BW','WZbXY0S00lP','SyzhZewrUHP'); -INSERT INTO `ProgramStageDataElement` VALUES (250,'DJCHTdDelIK',NULL,NULL,NULL,'2017-05-22T22:28:29.209','2017-05-22T22:28:29.209',0,0,0,0,0,'roKuXYfw1BW','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (251,'HW86hPvYRZN',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.215',0,0,0,1,0,'cKBSkBB3Mt4','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (252,'l1DJsq4qOwM',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.221',0,0,0,2,0,'nhW3SZX9JaN','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (253,'IRsTmN0AONT',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.226',0,0,0,3,1,'YKXci7Sm0Zq','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (254,'QSceQsNAv9V',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.230',0,0,0,4,0,'dyYdfamSY2Z','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (255,'Bs5KDWDjjo5',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.235',0,0,0,5,0,'w7enwqzx90I','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (256,'pYMc8xnQhRw',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.240',0,0,0,6,0,'QM5d0hfSbKk','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (257,'tAjQ4MMW5H7',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.244',0,0,0,7,0,'DCUDZxqOxUo','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (258,'X1VqPtgJhHT',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.249',0,0,0,8,0,'rHgrmXfa57b','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (259,'WqHqx8th7hC',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.254',0,0,0,9,0,'vPdXnmGWzfy','edqlbukwRfQ','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (260,'ZxncPcaW0qq',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.258',0,0,0,10,0,'X8HbdaoS9LN','edqlbukwRfQ','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (261,'HYYeO2vx7iT',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.263',0,0,0,11,0,'vANAXwtLwcT','edqlbukwRfQ','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (262,'BaRCakwPE70',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.267',0,0,0,12,0,'OSuxnldV4Ug','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (263,'jeqh8WPtQcw',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.272',0,0,0,13,0,'SeXllT5ypsh','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (264,'ukMuRM2fOzH',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.277',0,0,0,14,0,'PN6HcGjTraL','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (265,'MOL7AZMjVp2',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.281',0,0,0,15,0,'dpiyZz8bkVE','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (266,'FkjJGE8fJ6L',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.286',0,0,0,16,0,'a7XjFEuZuKE','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (267,'KR5IVMphmVB',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.291',0,0,0,17,0,'vTEkiy8F3yj','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (268,'z9AcKFA3aqp',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.296',0,0,0,18,0,'lcaG1Pnh27I','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (269,'FaIUlqus0xE',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.300',0,0,0,19,1,'DecmCMPDPdS','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (270,'TmaKQrm88n4',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.305',0,0,0,20,0,'ytV9rX4ADnn','edqlbukwRfQ','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (271,'i7qI8b3bFP4',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2017-05-22T22:28:29.309',0,0,0,21,0,'EyfTU3ibMmJ','edqlbukwRfQ','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (272,'sNq30q2ypFn',NULL,NULL,NULL,'2015-04-21T09:34:58.374','2017-05-22T22:28:29.314',0,0,0,22,0,'yTDoF5b1OhI','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (273,'VYKYP94XNe8',NULL,NULL,NULL,'2015-05-08T09:35:42.267','2017-05-22T22:28:29.318',0,0,0,23,0,'M4HEOoEFTAT','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (274,'Gl3fprbsx0E',NULL,NULL,NULL,'2015-05-08T09:48:31.495','2017-05-22T22:28:29.323',0,0,0,24,0,'w4ky6EkVahL','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (275,'Eu1xF9EGpxD',NULL,NULL,NULL,'2015-05-11T13:37:55.445','2017-05-22T22:28:29.329',0,0,0,25,0,'NPZPVg2rVh4','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (276,'v0kCIHDCHE3',NULL,NULL,NULL,'2015-05-12T08:10:26.182','2017-05-22T22:28:29.336',0,0,0,26,0,'Itl05OEupgQ','edqlbukwRfQ','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (277,'pqnP3LPnIr2',NULL,NULL,NULL,'2015-05-12T08:17:18.499','2017-05-22T22:28:29.341',0,0,0,27,0,'AAaJGnWR5js','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (278,'lMBnUb2rHsF',NULL,NULL,NULL,'2015-05-12T08:20:29.501','2017-05-22T22:28:29.348',0,0,0,28,0,'sWoqcoByYmD','edqlbukwRfQ','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (279,'bWLoaGsMKl7',NULL,NULL,NULL,'2015-05-12T08:20:29.510','2017-05-22T22:28:29.354',0,0,0,29,0,'Ok9OQpitjQr','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (280,'fklsmqPKgwe',NULL,NULL,NULL,'2015-05-12T08:21:24.162','2017-05-22T22:28:29.359',0,0,0,30,0,'OhcR0fpFcWa','edqlbukwRfQ',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (281,'NGYm5B8yW2S',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.682',0,0,0,0,0,'OhcR0fpFcWa','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (282,'LrTftNnowE7',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.687',0,0,0,1,0,'ez86AhQ5cqp','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (283,'QOp0PWLeWak',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.690',0,0,0,2,0,'L6Toy2TrHHq','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (284,'mNXtw47lMLW',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.694',0,0,0,3,0,'Itl05OEupgQ','PFDfvmGpsR3','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (285,'qVo72Oe3Jb5',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.698',0,0,0,4,0,'SojR4V7A8u2','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (286,'Sz3LLc7WoUL',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.703',0,0,0,5,0,'ALfOm7aaH6b','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (287,'Va8xtfuPX1u',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.707',0,0,0,6,0,'Mfq2Y9N21KZ','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (288,'zjxvVN18Qus',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.711',0,0,0,7,0,'mGHBXrtqSut','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (289,'IWrTFi5pWRy',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.715',0,0,0,8,0,'klEz81wXFoU','PFDfvmGpsR3','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (290,'jQCTAPgN8HX',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.719',0,0,0,9,0,'z8m3llJYuh9','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (291,'De4ZlZy7TbF',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.723',0,0,0,10,0,'MH33VLmOOqm','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (292,'Te4Z5287Osc',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.727',0,0,0,11,0,'spkG704sTh6','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (293,'PlnFiS1txNO',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.730',0,0,0,12,0,'EyfTU3ibMmJ','PFDfvmGpsR3','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (294,'yXzfUiuZZXI',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.734',0,0,0,13,0,'u7aAPS8OgLw','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (295,'eqfd3ASkxGV',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.738',0,0,0,14,0,'vPdXnmGWzfy','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (296,'BI9O9GsAFaV',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.742',0,0,0,15,0,'X8HbdaoS9LN','PFDfvmGpsR3','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (297,'RjJHxMrB9Zh',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.746',0,0,0,16,0,'vANAXwtLwcT','PFDfvmGpsR3','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (298,'Dr2gJS1nbjf',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.750',0,0,0,17,0,'pwfdgeE21Os','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (299,'qVXGGtpjEgh',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.753',0,0,0,18,0,'yq1qT0NdjYQ','PFDfvmGpsR3','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (300,'CZDO9iZsrjv',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.757',0,0,0,19,0,'D1EHM01p454','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (301,'R82I03NlKhp',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.761',0,0,0,20,0,'MVIV2RGWhUq','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (302,'oftZsLgbDAR',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.765',0,0,0,21,0,'oQgcj7kV1c3','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (303,'Q9u1AXydfjX',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.769',0,0,0,22,0,'FIHEeJwfhZH','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (304,'YoDCayjt4EN',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.774',0,0,0,23,0,'i9mEM7ZW7yV','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (305,'FV20iGAiBp4',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.778',0,0,0,24,0,'PQlndpI05Bb','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (306,'wRs9Fa01zGf',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.782',0,0,0,25,0,'YsVHgzQCwmr','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (307,'L17JpU6EPHU',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.787',0,0,0,26,0,'FYLMjPQ0wmo','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (308,'tChBdOVHz8D',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.791',0,0,0,27,0,'BmaBjPQX8ME','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (309,'BpUCdOZJLz1',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.796',0,0,0,28,0,'HUfKCOou7de','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (310,'zOEy7uhyDGz',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.800',0,0,0,29,0,'VXdfPQRXKiA','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (311,'irTn0Agjzz2',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.804',0,0,0,30,0,'V5PR8Kw8ZnC','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (312,'LvCgtg7ZYnx',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.808',0,0,0,31,0,'Spl22QJsWeu','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (313,'vvYxuplCyfx',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.812',0,0,0,32,0,'PCiOYWXZq2E','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (314,'MDdA7Ltc1BL',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.816',0,0,0,33,0,'AXuzjgLsBy3','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (315,'pbQrNUaPT2Z',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.819',0,0,0,34,0,'sWoqcoByYmD','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (316,'pyD3sW0qBQl',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.823',0,0,0,35,0,'sUX4i7QqbXF','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (317,'dD6eLjDmjwY',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.827',0,0,0,36,0,'m3XQrgadVK9','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (318,'rJYL0ogcG8H',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.832',0,0,0,37,0,'cz5DN6BVVeW','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (319,'uJH275XsxoM',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.835',0,0,0,38,0,'csl3yq5UC46','PFDfvmGpsR3',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (320,'ISufoESNnZ3',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:27.839',0,0,0,39,0,'hib4oz2sOLw','PFDfvmGpsR3','bbjzL5gp0NZ'); -INSERT INTO `ProgramStageDataElement` VALUES (321,'NAeZLv0sQNw',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:34.993',0,0,0,0,0,'OhcR0fpFcWa','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (322,'omYUT2r57dh',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:34.996',0,0,0,1,0,'nhW3SZX9JaN','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (323,'OzlOswS0P4F',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.000',0,0,0,2,0,'ez86AhQ5cqp','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (324,'Vj0mzNfgncu',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.003',0,0,0,3,0,'L6Toy2TrHHq','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (325,'wGAMuZZZtfu',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.007',0,0,0,4,0,'B3bDhNpCcEM','bbKtnxRZKEP','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (326,'LvinSJ4w30o',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.010',0,0,0,5,0,'Itl05OEupgQ','bbKtnxRZKEP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (327,'mukAiCUQpTO',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.013',0,0,0,6,0,'klEz81wXFoU','bbKtnxRZKEP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (328,'HOTIOcDeaQS',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.017',0,0,0,7,0,'cwgQnkamM2j','bbKtnxRZKEP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (329,'KI32oTvVZPg',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.020',0,0,0,8,0,'EyfTU3ibMmJ','bbKtnxRZKEP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (330,'lVbzuDXNRXs',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.024',0,0,0,9,0,'X8HbdaoS9LN','bbKtnxRZKEP','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (331,'pMfbyP2mH2B',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.027',0,0,0,10,0,'vANAXwtLwcT','bbKtnxRZKEP','zp6Z3kiwzeP'); -INSERT INTO `ProgramStageDataElement` VALUES (332,'vl2yI6b4Emi',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.030',0,0,0,11,0,'pwfdgeE21Os','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (333,'jZzfyTaPbko',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.033',0,0,0,12,0,'yq1qT0NdjYQ','bbKtnxRZKEP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (334,'ZYB0zBZVCQA',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.036',0,0,0,13,0,'FYLMjPQ0wmo','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (335,'DgbaQ7wNmxr',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.041',0,0,0,14,0,'u3TE34T4KH0','bbKtnxRZKEP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (336,'Lmpt0hBXIhf',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.044',0,0,0,15,0,'QWVRukwa83h','bbKtnxRZKEP','ehgw1raICOm'); -INSERT INTO `ProgramStageDataElement` VALUES (337,'e0xQEZiEH9e',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.048',0,0,0,16,0,'Spl22QJsWeu','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (338,'QAA6eujW5fw',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.051',0,0,0,17,0,'AXuzjgLsBy3','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (339,'Zod1gcshp16',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.054',0,0,0,18,0,'csl3yq5UC46','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (340,'s4huGaXqaEd',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.057',0,0,0,19,0,'Kb6kZzUCJi1','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (341,'RZ2HVWc3QWb',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.060',0,0,0,20,0,'RxVNLSeTjto','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (342,'yUK6Pa8nUdP',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.063',0,0,0,21,0,'nB4Ui3ckmUi','bbKtnxRZKEP',NULL); -INSERT INTO `ProgramStageDataElement` VALUES (343,'jvO0NkFnTQS',NULL,NULL,NULL,'2015-04-10T08:26:10.000','2015-10-14T14:17:35.067',0,0,0,22,0,'ytV9rX4ADnn','bbKtnxRZKEP','ehgw1raICOm'); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `ProgramStage` VALUES (1,'dBwrot7S420',NULL,'Antenatal care visit - Program rules demo','Antenatal care visit - Program rules demo','2016-04-12T15:30:43.806','2016-04-12T15:34:04.929','Visit date',0,1,NULL,0,0,0,'DEFAULT',0,0,1,1,0,1,0,NULL,'lxAQ7Zs9VYR'); -INSERT INTO `ProgramStage` VALUES (2,'A03MvHHogjR',NULL,'Birth','Birth','2013-03-04T11:41:07.541','2016-10-11T10:32:53.527','Report date',0,0,NULL,0,0,0,'DEFAULT',0,0,0,1,0,0,0,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramStage` VALUES (3,'ZzYYXq4fJie',NULL,'Baby Postnatal','Baby Postnatal','2013-03-04T11:41:07.541','2015-08-06T20:16:48.321',NULL,0,0,NULL,0,0,0,'DEFAULT',0,0,1,2,0,0,6,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramStage` VALUES (4,'aNLq9ZYoy9W',NULL,'Contraceptives Voucher Program','Contraceptives Voucher Program','2015-10-20T12:05:27.388','2015-10-20T12:06:32.515','Report date',0,0,NULL,0,0,0,'DEFAULT',0,0,1,1,0,0,0,NULL,'kla3mAPgvCH'); -INSERT INTO `ProgramStage` VALUES (5,'pSllsjpfLH2',NULL,'Information Campaign','Information Campaign','2014-06-22T13:28:24.042','2015-03-31T09:54:21.808',NULL,0,0,NULL,0,0,1,'CUSTOM',0,0,1,1,0,0,0,NULL,'q04UBOqq3rp'); -INSERT INTO `ProgramStage` VALUES (6,'Zj7UnCAulEk',NULL,'Inpatient morbidity and mortality','Inpatient morbidity and mortality','2013-02-07T14:12:20.493','2016-12-06T18:17:16.640','Report date',0,0,NULL,0,0,1,'SECTION',0,0,1,1,0,0,0,NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramStage` VALUES (7,'pTo4uMt3xur',NULL,'Malaria case registration','Malaria case registration','2016-03-30T20:18:31.146','2016-12-06T16:37:46.128','Report date',0,0,NULL,0,0,1,'DEFAULT',0,0,1,1,0,0,0,NULL,'VBqh0ynB2wv'); -INSERT INTO `ProgramStage` VALUES (8,'kO3z4Dhc038',NULL,'Malaria testing and surveillance','Malaria testing and surveillance','2017-05-22T16:34:38.357','2017-05-22T18:37:40.643',NULL,0,0,NULL,0,0,0,'SECTION',1,0,1,1,0,0,0,NULL,'bMcwwoVnbSR'); -INSERT INTO `ProgramStage` VALUES (9,'eaDHS084uMp',NULL,'ANC 1st visit','ANC 1st visit','2013-03-04T11:41:07.541','2013-04-10T12:15:02.041',NULL,0,0,'false',0,0,0,'DEFAULT',0,0,1,1,0,0,0,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramStage` VALUES (10,'grIfo3oOf4Y',NULL,'ANC Visit (2-4+)','ANC Visit (2-4+)','2013-03-04T11:41:07.541','2013-04-09T22:39:20.903',NULL,0,0,'false',0,0,0,'DEFAULT',1,0,1,2,0,0,90,30,'uy2gU8kT1jF'); -INSERT INTO `ProgramStage` VALUES (11,'Xgk8Wvl0jHr',NULL,'Delivery','Delivery','2013-03-04T11:41:07.541','2013-04-09T22:39:20.905',NULL,0,0,'false',0,0,0,'DEFAULT',1,0,1,3,0,0,280,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramStage` VALUES (12,'oRySG82BKE6',NULL,'PNC Visit','PNC Visit','2013-03-04T11:41:07.541','2013-04-09T22:39:20.907',NULL,0,0,'false',0,0,0,'DEFAULT',1,0,1,4,0,0,290,0,'uy2gU8kT1jF'); -INSERT INTO `ProgramStage` VALUES (13,'lST1OZ5BDJ2',NULL,'Provider Follow-up and Support Tool','Provider Follow-up and Support Tool','2014-04-25T15:14:18.890','2015-02-18T15:15:49.554',NULL,0,0,'indicentDate',1,0,0,'CUSTOM',0,0,1,1,0,0,0,NULL,'fDd25txQckK'); -INSERT INTO `ProgramStage` VALUES (14,'EPEcjy3FWmI',NULL,'Lab monitoring','Lab monitoring','2016-06-28T13:31:51.224','2016-06-28T13:32:28.127','Report date',0,0,NULL,0,1,0,'DEFAULT',0,0,0,1,0,0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramStage` VALUES (15,'ZkbAXlQUYJG',NULL,'TB visit','TB visit','2013-03-04T11:41:07.541','2016-08-03T23:44:30.685','TB visit date',0,0,NULL,0,0,1,'DEFAULT',0,0,1,2,0,0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramStage` VALUES (16,'jdRD35YwbRH',NULL,'Sputum smear microscopy test','Sputum smear microscopy test','2016-06-28T12:56:59.838','2016-06-28T13:32:34.805','Report date',0,0,NULL,0,1,0,'DEFAULT',0,0,0,3,0,0,0,NULL,'ur1Edk5Oe2n'); -INSERT INTO `ProgramStage` VALUES (17,'PUZaKR0Jh2k',NULL,'Previous deliveries','Previous deliveries','2015-05-05T19:58:52.389','2017-01-20T12:01:59.097','Date of birth',0,0,NULL,0,0,0,'DEFAULT',1,0,0,1,0,0,0,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramStage` VALUES (18,'WZbXY0S00lP',NULL,'First antenatal care visit','First antenatal care visit','2014-06-06T21:03:17.121','2017-05-22T22:27:13.296','Date of visit',1,0,'enrollmentDate',1,0,0,'SECTION',0,0,1,2,0,1,0,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramStage` VALUES (19,'edqlbukwRfQ',NULL,'Antenatal care visit','Antenatal care visit','2014-06-07T13:49:55.011','2017-05-22T22:28:29.362','Date of visit',0,0,NULL,0,1,0,'DEFAULT',1,0,0,3,0,1,56,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramStage` VALUES (20,'PFDfvmGpsR3',NULL,'Care at birth','Care at birth','2014-11-25T14:38:47.961','2017-01-20T12:01:59.103','Date of visit',0,0,NULL,0,0,0,'SECTION',0,0,0,4,0,0,280,NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramStage` VALUES (21,'bbKtnxRZKEP',NULL,'Postpartum care visit','Postpartum care visit','2014-11-25T15:24:56.927','2017-01-20T12:01:59.105','Date of visit',0,0,NULL,0,0,0,'SECTION',1,0,0,5,0,0,290,NULL,'WSGAb5XwJ3Y'); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `ProgramRuleVariable` VALUES (1,'omrL0gtPpDL',NULL,'hemoglobin','hemoglobin','2016-04-12T15:57:18.645','2017-05-23T00:29:24.356',NULL,'lxAQ7Zs9VYR',NULL,'vANAXwtLwcT',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (2,'Z92dJO9gIje',NULL,'womanSmoking','womanSmoking','2016-04-12T15:55:02.406','2017-05-23T00:29:24.368',NULL,'lxAQ7Zs9VYR',NULL,'sWoqcoByYmD',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (3,'g2GooOydipB',NULL,'apgarscore','apgarscore','2015-08-07T18:41:55.152','2017-05-23T00:29:24.345',NULL,'IpHINAT79UW',NULL,'a3kGcGDCuk6',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (4,'aKpfPKSRQnv',NULL,'apgarcomment','apgarcomment','2015-09-14T21:17:40.956','2017-05-23T00:29:24.345',NULL,'IpHINAT79UW',NULL,'H6uSAMO5WLD',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (5,'RycV5uDi66i',NULL,'age','age','2015-08-07T18:38:12.931','2017-05-23T00:29:24.343',NULL,'eBAyeGv0exc',NULL,'qrur9Dvnyt5',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (6,'zINGRka3g9N',NULL,'gender','gender','2015-08-09T16:01:44.829','2017-05-23T00:29:24.355',NULL,'eBAyeGv0exc',NULL,'oZg33kd9taw',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (7,'varonrw1032',NULL,'othermedicineallergy','othermedicineallergy','2015-10-15T14:48:31.068','2017-05-23T00:29:24.361',NULL,'WSGAb5XwJ3Y',NULL,'VSmOcdK3v7y',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (8,'idLCptBEOF9',NULL,'renaldisease','renaldisease','2015-10-15T11:51:27.871','2017-05-23T00:29:24.366',NULL,'WSGAb5XwJ3Y',NULL,'sdchiIXIcCf',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (9,'iGBDXK1Gbcb',NULL,'plurality','plurality','2015-10-15T11:51:27.755','2017-05-23T00:29:24.366',NULL,'WSGAb5XwJ3Y',NULL,'PN6HcGjTraL',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (10,'AI6kVYSFacb',NULL,'penicillinAllergy','penicillinAllergy','2017-05-22T14:51:59.639','2017-05-23T00:29:24.365',NULL,'WSGAb5XwJ3Y',NULL,'E6QaDtrQP5e',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (11,'varonrw1026',NULL,'allergies','allergies','2015-10-15T11:55:30.069','2017-05-23T00:29:24.344',NULL,'WSGAb5XwJ3Y',NULL,'QFX1FLWBwtq',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (12,'pJ79JBmuFT4',NULL,'autoimmunedisease','autoimmunedisease','2015-10-15T11:51:27.981','2017-05-23T00:29:24.346',NULL,'WSGAb5XwJ3Y',NULL,'zzGNbeMnTd6',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (13,'YnREl4QOKFB',NULL,'smoking','smoking','2015-10-15T11:37:03.631','2017-05-23T00:29:24.367',NULL,'WSGAb5XwJ3Y',NULL,'sWoqcoByYmD',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (14,'varonrw1030',NULL,'othersevereallergyexists','othersevereallergyexists','2015-10-15T14:48:17.342','2017-05-23T00:29:24.364',NULL,'WSGAb5XwJ3Y',NULL,'ZbDPeYzWsh2',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (15,'yrhN4QM8gqg',NULL,'lmp','lmp','2015-10-15T15:38:07.853','2017-05-23T00:29:24.358',NULL,'WSGAb5XwJ3Y',NULL,'w4ky6EkVahL',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (16,'WS8wNA4Jvev',NULL,'diabetes','diabetes','2015-10-15T11:51:28.036','2017-05-23T00:29:24.352',NULL,'WSGAb5XwJ3Y',NULL,'Q1x1HIhuwFN',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (17,'varonrw1027',NULL,'chronicconditions','chronicconditions','2015-10-15T14:48:06.276','2017-05-23T00:29:24.349',NULL,'WSGAb5XwJ3Y',NULL,'de0FEHSIoxh',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (18,'Jx93QwiIP1B',NULL,'lastName','lastName','2016-04-26T20:01:57.945','2017-05-23T00:29:24.357',NULL,'WSGAb5XwJ3Y',NULL,NULL,'zDhUuAYrxNC','TEI_ATTRIBUTE'); -INSERT INTO `ProgramRuleVariable` VALUES (19,'OnXTZg6lPA6',NULL,'streetAddress','streetAddress','2016-04-26T19:48:57.268','2017-05-23T00:29:24.367',NULL,'WSGAb5XwJ3Y',NULL,NULL,'VqEFza8wbwA','TEI_ATTRIBUTE'); -INSERT INTO `ProgramRuleVariable` VALUES (20,'varonrw1029',NULL,'othermedicineallergyexists','othermedicineallergyexists','2015-10-15T14:48:15.446','2017-05-23T00:29:24.362',NULL,'WSGAb5XwJ3Y',NULL,'dpOtt7HUQXa',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (21,'AU9n351Zwno',NULL,'firstName','firstName','2016-04-26T20:01:57.098','2017-05-23T00:29:24.354',NULL,'WSGAb5XwJ3Y',NULL,NULL,'w75KJ2mc4zz','TEI_ATTRIBUTE'); -INSERT INTO `ProgramRuleVariable` VALUES (22,'k8QP8SWkQtA',NULL,'chronichypertension','chronichypertension','2015-10-15T11:51:27.928','2017-05-23T00:29:24.350',NULL,'WSGAb5XwJ3Y',NULL,'UQ2Zo8CruPB',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (23,'VY8KZyr8d2d',NULL,'mobile','mobile','2016-04-26T20:04:06.875','2017-05-23T00:29:24.359',NULL,'WSGAb5XwJ3Y',NULL,NULL,'Agywv2JGwuq','TEI_ATTRIBUTE'); -INSERT INTO `ProgramRuleVariable` VALUES (24,'varonrw1028',NULL,'otherchronicconditionexists','otherchronicconditionexists','2015-10-15T14:48:12.885','2017-05-23T00:29:24.360',NULL,'WSGAb5XwJ3Y',NULL,'xPTngRLQTnu',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (25,'varonrw1033',NULL,'othersevereallergy','othersevereallergy','2015-10-15T14:48:26.711','2017-05-23T00:29:24.363',NULL,'WSGAb5XwJ3Y',NULL,'zk4Eui7Jhtr',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (26,'varonrw1031',NULL,'otherchroniccondition','otherchroniccondition','2015-10-15T14:48:21.838','2017-05-23T00:29:24.360',NULL,'WSGAb5XwJ3Y',NULL,'Mh7nK8UKoZP',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (27,'WuSvlMvjeu9',NULL,'born','born','2015-10-15T15:12:57.544','2017-05-23T00:29:24.348',NULL,'WSGAb5XwJ3Y',NULL,NULL,'gHGyrwKPzej','TEI_ATTRIBUTE'); -INSERT INTO `ProgramRuleVariable` VALUES (28,'dVU6XcAVtpw',NULL,'currentProgranancyOutcome','currentProgranancyOutcome','2017-01-20T13:24:14.797','2017-05-23T00:29:24.351',0,'WSGAb5XwJ3Y','PFDfvmGpsR3','V5PR8Kw8ZnC',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM_STAGE'); -INSERT INTO `ProgramRuleVariable` VALUES (29,'d1XWbV9mlle',NULL,'duedateclinical','duedateclinical','2015-10-15T15:38:07.905','2017-05-23T00:29:24.353',NULL,'WSGAb5XwJ3Y',NULL,'YKXci7Sm0Zq',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -INSERT INTO `ProgramRuleVariable` VALUES (30,'XJ3gR8WFYP1',NULL,'diastolicbloodpressure','diastolicbloodpressure','2015-10-15T11:51:27.818','2017-05-23T00:29:24.352',NULL,'WSGAb5XwJ3Y',NULL,'dyYdfamSY2Z',NULL,'DATAELEMENT_NEWEST_EVENT_PROGRAM'); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `ProgramRuleAction` VALUES (1,'UUwZWS8uirn',NULL,NULL,NULL,'2016-04-12T15:58:55.041','2017-05-23T00:29:24.454',NULL,'The hemoglobin value cannot be above 99',NULL,NULL,NULL,NULL,'SHOWERROR',NULL,'vANAXwtLwcT','dahuKlP7jR2'); -INSERT INTO `ProgramRuleAction` VALUES (2,'hwgyO59SSxu',NULL,NULL,NULL,'2016-04-12T15:55:03.082','2017-05-23T00:29:24.455',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'Ok9OQpitjQr','xOe5qCzRS0Y'); -INSERT INTO `ProgramRuleAction` VALUES (3,'suS9GnraCx1',NULL,NULL,NULL,'2016-04-12T15:57:19.288','2017-05-23T00:29:24.455',NULL,'Hemoglobin value lower than normal',NULL,NULL,NULL,NULL,'SHOWWARNING',NULL,'vANAXwtLwcT','GC4gpdoSD4r'); -INSERT INTO `ProgramRuleAction` VALUES (4,'v434s5YPDcP',NULL,NULL,NULL,'2015-09-14T21:17:41.033','2017-05-23T00:29:24.467',NULL,'It is suggested that an explanation is provided when the Apgar score is below 4',NULL,NULL,NULL,NULL,'SHOWWARNING',NULL,'H6uSAMO5WLD','NAgjOfWMXg6'); -INSERT INTO `ProgramRuleAction` VALUES (5,'t944GaMzNbs',NULL,NULL,NULL,'2015-09-14T22:20:33.543','2017-05-23T00:29:24.466',NULL,'If the apgar score is below zero, an explanation must be provided.',NULL,NULL,NULL,NULL,'SHOWERROR',NULL,'a3kGcGDCuk6','tTPMkizzUZg'); -INSERT INTO `ProgramRuleAction` VALUES (6,'iwGAWKvStTt',NULL,NULL,NULL,'2015-08-07T18:41:55.210','2017-05-23T00:29:24.468',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'H6uSAMO5WLD','ppdTpuQC7Q5'); -INSERT INTO `ProgramRuleAction` VALUES (7,'IrmpncBsypT',NULL,NULL,NULL,'2015-08-09T16:01:44.913','2017-05-23T00:29:24.468',NULL,NULL,NULL,NULL,NULL,'d7ZILSbPgYh','HIDEFIELD',NULL,'SWfdB5lX0fk','fd3wL1quxGb'); -INSERT INTO `ProgramRuleAction` VALUES (8,'yRqMFO2T3eb',NULL,NULL,NULL,'2017-05-22T15:16:38.633','2017-05-23T00:29:24.448','#{othermedicineallergy}','Medicine allergy: ','feedback',NULL,NULL,NULL,'DISPLAYTEXT',NULL,NULL,'OfWLsxH5ylF'); -INSERT INTO `ProgramRuleAction` VALUES (9,'hLOEPUPseEv',NULL,NULL,NULL,'2015-10-15T11:37:03.694','2017-05-23T00:29:24.466',NULL,'Smoking cessation counselling field is blanked, because the woman is no longer a registered smoker.',NULL,NULL,NULL,'EzhVeTS7vx4','HIDEFIELD',NULL,'Ok9OQpitjQr','tO1D62oB0tq'); -INSERT INTO `ProgramRuleAction` VALUES (10,'actonrw1065',NULL,NULL,NULL,'2015-10-15T14:50:23.572','2017-05-23T00:29:24.460',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'VSmOcdK3v7y','ruleonr1065'); -INSERT INTO `ProgramRuleAction` VALUES (11,'jlchLk7spuu',NULL,NULL,NULL,'2017-05-22T14:54:50.067','2017-05-23T00:29:24.449',NULL,'Penicillin allergy','feedback',NULL,NULL,NULL,'DISPLAYTEXT',NULL,NULL,'atg8LQkfZpd'); -INSERT INTO `ProgramRuleAction` VALUES (12,'nI9mPOEvHXU',NULL,NULL,NULL,'2016-04-26T19:48:57.928','2017-05-23T00:32:15.478',NULL,'Please enter a street name followed by a number',NULL,'VqEFza8wbwA',NULL,'EzhVeTS7vx4','SHOWWARNING',NULL,NULL,'jZ6TKNCRhdt'); -INSERT INTO `ProgramRuleAction` VALUES (13,'kwvLf4fwVOz',NULL,NULL,NULL,'2015-10-15T11:51:28.088','2017-05-23T00:29:24.465',NULL,'The field for treatment with acetylcalecylic acid was blanked, because the patient is no longer eligable for this treatment according to the guidelines.',NULL,NULL,NULL,'EzhVeTS7vx4','HIDEFIELD',NULL,'OSuxnldV4Ug','HTKIQDVMu0K'); -INSERT INTO `ProgramRuleAction` VALUES (14,'hQuM6JLPOuD',NULL,NULL,NULL,'2017-01-20T13:29:16.262','2017-05-23T00:29:24.452',NULL,NULL,NULL,NULL,NULL,'EzhVeTS7vx4','HIDEPROGRAMSTAGE','bbKtnxRZKEP',NULL,'xOm49QX4Nsc'); -INSERT INTO `ProgramRuleAction` VALUES (15,'oWFO8OtGZDX',NULL,NULL,NULL,'2017-05-22T14:03:02.387','2017-05-23T00:29:24.451','d2:weeksBetween(#{lmp},V{event_date})',NULL,NULL,NULL,NULL,NULL,'ASSIGN',NULL,'roKuXYfw1BW','KRMEVVbex0q'); -INSERT INTO `ProgramRuleAction` VALUES (16,'actonrw1066',NULL,NULL,NULL,'2015-10-15T14:50:19.520','2017-05-23T00:29:24.461',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'zk4Eui7Jhtr','ruleonr1066'); -INSERT INTO `ProgramRuleAction` VALUES (17,'actonrw1060',NULL,NULL,NULL,'2015-10-15T14:49:25.559','2017-05-23T00:29:24.463',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'xPTngRLQTnu','ruleonr1055'); -INSERT INTO `ProgramRuleAction` VALUES (18,'actonrw1059',NULL,NULL,NULL,'2015-10-15T14:49:25.711','2017-05-23T00:29:24.462',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'sdchiIXIcCf','ruleonr1055'); -INSERT INTO `ProgramRuleAction` VALUES (19,'actonrw1058',NULL,NULL,NULL,'2015-10-15T14:49:25.253','2017-05-23T00:29:24.463',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'VFffa31SKjH','ruleonr1055'); -INSERT INTO `ProgramRuleAction` VALUES (20,'actonrw1057',NULL,NULL,NULL,'2015-10-15T14:49:25.128','2017-05-23T00:29:24.464',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'Q1x1HIhuwFN','ruleonr1055'); -INSERT INTO `ProgramRuleAction` VALUES (21,'actonrw1056',NULL,NULL,NULL,'2015-10-15T14:49:24.799','2017-05-23T00:29:24.464',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'zzGNbeMnTd6','ruleonr1055'); -INSERT INTO `ProgramRuleAction` VALUES (22,'actonrw1055',NULL,NULL,NULL,'2015-10-15T14:49:19.714','2017-05-23T00:29:24.465',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'UQ2Zo8CruPB','ruleonr1055'); -INSERT INTO `ProgramRuleAction` VALUES (23,'actonrw1061',NULL,NULL,NULL,'2015-10-15T14:50:23.354','2017-05-23T00:29:24.461',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'Mh7nK8UKoZP','ruleonr1061'); -INSERT INTO `ProgramRuleAction` VALUES (24,'yKMX3B7kqbg',NULL,NULL,NULL,'2015-10-15T15:47:11.270','2017-05-23T00:29:24.456',NULL,'LMP date entered is after the date of the antenatal care visit.',NULL,NULL,NULL,'EzhVeTS7vx4','SHOWERROR',NULL,'w4ky6EkVahL','hpO8g3CRAeC'); -INSERT INTO `ProgramRuleAction` VALUES (25,'vBtnt6XvYXO',NULL,NULL,NULL,'2016-04-26T20:04:07.485','2017-05-23T00:32:43.648',NULL,'Valid mobile number can not contain 555',NULL,'Agywv2JGwuq',NULL,NULL,'SHOWWARNING',NULL,NULL,'IdrDtQmRGrv'); -INSERT INTO `ProgramRuleAction` VALUES (26,'tAiSv1t9qpL',NULL,NULL,NULL,'2015-10-15T15:38:07.996','2017-05-23T00:29:24.457',NULL,'The clinically estimated due date is less than 250 days after LMP date',NULL,NULL,NULL,'EzhVeTS7vx4','SHOWWARNING',NULL,'YKXci7Sm0Zq','NkpU28ZlfVh'); -INSERT INTO `ProgramRuleAction` VALUES (27,'PBSFvWH2j4K',NULL,NULL,NULL,'2015-10-15T15:38:07.950','2017-05-23T00:29:24.457',NULL,'The LMP date entered is less than 250 days before the clinically estimated due date.',NULL,NULL,NULL,'EzhVeTS7vx4','SHOWWARNING',NULL,'w4ky6EkVahL','NkpU28ZlfVh'); -INSERT INTO `ProgramRuleAction` VALUES (28,'cZPGCpHkl7x',NULL,NULL,NULL,'2017-05-22T14:36:55.617','2017-05-23T00:29:24.450','d2:concatenate(d2:weeksBetween(#{lmp}, V{current_date}), ''+'', d2:modulus(d2:daysBetween(#{lmp}, V{current_date}), 7))','Gest. age','indicators',NULL,NULL,NULL,'DISPLAYKEYVALUEPAIR',NULL,NULL,'zPHL03IEWvD'); -INSERT INTO `ProgramRuleAction` VALUES (29,'FBn9BggFMPK',NULL,NULL,NULL,'2015-10-15T15:12:57.588','2017-05-23T00:32:32.496','d2:yearsBetween(A{born},V{current_date})','The womans age is outside the normal range. With the birthdate entered, the age would be:',NULL,'gHGyrwKPzej',NULL,'EzhVeTS7vx4','SHOWWARNING',NULL,NULL,'RtCIjfyRB9L'); -INSERT INTO `ProgramRuleAction` VALUES (30,'actonrw1064',NULL,NULL,NULL,'2015-10-15T14:50:23.923','2017-05-23T00:29:24.459',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'ZbDPeYzWsh2','ruleonr1062'); -INSERT INTO `ProgramRuleAction` VALUES (31,'actonrw1063',NULL,NULL,NULL,'2015-10-15T14:50:24.046','2017-05-23T00:29:24.458',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'dpOtt7HUQXa','ruleonr1062'); -INSERT INTO `ProgramRuleAction` VALUES (32,'actonrw1062',NULL,NULL,NULL,'2015-10-15T14:50:23.793','2017-05-23T00:29:24.459',NULL,NULL,NULL,NULL,NULL,NULL,'HIDEFIELD',NULL,'E6QaDtrQP5e','ruleonr1062'); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `ProgramRule` VALUES (1,'dahuKlP7jR2',NULL,'Show error for high hemoglobin value','Show error for high hemoglobin value','2016-04-12T15:58:54.797','2017-05-23T00:29:24.535',NULL,'#{hemoglobin} > 99','lxAQ7Zs9VYR',NULL); -INSERT INTO `ProgramRule` VALUES (2,'xOe5qCzRS0Y',NULL,'Hide smoking cessation councelling','Hide smoking cessation councelling','2016-04-12T15:55:02.043','2017-05-23T00:29:24.533',NULL,'!#{womanSmoking} ','lxAQ7Zs9VYR',NULL); -INSERT INTO `ProgramRule` VALUES (3,'GC4gpdoSD4r',NULL,'Hemoglobin warning','Hemoglobin warning','2016-04-12T15:57:18.356','2017-05-23T00:29:24.528',NULL,'#{hemoglobin} < 9','lxAQ7Zs9VYR',NULL); -INSERT INTO `ProgramRule` VALUES (4,'NAgjOfWMXg6',NULL,'Ask for comment for low apgar','Ask for comment for low apgar','2015-09-14T21:17:40.841','2017-05-23T00:29:24.523',NULL,'#{apgarscore} >= 0 && #{apgarscore} < 4 && #{apgarcomment} == ''''','IpHINAT79UW',NULL); -INSERT INTO `ProgramRule` VALUES (5,'tTPMkizzUZg',NULL,'Demand comment if apgar is under zero','Demand comment if apgar is under zero','2015-09-14T22:20:33.429','2017-05-23T00:29:24.528',NULL,'#{apgarscore} <0 && #{apgarcomment} == ''''','IpHINAT79UW',NULL); -INSERT INTO `ProgramRule` VALUES (6,'ppdTpuQC7Q5',NULL,'Hide Apgar comment if score > 7','Hide Apgar comment if score > 7','2015-08-07T18:41:55.082','2017-05-23T00:29:24.529',NULL,'#{apgarscore} > 7','IpHINAT79UW',NULL); -INSERT INTO `ProgramRule` VALUES (7,'fd3wL1quxGb',NULL,'Hide pregnant if gender is male','Hide pregnant if gender is male','2015-08-09T16:01:44.705','2017-05-23T00:29:24.533',NULL,'#{gender} == ''Male''','eBAyeGv0exc',NULL); -INSERT INTO `ProgramRule` VALUES (8,'OfWLsxH5ylF',NULL,'Show feedback if the woman is registered with medicine allergy','Show feedback if the woman is registered with medicine allergy','2017-05-22T15:16:38.636','2017-05-23T00:29:24.535',NULL,'#{othermedicineallergyexists} == ''Yes''','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (9,'tO1D62oB0tq',NULL,'Hide smoking cessation if not smoking','Hide smoking cessation if not smoking','2015-10-15T11:37:03.560','2017-05-23T00:29:24.534',NULL,'!#{smoking}','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (10,'ruleonr1065',NULL,'Hide fields to specify other medicine allergy if a','Hide fields to specify other medicine allergy if a','2015-10-15T14:50:05.966','2017-05-23T00:29:24.531',NULL,'#{othermedicineallergyexists} !== ''Yes''','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (11,'atg8LQkfZpd',NULL,'Show feedback if woman is registered with penicillin allergy','Show feedback if woman is registered with penicillin allergy','2017-05-22T14:54:50.070','2017-05-23T00:29:24.536',NULL,'#{penicillinAllergy} == ''Yes''','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (12,'jZ6TKNCRhdt',NULL,'Check that address is on valid format','Check that address is on valid format','2016-04-26T19:48:56.752','2017-05-23T00:32:15.482',NULL,'d2:hasValue(''streetAddress'') && !d2:validatePattern(A{streetAddress},''[\\w ]+ \\d+'')','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (13,'HTKIQDVMu0K',NULL,'Hide field for treatment of aspirin','Hide field for treatment of aspirin','2015-10-15T11:51:27.694','2017-05-23T00:29:24.530',NULL,'(#{plurality} === ''Singleton'' || #{plurality} ===''Not assessed'' || #{plurality} === '''') && (#{diastolicbloodpressure} <= 90) && !#{renaldisease} && !#{chronichypertension} && !#{autoimmunedisease} && !#{diabetes}','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (14,'xOm49QX4Nsc',NULL,'Hide postpartum followup','Hide postpartum followup','2017-01-20T13:29:16.163','2017-05-23T00:29:24.532',NULL,'#{currentProgranancyOutcome} != ''Live birth''','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (15,'KRMEVVbex0q',NULL,'Calculate gestational age from LMP','Calculate gestational age from LMP','2017-05-22T13:56:07.799','2017-05-23T00:29:24.524',1,'d2:hasValue(''lmp'')','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (16,'ruleonr1066',NULL,'Hide fields to specify other severe allergy if ans','Hide fields to specify other severe allergy if ans','2015-10-15T14:50:12.216','2017-05-23T00:29:24.531',NULL,'#{othersevereallergyexists} !== ''Yes''','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (17,'ruleonr1055',NULL,'Hide all fields for chronic conitions unless the w','Hide all fields for chronic conitions unless the w','2015-10-15T14:49:10.503','2017-05-23T00:29:24.529',NULL,'!#{chronicconditions}','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (18,'ruleonr1061',NULL,'Hide field for -other chronic conditions specified','Hide field for -other chronic conditions specified','2015-10-15T14:49:42.990','2017-05-23T00:29:24.530',NULL,'!#{otherchronicconditionexists}','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (19,'hpO8g3CRAeC',NULL,'Check that LMP date given is before event date','Check that LMP date given is before event date','2015-10-15T15:47:11.224','2017-05-23T00:29:24.527',NULL,'d2:hasValue(''lmp'') && d2:daysBetween(#{lmp},V{event_date}) <= 0','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (20,'IdrDtQmRGrv',NULL,'Check mobile number','Check mobile number','2016-04-26T20:04:06.608','2017-05-23T00:32:43.652',NULL,'d2:validatePattern(A{mobile} ,''.*555.*'')','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (21,'NkpU28ZlfVh',NULL,'Check that clinical estimate of due is aligned with LMP date','Check that clinical estimate of due is aligned with LMP date','2015-10-15T15:38:07.796','2017-05-23T00:29:24.526',NULL,'d2:hasValue(''lmp'') && d2:hasValue(''duedateclinical'') && (d2:daysBetween(#{lmp},#{duedateclinical}) < 250) ','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (22,'zPHL03IEWvD',NULL,'Show current gestational age (w+d)','Show current gestational age (w+d)','2017-05-22T14:31:40.239','2017-05-23T00:29:24.534',NULL,'!d2:hasValue(''currentProgranancyOutcome'') && d2:hasValue(''lmp'') && d2:weeksBetween(#{lmp},V{current_date}) < 50','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (23,'RtCIjfyRB9L',NULL,'Check that birthdate is within usual range in registration','Check that birthdate is within usual range in registration','2015-10-15T15:12:57.494','2017-05-23T00:32:32.498',NULL,'(d2:yearsBetween(A{born},V{current_date}) < 12) || (d2:yearsBetween(A{born},V{current_date}) > 50)','WSGAb5XwJ3Y',NULL); -INSERT INTO `ProgramRule` VALUES (24,'ruleonr1062',NULL,'Hide fields to specyfy allergies unless the woman ','Hide fields to specyfy allergies unless the woman ','2015-10-15T14:49:49.616','2017-05-23T00:29:24.532',NULL,'#{allergies} !== ''Yes''','WSGAb5XwJ3Y',NULL); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -INSERT INTO `ProgramIndicator` VALUES (1,'rXoaHGAXWy9',NULL,'Health immunization score','Health immunization score','2015-10-20T11:26:19.631','2015-10-20T11:26:19.631','Health immunization score','Health immunization score','Sum of BCG doses, measles doses and yellow fever doses. If Apgar score over or equal to 2, multiply by 2.','Sum of BCG doses, measles doses and yellow fever doses. If Apgar score over or equal to 2, multiply by 2.',0,'(#{A03MvHHogjR.bx6fsa0t90x} + #{A03MvHHogjR.FqlgKAG8HOu} + #{A03MvHHogjR.rxBfISxXS2U}) * d2:condition(''#{A03MvHHogjR.a3kGcGDCuk6} >= 2'',1,2)','rXoaHGAXWy9',NULL,2,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (2,'GxdhnY5wmHq',NULL,'Average weight','Average weight','2015-09-14T20:25:55.543','2015-12-13T12:50:25.642','Average weight','Average weight',NULL,NULL,1,'(#{A03MvHHogjR.UXz7xuGCEhU}+#{ZzYYXq4fJie.GQY2lXrypjO})/V{value_count}','GxdhnY5wmHq','V{value_count}>0',NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (3,'Do41GSbf762','YELLOW_FEVER_DOSE','Yellow fever doses','Yellow fever doses','2017-03-13T21:48:02.535','2017-03-13T22:40:22.827','Yellow fever doses','Yellow fever doses',NULL,NULL,0,'#{ZzYYXq4fJie.rxBfISxXS2U}','Do41GSbf762',NULL,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (4,'fM7RZGVndZE',NULL,'Measles + Yellow fever doses','Measles + Yellow fever doses','2015-08-06T22:48:42.650','2015-08-09T21:42:06.928','Measles + Yellow fever doses','Measles + Yellow fever doses',NULL,NULL,1,'#{ZzYYXq4fJie.FqlgKAG8HOu} + #{ZzYYXq4fJie.rxBfISxXS2U}','fM7RZGVndZE',NULL,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (5,'p2Zxg0wcPQ3','BCG_DOSE','BCG doses','BCG doses','2015-08-06T22:25:14.645','2017-03-13T22:39:59.146','BCG doses','BCG doses',NULL,NULL,0,'#{A03MvHHogjR.bx6fsa0t90x}','p2Zxg0wcPQ3',NULL,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (6,'eo73fim1b2i',NULL,'Measles + Yellow fever doses female','Measles + Yellow fever doses female','2015-08-07T19:04:29.117','2015-08-07T19:04:29.117','Measles + Yellow fever doses female','Measles + Yellow fever doses female',NULL,NULL,0,'#{ZzYYXq4fJie.FqlgKAG8HOu} + #{ZzYYXq4fJie.rxBfISxXS2U}','eo73fim1b2i','A{cejWyOfXge6} == ''Female''',NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (7,'tt54DiKuQ9c',NULL,'Measles + Yellow fever doses low infant weight','Measles + Yellow fever doses low infant weight','2015-08-06T22:49:20.128','2015-08-06T22:51:19.787','Measles + Yellow fever doses low infant weight','Measles + Yellow fever doses low infant weight',NULL,NULL,0,'#{ZzYYXq4fJie.FqlgKAG8HOu} + #{ZzYYXq4fJie.rxBfISxXS2U}','tt54DiKuQ9c','#{ZzYYXq4fJie.GQY2lXrypjO} < 2700',NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (8,'qhTkqwAJLMv',NULL,'Weight gain(in g) between birth and last postnatal','Weight gain(in g) between birth and last postnatal','2017-01-20T10:32:26.388','2017-01-20T10:32:26.388','Weight gain(g)','Weight gain(g)','The average number of grams the baby has gained through the postnatal period. Only counted among the babies that has completed the postnatal period.','The average number of grams the baby has gained through the postnatal period. Only counted among the babies that has completed the postnatal period.',0,'#{ZzYYXq4fJie.GQY2lXrypjO} - #{A03MvHHogjR.UXz7xuGCEhU}','qhTkqwAJLMv','#{ZzYYXq4fJie.GQY2lXrypjO} != 0 && #{A03MvHHogjR.UXz7xuGCEhU} != 0 && V{enrollment_status} == ''COMPLETED''',NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (9,'hCYU0G5Ti2T',NULL,'BCG doses low birth weight','BCG doses low birth weight','2015-08-06T22:35:40.391','2015-08-06T22:35:40.391','BCG doses low birth weight','BCG doses low birth weight',NULL,NULL,0,'#{A03MvHHogjR.bx6fsa0t90x}','hCYU0G5Ti2T','#{A03MvHHogjR.UXz7xuGCEhU} < 2700',NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (10,'XfYhemMQWiI','MEASLES_DOSE','Measles doses','Measles doses','2017-03-13T21:32:58.586','2017-03-13T22:40:10.368','Measles doses','Measles doses',NULL,NULL,0,'#{ZzYYXq4fJie.FqlgKAG8HOu}','XfYhemMQWiI',NULL,NULL,'IpHINAT79UW'); -INSERT INTO `ProgramIndicator` VALUES (11,'x7PaHGvgWY2','BMI','BMI','BMI','2015-03-31T11:37:37.833','2015-08-09T21:35:21.650','BMI','BMI','Body Mass Index. Weight in kg / height in m square.','Body Mass Index. Weight in kg / height in m square.',1,'#{Zj7UnCAulEk.vV9UWAZohSf}/((#{Zj7UnCAulEk.GieVkTxp4HH}/100)*(#{Zj7UnCAulEk.GieVkTxp4HH}/100))','x7PaHGvgWY2',NULL,NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (12,'Kswd1r4qWLh',NULL,'Average height of boys at 10 years old','Average height of boys at 10 years old','2015-08-07T16:33:05.368','2015-08-07T16:33:05.368','Average height of boys at 10 years old','Average height of boys at 10 years old',NULL,NULL,0,'#{Zj7UnCAulEk.GieVkTxp4HH}','Kswd1r4qWLh','#{Zj7UnCAulEk.oZg33kd9taw} == ''Male'' and #{Zj7UnCAulEk.qrur9Dvnyt5} == 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (13,'hAHF3BEHGjM',NULL,'Inpatient cases female','Inpatient cases female','2015-12-13T12:36:00.816','2015-12-13T12:36:00.817','Inpatient cases female','Inpatient cases female',NULL,NULL,0,'V{event_count}','hAHF3BEHGjM','#{Zj7UnCAulEk.oZg33kd9taw} == ''Female''',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (14,'HS8QXAJtuKV',NULL,'Inpatient bed days average','Inpatient bed days average','2015-10-20T11:48:14.193','2015-10-20T11:48:14.193','Inpatient bed days average','Inpatient bed days average',NULL,NULL,0,'d2:daysBetween(#{Zj7UnCAulEk.eMyVanycQSC},#{Zj7UnCAulEk.msodh3rEMJa})','HS8QXAJtuKV',NULL,NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (15,'b8hd33dWjR6',NULL,'Inpatient bed days','Inpatient bed days','2017-01-26T17:11:24.919','2017-01-26T17:14:47.206','Inpatient bed days','Inpatient bed days','Inpatient days','Inpatient days',0,'d2:daysBetween(#{Zj7UnCAulEk.eMyVanycQSC},#{Zj7UnCAulEk.msodh3rEMJa})','b8hd33dWjR6',NULL,NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (16,'luLGbE2WKGP',NULL,'Inpatient cases','Inpatient cases','2015-12-13T12:33:39.857','2015-12-13T12:33:39.858','Inpatient cases','Inpatient cases',NULL,NULL,0,'V{event_count}','luLGbE2WKGP',NULL,NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (17,'nq5ohBSWj6E',NULL,'Inpatient cases male','Inpatient cases male','2015-12-13T12:35:44.927','2015-12-13T12:35:44.927','Inpatient cases male','Inpatient cases male',NULL,NULL,0,'V{event_count}','nq5ohBSWj6E','#{Zj7UnCAulEk.oZg33kd9taw} == ''Male''',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (18,'sGna2pquXOO',NULL,'Average age of female discharges','Average age of female discharges','2015-08-07T16:27:26.161','2015-08-07T16:27:26.161','Average age of female discharges','Average age of female discharges',NULL,NULL,0,'#{Zj7UnCAulEk.qrur9Dvnyt5}','sGna2pquXOO','#{Zj7UnCAulEk.oZg33kd9taw} == ''Female'' and #{Zj7UnCAulEk.fWIAEtYVEGk} == ''MODDISCH''',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (19,'Thkx2BnO5Kq',NULL,'BMI male','BMI male','2015-07-19T16:53:29.992','2015-07-19T18:46:02.630','BMI male','BMI male',NULL,NULL,0,'#{Zj7UnCAulEk.vV9UWAZohSf}/((#{Zj7UnCAulEk.GieVkTxp4HH}/100)*(#{Zj7UnCAulEk.GieVkTxp4HH}/100))','Thkx2BnO5Kq','#{Zj7UnCAulEk.oZg33kd9taw} == ''Male''',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (20,'htr2mMY515K',NULL,'Inpatient cases male under 5 y','Inpatient cases male under 5 y','2015-12-13T12:34:55.170','2015-12-13T12:34:55.170','Inpatient cases male under 5 y','Inpatient cases male under 5 y',NULL,NULL,0,'V{event_count}','htr2mMY515K','#{Zj7UnCAulEk.oZg33kd9taw} == ''Male'' and #{Zj7UnCAulEk.qrur9Dvnyt5} <= 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (21,'ST1CDYkWY4g',NULL,'Inpatient cases female under 5 y','Inpatient cases female under 5 y','2015-12-13T12:35:17.591','2015-12-13T12:35:17.592','Inpatient cases female under 5 y','Inpatient cases female under 5 y',NULL,NULL,0,'V{event_count}','ST1CDYkWY4g','#{Zj7UnCAulEk.oZg33kd9taw} == ''Female'' and #{Zj7UnCAulEk.qrur9Dvnyt5} <= 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (22,'vDdRoZYybP2',NULL,'Inpatient cases under 5 y','Inpatient cases under 5 y','2015-12-13T12:46:09.406','2015-12-13T12:46:09.406','Inpatient cases under 5 y','Inpatient cases under 5 y',NULL,NULL,0,'V{event_count}','vDdRoZYybP2','#{Zj7UnCAulEk.qrur9Dvnyt5} <= 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (23,'tUdBD1JDxpn',NULL,'Average age of deaths','Average age of deaths','2015-08-07T16:22:32.473','2015-08-07T16:22:32.473','Average age of deaths','Average age of deaths',NULL,NULL,0,'#{Zj7UnCAulEk.qrur9Dvnyt5}','tUdBD1JDxpn','#{Zj7UnCAulEk.fWIAEtYVEGk} == ''MODDIED''',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (24,'ReQEl5V3z6p',NULL,'Average weight of women','Average weight of women','2015-08-07T16:28:48.436','2015-08-07T16:30:07.862','Average weight of women','Average weight of women',NULL,NULL,0,'#{Zj7UnCAulEk.vV9UWAZohSf}','ReQEl5V3z6p','#{Zj7UnCAulEk.oZg33kd9taw} == ''Female''',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (25,'Y7hKDSuqEtH',NULL,'BMI male under 5 y','BMI male under 5 y','2015-07-19T17:01:34.556','2015-07-19T18:46:32.452','BMI male under 5 y','BMI male under 5 y',NULL,NULL,0,'#{Zj7UnCAulEk.vV9UWAZohSf}/((#{Zj7UnCAulEk.GieVkTxp4HH}/100)*(#{Zj7UnCAulEk.GieVkTxp4HH}/100))','Y7hKDSuqEtH','#{Zj7UnCAulEk.oZg33kd9taw} == ''Male'' and #{Zj7UnCAulEk.qrur9Dvnyt5} <= 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (26,'hlPt8H4bUOQ',NULL,'BMI female under 5 y','BMI female under 5 y','2015-07-19T17:01:03.156','2015-07-19T18:45:10.665','BMI female under 5 y','BMI female under 5 y',NULL,NULL,0,'#{Zj7UnCAulEk.vV9UWAZohSf}/((#{Zj7UnCAulEk.GieVkTxp4HH}/100)*(#{Zj7UnCAulEk.GieVkTxp4HH}/100))','hlPt8H4bUOQ','#{Zj7UnCAulEk.oZg33kd9taw} == ''Female'' and #{Zj7UnCAulEk.qrur9Dvnyt5} <= 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (27,'yFTplrY7NaL',NULL,'Height, weight and age','Height, weight and age','2015-10-20T12:44:43.341','2015-10-20T13:00:03.820','Height, weight and age','Height, weight and age',NULL,NULL,0,'sum(#{Zj7UnCAulEk.vV9UWAZohSf} *#{Zj7UnCAulEk.GieVkTxp4HH}) + avg(#{Zj7UnCAulEk.qrur9Dvnyt5})','yFTplrY7NaL',NULL,NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (28,'ToQVD4irW3Q',NULL,'Average height under 5 y','Average height under 5 y','2015-12-13T12:37:03.436','2015-12-13T12:37:03.436','Average height under 5 y','Average height under 5 y',NULL,NULL,0,'#{Zj7UnCAulEk.vV9UWAZohSf}','ToQVD4irW3Q','#{Zj7UnCAulEk.qrur9Dvnyt5} <= 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (29,'gWxh7DiRmG7',NULL,'Average height of girls at 5 years old','Average height of girls at 5 years old','2015-08-07T16:31:08.380','2015-08-07T16:31:46.003','Average height of girls at 5 years old','Average height of girls at 5 years old',NULL,NULL,0,'#{Zj7UnCAulEk.GieVkTxp4HH}','gWxh7DiRmG7','#{Zj7UnCAulEk.oZg33kd9taw} == ''Female'' and #{Zj7UnCAulEk.qrur9Dvnyt5} == 5',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (30,'XCMi7Wvnplm',NULL,'BMI female','BMI female','2015-07-19T17:00:14.019','2015-07-19T18:39:17.139','BMI female','BMI female',NULL,NULL,0,'#{Zj7UnCAulEk.vV9UWAZohSf}/((#{Zj7UnCAulEk.GieVkTxp4HH}/100)*(#{Zj7UnCAulEk.GieVkTxp4HH}/100))','XCMi7Wvnplm','#{Zj7UnCAulEk.oZg33kd9taw} == ''Female''',NULL,'eBAyeGv0exc'); -INSERT INTO `ProgramIndicator` VALUES (31,'nFICjJluo74',NULL,'Malaria case count','Malaria case count','2017-01-26T19:13:13.824','2017-01-26T19:13:13.824','Malaria case count','Malaria case count',NULL,NULL,0,'V{event_count}','nFICjJluo74',NULL,NULL,'VBqh0ynB2wv'); -INSERT INTO `ProgramIndicator` VALUES (32,'GSae40Fyppf',NULL,'Age at visit','Age at visit','2015-09-21T23:35:50.945','2015-09-21T23:47:57.820','Age','Age','Age at visit','Age at visit',1,'d2:yearsBetween(A{iESIqZ0R0R0},V{event_date})','GSae40Fyppf',NULL,NULL,'uy2gU8kT1jF'); -INSERT INTO `ProgramIndicator` VALUES (33,'dSBYyCUjCXd',NULL,'Age at visit - calc from days','Age at visit - calc from days','2016-04-05T15:20:36.968','2016-04-05T15:21:00.358','Age at visit - calc from days','Age at visit - calc from days',NULL,NULL,1,'d2:daysBetween(A{iESIqZ0R0R0},V{event_date})','dSBYyCUjCXd',NULL,0,'uy2gU8kT1jF'); -INSERT INTO `ProgramIndicator` VALUES (34,'TcTRasl29wo',NULL,'WHO RMNCH ANC Hemoglobin improvement','WHO RMNCH ANC Hemoglobin improvement','2017-01-19T14:39:51.119','2017-01-20T12:04:27.538','Hemoglobin inprovement','Hemoglobin inprovement','Improvement in hemoglobin','Improvement in hemoglobin',1,'#{edqlbukwRfQ.vANAXwtLwcT} - #{WZbXY0S00lP.vANAXwtLwcT}','TcTRasl29wo','#{edqlbukwRfQ.vANAXwtLwcT} != 0 and #{WZbXY0S00lP.vANAXwtLwcT} != 0',NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramIndicator` VALUES (35,'FIVbyQyO0tV',NULL,'WHO RMNCH Number of days since last activity in active pregnancies','WHO RMNCH Number of days since last activity in active pregnancies','2017-01-20T10:23:20.169','2017-01-26T16:54:49.005','Days since last activity in active pregnancies','Days since last activity in active pregnancies','Returns the average number of days since the last event was registered within the active pregnancies(enrollments).','Returns the average number of days since the last event was registered within the active pregnancies(enrollments).',0,'d2:daysBetween(V{event_date},V{current_date})','FIVbyQyO0tV','V{enrollment_status} == ''ACTIVE''',NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramIndicator` VALUES (36,'ksBXh8hBmpv',NULL,'WHO RMNCH Number of visits anemic woman','WHO RMNCH Number of visits anemic woman','2017-01-20T10:17:02.431','2017-01-20T10:17:49.776','Number of visits anemic woman','Number of visits anemic woman','The number of visits recorded where the subject woman has hemoglobin less than 11','The number of visits recorded where the subject woman has hemoglobin less than 11',0,'V{event_count}','ksBXh8hBmpv','#{edqlbukwRfQ.vANAXwtLwcT} < 11',NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramIndicator` VALUES (37,'Oy1a11KynDC',NULL,'WHO RMNCH Number of women turned anemic in ANC','WHO RMNCH Number of women turned anemic in ANC','2017-01-20T10:15:23.926','2017-01-26T16:55:55.369','Women turned anemic through ANC','Women turned anemic through ANC','The number of pregnancies(enrollments) where the woman had a hemoglobin value of less than 11 at the end of the ANC period, but was not anemic at the first antenatal care visit','The number of pregnancies(enrollments) where the woman had a hemoglobin value of less than 11 at the end of the ANC period, but was not anemic at the first antenatal care visit',0,'V{enrollment_count}','Oy1a11KynDC','#{edqlbukwRfQ.vANAXwtLwcT} < 11 and #{WZbXY0S00lP.vANAXwtLwcT} > 11',NULL,'WSGAb5XwJ3Y'); -INSERT INTO `ProgramIndicator` VALUES (38,'tYPIZKEVh23',NULL,'WHO RMNCH Days enrolled','WHO RMNCH Days enrolled','2017-01-26T17:08:22.098','2017-01-26T17:10:03.583','Days enrolled','Days enrolled','Number of days enrolled in program','Number of days enrolled in program',0,'d2:daysBetween(V{enrollment_date},V{event_date})','tYPIZKEVh23',NULL,NULL,'WSGAb5XwJ3Y'); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `Program` VALUES (1,'lxAQ7Zs9VYR',NULL,'Antenatal care visit','Antenatal care visit','2016-04-12T15:30:43.783','2017-01-19T14:32:05.307','Antenatal care','Antenatal care',NULL,NULL,3,0,'Enrollment Date',0,'Incident Date',0,0,NULL,0,0,0,0,0,0,'WITHOUT_REGISTRATION',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `Program` VALUES (2,'IpHINAT79UW',NULL,'Child Programme','Child Programme','2013-03-04T11:41:07.494','2017-01-26T19:39:33.356','Child Programme','Child Programme',NULL,NULL,5,1,'Date of enrollment',1,'Date of birth',1,0,NULL,0,0,0,1,1,0,'WITH_REGISTRATION',NULL,NULL,NULL,'nEenWmSyUEp',NULL); -INSERT INTO `Program` VALUES (3,'kla3mAPgvCH',NULL,'Contraceptives Voucher Program','Contraceptives Voucher Program','2015-10-20T12:05:27.374','2015-10-20T12:06:47.544','Contraceptives Voucher Program','Contraceptives Voucher Program',NULL,NULL,2,0,'Enrollment Date',0,'Incident Date',0,0,NULL,0,0,0,0,0,0,'WITHOUT_REGISTRATION',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `Program` VALUES (4,'q04UBOqq3rp',NULL,'Information Campaign','Information Campaign','2014-06-22T13:28:24.004','2014-06-22T13:28:56.127','Information Campaign','Information Campaign',NULL,NULL,1,0,'Enrollment Date',0,'Incident Date',0,0,NULL,0,0,0,0,0,0,'WITHOUT_REGISTRATION',NULL,'',NULL,NULL,NULL); -INSERT INTO `Program` VALUES (5,'eBAyeGv0exc',NULL,'Inpatient morbidity and mortality','Inpatient morbidity and mortality','2013-03-04T11:41:07.494','2015-08-07T15:00:34.120','Inpatient morbidity and mortality','Inpatient morbidity and mortality',NULL,NULL,4,0,NULL,0,'Date of Discharge',0,0,NULL,0,0,0,0,0,0,'WITHOUT_REGISTRATION',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `Program` VALUES (6,'VBqh0ynB2wv',NULL,'Malaria case registration','Malaria case registration','2016-03-30T20:18:31.020','2016-04-12T20:44:46.066','Malaria case registration','Malaria case registration',NULL,NULL,1,0,'Enrollment Date',0,'Incident Date',0,0,NULL,0,0,0,0,0,0,'WITHOUT_REGISTRATION',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `Program` VALUES (7,'bMcwwoVnbSR',NULL,'Malaria testing and surveillance','Malaria testing and surveillance','2017-05-22T16:34:38.445','2017-05-22T16:34:38.445','Malaria testing and surveillance','Malaria testing and surveillance',NULL,NULL,0,0,NULL,1,NULL,0,0,NULL,0,0,0,0,0,0,'WITHOUT_REGISTRATION',NULL,NULL,NULL,NULL,NULL); -INSERT INTO `Program` VALUES (8,'uy2gU8kT1jF',NULL,'MNCH / PNC (Adult Woman)','MNCH / PNC (Adult Woman)','2013-03-04T11:41:07.494','2015-09-21T23:39:24.372','MNCH / PNC (Adult Woman)','MNCH / PNC (Adult Woman)',NULL,NULL,4,0,'Date of enrollment',1,'LMP Date',1,0,NULL,0,1,0,0,0,0,'WITH_REGISTRATION','V2kkHafqs8G','Add child','IpHINAT79UW','nEenWmSyUEp',NULL); -INSERT INTO `Program` VALUES (9,'fDd25txQckK',NULL,'Provider Follow-up and Support Tool','Provider Follow-up and Support Tool','2014-04-25T15:14:18.868','2015-08-06T20:07:42.577','Provider Follow-up and Support Tool','Provider Follow-up and Support Tool',NULL,NULL,1,0,'Date of reporting',1,'Date of training',1,0,NULL,0,0,0,0,0,0,'WITH_REGISTRATION',NULL,'',NULL,'nEenWmSyUEp',NULL); -INSERT INTO `Program` VALUES (10,'ur1Edk5Oe2n',NULL,'TB program','TB program','2013-03-04T11:41:07.494','2017-01-26T19:40:15.617','TB program','TB program',NULL,NULL,19,0,'Start of treatment date',0,'Start of treatment date',1,0,NULL,0,0,0,0,0,0,'WITH_REGISTRATION',NULL,NULL,NULL,'nEenWmSyUEp',NULL); -INSERT INTO `Program` VALUES (11,'WSGAb5XwJ3Y',NULL,'WHO RMNCH Tracker','WHO RMNCH Tracker','2014-06-06T20:44:21.375','2017-05-22T22:30:55.412','WHO RMNCH Tracker','WHO RMNCH Tracker',NULL,NULL,12,0,'Date of first visit',0,'Date of incident',1,0,NULL,0,1,1,0,0,0,'WITH_REGISTRATION','V2kkHafqs8G','Add child','IpHINAT79UW','nEenWmSyUEp',NULL); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -INSERT INTO `OrganisationUnitProgramLink` VALUES (1,'DiszpKrYNg8','q04UBOqq3rp'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (2,'DiszpKrYNg8','kla3mAPgvCH'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (3,'DiszpKrYNg8','uy2gU8kT1jF'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (4,'DiszpKrYNg8','VBqh0ynB2wv'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (5,'DiszpKrYNg8','eBAyeGv0exc'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (6,'DiszpKrYNg8','lxAQ7Zs9VYR'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (7,'DiszpKrYNg8','IpHINAT79UW'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (8,'DiszpKrYNg8','bMcwwoVnbSR'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (9,'DiszpKrYNg8','ur1Edk5Oe2n'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (10,'DiszpKrYNg8','WSGAb5XwJ3Y'); -INSERT INTO `OrganisationUnitProgramLink` VALUES (11,'DiszpKrYNg8','fDd25txQckK'); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -INSERT INTO `OrganisationUnit` VALUES (1,'DiszpKrYNg8','OU_559','Ngelehun CHC','Ngelehun CHC','2012-02-17T15:54:39.987','2017-05-22T15:21:48.516','Ngelehun CHC','Ngelehun CHC',NULL,NULL,'/ImspTQPwCqd/O6uvpzGd5pu/YuQRtpLP10I/DiszpKrYNg8','1970-01-01T00:00:00.000',NULL,4,'YuQRtpLP10I'); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -INSERT INTO `OptionSet` VALUES (1,'f38bstJioPs',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (2,'kzgQRhOCadd',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (3,'x31y45jvIQL',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (4,'nH8Y04zS7UV',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (5,'udkr3ihaeD3',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (6,'oXR37f2wOb1',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (7,'OGmE3wUMEzu',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (8,'dgsftM0rXu2',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (9,'XdI8KRJiRoZ',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (10,'s3GoZHCmXL2',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (11,'VQ2lai3OfVG',NULL,'Age category','Age category','2014-06-22T10:59:26.564','2015-08-06T14:23:38.789',1,'TEXT'); -INSERT INTO `OptionSet` VALUES (12,'PmE3Ev4ZcHX',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (13,'Da7byW1wGzq',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (14,'pC3N9N77UmT',NULL,NULL,NULL,NULL,NULL,0,NULL); -INSERT INTO `OptionSet` VALUES (15,'iDFPKpFTiVw',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (16,'eUZ79clX7y1',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (17,'MmrbR9vqscW',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (18,'ku6syDAYWYV',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (19,'qCOOnBxlkMz',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (20,'tQ8erv0xjs3',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (21,'IpRuNUVbhTz',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (22,'zE2tXMHgoZU',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (23,'FkvSziHHUmZ',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (24,'YSaCD1K07iM',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (25,'pVV5aunSFRO',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (26,'fUS7fy2HbaI',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (27,'pQW2iZcMb2d',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (28,'vDQykDhxQVu',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (29,'HS9zgnYt2Ia',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (30,'RCTaQUCuDbu',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (31,'js7iuBwl03u',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (32,'mRl1KGfKrpt',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (33,'C6wvZOqmAKI',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (34,'ClTONeEYrI3',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (35,'VDVbkOVFbbT',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (36,'isYOcVDBgJo',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (37,'F9ypN9t9NUy',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (38,'Im9PtRGpdDW',NULL,NULL,NULL,NULL,NULL,0,NULL); -INSERT INTO `OptionSet` VALUES (39,'VFR0v2vRhlE',NULL,NULL,NULL,NULL,NULL,2,NULL); -INSERT INTO `OptionSet` VALUES (40,'jAyXdHaxGiH',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (41,'i65CmiT6dKV',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (42,'R3mpvjqJ81H',NULL,'ARV treatment plan','ARV treatment plan','2015-02-25T10:47:18.199','2015-10-14T13:36:03.722',1,'TEXT'); -INSERT INTO `OptionSet` VALUES (43,'J7nRCGjOtRa',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (44,'bVOLWJ2ZHdV',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (45,'g80kErVQ9nn',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (46,'bVOfVD9sJFP',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (47,'R3ShQczKnI9',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (48,'Na3EKYZ6CX6',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (49,'iqz8IiJwWPL',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (50,'pQYCiuosBnZ',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (51,'bh7Idg1kWYo',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (52,'HENAVEViqQP',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (53,'IkB24bxyneF',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (54,'WsxjrKsoi9W',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (55,'C3F7ypzeLiS',NULL,NULL,NULL,NULL,NULL,1,NULL); -INSERT INTO `OptionSet` VALUES (56,'RCsz7zzurLe',NULL,NULL,NULL,NULL,NULL,4,NULL); -INSERT INTO `OptionSet` VALUES (57,'xjA5E9MimMU',NULL,'Civil status','Civil status','2014-06-06T20:38:48.526','2015-10-14T13:36:01.187',1,'TEXT'); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -INSERT INTO `Option` VALUES (1,'Y1ILwhy5VDY','0-14 years','0-14 years','0-14 years','2014-08-18T12:39:16.000','2014-08-18T12:39:16.000','VQ2lai3OfVG'); -INSERT INTO `Option` VALUES (2,'egT1YqFWsVk','15-19 years','15-19 years','15-19 years','2014-08-18T12:39:16.000','2014-08-18T12:39:16.000','VQ2lai3OfVG'); -INSERT INTO `Option` VALUES (3,'WckXGsyYola','20-24 years','20-24 years','20-24 years','2014-08-18T12:39:16.000','2014-08-18T12:39:16.000','VQ2lai3OfVG'); -INSERT INTO `Option` VALUES (4,'EmQGvSlg0GD','25 years and above','25 years and above','25 years and above','2014-08-18T12:39:16.000','2014-08-18T12:39:16.000','VQ2lai3OfVG'); -INSERT INTO `Option` VALUES (5,'ENETOHGjmqb','None','No ARV medication plan','No ARV medication plan','2015-02-25T10:48:01.780','2015-10-14T13:35:56.365','R3mpvjqJ81H'); -INSERT INTO `Option` VALUES (6,'dNgtjuMPdfI','Ongoing','Ongoing ARV treatment','Ongoing ARV treatment','2015-02-25T10:48:58.693','2015-10-14T13:35:56.526','R3mpvjqJ81H'); -INSERT INTO `Option` VALUES (7,'izO4RwIbL0r','Initiated','ARV medication initiated','ARV medication initiated','2015-02-25T10:49:22.792','2015-10-14T13:35:56.691','R3mpvjqJ81H'); -INSERT INTO `Option` VALUES (8,'wfkKVdPBzho','Single or widow','Single or widow','Single or widow','2014-08-20T12:46:14.000','2015-10-14T13:35:43.355','xjA5E9MimMU'); -INSERT INTO `Option` VALUES (9,'Yjte6foKMny','Married (conjugal cohabitation)','Married (conjugal cohabitation)','Married (conjugal cohabitation)','2014-08-20T12:46:14.000','2015-10-14T13:35:43.522','xjA5E9MimMU'); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `Event` VALUES (1,'V1CerIi3sdL',NULL,'2017-08-07T15:47:25.959','2017-09-14T22:26:39.094',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2017-02-27T00:00:00.000','2017-02-27T00:00:00.000','2017-02-28T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (2,'fxprDvpLa7Y',NULL,'2017-01-28T22:31:57.523','2017-04-20T17:23:46.241',NULL,NULL,'VISITED','0','0','uy2gU8kT1jF','grIfo3oOf4Y','DiszpKrYNg8','2017-01-01T00:00:00.000',NULL,'2017-04-20T17:23:46.241','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (3,'kNpCKARLVHd',NULL,'2017-01-28T22:31:57.887','2017-04-20T17:23:21.290',NULL,NULL,'VISITED','0','0','uy2gU8kT1jF','oRySG82BKE6','DiszpKrYNg8','2017-01-01T00:00:00.000',NULL,'2017-04-20T17:23:21.289','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (4,'FyJ0jgAARNX',NULL,'2017-01-20T20:01:44.450','2017-04-20T16:27:12.019',NULL,NULL,'ACTIVE','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2017-08-02T00:00:00.000',NULL,'2017-04-20T16:27:12.019','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (5,'BijwU5PwIMh',NULL,'2017-01-20T13:10:17.570','2017-01-20T13:11:25.834',NULL,NULL,'COMPLETED','0','0','ur1Edk5Oe2n','ZkbAXlQUYJG','DiszpKrYNg8','2017-01-01T00:00:00.000','2017-01-01T00:00:00.000','2017-01-15T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (6,'qgaHGxGEI56',NULL,'2017-01-20T13:01:47.252','2017-01-20T13:09:15.453',NULL,NULL,'COMPLETED','0','0','ur1Edk5Oe2n','ZkbAXlQUYJG','DiszpKrYNg8','2017-01-02T00:00:00.000','2017-01-02T00:00:00.000','2017-01-01T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (7,'qf2qpuzVOki',NULL,'2017-08-06T21:20:41.754','2017-01-15T18:14:34.449',NULL,NULL,'ACTIVE','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-07-06T00:00:00.000',NULL,'2017-01-15T18:14:34.449','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (8,'KrsbTnx097t',NULL,'2016-11-16T12:53:34.970','2016-11-16T12:54:23.345',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','ZzYYXq4fJie','DiszpKrYNg8','2016-05-07T00:00:00.000','2016-11-16T12:54:23.345','2016-05-07T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (9,'V9HVjkqcUcg',NULL,'2016-11-16T12:53:34.770','2016-11-16T12:53:58.920',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-05-01T00:00:00.000','2016-11-16T12:53:58.920','2016-05-01T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (10,'vF0YkkC3JD3',NULL,'2016-11-16T12:25:30.652','2016-11-16T12:26:34.984',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','ZzYYXq4fJie','DiszpKrYNg8','2016-05-01T00:00:00.000','2016-11-16T12:26:34.984','2002-01-07T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (11,'nN7gGLW5Akv',NULL,'2016-11-16T12:25:30.337','2016-11-16T12:25:54.623',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-04-02T00:00:00.000','2016-11-16T12:25:54.623','2002-01-01T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (12,'XGLkLlOXgmE',NULL,'2016-11-16T11:38:23.746','2016-11-16T11:38:59.953',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-08-14T00:00:00.000','2016-11-16T11:38:45.971','2002-01-01T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (13,'YHMjNgw3yQZ',NULL,'2016-11-15T21:22:30.293','2016-11-15T21:22:45.437',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-11-15T00:00:00.000','2016-11-15T21:22:45.436','2016-11-14T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (14,'DJgiFfCU0zu',NULL,'2016-11-15T21:20:06.367','2016-11-15T21:20:20.365',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-11-01T00:00:00.000','2016-11-15T21:20:20.364','2016-11-02T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (15,'IeOweNjLXxv',NULL,'2016-11-15T21:19:09.343','2016-11-15T21:19:28.312',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-11-05T00:00:00.000','2016-11-15T21:19:28.311','2016-11-05T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (16,'vdbUbSCFVYS',NULL,'2016-11-15T19:51:08.343','2016-11-15T19:56:27.255',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','ZzYYXq4fJie','DiszpKrYNg8','2016-10-23T00:00:00.000','2016-11-15T19:56:27.254','2002-01-07T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (17,'DhwJD1gzgOZ',NULL,'2016-11-15T19:51:08.153','2016-11-15T19:55:41.383',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-09-25T00:00:00.000','2016-11-15T19:55:41.383','2016-11-15T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (18,'XvVI1eVrqxj',NULL,'2016-11-15T19:13:49.589','2016-11-15T19:14:06.366',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-11-13T00:00:00.000','2016-11-15T19:14:06.366','2016-11-13T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (19,'q0Hcikut16c',NULL,'2016-11-15T19:12:23.229','2016-11-15T19:12:47.031',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-11-12T00:00:00.000','2016-11-15T19:12:47.031','2016-11-12T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (20,'ea2QqDBbvMX',NULL,'2016-09-23T20:01:44.951','2016-11-15T19:11:31.131',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-05-22T00:00:00.000','2016-11-15T19:11:31.131','2009-10-02T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (21,'qIb7Lu0YDi9',NULL,'2016-11-15T18:00:48.008','2016-11-15T18:01:33.764',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','ZzYYXq4fJie','DiszpKrYNg8','2016-11-06T00:00:00.000','2016-11-15T18:01:33.763','2016-11-09T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (22,'aO0gvKzIj1k',NULL,'2016-11-15T18:00:47.817','2016-11-15T18:01:08.787',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-11-02T00:00:00.000','2016-11-15T18:01:08.786','2016-11-03T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (23,'zQg7E7SWhKY',NULL,'2016-11-15T17:56:31.124','2016-11-15T18:00:19.717',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','ZzYYXq4fJie','DiszpKrYNg8','2016-11-03T00:00:00.000','2016-11-15T18:00:19.717','2016-11-11T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (24,'LctNSYpfdh0',NULL,'2016-11-15T17:56:30.886','2016-11-15T17:59:53.633',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-11-11T00:00:00.000','2016-11-15T17:59:53.632','2016-11-05T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (25,'TgJUhG6P6TJ',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:24.003',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (26,'sYRVmmHJu9k',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.884',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (27,'sXjvyAhSGsx',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.850',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (28,'sG5GMkjDHX4',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.821',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (29,'sfUiGQXxGHY',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.771',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (30,'S3Ed7pz0Qss',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.735',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (31,'Ro8zY5sqPqo',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.701',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (32,'qIrQx5zCh92',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.661',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (33,'OCjUpTL9hFo',NULL,'2016-11-05T00:25:45.087','2016-11-15T14:55:23.558',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-11-03T00:00:00.000','2016-11-15T00:00:00.000','2016-11-03T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (34,'o5gLo6FlAe4',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.498',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (35,'NkvkOpBjkkH',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.464',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (36,'j0jx4um8pMX',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:23.215',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2016-11-15T00:00:00.000','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (37,'IfN2uN0PPgW',NULL,'2016-11-05T00:21:27.632','2016-11-15T14:55:23.139',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-11-04T00:00:00.000','2016-11-15T00:00:00.000','2016-11-04T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (38,'HUBOSWKAWoU',NULL,'2016-11-05T00:19:32.500','2016-11-15T14:55:23.035',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-11-05T00:00:00.000','2016-11-15T00:00:00.000','2016-11-05T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (39,'hnaWBxMw5j3',NULL,'2016-09-08T21:40:22.000','2016-11-15T14:55:22.995',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-01T00:00:00.000','2016-11-15T00:00:00.000','2016-05-01T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (40,'hjuhPUlUIdk',NULL,'2016-01-09T19:44:43.209','2016-11-15T14:55:22.960',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-01-01T00:00:00.000','2016-11-15T00:00:00.000','2016-01-01T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (41,'GFR73Oyo9bV',NULL,'2016-01-09T19:44:27.696','2016-11-15T14:55:22.820',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-01-01T00:00:00.000','2016-11-15T00:00:00.000','2016-01-01T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (42,'yWJCccgH2rQ',NULL,'2016-11-05T00:25:45.087','2016-11-05T00:25:45.087',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-11-04T00:00:00.000','2015-11-05T00:25:45.087','2016-11-04T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (43,'Yp0oC0Yb9hR',NULL,'2016-09-08T21:40:22.000','2016-09-08T21:40:22.000',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2015-05-30T10:53:07.030','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (44,'XgDqOaJrbut',NULL,'2016-09-08T21:40:22.000','2016-09-08T21:40:22.000',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2015-05-30T10:37:42.428','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (45,'YhVgcj1vXN6',NULL,'2016-09-08T21:40:22.000','2016-09-08T21:40:22.000',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2015-05-30T10:28:51.291','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (46,'xqaqOyXIrKI',NULL,'2016-09-08T21:40:22.000','2016-09-08T21:40:22.000',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2015-05-30T10:26:31.061','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (47,'xVIGJUcxIeK',NULL,'2016-09-08T21:40:22.000','2016-09-08T21:40:22.000',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2015-05-30T10:26:00.009','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (48,'XivskH4atI0',NULL,'2016-09-08T21:40:22.000','2016-09-08T21:40:22.000',NULL,NULL,'COMPLETED','0','0','eBAyeGv0exc','Zj7UnCAulEk','DiszpKrYNg8','2016-05-17T00:00:00.000','2015-05-30T11:26:35.330','2016-05-17T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (49,'oosW4rSH7CM',NULL,'2016-01-09T19:43:13.893','2016-01-09T19:44:03.316',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','ZzYYXq4fJie','DiszpKrYNg8','2016-01-01T00:00:00.000','2016-01-09T00:00:00.000','2016-01-14T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -INSERT INTO `Event` VALUES (50,'LKQXmteRtvQ',NULL,'2016-01-09T19:43:13.892','2016-01-09T19:43:41.732',NULL,NULL,'COMPLETED','0','0','IpHINAT79UW','A03MvHHogjR','DiszpKrYNg8','2016-01-01T00:00:00.000','2016-01-09T00:00:00.000','2016-01-08T00:00:00.000','SYNCED','as6ygGvUGNg','bRowv6yZOF2',NULL); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -INSERT INTO `DataElement` VALUES (1,'sWoqcoByYmD','STA_SMO','WHOMCH Smoking','WHOMCH Smoking','2015-01-14T07:43:31.645','2016-04-06T01:39:41.132','Smoking','Smoking',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Smoking',NULL,NULL); -INSERT INTO `DataElement` VALUES (2,'Ok9OQpitjQr','EA5_TRE_SMO','WHOMCH Smoking cessation counselling provided ','WHOMCH Smoking cessation counselling provided ','2013-10-31T12:12:02.900','2015-10-14T13:36:33.896','Smoking cessation counselling provided ','Smoking cessation counselling provided ','Counselling and behavioural interventions on smoking cessation.','Counselling and behavioural interventions on smoking cessation.','BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Smoking cessation counselling provided ',NULL,NULL); -INSERT INTO `DataElement` VALUES (3,'vANAXwtLwcT','LAB_HB','WHOMCH Hemoglobin value','WHOMCH Hemoglobin value','2013-10-28T17:27:17.826','2015-10-14T13:36:44.324','Hemoglobin value','Hemoglobin value','Screening for anemia.','Screening for anemia.','NUMBER',1,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Hemoglobin value',NULL,NULL); -INSERT INTO `DataElement` VALUES (4,'a3kGcGDCuk6','DE_2006098','MCH Apgar Score','MCH Apgar Score','2012-09-20T08:37:02.003','2016-04-20T17:32:10.262','Apgar Score','Apgar Score','Apgar is a quick test performed on a baby at 1 and 5 minutes after birth. The 1-minute score determines how well the baby tolerated the birthing process. The 5-minute score tells the doctor how well the baby is doing outside the mother''s womb.','Apgar is a quick test performed on a baby at 1 and 5 minutes after birth. The 1-minute score determines how well the baby tolerated the birthing process. The 5-minute score tells the doctor how well the baby is doing outside the mother''s womb.','NUMBER',0,'AVERAGE','Apgar Score',NULL,'TRACKER',NULL,'Apgar Score',NULL,NULL); -INSERT INTO `DataElement` VALUES (5,'H6uSAMO5WLD','DE_391382','MCH Apgar comment','MCH Apgar comment','2015-08-07T14:44:59.734','2015-08-07T14:45:56.684','Apgar comment','Apgar comment',NULL,NULL,'LONG_TEXT',0,'SUM','Apgar comment',NULL,'TRACKER',NULL,'Apgar comment',NULL,NULL); -INSERT INTO `DataElement` VALUES (6,'UXz7xuGCEhU','DE_2005736','MCH Weight (g)','MCH Weight (g)','2012-09-20T17:37:45.474','2014-11-11T21:56:05.418','Weight (g)','Weight (g)',NULL,NULL,'NUMBER',0,'AVERAGE','Weight (g)',NULL,'TRACKER',NULL,'Weight (g)',NULL,NULL); -INSERT INTO `DataElement` VALUES (7,'wQLfBvPrXqq','DE_2008294','MCH ARV at birth','MCH ARV at birth','2012-09-21T13:12:38.012','2014-11-11T21:56:05.404','ARV at birth','ARV at birth','Onlu used for birth details.','Onlu used for birth details.','TEXT',0,'AVERAGE','ARV at birth',NULL,'TRACKER',NULL,'ARV at birth','f38bstJioPs',NULL); -INSERT INTO `DataElement` VALUES (8,'bx6fsa0t90x','DE_2006101','MCH BCG dose','MCH BCG dose','2012-09-20T08:40:33.607','2015-08-06T22:17:09.056','BCG dose','BCG dose',NULL,NULL,'BOOLEAN',0,'SUM','BCG dose',NULL,'TRACKER',NULL,'BCG dose',NULL,NULL); -INSERT INTO `DataElement` VALUES (9,'ebaJjqltK5N','DE_2006104','MCH OPV dose','MCH OPV dose','2012-09-20T18:03:44.110','2015-08-06T16:44:30.622','OPV dose','OPV dose',NULL,NULL,'TEXT',0,'AVERAGE','OPV dose',NULL,'TRACKER',NULL,'OPV dose','kzgQRhOCadd',NULL); -INSERT INTO `DataElement` VALUES (10,'X8zyunlgUfM','DE_2006103','MCH Infant Feeding','MCH Infant Feeding','2012-09-20T08:43:58.131','2014-11-11T21:56:05.414','Infant Feeding','Infant Feeding',NULL,NULL,'TEXT',0,'AVERAGE','Infant Feeding',NULL,'TRACKER',NULL,'Infant Feeding','x31y45jvIQL',NULL); -INSERT INTO `DataElement` VALUES (11,'uf3svrmp8Oj','DE_424405','Birth certificate','Birth certificate','2016-01-15T18:13:32.416','2016-01-15T22:44:11.475','Birth certificate','Birth certificate',NULL,NULL,'FILE_RESOURCE',0,'SUM',NULL,NULL,'TRACKER',NULL,'Birth certificate',NULL,NULL); -INSERT INTO `DataElement` VALUES (12,'GQY2lXrypjO','DE_2006099','MCH Infant Weight (g)','MCH Infant Weight (g)','2012-09-20T08:44:53.428','2014-11-11T21:56:05.550','Infant Weight (g)','Infant Weight (g)','Infant weight in grams','Infant weight in grams','NUMBER',0,'AVERAGE','Infant Weight (g)',NULL,'TRACKER',NULL,'Infant Weight (g)',NULL,NULL); -INSERT INTO `DataElement` VALUES (13,'FqlgKAG8HOu','DE_2006125','MCH Measles dose','MCH Measles dose','2015-08-06T13:36:22.541','2015-08-06T22:17:50.754','Measles dose','Measles dose',NULL,NULL,'BOOLEAN',0,'SUM','Measles dose',NULL,'TRACKER',NULL,'Measles dose',NULL,NULL); -INSERT INTO `DataElement` VALUES (14,'vTUhAUZFoys','DE_347311','MCH Penta dose','MCH Penta dose','2015-08-06T13:39:31.690','2015-08-06T16:43:12.445','Penta dose','Penta dose',NULL,NULL,'TEXT',0,'AVERAGE','Penta dose',NULL,'TRACKER',NULL,'Penta dose','kzgQRhOCadd',NULL); -INSERT INTO `DataElement` VALUES (15,'rxBfISxXS2U','DE_2006126','MCH Yellow fever dose','MCH Yellow fever dose','2015-08-06T13:41:15.499','2015-08-06T22:18:27.907','Yellow fever dose','Yellow fever dose',NULL,NULL,'BOOLEAN',0,'SUM','Yellow fever dose',NULL,'TRACKER',NULL,'Yellow fever dose',NULL,NULL); -INSERT INTO `DataElement` VALUES (16,'lNNb3truQoi','DE_2005744','MCH IPT dose','MCH IPT dose','2012-09-20T08:45:02.015','2015-08-06T13:44:32.035','IPT dose','IPT dose',NULL,NULL,'TEXT',0,'AVERAGE','IPT dose',NULL,'TRACKER',NULL,'IPT dose','nH8Y04zS7UV',NULL); -INSERT INTO `DataElement` VALUES (17,'pOe0ogW4OWd','DE_2006105','MCH DPT dose','MCH DPT dose','2012-09-20T18:01:19.313','2015-08-06T16:43:25.692','DPT dose','DPT dose',NULL,NULL,'TEXT',0,'AVERAGE','DPT dose',NULL,'TRACKER',NULL,'DPT dose','udkr3ihaeD3',NULL); -INSERT INTO `DataElement` VALUES (18,'HLmTEmupdX0','DE_2006106','MCH Vit A','MCH Vit A','2012-09-20T08:46:58.580','2015-08-06T22:21:28.678','Vit A','Vit A',NULL,NULL,'BOOLEAN',0,'SUM','Vit A',NULL,'TRACKER',NULL,'Vit A',NULL,NULL); -INSERT INTO `DataElement` VALUES (19,'cYGaxwK615G','DE_2006107','MCH Infant HIV Test Result','MCH Infant HIV Test Result','2012-09-20T08:44:35.860','2014-11-11T21:56:05.548','Infant HIV Test Result','Infant HIV Test Result',NULL,NULL,'TEXT',0,'AVERAGE','Infant HIV Test Result',NULL,'TRACKER',NULL,'Infant HIV Test Result','oXR37f2wOb1',NULL); -INSERT INTO `DataElement` VALUES (20,'hDZbpskhqDd','DE_2006108','MCH HIV Test Type','MCH HIV Test Type','2012-09-20T08:43:45.821','2014-11-11T21:56:05.416','HIV Test Type','HIV Test Type',NULL,NULL,'TEXT',0,'AVERAGE','HIV Test Type',NULL,'TRACKER',NULL,'HIV Test Type','OGmE3wUMEzu',NULL); -INSERT INTO `DataElement` VALUES (21,'sj3j9Hwc7so','DE_2006100','MCH Child ARVs','MCH Child ARVs','2012-09-21T13:02:22.744','2014-11-11T21:56:05.599','Child ARVs','Child ARVs','ARVs for child postnatal visits.','ARVs for child postnatal visits.','TEXT',0,'AVERAGE','Child ARVs',NULL,'TRACKER',NULL,'Child ARVs','dgsftM0rXu2',NULL); -INSERT INTO `DataElement` VALUES (22,'aei1xRjSU2l','DE_2006109','MCH Septrin Given','MCH Septrin Given','2012-09-20T08:46:17.717','2014-11-11T21:56:05.417','Septrin Given','Septrin Given',NULL,NULL,'TEXT',0,'AVERAGE','Septrin Given',NULL,'TRACKER',NULL,'Septrin Given','XdI8KRJiRoZ',NULL); -INSERT INTO `DataElement` VALUES (23,'BeynU4L6VCQ','DE_2006110','MCH Results given to caretaker','MCH Results given to caretaker','2012-09-20T08:46:05.594','2014-11-11T21:56:05.402','Results given to caretake','Results given to caretake',NULL,NULL,'TEXT',0,'AVERAGE','Results given to caretaker',NULL,'TRACKER',NULL,'Results given to caretaker','XdI8KRJiRoZ',NULL); -INSERT INTO `DataElement` VALUES (24,'OuJ6sgPyAbC','DE_2008126','MCH Visit Comment','MCH Visit Comment','2012-09-20T16:18:26.595','2014-11-11T21:56:05.403','Visit Comment','Visit Comment','Free text comment used to put additional information for a visit.','Free text comment used to put additional information for a visit.','LONG_TEXT',0,'AVERAGE','Visit comment (optional)',NULL,'TRACKER',NULL,'Visit comment (optional)',NULL,NULL); -INSERT INTO `DataElement` VALUES (25,'b6dOUjAarHD','DE_424050','Voucher HTC','Voucher HTC','2015-10-20T12:01:05.290','2015-10-20T12:03:58.972','Voucher HTC','Voucher HTC',NULL,NULL,'INTEGER',0,'SUM',NULL,NULL,'TRACKER',NULL,'Voucher HTC',NULL,NULL); -INSERT INTO `DataElement` VALUES (26,'W7aC8jLASW8','DE_424051','Voucher IMCI','Voucher IMCI','2015-10-20T12:01:05.624','2015-10-20T12:04:04.010','Voucher IMCI','Voucher IMCI',NULL,NULL,'INTEGER',0,'SUM',NULL,NULL,'TRACKER',NULL,'Voucher IMCI',NULL,NULL); -INSERT INTO `DataElement` VALUES (27,'fqnXmRYo5Cz','DE_424052','Voucher Implants','Voucher Implants','2015-10-20T12:01:05.896','2015-10-20T12:04:08.634','Voucher Implants','Voucher Implants',NULL,NULL,'INTEGER',0,'SUM',NULL,NULL,'TRACKER',NULL,'Voucher Implants',NULL,NULL); -INSERT INTO `DataElement` VALUES (28,'HrJmqlBqTFG','DE_424053','Voucher Injections','Voucher Injections','2015-10-20T12:01:06.239','2015-10-20T12:04:17.133','Voucher Injections','Voucher Injections',NULL,NULL,'INTEGER',0,'SUM',NULL,NULL,'TRACKER',NULL,'Voucher Injections',NULL,NULL); -INSERT INTO `DataElement` VALUES (29,'Qz3kfeKgLgL','DE_424054','Voucher IUCD','Voucher IUCD','2015-10-20T12:01:06.507','2015-10-20T12:04:25.234','Voucher IUCD','Voucher IUCD',NULL,NULL,'INTEGER',0,'SUM',NULL,NULL,'TRACKER',NULL,'Voucher IUCD',NULL,NULL); -INSERT INTO `DataElement` VALUES (30,'UwCXONyUtGs','DE_424055','Voucher Pills','Voucher Pills','2015-10-20T12:01:06.781','2015-10-20T12:04:34.920','Voucher Pills','Voucher Pills',NULL,NULL,'INTEGER',0,'SUM',NULL,NULL,'TRACKER',NULL,'Voucher Pills',NULL,NULL); -INSERT INTO `DataElement` VALUES (31,'HyJL2Lt37jN','DE_424056','Voucher VMMC','Voucher VMMC','2015-10-20T12:01:07.125','2015-10-20T12:04:42.991','Voucher VMMC','Voucher VMMC',NULL,NULL,'INTEGER',0,'SUM',NULL,NULL,'TRACKER',NULL,'Voucher VMMC',NULL,NULL); -INSERT INTO `DataElement` VALUES (32,'f3Rn9XPEQuv','DE_223562','IC Activity','IC Activity','2014-06-22T12:43:57.149','2014-11-11T21:56:05.396','IC Activity','IC Activity',NULL,NULL,'TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'IC Activity','s3GoZHCmXL2',NULL); -INSERT INTO `DataElement` VALUES (33,'Dv7iIitX44Y','DE_223563','IC Age','IC Age','2014-06-22T12:45:44.666','2014-11-11T21:56:05.398','IC Age','IC Age',NULL,NULL,'TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'IC Age','VQ2lai3OfVG',NULL); -INSERT INTO `DataElement` VALUES (34,'UuL3eX8KJHY','DE_223560','IC Group Type','IC Group Type','2014-06-22T11:01:11.134','2014-11-11T21:56:05.396','IC Group Type','IC Group Type',NULL,NULL,'TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'IC Group Type','PmE3Ev4ZcHX',NULL); -INSERT INTO `DataElement` VALUES (35,'deQEw93Vr4j','DE_223564','IC Topic','IC Topic','2014-06-22T12:46:29.705','2014-11-11T21:56:05.399','IC Topic','IC Topic',NULL,NULL,'TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'IC Topic','s3GoZHCmXL2',NULL); -INSERT INTO `DataElement` VALUES (36,'DvrjjquRrvF','DE_223561','IC Venue','IC Venue','2014-06-22T11:01:45.918','2014-11-11T21:56:05.397','IC Venue','IC Venue',NULL,NULL,'TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'IC Venue','Da7byW1wGzq',NULL); -INSERT INTO `DataElement` VALUES (37,'lsJCUffec9h','DE_223565','IC People reached','IC People reached','2014-06-22T12:47:05.114','2014-11-11T21:56:05.399','IC People reached','IC People reached',NULL,NULL,'INTEGER_POSITIVE',0,'AVERAGE','',NULL,'TRACKER',NULL,'IC People reached',NULL,NULL); -INSERT INTO `DataElement` VALUES (38,'oZg33kd9taw','DE_3000004','Gender','Gender','2012-11-14T13:11:55.105','2016-04-12T20:37:49.203','Gender','Gender','Gender of patient.','Gender of patient.','TEXT',0,'AVERAGE','Gender',NULL,'TRACKER',NULL,'Gender','pC3N9N77UmT',NULL); -INSERT INTO `DataElement` VALUES (39,'SWfdB5lX0fk','DE_423442','Pregnant','Pregnant','2015-08-09T15:58:26.391','2015-08-09T15:58:26.413','Pregnant','Pregnant',NULL,NULL,'BOOLEAN',0,'SUM','Pregnant',NULL,'TRACKER',NULL,'Pregnant',NULL,NULL); -INSERT INTO `DataElement` VALUES (40,'qrur9Dvnyt5','DE_3000003','Age in years','Age in years','2012-11-14T14:41:39.639','2017-06-02T11:41:14.500','Age in years','Age in years','Age of person in years.','Age of person in years.','INTEGER',0,'AVERAGE','Age (years)',NULL,'TRACKER',NULL,'Age (years)',NULL,NULL); -INSERT INTO `DataElement` VALUES (41,'GieVkTxp4HH','DE_240794','Height in cm','Height in cm','2015-03-31T10:27:46.069','2015-03-31T11:22:51.642','Height in cm','Height in cm',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'Height in cm',NULL,NULL); -INSERT INTO `DataElement` VALUES (42,'vV9UWAZohSf','DE_240795','Weight in kg','Weight in kg','2015-03-31T10:28:01.218','2015-08-02T17:24:16.351','Weight in kg','Weight in kg',NULL,NULL,'INTEGER_POSITIVE',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'Weight in kg',NULL,NULL); -INSERT INTO `DataElement` VALUES (43,'eMyVanycQSC','DE_3000005','Admission Date','Admission Date','2012-11-14T13:12:49.254','2014-11-11T21:56:05.406','Admission Date','Admission Date','Date of Admission of patient.','Date of Admission of patient.','DATE',0,'AVERAGE','Date of admission',NULL,'TRACKER',NULL,'Date of admission',NULL,NULL); -INSERT INTO `DataElement` VALUES (44,'msodh3rEMJa','DE_3000006','Discharge Date','Discharge Date','2012-11-14T13:13:29.977','2014-11-11T21:56:05.407','Discharge Date','Discharge Date','Date of discharge of patient.','Date of discharge of patient.','DATE',0,'AVERAGE','Date of discharge',NULL,'TRACKER',NULL,'Date of discharge',NULL,NULL); -INSERT INTO `DataElement` VALUES (45,'S33cRBsnXPo','DE_862347','Inpatient Place of Infection','Inpatient Place of Infection','2016-10-11T18:25:57.013','2016-10-11T18:25:57.013','Inpatient Place of Infection','Inpatient Place of Infection',NULL,NULL,'ORGANISATION_UNIT',0,'NONE','Place of Infection',NULL,'TRACKER',NULL,'Place of Infection',NULL,NULL); -INSERT INTO `DataElement` VALUES (46,'fWIAEtYVEGk','DE_3000009','Mode of Discharge','Mode of Discharge','2012-11-14T14:49:15.974','2014-11-11T21:56:05.405','Mode of Discharge','Mode of Discharge','How the patient was discharged.','How the patient was discharged.','TEXT',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'Mode of Discharge','iDFPKpFTiVw',NULL); -INSERT INTO `DataElement` VALUES (47,'K6uUAvq500H','DE_3000010','Diagnosis (ICD-10)','Diagnosis (ICD-10)','2012-11-14T14:05:43.397','2014-11-11T21:56:05.409','Diagnosis (ICD-10)','Diagnosis (ICD-10)','ICD-10 coded diagnosis.','ICD-10 coded diagnosis.','TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'Diagnosis (ICD-10)','eUZ79clX7y1',NULL); -INSERT INTO `DataElement` VALUES (48,'ulD2zW0TIy2','DE_424404','Documentation','Documentation','2016-01-15T18:13:00.541','2016-01-15T22:44:11.475','Documentation','Documentation',NULL,NULL,'FILE_RESOURCE',0,'SUM',NULL,NULL,'TRACKER',NULL,'Documentation',NULL,NULL); -INSERT INTO `DataElement` VALUES (49,'F3ogKBuviRA','DE_862575','Household location','Household location','2016-12-06T16:29:26.767','2016-12-06T16:37:06.280','Household location','Household location',NULL,NULL,'COORDINATE',0,'NONE',NULL,NULL,'TRACKER',NULL,'Household location',NULL,NULL); -INSERT INTO `DataElement` VALUES (50,'hKZh1et5n7v',NULL,'RDT test result','RDT test result','2017-05-22T16:06:59.431','2017-05-22T16:06:59.431','RDT test result','RDT test result',NULL,NULL,'TEXT',0,'NONE',NULL,NULL,'TRACKER',NULL,'RDT test result','MmrbR9vqscW',NULL); -INSERT INTO `DataElement` VALUES (51,'O7OiONht8T3',NULL,'Treatment Malaria','Treatment Malaria','2017-05-22T16:07:33.029','2017-05-22T16:07:33.029','Treatment Malaria','Treatment Malaria',NULL,NULL,'TEXT',0,'NONE','Treatment',NULL,'TRACKER',NULL,'Treatment','ku6syDAYWYV',NULL); -INSERT INTO `DataElement` VALUES (52,'utliJZmDeeC','DE_2008125','MCH MUAC','MCH MUAC','2012-09-20T16:03:22.890','2014-11-11T21:56:05.545','MUAC','MUAC','Mid Upper Arm Circumference','Mid Upper Arm Circumference','TEXT',0,'AVERAGE','MUAC',NULL,'TRACKER',NULL,'MUAC','qCOOnBxlkMz',NULL); -INSERT INTO `DataElement` VALUES (53,'KVQpGEjHluk','DE_2008153','MCH Blood Pressure','MCH Blood Pressure','2012-09-20T16:53:26.177','2014-11-11T21:56:05.440','BP','BP',NULL,NULL,'TEXT',0,'AVERAGE','BP',NULL,'TRACKER',NULL,'BP',NULL,NULL); -INSERT INTO `DataElement` VALUES (54,'jkKCVlLRsFD','DE_2005737','MCH PMTCT W','MCH PMTCT W','2012-09-20T08:45:38.437','2014-11-11T21:56:05.400','PMTCT W','PMTCT W',NULL,NULL,'TEXT',0,'AVERAGE','PMTCT W',NULL,'TRACKER',NULL,'PMTCT W','tQ8erv0xjs3',NULL); -INSERT INTO `DataElement` VALUES (55,'SMo8UtuSF5p','DE_2005738','MCH PMTCT P','MCH PMTCT P','2012-09-20T08:45:32.658','2014-11-11T21:56:05.551','PMTCT P','PMTCT P',NULL,NULL,'TEXT',0,'AVERAGE','PMTCT P',NULL,'TRACKER',NULL,'PMTCT P','tQ8erv0xjs3',NULL); -INSERT INTO `DataElement` VALUES (56,'XorIxxprsOp','DE_2006092','MCH CD4 count','MCH CD4 count','2012-09-20T08:41:31.031','2014-11-11T21:56:05.546','CD4 Count','CD4 Count',NULL,NULL,'NUMBER',0,'AVERAGE','CD4 Count',NULL,'TRACKER',NULL,'CD4 Count',NULL,NULL); -INSERT INTO `DataElement` VALUES (57,'DRGELgdyWk9','DE_2006091','MCH WHO Stage','MCH WHO Stage','2012-09-20T08:47:13.372','2014-11-11T21:56:05.401','WHO Stage','WHO Stage',NULL,NULL,'TEXT',0,'AVERAGE','WHO Stage',NULL,'TRACKER',NULL,'WHO Stage','IpRuNUVbhTz',NULL); -INSERT INTO `DataElement` VALUES (58,'NALlPhMmMTQ','DE_2005739','MCH ARVs','MCH ARVs','2012-09-20T08:37:10.729','2014-11-11T21:56:05.561','ARVs','ARVs',NULL,NULL,'TEXT',0,'AVERAGE','ARVs',NULL,'TRACKER',NULL,'ARVs','dgsftM0rXu2',NULL); -INSERT INTO `DataElement` VALUES (59,'wpKRnvM14KO','DE_2005740','MCH TB Status','MCH TB Status','2012-09-20T08:46:34.800','2014-11-11T21:56:05.543','TB Status','TB Status',NULL,NULL,'TEXT',0,'AVERAGE','TB Status',NULL,'TRACKER',NULL,'TB Status','zE2tXMHgoZU',NULL); -INSERT INTO `DataElement` VALUES (60,'xjTklbpY6oG','DE_2005741','MCH HB','MCH HB','2012-09-20T08:43:28.851','2014-11-11T21:56:05.422','HB','HB',NULL,NULL,'NUMBER',0,'AVERAGE','HB',NULL,'TRACKER',NULL,'HB',NULL,NULL); -INSERT INTO `DataElement` VALUES (61,'r0VOslrt2RP','DE_2005742','MCH Syphilis Test','MCH Syphilis Test','2012-09-20T08:46:28.602','2014-11-11T21:56:05.557','Syphilis Test','Syphilis Test',NULL,NULL,'TEXT',0,'AVERAGE','Syphilis Test',NULL,'TRACKER',NULL,'Syphilis Test','FkvSziHHUmZ',NULL); -INSERT INTO `DataElement` VALUES (62,'gAbD3uDVHHh','DE_2005743','MCH Tetatus','MCH Tetatus','2012-09-20T08:46:48.078','2014-11-11T21:56:05.744','Tetanus','Tetanus',NULL,NULL,'TEXT',0,'AVERAGE','Tetanus',NULL,'TRACKER',NULL,'Tetanus','YSaCD1K07iM',NULL); -INSERT INTO `DataElement` VALUES (63,'sMspMpbvDYI','DE_2005745','MCH ITN','MCH ITN','2012-09-20T08:45:13.801','2014-11-11T21:56:05.415','ITN','ITN',NULL,NULL,'TEXT',0,'AVERAGE','ITN',NULL,'TRACKER',NULL,'ITN','XdI8KRJiRoZ',NULL); -INSERT INTO `DataElement` VALUES (64,'pB5sL7Ts4fb','DE_2008154','MCH Mabendazole','MCH Mabendazole','2012-09-20T16:54:11.146','2014-11-11T21:56:05.563','Mabendazole','Mabendazole',NULL,NULL,'TEXT',0,'AVERAGE','Mabendazole',NULL,'TRACKER',NULL,'Mabendazole','XdI8KRJiRoZ',NULL); -INSERT INTO `DataElement` VALUES (65,'EzMxXuVww2z','DE_2008144','MCH Iron/Folic','MCH Iron/Folic','2012-09-20T16:47:23.963','2014-11-11T21:56:05.560','Iron/Folic','Iron/Folic',NULL,NULL,'TEXT',0,'AVERAGE','Fe/Folic',NULL,'TRACKER',NULL,'Fe/Folic','pVV5aunSFRO',NULL); -INSERT INTO `DataElement` VALUES (66,'g9eOBujte1U','DE_2005735','MCH ANC Visit','MCH ANC Visit','2012-09-20T08:36:46.552','2014-11-11T21:56:05.560','ANC Visit','ANC Visit',NULL,NULL,'TEXT',0,'AVERAGE','ANC Visit',NULL,'TRACKER',NULL,'ANC Visit','fUS7fy2HbaI',NULL); -INSERT INTO `DataElement` VALUES (67,'fIy3fOtkbdS','DE_2008164','MCH Mode of Delivery','MCH Mode of Delivery','2012-09-20T17:08:35.220','2014-11-11T21:56:05.558','Mode of Delivery','Mode of Delivery',NULL,NULL,'TEXT',0,'AVERAGE','Mode of Delivery',NULL,'TRACKER',NULL,'Mode of Delivery','pQW2iZcMb2d',NULL); -INSERT INTO `DataElement` VALUES (68,'uxRgo9bGWhX','DE_2006093','MCH Date of Delivery','MCH Date of Delivery','2012-09-20T08:42:51.299','2014-11-11T21:56:05.418','Date of Delivery','Date of Delivery','Date of delivery of the baby','Date of delivery of the baby','DATE',0,'AVERAGE','Date of Delivery',NULL,'TRACKER',NULL,'Date of Delivery',NULL,NULL); -INSERT INTO `DataElement` VALUES (69,'gvrK6CxWTcp','DE_2008166','MCH Management of 3rd stage','MCH Management of 3rd stage','2012-09-20T17:13:06.633','2014-11-11T21:56:05.597','3rd stage mgt','3rd stage mgt',NULL,NULL,'TEXT',0,'AVERAGE','Management 3rd stage',NULL,'TRACKER',NULL,'Management 3rd stage','vDQykDhxQVu',NULL); -INSERT INTO `DataElement` VALUES (70,'Rbv6wcblbxe','DE_2008177','MCH Condition of mother on discharge','MCH Condition of mother on discharge','2012-09-20T17:48:04.103','2015-08-06T13:06:31.021','Condition of mother on discharge','Condition of mother on discharge',NULL,NULL,'TEXT',0,'AVERAGE','Condition Mother Discharge',NULL,'TRACKER',NULL,'Condition Mother Discharge','HS9zgnYt2Ia',NULL); -INSERT INTO `DataElement` VALUES (71,'PuakB9BOtIV','DE_2008176','MCH Condition of baby on discharge','MCH Condition of baby on discharge','2012-09-20T17:54:39.785','2015-08-06T13:06:38.465','Condition of baby on discharge','Condition of baby on discharge',NULL,NULL,'TEXT',0,'AVERAGE','Condition Baby discharge',NULL,'TRACKER',NULL,'Condition Baby discharge','RCTaQUCuDbu',NULL); -INSERT INTO `DataElement` VALUES (72,'tLn2UVJJ9kO','DE_2008167','MCH Delivery Comment','MCH Delivery Comment','2012-09-20T17:31:24.039','2014-11-11T21:56:05.562','Delivery Comment','Delivery Comment',NULL,NULL,'LONG_TEXT',0,'AVERAGE','Delivery Comment (optional)',NULL,'TRACKER',NULL,'Delivery Comment (optional)',NULL,NULL); -INSERT INTO `DataElement` VALUES (73,'DBFcMGod0Wy','DE_2006094','MCH Family Planning','MCH Family Planning','2012-09-20T08:43:17.627','2014-11-11T21:56:05.552','Family Planning','Family Planning',NULL,NULL,'TEXT',0,'AVERAGE','Family Planning',NULL,'TRACKER',NULL,'Family Planning','js7iuBwl03u',NULL); -INSERT INTO `DataElement` VALUES (74,'thO0LN2i2OJ','DE_2006095','MCH Breast Status','MCH Breast Status','2012-09-20T08:40:45.498','2015-08-06T13:43:59.430','Status of the brest','Status of the brest',NULL,NULL,'TEXT',0,'AVERAGE','Breast Status',NULL,'TRACKER',NULL,'Breast Status','mRl1KGfKrpt',NULL); -INSERT INTO `DataElement` VALUES (75,'DWcWXE0xO2b','DE_2006096','MCH Cervix Status','MCH Cervix Status','2012-09-20T18:38:59.644','2014-11-11T21:56:05.600','Status of the cervix','Status of the cervix',NULL,NULL,'TEXT',0,'AVERAGE','Cervix Status',NULL,'TRACKER',NULL,'Cervix Status','C6wvZOqmAKI',NULL); -INSERT INTO `DataElement` VALUES (76,'ihOp58eRcG3','DE_2006097','MCH CTX','MCH CTX','2012-09-20T08:42:40.074','2014-11-11T21:56:05.544','CTX','CTX',NULL,NULL,'TEXT',0,'AVERAGE','CTX',NULL,'TRACKER',NULL,'CTX','XdI8KRJiRoZ',NULL); -INSERT INTO `DataElement` VALUES (77,'L9G6ZtxbfjG','DE_2008194','MCH Status of the Baby (PNC)','MCH Status of the Baby (PNC)','2012-09-20T18:43:33.441','2014-11-11T21:56:05.598','baby status PNC','baby status PNC',NULL,NULL,'TEXT',0,'AVERAGE','Status of baby',NULL,'TRACKER',NULL,'Status of baby','ClTONeEYrI3',NULL); -INSERT INTO `DataElement` VALUES (78,'qpQinIDQ6Uy','DE_217125','PFS Date of training (end of training)','PFS Date of training (end of training)','2014-04-25T18:05:10.856','2014-11-11T21:56:05.419','PFS Date of training','PFS Date of training',NULL,NULL,'DATE',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Date of training (end of training)',NULL,NULL); -INSERT INTO `DataElement` VALUES (79,'zNXca47AaTh','DE_217130','PFS End-of-training assessment - CAC counseling','PFS End-of-training assessment - CAC counseling','2014-04-25T18:05:10.861','2014-11-11T21:56:05.589','PFS End-of-training - CAC counseling','PFS End-of-training - CAC counseling',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - CAC counseling',NULL,NULL); -INSERT INTO `DataElement` VALUES (80,'fQMBEt42CSl','DE_217131','PFS End-of-training assessment - CAC MVA','PFS End-of-training assessment - CAC MVA','2014-04-25T18:05:10.863','2014-11-11T21:56:05.572','PFS End-of-training - CAC MVA','PFS End-of-training - CAC MVA',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - CAC MVA',NULL,NULL); -INSERT INTO `DataElement` VALUES (81,'PfSefJQpg5g','DE_217126','PFS End-of-training assessment - CC FP counseling','PFS End-of-training assessment - CC FP counseling','2014-04-25T18:05:10.857','2014-11-11T21:56:05.420','PFS End-of-training - CC FP counseling','PFS End-of-training - CC FP counseling',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - CC FP counseling',NULL,NULL); -INSERT INTO `DataElement` VALUES (82,'f2MduVqwPXO','DE_217128','PFS End-of-training assessment - CC Implanon insertion','PFS End-of-training assessment - CC Implanon insertion','2014-04-25T18:05:10.859','2014-11-11T21:56:05.571','PFS End-of-training - CC Implanon insertion','PFS End-of-training - CC Implanon insertion',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - CC Implanon insertion',NULL,NULL); -INSERT INTO `DataElement` VALUES (83,'GXNUsigphqK','DE_217129','PFS End-of-training assessment - CC IUCD insertion','PFS End-of-training assessment - CC IUCD insertion','2014-04-25T18:05:10.860','2014-11-11T21:56:05.572','PFS End-of-training - CC IUCD insertion','PFS End-of-training - CC IUCD insertion',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - CC IUCD insertion',NULL,NULL); -INSERT INTO `DataElement` VALUES (84,'ROEGWNaasDP','DE_217127','PFS End-of-training assessment - CC Jadelle insertion','PFS End-of-training assessment - CC Jadelle insertion','2014-04-25T18:05:10.858','2014-11-11T21:56:05.421','PFS End-of-training - CC Jadelle insertion','PFS End-of-training - CC Jadelle insertion',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - CC Jadelle insertion',NULL,NULL); -INSERT INTO `DataElement` VALUES (85,'Lh9x3J6EF0g','DE_217132','PFS End-of-training assessment - PM FP counseling','PFS End-of-training assessment - PM FP counseling','2014-04-25T18:05:10.865','2014-11-11T21:56:05.573','PFS End-of-training - PM FP counseling','PFS End-of-training - PM FP counseling',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - PM FP counseling',NULL,NULL); -INSERT INTO `DataElement` VALUES (86,'BLNHqFdGFRv','DE_217134','PFS End-of-training assessment - PM NSV','PFS End-of-training assessment - PM NSV','2014-04-25T18:05:10.868','2014-11-11T21:56:05.575','PFS End-of-training - PM NSV','PFS End-of-training - PM NSV',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - PM NSV',NULL,NULL); -INSERT INTO `DataElement` VALUES (87,'Y35b9mKPwgz','DE_217133','PFS End-of-training assessment - PM Suprapubic minilap','PFS End-of-training assessment - PM Suprapubic minilap','2014-04-25T18:05:10.867','2014-11-11T21:56:05.574','PFS End-of-training - PM Suprapubic minilap','PFS End-of-training - PM Suprapubic minilap',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - PM Suprapubic minilap',NULL,NULL); -INSERT INTO `DataElement` VALUES (88,'CtpjtJOlix1','DE_217135','PFS End-of-training assessment - PPIUD FP counseling','PFS End-of-training assessment - PPIUD FP counseling','2014-04-25T18:05:10.870','2014-11-11T21:56:05.576','PFS End-of-training - PPIUD FP counseling','PFS End-of-training - PPIUD FP counseling',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - PPIUD FP counseling',NULL,NULL); -INSERT INTO `DataElement` VALUES (89,'Kdj9bEhmtER','DE_217136','PFS End-of-training assessment - PPUID Postplacental IUCD','PFS End-of-training assessment - PPUID Postplacental IUCD','2014-04-25T18:05:10.871','2014-11-11T21:56:05.576','PFS End-of-training - PPUID Postplacental IUCD','PFS End-of-training - PPUID Postplacental IUCD',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS End-of-training assessment - PPUID Postplacental IUCD',NULL,NULL); -INSERT INTO `DataElement` VALUES (90,'bTWjEduOv4P','DE_217187','PFS Inadequate client recovery area','PFS Inadequate client recovery area','2014-04-25T18:05:10.926','2014-11-11T21:56:05.894','PFS Inadequate recovery area','PFS Inadequate recovery area',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate client recovery area',NULL,NULL); -INSERT INTO `DataElement` VALUES (91,'qlzHqClWAsG','DE_217188','PFS Inadequate client recovery area - Discussion with provider','PFS Inadequate client recovery area - Discussion with provider','2014-04-25T18:05:10.928','2014-11-11T21:56:05.594','PFS Inadequate recovery area - Discussion provider','PFS Inadequate recovery area - Discussion provider',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate client recovery area - Discussion with provider',NULL,NULL); -INSERT INTO `DataElement` VALUES (92,'D795f7Ftl5Z','DE_217180','PFS Inadequate counseling room','PFS Inadequate counseling room','2014-04-25T18:05:10.915','2014-11-11T21:56:05.593','PFS Inadequate couns room','PFS Inadequate couns room',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate counseling room',NULL,NULL); -INSERT INTO `DataElement` VALUES (93,'msiehvzdkh0','DE_217183','PFS Inadequate counseling room - Discussion with off-site management','PFS Inadequate counseling room - Discussion with off-site management','2014-04-25T18:05:10.918','2014-11-11T21:56:05.431','PFS Inadequate couns room - Discuss off-site mgmnt','PFS Inadequate couns room - Discuss off-site mgmnt',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate counseling room - Discussion with off-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (94,'qv3Ivgr7qA8','DE_217182','PFS Inadequate counseling room - Discussion with on-site management','PFS Inadequate counseling room - Discussion with on-site management','2014-04-25T18:05:10.917','2014-11-11T21:56:05.430','PFS Inadequate couns room - Discuss on-site mgmnt','PFS Inadequate couns room - Discuss on-site mgmnt',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate counseling room - Discussion with on-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (95,'OjGY9phCVkF','DE_217181','PFS Inadequate counseling room - Discussion with provider','PFS Inadequate counseling room - Discussion with provider','2014-04-25T18:05:10.916','2014-11-11T21:56:05.429','PFS Inadequate couns room - Discuss provider','PFS Inadequate couns room - Discuss provider',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate counseling room - Discussion with provider',NULL,NULL); -INSERT INTO `DataElement` VALUES (96,'hFbuuBkjut3','DE_217184','PFS Inadequate procedure room','PFS Inadequate procedure room','2014-04-25T18:05:10.920','2014-11-11T21:56:05.517','PFS Inadequate procedure room','PFS Inadequate procedure room',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate procedure room',NULL,NULL); -INSERT INTO `DataElement` VALUES (97,'kSDiqFhUP8P','DE_217186','PFS Inadequate procedure room - Discussion with off-site management','PFS Inadequate procedure room - Discussion with off-site management','2014-04-25T18:05:10.924','2014-11-11T21:56:05.894','PFS Inadequate procedure room - Discuss off-site m','PFS Inadequate procedure room - Discuss off-site m',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate procedure room - Discussion with off-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (98,'zJer0XIW5fV','DE_217185','PFS Inadequate procedure room - Discussion with on-site management','PFS Inadequate procedure room - Discussion with on-site management','2014-04-25T18:05:10.922','2014-11-11T21:56:05.518','PFS Inadequate procedure room - Discuss on-site mg','PFS Inadequate procedure room - Discuss on-site mg',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Inadequate procedure room - Discussion with on-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (99,'zF6StgsGthD','DE_217173','PFS Lack of clinical knowledge','PFS Lack of clinical knowledge','2014-04-25T18:05:10.906','2014-11-11T21:56:05.593','PFS Lack of clinical knowledge','PFS Lack of clinical knowledge',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical knowledge',NULL,NULL); -INSERT INTO `DataElement` VALUES (100,'DgluqT5CbIp','DE_217174','PFS Lack of clinical knowledge - Clinical coaching','PFS Lack of clinical knowledge - Clinical coaching','2014-04-25T18:05:10.907','2014-11-11T21:56:05.425','PFS Lack of clinical knowledge - Clinical coaching','PFS Lack of clinical knowledge - Clinical coaching',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical knowledge - Clinical coaching',NULL,NULL); -INSERT INTO `DataElement` VALUES (101,'OKN6ZG1z7pq','DE_217175','PFS Lack of clinical knowledge - Knowledge update/orientation','PFS Lack of clinical knowledge - Knowledge update/orientation','2014-04-25T18:05:10.908','2014-11-11T21:56:05.426','PFS Lack of clinical knowledge - Knowledge update','PFS Lack of clinical knowledge - Knowledge update',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical knowledge - Knowledge update/orientation',NULL,NULL); -INSERT INTO `DataElement` VALUES (102,'ZpvFqxRhFuP','DE_217176','PFS Lack of clinical knowledge - Provision of reference materials','PFS Lack of clinical knowledge - Provision of reference materials','2014-04-25T18:05:10.909','2014-11-11T21:56:05.584','PFS Lack of clinical knowledge - Reference mater','PFS Lack of clinical knowledge - Reference mater',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical knowledge - Provision of reference materials',NULL,NULL); -INSERT INTO `DataElement` VALUES (103,'Q6vysZzUoPl','DE_217165','PFS Lack of clinical skill','PFS Lack of clinical skill','2014-04-25T18:05:10.898','2014-11-11T21:56:05.590','PFS Lack of clinical skill','PFS Lack of clinical skill',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical skill',NULL,NULL); -INSERT INTO `DataElement` VALUES (104,'ogBU5CfbAUZ','DE_217168','PFS Lack of clinical skill - Arrangement exchange visit high caseload site','PFS Lack of clinical skill - Arrangement exchange visit high caseload site','2014-04-25T18:05:10.901','2014-11-11T21:56:05.592','PFS Lack of clinical skill - Exchange visit','PFS Lack of clinical skill - Exchange visit',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical skill - Arrangement exchange visit high caseload site',NULL,NULL); -INSERT INTO `DataElement` VALUES (105,'z8Ay2GaaqpC','DE_217167','PFS Lack of clinical skill - Arrangement for peer mentoring on-site','PFS Lack of clinical skill - Arrangement for peer mentoring on-site','2014-04-25T18:05:10.900','2014-11-11T21:56:05.591','PFS Lack of clinical skill - Peer ment','PFS Lack of clinical skill - Peer ment',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical skill - Arrangement for peer mentoring on-site',NULL,NULL); -INSERT INTO `DataElement` VALUES (106,'lJSMLN5WRDF','DE_217166','PFS Lack of clinical skill - Clinical coaching','PFS Lack of clinical skill - Clinical coaching','2014-04-25T18:05:10.899','2014-11-11T21:56:05.591','PFS Lack of clinical skill - Clinical coaching','PFS Lack of clinical skill - Clinical coaching',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical skill - Clinical coaching',NULL,NULL); -INSERT INTO `DataElement` VALUES (107,'dGdEEpNb7GW','DE_217178','PFS Lack of clinical standards - Discussion with off-site management','PFS Lack of clinical standards - Discussion with off-site management','2014-04-25T18:05:10.912','2014-11-11T21:56:05.585','PFS Lack of clinical standards - Discuss off-site','PFS Lack of clinical standards - Discuss off-site',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical standards - Discussion with off-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (108,'uHkibfGqtXg','DE_217177','PFS Lack of clinical standards - Discussion with on-site management','PFS Lack of clinical standards - Discussion with on-site management','2014-04-25T18:05:10.911','2014-11-11T21:56:05.584','PFS Lack of clinical standards - Discuss on-site','PFS Lack of clinical standards - Discuss on-site',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical standards - Discussion with on-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (109,'HpC2iqyoMR8','DE_217179','PFS Lack of clinical standards - Provision of job aids/guidelines','PFS Lack of clinical standards - Provision of job aids/guidelines','2014-04-25T18:05:10.913','2014-11-11T21:56:05.586','PFS Lack of clinical standards - Job aids','PFS Lack of clinical standards - Job aids',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical standards - Provision of job aids/guidelines',NULL,NULL); -INSERT INTO `DataElement` VALUES (110,'fgPOFbi37BM','DE_217169','PFS Lack of confidence','PFS Lack of confidence','2014-04-25T18:05:10.901','2014-11-11T21:56:05.582','PFS Lack of confidence','PFS Lack of confidence',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of confidence',NULL,NULL); -INSERT INTO `DataElement` VALUES (111,'VDxTE7l7sc7','DE_217171','PFS Lack of confidence - Arrangement for peer mentoring on-site','PFS Lack of confidence - Arrangement for peer mentoring on-site','2014-04-25T18:05:10.903','2014-11-11T21:56:05.423','PFS Lack of confidence - Peer mentoring','PFS Lack of confidence - Peer mentoring',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of confidence - Arrangement for peer mentoring on-site',NULL,NULL); -INSERT INTO `DataElement` VALUES (112,'Ws36Dp6gHA1','DE_217170','PFS Lack of confidence - Clinical coaching','PFS Lack of confidence - Clinical coaching','2014-04-25T18:05:10.902','2014-11-11T21:56:05.583','PFS Lack of confidence - Clinical coaching','PFS Lack of confidence - Clinical coaching',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of confidence - Clinical coaching',NULL,NULL); -INSERT INTO `DataElement` VALUES (113,'KRJeVOPBy6t','DE_217172','PFS Lack of confidence - Encouragement','PFS Lack of confidence - Encouragement','2014-04-25T18:05:10.904','2014-11-11T21:56:05.424','PFS Lack of confidence - Encouragement','PFS Lack of confidence - Encouragement',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of confidence - Encouragement',NULL,NULL); -INSERT INTO `DataElement` VALUES (114,'IgkWhfPryqt','DE_217160','PFS Provider provision challenges - CAC','PFS Provider provision challenges - CAC','2014-04-25T18:05:10.893','2014-11-11T21:56:05.579','PFS Provider provision challenges - CAC','PFS Provider provision challenges - CAC',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Provider provision challenges - CAC',NULL,NULL); -INSERT INTO `DataElement` VALUES (115,'Q5725FPinzH','DE_217163','PFS Provider provision challenges - FS','PFS Provider provision challenges - FS','2014-04-25T18:05:10.896','2014-11-11T21:56:05.582','PFS Provider provision challenges - FS','PFS Provider provision challenges - FS',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Provider provision challenges - FS',NULL,NULL); -INSERT INTO `DataElement` VALUES (116,'ihgI4dDwUQT','DE_217159','PFS Provider provision challenges - Implant','PFS Provider provision challenges - Implant','2014-04-25T18:05:10.892','2014-11-11T21:56:05.579','PFS Provider provision challenges - Implant','PFS Provider provision challenges - Implant',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Provider provision challenges - Implant',NULL,NULL); -INSERT INTO `DataElement` VALUES (117,'AVC7oJYrZrk','DE_217158','PFS Provider provision challenges - IUD','PFS Provider provision challenges - IUD','2014-04-25T18:05:10.891','2014-11-11T21:56:05.578','PFS Provider provision challenges - IUD','PFS Provider provision challenges - IUD',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Provider provision challenges - IUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (118,'WMhpzP6czRF','DE_217164','PFS Provider provision challenges - NSV','PFS Provider provision challenges - NSV','2014-04-25T18:05:10.897','2014-11-11T21:56:05.589','PFS Provider provision challenges - NSV','PFS Provider provision challenges - NSV',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Provider provision challenges - NSV',NULL,NULL); -INSERT INTO `DataElement` VALUES (119,'ZhGKg3ssbmX','DE_217161','PFS Provider provision challenges - PAFP','PFS Provider provision challenges - PAFP','2014-04-25T18:05:10.894','2014-11-11T21:56:05.580','PFS Provider provision challenges - PAFP','PFS Provider provision challenges - PAFP',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Provider provision challenges - PAFP',NULL,NULL); -INSERT INTO `DataElement` VALUES (120,'UoRMWhj2YIy','DE_217162','PFS Provider provision challenges - PPIUD','PFS Provider provision challenges - PPIUD','2014-04-25T18:05:10.895','2014-11-11T21:56:05.581','PFS Provider provision challenges - PPIUD','PFS Provider provision challenges - PPIUD',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Provider provision challenges - PPIUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (121,'pharIEKZNo0','DE_217139','PFS Service provision 0 - CAC','PFS Service provision 0 - CAC','2014-04-25T18:05:10.874','2014-11-11T21:56:05.798','PFS Service provision 0 - CAC','PFS Service provision 0 - CAC',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 0 - CAC',NULL,NULL); -INSERT INTO `DataElement` VALUES (122,'IZSvH4lOb1h','DE_217142','PFS Service provision 0 - FS','PFS Service provision 0 - FS','2014-04-25T18:05:10.877','2014-11-11T21:56:05.800','PFS Service provision 0 - FS','PFS Service provision 0 - FS',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 0 - FS',NULL,NULL); -INSERT INTO `DataElement` VALUES (123,'DcsUXIcK8IJ','DE_217138','PFS Service provision 0 - Implant','PFS Service provision 0 - Implant','2014-04-25T18:05:10.873','2014-11-11T21:56:05.805','PFS Service provision 0 - Implant','PFS Service provision 0 - Implant',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 0 - Implant',NULL,NULL); -INSERT INTO `DataElement` VALUES (124,'rxTX7yNs8Ph','DE_217137','PFS Service provision 0 - IUD','PFS Service provision 0 - IUD','2014-04-25T18:05:10.872','2014-11-11T21:56:05.805','PFS Service provision 0 - IUD','PFS Service provision 0 - IUD',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 0 - IUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (125,'ypvDEOvkjTx','DE_217143','PFS Service provision 0 - NSV','PFS Service provision 0 - NSV','2014-04-25T18:05:10.878','2014-11-11T21:56:05.801','PFS Service provision 0 - NSV','PFS Service provision 0 - NSV',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 0 - NSV',NULL,NULL); -INSERT INTO `DataElement` VALUES (126,'SayYGlKyPCa','DE_217140','PFS Service provision 0 - PA FP','PFS Service provision 0 - PA FP','2014-04-25T18:05:10.875','2014-11-11T21:56:05.799','PFS Service provision 0 - PA FP','PFS Service provision 0 - PA FP',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 0 - PA FP',NULL,NULL); -INSERT INTO `DataElement` VALUES (127,'ASvofuem7Oa','DE_217141','PFS Service provision 0 - PPIUD','PFS Service provision 0 - PPIUD','2014-04-25T18:05:10.877','2014-11-11T21:56:05.933','PFS Service provision 0 - PPIUD','PFS Service provision 0 - PPIUD',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 0 - PPIUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (128,'M3H9NEMuBix','DE_217146','PFS Service provision 1 - CAC','PFS Service provision 1 - CAC','2014-04-25T18:05:10.881','2014-11-11T21:56:05.907','PFS Service provision 1 - CAC','PFS Service provision 1 - CAC',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 1 - CAC',NULL,NULL); -INSERT INTO `DataElement` VALUES (129,'hca8vQ6jEST','DE_217149','PFS Service provision 1 - FS','PFS Service provision 1 - FS','2014-04-25T18:05:10.884','2014-11-11T21:56:05.521','PFS Service provision 1 - FS','PFS Service provision 1 - FS',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 1 - FS',NULL,NULL); -INSERT INTO `DataElement` VALUES (130,'SKh80FGIVKI','DE_217145','PFS Service provision 1 - Implant','PFS Service provision 1 - Implant','2014-04-25T18:05:10.880','2014-11-11T21:56:05.802','PFS Service provision 1 - Implant','PFS Service provision 1 - Implant',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 1 - Implant',NULL,NULL); -INSERT INTO `DataElement` VALUES (131,'MUOpAoXRVX9','DE_217144','PFS Service provision 1 - IUD','PFS Service provision 1 - IUD','2014-04-25T18:05:10.879','2014-11-11T21:56:05.801','PFS Service provision 1 - IUD','PFS Service provision 1 - IUD',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 1 - IUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (132,'bCBiRLqLjQl','DE_217150','PFS Service provision 1 - NSV','PFS Service provision 1 - NSV','2014-04-25T18:05:10.884','2014-11-11T21:56:05.796','PFS Service provision 1 - NSV','PFS Service provision 1 - NSV',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 1 - NSV',NULL,NULL); -INSERT INTO `DataElement` VALUES (133,'vsKP6aojcqL','DE_217147','PFS Service provision 1 - PA FP','PFS Service provision 1 - PA FP','2014-04-25T18:05:10.882','2014-11-11T21:56:05.519','PFS Service provision 1 - PA FP','PFS Service provision 1 - PA FP',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 1 - PA FP',NULL,NULL); -INSERT INTO `DataElement` VALUES (134,'njV5usO9oNl','DE_217148','PFS Service provision 1 - PPIUD','PFS Service provision 1 - PPIUD','2014-04-25T18:05:10.883','2014-11-11T21:56:05.520','PFS Service provision 1 - PPIUD','PFS Service provision 1 - PPIUD',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 1 - PPIUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (135,'t9NU3SqPvcN','DE_217153','PFS Service provision 2 - CAC','PFS Service provision 2 - CAC','2014-04-25T18:05:10.887','2014-11-11T21:56:05.523','PFS Service provision 2 - CAC','PFS Service provision 2 - CAC',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 2 - CAC',NULL,NULL); -INSERT INTO `DataElement` VALUES (136,'zff1i2Iwk8S','DE_217156','PFS Service provision 2 - FS','PFS Service provision 2 - FS','2014-04-25T18:05:10.889','2014-11-11T21:56:05.803','PFS Service provision 2- FS','PFS Service provision 2- FS',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 2 - FS',NULL,NULL); -INSERT INTO `DataElement` VALUES (137,'PKBFrGgUy26','DE_217152','PFS Service provision 2 - Implant','PFS Service provision 2 - Implant','2014-04-25T18:05:10.886','2014-11-11T21:56:05.522','PFS Service provision 2 - Implant','PFS Service provision 2 - Implant',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 2 - Implant',NULL,NULL); -INSERT INTO `DataElement` VALUES (138,'pWpQ69deqiv','DE_217151','PFS Service provision 2 - IUD','PFS Service provision 2 - IUD','2014-04-25T18:05:10.885','2014-11-11T21:56:05.797','PFS Service provision 2 - IUD','PFS Service provision 2 - IUD',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 2 - IUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (139,'QKujt9JlJfn','DE_217157','PFS Service provision 2 - NSV','PFS Service provision 2 - NSV','2014-04-25T18:05:10.890','2014-11-11T21:56:05.804','PFS Service provision 2 - NSV','PFS Service provision 2 - NSV',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 2 - NSV',NULL,NULL); -INSERT INTO `DataElement` VALUES (140,'JSovKG6FZNW','DE_217154','PFS Service provision 2 - PA FP','PFS Service provision 2 - PA FP','2014-04-25T18:05:10.888','2014-11-11T21:56:05.524','PFS Service provision 2 - PA FP','PFS Service provision 2 - PA FP',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 2 - PA FP',NULL,NULL); -INSERT INTO `DataElement` VALUES (141,'cOXBak6pilm','DE_217155','PFS Service provision 2 - PPIUD','PFS Service provision 2 - PPIUD','2014-04-25T18:05:10.888','2014-11-11T21:56:05.803','PFS Service provision 2 - PPIUD','PFS Service provision 2 - PPIUD',NULL,NULL,'NUMBER',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Service provision 2 - PPIUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (142,'wqH05wytdJH','DE_217124','PFS Type of training - CC','PFS Type of training - CC','2014-04-25T18:05:10.845','2014-11-11T21:56:05.427','PFS Type of training - CC','PFS Type of training - CC',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Type of training - CC',NULL,NULL); -INSERT INTO `DataElement` VALUES (143,'yqiAt2vL2Oe','DE_217194','PFS Type of training - CAC','PFS Type of training - CAC','2014-04-25T19:18:30.671','2014-11-11T21:56:05.588','PFS Type of training - CAC','PFS Type of training - CAC',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Type of training - CAC',NULL,NULL); -INSERT INTO `DataElement` VALUES (144,'Ef3ueStqxJj','DE_217196','PFS Type of training - CC (OJT)','PFS Type of training - CC (OJT)','2014-04-25T19:18:30.674','2014-11-11T21:56:05.587','PFS Type of training - CC (OJT)','PFS Type of training - CC (OJT)',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Type of training - CC (OJT)',NULL,NULL); -INSERT INTO `DataElement` VALUES (145,'gtYt3KpQpW8','DE_217197','PFS Type of training - PM','PFS Type of training - PM','2014-04-25T19:18:30.675','2014-11-11T21:56:05.587','PFS Type of training - PM','PFS Type of training - PM',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Type of training - PM',NULL,NULL); -INSERT INTO `DataElement` VALUES (146,'suMqFd2seuA','DE_217195','PFS Type of training - PPIUD','PFS Type of training - PPIUD','2014-04-25T19:18:30.673','2014-11-11T21:56:05.577','PFS Type of training - PPIUD','PFS Type of training - PPIUD',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Type of training - PPIUD',NULL,NULL); -INSERT INTO `DataElement` VALUES (147,'GFDKf2idXLV','DE_217210','PFS Method of contact','PFS Method of contact','2014-04-29T16:44:20.457','2014-11-11T21:56:05.621','PFS Method of contact','PFS Method of contact',NULL,NULL,'TEXT',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Method of contact','VDVbkOVFbbT',NULL); -INSERT INTO `DataElement` VALUES (148,'e4EMaGSEyV9','DE_217211','PFS Name of person conducting follow-up','PFS Name of person conducting follow-up','2014-04-29T16:48:35.617','2014-11-11T21:56:05.622','PFS Name of person conducting follow-up','PFS Name of person conducting follow-up',NULL,NULL,'TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'PFS Name of person conducting follow-up',NULL,NULL); -INSERT INTO `DataElement` VALUES (149,'Mnkodq2wzlV','DE_217212','PFS Visit number','PFS Visit number','2014-04-29T16:48:45.870','2014-11-11T21:56:05.622','PFS Visit number','PFS Visit number',NULL,NULL,'TEXT',0,'AVERAGE','',NULL,'TRACKER',NULL,'PFS Visit number',NULL,NULL); -INSERT INTO `DataElement` VALUES (150,'LDEqL9GokCM','DE_217213','PFS Lack of clinical standards','PFS Lack of clinical standards','2014-04-29T17:29:54.478','2014-11-11T21:56:05.623','PFS Lack of clinical standards','PFS Lack of clinical standards',NULL,NULL,'TRUE_ONLY',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'PFS Lack of clinical standards',NULL,NULL); -INSERT INTO `DataElement` VALUES (151,'uYrt6Rjh0q2','DE_217215','PFS Inadequate client recovery area - Discussion off-site management','PFS Inadequate client recovery area - Discussion off-site management','2014-04-29T17:38:00.021','2014-11-11T21:56:05.625','PFS Inadequate recovery area - Discuss off-site mg','PFS Inadequate recovery area - Discuss off-site mg',NULL,NULL,'TRUE_ONLY',0,'AVERAGE','',NULL,'TRACKER',NULL,'PFS Inadequate client recovery area - Discussion off-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (152,'lsPerCow7QG','DE_217214','PFS Inadequate client recovery area - Discussion on-site management','PFS Inadequate client recovery area - Discussion on-site management','2014-04-29T17:37:29.745','2014-11-11T21:56:05.624','PFS Inadequate recovery area - Discuss on-site mgm','PFS Inadequate recovery area - Discuss on-site mgm',NULL,NULL,'TRUE_ONLY',0,'AVERAGE','',NULL,'TRACKER',NULL,'PFS Inadequate client recovery area - Discussion on-site management',NULL,NULL); -INSERT INTO `DataElement` VALUES (153,'Vk1tzSQxvOR','DE_860004','TB lab CD4','TB lab CD4','2016-06-28T13:27:14.686','2016-06-28T13:27:14.686','TB lab CD4','TB lab CD4',NULL,NULL,'TRUE_ONLY',0,'NONE','CD4',NULL,'TRACKER',NULL,'CD4',NULL,NULL); -INSERT INTO `DataElement` VALUES (154,'fCXKBdc27Bt','DE_860001','TB lab Creatinine','TB lab Creatinine','2016-06-28T13:24:55.554','2016-06-28T13:26:49.368','TB lab Creatinine','TB lab Creatinine',NULL,NULL,'TRUE_ONLY',0,'NONE','Creatinine',NULL,'TRACKER',NULL,'Creatinine',NULL,NULL); -INSERT INTO `DataElement` VALUES (155,'lJTx9EZ1dk1','DE_860003','Tb lab Glucose','Tb lab Glucose','2016-06-28T13:26:34.109','2016-06-28T13:26:34.109','Tb lab Glucose','Tb lab Glucose',NULL,NULL,'TRUE_ONLY',0,'NONE','Glucose',NULL,'TRACKER',NULL,'Glucose',NULL,NULL); -INSERT INTO `DataElement` VALUES (156,'fTZFU8cWvb3','DE_860002','TB lab Hemoglobin','TB lab Hemoglobin','2016-06-28T13:25:38.351','2016-06-28T13:25:38.351','TB lab Hemoglobin','TB lab Hemoglobin',NULL,NULL,'TRUE_ONLY',0,'NONE','Hemoglobin',NULL,'TRACKER',NULL,'Hemoglobin',NULL,NULL); -INSERT INTO `DataElement` VALUES (157,'D7m8vpzxHDJ','DE_1150453','TB Disease Classification','TB Disease Classification','2012-11-21T11:34:45.078','2014-11-11T21:56:05.411','TB Disease Class.','TB Disease Class.',NULL,NULL,'TEXT',0,'AVERAGE','Disease Classification',NULL,'TRACKER',NULL,'Disease Classification','isYOcVDBgJo',NULL); -INSERT INTO `DataElement` VALUES (158,'HmkXnHJxcD1','DE_1150454','TB Case Definition','TB Case Definition','2012-11-21T11:35:11.146','2016-08-03T23:02:49.456','TB Case Definition','TB Case Definition',NULL,NULL,'TEXT',0,'NONE','',NULL,'TRACKER',NULL,'TB Case Definition','F9ypN9t9NUy',NULL); -INSERT INTO `DataElement` VALUES (159,'lpHeSOA8GUV','DE_860596','TB treatment card','TB treatment card','2016-08-03T18:16:12.802','2016-08-03T18:16:12.802','TB treatment card','TB treatment card',NULL,NULL,'FILE_RESOURCE',0,'NONE','Treatment card',NULL,'TRACKER',NULL,'Treatment card',NULL,NULL); -INSERT INTO `DataElement` VALUES (160,'vAzDOljIN1o','TB Previous use of second- line drugs','TB Previous use of second-line drugs','TB Previous use of second-line drugs','2016-08-03T18:31:09.070','2016-08-03T22:59:18.440','TB Previous use of second- line drugs','TB Previous use of second- line drugs',NULL,NULL,'TRUE_ONLY',0,'NONE','Previous use of second- line drugs?',NULL,'TRACKER',NULL,'Previous use of second- line drugs?',NULL,NULL); -INSERT INTO `DataElement` VALUES (161,'zJbnrm3kUAk','DE_860623','TB Started on ART','TB Started on ART','2016-08-03T22:55:03.857','2016-08-03T22:55:03.857','TB Started on ART','TB Started on ART',NULL,NULL,'TRUE_ONLY',0,'NONE','Started on ART?',NULL,'TRACKER',NULL,'Started on ART?',NULL,NULL); -INSERT INTO `DataElement` VALUES (162,'P6hgV2tSIvi','DE_860624','TB Started on CPT','TB Started on CPT','2016-08-03T22:55:28.986','2016-08-03T22:56:32.537','TB Started on CPT','TB Started on CPT',NULL,NULL,'TRUE_ONLY',0,'NONE','Started on CPT?',NULL,'TRACKER',NULL,'Started on CPT?',NULL,NULL); -INSERT INTO `DataElement` VALUES (163,'U5ubm6PPYrM','DE_860610','TB HIV testing done','TB HIV testing done','2016-08-03T18:30:37.949','2016-08-03T18:30:37.949','TB HIV testing done','TB HIV testing done',NULL,NULL,'BOOLEAN',0,'NONE','HIV testing done',NULL,'TRACKER',NULL,'HIV testing done',NULL,NULL); -INSERT INTO `DataElement` VALUES (164,'yLIPuJHRgey','DE_859997','TB smear microscopy number of specimen','TB smear microscopy number of specimen','2016-06-28T12:55:16.162','2016-06-28T12:55:16.162','TB smear microscopy number of specimen','TB smear microscopy number of specimen',NULL,NULL,'INTEGER_POSITIVE',0,'NONE',NULL,NULL,'TRACKER',NULL,'TB smear microscopy number of specimen',NULL,NULL); -INSERT INTO `DataElement` VALUES (165,'zocHNQIQBIN','','TB smear microscopy test outcome','TB smear microscopy test outcome','2016-06-28T12:51:30.636','2016-07-04T15:34:19.082','TB smear microscopy test outcome','TB smear microscopy test outcome',NULL,NULL,'TEXT',0,'NONE',NULL,NULL,'TRACKER',NULL,'TB smear microscopy test outcome','Im9PtRGpdDW',NULL); -INSERT INTO `DataElement` VALUES (166,'mrVkW9h2Rdp','MMD_OBS_OUT','WHOMCH Previous pregnancy outcomes','WHOMCH Previous pregnancy outcomes','2013-12-22T12:59:06.806','2015-10-14T13:36:20.966','Previous pregnancy outcomes','Previous pregnancy outcomes',NULL,NULL,'TEXT',0,'SUM','Outcome',NULL,'TRACKER',NULL,'Outcome','VFR0v2vRhlE',NULL); -INSERT INTO `DataElement` VALUES (167,'W4zW3aPyS0G','MMD_OBS_DEL','WHOMCH Previous modes of delivery','WHOMCH Previous modes of delivery','2013-12-22T12:59:39.726','2015-10-14T13:36:20.082','Previous modes of delivery','Previous modes of delivery',NULL,NULL,'TEXT',0,'SUM','Mode of delivery',NULL,'TRACKER',NULL,'Mode of delivery','jAyXdHaxGiH',NULL); -INSERT INTO `DataElement` VALUES (168,'iwNXUX6KYX0','OBS_BIRTHWEIGHT','WHOMCH Previous pregnacy birthweight','WHOMCH Previous pregnacy birthweight','2015-05-06T05:26:06.439','2015-10-14T13:36:43.446','Previous pregnacy birthweight','Previous pregnacy birthweight',NULL,NULL,'NUMBER',0,'SUM','Birthweight',NULL,'TRACKER',NULL,'Birthweight',NULL,NULL); -INSERT INTO `DataElement` VALUES (169,'wqpUVEeJR3D','OBS_GEST_AGE','WHOMCH Previous pregnancy gest.age at birth','WHOMCH Previous pregnancy gest.age at birth','2015-05-06T05:25:25.796','2015-10-14T13:36:40.508','Previous pregnancy gest.age at birth','Previous pregnancy gest.age at birth',NULL,NULL,'NUMBER',0,'SUM','Gest. age at birth',NULL,'TRACKER',NULL,'Gest. age at birth',NULL,NULL); -INSERT INTO `DataElement` VALUES (170,'suhLG4CrzUw','MMD_OBS_CON','WHOMCH Conditions in previous pregnancy','WHOMCH Conditions in previous pregnancy','2013-11-29T21:32:38.086','2015-10-14T13:36:19.207','Conditions in previous pregnancy','Conditions in previous pregnancy',NULL,NULL,'TEXT',0,'SUM','Conditions',NULL,'TRACKER',NULL,'Conditions','i65CmiT6dKV',NULL); -INSERT INTO `DataElement` VALUES (171,'OhcR0fpFcWa','EA6_TRE_SYP1','WHOMCH Penicillin given','WHOMCH Penicillin given','2013-10-31T12:15:08.809','2015-10-14T13:36:46.528','Penicillin given','Penicillin given','For syphilis: Give benzathine benzylpenicillin; 2,4 million units in 5 ml IM, as two injections at separate sites. If allergic to penicillin, give erythromycin 500 mg (2x250 mg tablets) every 6 hours for 15 days.','For syphilis: Give benzathine benzylpenicillin; 2,4 million units in 5 ml IM, as two injections at separate sites. If allergic to penicillin, give erythromycin 500 mg (2x250 mg tablets) every 6 hours for 15 days.','TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Penicillin given',NULL,NULL); -INSERT INTO `DataElement` VALUES (172,'cKBSkBB3Mt4','EA8c_TRE_HYP','WHOMCH Antihypertensive drug given','WHOMCH Antihypertensive drug given','2013-12-23T12:46:55.833','2015-10-14T13:36:37.403','Antihypertensive drug given','Antihypertensive drug given','Accepted antihypertensiv drugs include hydralazine, alpha methyldopa, beta blockers (incl labetolol) and nifedipine.','Accepted antihypertensiv drugs include hydralazine, alpha methyldopa, beta blockers (incl labetolol) and nifedipine.','BOOLEAN',0,'SUM','Antihypertensive drug given according to national guidelines',NULL,'TRACKER',NULL,'Antihypertensive drug given according to national guidelines',NULL,NULL); -INSERT INTO `DataElement` VALUES (173,'nhW3SZX9JaN','TRE_HIV_ARV','WHOMCH Ongoing or initiated ARV regimen','WHOMCH Ongoing or initiated ARV regimen','2013-12-23T11:07:30.508','2015-10-14T13:36:42.277','Ongoing or initiated ARV regimen','Ongoing or initiated ARV regimen','Appropriate antiretroviral regimen according to local protocol should be used.','Appropriate antiretroviral regimen according to local protocol should be used.','TEXT',0,'COUNT',NULL,NULL,'TRACKER',NULL,'WHOMCH Ongoing or initiated ARV regimen','R3mpvjqJ81H',NULL); -INSERT INTO `DataElement` VALUES (174,'PKZPVfAJfHD','EA8a_TRE_CAL','WHOMCH Calcium supplements given ','WHOMCH Calcium supplements given ','2013-11-29T21:41:28.287','2015-10-14T13:36:08.430','Calcium supplements given ','Calcium supplements given ','In areas where dietary calcium intake is low, calcium supplementation during pregnancy (1.5-2.0 elemental calcium/day) is strongly recommended, moderate quality-evidence.','In areas where dietary calcium intake is low, calcium supplementation during pregnancy (1.5-2.0 elemental calcium/day) is strongly recommended, moderate quality-evidence.','BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Calcium supplements given ',NULL,NULL); -INSERT INTO `DataElement` VALUES (175,'Itl05OEupgQ','LAB_HIV','WHOMCH HIV rapid test','WHOMCH HIV rapid test','2013-11-29T21:43:39.044','2015-10-14T13:36:11.895','HIV rapid test','HIV rapid test',NULL,NULL,'TEXT',0,'SUM','HIV test result',NULL,'TRACKER',NULL,'HIV test result','J7nRCGjOtRa',NULL); -INSERT INTO `DataElement` VALUES (176,'YKXci7Sm0Zq','EA_EDD_CLI','WHOMCH Clinical estimate of due date','WHOMCH Clinical estimate of due date','2015-01-12T14:16:25.636','2015-10-15T15:22:14.721','Clinical estimate of due date','Clinical estimate of due date',NULL,NULL,'DATE',0,'SUM','Clinical est. due date',NULL,'AGGREGATE',NULL,'Clinical est. due date',NULL,NULL); -INSERT INTO `DataElement` VALUES (177,'MHW5v2Iljtw','EA4a_TRE_MAL1','WHOMCH Malaria prophylaxis given in second trimester','WHOMCH Malaria prophylaxis given in second trimester','2013-10-28T18:07:31.209','2015-10-14T13:36:07.150','Malaria prophylaxis given in second trimester','Malaria prophylaxis given in second trimester','DD.MM.YYYY since LMP > 14 weeks, Antimalarial tratment according to national policies. From Essential Interventions: "Give 3 tablets of sulfadoxine-pyrimethamine (500 mg + 25 mg pyrimethamine sulfadoxine) at the beginning of the second AND the third trimester to all women according to national policy. (Alternatively Chloroquine 150 mg for 3 days: 4+4+2 OR Chloroquin 100 mg for 3 days: 6+6+3).','DD.MM.YYYY since LMP > 14 weeks, Antimalarial tratment according to national policies. From Essential Interventions: "Give 3 tablets of sulfadoxine-pyrimethamine (500 mg + 25 mg pyrimethamine sulfadoxine) at the beginning of the second AND the third trimester to all women according to national policy. (Alternatively Chloroquine 150 mg for 3 days: 4+4+2 OR Chloroquin 100 mg for 3 days: 6+6+3).','BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Malaria prophylaxis given in second trimester',NULL,NULL); -INSERT INTO `DataElement` VALUES (178,'r3BqzOPxAjp','EA3_STA_TET_DAT','WHOMCH Date of last TT dose','WHOMCH Date of last TT dose','2013-10-28T18:12:06.060','2015-10-14T13:36:24.410','Date of last TT dose','Date of last TT dose','DD.MM.YYYY','DD.MM.YYYY','DATE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Date of last TT dose',NULL,NULL); -INSERT INTO `DataElement` VALUES (179,'dyYdfamSY2Z','EA_BP_DIA','WHOMCH Diastolic blood pressure','WHOMCH Diastolic blood pressure','2013-11-29T21:38:33.203','2015-10-14T13:36:39.641','Diastolic blood pressure','Diastolic blood pressure',NULL,NULL,'NUMBER',0,'AVERAGE_SUM_ORG_UNIT',NULL,NULL,'TRACKER',NULL,'WHOMCH Diastolic blood pressure',NULL,NULL); -INSERT INTO `DataElement` VALUES (180,'w7enwqzx90I','EA8_CLI_ECL1','WHOMCH Eclamptic convulsions','WHOMCH Eclamptic convulsions','2015-01-13T11:37:54.395','2015-10-14T13:36:52.919','Eclamptic convulsions','Eclamptic convulsions',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Eclamptic convulsions',NULL,NULL); -INSERT INTO `DataElement` VALUES (181,'rHgrmXfa57b','EA10b_TRE_PPR1','WHOMCH Erythromycin given for PPROM','WHOMCH Erythromycin given for PPROM','2015-01-13T11:46:44.231','2015-10-14T13:36:17.054','Erythromycin given for PPROM','Erythromycin given for PPROM',NULL,NULL,'BOOLEAN',0,'SUM','Erythromycin given for 10 days attributable to pPROM',NULL,'TRACKER',NULL,'Erythromycin given for 10 days attributable to pPROM',NULL,NULL); -INSERT INTO `DataElement` VALUES (182,'EyfTU3ibMmJ','CLI_PAL','WHOMCH Extreme pallor','WHOMCH Extreme pallor','2013-10-28T17:29:13.118','2015-10-14T13:36:34.750','Extreme pallor','Extreme pallor',NULL,NULL,'BOOLEAN',0,'SUM','Clinical signs of extreme pallor',NULL,'TRACKER',NULL,'Clinical signs of extreme pallor','bVOLWJ2ZHdV',NULL); -INSERT INTO `DataElement` VALUES (183,'vPdXnmGWzfy','STA_PRE','WHOMCH Fetal presentation','WHOMCH Fetal presentation','2015-01-13T11:52:59.214','2015-10-14T13:36:47.834','Fetal presentation','Fetal presentation',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Fetal presentation','g80kErVQ9nn',NULL); -INSERT INTO `DataElement` VALUES (184,'X8HbdaoS9LN','LAB_HCR','WHOMCH Haematocrit value','WHOMCH Haematocrit value','2013-10-28T17:28:01.354','2015-10-14T13:36:22.257','Haematocrit value','Haematocrit value','Screening for anemia','Screening for anemia','PERCENTAGE',1,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Haematocrit value',NULL,NULL); -INSERT INTO `DataElement` VALUES (185,'w4ky6EkVahL','EA_LMP_DAT','WHOMCH LMP date','WHOMCH LMP date','2013-12-22T13:01:23.732','2015-10-14T13:36:09.730','LMP date','LMP date',NULL,NULL,'DATE',0,'SUM','Date of first day of LMP',NULL,'TRACKER',NULL,'Date of first day of LMP',NULL,NULL); -INSERT INTO `DataElement` VALUES (186,'OSuxnldV4Ug','EA8b_TRE_ASP','WHOMCH Low-dose acetylsalicylic acid given','WHOMCH Low-dose acetylsalicylic acid given','2013-12-23T12:46:05.630','2015-10-14T13:36:51.606','Low-dose acetylsalicylic acid given','Low-dose acetylsalicylic acid given','Low-dose Acetylsalicylic acid (aspirin 75 mg daily) is strongly recommended with moderate-quality evidence for the prevention of pre-eclampsia in women at high risk.','Low-dose Acetylsalicylic acid (aspirin 75 mg daily) is strongly recommended with moderate-quality evidence for the prevention of pre-eclampsia in women at high risk.','BOOLEAN',0,'SUM','Low-dose acetylsalicylic acid given as first option method of preventative therapy',NULL,'TRACKER',NULL,'Low-dose acetylsalicylic acid given as first option method of preventative therapy',NULL,NULL); -INSERT INTO `DataElement` VALUES (187,'PN6HcGjTraL','EA_CLI_PLU','WHOMCH Plurality assessed','WHOMCH Plurality assessed','2015-01-13T15:04:24.973','2015-10-14T13:36:18.775','Plurality assessed','Plurality assessed',NULL,NULL,'TEXT',0,'SUM','Assess for plurality',NULL,'TRACKER',NULL,'Assess for plurality','bVOfVD9sJFP',NULL); -INSERT INTO `DataElement` VALUES (188,'dpiyZz8bkVE','EA_PRT_CON','WHOMCH Proteinuria (concentration mg/dL)','WHOMCH Proteinuria (concentration mg/dL)','2015-01-13T15:18:54.521','2015-10-14T13:36:46.081','Proteinuria (concentration mg/dL)','Proteinuria (concentration mg/dL)',NULL,NULL,'INTEGER_ZERO_OR_POSITIVE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Proteinuria (concentration mg/dL)',NULL,NULL); -INSERT INTO `DataElement` VALUES (189,'a7XjFEuZuKE','MMD_PRT_US','WHOMCH Proteinuria (urinstix)','WHOMCH Proteinuria (urinstix)','2013-11-29T21:43:57.718','2015-10-14T13:36:39.210','Proteinuria (urinstix)','Proteinuria (urinstix)',NULL,NULL,'NUMBER',0,'AVERAGE_SUM_ORG_UNIT',NULL,NULL,'TRACKER',NULL,'WHOMCH Proteinuria (urinstix)',NULL,NULL); -INSERT INTO `DataElement` VALUES (190,'vTEkiy8F3yj','EA8_CLI_ECL2','WHOMCH Recurrent eclamptic seizures','WHOMCH Recurrent eclamptic seizures','2015-01-13T15:20:47.278','2015-10-14T13:36:33.025','Recurrent eclamptic seizures','Recurrent eclamptic seizures',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Recurrent eclamptic seizures',NULL,NULL); -INSERT INTO `DataElement` VALUES (191,'AAaJGnWR5js','EA6_LAB_SYP','WHOMCH RPR test','WHOMCH RPR test','2013-10-31T12:13:55.196','2015-10-14T13:36:30.880','RPR test','RPR test',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH RPR test','J7nRCGjOtRa',NULL); -INSERT INTO `DataElement` VALUES (192,'ytV9rX4ADnn','EA4b_PRE_MAL','WHOMCH Slept under ITN (insecticide treated bednet)','WHOMCH Slept under ITN (insecticide treated bednet)','2013-10-28T17:50:24.570','2015-10-14T13:36:16.193','Slept under ITN (insecticide treated bednet)','Slept under ITN (insecticide treated bednet)','Promote use of bednet dipped in insecticide every 6 months to prevent malaria.','Promote use of bednet dipped in insecticide every 6 months to prevent malaria.','BOOLEAN',0,'SUM','Slept under ITN (insecticide treated bednet)',NULL,'TRACKER',NULL,'Slept under ITN (insecticide treated bednet)',NULL,NULL); -INSERT INTO `DataElement` VALUES (193,'M4HEOoEFTAT','EA_BP_SYS','WHOMCH Systolic blood pressure','WHOMCH Systolic blood pressure','2013-11-29T21:37:38.808','2015-10-14T13:36:40.077','Systolic blood pressure','Systolic blood pressure',NULL,NULL,'NUMBER',0,'AVERAGE_SUM_ORG_UNIT',NULL,NULL,'TRACKER',NULL,'WHOMCH Systolic blood pressure',NULL,NULL); -INSERT INTO `DataElement` VALUES (194,'lcaG1Pnh27I','EA8d_TRE_ECL','WHOMCH MgSO4 injection given','WHOMCH MgSO4 injection given','2015-01-14T08:25:38.457','2015-10-14T13:36:50.450','MgSO4 injection given','MgSO4 injection given',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH MgSO4 injection given',NULL,NULL); -INSERT INTO `DataElement` VALUES (195,'DecmCMPDPdS','EA_EDD_ULS','WHOMCH Ultrasound estimate of due date','WHOMCH Ultrasound estimate of due date','2015-01-14T08:27:20.419','2015-10-14T13:36:06.717','Ultrasound estimate of due date','Ultrasound estimate of due date',NULL,NULL,'DATE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Ultrasound estimate of due date',NULL,NULL); -INSERT INTO `DataElement` VALUES (196,'RxVNLSeTjto','EA2_TRE_ANE_MOD','WHOMCH Treatment for moderate anemia','WHOMCH Treatment for moderate anemia','2013-10-28T18:05:13.759','2015-10-14T13:36:25.264','Treatment for moderate anemia','Treatment for moderate anemia','Revise birth plan so as to deliver in a facility with blood transfusion services. Give double dose of iron (1 tablet twice daily=120 mg iron + 400 microg folic acid in total) for 3 months. Counsel on compliance with treatment. Give appropriate oral antimalarial.','Revise birth plan so as to deliver in a facility with blood transfusion services. Give double dose of iron (1 tablet twice daily=120 mg iron + 400 microg folic acid in total) for 3 months. Counsel on compliance with treatment. Give appropriate oral antimalarial.','BOOLEAN',0,'SUM','Daily iron and folic acid treatment for moderate anemia',NULL,'TRACKER',NULL,'Daily iron and folic acid treatment for moderate anemia',NULL,NULL); -INSERT INTO `DataElement` VALUES (197,'nB4Ui3ckmUi','EA2_TRE_ANE_SEV','WHOMCH Treatment for severe anemia','WHOMCH Treatment for severe anemia','2013-10-28T18:05:48.334','2015-10-14T13:36:35.179','Treatment for severe anemia','Treatment for severe anemia',NULL,NULL,'BOOLEAN',0,'SUM','Daily iron and folic acid treatment for severe anemia',NULL,'TRACKER',NULL,'Daily iron and folic acid treatment for severe anemia',NULL,NULL); -INSERT INTO `DataElement` VALUES (198,'Kb6kZzUCJi1','TRE_SUP','WHOMCH Iron and folic acid supplements given','WHOMCH Iron and folic acid supplements given','2013-10-28T17:57:54.404','2015-10-14T13:36:31.724','Iron and folic acid supplements given','Iron and folic acid supplements given','If prevalence of anaemia <40%, dosage required is: (60 mg iron+400 mg folic acid) for 6 months, if prevalence of anaemia is >40%, dosage required is: (60 mg iron+400 mg folic acid) for 6 months and continuing 3 months PPC.','If prevalence of anaemia <40%, dosage required is: (60 mg iron+400 mg folic acid) for 6 months, if prevalence of anaemia is >40%, dosage required is: (60 mg iron+400 mg folic acid) for 6 months and continuing 3 months PPC.','BOOLEAN',0,'SUM','Daily iron and folic acid supplements given',NULL,'TRACKER',NULL,'Daily iron and folic acid supplements given',NULL,NULL); -INSERT INTO `DataElement` VALUES (199,'jRo4KlnCKeX','EA7_TRE_HIV2b','WHOMCH HIV counselling provided - negative','WHOMCH HIV counselling provided - negative','2013-12-22T17:53:24.464','2015-10-14T13:36:34.320','HIV counselling provided - negative','HIV counselling provided - negative','Counsel on safe sex inclusive correct and consistent use of condoms to prevent HIV-infection.','Counsel on safe sex inclusive correct and consistent use of condoms to prevent HIV-infection.','BOOLEAN',0,'SUM','HIV counselling provided to the HIV-negative woman',NULL,'TRACKER',NULL,'HIV counselling provided to the HIV-negative woman',NULL,NULL); -INSERT INTO `DataElement` VALUES (200,'Js57E09s9fh','EA6_TRE_SYP2','WHOMCH Erythromycin given for syphillis','WHOMCH Erythromycin given for syphillis','2013-10-31T12:15:57.337','2015-10-14T13:36:19.649','Erythromycin given for syphillis','Erythromycin given for syphillis','Encourage the woman to bring her sexual partner for treatment (he can choose between erythromycin OR tetracycllin 2x250 mg tablets every 6 hours for 15 days OR doxylin 100 mg every 12 hours for 15 days, counsel on consistent use of condoms to prevent new infection. Plan to treat the baby,','Encourage the woman to bring her sexual partner for treatment (he can choose between erythromycin OR tetracycllin 2x250 mg tablets every 6 hours for 15 days OR doxylin 100 mg every 12 hours for 15 days, counsel on consistent use of condoms to prevent new infection. Plan to treat the baby,','TEXT',0,'SUM','Erythromycin given',NULL,'TRACKER',NULL,'Erythromycin given',NULL,NULL); -INSERT INTO `DataElement` VALUES (201,'QFX1FLWBwtq','MMD_ALL','WHOMCH Allergies (drugs and/or severe food allergies)','WHOMCH Allergies (drugs and/or severe food allergies)','2013-12-22T12:44:55.750','2015-10-14T13:36:48.279','Allergies','Allergies',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Allergies (drugs and/or severe food allergies)','R3ShQczKnI9',NULL); -INSERT INTO `DataElement` VALUES (202,'E6QaDtrQP5e','MMD_ALL_PEN','WHOMCH Penicillin allergy','WHOMCH Penicillin allergy','2015-01-30T13:28:10.204','2015-10-14T13:36:13.615','Penicillin allergy','Penicillin allergy',NULL,NULL,'TEXT',0,'SUM','A: Penicillin allergy',NULL,'TRACKER',NULL,'A: Penicillin allergy','R3ShQczKnI9',NULL); -INSERT INTO `DataElement` VALUES (203,'dpOtt7HUQXa','MMD_ALL_OM','WHOMCH Other medicine allergy','WHOMCH Other medicine allergy','2015-01-30T13:28:46.835','2015-10-14T13:36:12.322','Other medicine allergy','Other medicine allergy',NULL,NULL,'TEXT',0,'SUM','A: Other medicine allergy',NULL,'TRACKER',NULL,'A: Other medicine allergy','R3ShQczKnI9',NULL); -INSERT INTO `DataElement` VALUES (204,'VSmOcdK3v7y','MMD_ALL_OM_SPEC','WHOMCH Other medicine allergy specified','WHOMCH Other medicine allergy specified','2015-01-30T13:29:10.841','2015-10-14T13:36:05.579','Other medicine allergy specified','Other medicine allergy specified',NULL,NULL,'TEXT',0,'SUM','A: Other medicine allergy specified',NULL,'TRACKER',NULL,'A: Other medicine allergy specified',NULL,NULL); -INSERT INTO `DataElement` VALUES (205,'ZbDPeYzWsh2','MMD_ALL_OS','WHOMCH Other severe allergy','WHOMCH Other severe allergy','2015-01-30T13:29:45.270','2015-10-14T13:36:14.037','Other severe allergy','Other severe allergy',NULL,NULL,'TEXT',0,'SUM','A: Other severe allergy',NULL,'TRACKER',NULL,'A: Other severe allergy','R3ShQczKnI9',NULL); -INSERT INTO `DataElement` VALUES (206,'zk4Eui7Jhtr','MMD_ALL_OS_SPEC','WHOMCH Other severe allergy specified','WHOMCH Other severe allergy specified','2015-01-30T13:30:05.102','2015-10-14T13:36:23.555','Other severe allergy specified','Other severe allergy specified',NULL,NULL,'TEXT',0,'SUM','A: Other severe allergy specified',NULL,'TRACKER',NULL,'A: Other severe allergy specified',NULL,NULL); -INSERT INTO `DataElement` VALUES (207,'de0FEHSIoxh','MMD_COM','WHOMCH Chronic conditions','WHOMCH Chronic conditions','2014-11-29T17:18:17.962','2015-10-14T13:36:24.839','Chronic conditions','Chronic conditions',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Chronic conditions',NULL,NULL); -INSERT INTO `DataElement` VALUES (208,'UQ2Zo8CruPB','MMD_CON_CHT','WHOMCH Chronic hypertension','WHOMCH Chronic hypertension','2014-11-29T20:23:50.721','2015-10-14T13:36:29.580','Chronic hypertension','Chronic hypertension',NULL,NULL,'BOOLEAN',0,'SUM','CC: Chronic hypertension',NULL,'TRACKER',NULL,'CC: Chronic hypertension',NULL,NULL); -INSERT INTO `DataElement` VALUES (209,'zzGNbeMnTd6','MMD_CON_AID','WHOMCH Autoimmune disease','WHOMCH Autoimmune disease','2014-11-29T17:15:22.787','2015-10-14T13:36:25.699','Autoimmune disease','Autoimmune disease',NULL,NULL,'BOOLEAN',0,'SUM','CC: Autoimmune disease',NULL,'TRACKER',NULL,'CC: Autoimmune disease',NULL,NULL); -INSERT INTO `DataElement` VALUES (210,'Q1x1HIhuwFN','MMD_CON_DM','WHOMCH Diabetes','WHOMCH Diabetes','2013-12-23T12:49:46.556','2015-10-14T13:36:37.836','Diabetes','Diabetes',NULL,NULL,'BOOLEAN',0,'SUM','CC: Diabetes',NULL,'TRACKER',NULL,'CC: Diabetes',NULL,NULL); -INSERT INTO `DataElement` VALUES (211,'VFffa31SKjH','MMD_CON_HIV','WHOMCH Previously known HIV-positive','WHOMCH Previously known HIV-positive','2013-10-31T12:09:50.561','2015-10-14T13:36:35.615','Previously known HIV-positive','Previously known HIV-positive',NULL,NULL,'BOOLEAN',0,'SUM','CC: HIV Positive',NULL,'TRACKER',NULL,'CC: HIV Positive',NULL,NULL); -INSERT INTO `DataElement` VALUES (212,'sdchiIXIcCf','MMD_CON_RD','WHOMCH Renal disease','WHOMCH Renal disease','2014-11-29T16:59:34.053','2015-10-14T13:36:26.560','Renal disease','Renal disease',NULL,NULL,'BOOLEAN',0,'SUM','CC: Renal disease',NULL,'TRACKER',NULL,'CC: Renal disease',NULL,NULL); -INSERT INTO `DataElement` VALUES (213,'xPTngRLQTnu','MMD_CON_OTHER','WHOMCH Other chronic condition','WHOMCH Other chronic condition','2013-12-23T12:51:20.802','2015-10-14T13:36:26.128','Other chronic condition','Other chronic condition',NULL,NULL,'BOOLEAN',0,'SUM','CC: Other chronic condition',NULL,'TRACKER',NULL,'CC: Other chronic condition',NULL,NULL); -INSERT INTO `DataElement` VALUES (214,'Mh7nK8UKoZP','MMD_CON_OTHER_SPEC','WHOMCH Other chronic condition specified','WHOMCH Other chronic condition specified','2013-10-28T17:46:58.570','2015-10-14T13:36:23.984','Other chronic condition specified','Other chronic condition specified',NULL,NULL,'TEXT',0,'SUM','CC: Other chronic condition specified',NULL,'TRACKER',NULL,'CC: Other chronic condition specified',NULL,NULL); -INSERT INTO `DataElement` VALUES (215,'fNnOPQj83jz','DE_423611','WHOMCH Medication','WHOMCH Medication','2015-04-14T13:47:46.178','2015-10-14T13:36:06.287','Medication','Medication',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Medication',NULL,NULL); -INSERT INTO `DataElement` VALUES (216,'NPZPVg2rVh4','DE_423714','WHOMCH Insecticide treated bednet promoted','WHOMCH Insecticide treated bednet promoted','2015-05-11T12:53:39.440','2015-10-14T13:36:50.739','Insecticide treated bednet promoted','Insecticide treated bednet promoted',NULL,NULL,'BOOLEAN',0,'SUM','Use of insecticide treate bednet(ITN) is promoted',NULL,'TRACKER',NULL,'Use of insecticide treate bednet(ITN) is promoted',NULL,NULL); -INSERT INTO `DataElement` VALUES (217,'roKuXYfw1BW',NULL,'WHOMCH Gestational age at visit','WHOMCH Gestational age at visit','2017-05-22T22:26:36.224','2017-05-22T22:26:36.224','WHOMCH Gestational age at visit','WHOMCH Gestational age at visit',NULL,NULL,'INTEGER',0,'SUM','Gestational age at visit',NULL,'TRACKER',NULL,'Gestational age at visit',NULL,NULL); -INSERT INTO `DataElement` VALUES (218,'QM5d0hfSbKk','EA9_TRE_BRE1','WHOMCH ECV offered','WHOMCH ECV offered','2013-12-23T12:52:05.146','2015-10-14T13:36:06.025','ECV offered','ECV offered','Do not perform ECV if facilities for emergency caesarian section are not available OR if there are fetal heart rate abnormalities (less than 100 or more than 180 beats per minute) when the woman lie on her back, with elevated foot of the bed.','Do not perform ECV if facilities for emergency caesarian section are not available OR if there are fetal heart rate abnormalities (less than 100 or more than 180 beats per minute) when the woman lie on her back, with elevated foot of the bed.','TEXT',0,'SUM','ECV offered by skilled birth attendant ≥ 37 weeks of gestation',NULL,'TRACKER',NULL,'ECV offered by skilled birth attendant ≥ 37 weeks of gestation','Na3EKYZ6CX6',NULL); -INSERT INTO `DataElement` VALUES (219,'DCUDZxqOxUo','EA9_TRE_BRE2','WHOMCH ECV performed','WHOMCH ECV performed','2013-12-23T12:53:34.696','2015-10-14T13:36:52.485','ECV performed','ECV performed','Persistent conversion from breech to cephalic presentation after 1 week.','Persistent conversion from breech to cephalic presentation after 1 week.','BOOLEAN',0,'SUM','ECV performed by skilled birth attendant ≥ 37 weeks of gestation',NULL,'TRACKER',NULL,'ECV performed by skilled birth attendant ≥ 37 weeks of gestation',NULL,NULL); -INSERT INTO `DataElement` VALUES (220,'SeXllT5ypsh','OFF_IND','WHOMCH Offered a choice of induction of labour or expectant management','WHOMCH Offered a choice of induction of labour or expectant management','2013-12-23T13:00:29.276','2015-10-14T13:36:20.519','off. induction of labour or exp. management','off. induction of labour or exp. management','Professional health workers at Referral care only.','Professional health workers at Referral care only.','TEXT',0,'SUM','PROM Management',NULL,'TRACKER',NULL,'PROM Management','iqz8IiJwWPL',NULL); -INSERT INTO `DataElement` VALUES (221,'yTDoF5b1OhI','EA9_TRE_BRE3','WHOMCH ECV conversion remaining','WHOMCH ECV conversion remaining','2015-04-21T09:30:21.210','2015-10-14T13:36:47.399','ECV conversion remaining','ECV conversion remaining',NULL,NULL,'TEXT',0,'SUM','ECV conversion remaining 1 week after ECV was performed',NULL,'TRACKER',NULL,'ECV conversion remaining 1 week after ECV was performed','pQYCiuosBnZ',NULL); -INSERT INTO `DataElement` VALUES (222,'ez86AhQ5cqp','TRE_BLD','WHOMCH Blood transfusion','WHOMCH Blood transfusion','2015-01-12T19:27:31.126','2015-10-14T13:36:36.474','Blood transfusion','Blood transfusion',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Blood transfusion',NULL,NULL); -INSERT INTO `DataElement` VALUES (223,'L6Toy2TrHHq','CLI_TMP','WHOMCH Body temperature','WHOMCH Body temperature','2015-01-12T19:31:36.092','2015-10-14T13:36:32.159','Body temperature','Body temperature',NULL,NULL,'INTEGER_POSITIVE',0,'AVERAGE',NULL,NULL,'TRACKER',NULL,'WHOMCH Body temperature',NULL,NULL); -INSERT INTO `DataElement` VALUES (224,'SojR4V7A8u2','EC_CLI_NEA3','WHOMCH Maternal near-miss by other reason','WHOMCH Maternal near-miss by other reason','2015-01-15T07:48:51.143','2015-10-14T13:36:21.388','Maternal near-miss by other reason','Maternal near-miss by other reason',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Maternal near-miss by other reason',NULL,NULL); -INSERT INTO `DataElement` VALUES (225,'ALfOm7aaH6b','CLI_ECL','WHOMCH Clinical impression of eclampsia','WHOMCH Clinical impression of eclampsia','2014-11-29T17:16:32.829','2015-10-14T13:36:10.594','Clinical impression of eclampsia','Clinical impression of eclampsia','Clinical impression of eclampsia.','Clinical impression of eclampsia.','BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Clinical impression of eclampsia',NULL,NULL); -INSERT INTO `DataElement` VALUES (226,'Mfq2Y9N21KZ','CLI_PRE_ECL','WHOMCH Clinical impression of pre-eclampsia','WHOMCH Clinical impression of pre-eclampsia','2014-11-29T17:14:05.738','2015-10-14T13:36:18.348','Clinical impression of pre-eclampsia','Clinical impression of pre-eclampsia','Clinical impression of pre-eclampsia','Clinical impression of pre-eclampsia','TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Clinical impression of pre-eclampsia','bh7Idg1kWYo',NULL); -INSERT INTO `DataElement` VALUES (227,'mGHBXrtqSut','EC_LBR_TOC_DOC','WHOMCH Commencement of labour','WHOMCH Commencement of labour','2015-01-12T19:11:02.216','2015-10-14T13:36:17.925','Commencement of labour','Commencement of labour',NULL,NULL,'DATE',0,'COUNT',NULL,NULL,'TRACKER',NULL,'WHOMCH Commencement of labour',NULL,NULL); -INSERT INTO `DataElement` VALUES (228,'klEz81wXFoU','CLI_INF','WHOMCH Confirmed or suspected infection','WHOMCH Confirmed or suspected infection','2015-01-12T19:55:26.830','2015-10-14T13:36:41.841','Confirmed or suspected infection','Confirmed or suspected infection',NULL,NULL,'TEXT',0,'COUNT',NULL,NULL,'TRACKER',NULL,'WHOMCH Confirmed or suspected infection','HENAVEViqQP',NULL); -INSERT INTO `DataElement` VALUES (229,'z8m3llJYuh9','EC_TRE_LBR1','WHOMCH Continuous supportive presence during labour and birth ','WHOMCH Continuous supportive presence during labour and birth ','2015-01-12T20:04:28.767','2015-10-14T13:36:27.429','Continuous supportive presence','Continuous supportive presence',NULL,NULL,'BOOLEAN',0,'SUM','Did the patient have continuous supportive presence during labour and birth',NULL,'TRACKER',NULL,'Did the patient have continuous supportive presence during labour and birth',NULL,NULL); -INSERT INTO `DataElement` VALUES (230,'MH33VLmOOqm','EC_DEL_IND_DAT','WHOMCH Date of induction of labor','WHOMCH Date of induction of labor','2015-01-14T13:37:19.696','2015-10-14T13:36:15.321','Date of induction of labor','Date of induction of labor',NULL,NULL,'DATE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Date of induction of labor',NULL,NULL); -INSERT INTO `DataElement` VALUES (231,'spkG704sTh6','DEL_MET','WHOMCH Delivery method','WHOMCH Delivery method','2015-01-13T11:35:26.751','2015-10-14T13:36:44.770','Delivery method','Delivery method',NULL,NULL,'NUMBER',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Delivery method','jAyXdHaxGiH',NULL); -INSERT INTO `DataElement` VALUES (232,'u7aAPS8OgLw','EC_VIS_HR','WHOMCH Fetal heart rate on admission','WHOMCH Fetal heart rate on admission','2015-01-13T11:50:13.433','2015-10-14T13:36:21.826','Fetal heart rate on admission','Fetal heart rate on admission',NULL,NULL,'INTEGER_POSITIVE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Fetal heart rate on admission',NULL,NULL); -INSERT INTO `DataElement` VALUES (233,'pwfdgeE21Os','CLI_HR','WHOMCH Heart rate','WHOMCH Heart rate','2015-01-13T11:58:45.931','2015-10-14T13:36:13.183','Heart rate','Heart rate',NULL,NULL,'INTEGER_POSITIVE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Heart rate',NULL,NULL); -INSERT INTO `DataElement` VALUES (234,'yq1qT0NdjYQ','TRE_HIV_TRP','WHOMCH HIV test results provided to patient','WHOMCH HIV test results provided to patient','2015-01-14T17:48:50.813','2015-10-14T13:36:28.286','HIV test results provided to patient','HIV test results provided to patient',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH HIV test results provided to patient',NULL,NULL); -INSERT INTO `DataElement` VALUES (235,'D1EHM01p454','EC_DEL_IND1','WHOMCH Indication for induction of labour','WHOMCH Indication for induction of labour','2015-01-13T14:04:44.817','2015-10-14T13:36:22.697','Indication for induction of labour','Indication for induction of labour',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Indication for induction of labour','IkB24bxyneF',NULL); -INSERT INTO `DataElement` VALUES (236,'MVIV2RGWhUq','EC5_TRE_IND_PRO','WHOMCH Induction of labor','WHOMCH Induction of labor','2015-01-13T14:12:46.890','2015-10-14T13:36:38.727','Induction of labor','Induction of labor',NULL,NULL,'BOOLEAN',0,'SUM','Induction of labour for prolonged pregnancy',NULL,'TRACKER',NULL,'Induction of labour for prolonged pregnancy',NULL,NULL); -INSERT INTO `DataElement` VALUES (237,'oQgcj7kV1c3','EC5_TRE_IND','WHOMCH Induction of labour with vaginal prostaglandin performed at term','WHOMCH Induction of labour with vaginal prostaglandin performed at term','2013-12-23T13:01:44.719','2015-10-14T13:36:38.272','Induction of labour with vaginal prostaglandin','Induction of labour with vaginal prostaglandin','Professional health workers at Referral care only.','Professional health workers at Referral care only.','BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Induction of labour with vaginal prostaglandin performed at term',NULL,NULL); -INSERT INTO `DataElement` VALUES (238,'FIHEeJwfhZH','EC_CLI_NEA','WHOMCH Maternal near-miss','WHOMCH Maternal near-miss','2015-01-14T12:53:55.755','2015-10-14T13:36:49.578','Maternal near-miss','Maternal near-miss',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Maternal near-miss',NULL,NULL); -INSERT INTO `DataElement` VALUES (239,'i9mEM7ZW7yV','EC_CLI_NEA2','WHOMCH Maternal near-miss by coagulation/haematological dysfunction','WHOMCH Maternal near-miss by coagulation/haematological dysfunction','2015-01-13T14:32:38.060','2015-10-14T13:36:33.461','MNM by coagulation/haematological dysfunction','MNM by coagulation/haematological dysfunction',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Maternal near-miss by coagulation/haematological dysfunction',NULL,NULL); -INSERT INTO `DataElement` VALUES (240,'PQlndpI05Bb','EC_CLI_NEA1','WHOMCH Maternal near-miss by uterine dysfunction','WHOMCH Maternal near-miss by uterine dysfunction','2015-01-13T14:33:25.879','2015-10-14T13:36:36.910','MNM by uterine dysfunction','MNM by uterine dysfunction',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Maternal near-miss by uterine dysfunction',NULL,NULL); -INSERT INTO `DataElement` VALUES (241,'YsVHgzQCwmr','EC_CLI_MEC','WHOMCH Meconium stained liquor','WHOMCH Meconium stained liquor','2015-01-13T14:34:48.624','2015-10-14T13:36:27.859','Meconium stained liquor','Meconium stained liquor',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Meconium stained liquor',NULL,NULL); -INSERT INTO `DataElement` VALUES (242,'FYLMjPQ0wmo','CLI_ANE_MOD','WHOMCH Moderate aneamia','WHOMCH Moderate aneamia','2015-01-14T07:35:09.938','2015-10-14T13:36:16.623','Moderate aneamia','Moderate aneamia',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Moderate aneamia',NULL,NULL); -INSERT INTO `DataElement` VALUES (243,'BmaBjPQX8ME','EC_TRE_PPH','WHOMCH Oxytocin given','WHOMCH Oxytocin given','2015-01-13T14:51:25.532','2015-10-14T13:36:07.575','Oxytocin given','Oxytocin given',NULL,NULL,'BOOLEAN',0,'SUM','Oxytocin given immediately after birth for the prevention of PPH',NULL,'TRACKER',NULL,'Oxytocin given immediately after birth for the prevention of PPH',NULL,NULL); -INSERT INTO `DataElement` VALUES (244,'HUfKCOou7de','EC1_TRE_LBR3','WHOMCH Pain medication given','WHOMCH Pain medication given','2015-01-14T17:58:13.103','2015-10-14T13:36:14.470','Pain medication given','Pain medication given',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Pain medication given','WsxjrKsoi9W',NULL); -INSERT INTO `DataElement` VALUES (245,'VXdfPQRXKiA','EC_TRE_LBR2','WHOMCH Partograph used','WHOMCH Partograph used','2015-01-13T15:02:10.536','2015-10-14T13:36:49.143','Partograph used','Partograph used',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Partograph used',NULL,NULL); -INSERT INTO `DataElement` VALUES (246,'V5PR8Kw8ZnC','EC_PRE_OUT','WHOMCH Pregnancy outcome','WHOMCH Pregnancy outcome','2014-11-28T13:32:23.921','2015-10-14T13:36:23.127','Pregnancy outcome','Pregnancy outcome',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Pregnancy outcome','C3F7ypzeLiS',NULL); -INSERT INTO `DataElement` VALUES (247,'Spl22QJsWeu','CLI_RR','WHOMCH Respiratory rate','WHOMCH Respiratory rate','2015-01-14T07:19:40.246','2015-10-14T13:36:05.142','Respiratory rate','Respiratory rate',NULL,NULL,'INTEGER_NEGATIVE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Respiratory rate',NULL,NULL); -INSERT INTO `DataElement` VALUES (248,'PCiOYWXZq2E','EC_CLI_PLA','WHOMCH Retained placenta','WHOMCH Retained placenta','2015-01-14T07:21:22.703','2015-10-14T13:36:26.985','Retained placenta','Retained placenta',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Retained placenta',NULL,NULL); -INSERT INTO `DataElement` VALUES (249,'AXuzjgLsBy3','CLI_ANE_SEV','WHOMCH Severe anaemia','WHOMCH Severe anaemia','2015-01-14T07:33:49.737','2015-10-14T13:36:29.148','Severe anaemia','Severe anaemia',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Severe anaemia',NULL,NULL); -INSERT INTO `DataElement` VALUES (250,'sUX4i7QqbXF','EC_STA_TET','WHOMCH Tetanus vaccination status','WHOMCH Tetanus vaccination status','2013-10-28T17:56:06.298','2015-10-14T13:36:30.453','Tetanus vaccination status','Tetanus vaccination status',NULL,NULL,'TEXT',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Tetanus vaccination status','RCsz7zzurLe',NULL); -INSERT INTO `DataElement` VALUES (251,'m3XQrgadVK9','EC4_TRE_HEM','WHOMCH Uterotonics given','WHOMCH Uterotonics given','2014-11-29T20:30:04.338','2015-10-14T13:36:36.040','Uterotonics given','Uterotonics given','If person was treated with uterotonics','If person was treated with uterotonics','BOOLEAN',0,'SUM','Therapeutic uterotonics given for management of postpartum haemorrhage',NULL,'TRACKER',NULL,'Therapeutic uterotonics given for management of postpartum haemorrhage',NULL,NULL); -INSERT INTO `DataElement` VALUES (252,'cz5DN6BVVeW','EC_CLI_TEA','WHOMCH Third or fourth degree perineal tear','WHOMCH Third or fourth degree perineal tear','2015-01-14T08:16:01.167','2015-10-14T13:36:41.398','Third or fourth degree perineal tear','Third or fourth degree perineal tear',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Third or fourth degree perineal tear',NULL,NULL); -INSERT INTO `DataElement` VALUES (253,'csl3yq5UC46','LAB_WBC','WHOMCH White blood cell count','WHOMCH White blood cell count','2015-01-14T08:33:40.635','2015-10-14T13:36:40.954','White blood cell count','White blood cell count',NULL,NULL,'NUMBER',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH White blood cell count',NULL,NULL); -INSERT INTO `DataElement` VALUES (254,'hib4oz2sOLw','EC_CLI_PPH','WHOMCH Estimated blood loss (ml)','WHOMCH Estimated blood loss (ml)','2015-01-13T11:47:09.760','2015-10-14T13:36:45.643','Estimated blood loss (ml)','Estimated blood loss (ml)',NULL,NULL,'INTEGER_ZERO_OR_POSITIVE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Estimated blood loss (ml)',NULL,NULL); -INSERT INTO `DataElement` VALUES (255,'B3bDhNpCcEM','EP4_LAB_WBC_CD4','WHOMCH CD4 count','WHOMCH CD4 count','2015-01-12T19:35:00.471','2015-10-14T13:36:12.749','CD4 count','CD4 count',NULL,NULL,'INTEGER_POSITIVE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH CD4 count',NULL,NULL); -INSERT INTO `DataElement` VALUES (256,'cwgQnkamM2j','EN_DOB_REC','WHOMCH Date of birth of most recent newborn','WHOMCH Date of birth of most recent newborn','2015-01-13T10:59:23.686','2015-10-14T13:36:15.757','Date of birth of most recent newborn','Date of birth of most recent newborn',NULL,NULL,'DATE',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Date of birth of most recent newborn',NULL,NULL); -INSERT INTO `DataElement` VALUES (257,'u3TE34T4KH0','DOB','WHOMCH Date of birth/End of pregnancy','WHOMCH Date of birth/End of pregnancy','2014-11-28T13:14:17.561','2015-10-14T13:36:10.165','Date of birth','Date of birth',NULL,NULL,'DATE',0,'SUM','Date of birth',NULL,'TRACKER',NULL,'Date of birth',NULL,NULL); -INSERT INTO `DataElement` VALUES (258,'QWVRukwa83h','EP1_TRE_CCC','WHOMCH Contraceptive counselling provided','WHOMCH Contraceptive counselling provided','2015-01-13T15:10:12.336','2015-10-14T13:36:52.054','Contraceptive counselling provided','Contraceptive counselling provided',NULL,NULL,'BOOLEAN',0,'SUM',NULL,NULL,'TRACKER',NULL,'WHOMCH Contraceptive counselling provided',NULL,NULL); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -INSERT INTO `CategoryOptionComboCategoryLink` VALUES (1,'Gmbgme7z9BF','uZUnebiT5DI'); -INSERT INTO `CategoryOptionComboCategoryLink` VALUES (2,'Gmbgme7z9BF','Fp4gVHbRvEV'); -INSERT INTO `CategoryOptionComboCategoryLink` VALUES (3,'bRowv6yZOF2','as6ygGvUGNg'); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -INSERT INTO `CategoryOptionCombo` VALUES (1,'Gmbgme7z9BF','COC_359669','Trained TBA, At PHU','Trained TBA, At PHU','2011-12-24T12:24:25.319','2011-12-24T12:24:25.319','m2jTvAj5kkm'); -INSERT INTO `CategoryOptionCombo` VALUES (2,'bRowv6yZOF2','COC_4','default','default','2011-12-24T12:24:25.319','2011-12-24T12:24:25.319','p0KPaWEg3cf'); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -INSERT INTO `CategoryOption` VALUES (1,'as6ygGvUGNg',NULL,'default','default','2011-12-24T12:24:24.149','2016-04-12T20:37:48.414'); -INSERT INTO `CategoryOption` VALUES (2,'TNYQzTHdoxL','MCH_AIDES','MCH Aides','MCH Aides','2011-12-24T12:24:24.149','2011-12-24T12:24:24.149'); -INSERT INTO `CategoryOption` VALUES (3,'TXGfLxZlInA','SECHN','SECHN','SECHN','2011-12-24T12:24:24.149','2011-12-24T12:24:24.149'); -INSERT INTO `CategoryOption` VALUES (4,'uZUnebiT5DI','TRAINED_TBA','Trained TBA','Trained TBA','2011-12-24T12:24:24.149','2011-12-24T12:24:24.149'); -INSERT INTO `CategoryOption` VALUES (5,'apsOixVZlf1','FMLE','Female','Female','2011-12-24T12:24:24.149','2011-12-24T12:24:24.149'); -INSERT INTO `CategoryOption` VALUES (6,'jRbMi0aBjYn','MLE','Male','Male','2011-12-24T12:24:24.149','2011-12-24T12:24:24.149'); -INSERT INTO `CategoryOption` VALUES (7,'wHFX72Y0KXx','IN_COMM','In Community','In Community','2011-12-24T12:24:24.149','2011-12-24T12:24:24.149'); -INSERT INTO `CategoryOption` VALUES (8,'Fp4gVHbRvEV','AT_PHU','At PHU','At PHU','2011-12-24T12:24:24.149','2011-12-24T12:24:24.149'); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -INSERT INTO `CategoryCombo` VALUES (1,'m2jTvAj5kkm','BIRTHS','Births','Births','2011-12-24T12:24:25.203','2016-04-18T16:04:34.745',0); -INSERT INTO `CategoryCombo` VALUES (2,'p0KPaWEg3cf',NULL,'default','default','2011-12-24T12:24:25.203','2016-04-12T20:37:49.126',1); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -INSERT INTO `CategoryCategoryOptionLink` VALUES (1,'vGs6omsRekv','as6ygGvUGNg'); -INSERT INTO `CategoryCategoryOptionLink` VALUES (2,'KfdsGBcoiCa','TNYQzTHdoxL'); -INSERT INTO `CategoryCategoryOptionLink` VALUES (3,'KfdsGBcoiCa','TXGfLxZlInA'); -INSERT INTO `CategoryCategoryOptionLink` VALUES (4,'KfdsGBcoiCa','uZUnebiT5DI'); -INSERT INTO `CategoryCategoryOptionLink` VALUES (5,'cX5k9anHEHd','apsOixVZlf1'); -INSERT INTO `CategoryCategoryOptionLink` VALUES (6,'cX5k9anHEHd','jRbMi0aBjYn'); -INSERT INTO `CategoryCategoryOptionLink` VALUES (7,'x3uo8LqiTBk','wHFX72Y0KXx'); -INSERT INTO `CategoryCategoryOptionLink` VALUES (8,'x3uo8LqiTBk','Fp4gVHbRvEV'); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -INSERT INTO `CategoryCategoryComboLink` VALUES (1,'KfdsGBcoiCa','m2jTvAj5kkm'); -INSERT INTO `CategoryCategoryComboLink` VALUES (2,'cX5k9anHEHd','m2jTvAj5kkm'); -INSERT INTO `CategoryCategoryComboLink` VALUES (3,'vGs6omsRekv','p0KPaWEg3cf'); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -INSERT INTO `Category` VALUES (1,'vGs6omsRekv',NULL,'default','default','2012-11-21T12:15:18.537','2017-12-21T03:32:22.508','DISAGGREGATION'); -INSERT INTO `Category` VALUES (2,'KfdsGBcoiCa','BIRTHS_ATTENDED','Births attended by','Births attended by','2011-12-24T12:24:25.155','2017-10-09T16:03:48.729','DISAGGREGATION'); -INSERT INTO `Category` VALUES (3,'cX5k9anHEHd','GENDER','Gender','Gender','2011-12-24T12:24:25.155','2013-05-28T09:27:46.728','DISAGGREGATION'); -INSERT INTO `Category` VALUES (4,'x3uo8LqiTBk','LOC_PHU_COMM','Location PHU/Community','Location PHU/Community','2011-12-24T12:24:25.155','2013-05-28T09:59:48.308','DISAGGREGATION'); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -COMMIT; diff --git a/core/src/androidTest/resources/db_version_3.sql b/core/src/androidTest/resources/db_version_3.sql deleted file mode 100644 index 060c94cd9c..0000000000 --- a/core/src/androidTest/resources/db_version_3.sql +++ /dev/null @@ -1,43 +0,0 @@ -CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_4.sql b/core/src/androidTest/resources/db_version_4.sql deleted file mode 100644 index fc55afc59f..0000000000 --- a/core/src/androidTest/resources/db_version_4.sql +++ /dev/null @@ -1,44 +0,0 @@ -CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_5.sql b/core/src/androidTest/resources/db_version_5.sql deleted file mode 100644 index 474266d0f1..0000000000 --- a/core/src/androidTest/resources/db_version_5.sql +++ /dev/null @@ -1,47 +0,0 @@ -CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); diff --git a/core/src/androidTest/resources/db_version_6.sql b/core/src/androidTest/resources/db_version_6.sql deleted file mode 100644 index 3300c41933..0000000000 --- a/core/src/androidTest/resources/db_version_6.sql +++ /dev/null @@ -1,49 +0,0 @@ -CREATE TABLE UserRoleProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,userRole TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (userRole) REFERENCES UserRole (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (userRole, program)); -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (period) REFERENCES Period (periodId) FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_7.sql b/core/src/androidTest/resources/db_version_7.sql deleted file mode 100644 index 58b3fdf16f..0000000000 --- a/core/src/androidTest/resources/db_version_7.sql +++ /dev/null @@ -1,48 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_8.sql b/core/src/androidTest/resources/db_version_8.sql deleted file mode 100644 index 2651645a29..0000000000 --- a/core/src/androidTest/resources/db_version_8.sql +++ /dev/null @@ -1,49 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); \ No newline at end of file diff --git a/core/src/androidTest/resources/db_version_9.sql b/core/src/androidTest/resources/db_version_9.sql deleted file mode 100644 index 24927f85db..0000000000 --- a/core/src/androidTest/resources/db_version_9.sql +++ /dev/null @@ -1,50 +0,0 @@ -CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); -CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); -CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntity TEXT NOT NULL,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (event) REFERENCES Event (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE TrackedEntity (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); -CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); -CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); -CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); -CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,sortOrder INTEGER,program TEXT NOT NULL, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); -CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntity TEXT,categoryCombo TEXT, accessDataWrite INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntity) REFERENCES TrackedEntity (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); -CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT); -CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); -CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); -CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); -CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); -CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); -CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); -CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); -CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); -CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); -CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER, accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); -CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); -CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); -CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); -CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); -CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); -CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); -CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/example_migrations/1.yaml b/core/src/androidTest/resources/migrations/example_migrations/1.yaml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/core/src/androidTest/resources/migrations/example_migrations/2.yaml b/core/src/androidTest/resources/migrations/example_migrations/2.yaml deleted file mode 100644 index bceddb73ee..0000000000 --- a/core/src/androidTest/resources/migrations/example_migrations/2.yaml +++ /dev/null @@ -1,2 +0,0 @@ -up: - - ALTER TABLE USER ADD COLUMN testColumn INTEGER; \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/example_migrations/3.yaml b/core/src/androidTest/resources/migrations/example_migrations/3.yaml deleted file mode 100644 index 9af1123bd3..0000000000 --- a/core/src/androidTest/resources/migrations/example_migrations/3.yaml +++ /dev/null @@ -1,6 +0,0 @@ -up: - - create table if not exists TestTable (testColumn Integer) -seeds: - - INSERT INTO TestTable (testColumn) VALUES (1) -down: - - DROP TABLE TestTable \ No newline at end of file diff --git a/core/src/androidTest/resources/migrations/real_migrations/1.yaml b/core/src/androidTest/resources/migrations/old_migrations/1.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/1.yaml rename to core/src/androidTest/resources/migrations/old_migrations/1.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/10.yaml b/core/src/androidTest/resources/migrations/old_migrations/10.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/10.yaml rename to core/src/androidTest/resources/migrations/old_migrations/10.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/11.yaml b/core/src/androidTest/resources/migrations/old_migrations/11.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/11.yaml rename to core/src/androidTest/resources/migrations/old_migrations/11.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/12.yaml b/core/src/androidTest/resources/migrations/old_migrations/12.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/12.yaml rename to core/src/androidTest/resources/migrations/old_migrations/12.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/13.yaml b/core/src/androidTest/resources/migrations/old_migrations/13.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/13.yaml rename to core/src/androidTest/resources/migrations/old_migrations/13.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/14.yaml b/core/src/androidTest/resources/migrations/old_migrations/14.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/14.yaml rename to core/src/androidTest/resources/migrations/old_migrations/14.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/15.yaml b/core/src/androidTest/resources/migrations/old_migrations/15.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/15.yaml rename to core/src/androidTest/resources/migrations/old_migrations/15.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/16.yaml b/core/src/androidTest/resources/migrations/old_migrations/16.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/16.yaml rename to core/src/androidTest/resources/migrations/old_migrations/16.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/17.yaml b/core/src/androidTest/resources/migrations/old_migrations/17.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/17.yaml rename to core/src/androidTest/resources/migrations/old_migrations/17.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/18.yaml b/core/src/androidTest/resources/migrations/old_migrations/18.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/18.yaml rename to core/src/androidTest/resources/migrations/old_migrations/18.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/19.yaml b/core/src/androidTest/resources/migrations/old_migrations/19.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/19.yaml rename to core/src/androidTest/resources/migrations/old_migrations/19.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/2.yaml b/core/src/androidTest/resources/migrations/old_migrations/2.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/2.yaml rename to core/src/androidTest/resources/migrations/old_migrations/2.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/20.yaml b/core/src/androidTest/resources/migrations/old_migrations/20.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/20.yaml rename to core/src/androidTest/resources/migrations/old_migrations/20.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/21.yaml b/core/src/androidTest/resources/migrations/old_migrations/21.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/21.yaml rename to core/src/androidTest/resources/migrations/old_migrations/21.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/22.yaml b/core/src/androidTest/resources/migrations/old_migrations/22.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/22.yaml rename to core/src/androidTest/resources/migrations/old_migrations/22.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/23.yaml b/core/src/androidTest/resources/migrations/old_migrations/23.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/23.yaml rename to core/src/androidTest/resources/migrations/old_migrations/23.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/24.yaml b/core/src/androidTest/resources/migrations/old_migrations/24.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/24.yaml rename to core/src/androidTest/resources/migrations/old_migrations/24.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/3.yaml b/core/src/androidTest/resources/migrations/old_migrations/3.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/3.yaml rename to core/src/androidTest/resources/migrations/old_migrations/3.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/4.yaml b/core/src/androidTest/resources/migrations/old_migrations/4.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/4.yaml rename to core/src/androidTest/resources/migrations/old_migrations/4.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/5.yaml b/core/src/androidTest/resources/migrations/old_migrations/5.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/5.yaml rename to core/src/androidTest/resources/migrations/old_migrations/5.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/6.yaml b/core/src/androidTest/resources/migrations/old_migrations/6.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/6.yaml rename to core/src/androidTest/resources/migrations/old_migrations/6.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/7.yaml b/core/src/androidTest/resources/migrations/old_migrations/7.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/7.yaml rename to core/src/androidTest/resources/migrations/old_migrations/7.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/8.yaml b/core/src/androidTest/resources/migrations/old_migrations/8.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/8.yaml rename to core/src/androidTest/resources/migrations/old_migrations/8.yaml diff --git a/core/src/androidTest/resources/migrations/real_migrations/9.yaml b/core/src/androidTest/resources/migrations/old_migrations/9.yaml similarity index 100% rename from core/src/androidTest/resources/migrations/real_migrations/9.yaml rename to core/src/androidTest/resources/migrations/old_migrations/9.yaml diff --git a/core/src/main/assets/migrations/1.yaml b/core/src/main/assets/migrations/1.yaml index 587e29b946..c02e8209c0 100644 --- a/core/src/main/assets/migrations/1.yaml +++ b/core/src/main/assets/migrations/1.yaml @@ -1,3 +1,58 @@ up: -seeds: -down: \ No newline at end of file +- CREATE TABLE Configuration (_id INTEGER PRIMARY KEY AUTOINCREMENT,serverUrl TEXT NOT NULL UNIQUE); +- CREATE TABLE User (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,birthday TEXT,education TEXT,gender TEXT,jobTitle TEXT,surname TEXT,firstName TEXT,introduction TEXT,employer TEXT,interests TEXT,languages TEXT,email TEXT,phoneNumber TEXT,nationality TEXT); +- CREATE TABLE UserCredentials (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,username TEXT,user TEXT NOT NULL UNIQUE, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +- CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT); +- CREATE TABLE UserOrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL,organisationUnit TEXT NOT NULL,organisationUnitScope TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (user, organisationUnit, organisationUnitScope)); +- CREATE TABLE AuthenticatedUser (_id INTEGER PRIMARY KEY AUTOINCREMENT,user TEXT NOT NULL UNIQUE,credentials TEXT NOT NULL, FOREIGN KEY (user) REFERENCES User (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE OptionSet (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,version INTEGER,valueType TEXT); +- CREATE TABLE Option (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,optionSet TEXT NOT NULL, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +- CREATE TABLE Program (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, version INTEGER,onlyEnrollOnce INTEGER,enrollmentDateLabel TEXT,displayIncidentDate INTEGER,incidentDateLabel TEXT,registration INTEGER,selectEnrollmentDatesInFuture INTEGER,dataEntryMethod INTEGER,ignoreOverdueEvents INTEGER,relationshipFromA INTEGER,selectIncidentDatesInFuture INTEGER,captureCoordinates INTEGER,useFirstStageDuringRegistration INTEGER,displayFrontPageList INTEGER,programType TEXT,relationshipType TEXT,relationshipText TEXT,relatedProgram TEXT,trackedEntityType TEXT,categoryCombo TEXT,accessDataWrite INTEGER,expiryDays INTEGER,completeEventsExpiryDays INTEGER,expiryPeriodType TEXT,minAttributesRequiredToSearch INTEGER,maxTeiCountToReturn INTEGER, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE TrackedEntityType (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT); +- CREATE TABLE DataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, valueType TEXT,zeroIsSignificant INTEGER,aggregationType TEXT,formName TEXT,numberType TEXT,domainType TEXT,dimension TEXT,displayFormName TEXT,optionSet TEXT,categoryCombo TEXT, FOREIGN KEY ( optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE ProgramStageDataElement (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,displayInReports INTEGER,compulsory INTEGER,allowProvidedElsewhere INTEGER,sortOrder INTEGER,allowFutureDate INTEGER,dataElement TEXT NOT NULL,programStage TEXT NOT NULL,programStageSection TEXT, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE Relationship (_id INTEGER PRIMARY KEY AUTOINCREMENT,trackedEntityInstanceA TEXT NOT NULL,trackedEntityInstanceB TEXT NOT NULL,relationshipType TEXT NOT NULL, FOREIGN KEY (relationshipType) REFERENCES RelationshipType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceA) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityInstanceB) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE RelationshipType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, bIsToA TEXT, AIsToB TEXT ); +- CREATE TABLE ProgramStageSection (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,sortOrder INTEGER,programStage TEXT NOT NULL,desktopRenderType TEXT,mobileRenderType TEXT, FOREIGN KEY ( programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE ProgramStage (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, executionDateLabel TEXT,allowGenerateNextVisit INTEGER,validCompleteOnly INTEGER,reportDateToUse TEXT,openAfterEnrollment INTEGER,repeatable INTEGER,captureCoordinates INTEGER,formType TEXT,displayGenerateEventBox INTEGER,generatedByEnrollmentDate INTEGER,autoGenerateEvent INTEGER,sortOrder INTEGER,hideDueDate INTEGER,blockEntryForm INTEGER,minDaysFromStart INTEGER,standardInterval INTEGER,program TEXT NOT NULL,periodType TEXT,accessDataWrite INTEGER,remindCompleted INTEGER, FOREIGN KEY ( program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE ProgramRuleVariable (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,useCodeForOptionSet INTEGER,program TEXT NOT NULL,programStage TEXT,dataElement TEXT,trackedEntityAttribute TEXT,programRuleVariableSourceType TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute(uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE TrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,pattern TEXT,sortOrderInListNoProgram INTEGER,optionSet TEXT,valueType TEXT,expression TEXT,searchScope TEXT,programScope INTEGER,displayInListNoProgram INTEGER,generated INTEGER,displayOnVisitSchedule INTEGER,orgunitScope INTEGER,uniqueProperty INTEGER,inherit INTEGER, FOREIGN KEY (optionSet) REFERENCES OptionSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE ProgramTrackedEntityAttribute (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, mandatory INTEGER,trackedEntityAttribute TEXT NOT NULL,allowFutureDate INTEGER,displayInList INTEGER,program TEXT NOT NULL,sortOrder INTEGER,searchable INTEGER, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE Constant (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,value TEXT); +- CREATE TABLE SystemInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT, serverDate TEXT,dateFormat TEXT,version TEXT,contextPath TEXT); +- CREATE TABLE ProgramRule (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,priority INTEGER,condition TEXT,program TEXT NOT NULL,programStage TEXT, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE ProgramIndicator (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,shortName TEXT,displayShortName TEXT,description TEXT,displayDescription TEXT,displayInForm INTEGER,expression TEXT,dimensionItem TEXT,filter TEXT,decimals INTEGER,program TEXT NOT NULL, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +- CREATE TABLE ProgramRuleAction (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,data TEXT,content TEXT,location TEXT,trackedEntityAttribute TEXT,programIndicator TEXT,programStageSection TEXT,programRuleActionType TEXT,programStage TEXT,dataElement TEXT,programRule TEXT NOT NULL, FOREIGN KEY (programRule) REFERENCES ProgramRule (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityAttribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programStage) REFERENCES ProgramStage (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- 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 (event) REFERENCES Event (uid) ON DELETE CASCADE); +- CREATE TABLE TrackedEntityAttributeValue (_id INTEGER PRIMARY KEY AUTOINCREMENT,created TEXT,lastUpdated TEXT,value TEXT,trackedEntityAttribute TEXT NOT NULL,trackedEntityInstance TEXT NOT NULL, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- 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 DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE, FOREIGN KEY (attributeCategoryOptions) REFERENCES CategoryOption (uid) ON DELETE CASCADE, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE); +- CREATE TABLE TrackedEntityInstance (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,trackedEntityType TEXT NOT NULL,coordinates TEXT,featureType TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED FOREIGN KEY (trackedEntityType) REFERENCES TrackedEntityType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE Enrollment (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,created TEXT,lastUpdated TEXT,createdAtClient TEXT,lastUpdatedAtClient TEXT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL,enrollmentDate TEXT,incidentDate TEXT,followup INTEGER,status TEXT,trackedEntityInstance TEXT NOT NULL,latitude TEXT,longitude TEXT,state TEXT, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (trackedEntityInstance) REFERENCES TrackedEntityInstance (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE Resource (_id INTEGER PRIMARY KEY AUTOINCREMENT,resourceType TEXT NOT NULL,lastSynced TEXT); +- CREATE TABLE OrganisationUnitProgramLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,organisationUnit TEXT NOT NULL,program TEXT NOT NULL, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (program) REFERENCES Program (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (organisationUnit, program)); +- CREATE TABLE UserRole (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); +- CREATE TABLE ProgramStageSectionProgramIndicatorLinkTable (_id INTEGER PRIMARY KEY AUTOINCREMENT,programStageSection TEXT NOT NULL,programIndicator TEXT NOT NULL, FOREIGN KEY (programStageSection) REFERENCES ProgramStageSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programStageSection, programIndicator)); +- CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); +- CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, startDate TEXT,endDate TEXT); +- CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryOption TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); +- CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); +- CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); +- CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); +- CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); +- CREATE TABLE DataSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, periodType TEXT,categoryCombo TEXT NOT NULL,mobile INTEGER,version INTEGER,expiryDays INTEGER,timelyDays INTEGER,notifyCompletingUser INTEGER,openFuturePeriods INTEGER,fieldCombinationRequired INTEGER,validCompleteOnly INTEGER,noValueRequiresComment INTEGER,skipOffline INTEGER,dataElementDecoration INTEGER,renderAsTabs INTEGER,renderHorizontally INTEGER,accessDataWrite INTEGER, FOREIGN KEY ( categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE DataSetDataElementLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,dataElement TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, dataElement)); +- CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit)); +- CREATE TABLE Indicator (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, annualized INTEGER,indicatorType TEXT,numerator TEXT,numeratorDescription TEXT,denominator TEXT,denominatorDescription TEXT,url TEXT, FOREIGN KEY ( indicatorType) REFERENCES IndicatorType (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE IndicatorType (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, number INTEGER,factor INTEGER); +- CREATE TABLE DataSetIndicatorLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,indicator TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (indicator) REFERENCES Indicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, indicator)); +- CREATE TABLE DataValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataElement TEXT NOT NULL,period TEXT NOT NULL,organisationUnit TEXT NOT NULL,categoryOptionCombo TEXT NOT NULL,attributeOptionCombo TEXT NOT NULL,value TEXT,storedBy TEXT,created TEXT,lastUpdated TEXT,comment TEXT,followUp INTEGER, FOREIGN KEY (dataElement) REFERENCES DataElement (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (period) REFERENCES Period (periodId) FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attributeOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo)); +- CREATE TABLE Period (_id INTEGER PRIMARY KEY AUTOINCREMENT, periodId TEXT,periodType TEXT,startDate TEXT,endDate TEXT, UNIQUE (periodId)); +- CREATE TABLE ObjectStyle (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,color TEXT,icon TEXT, UNIQUE (uid)); +- CREATE TABLE ValueTypeDeviceRendering (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT,objectTable TEXT,deviceType TEXT,type TEXT,min INTEGER,max INTEGER,step INTEGER,decimalPoints INTEGER, UNIQUE (uid, deviceType)); +- CREATE TABLE Note (_id INTEGER PRIMARY KEY AUTOINCREMENT, enrollment TEXT,value TEXT,storedBy TEXT,storedDate TEXT, FOREIGN KEY (enrollment) REFERENCES Enrollment (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (enrollment, value, storedBy, storedDate)); +- CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED); +- CREATE TABLE LegendSet (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, symbolizer TEXT); +- CREATE TABLE ProgramIndicatorLegendSetLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programIndicator TEXT NOT NULL,legendSet TEXT NOT NULL, FOREIGN KEY (programIndicator) REFERENCES ProgramIndicator (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programIndicator, legendSet)); +- CREATE TABLE SystemSetting (_id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT,value TEXT, UNIQUE (key)); +- CREATE TABLE ProgramSection (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, description TEXT,program TEXT,sortOrder INTEGER,formName TEXT); +- CREATE TABLE ProgramSectionAttributeLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, programSection TEXT NOT NULL,attribute TEXT NOT NULL, FOREIGN KEY (programSection) REFERENCES ProgramSection (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (attribute) REFERENCES TrackedEntityAttribute (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (programSection, attribute)); \ No newline at end of file diff --git a/core/src/main/assets/migrations/2.yaml b/core/src/main/assets/migrations/2.yaml index 84ca7d5c08..0fd6f8c314 100644 --- a/core/src/main/assets/migrations/2.yaml +++ b/core/src/main/assets/migrations/2.yaml @@ -1,19 +1,2 @@ up: - - ALTER TABLE DataElement ADD COLUMN categoryCombo Text; - - ALTER TABLE Program ADD COLUMN categoryCombo Text; - - ALTER TABLE Event ADD COLUMN attributeCategoryOptions Text; - - ALTER TABLE Event ADD COLUMN attributeOptionCombo Text; - - ALTER TABLE Event ADD COLUMN trackedEntityInstance Text; - - CREATE TABLE CategoryCategoryOptionLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,option TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryOption) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryOption)); - - CREATE TABLE CategoryOptionComboCategoryLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,categoryOptionCombo TEXT NOT NULL,category TEXT NOT NULL, FOREIGN KEY (categoryOptionCombo) REFERENCES CategoryOptionCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (category) REFERENCES CategoryOption (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (categoryOptionCombo, category)); - - CREATE TABLE CategoryOptionCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, categoryCombo TEXT, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED ); - - CREATE TABLE CategoryOption (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT); - - CREATE TABLE CategoryCategoryComboLink (_id INTEGER PRIMARY KEY AUTOINCREMENT,category TEXT NOT NULL,categoryCombo TEXT NOT NULL, FOREIGN KEY (category) REFERENCES Category (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (categoryCombo) REFERENCES CategoryCombo (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,UNIQUE (category, categoryCombo)); - - CREATE TABLE CategoryCombo (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT, isDefault INTEGER); - - CREATE TABLE Category (_id INTEGER PRIMARY KEY AUTOINCREMENT,uid TEXT NOT NULL UNIQUE,code TEXT,name TEXT,displayName TEXT,created TEXT,lastUpdated TEXT,dataDimensionType TEXT); -down: - - DROP TABLE IF EXISTS CategoryCombo; - - DROP TABLE IF EXISTS CategoryCategoryComboLink; - - DROP TABLE IF EXISTS CategoryOptionCombo; - - DROP TABLE IF EXISTS CategoryOptionComboCategoryLink; - - DROP TABLE IF EXISTS CategoryCategoryOptionLink; \ No newline at end of file +- CREATE TABLE TrackedEntityAttributeReservedValue (_id INTEGER PRIMARY KEY AUTOINCREMENT, ownerObject TEXT,ownerUid TEXT,key TEXT,value TEXT,created TEXT,expiryDate TEXT,organisationUnit TEXT); \ No newline at end of file diff --git a/core/src/main/assets/migrations/3.yaml b/core/src/main/assets/migrations/3.yaml index 1d8e5409c5..5b4575d434 100644 --- a/core/src/main/assets/migrations/3.yaml +++ b/core/src/main/assets/migrations/3.yaml @@ -1,14 +1,2 @@ up: - - PRAGMA foreign_keys=off; - - BEGIN TRANSACTION; - - ALTER TABLE Event RENAME TO EventOld; - - 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); - - INSERT INTO Event (uid, enrollment, created, lastUpdated, createdAtClient, lastUpdatedAtClient, status, latitude, longitude, program, programStage, organisationUnit, eventDate, completedDate, dueDate, state, attributeCategoryOptions, attributeOptionCombo, trackedEntityInstance) Select uid, enrollment, created, lastUpdated, createdAtClient, lastUpdatedAtClient, status, latitude, longitude, program, programStage, organisationUnit, eventDate, completedDate, dueDate, state, attributeCategoryOptions, attributeOptionCombo, trackedEntityInstance from EventOld - - ALTER TABLE TrackedEntityDataValue RENAME TO TrackedEntityDataValueOld; - - 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); - - INSERT INTO TrackedEntityDataValue (event, dataElement, storedBy, value, created, lastUpdated, providedElsewhere) Select event, dataElement, storedBy, value, created, lastUpdated, providedElsewhere from TrackedEntityDataValueOld - - DROP TABLE IF EXISTS TrackedEntityDataValueOld; - - DROP TABLE IF EXISTS EventOld; - - COMMIT; - - PRAGMA foreign_keys=on; -down: \ No newline at end of file +- ALTER TABLE UserOrganisationUnit ADD COLUMN root INTEGER; \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/D2.java b/core/src/main/java/org/hisp/dhis/android/core/D2.java index 88612853a3..f819f0d8f0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/D2.java +++ b/core/src/main/java/org/hisp/dhis/android/core/D2.java @@ -39,8 +39,8 @@ import org.hisp.dhis.android.core.calls.MetadataCall; import org.hisp.dhis.android.core.calls.SingleDataCall; import org.hisp.dhis.android.core.calls.TrackedEntityInstancePostCall; +import org.hisp.dhis.android.core.calls.TrackedEntityInstanceWithLimitEndpointCall; import org.hisp.dhis.android.core.calls.TrackerDataCall; -import org.hisp.dhis.android.core.calls.TrackerEntitiesDataCall; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; import org.hisp.dhis.android.core.configuration.ConfigurationModel; import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; @@ -50,14 +50,16 @@ import org.hisp.dhis.android.core.imports.WebResponse; import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValueManager; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceEndPointCall; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceListDownloadAndPersistCall; import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQuery; import org.hisp.dhis.android.core.trackedentity.search.TrackedEntityInstanceQueryCall; import org.hisp.dhis.android.core.user.IsUserLoggedInCallable; import org.hisp.dhis.android.core.user.LogOutUserCallable; import org.hisp.dhis.android.core.user.User; import org.hisp.dhis.android.core.user.UserAuthenticateCall; +import org.hisp.dhis.android.core.utils.services.ProgramIndicatorEngine; +import java.util.Collection; import java.util.List; import java.util.concurrent.Callable; @@ -133,19 +135,18 @@ public Call syncSingleData(int eventLimitByOrgUnit) { } @NonNull - public Call syncTrackerData() { + public Call> syncTrackerData() { return TrackerDataCall.create(databaseAdapter, retrofit); } @NonNull - public Call> - downloadTrackedEntityInstance(String trackedEntityInstanceUid) { - return TrackedEntityInstanceEndPointCall.create(databaseAdapter, retrofit, trackedEntityInstanceUid); + public Call> downloadTrackedEntityInstancesByUid(Collection uids) { + return TrackedEntityInstanceListDownloadAndPersistCall.create(databaseAdapter, retrofit, uids); } @NonNull - public Call downloadTrackedEntityInstances(int teiLimitByOrgUnit) { - return TrackerEntitiesDataCall.create(databaseAdapter, retrofit, teiLimitByOrgUnit); + public Call> downloadTrackedEntityInstances(int teiLimit, boolean limitByOrgUnit) { + return TrackedEntityInstanceWithLimitEndpointCall.create(databaseAdapter, retrofit, teiLimit, limitByOrgUnit); } @NonNull @@ -168,6 +169,11 @@ public Call> syncSingleEvents() { return EventPostCall.create(databaseAdapter, retrofit); } + public String evaluateProgramIndicator(String enrollmentUid, String eventUid, String programIndicatorUid) { + return ProgramIndicatorEngine.create(databaseAdapter) + .getProgramIndicatorValue(enrollmentUid, eventUid, programIndicatorUid); + } + public static class Builder { private ConfigurationModel configuration; private DatabaseAdapter databaseAdapter; diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java index c1d3193a8b..2e80816df6 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/MetadataCall.java @@ -38,15 +38,14 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.SimpleCallFactory; import org.hisp.dhis.android.core.common.SyncCall; +import org.hisp.dhis.android.core.common.UidsHelper; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.dataset.DataSetParentCall; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitCall; import org.hisp.dhis.android.core.program.Program; -import org.hisp.dhis.android.core.program.ProgramAccessEndpointCall; import org.hisp.dhis.android.core.program.ProgramParentCall; -import org.hisp.dhis.android.core.program.ProgramParentUidsHelper; import org.hisp.dhis.android.core.settings.SystemSetting; import org.hisp.dhis.android.core.settings.SystemSettingCall; import org.hisp.dhis.android.core.systeminfo.SystemInfo; @@ -55,7 +54,6 @@ import org.hisp.dhis.android.core.user.UserCall; import java.util.List; -import java.util.Set; import retrofit2.Response; import retrofit2.Retrofit; @@ -72,8 +70,7 @@ public class MetadataCall extends SyncCall { private final SimpleCallFactory userCallFactory; private final SimpleCallFactory> categoryCallFactory; private final SimpleCallFactory> categoryComboCallFactory; - private final SimpleCallFactory> programAccessCallFactory; - private final ProgramParentCall.Factory programParentCallFactory; + private final SimpleCallFactory> programParentCallFactory; private final OrganisationUnitCall.Factory organisationUnitCallFactory; private final DataSetParentCall.Factory dataSetParentCallFactory; @@ -84,8 +81,7 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, @NonNull SimpleCallFactory userCallFactory, @NonNull SimpleCallFactory> categoryCallFactory, @NonNull SimpleCallFactory> categoryComboCallFactory, - @NonNull SimpleCallFactory> programAccessCallFactory, - @NonNull ProgramParentCall.Factory programParentCallFactory, + @NonNull SimpleCallFactory> programParentCallFactory, @NonNull OrganisationUnitCall.Factory organisationUnitCallFactory, @NonNull DataSetParentCall.Factory dataSetParentCallFactory) { this.databaseAdapter = databaseAdapter; @@ -96,7 +92,6 @@ public MetadataCall(@NonNull DatabaseAdapter databaseAdapter, this.userCallFactory = userCallFactory; this.categoryCallFactory = categoryCallFactory; this.categoryComboCallFactory = categoryComboCallFactory; - this.programAccessCallFactory = programAccessCallFactory; this.programParentCallFactory = programParentCallFactory; this.organisationUnitCallFactory = organisationUnitCallFactory; this.dataSetParentCallFactory = dataSetParentCallFactory; @@ -138,22 +133,15 @@ public Response call() throws Exception { return categoryComboResponse; } - Response> programAccessResponse - = programAccessCallFactory.create(genericCallData).call(); - if (!programAccessResponse.isSuccessful()) { - return programAccessResponse; - } - - Set programUids = ProgramParentUidsHelper - .getProgramUidsWithDataReadAccess(programAccessResponse.body().items()); - Response programResponse = programParentCallFactory.create(genericCallData, programUids).call(); + Response> programResponse = programParentCallFactory.create(genericCallData).call(); if (!programResponse.isSuccessful()) { return programResponse; } User user = userResponse.body(); Response> organisationUnitResponse = - organisationUnitCallFactory.create(genericCallData, user, programUids).call(); + organisationUnitCallFactory.create(genericCallData, user, + UidsHelper.getUids(programResponse.body().items())).call(); if (!organisationUnitResponse.isSuccessful()) { return organisationUnitResponse; @@ -182,7 +170,6 @@ public static MetadataCall create(DatabaseAdapter databaseAdapter, Retrofit retr UserCall.FACTORY, CategoryEndpointCall.FACTORY, CategoryComboEndpointCall.FACTORY, - ProgramAccessEndpointCall.FACTORY, ProgramParentCall.FACTORY, OrganisationUnitCall.FACTORY, DataSetParentCall.FACTORY diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackedEntityInstanceWithLimitEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackedEntityInstanceWithLimitEndpointCall.java new file mode 100644 index 0000000000..50cab9875f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackedEntityInstanceWithLimitEndpointCall.java @@ -0,0 +1,165 @@ +package org.hisp.dhis.android.core.calls; + + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.common.D2CallException; +import org.hisp.dhis.android.core.common.GenericCallData; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.SyncCall; +import org.hisp.dhis.android.core.data.api.OuMode; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import org.hisp.dhis.android.core.data.database.Transaction; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; +import org.hisp.dhis.android.core.systeminfo.SystemInfo; +import org.hisp.dhis.android.core.systeminfo.SystemInfoCall; +import org.hisp.dhis.android.core.trackedentity.TeiQuery; +import org.hisp.dhis.android.core.trackedentity.TeisEndPointCall; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; +import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; +import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; +import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStoreInterface; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import retrofit2.Response; +import retrofit2.Retrofit; + +public final class TrackedEntityInstanceWithLimitEndpointCall extends SyncCall> { + + private final boolean limitByOrgUnit; + private final int teiLimit; + private final DatabaseAdapter databaseAdapter; + private final Retrofit retrofit; + private final UserOrganisationUnitLinkStoreInterface userOrganisationUnitLinkStore; + private final D2CallException.Builder httpExceptionBuilder; + + private TrackedEntityInstanceWithLimitEndpointCall( + @NonNull DatabaseAdapter databaseAdapter, + @NonNull Retrofit retrofit, + @NonNull UserOrganisationUnitLinkStoreInterface userOrganisationUnitLinkStore, + int teiLimit, + boolean limitByOrgUnit) { + this.databaseAdapter = databaseAdapter; + this.retrofit = retrofit; + this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; + this.teiLimit = teiLimit; + this.limitByOrgUnit = limitByOrgUnit; + this.httpExceptionBuilder = D2CallException.builder().isHttpError(true).errorDescription("TEIs call failed"); + } + + @Override + public List call() throws D2CallException { + this.setExecuted(); + Transaction transaction = databaseAdapter.beginNewTransaction(); + + try { + Response systemInfoResponse = SystemInfoCall.FACTORY.create(databaseAdapter, retrofit).call(); + + if (!systemInfoResponse.isSuccessful()) { + throw httpExceptionBuilder.httpErrorCode(systemInfoResponse.code()).build(); + } + + SystemInfo systemInfo = systemInfoResponse.body(); + GenericCallData genericCallData = GenericCallData.create(databaseAdapter, retrofit, + systemInfo.serverDate()); + + List trackedEntityInstances = trackerCall(genericCallData); + + transaction.setSuccessful(); + + return trackedEntityInstances; + + } catch (Exception e) { + throw httpExceptionBuilder.originalException(e).build(); + } finally { + transaction.end(); + } + } + + private List trackerCall(GenericCallData genericCallData) throws D2CallException { + Set organisationUnitUids; + List trackedEntityInstances = new ArrayList<>(); + TeiQuery.Builder teiQueryBuilder = TeiQuery.Builder.create(); + int pageSize = TeiQuery.Builder.create().build().getPageSize(); + int numPages = (int) Math.ceil((double) teiLimit / pageSize); + + if (limitByOrgUnit) { + organisationUnitUids = getOrgUnitUids(); + Set orgUnitWrapper = new HashSet<>(); + for (String orgUnitUid : organisationUnitUids) { + orgUnitWrapper.clear(); + orgUnitWrapper.add(orgUnitUid); + teiQueryBuilder.withOrgUnits(orgUnitWrapper); + trackedEntityInstances.addAll(getTrackedEntityInstances(teiQueryBuilder, genericCallData, pageSize, + numPages)); + } + } else { + organisationUnitUids = userOrganisationUnitLinkStore.queryRootOrganisationUnitUids(); + teiQueryBuilder.withOrgUnits(organisationUnitUids).withOuMode(OuMode.DESCENDANTS); + trackedEntityInstances = getTrackedEntityInstances(teiQueryBuilder, genericCallData, pageSize, numPages); + } + + return trackedEntityInstances; + } + + private List getTrackedEntityInstances(TeiQuery.Builder teiQueryBuilder, + GenericCallData genericCallData, int pageSize, int numPages) throws D2CallException { + Response> trackerCallResponse; + List trackedEntityInstances = new ArrayList<>(); + + for (int page = 1; page <= numPages; page++) { + try { + if (page == numPages) { + teiQueryBuilder.withPage(page).withPageLimit(teiLimit - ((page - 1) * pageSize)); + } + teiQueryBuilder.withPage(page); + trackerCallResponse = TeisEndPointCall.create(genericCallData, teiQueryBuilder.build()).call(); + + if (!trackerCallResponse.isSuccessful()) { + throw httpExceptionBuilder.httpErrorCode(trackerCallResponse.code()).build(); + } + + trackedEntityInstances.addAll(trackerCallResponse.body().items()); + } catch (Exception e) { + throw httpExceptionBuilder.originalException(e).build(); + } + + if (trackerCallResponse.body().items().size() < pageSize) { + break; + } + } + + return trackedEntityInstances; + } + + private Set getOrgUnitUids() { + Set userOrganisationUnitLinks = userOrganisationUnitLinkStore.selectAll( + UserOrganisationUnitLinkModel.factory); + + Set organisationUnitUids = new HashSet<>(); + + for (UserOrganisationUnitLinkModel linkModel: userOrganisationUnitLinks) { + if (linkModel.organisationUnitScope().equals( + OrganisationUnitModel.Scope.SCOPE_DATA_CAPTURE.name())) { + organisationUnitUids.add(linkModel.organisationUnit()); + } + } + + return organisationUnitUids; + } + + public static TrackedEntityInstanceWithLimitEndpointCall create(DatabaseAdapter databaseAdapter, Retrofit retrofit, + int teiLimit, boolean limitByOrgUnit) { + return new TrackedEntityInstanceWithLimitEndpointCall( + databaseAdapter, + retrofit, + UserOrganisationUnitLinkStore.create(databaseAdapter), + teiLimit, + limitByOrgUnit + ); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerDataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerDataCall.java index 92abba68b7..dccc4cde84 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerDataCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerDataCall.java @@ -2,21 +2,21 @@ import android.support.annotation.NonNull; +import org.hisp.dhis.android.core.common.D2CallException; +import org.hisp.dhis.android.core.common.D2CallExecutor; import org.hisp.dhis.android.core.common.SyncCall; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceEndPointCall; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceListDownloadAndPersistCall; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceStore; import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceStoreImpl; +import java.util.List; import java.util.Map; -import retrofit2.Response; import retrofit2.Retrofit; -@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") -public final class TrackerDataCall extends SyncCall { +public final class TrackerDataCall extends SyncCall> { private final DatabaseAdapter databaseAdapter; private final Retrofit retrofit; @@ -31,42 +31,12 @@ private TrackerDataCall(@NonNull DatabaseAdapter databaseAdapter, } @Override - public Response call() throws Exception { + public List call() throws D2CallException { super.setExecuted(); - - Response response = null; - - Map trackedEntityInstances = - trackedEntityInstanceStore.querySynced(); - - if (!trackedEntityInstances.isEmpty()) { - Transaction transaction = databaseAdapter.beginNewTransaction(); - try { - response = trackedEntityInstanceCall(trackedEntityInstances); - transaction.setSuccessful(); - } finally { - transaction.end(); - } - } - - return response; - } - - private Response trackedEntityInstanceCall( - Map trackedEntityInstances) throws Exception { - Response response = null; - - for (Map.Entry entry : trackedEntityInstances.entrySet()) { - - response = TrackedEntityInstanceEndPointCall.create(databaseAdapter, retrofit, - entry.getValue().uid()).call(); - - if (!response.isSuccessful()) { - return response; - } - } - - return response; + Map trackedEntityInstances = trackedEntityInstanceStore.querySynced(); + Call> call = TrackedEntityInstanceListDownloadAndPersistCall + .create(databaseAdapter, retrofit, trackedEntityInstances.keySet()); + return new D2CallExecutor().executeD2Call(call); } public static TrackerDataCall create(DatabaseAdapter databaseAdapter, Retrofit retrofit) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java deleted file mode 100644 index b4a702577d..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/TrackerEntitiesDataCall.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.hisp.dhis.android.core.calls; - - -import android.support.annotation.NonNull; - -import org.hisp.dhis.android.core.common.GenericCallData; -import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; -import org.hisp.dhis.android.core.common.SyncCall; -import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.data.database.Transaction; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; -import org.hisp.dhis.android.core.resource.ResourceModel; -import org.hisp.dhis.android.core.systeminfo.SystemInfo; -import org.hisp.dhis.android.core.systeminfo.SystemInfoCall; -import org.hisp.dhis.android.core.trackedentity.TeiQuery; -import org.hisp.dhis.android.core.trackedentity.TeisEndPointCall; -import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; -import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; - -import java.util.HashSet; -import java.util.Set; - -import retrofit2.Response; -import retrofit2.Retrofit; - -public final class TrackerEntitiesDataCall extends SyncCall { - - private final int teiLimitByOrgUnit; - private final DatabaseAdapter databaseAdapter; - private final Retrofit retrofit; - private final ObjectWithoutUidStore userOrganisationUnitLinkStore; - - private TrackerEntitiesDataCall( - @NonNull DatabaseAdapter databaseAdapter, - @NonNull Retrofit retrofit, - @NonNull ObjectWithoutUidStore userOrganisationUnitLinkStore, - int teiLimitByOrgUnit) { - this.databaseAdapter = databaseAdapter; - this.retrofit = retrofit; - this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; - this.teiLimitByOrgUnit = teiLimitByOrgUnit; - } - - @Override - public Response call() throws Exception { - this.setExecuted(); - - Response response = null; - - Transaction transaction = databaseAdapter.beginNewTransaction(); - - try { - response = SystemInfoCall.FACTORY.create(databaseAdapter, retrofit).call(); - - if (!response.isSuccessful()) { - return response; - } - - SystemInfo systemInfo = (SystemInfo) response.body(); - GenericCallData genericCallData = GenericCallData.create(databaseAdapter, retrofit, - systemInfo.serverDate()); - - response = trackerCall(genericCallData); - - if (response == null || !response.isSuccessful()) { - return response; - } - - transaction.setSuccessful(); - - return response; - } finally { - transaction.end(); - } - } - - private Response trackerCall(GenericCallData genericCallData) throws Exception { - Response response = null; - - Set organisationUnitUids = getOrgUnitUids(); - - int pageSize = TeiQuery.Builder.create().build().getPageSize(); - - int numPages = (int) Math.ceil((double) teiLimitByOrgUnit / pageSize); - - int pageLimit = 0; - - for (String orgUnitUid : organisationUnitUids) { - - int teisDownloaded = 0; - - for (int page = 1; page <= numPages; page++) { - - if (page == numPages && teiLimitByOrgUnit > 0) { - pageLimit = teiLimitByOrgUnit - teisDownloaded; - } - - TeiQuery teiQuery = TeiQuery. - Builder.create() - .withOrgUnit(orgUnitUid) - .withPage(page) - .withPageLimit(pageLimit) - .build(); - - response = TeisEndPointCall.create(genericCallData, teiQuery).call(); - - if (!response.isSuccessful()) { - return response; - } - - teisDownloaded = teisDownloaded + teiQuery.getPageSize(); - } - - } - - if (response != null && response.isSuccessful()) { - genericCallData.resourceHandler().handleResource(ResourceModel.Type.TRACKED_ENTITY_INSTANCE, - genericCallData.serverDate()); - } - - return response; - } - - private Set getOrgUnitUids() { - Set userOrganisationUnitLinks = userOrganisationUnitLinkStore.selectAll( - UserOrganisationUnitLinkModel.factory); - - Set organisationUnitUids = new HashSet<>(); - - for (UserOrganisationUnitLinkModel linkModel: userOrganisationUnitLinks) { - if (linkModel.organisationUnitScope().equals( - OrganisationUnitModel.Scope.SCOPE_DATA_CAPTURE.name())) { - organisationUnitUids.add(linkModel.organisationUnit()); - } - } - - return organisationUnitUids; - } - - - public static TrackerEntitiesDataCall create(DatabaseAdapter databaseAdapter, Retrofit retrofit, - int teiLimitByOrgUnit) { - return new TrackerEntitiesDataCall( - databaseAdapter, - retrofit, - UserOrganisationUnitLinkStore.create(databaseAdapter), - teiLimitByOrgUnit - ); - } -} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/calls/TransactionalCall.java b/core/src/main/java/org/hisp/dhis/android/core/calls/TransactionalCall.java index 258d7fca5d..ae83d5c39a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/calls/TransactionalCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/calls/TransactionalCall.java @@ -34,17 +34,17 @@ import retrofit2.Response; -public abstract class TransactionalCall extends SyncCall { +public abstract class TransactionalCall extends SyncCall> { protected final DatabaseAdapter databaseAdapter; protected TransactionalCall(DatabaseAdapter databaseAdapter) { this.databaseAdapter = databaseAdapter; } - public abstract Response callBody() throws Exception; + public abstract Response callBody() throws Exception; @Override - public final Response call() throws Exception { + public final Response call() throws Exception { super.setExecuted(); Transaction transaction = databaseAdapter.beginNewTransaction(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/APICallExecutor.java b/core/src/main/java/org/hisp/dhis/android/core/common/APICallExecutor.java new file mode 100644 index 0000000000..174b109c1e --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/APICallExecutor.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.common; + +import android.util.Log; + +import java.io.IOException; +import java.util.List; + +import retrofit2.Call; +import retrofit2.Response; + +public final class APICallExecutor { + + private final D2CallException.Builder exceptionBuilder = D2CallException + .builder() + .isHttpError(true); + + public

List

executePayloadCall(Call> call) throws D2CallException { + try { + Response> response = call.execute(); + if (response.isSuccessful()) { + return response.body().items(); + } else { + throw responseException(response); + } + } catch (IOException e) { + throw ioException(e); + + } + } + + public

P executeObjectCall(Call

call) throws D2CallException { + try { + Response

response = call.execute(); + if (response.isSuccessful()) { + return response.body(); + } else { + throw responseException(response); + } + } catch (IOException e) { + throw ioException(e); + } + } + + private D2CallException responseException(Response response) { + return exceptionBuilder + .httpErrorCode(response.code()) + .errorDescription("API call failed, response: " + response.toString()) + .build(); + } + + private D2CallException ioException(IOException e) { + Log.e(this.getClass().getSimpleName(), e.toString()); + return exceptionBuilder + .errorDescription("API call threw IOException") + .originalException(e) + .build(); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java b/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java index 728a38d02f..a447f53cd9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/BaseModel.java @@ -50,14 +50,6 @@ public String[] all() { public String[] whereUpdate() { return new String[] {}; } - - public String[] whereDelete() { - return whereUpdate(); - } - - public String[] whereSelect() { - return whereUpdate(); - } } @NonNull @@ -82,9 +74,4 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { // Intentional empty method. } - - @Override - public void bindToDeleteWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { - // Intentional empty method. - } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/common/D2CallExecutor.java similarity index 54% rename from core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java rename to core/src/main/java/org/hisp/dhis/android/core/common/D2CallExecutor.java index 54a8a28b63..cdb9c63a5a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/D2CallExecutor.java @@ -26,38 +26,28 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.hisp.dhis.android.core.dataset; +package org.hisp.dhis.android.core.common; + +import android.util.Log; import org.hisp.dhis.android.core.calls.Call; -import org.hisp.dhis.android.core.common.GenericCallData; -import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.common.SimpleCallFactory; -import org.hisp.dhis.android.core.common.SyncCall; -import org.hisp.dhis.android.core.resource.ResourceModel; -import retrofit2.Response; +@SuppressWarnings({"PMD.PreserveStackTrace"}) +public final class D2CallExecutor { -public final class DataSetAccessEndpointCall extends SyncCall>> { - private final GenericCallData data; - private final DataSetService dataSetService; + private final D2CallException.Builder exceptionBuilder = D2CallException + .builder() + .isHttpError(false); - private DataSetAccessEndpointCall(GenericCallData data, DataSetService dataSetService) { - this.data = data; - this.dataSetService = dataSetService; - } + public

P executeD2Call(Call

call) throws D2CallException { + try { + return call.call(); + } catch (D2CallException d2e) { + throw d2e; - @Override - public Response> call() throws Exception { - super.setExecuted(); - String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.DATA_SET); - return dataSetService.getDataSetsForAccess(DataSet.uidAndAccessRead, DataSet.lastUpdated.gt(lastUpdated), - Boolean.FALSE).execute(); - } - - static final SimpleCallFactory> FACTORY = new SimpleCallFactory>() { - @Override - public Call>> create(GenericCallData data) { - return new DataSetAccessEndpointCall(data, data.retrofit().create(DataSetService.class)); + } catch (Exception e) { + Log.e(this.getClass().getSimpleName(), e.toString()); + throw exceptionBuilder.errorDescription("Unexpected error calling " + call).build(); } - }; + } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java index dacf5f8d91..088aea3b44 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStore.java @@ -42,5 +42,7 @@ public interface IdentifiableObjectStore Set selectUids() throws RuntimeException; + Set selectUidsWhere(String whereClause) throws RuntimeException; + M selectByUid(String uid, CursorModelFactory modelFactory) throws RuntimeException; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java index a550e158c8..c7fdd6bc41 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/IdentifiableObjectStoreImpl.java @@ -33,7 +33,6 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import java.util.HashSet; import java.util.Set; import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @@ -84,24 +83,12 @@ public final void updateOrInsert(@NonNull M m) throws RuntimeException { @Override public Set selectUids() throws RuntimeException { Cursor cursor = databaseAdapter.query(statements.selectUids); - return mapObjectsWithUidFromCursor(cursor); + return mapStringColumnSetFromCursor(cursor); } - private Set mapObjectsWithUidFromCursor(Cursor cursor) { - Set uids = new HashSet<>(cursor.getCount()); - - try { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - do { - uids.add(cursor.getString(0)); - } - while (cursor.moveToNext()); - } - } finally { - cursor.close(); - } - return uids; + public Set selectUidsWhere(String whereClause) throws RuntimeException { + Cursor cursor = databaseAdapter.query(builder.selectUidsWhere(whereClause)); + return mapStringColumnSetFromCursor(cursor); } @Override diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/NameableObject.java b/core/src/main/java/org/hisp/dhis/android/core/common/NameableObject.java index 8e5a43ef55..be954e5e9d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/NameableObject.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/NameableObject.java @@ -28,7 +28,7 @@ package org.hisp.dhis.android.core.common; -public interface NameableObject { +public interface NameableObject extends IdentifiableObject { String shortName(); String displayShortName(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java index 4360590a49..d346e8006e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStore.java @@ -36,5 +36,9 @@ public interface ObjectStore extends DeletableStore { void insert(@NonNull M m) throws RuntimeException; - Set selectAll(CursorModelFactory modelFactory) throws RuntimeException; + Set selectAll(CursorModelFactory modelFactory); + + Set selectStringColumnsWhereClause(String column, String clause) throws RuntimeException; + + boolean deleteById(@NonNull M m); } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java index 9b720786f2..1e22ad2958 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectStoreImpl.java @@ -34,6 +34,7 @@ import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -75,26 +76,89 @@ protected void executeUpdateDelete(SQLiteStatement statement) throws RuntimeExce } } - @Override - public Set selectAll(@NonNull CursorModelFactory modelFactory) throws RuntimeException { + private void addAll(@NonNull CursorModelFactory modelFactory, + @NonNull Collection collection) { Cursor cursor = databaseAdapter.query(builder.selectAll()); - return mapObjectsFromCursor(cursor, modelFactory); + addObjectsToCollection(cursor, modelFactory, collection); + } + + @Override + public Set selectAll(@NonNull CursorModelFactory modelFactory) { + Set set = new HashSet<>(); + addAll(modelFactory, set); + return set; + } + + @Override + public boolean deleteById(@NonNull M m) { + return deleteWhereClause(BaseModel.Columns.ID + "='" + m.id() + "';"); + } + + private M selectOneWhere(@NonNull CursorModelFactory modelFactory, + @NonNull String whereClause) { + Cursor cursor = databaseAdapter.query(builder.selectWhereWithLimit(whereClause, 1)); + if (cursor.getCount() == 1) { + cursor.moveToFirst(); + return modelFactory.fromCursor(cursor); + } else { + return null; + } + } + + protected M popOneWhere(@NonNull CursorModelFactory modelFactory, + @NonNull String whereClause) { + M m = selectOneWhere(modelFactory, whereClause); + if (m != null) { + deleteById(m); + } + return m; + } + + protected int countWhere(@NonNull String whereClause) { + Cursor cursor = databaseAdapter.query(builder.countWhere(whereClause)); + cursor.moveToFirst(); + return cursor.getInt(0); + } + + private void addObjectsToCollection(Cursor cursor, CursorModelFactory modelFactory, + Collection collection) { + try { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + do { + collection.add(modelFactory.fromCursor(cursor)); + } + while (cursor.moveToNext()); + } + } finally { + cursor.close(); + } + } + + protected boolean deleteWhereClause(String clause) { + return databaseAdapter.database().delete(builder.tableName, clause, null) > 0; + } + + @Override + public Set selectStringColumnsWhereClause(String column, String clause) { + Cursor cursor = databaseAdapter.query(builder.selectColumnWhere(column, clause)); + return mapStringColumnSetFromCursor(cursor); } - Set mapObjectsFromCursor(Cursor cursor, CursorModelFactory modelFactory) { - Set objects = new HashSet<>(cursor.getCount()); + Set mapStringColumnSetFromCursor(Cursor cursor) { + Set columns = new HashSet<>(cursor.getCount()); try { if (cursor.getCount() > 0) { cursor.moveToFirst(); do { - objects.add(modelFactory.fromCursor(cursor)); + columns.add(cursor.getString(0)); } while (cursor.moveToNext()); } } finally { cursor.close(); } - return objects; + return columns; } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStore.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStore.java index f692c43592..b2fdfe8d79 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStore.java @@ -30,16 +30,9 @@ import android.support.annotation.NonNull; -import java.util.List; - public interface ObjectWithoutUidStore extends ObjectStore { void updateWhere(@NonNull M m) throws RuntimeException; void updateOrInsertWhere(@NonNull M m) throws RuntimeException; - - void deleteWhere(@NonNull M m) throws RuntimeException; - - List selectWhere(@NonNull CursorModelFactory modelFactory, @NonNull String... selectionArgs) - throws RuntimeException; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStoreImpl.java index 14e535f4a1..8c06aade9c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/ObjectWithoutUidStoreImpl.java @@ -28,28 +28,23 @@ package org.hisp.dhis.android.core.common; -import android.database.Cursor; import android.database.sqlite.SQLiteStatement; import android.support.annotation.NonNull; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import java.util.ArrayList; -import java.util.List; - import static org.hisp.dhis.android.core.utils.Utils.isNull; public class ObjectWithoutUidStoreImpl extends ObjectStoreImpl implements ObjectWithoutUidStore { - protected final SQLiteStatement updateWhereStatement; - protected final SQLiteStatement deleteWhereStatement; + private final SQLiteStatement updateWhereStatement; - ObjectWithoutUidStoreImpl(DatabaseAdapter databaseAdapter, SQLiteStatement insertStatement, - SQLiteStatement updateWhereStatement, SQLiteStatement deleteWhereStatement, + public ObjectWithoutUidStoreImpl(DatabaseAdapter databaseAdapter, + SQLiteStatement insertStatement, + SQLiteStatement updateWhereStatement, SQLStatementBuilder builder) { super(databaseAdapter, insertStatement, builder); this.updateWhereStatement = updateWhereStatement; - this.deleteWhereStatement = deleteWhereStatement; } @Override @@ -68,35 +63,4 @@ public void updateOrInsertWhere(@NonNull M m) throws RuntimeException { insert(m); } } - - @Override - public void deleteWhere(@NonNull M m) throws RuntimeException { - isNull(m); - m.bindToDeleteWhereStatement(deleteWhereStatement); - executeUpdateDelete(deleteWhereStatement); - } - - @Override - public List selectWhere(@NonNull CursorModelFactory modelFactory, @NonNull String... selectionArgs) - throws RuntimeException { - Cursor cursor = databaseAdapter.query(builder.selectWhere(), selectionArgs); - return listObjectsFromCursor(cursor, modelFactory); - } - - private List listObjectsFromCursor(Cursor cursor, CursorModelFactory modelFactory) { - List objects = new ArrayList<>(cursor.getCount()); - - try { - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - do { - objects.add(modelFactory.fromCursor(cursor)); - } - while (cursor.moveToNext()); - } - } finally { - cursor.close(); - } - return objects; - } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java index c2738be972..1b02690b35 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/SQLStatementBuilder.java @@ -36,19 +36,23 @@ public class SQLStatementBuilder { final String tableName; public final String[] columns; private final String[] updateWhereColumns; - private final String[] deleteWhereColumns; - private final String[] selectWhereColumns; private final static String TEXT = " TEXT"; private final static String WHERE = " WHERE "; + private final static String LIMIT = " LIMIT "; + private final static String FROM = " FROM "; + private final static String SELECT = "SELECT "; @SuppressWarnings("PMD.UseVarargs") - SQLStatementBuilder(String tableName, String[] columns, String[] updateWhereColumns, String[] deleteWhereColumns, - String[] selectWhereColumns) { + SQLStatementBuilder(String tableName, String[] columns, String[] updateWhereColumns) { this.tableName = tableName; this.columns = columns.clone(); this.updateWhereColumns = updateWhereColumns.clone(); - this.deleteWhereColumns = deleteWhereColumns.clone(); - this.selectWhereColumns = selectWhereColumns.clone(); + } + + public SQLStatementBuilder(String tableName, BaseModel.Columns columns) { + this.tableName = tableName; + this.columns = columns.all().clone(); + this.updateWhereColumns = columns.whereUpdate().clone(); } private String commaSeparatedColumns() { @@ -82,32 +86,39 @@ public String insert() { } String deleteById() { - return "DELETE FROM " + tableName + WHERE + BaseIdentifiableObjectModel.Columns.UID + "=?;"; + return "DELETE" + FROM + tableName + WHERE + BaseIdentifiableObjectModel.Columns.UID + "=?;"; } - String deleteWhere() { - String whereClause = deleteWhereColumns.length == 0 ? BaseModel.Columns.ID + " = -1" : - andSeparatedColumnEqualInterrogationMark(deleteWhereColumns); - return "DELETE FROM " + tableName + WHERE + whereClause + ";"; + String selectUids() { + return SELECT + BaseIdentifiableObjectModel.Columns.UID + FROM + tableName; } - String selectWhere() { - String whereClause = selectWhereColumns.length == 0 ? BaseModel.Columns.ID + " = -1" : - andSeparatedColumnEqualInterrogationMark(selectWhereColumns); - return "SELECT * FROM " + tableName + WHERE + whereClause; + String selectUidsWhere(String whereClause) { + return SELECT + BaseIdentifiableObjectModel.Columns.UID + FROM + tableName + WHERE + whereClause + ";"; } - String selectUids() { - return "SELECT " + BaseIdentifiableObjectModel.Columns.UID + " FROM " + tableName; + String selectColumnWhere(String column, String whereClause) { + return SELECT + column + FROM + tableName + WHERE + whereClause + ";"; } String selectByUid() { - return "SELECT * FROM " + tableName + WHERE + - andSeparatedColumnEqualInterrogationMark(BaseIdentifiableObjectModel.Columns.UID); + return selectWhere(andSeparatedColumnEqualInterrogationMark(BaseIdentifiableObjectModel.Columns.UID)); + } + + String selectWhere(String whereClause) { + return SELECT + "*" + FROM + tableName + WHERE + whereClause + ";"; + } + + String selectWhereWithLimit(String whereClause, int limit) { + return selectWhere(whereClause + LIMIT + limit); } String selectAll() { - return "SELECT " + commaSeparatedColumns() + " FROM " + tableName; + return SELECT + commaSeparatedColumns() + FROM + tableName; + } + + String countWhere(String whereClause) { + return SELECT + "COUNT(*)" + FROM + tableName + WHERE + whereClause + ";"; } public String update() { @@ -115,7 +126,7 @@ public String update() { WHERE + BaseIdentifiableObjectModel.Columns.UID + "=?;"; } - String updateWhere() { + public String updateWhere() { // TODO refactor to only generate for object without uids store. String whereClause = updateWhereColumns.length == 0 ? BaseModel.Columns.ID + " = -1" : andSeparatedColumnEqualInterrogationMark(updateWhereColumns); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java b/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java index fbab37853b..dbcbe09580 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/StoreFactory.java @@ -37,8 +37,7 @@ private StoreFactory() {} @SuppressWarnings("PMD.UseVarargs") public static IdentifiableObjectStore identifiableStore(DatabaseAdapter databaseAdapter, String tableName, String[] columns) { - SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns, new String[]{}, - new String[]{}, new String[]{}); + SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns, new String[]{}); SQLStatementWrapper statements = new SQLStatementWrapper(statementBuilder, databaseAdapter); return new IdentifiableObjectStoreImpl<>(databaseAdapter, statements, statementBuilder); } @@ -46,8 +45,7 @@ private StoreFactory() {} @SuppressWarnings("PMD.UseVarargs") static ObjectStore objectStore(DatabaseAdapter databaseAdapter, String tableName, String[] columns) { - SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns, new String[]{}, - new String[]{}, new String[]{}); + SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns, new String[]{}); return new ObjectStoreImpl<>(databaseAdapter, databaseAdapter.compileStatement( statementBuilder.insert()), statementBuilder); } @@ -55,12 +53,10 @@ private StoreFactory() {} @SuppressWarnings("PMD.UseVarargs") public static ObjectWithoutUidStore objectWithoutUidStore( DatabaseAdapter databaseAdapter, String tableName, BaseModel.Columns columns) { - SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns.all(), columns.whereUpdate(), - columns.whereDelete(), columns.whereSelect()); + SQLStatementBuilder statementBuilder = new SQLStatementBuilder(tableName, columns.all(), columns.whereUpdate()); return new ObjectWithoutUidStoreImpl<>(databaseAdapter, databaseAdapter.compileStatement(statementBuilder.insert()), databaseAdapter.compileStatement(statementBuilder.updateWhere()), - databaseAdapter.compileStatement(statementBuilder.deleteWhere()), statementBuilder); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/SyncCall.java b/core/src/main/java/org/hisp/dhis/android/core/common/SyncCall.java index 959b1df1e9..7f8f44fc77 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/SyncCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/SyncCall.java @@ -40,7 +40,7 @@ public final boolean isExecuted() { } } - protected final void setExecuted() throws IllegalStateException { + protected final void setExecuted() { synchronized (this) { if (isExecuted) { throw new IllegalStateException("Already executed"); diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/UidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/common/UidsHelper.java new file mode 100644 index 0000000000..a6e5029c0a --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/common/UidsHelper.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.common; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +public final class UidsHelper { + + private UidsHelper() {} + + public static Set getUids(Collection objects) { + return addUids(new HashSet(), objects); + } + + public static Set addUids(Set uids, Collection objects) { + for (IdentifiableObject object: objects) { + uids.add(object.uid()); + } + return uids; + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/common/WhereStatementBinder.java b/core/src/main/java/org/hisp/dhis/android/core/common/WhereStatementBinder.java index 1d383b61ef..eb2488f419 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/common/WhereStatementBinder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/common/WhereStatementBinder.java @@ -33,6 +33,4 @@ public interface WhereStatementBinder extends StatementBinder { void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement); - - void bindToDeleteWhereStatement(@NonNull SQLiteStatement sqLiteStatement); } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModel.java b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModel.java index d3a0fc3044..32cb22bbb9 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantModel.java @@ -29,12 +29,18 @@ package org.hisp.dhis.android.core.constant; import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.gabrielittner.auto.value.cursor.ColumnName; import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseIdentifiableObjectModel; +import org.hisp.dhis.android.core.common.CursorModelFactory; +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue public abstract class ConstantModel extends BaseIdentifiableObjectModel { @@ -43,6 +49,11 @@ public abstract class ConstantModel extends BaseIdentifiableObjectModel { public static class Columns extends BaseIdentifiableObjectModel.Columns { public static final String VALUE = "value"; + + @Override + public String[] all() { + return Utils.appendInNewArray(super.all(), VALUE); + } } public static ConstantModel create(Cursor cursor) { @@ -53,11 +64,24 @@ public static Builder builder() { return new $$AutoValue_ConstantModel.Builder(); } + public static final CursorModelFactory factory + = new CursorModelFactory() { + @Override + public ConstantModel fromCursor(Cursor cursor) { + return create(cursor); + } + }; @Nullable @ColumnName(Columns.VALUE) public abstract String value(); + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + super.bindToStatement(sqLiteStatement); + sqLiteBind(sqLiteStatement, 7, value()); + } + @AutoValue.Builder public static abstract class Builder extends BaseIdentifiableObjectModel.Builder { diff --git a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantStore.java b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantStore.java index e8242e823a..4fb6198d2a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantStore.java @@ -28,19 +28,15 @@ package org.hisp.dhis.android.core.constant; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.common.DeletableStore; +public final class ConstantStore { -import java.util.Date; - -public interface ConstantStore extends DeletableStore { - - long insert( - @NonNull String uid, @Nullable String code, @Nullable String name, - @Nullable String displayName, @Nullable Date created, - @Nullable Date lastUpdated, @NonNull String value - ); + private ConstantStore() {} + public static IdentifiableObjectStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.identifiableStore(databaseAdapter, ConstantModel.TABLE, new ConstantModel.Columns().all()); + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantStoreImpl.java deleted file mode 100644 index ebb2095135..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/constant/ConstantStoreImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2017, University of Oslo - * - * All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.constant; - -import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; -import static org.hisp.dhis.android.core.utils.Utils.isNull; - -import android.database.sqlite.SQLiteStatement; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import org.hisp.dhis.android.core.data.database.DatabaseAdapter; - -import java.util.Date; - -public class ConstantStoreImpl implements ConstantStore { - private static final String INSERT_STATEMENT = "INSERT INTO " + ConstantModel.TABLE + " (" + - ConstantModel.Columns.UID + "," + - ConstantModel.Columns.CODE + "," + - ConstantModel.Columns.NAME + "," + - ConstantModel.Columns.DISPLAY_NAME + "," + - ConstantModel.Columns.CREATED + "," + - ConstantModel.Columns.LAST_UPDATED + "," + - ConstantModel.Columns.VALUE + - ") VALUES (?, ?, ?, ?, ?, ?, ?);"; - - private final SQLiteStatement insertStatement; - private final DatabaseAdapter databaseAdapter; - - public ConstantStoreImpl(DatabaseAdapter databaseAdapter) { - this.databaseAdapter = databaseAdapter; - this.insertStatement = databaseAdapter.compileStatement(INSERT_STATEMENT); - } - - @Override - public long insert(@NonNull String uid, @Nullable String code, @Nullable String name, - @Nullable String displayName, @Nullable Date created, - @Nullable Date lastUpdated, @NonNull String value) { - isNull(uid); - sqLiteBind(insertStatement, 1, uid); - sqLiteBind(insertStatement, 2, code); - sqLiteBind(insertStatement, 3, name); - sqLiteBind(insertStatement, 4, displayName); - sqLiteBind(insertStatement, 5, created); - sqLiteBind(insertStatement, 6, lastUpdated); - sqLiteBind(insertStatement, 7, value); - - long ret = databaseAdapter.executeInsert(ConstantModel.TABLE, insertStatement); - insertStatement.clearBindings(); - return ret; - } - - @Override - public int delete() { - return databaseAdapter.delete(ConstantModel.TABLE); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java index 5bf5427245..9b818f7a90 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/api/Field.java @@ -39,8 +39,12 @@ @AutoValue public abstract class Field implements Property { + public Filter eq(V value) { + return SingleValueFilter.eq(this, value.toString()); + } + public Filter gt(String value) { - return GtFilter.create(this, value); + return SingleValueFilter.gt(this, value); } public Filter in(Collection values) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/api/GtFilter.java b/core/src/main/java/org/hisp/dhis/android/core/data/api/SingleValueFilter.java similarity index 58% rename from core/src/main/java/org/hisp/dhis/android/core/data/api/GtFilter.java rename to core/src/main/java/org/hisp/dhis/android/core/data/api/SingleValueFilter.java index 80cfb72f41..388ebdfa0b 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/api/GtFilter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/api/SingleValueFilter.java @@ -9,16 +9,27 @@ import java.util.Iterator; @AutoValue -public abstract class GtFilter implements Filter { - public static Filter create(@NonNull Field field, @Nullable String value) { +public abstract class SingleValueFilter implements Filter { + + private static Filter create(@NonNull Field field, + @NonNull String operator, + @Nullable String value) { //If the filter is incomplete, returning null, tells Retrofit that this filter should not be included. if (value == null || value.equals("")) { return null; } - return new AutoValue_GtFilter<>(field, "gt", + return new AutoValue_SingleValueFilter<>(field, operator, Collections.unmodifiableCollection(Collections.singletonList(value))); } + public static Filter gt(@NonNull Field field, @Nullable String value) { + return create(field, "gt", value); + } + + public static Filter eq(@NonNull Field field, @Nullable String value) { + return create(field, "eq", value); + } + @Override public String generateString() { StringBuilder builder = new StringBuilder(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/CustomSQLBriteOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/CustomSQLBriteOpenHelper.java deleted file mode 100644 index 9f5cc0265d..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/CustomSQLBriteOpenHelper.java +++ /dev/null @@ -1,418 +0,0 @@ -package org.hisp.dhis.android.core.data.database; - -import android.content.Context; -import android.database.DatabaseErrorHandler; -import android.database.sqlite.SQLiteDatabase; -import android.util.Log; - -import com.github.lykmapipo.sqlbrite.migrations.SQLBriteOpenHelper; -import com.squareup.sqlbrite2.BriteDatabase; -import com.squareup.sqlbrite2.SqlBrite; - -import org.yaml.snakeyaml.Yaml; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import io.reactivex.schedulers.Schedulers; - -/* - * A helper class to manage database migrations and seeding using - * an application's raw asset files. - *

- * This class provides developers with a simple way to ship their Android app - * with migrations files which manage database creation and any upgrades required with subsequent - * version releases. - *

- *

For examples see - * https://github.com/lykmapipo/sqlbrite-migrations - *

- *

Note: this class assumes - * monotonically increasing version numbers for upgrades.

- */ -public class CustomSQLBriteOpenHelper extends SQLBriteOpenHelper { - - private String migrationTestDir = "migrations"; - final private Context context; - private final int version; - //current database version to support seed up to requested database version - private boolean isOnTestMode; - private static BriteDatabase briteDatabase; - - - /* - * Create a helper object to create, open, and/or manage a database. - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - */ - public CustomSQLBriteOpenHelper(Context context, String name, - SQLiteDatabase.CursorFactory factory, int version, String migrationTestDir) { - super(context, name, factory, version); - this.version = version; - this.context = context; - this.migrationTestDir = migrationTestDir; - } - - - /* - * Create a helper object to create, open, and/or manage a database. - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - */ - public CustomSQLBriteOpenHelper(Context context, String name, - SQLiteDatabase.CursorFactory factory, - int version, String migrationTestDir, DatabaseErrorHandler errorHandler) { - super(context, name, factory, version, errorHandler); - this.version = version; - this.context = context; - this.migrationTestDir = migrationTestDir; - } - - - /* - * Create a helper object to create, open, and/or manage a testing database. - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - */ - public CustomSQLBriteOpenHelper(Context context, String name, int version) { - super(context, name, null, version); - this.context = context; - this.version = version; - this.isOnTestMode = false; - } - - /* - * Create a helper object to create, open, and/or manage a testing database. - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - */ - public CustomSQLBriteOpenHelper(Context context, String name, int version, boolean testing, - String migrationTestDir) { - super(context, name, null, version); - this.context = context; - this.version = version; - this.isOnTestMode = testing; - this.migrationTestDir = migrationTestDir; - } - - @Override - public void onCreate(SQLiteDatabase db) { - try { - int version = db.getVersion(); - if(version == this.version || version == 0){ - return; - } - //run all migrations from begin to current requested database version - version = version > this.version ? version - : this.version; //ensure we start at requested database version - List>> parsed = parse(0, version, true); - up(db, parsed); - } catch (IOException e) { - Log.e("Database Error:", e.getMessage()); - } - } - - /* - * Upgrade database to latest new version - */ - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - try { - //load all migrations from old version to current version - List>> parsed = parse(oldVersion, newVersion, true); - - //upgrade database - up(db, parsed); - } catch (IOException e) { - Log.e("Database Error:", e.getMessage()); - } - } - - /* - * Create a {@link BriteDatabase} instance.N - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - * @see BriteDatabase - */ - - @SuppressWarnings("PMD") - public synchronized static BriteDatabase get(Context context, String name, int version) { - if (briteDatabase == null) { - SQLBriteOpenHelper sqlBriteOpenHelper = new SQLBriteOpenHelper(context, name, null, version); - SqlBrite sqlBrite = new SqlBrite.Builder().build(); - briteDatabase = sqlBrite.wrapDatabaseHelper(sqlBriteOpenHelper, Schedulers.io()); - } - return briteDatabase; - } - - - /* - * Create a {@link BriteDatabase} instance. - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - * @see BriteDatabase - */ - - @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") - public synchronized static BriteDatabase get(Context context, String name, - SQLiteDatabase.CursorFactory factory, int version, String migrationDir) { - if (briteDatabase == null) { - CustomSQLBriteOpenHelper sqlBriteOpenHelper = new CustomSQLBriteOpenHelper(context, name, factory, - version, migrationDir); - SqlBrite sqlBrite = new SqlBrite.Builder().build(); - briteDatabase = sqlBrite.wrapDatabaseHelper(sqlBriteOpenHelper, Schedulers.io()); - } - return briteDatabase; - } - - - /* - * Create a {@link BriteDatabase} instance. - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - * @see BriteDatabase - */ - - @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") - public synchronized static BriteDatabase get(Context context, String name, - SQLiteDatabase.CursorFactory factory, int version, String migrationDir, - DatabaseErrorHandler errorHandler) { - if (briteDatabase == null) { - CustomSQLBriteOpenHelper sqlBriteOpenHelper = new CustomSQLBriteOpenHelper(context, name, factory, - version, migrationDir, errorHandler); - SqlBrite sqlBrite = new SqlBrite.Builder().build(); - briteDatabase = sqlBrite.wrapDatabaseHelper(sqlBriteOpenHelper, Schedulers.io()); - } - return briteDatabase; - } - - /* - * Create a {@link BriteDatabase} instance for testing. - * This method always returns very quickly. The database is not actually - * created or opened until one of {@link #getWritableDatabase} or - * {@link #getReadableDatabase} is called. - * - * @see SQLBriteOpenHelper - * @see BriteDatabase - */ - - @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel") - public synchronized static BriteDatabase get(Context context, String name, int version, boolean testing, - String migrationTestDir) { - //always return new instance on test mode - CustomSQLBriteOpenHelper sqlBriteOpenHelper = new CustomSQLBriteOpenHelper(context, name, version, - testing, migrationTestDir); - SqlBrite sqlBrite = new SqlBrite.Builder().build(); - briteDatabase = sqlBrite.wrapDatabaseHelper(sqlBriteOpenHelper, Schedulers.trampoline()); - return briteDatabase; - } - - /* - * Downgrade database to previous old version - */ - @Override - public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { - try { - //load all migrations from old version to current version - List>> parsed = parse(oldVersion, newVersion, false); - - //upgrade database - down(db, parsed); - } catch (IOException e) { - Log.e("Database Error:", e.getMessage()); - } - } - - - /* - * Load and parse all required database migrations. - */ - public List>> parse(int oldVersion, int newVersion, boolean up) - throws IOException { - synchronized (this) { - //collect all require migrations - List>> scripts = new ArrayList>>(); - - //iterate over all required migrations - if (up) { - //parse up migrations - int startVersion = oldVersion + 1; - for (int i = startVersion; i <= newVersion; i++) { - Map> script = this.parse(i); - scripts.add(script); - } - } else { - //parse down migrations - for (int i = oldVersion; i > newVersion; i--) { - Map> script = this.parse(i); - scripts.add(script); - } - } - - return scripts; - } - } - - - /* - * Load and parse initial database migrations. - *

- * It used it creating initial database - *

- */ - public Map> parse() throws IOException { - synchronized (this) { - return this.parse(1); - } - } - - - /* - * Parse migration file - *

- * It used to upgrade database to newer version - *

- * - * @param newVersion newer database version - */ - public Map> parse(int newVersion) throws IOException { - synchronized (this) { - //obtain migration path - InputStream inputStream = null; - String migrationPath = migrationTestDir + "/" + newVersion + ".yaml"; - //handle test mode - if (isOnTestMode) { - inputStream = this.getClass().getClassLoader().getResourceAsStream(migrationPath); - } else { - inputStream = this.context.getAssets().open(migrationPath); - } - //parse migration content - Yaml yaml = new Yaml(); - Map> parsed = (Map) yaml.load(inputStream); - - return parsed; - } - } - - - /* - * Apply up migration scripts and seed database with provided seeds - */ - private void up(SQLiteDatabase database, Map> scripts) { - synchronized (this) { - database.beginTransaction(); - try { - //obtain up migrations - List ups = scripts.get("up"); - - //apply up migrations - if (ups != null) { - for (String script : ups) { - database.execSQL(script); - } - } - - //obtain seeds - List seeds = scripts.get("seeds"); - - //apply seed migrations - if (seeds != null) { - for (String script : seeds) { - database.execSQL(script); - } - } - - database.setTransactionSuccessful(); - } finally { - database.endTransaction(); - } - } - } - - /* - * Apply up migration scripts and seed database with provided seeds - */ - private void up(SQLiteDatabase database, List>> scripts) { - synchronized (this) { - //ensure we apply or fail as whole - database.beginTransaction(); - try { - //start apply all migrations - for (Map> script : scripts) { - up(database, script); - } - database.setTransactionSuccessful(); - } finally { - database.endTransaction(); - } - } - } - - - /* - * Apply down migration scripts - */ - private void down(SQLiteDatabase database, Map> scripts) { - synchronized (this) { - database.beginTransaction(); - try { - //obtain down migrations - List downs = scripts.get("down"); - - //apply down migrations - if (downs != null) { - for (String script : downs) { - database.execSQL(script); - } - } - - database.setTransactionSuccessful(); - } finally { - database.endTransaction(); - } - } - } - - /* - * Apply down migration scripts - */ - private void down(SQLiteDatabase database, List>> scripts) { - synchronized (this) { - //ensure we apply or fail as whole - database.beginTransaction(); - try { - //start apply all migrations - for (Map> script : scripts) { - down(database, script); - } - database.setTransactionSuccessful(); - } finally { - database.endTransaction(); - } - } - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DatabaseAdapter.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DatabaseAdapter.java index f12e7687b3..b0951d8e35 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DatabaseAdapter.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DatabaseAdapter.java @@ -29,6 +29,7 @@ package org.hisp.dhis.android.core.data.database; import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; @SuppressWarnings("PMD.UseVarargs") @@ -115,4 +116,5 @@ public interface DatabaseAdapter { */ Transaction beginNewTransaction(); + SQLiteDatabase database(); } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java index d159f5c2a7..5d843ad22f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/data/database/DbOpenHelper.java @@ -32,1177 +32,24 @@ import android.database.sqlite.SQLiteDatabase; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; -import android.util.Log; -import org.hisp.dhis.android.core.category.CategoryCategoryComboLinkModel; -import org.hisp.dhis.android.core.category.CategoryCategoryOptionLinkModel; -import org.hisp.dhis.android.core.category.CategoryComboModel; -import org.hisp.dhis.android.core.category.CategoryModel; -import org.hisp.dhis.android.core.category.CategoryOptionComboCategoryLinkModel; -import org.hisp.dhis.android.core.category.CategoryOptionComboModel; -import org.hisp.dhis.android.core.category.CategoryOptionModel; -import org.hisp.dhis.android.core.common.ObjectStyleModel; -import org.hisp.dhis.android.core.common.SQLStatementBuilder; -import org.hisp.dhis.android.core.common.ValueTypeDeviceRenderingModel; -import org.hisp.dhis.android.core.configuration.ConfigurationModel; -import org.hisp.dhis.android.core.constant.ConstantModel; -import org.hisp.dhis.android.core.dataelement.DataElementModel; -import org.hisp.dhis.android.core.dataset.DataSetDataElementLinkModel; -import org.hisp.dhis.android.core.dataset.DataSetModel; -import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; -import org.hisp.dhis.android.core.datavalue.DataValueModel; -import org.hisp.dhis.android.core.enrollment.EnrollmentModel; -import org.hisp.dhis.android.core.enrollment.note.NoteModel; -import org.hisp.dhis.android.core.event.EventModel; -import org.hisp.dhis.android.core.indicator.DataSetIndicatorLinkModel; -import org.hisp.dhis.android.core.indicator.IndicatorModel; -import org.hisp.dhis.android.core.indicator.IndicatorTypeModel; -import org.hisp.dhis.android.core.legendset.LegendModel; -import org.hisp.dhis.android.core.legendset.LegendSetModel; -import org.hisp.dhis.android.core.legendset.ProgramIndicatorLegendSetLinkModel; -import org.hisp.dhis.android.core.option.OptionModel; -import org.hisp.dhis.android.core.option.OptionSetModel; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; -import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkModel; -import org.hisp.dhis.android.core.period.PeriodModel; -import org.hisp.dhis.android.core.program.ProgramIndicatorModel; -import org.hisp.dhis.android.core.program.ProgramModel; -import org.hisp.dhis.android.core.program.ProgramRuleActionModel; -import org.hisp.dhis.android.core.program.ProgramRuleModel; -import org.hisp.dhis.android.core.program.ProgramRuleVariableModel; -import org.hisp.dhis.android.core.program.ProgramStageDataElementModel; -import org.hisp.dhis.android.core.program.ProgramStageModel; -import org.hisp.dhis.android.core.program.ProgramStageSectionModel; -import org.hisp.dhis.android.core.program.ProgramStageSectionProgramIndicatorLinkModel; -import org.hisp.dhis.android.core.program.ProgramTrackedEntityAttributeModel; -import org.hisp.dhis.android.core.relationship.RelationshipModel; -import org.hisp.dhis.android.core.relationship.RelationshipTypeModel; -import org.hisp.dhis.android.core.resource.ResourceModel; -import org.hisp.dhis.android.core.settings.SystemSettingModel; -import org.hisp.dhis.android.core.systeminfo.SystemInfoModel; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeModel; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValueModel; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueModel; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueModel; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstanceModel; -import org.hisp.dhis.android.core.trackedentity.TrackedEntityTypeModel; -import org.hisp.dhis.android.core.user.AuthenticatedUserModel; -import org.hisp.dhis.android.core.user.UserCredentialsModel; -import org.hisp.dhis.android.core.user.UserModel; -import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; -import org.hisp.dhis.android.core.user.UserRoleModel; +import com.github.lykmapipo.sqlbrite.migrations.SQLBriteOpenHelper; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; -import static org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT_SCOPE; +public class DbOpenHelper extends SQLBriteOpenHelper { -@SuppressWarnings({ - "PMD.AvoidDuplicateLiterals", "PMD.ExcessiveImports", "PMD.ExcessiveClassLength" -}) -public class DbOpenHelper extends CustomSQLBriteOpenHelper { - - public static final int VERSION = 24; - public String mockedSqlDatabase = ""; - private static final String CREATE_CONFIGURATION_TABLE = - "CREATE TABLE " + ConfigurationModel.CONFIGURATION + " (" + - ConfigurationModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ConfigurationModel.Columns.SERVER_URL + " TEXT NOT NULL UNIQUE" + - ");"; - - private static final String CREATE_CATEGORY_TABLE = - "CREATE TABLE " + CategoryModel.TABLE + " (" + - CategoryModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - CategoryModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - CategoryModel.Columns.CODE + " TEXT," + - CategoryModel.Columns.NAME + " TEXT," + - CategoryModel.Columns.DISPLAY_NAME + " TEXT," + - CategoryModel.Columns.CREATED + " TEXT," + - CategoryModel.Columns.LAST_UPDATED + " TEXT," + - CategoryModel.Columns.DATA_DIMENSION_TYPE + " TEXT" + ");"; - - private static final String CREATE_CATEGORY_OPTION_TABLE = - SQLStatementBuilder.createNameableModelTable(CategoryOptionModel.TABLE, - CategoryOptionModel.Columns.START_DATE + " TEXT," + - CategoryOptionModel.Columns.END_DATE + " TEXT" - ); - - private static final String CREATE_CATEGORY_CATEGORY_OPTION_LINK_TABLE = "CREATE TABLE " + - CategoryCategoryOptionLinkModel.TABLE + " (" + - CategoryCategoryOptionLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - CategoryCategoryOptionLinkModel.Columns.CATEGORY + " TEXT NOT NULL," + - CategoryCategoryOptionLinkModel.Columns.CATEGORY_OPTION + " TEXT NOT NULL, " + - " FOREIGN KEY (" + CategoryCategoryOptionLinkModel.Columns.CATEGORY + ") " + - " REFERENCES " + CategoryModel.TABLE + " (" + CategoryModel.Columns.UID + ") " + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + CategoryCategoryOptionLinkModel.Columns.CATEGORY_OPTION + ") " + - " REFERENCES " + CategoryOptionModel.TABLE + " (" + CategoryOptionModel.Columns.UID - + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - "UNIQUE (" + CategoryCategoryOptionLinkModel.Columns.CATEGORY + ", " + - CategoryCategoryOptionLinkModel.Columns.CATEGORY_OPTION + ")" + - ");"; - - private static final String CREATE_CATEGORY_COMBO_TABLE = - "CREATE TABLE " + CategoryComboModel.TABLE + " (" + - CategoryComboModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - CategoryComboModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - CategoryComboModel.Columns.CODE + " TEXT," + - CategoryComboModel.Columns.NAME + " TEXT," + - CategoryComboModel.Columns.DISPLAY_NAME + " TEXT," + - CategoryComboModel.Columns.CREATED + " TEXT," + - CategoryComboModel.Columns.LAST_UPDATED + " TEXT, " + - CategoryComboModel.Columns.IS_DEFAULT + " INTEGER" + ");"; - - private static final String CREATE_CATEGORY_CATEGORY_COMBO_LINK_TABLE = "CREATE TABLE " + - CategoryCategoryComboLinkModel.TABLE + " (" + - CategoryCategoryComboLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - CategoryCategoryComboLinkModel.Columns.CATEGORY + " TEXT NOT NULL," + - CategoryCategoryComboLinkModel.Columns.CATEGORY_COMBO + " TEXT NOT NULL, " + - " FOREIGN KEY (" + CategoryCategoryComboLinkModel.Columns.CATEGORY + ") " + - " REFERENCES " + CategoryModel.TABLE + " (" + CategoryModel.Columns.UID + ") " + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + CategoryCategoryComboLinkModel.Columns.CATEGORY_COMBO + ") " + - " REFERENCES " + CategoryComboModel.TABLE + " (" + CategoryComboModel.Columns.UID + ")" - + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - "UNIQUE (" + CategoryCategoryComboLinkModel.Columns.CATEGORY + ", " + - CategoryCategoryComboLinkModel.Columns.CATEGORY_COMBO + ")" + - ");"; - - private static final String CREATE_CATEGORY_OPTION_COMBO_TABLE = - "CREATE TABLE " + CategoryOptionComboModel.TABLE + " (" + - CategoryOptionComboModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - CategoryOptionComboModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - CategoryOptionComboModel.Columns.CODE + " TEXT," + - CategoryOptionComboModel.Columns.NAME + " TEXT," + - CategoryOptionComboModel.Columns.DISPLAY_NAME + " TEXT," + - CategoryOptionComboModel.Columns.CREATED + " TEXT," + - CategoryOptionComboModel.Columns.LAST_UPDATED + " TEXT, " + - CategoryOptionComboModel.Columns.CATEGORY_COMBO + " TEXT, " + - " FOREIGN KEY (" + CategoryOptionComboModel.Columns.CATEGORY_COMBO + ") " + - " REFERENCES " + CategoryComboModel.TABLE + " (" - + CategoryComboModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED );"; - - private static final String CREATE_CATEGORY_OPTION_COMBO_CATEGORY_LINK_TABLE = "CREATE TABLE " + - CategoryOptionComboCategoryLinkModel.TABLE + " (" + - CategoryOptionComboCategoryLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," - + - CategoryOptionComboCategoryLinkModel.Columns.CATEGORY_OPTION_COMBO + " TEXT NOT NULL," + - CategoryOptionComboCategoryLinkModel.Columns.CATEGORY + " TEXT NOT NULL, " + - " FOREIGN KEY (" + CategoryOptionComboCategoryLinkModel.Columns.CATEGORY_OPTION_COMBO + ") " + - " REFERENCES " + CategoryOptionComboModel.TABLE + " (" - + CategoryOptionComboModel.Columns.UID + ") " + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - "UNIQUE (" + CategoryOptionComboCategoryLinkModel.Columns.CATEGORY_OPTION_COMBO + ", " + - CategoryOptionComboCategoryLinkModel.Columns.CATEGORY + ")" + - ");"; - - private static final String CREATE_USER_TABLE = "CREATE TABLE " + UserModel.TABLE + " (" + - UserModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - UserModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - UserModel.Columns.CODE + " TEXT," + - UserModel.Columns.NAME + " TEXT," + - UserModel.Columns.DISPLAY_NAME + " TEXT," + - UserModel.Columns.CREATED + " TEXT," + - UserModel.Columns.LAST_UPDATED + " TEXT," + - UserModel.Columns.BIRTHDAY + " TEXT," + - UserModel.Columns.EDUCATION + " TEXT," + - UserModel.Columns.GENDER + " TEXT," + - UserModel.Columns.JOB_TITLE + " TEXT," + - UserModel.Columns.SURNAME + " TEXT," + - UserModel.Columns.FIRST_NAME + " TEXT," + - UserModel.Columns.INTRODUCTION + " TEXT," + - UserModel.Columns.EMPLOYER + " TEXT," + - UserModel.Columns.INTERESTS + " TEXT," + - UserModel.Columns.LANGUAGES + " TEXT," + - UserModel.Columns.EMAIL + " TEXT," + - UserModel.Columns.PHONE_NUMBER + " TEXT," + - UserModel.Columns.NATIONALITY + " TEXT" + - ");"; - - private static final String CREATE_USER_CREDENTIALS_TABLE = "CREATE TABLE " + - UserCredentialsModel.TABLE + " (" + - UserCredentialsModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - UserCredentialsModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - UserCredentialsModel.Columns.CODE + " TEXT," + - UserCredentialsModel.Columns.NAME + " TEXT," + - UserCredentialsModel.Columns.DISPLAY_NAME + " TEXT," + - UserCredentialsModel.Columns.CREATED + " TEXT," + - UserCredentialsModel.Columns.LAST_UPDATED + " TEXT," + - UserCredentialsModel.Columns.USERNAME + " TEXT," + - UserCredentialsModel.Columns.USER + " TEXT NOT NULL UNIQUE," + - " FOREIGN KEY (" + UserCredentialsModel.Columns.USER + ") " + - "REFERENCES " + UserModel.TABLE + " (" + UserModel.Columns.UID + ") " + - "ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED " + - ");"; - - private static final String CREATE_ORGANISATION_UNIT_TABLE = - SQLStatementBuilder.createNameableModelTable(OrganisationUnitModel.TABLE, - OrganisationUnitModel.Columns.PATH + " TEXT," + - OrganisationUnitModel.Columns.OPENING_DATE + " TEXT," + - OrganisationUnitModel.Columns.CLOSED_DATE + " TEXT," + - OrganisationUnitModel.Columns.LEVEL + " INTEGER," + - OrganisationUnitModel.Columns.PARENT + " TEXT," + - OrganisationUnitModel.Columns.DISPLAY_NAME_PATH + " TEXT" - ); - - private static final String CREATE_USER_ORGANISATION_UNIT_TABLE = "CREATE TABLE " + - UserOrganisationUnitLinkModel.TABLE + " (" + - UserOrganisationUnitLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - UserOrganisationUnitLinkModel.Columns.USER + " TEXT NOT NULL," + - UserOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - ORGANISATION_UNIT_SCOPE + " TEXT NOT NULL," + - " FOREIGN KEY (" + UserOrganisationUnitLinkModel.Columns.USER + ") " + - " REFERENCES " + UserModel.TABLE + " (" + UserModel.Columns.UID + ") " + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + UserOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ") " + - " REFERENCES " + OrganisationUnitModel.TABLE + " (" + OrganisationUnitModel.Columns.UID - + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - "UNIQUE (" + UserOrganisationUnitLinkModel.Columns.USER + ", " + - UserOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ", " + - ORGANISATION_UNIT_SCOPE + ")" + - ");"; - - private static final String CREATE_AUTHENTICATED_USER_TABLE = "CREATE TABLE " + - AuthenticatedUserModel.TABLE + " (" + - AuthenticatedUserModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - AuthenticatedUserModel.Columns.USER + " TEXT NOT NULL UNIQUE," + - AuthenticatedUserModel.Columns.CREDENTIALS + " TEXT NOT NULL," + - " FOREIGN KEY (" + AuthenticatedUserModel.Columns.USER + ") " + - " REFERENCES " + UserModel.TABLE + " (" + UserModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_OPTION_SET_TABLE = - "CREATE TABLE " + OptionSetModel.TABLE + " (" + - OptionSetModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - OptionSetModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - OptionSetModel.Columns.CODE + " TEXT," + - OptionSetModel.Columns.NAME + " TEXT," + - OptionSetModel.Columns.DISPLAY_NAME + " TEXT," + - OptionSetModel.Columns.CREATED + " TEXT," + - OptionSetModel.Columns.LAST_UPDATED + " TEXT," + - OptionSetModel.Columns.VERSION + " INTEGER," + - OptionSetModel.Columns.VALUE_TYPE + " TEXT" + - ");"; - - private static final String CREATE_OPTION_TABLE = "CREATE TABLE " + OptionModel.TABLE + " (" + - OptionModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - OptionModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - OptionModel.Columns.CODE + " TEXT," + - OptionModel.Columns.NAME + " TEXT," + - OptionModel.Columns.DISPLAY_NAME + " TEXT," + - OptionModel.Columns.CREATED + " TEXT," + - OptionModel.Columns.LAST_UPDATED + " TEXT," + - OptionModel.Columns.OPTION_SET + " TEXT NOT NULL," + - " FOREIGN KEY (" + OptionModel.Columns.OPTION_SET + ") " + - " REFERENCES " + OptionSetModel.TABLE + - " (" + OptionSetModel.Columns.UID + ") ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED " - + - ");"; - - private static final String CREATE_PROGRAM_TABLE = - SQLStatementBuilder.createNameableModelTable(ProgramModel.TABLE, - ProgramModel.Columns.VERSION + " INTEGER," + - ProgramModel.Columns.ONLY_ENROLL_ONCE + " INTEGER," + - ProgramModel.Columns.ENROLLMENT_DATE_LABEL + " TEXT," + - ProgramModel.Columns.DISPLAY_INCIDENT_DATE + " INTEGER," + - ProgramModel.Columns.INCIDENT_DATE_LABEL + " TEXT," + - ProgramModel.Columns.REGISTRATION + " INTEGER," + - ProgramModel.Columns.SELECT_ENROLLMENT_DATES_IN_FUTURE + " INTEGER," + - ProgramModel.Columns.DATA_ENTRY_METHOD + " INTEGER," + - ProgramModel.Columns.IGNORE_OVERDUE_EVENTS + " INTEGER," + - ProgramModel.Columns.RELATIONSHIP_FROM_A + " INTEGER," + - ProgramModel.Columns.SELECT_INCIDENT_DATES_IN_FUTURE + " INTEGER," + - ProgramModel.Columns.CAPTURE_COORDINATES + " INTEGER," + - ProgramModel.Columns.USE_FIRST_STAGE_DURING_REGISTRATION + " INTEGER," + - ProgramModel.Columns.DISPLAY_FRONT_PAGE_LIST + " INTEGER," + - ProgramModel.Columns.PROGRAM_TYPE + " TEXT," + - ProgramModel.Columns.RELATIONSHIP_TYPE + " TEXT," + - ProgramModel.Columns.RELATIONSHIP_TEXT + " TEXT," + - ProgramModel.Columns.RELATED_PROGRAM + " TEXT," + - ProgramModel.Columns.TRACKED_ENTITY_TYPE + " TEXT," + - ProgramModel.Columns.CATEGORY_COMBO + " TEXT," + - ProgramModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + - ProgramModel.Columns.EXPIRY_DAYS + " INTEGER," + - ProgramModel.Columns.COMPLETE_EVENTS_EXPIRY_DAYS + " INTEGER," + - ProgramModel.Columns.EXPIRY_PERIOD_TYPE + " TEXT," + - ProgramModel.Columns.MIN_ATTRIBUTES_REQUIRED_TO_SEARCH + " INTEGER," + - ProgramModel.Columns.MAX_TEI_COUNT_TO_RETURN + " INTEGER," + - " FOREIGN KEY (" + ProgramModel.Columns.RELATIONSHIP_TYPE + ")" + - " REFERENCES " + RelationshipTypeModel.TABLE + " (" + RelationshipTypeModel.Columns.UID - + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, " + - " FOREIGN KEY (" + ProgramModel.Columns.TRACKED_ENTITY_TYPE + ")" + - " REFERENCES " + TrackedEntityTypeModel.TABLE + " (" + TrackedEntityTypeModel.Columns.UID - + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - " FOREIGN KEY (" + ProgramModel.Columns.CATEGORY_COMBO + ")" + - " REFERENCES " + CategoryComboModel.TABLE + " (" + CategoryComboModel.Columns.UID + ")" - + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" - ); - - private static final String CREATE_TRACKED_ENTITY_TABLE = - "CREATE TABLE " + TrackedEntityTypeModel.TABLE + - " (" + - TrackedEntityTypeModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - TrackedEntityTypeModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - TrackedEntityTypeModel.Columns.CODE + " TEXT," + - TrackedEntityTypeModel.Columns.NAME + " TEXT," + - TrackedEntityTypeModel.Columns.DISPLAY_NAME + " TEXT," + - TrackedEntityTypeModel.Columns.CREATED + " TEXT," + - TrackedEntityTypeModel.Columns.LAST_UPDATED + " TEXT," + - TrackedEntityTypeModel.Columns.SHORT_NAME + " TEXT," + - TrackedEntityTypeModel.Columns.DISPLAY_SHORT_NAME + " TEXT," + - TrackedEntityTypeModel.Columns.DESCRIPTION + " TEXT," + - TrackedEntityTypeModel.Columns.DISPLAY_DESCRIPTION + " TEXT" + - ");"; - - private static final String CREATE_DATA_ELEMENT_TABLE = - SQLStatementBuilder.createNameableModelTable(DataElementModel.TABLE, - DataElementModel.Columns.VALUE_TYPE + " TEXT," + - DataElementModel.Columns.ZERO_IS_SIGNIFICANT + " INTEGER," + - DataElementModel.Columns.AGGREGATION_TYPE + " TEXT," + - DataElementModel.Columns.FORM_NAME + " TEXT," + - DataElementModel.Columns.NUMBER_TYPE + " TEXT," + - DataElementModel.Columns.DOMAIN_TYPE + " TEXT," + - DataElementModel.Columns.DIMENSION + " TEXT," + - DataElementModel.Columns.DISPLAY_FORM_NAME + " TEXT," + - DataElementModel.Columns.OPTION_SET + " TEXT," + - DataElementModel.Columns.CATEGORY_COMBO + " TEXT," + " FOREIGN KEY ( " - + DataElementModel.Columns.OPTION_SET + ")" + - " REFERENCES " + OptionSetModel.TABLE + " (" + OptionSetModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" - ); - - private static final String CREATE_PROGRAM_STAGE_DATA_ELEMENT_TABLE = "CREATE TABLE " + - ProgramStageDataElementModel.TABLE + " (" + - ProgramStageDataElementModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ProgramStageDataElementModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - ProgramStageDataElementModel.Columns.CODE + " TEXT," + - ProgramStageDataElementModel.Columns.NAME + " TEXT," + - ProgramStageDataElementModel.Columns.DISPLAY_NAME + " TEXT," + - ProgramStageDataElementModel.Columns.CREATED + " TEXT," + - ProgramStageDataElementModel.Columns.LAST_UPDATED + " TEXT," + - ProgramStageDataElementModel.Columns.DISPLAY_IN_REPORTS + " INTEGER," + - ProgramStageDataElementModel.Columns.COMPULSORY + " INTEGER," + - ProgramStageDataElementModel.Columns.ALLOW_PROVIDED_ELSEWHERE + " INTEGER," + - ProgramStageDataElementModel.Columns.SORT_ORDER + " INTEGER," + - ProgramStageDataElementModel.Columns.ALLOW_FUTURE_DATE + " INTEGER," + - ProgramStageDataElementModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + - ProgramStageDataElementModel.Columns.PROGRAM_STAGE + " TEXT NOT NULL," + - ProgramStageDataElementModel.Columns.PROGRAM_STAGE_SECTION + " TEXT," + - " FOREIGN KEY (" + ProgramStageDataElementModel.Columns.PROGRAM_STAGE + ")" + - " REFERENCES " + ProgramStageModel.TABLE + " (" + ProgramStageModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramStageDataElementModel.Columns.DATA_ELEMENT + ")" + - " REFERENCES " + DataElementModel.TABLE + " (" + DataElementModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramStageDataElementModel.Columns.PROGRAM_STAGE_SECTION + ")" + - " REFERENCES " + ProgramStageSectionModel.TABLE + " (" - + ProgramStageSectionModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_RELATIONSHIP_TABLE = - "CREATE TABLE " + RelationshipModel.TABLE + " (" + - RelationshipModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - RelationshipModel.Columns.TRACKED_ENTITY_INSTANCE_A + " TEXT NOT NULL," + - RelationshipModel.Columns.TRACKED_ENTITY_INSTANCE_B + " TEXT NOT NULL," + - RelationshipModel.Columns.RELATIONSHIP_TYPE + " TEXT NOT NULL," + - " FOREIGN KEY (" + RelationshipModel.Columns.RELATIONSHIP_TYPE + ") " + - " REFERENCES " + RelationshipTypeModel.TABLE + " (" - + RelationshipTypeModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - " FOREIGN KEY (" + RelationshipModel.Columns.TRACKED_ENTITY_INSTANCE_A + ") " + - " REFERENCES " + TrackedEntityInstanceModel.TABLE + " (" - + TrackedEntityInstanceModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - " FOREIGN KEY (" + RelationshipModel.Columns.TRACKED_ENTITY_INSTANCE_B + ") " + - " REFERENCES " + TrackedEntityInstanceModel.TABLE + " (" - + TrackedEntityInstanceModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_RELATIONSHIP_TYPE_TABLE = "CREATE TABLE " + - RelationshipTypeModel.TABLE + " (" + - RelationshipTypeModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + - RelationshipTypeModel.Columns.UID + " TEXT NOT NULL UNIQUE, " + - RelationshipTypeModel.Columns.CODE + " TEXT, " + - RelationshipTypeModel.Columns.NAME + " TEXT, " + - RelationshipTypeModel.Columns.DISPLAY_NAME + " TEXT, " + - RelationshipTypeModel.Columns.CREATED + " TEXT, " + - RelationshipTypeModel.Columns.LAST_UPDATED + " TEXT, " + - RelationshipTypeModel.Columns.B_IS_TO_A + " TEXT, " + - RelationshipTypeModel.Columns.A_IS_TO_B + " TEXT " + - ");"; - - private static final String CREATE_PROGRAM_STAGE_SECTION_TABLE = "CREATE TABLE " + - ProgramStageSectionModel.TABLE + " (" + - ProgramStageSectionModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ProgramStageSectionModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - ProgramStageSectionModel.Columns.CODE + " TEXT," + - ProgramStageSectionModel.Columns.NAME + " TEXT," + - ProgramStageSectionModel.Columns.DISPLAY_NAME + " TEXT," + - ProgramStageSectionModel.Columns.CREATED + " TEXT," + - ProgramStageSectionModel.Columns.LAST_UPDATED + " TEXT," + - ProgramStageSectionModel.Columns.SORT_ORDER + " INTEGER," + - ProgramStageSectionModel.Columns.PROGRAM_STAGE + " TEXT NOT NULL," + - ProgramStageSectionModel.Columns.DESKTOP_RENDER_TYPE + " TEXT," + - ProgramStageSectionModel.Columns.MOBILE_RENDER_TYPE + " TEXT," + - " FOREIGN KEY ( " + ProgramStageSectionModel.Columns.PROGRAM_STAGE + ")" + - " REFERENCES " + ProgramStageModel.TABLE + " (" + ProgramStageModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_PROGRAM_STAGE_TABLE = - SQLStatementBuilder.createIdentifiableModelTable(ProgramStageModel.TABLE, - ProgramStageModel.Columns.EXECUTION_DATE_LABEL + " TEXT," + - ProgramStageModel.Columns.ALLOW_GENERATE_NEXT_VISIT + " INTEGER," + - ProgramStageModel.Columns.VALID_COMPLETE_ONLY + " INTEGER," + - ProgramStageModel.Columns.REPORT_DATE_TO_USE + " TEXT," + - ProgramStageModel.Columns.OPEN_AFTER_ENROLLMENT + " INTEGER," + - ProgramStageModel.Columns.REPEATABLE + " INTEGER," + - ProgramStageModel.Columns.CAPTURE_COORDINATES + " INTEGER," + - ProgramStageModel.Columns.FORM_TYPE + " TEXT," + - ProgramStageModel.Columns.DISPLAY_GENERATE_EVENT_BOX + " INTEGER," + - ProgramStageModel.Columns.GENERATED_BY_ENROLMENT_DATE + " INTEGER," + - ProgramStageModel.Columns.AUTO_GENERATE_EVENT + " INTEGER," + - ProgramStageModel.Columns.SORT_ORDER + " INTEGER," + - ProgramStageModel.Columns.HIDE_DUE_DATE + " INTEGER," + - ProgramStageModel.Columns.BLOCK_ENTRY_FORM + " INTEGER," + - ProgramStageModel.Columns.MIN_DAYS_FROM_START + " INTEGER," + - ProgramStageModel.Columns.STANDARD_INTERVAL + " INTEGER," + - ProgramStageModel.Columns.PROGRAM + " TEXT NOT NULL," + - ProgramStageModel.Columns.PERIOD_TYPE + " TEXT," + - ProgramStageModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + - ProgramStageModel.Columns.REMIND_COMPLETED + " INTEGER," + - " FOREIGN KEY ( " + ProgramStageModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" - ); - - private static final String CREATE_PROGRAM_RULE_VARIABLE_TABLE = "CREATE TABLE " + - ProgramRuleVariableModel.TABLE + " (" + - ProgramRuleVariableModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ProgramRuleVariableModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - ProgramRuleVariableModel.Columns.CODE + " TEXT," + - ProgramRuleVariableModel.Columns.NAME + " TEXT," + - ProgramRuleVariableModel.Columns.DISPLAY_NAME + " TEXT," + - ProgramRuleVariableModel.Columns.CREATED + " TEXT," + - ProgramRuleVariableModel.Columns.LAST_UPDATED + " TEXT," + - ProgramRuleVariableModel.Columns.USE_CODE_FOR_OPTION_SET + " INTEGER," + - ProgramRuleVariableModel.Columns.PROGRAM + " TEXT NOT NULL," + - ProgramRuleVariableModel.Columns.PROGRAM_STAGE + " TEXT," + - ProgramRuleVariableModel.Columns.DATA_ELEMENT + " TEXT," + - ProgramRuleVariableModel.Columns.TRACKED_ENTITY_ATTRIBUTE + " TEXT," + - ProgramRuleVariableModel.Columns.PROGRAM_RULE_VARIABLE_SOURCE_TYPE + " TEXT," + - " FOREIGN KEY (" + ProgramRuleVariableModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleVariableModel.Columns.PROGRAM_STAGE + ")" + - " REFERENCES " + ProgramStageModel.TABLE + " (" + ProgramStageModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleVariableModel.Columns.TRACKED_ENTITY_ATTRIBUTE + ")" + - " REFERENCES " + TrackedEntityAttributeModel.TABLE + "(" - + TrackedEntityAttributeModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleVariableModel.Columns.DATA_ELEMENT + ")" + - " REFERENCES " + DataElementModel.TABLE + " (" + DataElementModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_TRACKED_ENTITY_ATTRIBUTE_TABLE = "CREATE TABLE " + - TrackedEntityAttributeModel.TABLE + " (" + - TrackedEntityAttributeModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - TrackedEntityAttributeModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - TrackedEntityAttributeModel.Columns.CODE + " TEXT," + - TrackedEntityAttributeModel.Columns.NAME + " TEXT," + - TrackedEntityAttributeModel.Columns.DISPLAY_NAME + " TEXT," + - TrackedEntityAttributeModel.Columns.CREATED + " TEXT," + - TrackedEntityAttributeModel.Columns.LAST_UPDATED + " TEXT," + - TrackedEntityAttributeModel.Columns.SHORT_NAME + " TEXT," + - TrackedEntityAttributeModel.Columns.DISPLAY_SHORT_NAME + " TEXT," + - TrackedEntityAttributeModel.Columns.DESCRIPTION + " TEXT," + - TrackedEntityAttributeModel.Columns.DISPLAY_DESCRIPTION + " TEXT," + - TrackedEntityAttributeModel.Columns.PATTERN + " TEXT," + - TrackedEntityAttributeModel.Columns.SORT_ORDER_IN_LIST_NO_PROGRAM + " INTEGER," + - TrackedEntityAttributeModel.Columns.OPTION_SET + " TEXT," + - TrackedEntityAttributeModel.Columns.VALUE_TYPE + " TEXT," + - TrackedEntityAttributeModel.Columns.EXPRESSION + " TEXT," + - TrackedEntityAttributeModel.Columns.SEARCH_SCOPE + " TEXT," + - TrackedEntityAttributeModel.Columns.PROGRAM_SCOPE + " INTEGER," + - TrackedEntityAttributeModel.Columns.DISPLAY_IN_LIST_NO_PROGRAM + " INTEGER," + - TrackedEntityAttributeModel.Columns.GENERATED + " INTEGER," + - TrackedEntityAttributeModel.Columns.DISPLAY_ON_VISIT_SCHEDULE + " INTEGER," + - TrackedEntityAttributeModel.Columns.ORG_UNIT_SCOPE + " INTEGER," + - TrackedEntityAttributeModel.Columns.UNIQUE + " INTEGER," + - TrackedEntityAttributeModel.Columns.INHERIT + " INTEGER," + - " FOREIGN KEY (" + TrackedEntityAttributeModel.Columns.OPTION_SET + ")" + - " REFERENCES " + OptionSetModel.TABLE + " (" + OptionSetModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_PROGRAM_TRACKED_ENTITY_ATTRIBUTE_TABLE = - SQLStatementBuilder.createNameableModelTable(ProgramTrackedEntityAttributeModel.TABLE, - ProgramTrackedEntityAttributeModel.Columns.MANDATORY + " INTEGER," + - ProgramTrackedEntityAttributeModel.Columns.TRACKED_ENTITY_ATTRIBUTE + " TEXT NOT NULL," + - ProgramTrackedEntityAttributeModel.Columns.ALLOW_FUTURE_DATES + " INTEGER," + - ProgramTrackedEntityAttributeModel.Columns.DISPLAY_IN_LIST + " INTEGER," + - ProgramTrackedEntityAttributeModel.Columns.PROGRAM + " TEXT NOT NULL," + - ProgramTrackedEntityAttributeModel.Columns.SORT_ORDER + " INTEGER," + - ProgramTrackedEntityAttributeModel.Columns.SEARCHABLE + " INTEGER," + - " FOREIGN KEY (" + ProgramTrackedEntityAttributeModel.Columns.TRACKED_ENTITY_ATTRIBUTE - + ")" + " REFERENCES " + TrackedEntityAttributeModel.TABLE + - " (" + TrackedEntityAttributeModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramTrackedEntityAttributeModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" - ); - - private static final String CREATE_PROGRAM_RULE_TABLE = "CREATE TABLE " + - ProgramRuleModel.TABLE + " (" + - ProgramRuleModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ProgramRuleModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - ProgramRuleModel.Columns.CODE + " TEXT," + - ProgramRuleModel.Columns.NAME + " TEXT," + - ProgramRuleModel.Columns.DISPLAY_NAME + " TEXT," + - ProgramRuleModel.Columns.CREATED + " TEXT," + - ProgramRuleModel.Columns.LAST_UPDATED + " TEXT," + - ProgramRuleModel.Columns.PRIORITY + " INTEGER," + - ProgramRuleModel.Columns.CONDITION + " TEXT," + - ProgramRuleModel.Columns.PROGRAM + " TEXT NOT NULL," + - ProgramRuleModel.Columns.PROGRAM_STAGE + " TEXT," + - " FOREIGN KEY (" + ProgramRuleModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleModel.Columns.PROGRAM_STAGE + ")" + - " REFERENCES " + ProgramStageModel.TABLE + " (" + ProgramStageModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_CONSTANT_TABLE = - "CREATE TABLE " + ConstantModel.TABLE + " (" + - ConstantModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ConstantModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - ConstantModel.Columns.CODE + " TEXT," + - ConstantModel.Columns.NAME + " TEXT," + - ConstantModel.Columns.DISPLAY_NAME + " TEXT," + - ConstantModel.Columns.CREATED + " TEXT," + - ConstantModel.Columns.LAST_UPDATED + " TEXT," + - ConstantModel.Columns.VALUE + " TEXT" + - ");"; - - private static final String CREATE_SYSTEM_INFO_TABLE = - "CREATE TABLE " + SystemInfoModel.TABLE + " (" + - SystemInfoModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + - SystemInfoModel.Columns.SERVER_DATE + " TEXT," + - SystemInfoModel.Columns.DATE_FORMAT + " TEXT," + - SystemInfoModel.Columns.VERSION + " TEXT," + - SystemInfoModel.Columns.CONTEXT_PATH + " TEXT" + - ");"; - - private static final String CREATE_PROGRAM_INDICATOR_TABLE = "CREATE TABLE " + - ProgramIndicatorModel.TABLE + " (" + - ProgramIndicatorModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ProgramIndicatorModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - ProgramIndicatorModel.Columns.CODE + " TEXT," + - ProgramIndicatorModel.Columns.NAME + " TEXT," + - ProgramIndicatorModel.Columns.DISPLAY_NAME + " TEXT," + - ProgramIndicatorModel.Columns.CREATED + " TEXT," + - ProgramIndicatorModel.Columns.LAST_UPDATED + " TEXT," + - ProgramIndicatorModel.Columns.SHORT_NAME + " TEXT," + - ProgramIndicatorModel.Columns.DISPLAY_SHORT_NAME + " TEXT," + - ProgramIndicatorModel.Columns.DESCRIPTION + " TEXT," + - ProgramIndicatorModel.Columns.DISPLAY_DESCRIPTION + " TEXT," + - ProgramIndicatorModel.Columns.DISPLAY_IN_FORM + " INTEGER," + - ProgramIndicatorModel.Columns.EXPRESSION + " TEXT," + - ProgramIndicatorModel.Columns.DIMENSION_ITEM + " TEXT," + - ProgramIndicatorModel.Columns.FILTER + " TEXT," + - ProgramIndicatorModel.Columns.DECIMALS + " INTEGER," + - ProgramIndicatorModel.Columns.PROGRAM + " TEXT NOT NULL," + - " FOREIGN KEY (" + ProgramIndicatorModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED " + - ");"; - - private static final String CREATE_PROGRAM_RULE_ACTION_TABLE = "CREATE TABLE " + - ProgramRuleActionModel.TABLE + " (" + - ProgramRuleActionModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ProgramRuleActionModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - ProgramRuleActionModel.Columns.CODE + " TEXT," + - ProgramRuleActionModel.Columns.NAME + " TEXT," + - ProgramRuleActionModel.Columns.DISPLAY_NAME + " TEXT," + - ProgramRuleActionModel.Columns.CREATED + " TEXT," + - ProgramRuleActionModel.Columns.LAST_UPDATED + " TEXT," + - ProgramRuleActionModel.Columns.DATA + " TEXT," + - ProgramRuleActionModel.Columns.CONTENT + " TEXT," + - ProgramRuleActionModel.Columns.LOCATION + " TEXT," + - ProgramRuleActionModel.Columns.TRACKED_ENTITY_ATTRIBUTE + " TEXT," + - ProgramRuleActionModel.Columns.PROGRAM_INDICATOR + " TEXT," + - ProgramRuleActionModel.Columns.PROGRAM_STAGE_SECTION + " TEXT," + - ProgramRuleActionModel.Columns.PROGRAM_RULE_ACTION_TYPE + " TEXT," + - ProgramRuleActionModel.Columns.PROGRAM_STAGE + " TEXT," + - ProgramRuleActionModel.Columns.DATA_ELEMENT + " TEXT," + - ProgramRuleActionModel.Columns.PROGRAM_RULE + " TEXT NOT NULL," + - " FOREIGN KEY (" + ProgramRuleActionModel.Columns.PROGRAM_RULE + ")" + - " REFERENCES " + ProgramRuleModel.TABLE + - " (" + ProgramRuleModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleActionModel.Columns.TRACKED_ENTITY_ATTRIBUTE + ")" + - " REFERENCES " + TrackedEntityAttributeModel.TABLE + - " (" + TrackedEntityAttributeModel.Columns.UID + ") " + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleActionModel.Columns.PROGRAM_INDICATOR + ")" + - " REFERENCES " + ProgramIndicatorModel.TABLE + - " (" + ProgramIndicatorModel.Columns.UID + ") " + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleActionModel.Columns.PROGRAM_STAGE_SECTION + ")" + - " REFERENCES " + ProgramStageSectionModel.TABLE + - " (" + ProgramStageSectionModel.Columns.UID + ") " + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleActionModel.Columns.PROGRAM_STAGE + ")" + - " REFERENCES " + ProgramStageModel.TABLE + - " (" + ProgramStageModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramRuleActionModel.Columns.DATA_ELEMENT + ")" + - " REFERENCES " + DataElementModel.TABLE + - " (" + DataElementModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - //TODO We need to review the constrain between dataelement and trackedentitydatavalue - private static final String CREATE_TRACKED_ENTITY_DATA_VALUE_TABLE = "CREATE TABLE " + - TrackedEntityDataValueModel.TABLE + " (" + - TrackedEntityDataValueModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - TrackedEntityDataValueModel.Columns.EVENT + " TEXT NOT NULL," + - TrackedEntityDataValueModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + - TrackedEntityDataValueModel.Columns.STORED_BY + " TEXT," + - TrackedEntityDataValueModel.Columns.VALUE + " TEXT," + - TrackedEntityDataValueModel.Columns.CREATED + " TEXT," + - TrackedEntityDataValueModel.Columns.LAST_UPDATED + " TEXT," + - TrackedEntityDataValueModel.Columns.PROVIDED_ELSEWHERE + " INTEGER," + - /*" FOREIGN KEY (" + TrackedEntityDataValueModel.Columns.DATA_ELEMENT + ")" + - " REFERENCES " + DataElementModel.TABLE + - " (" + DataElementModel.Columns.UID + ")" + - " ON DELETE CASCADE, " +*/ - " FOREIGN KEY (" + TrackedEntityDataValueModel.Columns.EVENT + ")" + - " REFERENCES " + EventModel.TABLE + " (" + EventModel.Columns.UID + ")" + - " ON DELETE CASCADE" + - ");"; - - private static final String CREATE_TRACKED_ENTITY_ATTRIBUTE_VALUE_TABLE = "CREATE TABLE " + - TrackedEntityAttributeValueModel.TABLE + " (" + - TrackedEntityAttributeValueModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - TrackedEntityAttributeValueModel.Columns.CREATED + " TEXT," + - TrackedEntityAttributeValueModel.Columns.LAST_UPDATED + " TEXT," + - TrackedEntityAttributeValueModel.Columns.VALUE + " TEXT," + - TrackedEntityAttributeValueModel.Columns.TRACKED_ENTITY_ATTRIBUTE + " TEXT NOT NULL," + - TrackedEntityAttributeValueModel.Columns.TRACKED_ENTITY_INSTANCE + " TEXT NOT NULL," + - /*" FOREIGN KEY (" + TrackedEntityAttributeValueModel.Columns.TRACKED_ENTITY_ATTRIBUTE - + ")" + - " REFERENCES " + TrackedEntityAttributeModel.TABLE + - " (" + TrackedEntityAttributeModel.Columns.UID + ")" + - " ON DELETE CASCADE, " +*/ - " FOREIGN KEY (" + TrackedEntityAttributeValueModel.Columns.TRACKED_ENTITY_INSTANCE - + ") " + - " REFERENCES " + TrackedEntityInstanceModel.TABLE + - " (" + TrackedEntityInstanceModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_EVENT_TABLE = "CREATE TABLE " + EventModel.TABLE + " (" + - EventModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - EventModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - EventModel.Columns.ENROLLMENT_UID + " TEXT," + - EventModel.Columns.CREATED + " TEXT," + - EventModel.Columns.LAST_UPDATED + " TEXT," + - EventModel.Columns.CREATED_AT_CLIENT + " TEXT," + - EventModel.Columns.LAST_UPDATED_AT_CLIENT + " TEXT," + - EventModel.Columns.STATUS + " TEXT," + - EventModel.Columns.LATITUDE + " TEXT," + - EventModel.Columns.LONGITUDE + " TEXT," + - EventModel.Columns.PROGRAM + " TEXT NOT NULL," + - EventModel.Columns.PROGRAM_STAGE + " TEXT NOT NULL," + - EventModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - EventModel.Columns.EVENT_DATE + " TEXT," + - EventModel.Columns.COMPLETE_DATE + " TEXT," + - EventModel.Columns.DUE_DATE + " TEXT," + - EventModel.Columns.STATE + " TEXT," + - EventModel.Columns.ATTRIBUTE_CATEGORY_OPTIONS + " TEXT," + - EventModel.Columns.ATTRIBUTE_OPTION_COMBO + " TEXT," + - EventModel.Columns.TRACKED_ENTITY_INSTANCE + " TEXT," + - " FOREIGN KEY (" + EventModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + - " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE," + - " FOREIGN KEY (" + EventModel.Columns.PROGRAM_STAGE + ")" + - " REFERENCES " + ProgramStageModel.TABLE + - " (" + ProgramStageModel.Columns.UID + ")" + - " ON DELETE CASCADE," + - "FOREIGN KEY (" + EventModel.Columns.ENROLLMENT_UID + ")" + - " REFERENCES " + EnrollmentModel.TABLE + - " (" + EnrollmentModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + EventModel.Columns.ORGANISATION_UNIT + ")" + - " REFERENCES " + OrganisationUnitModel.TABLE + - " (" + OrganisationUnitModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + EventModel.Columns.TRACKED_ENTITY_INSTANCE + ")" + - " REFERENCES " + TrackedEntityInstanceModel.TABLE + " (" + TrackedEntityInstanceModel.Columns.UID + ")" + - " ON DELETE CASCADE," + - " FOREIGN KEY (" + EventModel.Columns.ATTRIBUTE_CATEGORY_OPTIONS + ")" + - " REFERENCES " + CategoryOptionModel.TABLE + " (" + CategoryOptionModel.Columns.UID + ")"+ - " ON DELETE CASCADE," + - " FOREIGN KEY (" + EventModel.Columns.ATTRIBUTE_OPTION_COMBO + ")" + - " REFERENCES " + CategoryOptionComboModel.TABLE + " (" + CategoryOptionComboModel.Columns.UID + ")" - + - " ON DELETE CASCADE" + - ");"; - - private static final String CREATE_TRACKED_ENTITY_INSTANCE_TABLE = "CREATE TABLE " + - TrackedEntityInstanceModel.TABLE + " (" + - TrackedEntityInstanceModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - TrackedEntityInstanceModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - TrackedEntityInstanceModel.Columns.CREATED + " TEXT," + - TrackedEntityInstanceModel.Columns.LAST_UPDATED + " TEXT," + - TrackedEntityInstanceModel.Columns.CREATED_AT_CLIENT + " TEXT," + - TrackedEntityInstanceModel.Columns.LAST_UPDATED_AT_CLIENT + " TEXT," + - TrackedEntityInstanceModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - TrackedEntityInstanceModel.Columns.TRACKED_ENTITY_TYPE + " TEXT NOT NULL," + - TrackedEntityInstanceModel.Columns.COORDINATES + " TEXT," + - TrackedEntityInstanceModel.Columns.FEATURE_TYPE + " TEXT," + - TrackedEntityInstanceModel.Columns.STATE + " TEXT," + - " FOREIGN KEY (" + TrackedEntityInstanceModel.Columns.ORGANISATION_UNIT + ")" + - " REFERENCES " + OrganisationUnitModel.TABLE + " (" + OrganisationUnitModel.Columns.UID - + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - " FOREIGN KEY (" + TrackedEntityInstanceModel.Columns.TRACKED_ENTITY_TYPE + ")" + - " REFERENCES " + TrackedEntityTypeModel.TABLE + " (" + TrackedEntityTypeModel.Columns.UID + ")" - + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_ENROLLMENT_TABLE = - "CREATE TABLE " + EnrollmentModel.TABLE + " (" + - EnrollmentModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - EnrollmentModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - EnrollmentModel.Columns.CREATED + " TEXT," + - EnrollmentModel.Columns.LAST_UPDATED + " TEXT," + - EnrollmentModel.Columns.CREATED_AT_CLIENT + " TEXT," + - EnrollmentModel.Columns.LAST_UPDATED_AT_CLIENT + " TEXT," + - EnrollmentModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - EnrollmentModel.Columns.PROGRAM + " TEXT NOT NULL," + - EnrollmentModel.Columns.DATE_OF_ENROLLMENT + " TEXT," + - EnrollmentModel.Columns.DATE_OF_INCIDENT + " TEXT," + - EnrollmentModel.Columns.FOLLOW_UP + " INTEGER," + - EnrollmentModel.Columns.ENROLLMENT_STATUS + " TEXT," + - EnrollmentModel.Columns.TRACKED_ENTITY_INSTANCE + " TEXT NOT NULL," + - EnrollmentModel.Columns.LATITUDE + " TEXT," + - EnrollmentModel.Columns.LONGITUDE + " TEXT," + - EnrollmentModel.Columns.STATE + " TEXT," + - " FOREIGN KEY (" + EnrollmentModel.Columns.ORGANISATION_UNIT + ")" + - " REFERENCES " + OrganisationUnitModel.TABLE + - " (" + OrganisationUnitModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + EnrollmentModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + - " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + EnrollmentModel.Columns.TRACKED_ENTITY_INSTANCE + ")" + - " REFERENCES " + TrackedEntityInstanceModel.TABLE + - " (" + TrackedEntityInstanceModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + - ");"; - - private static final String CREATE_RESOURCE_TABLE = - "CREATE TABLE " + ResourceModel.TABLE + " (" + - ResourceModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ResourceModel.Columns.RESOURCE_TYPE + " TEXT NOT NULL," + - ResourceModel.Columns.LAST_SYNCED + " TEXT" + ");"; - - private static final String CREATE_ORGANISATION_UNIT_PROGRAM_LINK_TABLE = "CREATE TABLE " + - OrganisationUnitProgramLinkModel.TABLE + " (" + - OrganisationUnitProgramLinkModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - OrganisationUnitProgramLinkModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - OrganisationUnitProgramLinkModel.Columns.PROGRAM + " TEXT NOT NULL," + - " FOREIGN KEY (" + OrganisationUnitProgramLinkModel.Columns.ORGANISATION_UNIT + ")" + - " REFERENCES " + OrganisationUnitModel.TABLE + " (" + OrganisationUnitModel.Columns.UID - + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + OrganisationUnitProgramLinkModel.Columns.PROGRAM + ")" + - " REFERENCES " + ProgramModel.TABLE + " (" + ProgramModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + OrganisationUnitProgramLinkModel.Columns.ORGANISATION_UNIT + ", " + - OrganisationUnitProgramLinkModel.Columns.PROGRAM + ")" + - ");"; - - private static final String CREATE_USER_ROLE_TABLE = - "CREATE TABLE " + UserRoleModel.TABLE + " (" + - UserRoleModel.Columns.ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + - UserRoleModel.Columns.UID + " TEXT NOT NULL UNIQUE," + - UserRoleModel.Columns.CODE + " TEXT," + - UserRoleModel.Columns.NAME + " TEXT," + - UserRoleModel.Columns.DISPLAY_NAME + " TEXT," + - UserRoleModel.Columns.CREATED + " TEXT," + - UserRoleModel.Columns.LAST_UPDATED + " TEXT" + - ");"; - - private static final String CREATE_PROGRAM_STAGE_SECTION_PROGRAM_INDICATOR_LINK_TABLE = - "CREATE TABLE " + - ProgramStageSectionProgramIndicatorLinkModel.TABLE + " (" + - ProgramStageSectionProgramIndicatorLinkModel.Columns.ID - + " INTEGER PRIMARY KEY AUTOINCREMENT," + - ProgramStageSectionProgramIndicatorLinkModel.Columns.PROGRAM_STAGE_SECTION - + " TEXT NOT NULL," + - ProgramStageSectionProgramIndicatorLinkModel.Columns.PROGRAM_INDICATOR - + " TEXT NOT NULL," + - " FOREIGN KEY (" - + ProgramStageSectionProgramIndicatorLinkModel.Columns.PROGRAM_STAGE_SECTION - + ") " + - " REFERENCES " + ProgramStageSectionModel.TABLE + " (" - + ProgramStageModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" - + ProgramStageSectionProgramIndicatorLinkModel.Columns.PROGRAM_INDICATOR + ") " - + - " REFERENCES " + ProgramIndicatorModel.TABLE + " (" - + ProgramIndicatorModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, " + - " UNIQUE (" - + ProgramStageSectionProgramIndicatorLinkModel.Columns.PROGRAM_STAGE_SECTION - + ", " + - ProgramStageSectionProgramIndicatorLinkModel.Columns.PROGRAM_INDICATOR + ")" + - ");"; - - private static final String CREATE_DATA_SET_TABLE = - SQLStatementBuilder.createNameableModelTable(DataSetModel.TABLE, - DataSetModel.Columns.PERIOD_TYPE + " TEXT," + - DataSetModel.Columns.CATEGORY_COMBO + " TEXT NOT NULL," + - DataSetModel.Columns.MOBILE + " INTEGER," + - DataSetModel.Columns.VERSION + " INTEGER," + - DataSetModel.Columns.EXPIRY_DAYS + " INTEGER," + - DataSetModel.Columns.TIMELY_DAYS + " INTEGER," + - DataSetModel.Columns.NOTIFY_COMPLETING_USER + " INTEGER," + - DataSetModel.Columns.OPEN_FUTURE_PERIODS + " INTEGER," + - DataSetModel.Columns.FIELD_COMBINATION_REQUIRED + " INTEGER," + - DataSetModel.Columns.VALID_COMPLETE_ONLY + " INTEGER," + - DataSetModel.Columns.NO_VALUE_REQUIRES_COMMENT + " INTEGER," + - DataSetModel.Columns.SKIP_OFFLINE + " INTEGER," + - DataSetModel.Columns.DATA_ELEMENT_DECORATION + " INTEGER," + - DataSetModel.Columns.RENDER_AS_TABS + " INTEGER," + - DataSetModel.Columns.RENDER_HORIZONTALLY + " INTEGER," + - DataSetModel.Columns.ACCESS_DATA_WRITE + " INTEGER," + - " FOREIGN KEY ( " + DataSetModel.Columns.CATEGORY_COMBO + ")" + - " REFERENCES " + CategoryComboModel.TABLE + " (" + CategoryComboModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" - ); - - private static final String CREATE_DATA_SET_DATA_ELEMENT_LINK_TABLE = - SQLStatementBuilder.createModelTable(DataSetDataElementLinkModel.TABLE, - DataSetDataElementLinkModel.Columns.DATA_SET + " TEXT NOT NULL," + - DataSetDataElementLinkModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + - " FOREIGN KEY (" + DataSetDataElementLinkModel.Columns.DATA_SET + ") " + - " REFERENCES " + DataSetModel.TABLE + " (" + DataSetModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + DataSetDataElementLinkModel.Columns.DATA_ELEMENT + ") " + - " REFERENCES " + DataElementModel.TABLE + " (" + DataElementModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + DataSetDataElementLinkModel.Columns.DATA_SET + ", " + - DataSetDataElementLinkModel.Columns.DATA_ELEMENT + ")" - ); - - private static final String CREATE_DATA_SET_ORGANISATION_UNIT_LINK_TABLE = - SQLStatementBuilder.createModelTable(DataSetOrganisationUnitLinkModel.TABLE, - DataSetOrganisationUnitLinkModel.Columns.DATA_SET + " TEXT NOT NULL," + - DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - " FOREIGN KEY (" + DataSetOrganisationUnitLinkModel.Columns.DATA_SET + ") " + - " REFERENCES " + DataSetModel.TABLE + " (" + DataSetModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ") " + - " REFERENCES " + OrganisationUnitModel.TABLE + " (" + - OrganisationUnitModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + DataSetOrganisationUnitLinkModel.Columns.DATA_SET + ", " + - DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ")" - ); - - private static final String CREATE_INDICATOR_TABLE = - SQLStatementBuilder.createNameableModelTable(IndicatorModel.TABLE, - IndicatorModel.Columns.ANNUALIZED + " INTEGER," + - IndicatorModel.Columns.INDICATOR_TYPE + " TEXT," + - IndicatorModel.Columns.NUMERATOR + " TEXT," + - IndicatorModel.Columns.NUMERATOR_DESCRIPTION + " TEXT," + - IndicatorModel.Columns.DENOMINATOR + " TEXT," + - IndicatorModel.Columns.DENOMINATOR_DESCRIPTION + " TEXT," + - IndicatorModel.Columns.URL + " TEXT," + - " FOREIGN KEY ( " + IndicatorModel.Columns.INDICATOR_TYPE + ")" + - " REFERENCES " + IndicatorTypeModel.TABLE + " (" + IndicatorTypeModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" - ); - - private static final String CREATE_INDICATOR_TYPE_TABLE = - SQLStatementBuilder.createNameableModelTable(IndicatorTypeModel.TABLE, - IndicatorTypeModel.Columns.NUMBER + " INTEGER," + - IndicatorTypeModel.Columns.FACTOR + " INTEGER" - ); - - private static final String CREATE_DATA_SET_INDICATOR_LINK_TABLE = - SQLStatementBuilder.createModelTable(DataSetIndicatorLinkModel.TABLE, - DataSetIndicatorLinkModel.Columns.DATA_SET + " TEXT NOT NULL," + - DataSetIndicatorLinkModel.Columns.INDICATOR + " TEXT NOT NULL," + - " FOREIGN KEY (" + DataSetIndicatorLinkModel.Columns.DATA_SET + ") " + - " REFERENCES " + DataSetModel.TABLE + " (" + DataSetModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + DataSetIndicatorLinkModel.Columns.INDICATOR + ") " + - " REFERENCES " + IndicatorModel.TABLE + " (" + IndicatorModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + DataSetIndicatorLinkModel.Columns.DATA_SET + ", " + - DataSetIndicatorLinkModel.Columns.INDICATOR + ")" - ); - - private static final String CREATE_DATA_VALUE_TABLE = - SQLStatementBuilder.createModelTable(DataValueModel.TABLE, - DataValueModel.Columns.DATA_ELEMENT + " TEXT NOT NULL," + - DataValueModel.Columns.PERIOD + " TEXT NOT NULL," + - DataValueModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + - DataValueModel.Columns.CATEGORY_OPTION_COMBO + " TEXT NOT NULL," + - DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + " TEXT NOT NULL," + - DataValueModel.Columns.VALUE + " TEXT," + - DataValueModel.Columns.STORED_BY + " TEXT," + - DataValueModel.Columns.CREATED + " TEXT," + - DataValueModel.Columns.LAST_UPDATED + " TEXT," + - DataValueModel.Columns.COMMENT + " TEXT," + - DataValueModel.Columns.FOLLOW_UP + " INTEGER," + - " FOREIGN KEY (" + DataValueModel.Columns.DATA_ELEMENT + ") " + - " REFERENCES " + DataElementModel.TABLE + " (" + DataElementModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + DataValueModel.Columns.PERIOD + ") " + - " REFERENCES " + PeriodModel.TABLE + " (" + - PeriodModel.Columns.PERIOD_ID + ")" + - " FOREIGN KEY (" + DataValueModel.Columns.ORGANISATION_UNIT + ") " + - " REFERENCES " + OrganisationUnitModel.TABLE + " (" + - OrganisationUnitModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + DataValueModel.Columns.CATEGORY_OPTION_COMBO + ") " + - " REFERENCES " + CategoryOptionComboModel.TABLE + " (" + - CategoryOptionComboModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + ") " + - " REFERENCES " + CategoryOptionComboModel.TABLE + " (" + - CategoryOptionComboModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + - DataValueModel.Columns.DATA_ELEMENT + ", " + - DataValueModel.Columns.PERIOD + ", " + - DataValueModel.Columns.ORGANISATION_UNIT + ", " + - DataValueModel.Columns.CATEGORY_OPTION_COMBO + ", " + - DataValueModel.Columns.ATTRIBUTE_OPTION_COMBO + ")" - ); - - private static final String CREATE_PERIOD_TABLE = - SQLStatementBuilder.createModelTable(PeriodModel.TABLE, - PeriodModel.Columns.PERIOD_ID + " TEXT," + - PeriodModel.Columns.PERIOD_TYPE + " TEXT," + - PeriodModel.Columns.START_DATE + " TEXT," + - PeriodModel.Columns.END_DATE + " TEXT," + - " UNIQUE (" + PeriodModel.Columns.PERIOD_ID + ")" - ); - - private static final String CREATE_OBJECT_STYLE_TABLE = - SQLStatementBuilder.createModelTable(ObjectStyleModel.TABLE, - ObjectStyleModel.Columns.UID + " TEXT," + - ObjectStyleModel.Columns.OBJECT_TABLE + " TEXT," + - ObjectStyleModel.Columns.COLOR + " TEXT," + - ObjectStyleModel.Columns.ICON + " TEXT," + - " UNIQUE (" + ObjectStyleModel.Columns.UID + ")" - ); - - private static final String CREATE_VALUE_TYPE_DEVICE_RENDERING_TABLE = - SQLStatementBuilder.createModelTable(ValueTypeDeviceRenderingModel.TABLE, - ValueTypeDeviceRenderingModel.Columns.UID + " TEXT," + - ValueTypeDeviceRenderingModel.Columns.OBJECT_TABLE + " TEXT," + - ValueTypeDeviceRenderingModel.Columns.DEVICE_TYPE + " TEXT," + - ValueTypeDeviceRenderingModel.Columns.TYPE + " TEXT," + - ValueTypeDeviceRenderingModel.Columns.MIN + " INTEGER," + - ValueTypeDeviceRenderingModel.Columns.MAX + " INTEGER," + - ValueTypeDeviceRenderingModel.Columns.STEP + " INTEGER," + - ValueTypeDeviceRenderingModel.Columns.DECIMAL_POINTS + " INTEGER," + - " UNIQUE (" + ValueTypeDeviceRenderingModel.Columns.UID + ", " + - ValueTypeDeviceRenderingModel.Columns.DEVICE_TYPE + ")" - ); - - private static final String CREATE_NOTE_TABLE = - SQLStatementBuilder.createModelTable(NoteModel.TABLE, - NoteModel.Columns.ENROLLMENT + " TEXT," + - NoteModel.Columns.VALUE + " TEXT," + - NoteModel.Columns.STORED_BY + " TEXT," + - NoteModel.Columns.STORED_DATE + " TEXT," + - " FOREIGN KEY (" + NoteModel.Columns.ENROLLMENT + ") " + - " REFERENCES " + EnrollmentModel.TABLE + " (" + EnrollmentModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + NoteModel.Columns.ENROLLMENT + ", " + - NoteModel.Columns.VALUE + ", " + - NoteModel.Columns.STORED_BY + ", " + - NoteModel.Columns.STORED_DATE + ")" - ); - - private static final String CREATE_LEGEND_TABLE = - SQLStatementBuilder.createIdentifiableModelTable(LegendModel.TABLE, - LegendModel.Columns.START_VALUE + " REAL," + - LegendModel.Columns.END_VALUE + " REAL," + - LegendModel.Columns.COLOR + " TEXT," + - LegendModel.Columns.LEGEND_SET + " TEXT," + - " FOREIGN KEY ( " + LegendModel.Columns.LEGEND_SET + ")" + - " REFERENCES " + LegendSetModel.TABLE + " (" + LegendSetModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" - ); - - private static final String CREATE_LEGEND_SET_TABLE = - SQLStatementBuilder.createIdentifiableModelTable(LegendSetModel.TABLE, - LegendSetModel.Columns.SYMBOLIZER + " TEXT" - ); - - private static final String CREATE_PROGRAM_INDICATOR_LEGEND_SET_LINK_TABLE = - SQLStatementBuilder.createModelTable(ProgramIndicatorLegendSetLinkModel.TABLE, - ProgramIndicatorLegendSetLinkModel.Columns.PROGRAM_INDICATOR + " TEXT NOT NULL," + - ProgramIndicatorLegendSetLinkModel.Columns.LEGEND_SET + " TEXT NOT NULL," + - " FOREIGN KEY (" + ProgramIndicatorLegendSetLinkModel.Columns.PROGRAM_INDICATOR + ") " + - " REFERENCES " + ProgramIndicatorModel.TABLE + " (" + - ProgramIndicatorModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " FOREIGN KEY (" + ProgramIndicatorLegendSetLinkModel.Columns.LEGEND_SET + ") " + - " REFERENCES " + LegendSetModel.TABLE + " (" + LegendSetModel.Columns.UID + ")" + - " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + - " UNIQUE (" + ProgramIndicatorLegendSetLinkModel.Columns.PROGRAM_INDICATOR + ", " + - ProgramIndicatorLegendSetLinkModel.Columns.LEGEND_SET + ")" - ); - - private static final String CREATE_SYSTEM_SETTING_TABLE = - SQLStatementBuilder.createModelTable(SystemSettingModel.TABLE, - SystemSettingModel.Columns.KEY + " TEXT," + - SystemSettingModel.Columns.VALUE + " TEXT," + - " UNIQUE (" + SystemSettingModel.Columns.KEY + ")" - ); - - private static final String CREATE_TRACKED_ENTITY_ATTRIBUTE_RESERVED_VALUE_TABLE = - SQLStatementBuilder.createModelTable(TrackedEntityAttributeReservedValueModel.TABLE, - TrackedEntityAttributeReservedValueModel.Columns.OWNER_OBJECT + " TEXT," + - TrackedEntityAttributeReservedValueModel.Columns.OWNER_UID + " TEXT," + - TrackedEntityAttributeReservedValueModel.Columns.KEY + " TEXT," + - TrackedEntityAttributeReservedValueModel.Columns.VALUE + " TEXT," + - TrackedEntityAttributeReservedValueModel.Columns.CREATED + " TEXT," + - TrackedEntityAttributeReservedValueModel.Columns.EXPIRY_DATE + " TEXT," + - TrackedEntityAttributeReservedValueModel.Columns.ORGANISATION_UNIT + " TEXT" - ); - - /** - * This method should be used only for testing purposes - */ - // ToDo: Revise usage of this method - @VisibleForTesting - static SQLiteDatabase create() { - return create(SQLiteDatabase.create(null)); - } - - - private static SQLiteDatabase create(SQLiteDatabase database) { - database.execSQL(CREATE_CONFIGURATION_TABLE); - database.execSQL(CREATE_USER_TABLE); - database.execSQL(CREATE_USER_CREDENTIALS_TABLE); - database.execSQL(CREATE_ORGANISATION_UNIT_TABLE); - database.execSQL(CREATE_USER_ORGANISATION_UNIT_TABLE); - database.execSQL(CREATE_AUTHENTICATED_USER_TABLE); - database.execSQL(CREATE_OPTION_SET_TABLE); - database.execSQL(CREATE_OPTION_TABLE); - database.execSQL(CREATE_PROGRAM_TABLE); - database.execSQL(CREATE_TRACKED_ENTITY_TABLE); - database.execSQL(CREATE_DATA_ELEMENT_TABLE); - database.execSQL(CREATE_PROGRAM_STAGE_DATA_ELEMENT_TABLE); - database.execSQL(CREATE_RELATIONSHIP_TABLE); - database.execSQL(CREATE_RELATIONSHIP_TYPE_TABLE); - database.execSQL(CREATE_PROGRAM_STAGE_SECTION_TABLE); - database.execSQL(CREATE_PROGRAM_STAGE_TABLE); - database.execSQL(CREATE_PROGRAM_RULE_VARIABLE_TABLE); - database.execSQL(CREATE_TRACKED_ENTITY_ATTRIBUTE_TABLE); - database.execSQL(CREATE_PROGRAM_TRACKED_ENTITY_ATTRIBUTE_TABLE); - database.execSQL(CREATE_CONSTANT_TABLE); - database.execSQL(CREATE_SYSTEM_INFO_TABLE); - database.execSQL(CREATE_PROGRAM_RULE_TABLE); - database.execSQL(CREATE_PROGRAM_INDICATOR_TABLE); - database.execSQL(CREATE_PROGRAM_RULE_ACTION_TABLE); - database.execSQL(CREATE_TRACKED_ENTITY_DATA_VALUE_TABLE); - database.execSQL(CREATE_TRACKED_ENTITY_ATTRIBUTE_VALUE_TABLE); - database.execSQL(CREATE_EVENT_TABLE); - database.execSQL(CREATE_TRACKED_ENTITY_INSTANCE_TABLE); - database.execSQL(CREATE_ENROLLMENT_TABLE); - database.execSQL(CREATE_RESOURCE_TABLE); - database.execSQL(CREATE_ORGANISATION_UNIT_PROGRAM_LINK_TABLE); - database.execSQL(CREATE_USER_ROLE_TABLE); - database.execSQL(CREATE_PROGRAM_STAGE_SECTION_PROGRAM_INDICATOR_LINK_TABLE); - database.execSQL(CREATE_CATEGORY_TABLE); - database.execSQL(CREATE_CATEGORY_OPTION_TABLE); - database.execSQL(CREATE_CATEGORY_CATEGORY_OPTION_LINK_TABLE); - database.execSQL(CREATE_CATEGORY_COMBO_TABLE); - database.execSQL(CREATE_CATEGORY_CATEGORY_COMBO_LINK_TABLE); - database.execSQL(CREATE_CATEGORY_OPTION_COMBO_TABLE); - database.execSQL(CREATE_CATEGORY_OPTION_COMBO_CATEGORY_LINK_TABLE); - database.execSQL(CREATE_DATA_SET_TABLE); - database.execSQL(CREATE_DATA_SET_DATA_ELEMENT_LINK_TABLE); - database.execSQL(CREATE_DATA_SET_ORGANISATION_UNIT_LINK_TABLE); - database.execSQL(CREATE_INDICATOR_TABLE); - database.execSQL(CREATE_INDICATOR_TYPE_TABLE); - database.execSQL(CREATE_DATA_SET_INDICATOR_LINK_TABLE); - database.execSQL(CREATE_DATA_VALUE_TABLE); - database.execSQL(CREATE_PERIOD_TABLE); - database.execSQL(CREATE_OBJECT_STYLE_TABLE); - database.execSQL(CREATE_VALUE_TYPE_DEVICE_RENDERING_TABLE); - database.execSQL(CREATE_NOTE_TABLE); - database.execSQL(CREATE_LEGEND_TABLE); - database.execSQL(CREATE_LEGEND_SET_TABLE); - database.execSQL(CREATE_PROGRAM_INDICATOR_LEGEND_SET_LINK_TABLE); - database.execSQL(CREATE_SYSTEM_SETTING_TABLE); - database.execSQL(CREATE_TRACKED_ENTITY_ATTRIBUTE_RESERVED_VALUE_TABLE); - return database; - } - - public DbOpenHelper(Context context, String databaseName, int version, String migrationTestDir, - String sqlDatabase) { - super(context, databaseName, version, true, migrationTestDir); - mockedSqlDatabase = sqlDatabase; - } + public static final int VERSION = 3; public DbOpenHelper(@NonNull Context context, @Nullable String databaseName) { - super(context, databaseName, VERSION); + super(context, databaseName, null, VERSION); } public DbOpenHelper(Context context, String databaseName, int testVersion) { - super(context, databaseName, testVersion); - } - - @Override - public void onCreate(SQLiteDatabase db) { - String emptySqlFile = ""; - if (emptySqlFile.equals(mockedSqlDatabase)) { - create(db); - } else { - populateDBfromResource(db, mockedSqlDatabase); - } - super.onCreate(db); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - super.onUpgrade(db, oldVersion, newVersion); + super(context, databaseName, null, testVersion); } @Override @@ -1213,32 +60,14 @@ public void onOpen(SQLiteDatabase db) { db.execSQL("PRAGMA foreign_keys = ON;"); } - private SQLiteDatabase populateDBfromResource(SQLiteDatabase database, String databaseSqlFile) { - String emptySqlFile = ""; - if (emptySqlFile.equals(databaseSqlFile)) { - return database; - } - InputStream in = this.getClass().getClassLoader().getResourceAsStream(databaseSqlFile); - InputStreamReader inputStreamReader = new InputStreamReader(in, Charset.forName("UTF-8")); - BufferedReader reader = new BufferedReader(inputStreamReader); - String line = null; - try { - line = reader.readLine(); - while (line != null) { - database.execSQL(line); - line = reader.readLine(); - } - } catch (IOException e) { - Log.e(getClass().getName(), e.getMessage()); - } finally { - try { - reader.close(); - inputStreamReader.close(); - in.close(); - } catch (IOException e) { - Log.e(getClass().getName(), e.getMessage()); - } + // This fixes the bug in SQLBriteOpenHelper, which doesn't let seeds to be optional + @Override + public Map> parse(int newVersion) throws IOException { + Map> versionMigrations = super.parse(newVersion); + List seeds = versionMigrations.get("seeds"); + if (seeds == null || seeds.size() == 1 && seeds.get(0) == null) { + versionMigrations.put("seeds", new ArrayList()); } - return database; + return versionMigrations; } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java index 60f0537a6f..b45015cd23 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataelement/DataElementModel.java @@ -38,6 +38,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseNameableObjectModel; +import org.hisp.dhis.android.core.common.CursorModelFactory; import org.hisp.dhis.android.core.common.ValueType; import org.hisp.dhis.android.core.data.database.DbValueTypeColumnAdapter; import org.hisp.dhis.android.core.utils.Utils; @@ -77,6 +78,14 @@ public static Builder builder() { return new $$AutoValue_DataElementModel.Builder(); } + public static final CursorModelFactory factory + = new CursorModelFactory() { + @Override + public DataElementModel fromCursor(Cursor cursor) { + return create(cursor); + } + }; + @Nullable @ColumnName(Columns.VALUE_TYPE) @ColumnAdapter(DbValueTypeColumnAdapter.class) diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java index c52619413b..2e5fe736ff 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetEndpointCall.java @@ -28,39 +28,38 @@ package org.hisp.dhis.android.core.dataset; +import org.hisp.dhis.android.core.common.DataAccess; +import org.hisp.dhis.android.core.common.EmptyQuery; import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.common.UidsCallFactory; -import org.hisp.dhis.android.core.common.UidsQuery; +import org.hisp.dhis.android.core.common.SimpleCallFactory; import org.hisp.dhis.android.core.resource.ResourceModel; -import java.io.IOException; -import java.util.Set; - import retrofit2.Call; -public final class DataSetEndpointCall extends GenericEndpointCallImpl { +public final class DataSetEndpointCall extends GenericEndpointCallImpl { private final DataSetService dataSetService; private DataSetEndpointCall(GenericCallData data, DataSetService dataSetService, - GenericHandler dataSetHandler, UidsQuery uidsQuery) { - super(data, dataSetHandler, ResourceModel.Type.DATA_SET, new DataSetModelBuilder(), uidsQuery); + GenericHandler dataSetHandler, EmptyQuery query) { + super(data, dataSetHandler, ResourceModel.Type.DATA_SET, new DataSetModelBuilder(), query); this.dataSetService = dataSetService; } @Override - protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { + protected Call> getCall(EmptyQuery query, String lastUpdated) { + String accessDataReadFilter = "access.data." + DataAccess.read.eq(true).generateString(); return dataSetService.getDataSets(DataSet.allFields, DataSet.lastUpdated.gt(lastUpdated), - DataSet.uid.in(query.uids()), Boolean.FALSE); + accessDataReadFilter, Boolean.FALSE); } - static final UidsCallFactory FACTORY = new UidsCallFactory() { + static final SimpleCallFactory> FACTORY = new SimpleCallFactory>() { @Override - public DataSetEndpointCall create(GenericCallData data, Set uids) { + public DataSetEndpointCall create(GenericCallData data) { return new DataSetEndpointCall(data, data.retrofit().create(DataSetService.class), - DataSetHandler.create(data.databaseAdapter()), UidsQuery.create(uids, 64)); + DataSetHandler.create(data.databaseAdapter()), EmptyQuery.create()); } }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java index d64876d4dd..9d6944e10d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentCall.java @@ -33,6 +33,7 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.SimpleCallFactory; import org.hisp.dhis.android.core.common.UidsCallFactory; +import org.hisp.dhis.android.core.common.UidsHelper; import org.hisp.dhis.android.core.dataelement.DataElement; import org.hisp.dhis.android.core.dataelement.DataElementEndpointCall; import org.hisp.dhis.android.core.indicator.Indicator; @@ -51,8 +52,7 @@ public class DataSetParentCall extends TransactionalCall { private final DataSetParentLinkManager linkManager; private final GenericCallData genericCallData; - private final SimpleCallFactory> dataSetAccessCallFactory; - private final UidsCallFactory dataSetCallFactory; + private final SimpleCallFactory> dataSetCallFactory; private final UidsCallFactory dataElementCallFactory; private final UidsCallFactory indicatorCallFactory; private final UidsCallFactory indicatorTypeCallFactory; @@ -61,8 +61,7 @@ public class DataSetParentCall extends TransactionalCall { private DataSetParentCall(GenericCallData genericCallData, DataSetParentLinkManager linkManager, - SimpleCallFactory> dataSetAccessCallFactory, - UidsCallFactory dataSetCallFactory, + SimpleCallFactory> dataSetCallFactory, UidsCallFactory dataElementCallFactory, UidsCallFactory indicatorCallFactory, UidsCallFactory indicatorTypeCallFactory, @@ -71,7 +70,6 @@ private DataSetParentCall(GenericCallData genericCallData, super(genericCallData.databaseAdapter()); this.genericCallData = genericCallData; this.linkManager = linkManager; - this.dataSetAccessCallFactory = dataSetAccessCallFactory; this.dataSetCallFactory = dataSetCallFactory; this.dataElementCallFactory = dataElementCallFactory; this.indicatorCallFactory = indicatorCallFactory; @@ -82,15 +80,11 @@ private DataSetParentCall(GenericCallData genericCallData, @Override public Response callBody() throws Exception { - Call>> dataSetAccessEndpointCall = dataSetAccessCallFactory.create(genericCallData); - Response> dataSetAccessResponse = dataSetAccessEndpointCall.call(); - List dataSetsWithAccess = dataSetAccessResponse.body().items(); - - Set dataSetUids = DataSetParentUidsHelper.getAssignedDataSetUids(dataSetsWithAccess); - - Call>> dataSetEndpointCall = dataSetCallFactory.create(genericCallData, dataSetUids); + Call>> dataSetEndpointCall = dataSetCallFactory.create(genericCallData); Response> dataSetResponse = dataSetEndpointCall.call(); + Set dataSetUids = UidsHelper.getUids(dataSetResponse.body().items()); + Call>> dataElementEndpointCall = dataElementCallFactory.create(genericCallData, dataSetUids); Response> dataElementResponse = dataElementEndpointCall.call(); @@ -123,7 +117,6 @@ public interface Factory { public Call create(User user, GenericCallData data, List organisationUnits) { return new DataSetParentCall(data, DataSetParentLinkManager.create(data.databaseAdapter()), - DataSetAccessEndpointCall.FACTORY, DataSetEndpointCall.FACTORY, DataElementEndpointCall.FACTORY, IndicatorEndpointCall.FACTORY, diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java index f463be3c9a..4727c4ebff 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetParentUidsHelper.java @@ -27,7 +27,6 @@ */ package org.hisp.dhis.android.core.dataset; -import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.indicator.Indicator; @@ -39,18 +38,6 @@ final class DataSetParentUidsHelper { private DataSetParentUidsHelper() {} - static Set getAssignedDataSetUids(List dataSetsWithAccess) { - Set dataSetUids = new HashSet<>(); - for (DataSet dataSet: dataSetsWithAccess) { - Access access = dataSet.access(); - if (access != null && access.data().read()) { - dataSetUids.add(dataSet.uid()); - } - } - - return dataSetUids; - } - static Set getIndicatorUids(List dataSets) { Set uids = new HashSet<>(); for (DataSet dataSet : dataSets) { diff --git a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java index fdb7d45f08..4cf3f493f1 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/dataset/DataSetService.java @@ -41,11 +41,6 @@ public interface DataSetService { @GET("dataSets") Call> getDataSets(@Query("fields") @Which Fields fields, @Query("filter") @Where Filter lastUpdated, - @Query("filter") @Where Filter uids, - @Query("paging") Boolean paging); - - @GET("dataSets") - Call> getDataSetsForAccess(@Query("fields") @Which Fields fields, - @Query("filter") @Where Filter lastUpdated, + @Query("filter") @Where String accessDataReadFilter, @Query("paging") Boolean paging); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/Enrollment.java b/core/src/main/java/org/hisp/dhis/android/core/enrollment/Enrollment.java index e8c77eef44..552b62b9d8 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/Enrollment.java +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/Enrollment.java @@ -36,6 +36,7 @@ import org.hisp.dhis.android.core.common.Coordinates; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; import org.hisp.dhis.android.core.enrollment.note.Note; import org.hisp.dhis.android.core.event.Event; @@ -64,23 +65,27 @@ public abstract class Enrollment { private static final String EVENTS = "events"; private static final String NOTES = "notes"; - public static final Field uid = Field.create(UID); - public static final Field created = Field.create(CREATED); - public static final Field lastUpdated = Field.create(LAST_UPDATED); - public static final Field createdAtClient = Field.create(CREATED_AT_CLIENT); - public static final Field lastUpdatedAtClient = Field.create(LAST_UPDATED_AT_CLIENT); - public static final Field organisationUnit = Field.create(ORGANISATION_UNIT); - public static final Field program = Field.create(PROGRAM); - public static final Field dateOfEnrollment = Field.create(DATE_OF_ENROLLMENT); - public static final Field dateOfIncident = Field.create(DATE_OF_INCIDENT); - public static final Field followUp = Field.create(FOLLOW_UP); - public static final Field enrollmentStatus = Field.create(ENROLLMENT_STATUS); - public static final Field deleted = Field.create(DELETED); - public static final Field trackedEntityInstance = Field.create(TRACKED_ENTITY_INSTANCE); - public static final Field coordinate = Field.create(COORDINATE); - - public static final NestedField events = NestedField.create(EVENTS); - public static final NestedField notes = NestedField.create(NOTES); + private static final Field uid = Field.create(UID); + private static final Field created = Field.create(CREATED); + private static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field organisationUnit = Field.create(ORGANISATION_UNIT); + private static final Field program = Field.create(PROGRAM); + private static final Field dateOfEnrollment = Field.create(DATE_OF_ENROLLMENT); + private static final Field dateOfIncident = Field.create(DATE_OF_INCIDENT); + private static final Field followUp = Field.create(FOLLOW_UP); + private static final Field enrollmentStatus = Field.create(ENROLLMENT_STATUS); + private static final Field deleted = Field.create(DELETED); + private static final Field trackedEntityInstance = Field.create(TRACKED_ENTITY_INSTANCE); + private static final Field coordinate = Field.create(COORDINATE); + + private static final NestedField events = NestedField.create(EVENTS); + private static final NestedField notes = NestedField.create(NOTES); + + public static final Fields allFields = Fields.builder().fields( + uid, created, lastUpdated, coordinate, dateOfEnrollment, dateOfIncident, enrollmentStatus, + followUp, program, organisationUnit, trackedEntityInstance, deleted, events.with(Event.allFields), + notes.with(Note.allFields) + ).build(); @JsonProperty(UID) public abstract String uid(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStore.java b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStore.java index c288b7710f..dcc3c90375 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStore.java @@ -80,4 +80,6 @@ int update(@NonNull String uid, Map> query(); Map> queryAll(); + + EnrollmentModel queryByUid(String enrollmentUid); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStoreImpl.java index 904e7f551f..b3aa4a77bc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/enrollment/EnrollmentStoreImpl.java @@ -122,7 +122,8 @@ public class EnrollmentStoreImpl implements EnrollmentStore { " Enrollment.status, " + " Enrollment.trackedEntityInstance, " + " Enrollment.latitude, " + - " Enrollment.longitude "; + " Enrollment.longitude, " + + " Enrollment.state "; private static final String QUERY_STATEMENT_TO_POST = "SELECT " + FIELDS + @@ -139,6 +140,10 @@ public class EnrollmentStoreImpl implements EnrollmentStore { FIELDS + " FROM Enrollment;"; + private static final String QUERY_BY_UID = "SELECT " + + FIELDS + + " FROM Enrollment WHERE Enrollment.uid = '?'"; + private final SQLiteStatement insertStatement; private final SQLiteStatement updateStatement; private final SQLiteStatement deleteStatement; @@ -252,6 +257,25 @@ public Map> queryAll() { return mapFromCursor(cursor); } + @Override + public EnrollmentModel queryByUid(String enrollmentUid) { + String queryStatement = QUERY_BY_UID.replace("?", enrollmentUid); + + Cursor cursor = databaseAdapter.query(queryStatement); + + EnrollmentModel object = null; + try { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + object = EnrollmentModel.create(cursor); + } + } finally { + cursor.close(); + } + + return object; + } + private Map> mapFromCursor(Cursor cursor) { Map> enrollmentMap = new HashMap<>(); @@ -284,6 +308,7 @@ private Map> mapFromCursor(Cursor cursor) { : cursor.getString(11); String latitude = cursor.getString(12) == null ? null : cursor.getString(12); String longitude = cursor.getString(13) == null ? null : cursor.getString(13); + // "state" field is ignored if (enrollmentMap.get(trackedEntityInstance) == null) { enrollmentMap.put(trackedEntityInstance, new ArrayList()); diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/Event.java b/core/src/main/java/org/hisp/dhis/android/core/event/Event.java index 7e4d4d4e35..2d6aea792c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/Event.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/Event.java @@ -38,6 +38,7 @@ import org.hisp.dhis.android.core.common.Coordinates; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue; @@ -66,28 +67,33 @@ public abstract class Event { private static final String ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo"; private static final String TRACKED_ENTITY_INSTANCE = "trackedEntityInstance"; - public static final Field uid = Field.create(UID); - public static final Field enrollment = Field.create(ENROLLMENT_UID); - public static final Field created = Field.create(CREATED); - public static final Field lastUpdated = Field.create(LAST_UPDATED); - public static final Field createdAtClient = Field.create(CREATED_AT_CLIENT); - public static final Field lastUpdatedAtClient = Field.create(LAST_UPDATED_AT_CLIENT); - public static final Field eventStatus = Field.create(STATUS); - public static final Field coordinates = Field.create(COORDINATE); - public static final Field program = Field.create(PROGRAM); - public static final Field programStage = Field.create(PROGRAM_STAGE); - public static final Field organisationUnit = Field.create(ORGANISATION_UNIT); - public static final Field eventDate = Field.create(EVENT_DATE); - public static final Field completeDate = Field.create(COMPLETE_DATE); - public static final Field deleted = Field.create(DELETED); - public static final Field dueDate = Field.create(DUE_DATE); - public static final Field attributeCategoryOptions = Field.create(ATTRIBUTE_CATEGORY_OPTIONS); - public static final Field attributeOptionCombo = Field.create(ATTRIBUTE_OPTION_COMBO); - public static final Field trackedEntityInstance = Field.create(TRACKED_ENTITY_INSTANCE); - - public static final NestedField trackedEntityDataValues + static final Field uid = Field.create(UID); + private static final Field enrollment = Field.create(ENROLLMENT_UID); + private static final Field created = Field.create(CREATED); + static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field eventStatus = Field.create(STATUS); + private static final Field coordinates = Field.create(COORDINATE); + private static final Field program = Field.create(PROGRAM); + private static final Field programStage = Field.create(PROGRAM_STAGE); + private static final Field organisationUnit = Field.create(ORGANISATION_UNIT); + private static final Field eventDate = Field.create(EVENT_DATE); + private static final Field completeDate = Field.create(COMPLETE_DATE); + private static final Field deleted = Field.create(DELETED); + private static final Field dueDate = Field.create(DUE_DATE); + private static final Field attributeCategoryOptions = Field.create(ATTRIBUTE_CATEGORY_OPTIONS); + private static final Field attributeOptionCombo = Field.create(ATTRIBUTE_OPTION_COMBO); + + private static final NestedField trackedEntityDataValues = NestedField.create(TRACKED_ENTITY_DATA_VALUES); + public static final Fields allFields = Fields.builder().fields( + attributeCategoryOptions, attributeOptionCombo, uid, created, lastUpdated, completeDate, + coordinates, dueDate, enrollment, eventDate, eventStatus, organisationUnit, program, programStage, + deleted, trackedEntityDataValues.with(TrackedEntityDataValue.allFields) + ).build(); + + + @JsonProperty(UID) public abstract String uid(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/EventEndPointCall.java b/core/src/main/java/org/hisp/dhis/android/core/event/EventEndPointCall.java index 2280455bb8..a4bf334bbd 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/EventEndPointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/EventEndPointCall.java @@ -9,7 +9,6 @@ import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.SyncCall; -import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.database.Transaction; import org.hisp.dhis.android.core.resource.ResourceModel; @@ -55,7 +54,7 @@ public Response> call() throws Exception { eventsByLastUpdated = eventService.getEvents( eventQuery.getOrgUnit(), eventQuery.getProgram(), - eventQuery.getTrackedEntityInstance(), getSingleFields(), + eventQuery.getTrackedEntityInstance(), Event.allFields, Event.lastUpdated.gt(lastSyncedEvents), Event.uid.in(eventQuery.getUIds()), Boolean.TRUE, eventQuery.getPage(), eventQuery.getPageSize()).execute(); } else { @@ -64,7 +63,7 @@ public Response> call() throws Exception { eventsByLastUpdated = eventService.getEvents( eventQuery.getOrgUnit(), eventQuery.getProgram(), - eventQuery.getTrackedEntityInstance(), getSingleFields(), + eventQuery.getTrackedEntityInstance(), Event.allFields, Event.lastUpdated.gt(lastSyncedEvents), Event.uid.in(eventQuery.getUIds()), Boolean.TRUE, eventQuery.getPage(), eventQuery.getPageSize(), categoryCombo.uid(), categoryOption.uid()).execute(); @@ -102,16 +101,6 @@ public Response> call() throws Exception { return eventsByLastUpdated; } - private Fields getSingleFields() { - return Fields.builder().fields( - Event.attributeCategoryOptions, Event.attributeOptionCombo, - Event.uid, Event.created, Event.lastUpdated, - Event.eventStatus, Event.coordinates, Event.program, Event.programStage, - Event.organisationUnit, Event.eventDate, Event.completeDate, - Event.dueDate, Event.deleted, Event.trackedEntityDataValues - ).build(); - } - public static EventEndPointCall create(GenericCallData genericCallData, EventQuery eventQuery) { return new EventEndPointCall( diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/EventStore.java b/core/src/main/java/org/hisp/dhis/android/core/event/EventStore.java index 50d4d95050..f113e0d357 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/EventStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/EventStore.java @@ -93,4 +93,8 @@ int update(@NonNull String uid, List querySingleEvents(); List queryAll(); + + EventModel queryByUid(String eventUid); + + EventModel queryByEnrollmentAndProgramStage(String enrollmentUid, String programStageUid); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/event/EventStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/event/EventStoreImpl.java index 39f28c2cd8..bc74d66847 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/event/EventStoreImpl.java +++ b/core/src/main/java/org/hisp/dhis/android/core/event/EventStoreImpl.java @@ -28,9 +28,6 @@ package org.hisp.dhis.android.core.event; -import static org.hisp.dhis.android.core.utils.StoreUtils.parse; -import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; - import android.database.Cursor; import android.database.sqlite.SQLiteStatement; import android.support.annotation.NonNull; @@ -47,6 +44,9 @@ import java.util.List; import java.util.Map; +import static org.hisp.dhis.android.core.utils.StoreUtils.parse; +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + @SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "PMD.NPathComplexity", @@ -127,6 +127,7 @@ public class EventStoreImpl implements EventStore { " Event.eventDate, " + " Event.completedDate, " + " Event.dueDate, " + + " Event.state, " + " Event.attributeCategoryOptions, " + " Event.attributeOptionCombo, " + " Event.trackedEntityInstance "; @@ -149,6 +150,14 @@ public class EventStoreImpl implements EventStore { private static final String QUERY_SINGLE_EVENTS_TO_POST = QUERY_SINGLE_EVENTS + " AND (Event.state = 'TO_POST' OR Event.state = 'TO_UPDATE')"; + private static final String QUERY_BY_UID = "SELECT " + + FIELDS + + " FROM Event WHERE Event.uid = '?'"; + + private static final String QUERY_BY_ENROLLMENT_AND_PROGRAM_STAGE = "SELECT " + + FIELDS + + " FROM Event WHERE Event.enrollment = '_enrollment' AND Event.programStage = '_programStage'"; + private final SQLiteStatement insertStatement; private final SQLiteStatement updateStatement; private final SQLiteStatement deleteStatement; @@ -310,6 +319,46 @@ public List queryAll() { return mapEventsFromCursor(cursor); } + @Override + public EventModel queryByUid(String eventUid) { + String queryStatement = QUERY_BY_UID.replace("?", eventUid); + + Cursor cursor = databaseAdapter.query(queryStatement); + + EventModel object = null; + try { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + object = EventModel.create(cursor); + } + } finally { + cursor.close(); + } + + return object; + } + + @Override + public EventModel queryByEnrollmentAndProgramStage(String enrollmentUid, String programStageUid) { + String queryStatement = QUERY_BY_ENROLLMENT_AND_PROGRAM_STAGE; + queryStatement = queryStatement.replace("_enrollment", enrollmentUid); + queryStatement = queryStatement.replace("_programStage", programStageUid); + + Cursor cursor = databaseAdapter.query(queryStatement); + + EventModel object = null; + try { + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + object = EventModel.create(cursor); + } + } finally { + cursor.close(); + } + + return object; + } + private List mapEventsFromCursor(Cursor cursor) { List events = new ArrayList<>(cursor.getCount()); @@ -350,9 +399,10 @@ private Event mapEventFromCursor(Cursor cursor) { Date eventDate = cursor.getString(12) == null ? null : parse(cursor.getString(12)); Date completedDate = cursor.getString(13) == null ? null : parse(cursor.getString(13)); Date dueDate = cursor.getString(14) == null ? null : parse(cursor.getString(14)); - String categoryCombo = cursor.getString(15) == null ? null : cursor.getString(15); - String optionCombo = cursor.getString(16) == null ? null : cursor.getString(16); - String trackedEntityInstance = cursor.getString(17) == null ? null : cursor.getString(17); + // "state" field is ignored + String categoryCombo = cursor.getString(16) == null ? null : cursor.getString(16); + String optionCombo = cursor.getString(17) == null ? null : cursor.getString(17); + String trackedEntityInstance = cursor.getString(18) == null ? null : cursor.getString(18); Coordinates coordinates = null; diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java index 256936d922..653512be40 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCall.java @@ -111,7 +111,7 @@ private Response> getOrganisationUnit( @NonNull String uid, @Nullable Filter lastUpdatedFilter) throws IOException { - return organisationUnitService.getOrganisationUnits(uid, OrganisationUnit.allFields, + return organisationUnitService.getOrganisationUnitWithDescendants(uid, OrganisationUnit.allFields, lastUpdatedFilter, true, false).execute(); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitService.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitService.java index 1e50e6079f..f166a49e10 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitService.java @@ -41,11 +41,18 @@ public interface OrganisationUnitService { @GET("organisationUnits/{uid}") - Call> getOrganisationUnits( + Call> getOrganisationUnitWithDescendants( @Path("uid") String organisationUnitUid, @Query("fields") @Which Fields fields, @Query("filter") @Where Filter lastUpdated, @Query("includeDescendants") Boolean descendants, @Query("paging") Boolean paging ); + + @GET("organisationUnits") + Call> getSearchOrganisationUnits( + @Query("fields") @Which Fields fields, + @Query("filter") @Where Filter filter, + @Query("paging") Boolean paging + ); } diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitCall.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitCall.java new file mode 100644 index 0000000000..cb53012ea1 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitCall.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.organisationunit; + +import org.hisp.dhis.android.core.common.APICallExecutor; +import org.hisp.dhis.android.core.common.D2CallException; +import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.Payload; +import org.hisp.dhis.android.core.common.SyncCall; +import org.hisp.dhis.android.core.common.UidsQuery; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +import java.util.List; +import java.util.Set; + +import retrofit2.Call; +import retrofit2.Retrofit; + +public final class SearchOrganisationUnitCall extends SyncCall> { + private final OrganisationUnitService service; + private final GenericHandler handler; + private final UidsQuery query; + + private SearchOrganisationUnitCall(OrganisationUnitService service, + GenericHandler handler, + UidsQuery query) { + this.service = service; + this.handler = handler; + this.query = query; + } + + @Override + public List call() throws D2CallException { + Call> call = service.getSearchOrganisationUnits(OrganisationUnit.allFields, + OrganisationUnit.uid.in(query.uids()), Boolean.FALSE); + List organisationUnits = new APICallExecutor().executePayloadCall(call); + handler.handleMany(organisationUnits, new OrganisationUnitModelBuilder()); + return organisationUnits; + } + + public interface Factory { + SearchOrganisationUnitCall create(DatabaseAdapter databaseAdapter, + Retrofit retrofit, + Set uids, + String userId); + } + + public static final Factory FACTORY = new Factory() { + + @Override + public SearchOrganisationUnitCall create( + DatabaseAdapter databaseAdapter, + Retrofit retrofit, + Set uids, + String userId) { + + return new SearchOrganisationUnitCall( + retrofit.create(OrganisationUnitService.class), + SearchOrganisationUnitHandler.create(databaseAdapter, userId), + UidsQuery.create(uids, null) + ); + } + }; +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitHandler.java b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitHandler.java new file mode 100644 index 0000000000..6838d62694 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitHandler.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.organisationunit; + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import org.hisp.dhis.android.core.user.User; +import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; +import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModelBuilder; +import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkStore; + +public class SearchOrganisationUnitHandler extends IdentifiableHandlerImpl { + + private final ObjectWithoutUidStore userOrganisationUnitLinkStore; + private final String userId; + + SearchOrganisationUnitHandler(@NonNull IdentifiableObjectStore organisationUnitStore, + @NonNull ObjectWithoutUidStore + userOrganisationUnitLinkStore, + @NonNull String userId) { + super(organisationUnitStore); + this.userOrganisationUnitLinkStore = userOrganisationUnitLinkStore; + this.userId = userId; + } + + @Override + protected void afterObjectPersisted(OrganisationUnit organisationUnit) { + UserOrganisationUnitLinkModelBuilder modelBuilder = new UserOrganisationUnitLinkModelBuilder( + OrganisationUnitModel.Scope.SCOPE_TEI_SEARCH, User.builder().uid(userId).build()); + + userOrganisationUnitLinkStore.updateOrInsertWhere(modelBuilder.buildModel(organisationUnit)); + } + + public static SearchOrganisationUnitHandler create(DatabaseAdapter databaseAdapter, + String userId) { + return new SearchOrganisationUnitHandler( + OrganisationUnitStore.create(databaseAdapter), + UserOrganisationUnitLinkStore.create(databaseAdapter), + userId); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java index 7e10a2d013..37247319eb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/Program.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/Program.java @@ -87,6 +87,7 @@ public abstract class Program extends BaseNameableObject { private final static String EXPIRY_PERIOD_TYPE = "expiryPeriodType"; private final static String MIN_ATTRIBUTES_REQUIRED_TO_SEARCH = "minAttributesRequiredToSearch"; private final static String MAX_TEI_COUNT_TO_RETURN = "maxTeiCountToReturn"; + private final static String PROGRAM_SECTIONS = "programSections"; static final Field uid = Field.create(UID); private static final Field code = Field.create(CODE); @@ -146,6 +147,7 @@ public abstract class Program extends BaseNameableObject { private static final NestedField programRuleVariables = NestedField.create(PROGRAM_RULE_VARIABLES); private static final NestedField style = NestedField.create(STYLE); + private static final NestedField programSections = NestedField.create(PROGRAM_SECTIONS); static final Fields allFields = Fields.builder().fields( uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, description, @@ -160,7 +162,7 @@ public abstract class Program extends BaseNameableObject { programTrackedEntityAttributes.with(ProgramTrackedEntityAttribute.allFields), trackedEntityType.with(ObjectWithUid.uid), categoryCombo.with(ObjectWithUid.uid), relationshipType.with(ObjectWithUid.uid), access.with(Access.data.with(DataAccess.write)), - style.with(ObjectStyle.allFields)).build(); + style.with(ObjectStyle.allFields), programSections.with(ProgramSection.allFields)).build(); static final Fields uidAndAccessRead = Fields.builder().fields( uid, access.with(Access.data.with(DataAccess.read))).build(); @@ -313,6 +315,10 @@ String categoryComboUid() { @JsonProperty(MAX_TEI_COUNT_TO_RETURN) public abstract Integer maxTeiCountToReturn(); + @Nullable + @JsonProperty(PROGRAM_SECTIONS) + public abstract List programSections(); + @JsonCreator public static Program create( @JsonProperty(UID) String uid, @@ -357,6 +363,7 @@ public static Program create( @JsonProperty(EXPIRY_PERIOD_TYPE) PeriodType expiryPeriodType, @JsonProperty(MIN_ATTRIBUTES_REQUIRED_TO_SEARCH) Integer minAttributesRequiredToSearch, @JsonProperty(MAX_TEI_COUNT_TO_RETURN) Integer maxTeiCountToReturn, + @JsonProperty(PROGRAM_SECTIONS) List programSections, @JsonProperty(DELETED) Boolean deleted) { return new AutoValue_Program( @@ -402,6 +409,7 @@ public static Program create( completeEventsExpiryDays, expiryPeriodType, minAttributesRequiredToSearch, - maxTeiCountToReturn); + maxTeiCountToReturn, + programSections); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramEndpointCall.java index acb07cc72f..ccec8883d5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramEndpointCall.java @@ -28,39 +28,38 @@ package org.hisp.dhis.android.core.program; +import org.hisp.dhis.android.core.common.DataAccess; +import org.hisp.dhis.android.core.common.EmptyQuery; import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.GenericEndpointCallImpl; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.common.UidsCallFactory; -import org.hisp.dhis.android.core.common.UidsQuery; +import org.hisp.dhis.android.core.common.SimpleCallFactory; import org.hisp.dhis.android.core.resource.ResourceModel; -import java.io.IOException; -import java.util.Set; - import retrofit2.Call; -public final class ProgramEndpointCall extends GenericEndpointCallImpl { +public final class ProgramEndpointCall extends GenericEndpointCallImpl { private final ProgramService programService; ProgramEndpointCall(GenericCallData data, ProgramService programService, - GenericHandler programHandler, UidsQuery uidsQuery) { - super(data, programHandler, ResourceModel.Type.PROGRAM, new ProgramModelBuilder(), uidsQuery); + GenericHandler programHandler, EmptyQuery query) { + super(data, programHandler, ResourceModel.Type.PROGRAM, new ProgramModelBuilder(), query); this.programService = programService; } @Override - protected Call> getCall(UidsQuery query, String lastUpdated) throws IOException { + protected Call> getCall(EmptyQuery query, String lastUpdated) { + String accessDataReadFilter = "access.data." + DataAccess.read.eq(true).generateString(); return programService.getPrograms(Program.allFields, Program.lastUpdated.gt(lastUpdated), - Program.uid.in(query.uids()), Boolean.FALSE); + accessDataReadFilter, Boolean.FALSE); } - static final UidsCallFactory FACTORY = new UidsCallFactory() { + static final SimpleCallFactory> FACTORY = new SimpleCallFactory>() { @Override - public ProgramEndpointCall create(GenericCallData data, Set uids) { + public ProgramEndpointCall create(GenericCallData data) { return new ProgramEndpointCall(data, data.retrofit().create(ProgramService.class), - ProgramHandler.create(data.databaseAdapter()), UidsQuery.create(uids, 64)); + ProgramHandler.create(data.databaseAdapter()), EmptyQuery.create()); } }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java index 8cecd2eb24..04967fd1fe 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramHandler.java @@ -39,24 +39,27 @@ public class ProgramHandler extends IdentifiableHandlerImpl { private final ProgramRuleVariableHandler programRuleVariableHandler; - private final ProgramIndicatorHandler programIndicatorHandler; + private final GenericHandler programIndicatorHandler; private final ProgramRuleHandler programRuleHandler; private final GenericHandler programTrackedEntityAttributeHandler; + private final GenericHandler programSectionHandler; private final GenericHandler styleHandler; ProgramHandler(IdentifiableObjectStore programStore, ProgramRuleVariableHandler programRuleVariableHandler, - ProgramIndicatorHandler programIndicatorHandler, + GenericHandler programIndicatorHandler, ProgramRuleHandler programRuleHandler, GenericHandler programTrackedEntityAttributeHandler, + GenericHandler programSectionHandler, GenericHandler styleHandler) { super(programStore); this.programRuleVariableHandler = programRuleVariableHandler; this.programIndicatorHandler = programIndicatorHandler; this.programRuleHandler = programRuleHandler; this.programTrackedEntityAttributeHandler = programTrackedEntityAttributeHandler; + this.programSectionHandler = programSectionHandler; this.styleHandler = styleHandler; } @@ -67,6 +70,7 @@ public static ProgramHandler create(DatabaseAdapter databaseAdapter) { ProgramIndicatorHandler.create(databaseAdapter), ProgramRuleHandler.create(databaseAdapter), ProgramTrackedEntityAttributeHandler.create(databaseAdapter), + ProgramSectionHandler.create(databaseAdapter), ObjectStyleHandler.create(databaseAdapter) ); } @@ -75,9 +79,10 @@ public static ProgramHandler create(DatabaseAdapter databaseAdapter) { protected void afterObjectPersisted(Program program) { programTrackedEntityAttributeHandler.handleMany(program.programTrackedEntityAttributes(), new ProgramTrackedEntityAttributeModelBuilder()); - programIndicatorHandler.handleProgramIndicator(null, program.programIndicators()); + programIndicatorHandler.handleMany(program.programIndicators(), new ProgramIndicatorModelBuilder()); programRuleHandler.handleProgramRules(program.programRules()); programRuleVariableHandler.handleProgramRuleVariables(program.programRuleVariables()); + programSectionHandler.handleMany(program.programSections(), new ProgramSectionModelBuilder()); styleHandler.handle(program.style(), new ObjectStyleModelBuilder(program.uid(), ProgramModel.TABLE)); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicator.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicator.java index 03292450b1..888c6fd6a2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicator.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicator.java @@ -101,7 +101,7 @@ public abstract class ProgramIndicator extends BaseNameableObject { @Nullable @JsonProperty(PROGRAM) - public abstract Program program(); + public abstract ObjectWithUid program(); @Nullable @JsonProperty(LEGEND_SETS) @@ -125,7 +125,7 @@ public static ProgramIndicator create( @JsonProperty(FILTER) String filter, @JsonProperty(DECIMALS) Integer decimals, @JsonProperty(DELETED) Boolean deleted, - @JsonProperty(PROGRAM) Program program, + @JsonProperty(PROGRAM) ObjectWithUid program, @JsonProperty(LEGEND_SETS) List legendSets ) { return new AutoValue_ProgramIndicator( diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandler.java index 411697a7d8..f720127ffc 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandler.java @@ -28,6 +28,9 @@ package org.hisp.dhis.android.core.program; import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ModelBuilder; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.legendset.LegendSet; @@ -38,98 +41,65 @@ import org.hisp.dhis.android.core.legendset.ProgramIndicatorLegendSetLinkModelBuilder; import org.hisp.dhis.android.core.legendset.ProgramIndicatorLegendSetLinkStore; -import java.util.List; +import java.util.Collection; -import static org.hisp.dhis.android.core.utils.Utils.isDeleted; - -public class ProgramIndicatorHandler { - private final ProgramIndicatorStore programIndicatorStore; +public class ProgramIndicatorHandler extends IdentifiableHandlerImpl { private final ProgramStageSectionProgramIndicatorLinkStore programStageSectionProgramIndicatorLinkStore; private final ObjectWithoutUidStore programIndicatorLegendSetLinkStore; private final GenericHandler legendSetHandler; - ProgramIndicatorHandler(ProgramIndicatorStore programIndicatorStore, + ProgramIndicatorHandler(IdentifiableObjectStore programIndicatorStore, ProgramStageSectionProgramIndicatorLinkStore programStageSectionProgramIndicatorLinkStore, ObjectWithoutUidStore programIndicatorLegendSetLinkStore, GenericHandler legendSetHandler) { - this.programIndicatorStore = programIndicatorStore; + super(programIndicatorStore); this.programStageSectionProgramIndicatorLinkStore = programStageSectionProgramIndicatorLinkStore; this.programIndicatorLegendSetLinkStore = programIndicatorLegendSetLinkStore; this.legendSetHandler = legendSetHandler; } - void handleProgramIndicator(String programStageSectionUid, List programIndicators) { - if (programIndicators == null) { - return; - } - deleteOrPersistProgramIndicators(programStageSectionUid, programIndicators); + public static ProgramIndicatorHandler create(DatabaseAdapter databaseAdapter) { + return new ProgramIndicatorHandler( + ProgramIndicatorStore.create(databaseAdapter), + new ProgramStageSectionProgramIndicatorLinkStoreImpl(databaseAdapter), + ProgramIndicatorLegendSetLinkStore.create(databaseAdapter), + LegendSetHandler.create(databaseAdapter) + ); } - /** - * This method deletes or persists program indicators and the link table between program stage sections - * and program indicators - * - * @param programStageSectionUid - * @param programIndicators - */ - //TODO: Review if this is necessary with saving through sections and then saving through programs - //TODO: Morten should have implemented the link between program indicator and program stage section in March. - private void deleteOrPersistProgramIndicators(String programStageSectionUid, - List programIndicators) { - int size = programIndicators.size(); - - for (int i = 0; i < size; i++) { - ProgramIndicator programIndicator = programIndicators.get(i); + void handleManyWithProgramStageSection(Collection pCollection, ModelBuilder modelBuilder, String programStageSection) { + super.handleMany(pCollection, modelBuilder); - if (isDeleted(programIndicator)) { - programIndicatorStore.delete(programIndicator.uid()); - } else { - int updatedRow = programIndicatorStore.update( - programIndicator.uid(), programIndicator.code(), - programIndicator.name(), programIndicator.displayName(), programIndicator.created(), - programIndicator.lastUpdated(), programIndicator.shortName(), - programIndicator.displayShortName(), programIndicator.description(), - programIndicator.displayDescription(), programIndicator.displayInForm(), - programIndicator.expression(), programIndicator.dimensionItem(), programIndicator.filter(), - programIndicator.decimals(), programIndicator.program().uid(), programIndicator.uid() - ); + updateProgramStageSectionProgramIndicatorLink(pCollection, programStageSection); + } - if (updatedRow <= 0) { - programIndicatorStore.insert( - programIndicator.uid(), programIndicator.code(), - programIndicator.name(), programIndicator.displayName(), - programIndicator.created(), programIndicator.lastUpdated(), - programIndicator.shortName(), programIndicator.displayShortName(), - programIndicator.description(), - programIndicator.displayDescription(), programIndicator.displayInForm(), - programIndicator.expression(), programIndicator.dimensionItem(), - programIndicator.filter(), - programIndicator.decimals(), programIndicator.program().uid() - ); - } - } - if (programStageSectionUid == null) { - handleLegendSet(programIndicator); - } else { - // since this is many-to-many relationship we need to update link table + private void updateProgramStageSectionProgramIndicatorLink(Collection pCollection, + String programStageSection) { + for(ProgramIndicator programIndicator : pCollection) { + int updatedLink = programStageSectionProgramIndicatorLinkStore.update( + programStageSection, programIndicator.uid(), + programStageSection, programIndicator.uid() + ); - int updatedLink = programStageSectionProgramIndicatorLinkStore.update( - programStageSectionUid, programIndicator.uid(), - programStageSectionUid, programIndicator.uid() + if (updatedLink <= 0) { + programStageSectionProgramIndicatorLinkStore.insert( + programStageSection, programIndicator.uid() ); - - if (updatedLink <= 0) { - programStageSectionProgramIndicatorLinkStore.insert( - programStageSectionUid, programIndicator.uid() - ); - } } } } + @Override + protected void afterObjectPersisted(ProgramIndicator programIndicator) { + if (programIndicator.legendSets() != null && programIndicator.legendSets().size() > 0) { + handleLegendSet(programIndicator); + } + } + private void handleLegendSet(ProgramIndicator programIndicator) { legendSetHandler.handleMany(programIndicator.legendSets(), new LegendSetModelBuilder()); @@ -140,13 +110,4 @@ private void handleLegendSet(ProgramIndicator programIndicator) { programIndicatorLegendSetLinkStore.updateOrInsertWhere(builder.buildModel(legendSet)); } } - - public static ProgramIndicatorHandler create(DatabaseAdapter databaseAdapter) { - return new ProgramIndicatorHandler( - new ProgramIndicatorStoreImpl(databaseAdapter), - new ProgramStageSectionProgramIndicatorLinkStoreImpl(databaseAdapter), - ProgramIndicatorLegendSetLinkStore.create(databaseAdapter), - LegendSetHandler.create(databaseAdapter) - ); - } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorModel.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorModel.java index fbaa2a142e..8b228792b5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorModel.java @@ -29,6 +29,7 @@ package org.hisp.dhis.android.core.program; import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -36,6 +37,10 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseNameableObjectModel; +import org.hisp.dhis.android.core.common.CursorModelFactory; +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; @AutoValue public abstract class ProgramIndicatorModel extends BaseNameableObjectModel { @@ -48,6 +53,12 @@ public static class Columns extends BaseNameableObjectModel.Columns { public static final String FILTER = "filter"; public static final String DECIMALS = "decimals"; public static final String PROGRAM = "program"; + + @Override + public String[] all() { + return Utils.appendInNewArray(super.all(), + DISPLAY_IN_FORM, EXPRESSION, DIMENSION_ITEM, FILTER, DECIMALS, PROGRAM); + } } @NonNull @@ -60,6 +71,15 @@ public static ProgramIndicatorModel create(Cursor cursor) { return AutoValue_ProgramIndicatorModel.createFromCursor(cursor); } + public static final CursorModelFactory factory + = new CursorModelFactory() { + @Override + public ProgramIndicatorModel fromCursor(Cursor cursor) { + return create(cursor); + } + }; + + @Nullable @ColumnName(Columns.DISPLAY_IN_FORM) public abstract Boolean displayInForm(); @@ -105,6 +125,17 @@ public static abstract class Builder extends BaseNameableObjectModel.Builder { + + @Override + public ProgramIndicatorModel buildModel(ProgramIndicator programIndicator) { + return ProgramIndicatorModel.builder() + .uid(programIndicator.uid()) + .code(programIndicator.code()) + .name(programIndicator.name()) + .displayName(programIndicator.displayName()) + .created(programIndicator.created()) + .lastUpdated(programIndicator.lastUpdated()) + .shortName(programIndicator.shortName()) + .displayShortName(programIndicator.displayShortName()) + .description(programIndicator.description()) + .displayDescription(programIndicator.displayDescription()) + .displayInForm(programIndicator.displayInForm()) + .expression(programIndicator.expression()) + .dimensionItem(programIndicator.dimensionItem()) + .filter(programIndicator.filter()) + .decimals(programIndicator.decimals()) + .program(programIndicator.program().uid()) + .build(); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorStore.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorStore.java index 0cdde6fa42..1f10cb6cc2 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorStore.java @@ -28,30 +28,16 @@ package org.hisp.dhis.android.core.program; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.common.DeletableStore; +public final class ProgramIndicatorStore { -import java.util.Date; + private ProgramIndicatorStore() {} -public interface ProgramIndicatorStore extends DeletableStore { - long insert(@NonNull String uid, @Nullable String code, @NonNull String name, - @Nullable String displayName, @NonNull Date created, @NonNull Date lastUpdated, - @Nullable String shortName, @Nullable String displayShortName, - @Nullable String description, @Nullable String displayDescription, - @Nullable Boolean displayInForm, @Nullable String expression, - @Nullable String dimensionItem, @Nullable String filter, - @Nullable Integer decimals, @Nullable String program); - - int update(@NonNull String uid, @Nullable String code, @NonNull String name, - @Nullable String displayName, @NonNull Date created, @NonNull Date lastUpdated, - @Nullable String shortName, @Nullable String displayShortName, - @Nullable String description, @Nullable String displayDescription, - @Nullable Boolean displayInForm, @Nullable String expression, - @Nullable String dimensionItem, @Nullable String filter, - @Nullable Integer decimals, @Nullable String program, @NonNull String whereProgramIndicatorUid - ); - - int delete(String uid); + public static IdentifiableObjectStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.identifiableStore(databaseAdapter, + ProgramIndicatorModel.TABLE, new ProgramIndicatorModel.Columns().all()); + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorStoreImpl.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorStoreImpl.java deleted file mode 100644 index 2ec1a14753..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramIndicatorStoreImpl.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2017, University of Oslo - * - * All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.hisp.dhis.android.core.program; - -import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; -import static org.hisp.dhis.android.core.utils.Utils.isNull; - -import android.database.sqlite.SQLiteStatement; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import org.hisp.dhis.android.core.data.database.DatabaseAdapter; - -import java.util.Date; - -@SuppressWarnings({ - "PMD.AvoidDuplicateLiterals" -}) -public class ProgramIndicatorStoreImpl implements ProgramIndicatorStore { - private static final String INSERT_STATEMENT = "INSERT INTO " + ProgramIndicatorModel.TABLE + " (" + - ProgramIndicatorModel.Columns.UID + ", " + - ProgramIndicatorModel.Columns.CODE + ", " + - ProgramIndicatorModel.Columns.NAME + ", " + - ProgramIndicatorModel.Columns.DISPLAY_NAME + ", " + - ProgramIndicatorModel.Columns.CREATED + ", " + - ProgramIndicatorModel.Columns.LAST_UPDATED + ", " + - ProgramIndicatorModel.Columns.SHORT_NAME + ", " + - ProgramIndicatorModel.Columns.DISPLAY_SHORT_NAME + ", " + - ProgramIndicatorModel.Columns.DESCRIPTION + ", " + - ProgramIndicatorModel.Columns.DISPLAY_DESCRIPTION + ", " + - ProgramIndicatorModel.Columns.DISPLAY_IN_FORM + ", " + - ProgramIndicatorModel.Columns.EXPRESSION + ", " + - ProgramIndicatorModel.Columns.DIMENSION_ITEM + ", " + - ProgramIndicatorModel.Columns.FILTER + ", " + - ProgramIndicatorModel.Columns.DECIMALS + ", " + - ProgramIndicatorModel.Columns.PROGRAM + ") " - + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; - - private static final String UPDATE_STATEMENT = "UPDATE " + ProgramIndicatorModel.TABLE + " SET " + - ProgramIndicatorModel.Columns.UID + " =?, " + - ProgramIndicatorModel.Columns.CODE + " =?, " + - ProgramIndicatorModel.Columns.NAME + " =?, " + - ProgramIndicatorModel.Columns.DISPLAY_NAME + " =?, " + - ProgramIndicatorModel.Columns.CREATED + " =?, " + - ProgramIndicatorModel.Columns.LAST_UPDATED + " =?, " + - ProgramIndicatorModel.Columns.SHORT_NAME + " =?, " + - ProgramIndicatorModel.Columns.DISPLAY_SHORT_NAME + " =?, " + - ProgramIndicatorModel.Columns.DESCRIPTION + " =?, " + - ProgramIndicatorModel.Columns.DISPLAY_DESCRIPTION + " =?, " + - ProgramIndicatorModel.Columns.DISPLAY_IN_FORM + " =?, " + - ProgramIndicatorModel.Columns.EXPRESSION + " =?, " + - ProgramIndicatorModel.Columns.DIMENSION_ITEM + " =?, " + - ProgramIndicatorModel.Columns.FILTER + " =?, " + - ProgramIndicatorModel.Columns.DECIMALS + " =?, " + - ProgramIndicatorModel.Columns.PROGRAM + " =? " + - " WHERE " + ProgramIndicatorModel.Columns.UID + " =?;"; - - private static final String DELETE_STATEMENT = "DELETE FROM " + ProgramIndicatorModel.TABLE + - " WHERE " + ProgramIndicatorModel.Columns.UID + " =?;"; - - private final SQLiteStatement insertRowStatement; - private final SQLiteStatement updateStatement; - private final SQLiteStatement deleteStatement; - - private final DatabaseAdapter databaseAdapter; - - public ProgramIndicatorStoreImpl(DatabaseAdapter databaseAdapter) { - this.databaseAdapter = databaseAdapter; - this.insertRowStatement = databaseAdapter.compileStatement(INSERT_STATEMENT); - this.updateStatement = databaseAdapter.compileStatement(UPDATE_STATEMENT); - this.deleteStatement = databaseAdapter.compileStatement(DELETE_STATEMENT); - } - - @Override - public long insert(@NonNull String uid, @Nullable String code, @NonNull String name, - @Nullable String displayName, @NonNull Date created, - @NonNull Date lastUpdated, @Nullable String shortName, - @Nullable String displayShortName, @Nullable String description, - @Nullable String displayDescription, @Nullable Boolean displayInForm, - @Nullable String expression, @Nullable String dimensionItem, - @Nullable String filter, @Nullable Integer decimals, - @Nullable String program) { - isNull(uid); - isNull(program); - bindArguments(insertRowStatement, uid, code, name, displayName, created, lastUpdated, shortName, - displayShortName, description, displayDescription, displayInForm, expression, dimensionItem, - filter, decimals, program); - - // execute and clear bindings - Long insert = databaseAdapter.executeInsert(ProgramIndicatorModel.TABLE, insertRowStatement); - insertRowStatement.clearBindings(); - return insert; - } - - @Override - public int update(@NonNull String uid, @Nullable String code, @NonNull String name, @Nullable String displayName, - @NonNull Date created, @NonNull Date lastUpdated, @Nullable String shortName, - @Nullable String displayShortName, @Nullable String description, - @Nullable String displayDescription, @Nullable Boolean displayInForm, - @Nullable String expression, @Nullable String dimensionItem, @Nullable String filter, - @Nullable Integer decimals, @Nullable String program, - @NonNull String whereProgramIndicatorUid) { - isNull(uid); - isNull(program); - isNull(whereProgramIndicatorUid); - bindArguments(updateStatement, uid, code, name, displayName, created, lastUpdated, shortName, displayShortName, - description, displayDescription, displayInForm, expression, dimensionItem, filter, decimals, program); - - // bind the where argument - sqLiteBind(updateStatement, 17, whereProgramIndicatorUid); - - // execute and clear bindings - int update = databaseAdapter.executeUpdateDelete(ProgramIndicatorModel.TABLE, updateStatement); - updateStatement.clearBindings(); - return update; - } - - @Override - public int delete(String uid) { - isNull(uid); - // bind the where argument - sqLiteBind(deleteStatement, 1, uid); - - // execute and clear bindings - int delete = databaseAdapter.executeUpdateDelete(ProgramIndicatorModel.TABLE, deleteStatement); - deleteStatement.clearBindings(); - return delete; - } - - private void bindArguments(@NonNull SQLiteStatement sqLiteStatement, @NonNull String uid, @Nullable String code, - @NonNull String name, @Nullable String displayName, @NonNull Date created, - @NonNull Date lastUpdated, @Nullable String shortName, - @Nullable String displayShortName, @Nullable String description, - @Nullable String displayDescription, @Nullable Boolean displayInForm, - @Nullable String expression, @Nullable String dimensionItem, - @Nullable String filter, @Nullable Integer decimals, - @Nullable String program) { - sqLiteBind(sqLiteStatement, 1, uid); - sqLiteBind(sqLiteStatement, 2, code); - sqLiteBind(sqLiteStatement, 3, name); - sqLiteBind(sqLiteStatement, 4, displayName); - sqLiteBind(sqLiteStatement, 5, created); - sqLiteBind(sqLiteStatement, 6, lastUpdated); - sqLiteBind(sqLiteStatement, 7, shortName); - sqLiteBind(sqLiteStatement, 8, displayShortName); - sqLiteBind(sqLiteStatement, 9, description); - sqLiteBind(sqLiteStatement, 10, displayDescription); - sqLiteBind(sqLiteStatement, 11, displayInForm); - sqLiteBind(sqLiteStatement, 12, expression); - sqLiteBind(sqLiteStatement, 13, dimensionItem); - sqLiteBind(sqLiteStatement, 14, filter); - sqLiteBind(sqLiteStatement, 15, decimals); - sqLiteBind(sqLiteStatement, 16, program); - } - - @Override - public int delete() { - return databaseAdapter.delete(ProgramIndicatorModel.TABLE); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentCall.java index 435b3a389c..6313b8041d 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentCall.java @@ -45,27 +45,24 @@ import retrofit2.Response; -public class ProgramParentCall extends TransactionalCall { +public class ProgramParentCall extends TransactionalCall> { private final GenericCallData genericCallData; - private final UidsCallFactory programCallFactory; - private final Set programUids; + private final SimpleCallFactory> programCallFactory; private final UidsCallFactory programStageCallFactory; private final UidsCallFactory trackedEntityTypeCallFactory; private final SimpleCallFactory> relationshipTypeCallFactory; private final UidsCallFactory optionSetCallFactory; ProgramParentCall(GenericCallData genericCallData, - UidsCallFactory programCallFactory, + SimpleCallFactory> programCallFactory, UidsCallFactory programStageCallFactory, UidsCallFactory trackedEntityTypeCallFactory, SimpleCallFactory> relationshipTypeCallFactory, - UidsCallFactory optionSetCallFactory, - Set programUids) { + UidsCallFactory optionSetCallFactory) { super(genericCallData.databaseAdapter()); this.genericCallData = genericCallData; this.programCallFactory = programCallFactory; - this.programUids = programUids; this.programStageCallFactory = programStageCallFactory; this.trackedEntityTypeCallFactory = trackedEntityTypeCallFactory; this.relationshipTypeCallFactory = relationshipTypeCallFactory; @@ -73,8 +70,8 @@ public class ProgramParentCall extends TransactionalCall { } @Override - public Response callBody() throws Exception { - Call>> programEndpointCall = programCallFactory.create(genericCallData, programUids); + public Response> callBody() throws Exception { + Call>> programEndpointCall = programCallFactory.create(genericCallData); Response> programResponse = programEndpointCall.call(); List programs = programResponse.body().items(); @@ -89,24 +86,21 @@ public Response callBody() throws Exception { List programStages = programStageResponse.body().items(); Set optionSetUids = ProgramParentUidsHelper.getAssignedOptionSetUids(programs, programStages); - return optionSetCallFactory.create(genericCallData, optionSetUids).call(); - } + optionSetCallFactory.create(genericCallData, optionSetUids).call(); - public interface Factory { - Call create(GenericCallData genericCallData, Set uids); + return programResponse; } - public static final Factory FACTORY = new Factory() { + public static final SimpleCallFactory> FACTORY = new SimpleCallFactory>() { @Override - public Call create(GenericCallData genericCallData, Set programUids) { + public Call>> create(GenericCallData genericCallData) { return new ProgramParentCall( genericCallData, ProgramEndpointCall.FACTORY, ProgramStageEndpointCall.FACTORY, TrackedEntityTypeCall.FACTORY, RelationshipTypeEndpointCall.FACTORY, - OptionSetCall.FACTORY, - programUids); + OptionSetCall.FACTORY); } }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentUidsHelper.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentUidsHelper.java index 618ff1688a..c71fe11e46 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentUidsHelper.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramParentUidsHelper.java @@ -27,7 +27,6 @@ */ package org.hisp.dhis.android.core.program; -import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.ObjectWithUid; import java.util.HashSet; @@ -118,16 +117,4 @@ static Set getAssignedProgramStageUids(List programs) { return programStageUids; } - - public static Set getProgramUidsWithDataReadAccess(List programsWithAccess) { - Set programUids = new HashSet<>(); - for (Program program: programsWithAccess) { - Access access = program.access(); - if (access != null && access.data().read()) { - programUids.add(program.uid()); - } - } - - return programUids; - } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSection.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSection.java new file mode 100644 index 0000000000..a2880ab5b9 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSection.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import android.support.annotation.Nullable; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.ObjectStyle; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; +import org.hisp.dhis.android.core.data.api.NestedField; + +import java.util.Date; +import java.util.List; + +@AutoValue +public abstract class ProgramSection extends BaseIdentifiableObject { + private static final String DESCRIPTION = "description"; + private static final String PROGRAM = "program"; + private static final String ATTRIBUTES = "programTrackedEntityAttribute"; + private static final String SORT_ORDER = "sortOrder"; + private static final String STYLE = "style"; + private static final String FORM_NAME = "formName"; + + private static final Field uid = Field.create(UID); + private static final Field code = Field.create(CODE); + private static final Field name = Field.create(NAME); + private static final Field displayName = Field.create(DISPLAY_NAME); + private static final Field created = Field.create(CREATED); + private static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field deleted = Field.create(DELETED); + + private static final Field description = Field.create(DESCRIPTION); + private static final NestedField program = NestedField.create(PROGRAM); + private static final NestedField attributes = + NestedField.create(ATTRIBUTES); + private static final Field sortOrder = Field.create(SORT_ORDER); + private static final NestedField style = NestedField.create(STYLE); + private static final Field formName = Field.create(FORM_NAME); + + static final Fields allFields = Fields.builder().fields( + uid, code, name, displayName, created, lastUpdated, deleted, description, program.with(ObjectWithUid.uid), + sortOrder, formName, attributes.with(ObjectWithUid.uid), style.with(ObjectStyle.allFields)).build(); + + @Nullable + @JsonProperty(DESCRIPTION) + public abstract String description(); + + @Nullable + @JsonProperty(PROGRAM) + public abstract ObjectWithUid program(); + + String programUid() { + ObjectWithUid program = program(); + return program == null ? null : program.uid(); + } + + @Nullable + @JsonProperty(ATTRIBUTES) + public abstract List attributes(); + + @Nullable + @JsonProperty(SORT_ORDER) + public abstract Integer sortOrder(); + + @Nullable + @JsonProperty(STYLE) + public abstract ObjectStyle style(); + + @Nullable + @JsonProperty(FORM_NAME) + public abstract String formName(); + + @JsonCreator + public static ProgramSection create( + @JsonProperty(UID) String uid, + @JsonProperty(CODE) String code, + @JsonProperty(NAME) String name, + @JsonProperty(DISPLAY_NAME) String displayName, + @JsonProperty(CREATED) Date created, + @JsonProperty(LAST_UPDATED) Date lastUpdated, + + @JsonProperty(DESCRIPTION) String description, + @JsonProperty(PROGRAM) ObjectWithUid program, + @JsonProperty(ATTRIBUTES) List attributes, + @JsonProperty(SORT_ORDER) Integer sortOrder, + @JsonProperty(STYLE) ObjectStyle style, + @JsonProperty(FORM_NAME) String formName, + @JsonProperty(DELETED) Boolean deleted) { + + return new AutoValue_ProgramSection( + uid, code, name, displayName, created, lastUpdated, deleted, description, program, + attributes, sortOrder, style, formName + ); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModel.java new file mode 100644 index 0000000000..d83f1d57b2 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModel.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.program; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.gabrielittner.auto.value.cursor.ColumnName; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseModel; +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + +@AutoValue +public abstract class ProgramSectionAttributeLinkModel extends BaseModel { + public static final String TABLE = "ProgramSectionAttributeLink"; + + public static class Columns extends BaseModel.Columns { + public static final String PROGRAM_SECTION = "programSection"; + public static final String ATTRIBUTE = "attribute"; + + @Override + public String[] all() { + return Utils.appendInNewArray(super.all(), PROGRAM_SECTION, ATTRIBUTE); + } + + @Override + public String[] whereUpdate() { + return new String[]{PROGRAM_SECTION, ATTRIBUTE}; + } + } + + public static ProgramSectionAttributeLinkModel create(Cursor cursor) { + return AutoValue_ProgramSectionAttributeLinkModel.createFromCursor(cursor); + } + + public static Builder builder() { + return new $$AutoValue_ProgramSectionAttributeLinkModel.Builder(); + } + + @Nullable + @ColumnName(Columns.PROGRAM_SECTION) + public abstract String programSection(); + + @Nullable + @ColumnName(Columns.ATTRIBUTE) + public abstract String attribute(); + + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 1, programSection()); + sqLiteBind(sqLiteStatement, 2, attribute()); + } + + @Override + public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { + sqLiteBind(sqLiteStatement, 3, programSection()); + sqLiteBind(sqLiteStatement, 4, attribute()); + } + + @AutoValue.Builder + public static abstract class Builder extends BaseModel.Builder { + public abstract Builder programSection(String programSection); + + public abstract Builder attribute(String attribute); + + public abstract ProgramSectionAttributeLinkModel build(); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelBuilder.java similarity index 54% rename from core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java rename to core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelBuilder.java index 3c355c67ff..9f9a71d42f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramAccessEndpointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelBuilder.java @@ -28,38 +28,23 @@ package org.hisp.dhis.android.core.program; -import org.hisp.dhis.android.core.common.GenericCallData; -import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.common.SimpleCallFactory; -import org.hisp.dhis.android.core.common.SyncCall; -import org.hisp.dhis.android.core.resource.ResourceModel; +import org.hisp.dhis.android.core.common.ModelBuilder; +import org.hisp.dhis.android.core.common.ObjectWithUid; -import retrofit2.Response; +public class ProgramSectionAttributeLinkModelBuilder + extends ModelBuilder { -public final class ProgramAccessEndpointCall extends SyncCall>> { - private final GenericCallData data; - private final ProgramService programService; + private final ProgramSectionAttributeLinkModel.Builder builder; - private ProgramAccessEndpointCall(GenericCallData data, ProgramService programService) { - this.data = data; - this.programService = programService; + ProgramSectionAttributeLinkModelBuilder(ProgramSection programSection) { + this.builder = ProgramSectionAttributeLinkModel.builder() + .programSection(programSection.uid()); } @Override - public Response> call() throws Exception { - super.setExecuted(); - String lastUpdated = data.resourceHandler().getLastUpdated(ResourceModel.Type.PROGRAM); - return programService.getProgramsForAccess(Program.uidAndAccessRead, Program.lastUpdated.gt(lastUpdated), - Boolean.FALSE).execute(); + public ProgramSectionAttributeLinkModel buildModel(ObjectWithUid attribute) { + return builder + .attribute(attribute.uid()) + .build(); } - - public static final SimpleCallFactory> FACTORY - = new SimpleCallFactory>() { - - @Override - public ProgramAccessEndpointCall create(GenericCallData genericCallData) { - return new ProgramAccessEndpointCall(genericCallData, - genericCallData.retrofit().create(ProgramService.class)); - } - }; } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkStore.java new file mode 100644 index 0000000000..25ec6edcce --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkStore.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public final class ProgramSectionAttributeLinkStore { + + private ProgramSectionAttributeLinkStore() {} + + public static ObjectWithoutUidStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.objectWithoutUidStore(databaseAdapter, ProgramSectionAttributeLinkModel.TABLE, + new ProgramSectionAttributeLinkModel.Columns()); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionHandler.java new file mode 100644 index 0000000000..ffa4e9e958 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionHandler.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectStyle; +import org.hisp.dhis.android.core.common.ObjectStyleHandler; +import org.hisp.dhis.android.core.common.ObjectStyleModel; +import org.hisp.dhis.android.core.common.ObjectStyleModelBuilder; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +import java.util.List; + +public class ProgramSectionHandler extends IdentifiableHandlerImpl { + private final ObjectWithoutUidStore programSectionAttributeLinkStore; + private final GenericHandler styleHandler; + + ProgramSectionHandler(IdentifiableObjectStore programSectionStore, + ObjectWithoutUidStore programSectionAttributeLinkStore, + GenericHandler styleHandler) { + super(programSectionStore); + this.programSectionAttributeLinkStore = programSectionAttributeLinkStore; + this.styleHandler = styleHandler; + } + + public static ProgramSectionHandler create(DatabaseAdapter databaseAdapter) { + return new ProgramSectionHandler( + ProgramSectionStore.create(databaseAdapter), + ProgramSectionAttributeLinkStore.create(databaseAdapter), + ObjectStyleHandler.create(databaseAdapter) + ); + } + + @Override + protected void afterObjectPersisted(ProgramSection programSection) { + saveProgramSectionAttributeLink(programSection); + styleHandler.handle(programSection.style(), new ObjectStyleModelBuilder(programSection.uid(), + ProgramSectionModel.TABLE)); + } + + private void saveProgramSectionAttributeLink(ProgramSection programSection) { + List attributes = programSection.attributes(); + if (attributes != null) { + ProgramSectionAttributeLinkModelBuilder builder = + new ProgramSectionAttributeLinkModelBuilder(programSection); + for (ObjectWithUid attribute : attributes) { + programSectionAttributeLinkStore.updateOrInsertWhere(builder.buildModel(attribute)); + } + } + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionModel.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionModel.java new file mode 100644 index 0000000000..a21a380074 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionModel.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import android.database.Cursor; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +import com.gabrielittner.auto.value.cursor.ColumnName; +import com.google.auto.value.AutoValue; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObjectModel; +import org.hisp.dhis.android.core.utils.Utils; + +import static org.hisp.dhis.android.core.utils.StoreUtils.sqLiteBind; + +@AutoValue +public abstract class ProgramSectionModel extends BaseIdentifiableObjectModel { + + public static final String TABLE = "ProgramSection"; + + public static class Columns extends BaseIdentifiableObjectModel.Columns { + public static final String DESCRIPTION = "description"; + public static final String PROGRAM = "program"; + public static final String SORT_ORDER = "sortOrder"; + public static final String FORM_NAME = "formName"; + + @Override + public String[] all() { + return Utils.appendInNewArray(super.all(), DESCRIPTION, PROGRAM, SORT_ORDER, FORM_NAME); + } + } + + public static ProgramSectionModel create(Cursor cursor) { + return AutoValue_ProgramSectionModel.createFromCursor(cursor); + } + + public static Builder builder() { + return new $$AutoValue_ProgramSectionModel.Builder(); + } + + @Nullable + @ColumnName(Columns.DESCRIPTION) + public abstract String description(); + + @Nullable + @ColumnName(Columns.PROGRAM) + public abstract String program(); + + @Nullable + @ColumnName(Columns.SORT_ORDER) + public abstract Integer sortOrder(); + + @Nullable + @ColumnName(Columns.FORM_NAME) + public abstract String formName(); + + @Override + public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { + super.bindToStatement(sqLiteStatement); + sqLiteBind(sqLiteStatement, 7, description()); + sqLiteBind(sqLiteStatement, 8, program()); + sqLiteBind(sqLiteStatement, 9, sortOrder()); + sqLiteBind(sqLiteStatement, 10, formName()); + } + + @AutoValue.Builder + public static abstract class Builder extends BaseIdentifiableObjectModel.Builder { + + public abstract Builder description(@Nullable String description); + + public abstract Builder program(@Nullable String program); + + public abstract Builder sortOrder(@Nullable Integer sortOrder); + + public abstract Builder formName(@Nullable String formName); + + public abstract ProgramSectionModel build(); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionModelBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionModelBuilder.java new file mode 100644 index 0000000000..ed7aac36fb --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionModelBuilder.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.ModelBuilder; + +public class ProgramSectionModelBuilder extends ModelBuilder { + + @Override + public ProgramSectionModel buildModel(ProgramSection programSection) { + return ProgramSectionModel.builder() + .uid(programSection.uid()) + .code(programSection.code()) + .name(programSection.name()) + .displayName(programSection.displayName()) + .created(programSection.created()) + .lastUpdated(programSection.lastUpdated()) + .description(programSection.description()) + .program(programSection.programUid()) + .sortOrder(programSection.sortOrder()) + .formName(programSection.formName()) + .build(); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionStore.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionStore.java new file mode 100644 index 0000000000..1f59914bb3 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramSectionStore.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.StoreFactory; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +public final class ProgramSectionStore { + + private ProgramSectionStore() {} + + public static IdentifiableObjectStore create(DatabaseAdapter databaseAdapter) { + return StoreFactory.identifiableStore(databaseAdapter, ProgramSectionModel.TABLE, + new ProgramSectionModel.Columns().all()); + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java index d781a92613..1f8e09190f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramService.java @@ -41,12 +41,6 @@ public interface ProgramService { @GET("programs") Call> getPrograms(@Query("fields") @Which Fields fields, @Query("filter") @Where Filter lastUpdated, - @Query("filter") @Where Filter uids, + @Query("filter") @Where String accessDataReadFilter, @Query("paging") Boolean paging); - - @GET("programs") - Call> getProgramsForAccess(@Query("fields") @Which Fields fields, - @Query("filter") @Where Filter lastUpdated, - @Query("paging") Boolean paging); - } diff --git a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandler.java b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandler.java index 1087eb1a33..a29c6f760a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandler.java @@ -61,6 +61,8 @@ public void handleProgramStageSection(String programStageUid, List orgUnits; private final int pageLimit; + private final OuMode ouMode; @Nullable private final Set uIds; - public TeiQuery(boolean paging, int page, int pageSize, - String orgUnit, int pageLimit) { + public TeiQuery(boolean paging, int page, int pageSize, Set orgUnits, int pageLimit, OuMode ouMode) { this.paging = paging; this.page = page; this.pageSize = pageSize; - this.orgUnit = orgUnit; + this.orgUnits = orgUnits; this.pageLimit = pageLimit; + this.ouMode = ouMode; uIds = null; } public TeiQuery(boolean paging, int page, int pageSize, - String orgUnit, @Nullable Set uIds, int pageLimit) { + Set orgUnits, @Nullable Set uIds, int pageLimit, OuMode ouMode) { this.paging = paging; this.page = page; this.pageSize = pageSize; - this.orgUnit = orgUnit; + this.orgUnits = orgUnits; this.uIds = uIds; this.pageLimit = pageLimit; + this.ouMode = ouMode; } @Nullable @@ -54,8 +58,12 @@ public boolean isPaging() { return paging; } - public String getOrgUnit() { - return orgUnit; + public OuMode getOuMode() { + return ouMode; + } + + public Set getOrgUnits() { + return orgUnits; } public int getPageLimit() { @@ -66,8 +74,9 @@ public static class Builder { private int page = 1; private int pageSize = 50; private boolean paging; - private String orgUnit; - int pageLimit; + private Set orgUnits; + int pageLimit = 50; + OuMode ouMode = OuMode.SELECTED; private Set uIds = new HashSet<>(); @@ -93,8 +102,8 @@ public TeiQuery.Builder withPageSize(int pageSize) { return this; } - public TeiQuery.Builder withOrgUnit(String orgUnit) { - this.orgUnit = orgUnit; + public TeiQuery.Builder withOrgUnits(Set orgUnits) { + this.orgUnits = orgUnits; return this; } @@ -108,14 +117,18 @@ public TeiQuery.Builder withPageLimit(int pageLimit) { return this; } + public TeiQuery.Builder withOuMode(OuMode ouMode) { + this.ouMode = ouMode; + return this; + } + public TeiQuery build() { if (pageLimit > pageSize) { throw new IllegalArgumentException( "pageLimit can not be more greater than pageSize"); } - return new TeiQuery(paging, page, pageSize, - orgUnit, uIds, pageLimit); + return new TeiQuery(paging, page, pageSize, orgUnits, uIds, pageLimit, ouMode); } } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java index 7e530934d0..3310d1e333 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TeisEndPointCall.java @@ -7,14 +7,8 @@ import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.SyncCall; -import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.database.Transaction; -import org.hisp.dhis.android.core.enrollment.Enrollment; -import org.hisp.dhis.android.core.enrollment.note.Note; -import org.hisp.dhis.android.core.event.Event; -import org.hisp.dhis.android.core.relationship.Relationship; -import org.hisp.dhis.android.core.resource.ResourceHandler; -import org.hisp.dhis.android.core.resource.ResourceModel; +import org.hisp.dhis.android.core.utils.Utils; import java.util.List; @@ -26,111 +20,52 @@ public final class TeisEndPointCall extends SyncCall> call() throws Exception { super.setExecuted(); - String lastSyncedTEIs = resourceHandler.getLastUpdated(ResourceModel.Type.TRACKED_ENTITY_INSTANCE); + Integer teisToRequest = Math.min(trackerQuery.getPageLimit(), trackerQuery.getPageSize()); + Response> response = trackedEntityInstanceService.getTrackedEntityInstances( + Utils.joinCollectionWithSeparator(trackerQuery.getOrgUnits(), ";"), + trackerQuery.getOuMode().name(), TrackedEntityInstance.allFields, Boolean.TRUE, + trackerQuery.getPage(), teisToRequest) + .execute(); - Response> response; - - response = trackedEntityInstanceService.getTEIs(trackerQuery.getOrgUnit(), - TrackedEntityInstance.lastUpdated.gt(lastSyncedTEIs), fields(), - Boolean.TRUE, trackerQuery.getPage(), trackerQuery.getPageSize()).execute(); - - if (response.isSuccessful() && response.body().items() != null - && response.body().items().size()>0) { + if (response.isSuccessful() && !response.body().items().isEmpty()) { List trackedEntityInstances = response.body().items(); - int size = trackedEntityInstances.size(); - - if (trackerQuery.getPageLimit() > 0) { - size = Math.min(size, trackerQuery.getPageLimit()); - } - - for (int i = 0; i < size; i++) { - Transaction transaction = genericCallData.databaseAdapter().beginNewTransaction(); - TrackedEntityInstance trackedEntityInstance = trackedEntityInstances.get(i); - try { - trackedEntityInstanceHandler.handle(trackedEntityInstance); - transaction.setSuccessful(); - } catch (SQLiteConstraintException sql) { - /* - This catch is necessary to ignore events with bad foreign keys exception - More info: If the foreign key have the flag - DEFERRABLE INITIALLY DEFERRED this exception will be throw in transaction - .end() - And the rollback will be executed only when the database is closed. - It is a reported as unfixed bug: https://issuetracker.google - .com/issues/37001653 - */ - Log.d(this.getClass().getSimpleName(), sql.getMessage()); - } finally { - transaction.end(); - } - } - - resourceHandler.handleResource(ResourceModel.Type.TRACKED_ENTITY_INSTANCE, - genericCallData.serverDate()); + persistTeis(trackedEntityInstances); } return response; } - private Fields fields() { - return Fields.builder().fields( - TrackedEntityInstance.uid, TrackedEntityInstance.created, - TrackedEntityInstance.lastUpdated, - TrackedEntityInstance.organisationUnit, - TrackedEntityInstance.trackedEntityType, - TrackedEntityInstance.deleted, - TrackedEntityInstance.relationships.with(Relationship.allFields), - TrackedEntityInstance.trackedEntityAttributeValues.with( - TrackedEntityAttributeValue.trackedEntityAttribute, - TrackedEntityAttributeValue.value, - TrackedEntityAttributeValue.created, - TrackedEntityAttributeValue.lastUpdated), - TrackedEntityInstance.enrollment.with( - Enrollment.uid, Enrollment.created, Enrollment.lastUpdated, - Enrollment.coordinate, - Enrollment.dateOfEnrollment, Enrollment.dateOfIncident, - Enrollment.enrollmentStatus, - Enrollment.followUp, Enrollment.program, Enrollment.organisationUnit, - Enrollment.trackedEntityInstance, - Enrollment.deleted, - Enrollment.events.with( - Event.attributeCategoryOptions, Event.attributeOptionCombo, - Event.uid, Event.created, Event.lastUpdated, Event.completeDate, - Event.coordinates, - Event.dueDate, Event.enrollment, Event.eventDate, Event.eventStatus, - Event.organisationUnit, Event.program, Event.programStage, - Event.deleted, - Event.trackedEntityDataValues.with( - TrackedEntityDataValue.created, - TrackedEntityDataValue.lastUpdated, - TrackedEntityDataValue.dataElement, - TrackedEntityDataValue.providedElsewhere, - TrackedEntityDataValue.storedBy, - TrackedEntityDataValue.value - ) - ), - Enrollment.notes.with(Note.allFields) - ) - ).build(); + private void persistTeis(List trackedEntityInstances) { + Transaction transaction = genericCallData.databaseAdapter().beginNewTransaction(); + try { + trackedEntityInstanceHandler.handleMany(trackedEntityInstances); + transaction.setSuccessful(); + } catch (SQLiteConstraintException sql) { + /* This catch is necessary to ignore events with bad foreign keys exception + More info: If the foreign key have the flag DEFERRABLE INITIALLY DEFERRED this exception will be + throw in transaction.end() + And the rollback will be executed only when the database is closed. + It is a reported as unfixed bug: https://issuetracker.google.com/issues/37001653 */ + Log.d(this.getClass().getSimpleName(), sql.getMessage()); + } finally { + transaction.end(); + } } public static TeisEndPointCall create(GenericCallData genericCallData, TeiQuery teiQuery) { @@ -138,8 +73,6 @@ public static TeisEndPointCall create(GenericCallData genericCallData, TeiQuery genericCallData, genericCallData.retrofit().create(TrackedEntityInstanceService.class), teiQuery, - TrackedEntityInstanceHandler.create(genericCallData.databaseAdapter()), - genericCallData.resourceHandler() - ); + TrackedEntityInstanceHandler.create(genericCallData.databaseAdapter())); } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.java index 929ecf5b8a..70512b484e 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueManager.java @@ -29,14 +29,13 @@ import org.hisp.dhis.android.core.common.GenericCallData; import org.hisp.dhis.android.core.common.IdentifiableObjectStore; -import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; import org.hisp.dhis.android.core.systeminfo.SystemInfo; import org.hisp.dhis.android.core.systeminfo.SystemInfoCall; -import java.util.List; +import java.util.Date; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import retrofit2.Response; @@ -44,16 +43,22 @@ public final class TrackedEntityAttributeReservedValueManager { - private final ObjectWithoutUidStore store; + private static final int MIN_TO_TRY_FILL = 50; + private static final int FILL_UP_TO = 100; + + private final TrackedEntityAttributeReservedValueStoreInterface store; private final IdentifiableObjectStore organisationUnitStore; private final DatabaseAdapter databaseAdapter; private final Retrofit retrofit; - private TrackedEntityAttributeReservedValueManager(DatabaseAdapter databaseAdapter, Retrofit retrofit) { + TrackedEntityAttributeReservedValueManager(DatabaseAdapter databaseAdapter, + Retrofit retrofit, + TrackedEntityAttributeReservedValueStoreInterface store, + IdentifiableObjectStore organisationUnitStore) { this.databaseAdapter = databaseAdapter; this.retrofit = retrofit; - this.store = TrackedEntityAttributeReservedValueStore.create(databaseAdapter); - this.organisationUnitStore = OrganisationUnitStore.create(databaseAdapter); + this.store = store; + this.organisationUnitStore = organisationUnitStore; } @SuppressFBWarnings("DE_MIGHT_IGNORE") @@ -65,46 +70,28 @@ public String getValue(String attribute, String organisationUnitUid) throws Runt // Synchronization was not successful. } - List reservedValues = getReservedValues(attribute, - organisationUnitUid); + TrackedEntityAttributeReservedValueModel reservedValue = store.popOne(attribute, organisationUnitUid); - if (reservedValues.isEmpty()) { + if (reservedValue == null) { throw new RuntimeException("There are no reserved values."); } else { - TrackedEntityAttributeReservedValueModel reservedValue = reservedValues.get(0); - deleteReservedValue(reservedValue); return reservedValue.value(); } } - List getReservedValues(String attributeUid, String orgUnitUid) { - return this.store.selectWhere(TrackedEntityAttributeReservedValueModel.factory, attributeUid, orgUnitUid); - } - - private void deleteReservedValue(TrackedEntityAttributeReservedValueModel reservedValueModel) { - store.deleteWhere(reservedValueModel); - } - private void syncReservedValues(String attribute, String organisationUnitUid) throws Exception { - deleteExpiredDates(attribute, organisationUnitUid); - List reservedValues = getReservedValues(attribute, - organisationUnitUid); - if (reservedValues.size() <= 50) { - fillReservedValues(attribute, organisationUnitUid, reservedValues.size()); - } - } + // TODO use server date + store.deleteExpired(new Date()); - private void deleteExpiredDates(String attributeUid, String orgUnitUid) { - List reservedValues = getReservedValues(attributeUid, orgUnitUid); - - for (TrackedEntityAttributeReservedValueModel reservedValue : reservedValues) { - if (reservedValue.expiryDate().getTime() < System.currentTimeMillis()) { - deleteReservedValue(reservedValue); - } + int remainingValues = store.count(attribute, organisationUnitUid); + if (remainingValues <= MIN_TO_TRY_FILL) { + fillReservedValues(attribute, organisationUnitUid, remainingValues); } } - private void fillReservedValues(String attribute, String organisationUnitUid, Integer size) throws Exception { + private void fillReservedValues(String attribute, String organisationUnitUid, Integer remainingValues) + throws Exception { + Response systemInfoResponse = SystemInfoCall.FACTORY.create(databaseAdapter, retrofit).call(); if (!systemInfoResponse.isSuccessful()) { throw new RuntimeException("SystemInfo call failed."); @@ -114,7 +101,7 @@ private void fillReservedValues(String attribute, String organisationUnitUid, In GenericCallData genericCallData = GenericCallData.create(databaseAdapter, retrofit, systemInfo.serverDate()); - Integer numberToReserve = 100 - size; + Integer numberToReserve = FILL_UP_TO - remainingValues; OrganisationUnitModel organisationUnitModel = this.organisationUnitStore.selectByUid(organisationUnitUid, OrganisationUnitModel.factory); @@ -127,6 +114,10 @@ private void fillReservedValues(String attribute, String organisationUnitUid, In public static TrackedEntityAttributeReservedValueManager create(DatabaseAdapter databaseAdapter, Retrofit retrofit) { - return new TrackedEntityAttributeReservedValueManager(databaseAdapter, retrofit); + return new TrackedEntityAttributeReservedValueManager( + databaseAdapter, + retrofit, + TrackedEntityAttributeReservedValueStore.create(databaseAdapter), + OrganisationUnitStore.create(databaseAdapter)); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueModel.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueModel.java index 7ae0a9965f..b5f33b4a59 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueModel.java @@ -70,11 +70,6 @@ public String[] all() { public String[] whereUpdate() { return new String[]{OWNER_UID, VALUE, ORGANISATION_UNIT}; } - - @Override - public String[] whereSelect() { - return new String[]{OWNER_UID, ORGANISATION_UNIT}; - } } static TrackedEntityAttributeReservedValueModel create(Cursor cursor) { @@ -142,13 +137,6 @@ public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) sqLiteBind(sqLiteStatement, 10, organisationUnit()); } - @Override - public void bindToDeleteWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { - sqLiteBind(sqLiteStatement, 1, ownerUid()); - sqLiteBind(sqLiteStatement, 2, value()); - sqLiteBind(sqLiteStatement, 3, organisationUnit()); - } - @AutoValue.Builder public static abstract class Builder extends BaseModel.Builder { public abstract Builder ownerObject(String ownerObject); diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStore.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStore.java index 85b19ab05e..469e9ae57f 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStore.java @@ -28,17 +28,65 @@ package org.hisp.dhis.android.core.trackedentity; -import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; -import org.hisp.dhis.android.core.common.StoreFactory; +import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.BaseModel; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStoreImpl; +import org.hisp.dhis.android.core.common.SQLStatementBuilder; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValueModel.Columns; + +import java.util.Date; + +import static org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeReservedValueModel.factory; + +public final class TrackedEntityAttributeReservedValueStore + extends ObjectWithoutUidStoreImpl + implements TrackedEntityAttributeReservedValueStoreInterface { + + private TrackedEntityAttributeReservedValueStore(DatabaseAdapter databaseAdapter, + SQLiteStatement insertStatement, + SQLiteStatement updateWhereStatement, + SQLStatementBuilder builder) { + super(databaseAdapter, insertStatement, updateWhereStatement, builder); + } + + @Override + public void deleteExpired(@NonNull Date serverDate) throws RuntimeException { + super.deleteWhereClause(Columns.EXPIRY_DATE + + " < date('" + BaseIdentifiableObject.DATE_FORMAT.format(serverDate) + "')"); + } -public final class TrackedEntityAttributeReservedValueStore { + @Override + public TrackedEntityAttributeReservedValueModel popOne(@NonNull String ownerUid, + @NonNull String organisationUnitUid) { + return popOneWhere(factory, where(ownerUid, organisationUnitUid)); + } - private TrackedEntityAttributeReservedValueStore() {} + @Override + public int count(@NonNull String ownerUid, @NonNull String organisationUnitUid) { + return countWhere(where(ownerUid, organisationUnitUid)); + } - public static ObjectWithoutUidStore + private String where(@NonNull String ownerUid, + @NonNull String organisationUnitUid) { + return Columns.OWNER_UID + "='" + ownerUid + "' AND " + + Columns.ORGANISATION_UNIT + "='" + organisationUnitUid + "'"; + } + + public static TrackedEntityAttributeReservedValueStoreInterface create(DatabaseAdapter databaseAdapter) { - return StoreFactory.objectWithoutUidStore(databaseAdapter, TrackedEntityAttributeReservedValueModel.TABLE, - new TrackedEntityAttributeReservedValueModel.Columns()); + BaseModel.Columns columns = new TrackedEntityAttributeReservedValueModel.Columns(); + + SQLStatementBuilder statementBuilder = new SQLStatementBuilder( + TrackedEntityAttributeReservedValueModel.TABLE, columns); + + return new TrackedEntityAttributeReservedValueStore( + databaseAdapter, + databaseAdapter.compileStatement(statementBuilder.insert()), + databaseAdapter.compileStatement(statementBuilder.updateWhere()), + statementBuilder); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStoreInterface.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStoreInterface.java new file mode 100644 index 0000000000..23f3406b17 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeReservedValueStoreInterface.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.trackedentity; + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; + +import java.util.Date; + +public interface TrackedEntityAttributeReservedValueStoreInterface + extends ObjectWithoutUidStore { + + void deleteExpired(@NonNull Date serverDate); + + TrackedEntityAttributeReservedValueModel popOne(@NonNull String ownerUid, + @NonNull String organisationUnitUid); + + int count(@NonNull String ownerUid, + @NonNull String organisationUnitUid); +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValue.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValue.java index f36bb7f8a4..6d4b752dd4 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValue.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityAttributeValue.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import java.util.Date; @@ -45,13 +46,18 @@ public abstract class TrackedEntityAttributeValue { private final static String CREATED = "created"; private final static String LAST_UPDATED = "lastUpdated"; - public static final Field trackedEntityAttribute = + private static final Field trackedEntityAttribute = Field.create(ATTRIBUTE); - public static final Field value = Field.create(VALUE); - public static final Field created = Field.create(CREATED); - public static final Field lastUpdated = Field.create( + private static final Field value = Field.create(VALUE); + private static final Field created = Field.create(CREATED); + private static final Field lastUpdated = Field.create( LAST_UPDATED); + public static final Fields allFields = Fields + .builder().fields( + trackedEntityAttribute, value, created, lastUpdated + ).build(); + @Nullable @JsonProperty(ATTRIBUTE) public abstract String trackedEntityAttribute(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValue.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValue.java index 424e30f555..c1f289f6ac 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValue.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityDataValue.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import java.util.Date; @@ -47,12 +48,15 @@ public abstract class TrackedEntityDataValue { private final static String LAST_UPDATED = "lastUpdated"; private final static String PROVIDED_ELSEWHERE = "providedElsewhere"; - public static final Field dataElement = Field.create(DATA_ELEMENT); - public static final Field storedBy = Field.create(STORED_BY); - public static final Field value = Field.create(VALUE); - public static final Field created = Field.create(CREATED); - public static final Field lastUpdated = Field.create(LAST_UPDATED); - public static final Field providedElsewhere = Field.create(PROVIDED_ELSEWHERE); + private static final Field dataElement = Field.create(DATA_ELEMENT); + private static final Field storedBy = Field.create(STORED_BY); + private static final Field value = Field.create(VALUE); + private static final Field created = Field.create(CREATED); + private static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field providedElsewhere = Field.create(PROVIDED_ELSEWHERE); + + public static final Fields allFields = Fields.builder().fields( + dataElement, storedBy, value, created, lastUpdated, providedElsewhere).build(); @Nullable @JsonProperty(CREATED) diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java index 9b7fc9fc07..7d00cb74df 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstance.java @@ -35,6 +35,7 @@ import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.data.api.Field; +import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.NestedField; import org.hisp.dhis.android.core.enrollment.Enrollment; import org.hisp.dhis.android.core.period.FeatureType; @@ -61,24 +62,29 @@ public abstract class TrackedEntityInstance { private static final String DELETED = "deleted"; private static final String ENROLLMENTS = "enrollments"; - public static final Field uid = Field.create(UID); - public static final Field created = Field.create(CREATED); - public static final Field lastUpdated = Field.create(LAST_UPDATED); - public static final Field createdAtClient = Field.create(CREATED_AT_CLIENT); - public static final Field lastUpdatedAtClient = Field.create(LAST_UPDATED_AT_CLIENT); - public static final Field organisationUnit = Field.create(ORGANISATION_UNIT); - public static final Field trackedEntityType = Field.create(TRACKED_ENTITY_TYPE); - public static final Field coordinates = Field.create(COORDINATES); - public static final Field featureType = Field.create(FEATURE_TYPE); - public static final Field deleted = Field.create(DELETED); - - public static final NestedField enrollment + static final Field uid = Field.create(UID); + private static final Field created = Field.create(CREATED); + private static final Field lastUpdated = Field.create(LAST_UPDATED); + private static final Field organisationUnit = Field.create(ORGANISATION_UNIT); + private static final Field trackedEntityType = Field.create(TRACKED_ENTITY_TYPE); + private static final Field coordinates = Field.create(COORDINATES); + private static final Field featureType = Field.create(FEATURE_TYPE); + private static final Field deleted = Field.create(DELETED); + + private static final NestedField enrollment = NestedField.create(ENROLLMENTS); - public static final NestedField trackedEntityAttributeValues + private static final NestedField trackedEntityAttributeValues = NestedField.create(TRACKED_ENTITY_ATTRIBUTE_VALUES); - public static final NestedField relationships + private static final NestedField relationships = NestedField.create(RELATIONSHIPS); + public static final Fields allFields = Fields.builder().fields( + uid, created, lastUpdated, organisationUnit, trackedEntityType, deleted, + relationships.with(Relationship.allFields), + trackedEntityAttributeValues.with(TrackedEntityAttributeValue.allFields), + enrollment.with(Enrollment.allFields), coordinates, featureType + ).build(); + @JsonProperty(UID) public abstract String uid(); diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceDownloadByUidEndPointCall.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceDownloadByUidEndPointCall.java new file mode 100644 index 0000000000..df7a43f682 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceDownloadByUidEndPointCall.java @@ -0,0 +1,46 @@ +package org.hisp.dhis.android.core.trackedentity; + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.calls.Call; +import org.hisp.dhis.android.core.common.APICallExecutor; +import org.hisp.dhis.android.core.common.D2CallException; +import org.hisp.dhis.android.core.common.SyncCall; + +import retrofit2.Retrofit; + +final class TrackedEntityInstanceDownloadByUidEndPointCall extends SyncCall { + + private final TrackedEntityInstanceService trackedEntityInstanceService; + private final String uid; + + private TrackedEntityInstanceDownloadByUidEndPointCall( + @NonNull TrackedEntityInstanceService trackedEntityInstanceService, + @NonNull String uid) { + + this.trackedEntityInstanceService = trackedEntityInstanceService; + this.uid = uid; + } + + @Override + public TrackedEntityInstance call() throws D2CallException { + super.setExecuted(); + + if (uid == null) { + throw D2CallException.builder().isHttpError(false).errorDescription("UID null").build(); + } + + retrofit2.Call call = + trackedEntityInstanceService.getTrackedEntityInstance(uid, + TrackedEntityInstance.allFields, true); + + return new APICallExecutor().executeObjectCall(call); + } + + public static Call create(Retrofit retrofit, String uid) { + return new TrackedEntityInstanceDownloadByUidEndPointCall( + retrofit.create(TrackedEntityInstanceService.class), + uid + ); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceEndPointCall.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceEndPointCall.java deleted file mode 100644 index 8ba2272acb..0000000000 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceEndPointCall.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.hisp.dhis.android.core.trackedentity; - -import android.database.sqlite.SQLiteConstraintException; -import android.support.annotation.NonNull; -import android.util.Log; - -import org.hisp.dhis.android.core.common.SyncCall; -import org.hisp.dhis.android.core.data.api.Fields; -import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.data.database.Transaction; -import org.hisp.dhis.android.core.enrollment.Enrollment; -import org.hisp.dhis.android.core.enrollment.note.Note; -import org.hisp.dhis.android.core.event.Event; -import org.hisp.dhis.android.core.relationship.Relationship; - -import retrofit2.Response; -import retrofit2.Retrofit; - -public class TrackedEntityInstanceEndPointCall extends SyncCall> { - - private final DatabaseAdapter databaseAdapter; - private final TrackedEntityInstanceService trackedEntityInstanceService; - private final TrackedEntityInstanceHandler trackedEntityInstanceHandler; - private final String trackedEntityInstanceUid; - - TrackedEntityInstanceEndPointCall( - @NonNull DatabaseAdapter databaseAdapter, - @NonNull TrackedEntityInstanceService trackedEntityInstanceService, - @NonNull TrackedEntityInstanceHandler trackedEntityInstanceHandler, - @NonNull String trackedEntityInstanceUid) { - this.databaseAdapter = databaseAdapter; - this.trackedEntityInstanceService = trackedEntityInstanceService; - this.trackedEntityInstanceHandler = trackedEntityInstanceHandler; - - if (trackedEntityInstanceUid == null || trackedEntityInstanceUid.isEmpty()) { - throw new IllegalArgumentException( - "trackedEntityInstanceUid is required to realize a request"); - } - - this.trackedEntityInstanceUid = trackedEntityInstanceUid; - } - - @Override - public Response call() throws Exception { - super.setExecuted(); - - Response response = - trackedEntityInstanceService.trackedEntityInstance(trackedEntityInstanceUid, - fields(), true).execute(); - - if (response == null || !response.isSuccessful()) { - return response; - } - - Transaction transaction = databaseAdapter.beginNewTransaction(); - - try { - TrackedEntityInstance trackedEntityInstance = response.body(); - trackedEntityInstanceHandler.handle(trackedEntityInstance); - transaction.setSuccessful(); - - } catch (SQLiteConstraintException sql) { - // This catch is necessary to ignore events with bad foreign keys exception - // More info: If the foreign key have the flag - // DEFERRABLE INITIALLY DEFERRED this exception will be throw in transaction - // .end() - // And the rollback will be executed only when the database is closed. - // It is a reported as unfixed bug: https://issuetracker.google - // .com/issues/37001653 - Log.d(this.getClass().getSimpleName(), sql.getMessage()); - } finally { - transaction.end(); - } - - return response; - } - - private Fields fields() { - return Fields.builder().fields( - TrackedEntityInstance.uid, TrackedEntityInstance.created, - TrackedEntityInstance.lastUpdated, - TrackedEntityInstance.organisationUnit, - TrackedEntityInstance.trackedEntityType, - TrackedEntityInstance.coordinates, - TrackedEntityInstance.featureType, - TrackedEntityInstance.deleted, - TrackedEntityInstance.relationships.with(Relationship.allFields), - TrackedEntityInstance.trackedEntityAttributeValues.with( - TrackedEntityAttributeValue.trackedEntityAttribute, - TrackedEntityAttributeValue.value, - TrackedEntityAttributeValue.created, - TrackedEntityAttributeValue.lastUpdated), - TrackedEntityInstance.enrollment.with( - Enrollment.uid, Enrollment.created, Enrollment.lastUpdated, - Enrollment.coordinate, - Enrollment.dateOfEnrollment, Enrollment.dateOfIncident, - Enrollment.enrollmentStatus, - Enrollment.followUp, Enrollment.program, Enrollment.organisationUnit, - Enrollment.trackedEntityInstance, - Enrollment.deleted, - Enrollment.events.with( - Event.attributeCategoryOptions, Event.attributeOptionCombo, - Event.uid, Event.created, Event.lastUpdated, Event.completeDate, - Event.coordinates, - Event.dueDate, Event.enrollment, Event.eventDate, Event.eventStatus, - Event.organisationUnit, Event.program, Event.programStage, - Event.deleted, - Event.trackedEntityDataValues.with( - TrackedEntityDataValue.created, - TrackedEntityDataValue.lastUpdated, - TrackedEntityDataValue.dataElement, - TrackedEntityDataValue.providedElsewhere, - TrackedEntityDataValue.storedBy, - TrackedEntityDataValue.value - ) - ), - Enrollment.notes.with(Note.allFields) - ) - ).build(); - } - - public static TrackedEntityInstanceEndPointCall create(DatabaseAdapter databaseAdapter, - Retrofit retrofit, - String trackedEntityInstanceUid) { - return new TrackedEntityInstanceEndPointCall( - databaseAdapter, - retrofit.create(TrackedEntityInstanceService.class), - TrackedEntityInstanceHandler.create(databaseAdapter), - trackedEntityInstanceUid - ); - } -} diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceHandler.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceHandler.java index 8e22f380aa..5d3534416a 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceHandler.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceHandler.java @@ -12,6 +12,7 @@ import org.hisp.dhis.android.core.relationship.RelationshipModelBuilder; import org.hisp.dhis.android.core.relationship.RelationshipStore; +import java.util.Collection; import java.util.List; import static org.hisp.dhis.android.core.utils.Utils.isDeleted; @@ -73,6 +74,12 @@ public void handle(@NonNull TrackedEntityInstance trackedEntityInstance) { } } + public void handleMany(@NonNull Collection trackedEntityInstances) { + for (TrackedEntityInstance trackedEntityInstance : trackedEntityInstances) { + handle(trackedEntityInstance); + } + } + public static TrackedEntityInstanceHandler create(DatabaseAdapter databaseAdapter) { return new TrackedEntityInstanceHandler( new TrackedEntityInstanceStoreImpl(databaseAdapter), diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceListDownloadAndPersistCall.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceListDownloadAndPersistCall.java new file mode 100644 index 0000000000..60ffdcf039 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceListDownloadAndPersistCall.java @@ -0,0 +1,63 @@ +package org.hisp.dhis.android.core.trackedentity; + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.calls.Call; +import org.hisp.dhis.android.core.common.D2CallException; +import org.hisp.dhis.android.core.common.D2CallExecutor; +import org.hisp.dhis.android.core.common.SyncCall; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import retrofit2.Retrofit; + +public final class TrackedEntityInstanceListDownloadAndPersistCall extends SyncCall> { + + private final DatabaseAdapter databaseAdapter; + private final Retrofit retrofit; + + private final Collection trackedEntityInstanceUids; + + private TrackedEntityInstanceListDownloadAndPersistCall( + @NonNull DatabaseAdapter databaseAdapter, + @NonNull Retrofit retrofit, + @NonNull Collection trackedEntityInstanceUids) { + this.databaseAdapter = databaseAdapter; + this.retrofit = retrofit; + this.trackedEntityInstanceUids = trackedEntityInstanceUids; + } + + @Override + public List call() throws D2CallException { + super.setExecuted(); + + if (trackedEntityInstanceUids == null) { + throw D2CallException.builder().isHttpError(false).errorDescription("UID list null").build(); + } + + List teis = new ArrayList<>(); + D2CallExecutor executor = new D2CallExecutor(); + for (String uid: trackedEntityInstanceUids) { + Call teiCall = + TrackedEntityInstanceDownloadByUidEndPointCall.create(retrofit, uid); + teis.add(executor.executeD2Call(teiCall)); + } + + TrackedEntityInstancePersistenceCall.create(databaseAdapter, retrofit, teis).call(); + + return teis; + } + + public static Call> create(DatabaseAdapter databaseAdapter, + Retrofit retrofit, + Collection trackedEntityInstanceUids) { + return new TrackedEntityInstanceListDownloadAndPersistCall( + databaseAdapter, + retrofit, + trackedEntityInstanceUids + ); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstancePersistenceCall.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstancePersistenceCall.java new file mode 100644 index 0000000000..90b31b009f --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstancePersistenceCall.java @@ -0,0 +1,87 @@ +package org.hisp.dhis.android.core.trackedentity; + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.common.D2CallException; +import org.hisp.dhis.android.core.common.SyncCall; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import org.hisp.dhis.android.core.data.database.Transaction; +import org.hisp.dhis.android.core.organisationunit.SearchOrganisationUnitCall; +import org.hisp.dhis.android.core.user.AuthenticatedUserModel; +import org.hisp.dhis.android.core.user.AuthenticatedUserStore; +import org.hisp.dhis.android.core.user.AuthenticatedUserStoreImpl; + +import java.util.Collection; +import java.util.Set; + +import retrofit2.Retrofit; + +final class TrackedEntityInstancePersistenceCall extends SyncCall { + + private final DatabaseAdapter databaseAdapter; + private final Retrofit retrofit; + private final TrackedEntityInstanceHandler trackedEntityInstanceHandler; + private final TrackedEntityInstanceUidHelper uidsHelper; + private final AuthenticatedUserStore authenticatedUserStore; + private final SearchOrganisationUnitCall.Factory organisationUnitCallFactory; + + private final Collection trackedEntityInstances; + + private TrackedEntityInstancePersistenceCall( + @NonNull DatabaseAdapter databaseAdapter, + @NonNull Retrofit retrofit, + @NonNull TrackedEntityInstanceHandler trackedEntityInstanceHandler, + @NonNull TrackedEntityInstanceUidHelper uidsHelper, + @NonNull AuthenticatedUserStore authenticatedUserStore, + @NonNull SearchOrganisationUnitCall.Factory organisationUnitCallFactory, + @NonNull Collection trackedEntityInstances) { + this.databaseAdapter = databaseAdapter; + this.retrofit = retrofit; + this.trackedEntityInstanceHandler = trackedEntityInstanceHandler; + this.uidsHelper = uidsHelper; + this.authenticatedUserStore = authenticatedUserStore; + this.organisationUnitCallFactory = organisationUnitCallFactory; + this.trackedEntityInstances = trackedEntityInstances; + } + + @Override + public Void call() throws D2CallException { + super.setExecuted(); + + Transaction transaction = databaseAdapter.beginNewTransaction(); + + try { + trackedEntityInstanceHandler.handleMany(trackedEntityInstances); + + Set searchOrgUnitUids = uidsHelper.getMissingOrganisationUnitUids(trackedEntityInstances); + + if (!searchOrgUnitUids.isEmpty()) { + AuthenticatedUserModel authenticatedUserModel = authenticatedUserStore.query().get(0); + SearchOrganisationUnitCall organisationUnitCall = organisationUnitCallFactory.create( + databaseAdapter, retrofit, searchOrgUnitUids, authenticatedUserModel.user()); + organisationUnitCall.call(); + } + + transaction.setSuccessful(); + } finally { + transaction.end(); + } + + return null; + } + + public static TrackedEntityInstancePersistenceCall create(DatabaseAdapter databaseAdapter, + Retrofit retrofit, + Collection + trackedEntityInstances) { + return new TrackedEntityInstancePersistenceCall( + databaseAdapter, + retrofit, + TrackedEntityInstanceHandler.create(databaseAdapter), + TrackedEntityInstanceUidHelperImpl.create(databaseAdapter), + new AuthenticatedUserStoreImpl(databaseAdapter), + SearchOrganisationUnitCall.FACTORY, + trackedEntityInstances + ); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java index 44c0eece4a..5ba165cd06 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceService.java @@ -2,8 +2,6 @@ import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.data.api.Fields; -import org.hisp.dhis.android.core.data.api.Filter; -import org.hisp.dhis.android.core.data.api.Where; import org.hisp.dhis.android.core.data.api.Which; import org.hisp.dhis.android.core.imports.WebResponse; import org.hisp.dhis.android.core.trackedentity.search.SearchGrid; @@ -19,7 +17,7 @@ public interface TrackedEntityInstanceService { String TRACKED_ENTITY_INSTANCES = "trackedEntityInstances"; - String TRACKED_ENTITY_INSTANCES_UID = "trackedEntityInstanceUid"; + String TRACKED_ENTITY_INSTANCE_UID = "trackedEntityInstanceUid"; String OU = "ou"; String OU_MODE = "ouMode"; String FIELDS = "fields"; @@ -36,16 +34,16 @@ public interface TrackedEntityInstanceService { Call postTrackedEntityInstances( @Body TrackedEntityInstancePayload trackedEntityInstances); - @GET(TRACKED_ENTITY_INSTANCES + "/{" + TRACKED_ENTITY_INSTANCES_UID + "}") - Call trackedEntityInstance( - @Path(TRACKED_ENTITY_INSTANCES_UID) String trackedEntityInstanceUid, + @GET(TRACKED_ENTITY_INSTANCES + "/{" + TRACKED_ENTITY_INSTANCE_UID + "}") + Call getTrackedEntityInstance( + @Path(TRACKED_ENTITY_INSTANCE_UID) String trackedEntityInstanceUid, @Query(FIELDS) @Which Fields fields, @Query(INCLUDE_DELETED) boolean includeDeleted); @GET(TRACKED_ENTITY_INSTANCES) - Call> getTEIs( - @Query(OU) String orgUnit, - @Query(FILTER) @Where Filter lastUpdated, + Call> getTrackedEntityInstances( + @Query(OU) String orgUnits, + @Query(OU_MODE) String orgUnitMode, @Query(FIELDS) @Which Fields fields, @Query(PAGING) Boolean paging, @Query(PAGE) int page, diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelper.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelper.java new file mode 100644 index 0000000000..6a1a7d1e6e --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelper.java @@ -0,0 +1,8 @@ +package org.hisp.dhis.android.core.trackedentity; + +import java.util.Collection; +import java.util.Set; + +interface TrackedEntityInstanceUidHelper { + Set getMissingOrganisationUnitUids(Collection trackedEntityInstances); +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelperImpl.java b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelperImpl.java new file mode 100644 index 0000000000..e1aee3d56a --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelperImpl.java @@ -0,0 +1,63 @@ +package org.hisp.dhis.android.core.trackedentity; + +import android.support.annotation.NonNull; + +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import org.hisp.dhis.android.core.enrollment.Enrollment; +import org.hisp.dhis.android.core.event.Event; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +class TrackedEntityInstanceUidHelperImpl implements TrackedEntityInstanceUidHelper { + + private final IdentifiableObjectStore organisationUnitStore; + + TrackedEntityInstanceUidHelperImpl( + @NonNull IdentifiableObjectStore organisationUnitStore) { + this.organisationUnitStore = organisationUnitStore; + } + + @Override + public Set getMissingOrganisationUnitUids(Collection trackedEntityInstances) { + Set uids = new HashSet<>(); + for (TrackedEntityInstance tei: trackedEntityInstances) { + if (tei.organisationUnit() != null) { + uids.add(tei.organisationUnit()); + } + addEnrollmentsUids(tei.enrollments(), uids); + } + uids.removeAll(organisationUnitStore.selectUids()); + return uids; + } + + private void addEnrollmentsUids(List enrollments, Set uids) { + if (enrollments != null) { + for (Enrollment enrollment: enrollments) { + if (enrollment.organisationUnit() != null) { + uids.add(enrollment.organisationUnit()); + } + addEventsUids(enrollment.events(), uids); + } + } + } + + private void addEventsUids(List events, Set uids) { + if (events != null) { + for (Event event: events) { + if (event.organisationUnit() != null) { + uids.add(event.organisationUnit()); + } + } + } + } + + public static TrackedEntityInstanceUidHelperImpl create(DatabaseAdapter databaseAdapter) { + return new TrackedEntityInstanceUidHelperImpl(OrganisationUnitStore.create(databaseAdapter)); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/LogOutUserCallable.java b/core/src/main/java/org/hisp/dhis/android/core/user/LogOutUserCallable.java index af366313d8..d9cd6ba3cb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/LogOutUserCallable.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/LogOutUserCallable.java @@ -59,7 +59,7 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnitProgramLinkStore; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitStore; import org.hisp.dhis.android.core.period.PeriodStore; -import org.hisp.dhis.android.core.program.ProgramIndicatorStoreImpl; +import org.hisp.dhis.android.core.program.ProgramIndicatorStore; import org.hisp.dhis.android.core.program.ProgramRuleActionStoreImpl; import org.hisp.dhis.android.core.program.ProgramRuleStoreImpl; import org.hisp.dhis.android.core.program.ProgramRuleVariableStoreImpl; @@ -123,7 +123,7 @@ public static LogOutUserCallable createToWipe(DatabaseAdapter databaseAdapter) { ProgramTrackedEntityAttributeStore.create(databaseAdapter), new ProgramRuleVariableStoreImpl(databaseAdapter), - new ProgramIndicatorStoreImpl(databaseAdapter), + ProgramIndicatorStore.create(databaseAdapter), new ProgramStageSectionProgramIndicatorLinkStoreImpl(databaseAdapter), new ProgramRuleActionStoreImpl(databaseAdapter), new ProgramRuleStoreImpl(databaseAdapter), diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/User.java b/core/src/main/java/org/hisp/dhis/android/core/user/User.java index 840f7e4b19..86b1fa39d5 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/User.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/User.java @@ -30,8 +30,8 @@ import android.support.annotation.Nullable; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.auto.value.AutoValue; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; @@ -39,13 +39,10 @@ import org.hisp.dhis.android.core.data.api.NestedField; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; -import java.util.Date; import java.util.List; -import static org.hisp.dhis.android.core.utils.Utils.safeUnmodifiableList; - @AutoValue -// @JsonDeserialize(builder = AutoValue_User.Builder.class) +@JsonDeserialize(builder = AutoValue_User.Builder.class) public abstract class User extends BaseIdentifiableObject { public static final String GENDER_MALE = "gender_male"; public static final String GENDER_FEMALE = "gender_female"; @@ -171,6 +168,7 @@ public abstract class User extends BaseIdentifiableObject { @JsonProperty(NATIONALITY) public abstract String nationality(); + @Nullable @JsonProperty(USER_CREDENTIALS) public abstract UserCredentials userCredentials(); @@ -186,42 +184,64 @@ public abstract class User extends BaseIdentifiableObject { @JsonProperty(DATA_VIEW_ORGANISATION_UNITS) public abstract List dataViewOrganisationUnits(); - @JsonCreator - public static User create( - @JsonProperty(UID) String uid, - @JsonProperty(CODE) String code, - @JsonProperty(NAME) String name, - @JsonProperty(DISPLAY_NAME) String displayName, - @JsonProperty(CREATED) Date created, - @JsonProperty(LAST_UPDATED) Date lastUpdated, - @JsonProperty(BIRTHDAY) String birthday, - @JsonProperty(EDUCATION) String education, - @JsonProperty(GENDER) String gender, - @JsonProperty(JOB_TITLE) String jobTitle, - @JsonProperty(SURNAME) String surname, - @JsonProperty(FIRST_NAME) String firstName, - @JsonProperty(INTRODUCTION) String introduction, - @JsonProperty(EMPLOYER) String employer, - @JsonProperty(INTERESTS) String interests, - @JsonProperty(LANGUAGES) String languages, - @JsonProperty(EMAIL) String email, - @JsonProperty(PHONE_NUMBER) String phoneNumber, - @JsonProperty(NATIONALITY) String nationality, - @JsonProperty(USER_CREDENTIALS) UserCredentials userCredentials, - @JsonProperty(ORGANISATION_UNITS) List orgUnits, - @JsonProperty(TEI_SEARCH_ORGANISATION_UNITS) List searchOrgUnits, - @JsonProperty(DATA_VIEW_ORGANISATION_UNITS) List dataViewOrgUnits, - @JsonProperty(DELETED) Boolean deleted) { - // ToDo: change from jackson to gson and implement autovalue-gson extension - - return new AutoValue_User( - uid, code, name, displayName, created, lastUpdated, deleted, birthday, education, gender, - jobTitle, surname, firstName, introduction, employer, interests, languages, email, - phoneNumber, nationality, userCredentials, - safeUnmodifiableList(orgUnits), - safeUnmodifiableList(searchOrgUnits), - safeUnmodifiableList(dataViewOrgUnits) - ); + public static User.Builder builder() { + return new AutoValue_User.Builder(); } + @AutoValue.Builder + public static abstract class Builder extends BaseIdentifiableObject.Builder { + + @JsonProperty(BIRTHDAY) + public abstract Builder birthday(String birthday); + + @JsonProperty(EDUCATION) + public abstract Builder education(String education); + + @JsonProperty(GENDER) + public abstract Builder gender(String gender); + + @JsonProperty(JOB_TITLE) + public abstract Builder jobTitle(String jobTitle); + + @JsonProperty(SURNAME) + public abstract Builder surname(String surname); + + @JsonProperty(FIRST_NAME) + public abstract Builder firstName(String firstName); + + @JsonProperty(INTRODUCTION) + public abstract Builder introduction(String introduction); + + @JsonProperty(EMPLOYER) + public abstract Builder employer(String employer); + + @JsonProperty(INTERESTS) + public abstract Builder interests(String interests); + + @JsonProperty(LANGUAGES) + public abstract Builder languages(String languages); + + @JsonProperty(EMAIL) + public abstract Builder email(String email); + + @JsonProperty(PHONE_NUMBER) + public abstract Builder phoneNumber(String phoneNumber); + + @JsonProperty(NATIONALITY) + public abstract Builder nationality(String nationality); + + @JsonProperty(USER_CREDENTIALS) + public abstract Builder userCredentials(UserCredentials userCredentials); + + @JsonProperty(ORGANISATION_UNITS) + public abstract Builder organisationUnits(List organisationUnits); + + @JsonProperty(TEI_SEARCH_ORGANISATION_UNITS) + public abstract Builder teiSearchOrganisationUnits(List teiSearchOrganisationUnits); + + @JsonProperty(DATA_VIEW_ORGANISATION_UNITS) + public abstract Builder dataViewOrganisationUnits(List dataViewOrganisationUnits); + + public abstract User build(); + } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModel.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModel.java index 5b8b5f534e..1d36bb21ec 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModel.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModel.java @@ -50,10 +50,11 @@ public static class Columns extends BaseModel.Columns { public static final String USER = "user"; public static final String ORGANISATION_UNIT = "organisationUnit"; public static final String ORGANISATION_UNIT_SCOPE = "organisationUnitScope"; + public static final String ROOT = "root"; @Override public String[] all() { - return Utils.appendInNewArray(super.all(), USER, ORGANISATION_UNIT, ORGANISATION_UNIT_SCOPE); + return Utils.appendInNewArray(super.all(), USER, ORGANISATION_UNIT, ORGANISATION_UNIT_SCOPE, ROOT); } @Override @@ -74,6 +75,10 @@ public String[] whereUpdate() { @ColumnName(Columns.ORGANISATION_UNIT_SCOPE) public abstract String organisationUnitScope(); + @Nullable + @ColumnName(Columns.ROOT) + public abstract Boolean root(); + @NonNull public static UserOrganisationUnitLinkModel create(Cursor cursor) { return AutoValue_UserOrganisationUnitLinkModel.createFromCursor(cursor); @@ -92,13 +97,15 @@ public void bindToStatement(@NonNull SQLiteStatement sqLiteStatement) { sqLiteBind(sqLiteStatement, 1, user()); sqLiteBind(sqLiteStatement, 2, organisationUnit()); sqLiteBind(sqLiteStatement, 3, organisationUnitScope()); + sqLiteBind(sqLiteStatement, 4, root()); } @Override public void bindToUpdateWhereStatement(@NonNull SQLiteStatement sqLiteStatement) { - sqLiteBind(sqLiteStatement, 4, user()); - sqLiteBind(sqLiteStatement, 5, organisationUnit()); - sqLiteBind(sqLiteStatement, 6, organisationUnitScope()); + sqLiteBind(sqLiteStatement, 5, user()); + sqLiteBind(sqLiteStatement, 6, organisationUnit()); + sqLiteBind(sqLiteStatement, 7, organisationUnitScope()); + sqLiteBind(sqLiteStatement, 8, root()); } @NonNull @@ -114,6 +121,8 @@ public static abstract class Builder extends BaseModel.Builder { public abstract Builder organisationUnitScope(@Nullable String organisationUnitScope); + public abstract Builder root(@Nullable Boolean root); + public abstract UserOrganisationUnitLinkModel build(); } } diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelBuilder.java index 692fcf5d46..367bfd221c 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkModelBuilder.java @@ -32,12 +32,18 @@ import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; +import java.util.Set; + +import static org.hisp.dhis.android.core.organisationunit.OrganisationUnitTree.findRoots; + public class UserOrganisationUnitLinkModelBuilder extends ModelBuilder { private final UserOrganisationUnitLinkModel.Builder builder; + private final User user; public UserOrganisationUnitLinkModelBuilder(OrganisationUnitModel.Scope scope, User user) { + this.user = user; this.builder = UserOrganisationUnitLinkModel.builder() .organisationUnitScope(scope.name()) .user(user.uid()); @@ -47,6 +53,16 @@ public UserOrganisationUnitLinkModelBuilder(OrganisationUnitModel.Scope scope, U public UserOrganisationUnitLinkModel buildModel(OrganisationUnit organisationUnit) { return builder .organisationUnit(organisationUnit.uid()) + .root(isRoot(organisationUnit)) .build(); } -} + + private boolean isRoot(OrganisationUnit organisationUnit) { + if (user.organisationUnits() == null) { + return false; + } else { + Set rootOrgUnitUids = findRoots(user.organisationUnits()); + return rootOrgUnitUids.contains(organisationUnit.uid()); + } + } +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkStore.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkStore.java index 811b1b4e4d..baffb56feb 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkStore.java +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkStore.java @@ -28,16 +28,38 @@ package org.hisp.dhis.android.core.user; -import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; -import org.hisp.dhis.android.core.common.StoreFactory; +import android.database.sqlite.SQLiteStatement; + +import org.hisp.dhis.android.core.common.ObjectWithoutUidStoreImpl; +import org.hisp.dhis.android.core.common.SQLStatementBuilder; import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -public final class UserOrganisationUnitLinkStore { +import java.util.Set; + +public final class UserOrganisationUnitLinkStore extends ObjectWithoutUidStoreImpl + implements UserOrganisationUnitLinkStoreInterface{ + + private UserOrganisationUnitLinkStore(DatabaseAdapter databaseAdapter, + SQLiteStatement insertStatement, + SQLiteStatement updateWhereStatement, + SQLStatementBuilder builder) { + super(databaseAdapter, insertStatement, updateWhereStatement, builder); + } + + public static UserOrganisationUnitLinkStoreInterface create(DatabaseAdapter databaseAdapter) { + SQLStatementBuilder statementBuilder = new SQLStatementBuilder( + UserOrganisationUnitLinkModel.TABLE, new UserOrganisationUnitLinkModel.Columns()); - private UserOrganisationUnitLinkStore() {} + return new UserOrganisationUnitLinkStore( + databaseAdapter, + databaseAdapter.compileStatement(statementBuilder.insert()), + databaseAdapter.compileStatement(statementBuilder.updateWhere()), + statementBuilder); + } - public static ObjectWithoutUidStore create(DatabaseAdapter databaseAdapter) { - return StoreFactory.objectWithoutUidStore(databaseAdapter, UserOrganisationUnitLinkModel.TABLE, - new UserOrganisationUnitLinkModel.Columns()); + @Override + public Set queryRootOrganisationUnitUids() throws RuntimeException { + return selectStringColumnsWhereClause(UserOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT, + UserOrganisationUnitLinkModel.Columns.ROOT + " = 1"); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkStoreInterface.java b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkStoreInterface.java new file mode 100644 index 0000000000..c33b7d50d6 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/user/UserOrganisationUnitLinkStoreInterface.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.user; + +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; + +import java.util.Set; + +public interface UserOrganisationUnitLinkStoreInterface extends ObjectWithoutUidStore { + + Set queryRootOrganisationUnitUids() throws RuntimeException; +} \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java index 8842689b64..b9eb8b8f99 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/Utils.java @@ -115,6 +115,6 @@ public static String commaSeparatedCollectionValues(Collection values) { } public static String joinCollectionWithSeparator(Collection values, String separator) { - return commaSeparatedCollectionValues(values).replace(",", ";"); + return commaSeparatedCollectionValues(values).replace(",", separator); } } \ No newline at end of file diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngine.java b/core/src/main/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngine.java new file mode 100644 index 0000000000..51b9196a53 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngine.java @@ -0,0 +1,358 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.utils.services; + + +import org.apache.commons.jexl2.JexlException; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ValueType; +import org.hisp.dhis.android.core.constant.ConstantModel; +import org.hisp.dhis.android.core.constant.ConstantStore; +import org.hisp.dhis.android.core.data.database.DatabaseAdapter; +import org.hisp.dhis.android.core.dataelement.DataElementModel; +import org.hisp.dhis.android.core.dataelement.DataElementStore; +import org.hisp.dhis.android.core.enrollment.EnrollmentModel; +import org.hisp.dhis.android.core.enrollment.EnrollmentStore; +import org.hisp.dhis.android.core.enrollment.EnrollmentStoreImpl; +import org.hisp.dhis.android.core.event.EventModel; +import org.hisp.dhis.android.core.event.EventStore; +import org.hisp.dhis.android.core.event.EventStoreImpl; +import org.hisp.dhis.android.core.program.ProgramIndicatorModel; +import org.hisp.dhis.android.core.program.ProgramIndicatorStore; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueStore; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueStoreImpl; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStoreImpl; +import org.hisp.dhis.android.core.utils.support.DateUtils; +import org.hisp.dhis.android.core.utils.support.ExpressionUtils; +import org.hisp.dhis.android.core.utils.support.MathUtils; +import org.hisp.dhis.android.core.utils.support.TextUtils; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Chau Thu Tran + */ + +@SuppressWarnings({ + "PMD.ExcessiveImports", + "PMD.ExcessiveMethodLength", + "PMD.NPathComplexity", + "PMD.CyclomaticComplexity", + "PMD.ModifiedCyclomaticComplexity", + "PMD.StdCyclomaticComplexity", + "PMD.GodClass" +}) +public class ProgramIndicatorEngine { + private static final String NULL_REPLACEMENT = "null"; + + private static final String SEPARATOR_ID = "\\."; + private static final String KEY_DATAELEMENT = "#"; + private static final String KEY_ATTRIBUTE = "A"; + private static final String KEY_PROGRAM_VARIABLE = "V"; + private static final String KEY_CONSTANT = "C"; + private static final String INCIDENT_DATE = "incident_date"; + private static final String ENROLLMENT_DATE = "enrollment_date"; + private static final String EVENT_DATE = "event_date"; + private static final String CURRENT_DATE = "current_date"; + private static final String VAR_VALUE_COUNT = "value_count"; + private static final String VAR_ZERO_POS_VALUE_COUNT = "zero_pos_value_count"; + private static final String EXPRESSION_REGEXP = "(" + KEY_DATAELEMENT + "|" + KEY_ATTRIBUTE + "|" + + KEY_PROGRAM_VARIABLE + "|" + KEY_CONSTANT + + ")\\{(\\w+|" + INCIDENT_DATE + "|" + ENROLLMENT_DATE + "|" + CURRENT_DATE + "|" + EVENT_DATE + ")" + + SEPARATOR_ID + "?(\\w*)\\}"; + private static final Pattern EXPRESSION_PATTERN = Pattern.compile(EXPRESSION_REGEXP); + private static final Pattern VALUECOUNT_PATTERN = + Pattern.compile("V\\{(" + VAR_VALUE_COUNT + "|" + VAR_ZERO_POS_VALUE_COUNT + ")\\}"); + + private final IdentifiableObjectStore programIndicatorStore; + private final TrackedEntityDataValueStore trackedEntityDataValueStore; + private final EnrollmentStore enrollmentStore; + private final EventStore eventStore; + private final IdentifiableObjectStore dataElementStore; + private final IdentifiableObjectStore constantStore; + private final TrackedEntityAttributeValueStore trackedEntityAttributeValueStore; + + ProgramIndicatorEngine(IdentifiableObjectStore programIndicatorStore, + TrackedEntityDataValueStore trackedEntityDataValueStore, + EnrollmentStore enrollmentStore, + EventStore eventStore, + IdentifiableObjectStore dataElementStore, + IdentifiableObjectStore constantStore, + TrackedEntityAttributeValueStore trackedEntityAttributeValueStore) { + this.programIndicatorStore = programIndicatorStore; + this.trackedEntityDataValueStore = trackedEntityDataValueStore; + this.enrollmentStore = enrollmentStore; + this.eventStore = eventStore; + this.dataElementStore = dataElementStore; + this.constantStore = constantStore; + this.trackedEntityAttributeValueStore = trackedEntityAttributeValueStore; + } + + /** + * Calculate an program indicator value based on program instance and an + * indicator defined for a TrackedEntityInstance + * + * @param enrollment Enrollment uid + * @param event Event uid + * @param programIndicatorUid ProgramIndicator + * @return Indicator value + */ + public String getProgramIndicatorValue(String enrollment, String event, String programIndicatorUid) { + if(enrollment == null && event == null) { + return null; + } + + Double value = getValue(enrollment, event, programIndicatorUid); + + return TextUtils.fromDouble(value); + } + + // ------------------------------------------------------------------------- + // Supportive methods + // ------------------------------------------------------------------------- + + String parseIndicatorExpression(String enrollment, String event, String indicatorUid) { + StringBuffer buffer = new StringBuffer(); + + ProgramIndicatorModel programIndicator = this.programIndicatorStore.selectByUid(indicatorUid, + ProgramIndicatorModel.factory); + String expression = programIndicator.expression(); + + Matcher matcher = EXPRESSION_PATTERN.matcher(expression); + + int valueCount = 0; + int zeroPosValueCount = 0; + + EventModel cachedEventModel = null; + Map dataElementToDataValues = new HashMap<>(); + EnrollmentModel cachedEnrollment = null; + Map attributeToAttributeValues = new HashMap<>(); + + Date currentDate = new Date(); + + while (matcher.find()) { + String key = matcher.group(1); + String uid = matcher.group(2); + + if (KEY_DATAELEMENT.equals(key)) { + String de = matcher.group(3); + String programStageUid = uid; + + if (programStageUid == null || de == null) { + continue; + } + + if (enrollment == null) { + // Single event without registration + dataElementToDataValues = getTrackedEntityDataValues(event); + } else { + if (cachedEventModel == null || + !cachedEventModel.programStage().equals(programStageUid)) { + cachedEventModel = eventStore.queryByEnrollmentAndProgramStage(enrollment, + programStageUid); + + dataElementToDataValues.clear(); + if (cachedEventModel != null) { + dataElementToDataValues = getTrackedEntityDataValues(cachedEventModel.uid()); + } + } + } + + TrackedEntityDataValue dataValue; + dataValue = dataElementToDataValues.get(de); + + String value; + if (dataValue == null || dataValue.value() == null || dataValue.value().isEmpty()) { + value = "0"; + } else { + value = formatDataValue(dataValue); + valueCount++; + zeroPosValueCount = isZeroOrPositive(value) ? (zeroPosValueCount + 1) : zeroPosValueCount; + } + + matcher.appendReplacement(buffer, TextUtils.quote(value)); + + } else if (KEY_ATTRIBUTE.equals(key)) { + if (enrollment == null) { + continue; + } + + if (uid != null) { + if (cachedEnrollment == null) { + cachedEnrollment = enrollmentStore.queryByUid(enrollment); + attributeToAttributeValues = getTrackedEntityAttributeValues(cachedEnrollment + .trackedEntityInstance()); + } + TrackedEntityAttributeValue attributeValue = attributeToAttributeValues.get(uid); + String value; + if (attributeValue == null || attributeValue.value() == null || + attributeValue.value().isEmpty()) { + value = NULL_REPLACEMENT; + } else { + value = attributeValue.value(); + + valueCount++; + zeroPosValueCount = isZeroOrPositive(value) ? (zeroPosValueCount + 1) : zeroPosValueCount; + } + matcher.appendReplacement(buffer, TextUtils.quote(value)); + } + } else if (KEY_CONSTANT.equals(key)) { + ConstantModel constant = constantStore.selectByUid(uid, ConstantModel.factory); + + if (constant != null) { + matcher.appendReplacement(buffer, String.valueOf(constant.value())); + } + } else if (KEY_PROGRAM_VARIABLE.equals(key)) { + Date date = null; + + if (enrollment != null) { //in case of single event without reg + if (cachedEnrollment == null) { + cachedEnrollment = enrollmentStore.queryByUid(enrollment); + } + + if (ENROLLMENT_DATE.equals(uid)) { + date = cachedEnrollment.dateOfEnrollment(); + } else if (INCIDENT_DATE.equals(uid)) { + date = cachedEnrollment.dateOfIncident(); + } + } + + if (EVENT_DATE.equals(uid) && event != null) { + cachedEventModel = eventStore.queryByUid(event); + date = cachedEventModel.eventDate(); + } + + if (CURRENT_DATE.equals(uid)) { + date = currentDate; + } + + if (date != null) { + valueCount++; + matcher.appendReplacement(buffer, TextUtils.quote(DateUtils.getMediumDateString(date))); + } + } + } + + if(valueCount <= 0) { + return null; + } + + expression = TextUtils.appendTail(matcher, buffer); + + buffer = new StringBuffer(); + matcher = VALUECOUNT_PATTERN.matcher(expression); + + while (matcher.find()) { + String var = matcher.group(1); + + if (VAR_VALUE_COUNT.equals(var)) { + matcher.appendReplacement(buffer, String.valueOf(valueCount)); + } else if (VAR_ZERO_POS_VALUE_COUNT.equals(var)) { + matcher.appendReplacement(buffer, String.valueOf(zeroPosValueCount)); + } + } + + return TextUtils.appendTail(matcher, buffer); + } + + private Map getTrackedEntityAttributeValues(String tei) { + Map attributeToAttributeValues = new HashMap<>(); + List trackedEntityAttributeValues = + trackedEntityAttributeValueStore.queryByTrackedEntityInstance(tei); + if(trackedEntityAttributeValues != null) { + for (TrackedEntityAttributeValue value : trackedEntityAttributeValues) { + attributeToAttributeValues.put(value.trackedEntityAttribute(), value); + } + } + return attributeToAttributeValues; + } + + private Map getTrackedEntityDataValues(String eventUid) { + Map dataElementToDataValues = new HashMap<>(); + List trackedEntityDataValues = + trackedEntityDataValueStore.queryTrackedEntityDataValues(eventUid); + if (trackedEntityDataValues != null) { + for (TrackedEntityDataValue dataValue : trackedEntityDataValues) { + dataElementToDataValues.put(dataValue.dataElement(), dataValue); + } + } + return dataElementToDataValues; + } + + private String formatDataValue(TrackedEntityDataValue dataValue) { + if(dataElementStore.selectByUid(dataValue.dataElement(), DataElementModel.factory) + .valueType() == ValueType.BOOLEAN) { + if(dataValue.value().equals("true")) { + return "1"; + } else { + return "0"; + } + } else if(dataValue.value().endsWith(".")) { + return (dataValue.value() + "0"); + } else if(dataValue.value().contains(".")) { + return dataValue.value(); + } else { + return dataValue.value() + ".0"; + } + } + + private Double getValue(String enrollment, String event, String indicatorUid) { + String expression = parseIndicatorExpression(enrollment, event, indicatorUid); + Double value; + try { + value = ExpressionUtils.evaluateToDouble(expression, null); + } catch (JexlException e) { + value = null; + } catch (IllegalStateException e){ + value = null; + } + return value; + } + + private static boolean isZeroOrPositive(String value) { + return MathUtils.isNumeric(value) && Double.valueOf(value) >= 0d; + } + + public static ProgramIndicatorEngine create(DatabaseAdapter databaseAdapter) { + return new ProgramIndicatorEngine(ProgramIndicatorStore.create(databaseAdapter), + new TrackedEntityDataValueStoreImpl(databaseAdapter), + new EnrollmentStoreImpl(databaseAdapter), + new EventStoreImpl(databaseAdapter), + DataElementStore.create(databaseAdapter), ConstantStore.create(databaseAdapter), + new TrackedEntityAttributeValueStoreImpl(databaseAdapter)); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/support/DateUtils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/support/DateUtils.java new file mode 100644 index 0000000000..016151c182 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/support/DateUtils.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016, University of Oslo + * * All rights reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * * list of conditions and the following disclaimer. + * * + * * Redistributions in binary form must reproduce the above copyright notice, + * * this list of conditions and the following disclaimer in the documentation + * * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * * be used to endorse or promote products derived from this software without + * * specific prior written permission. + * * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package org.hisp.dhis.android.core.utils.support; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author Lars Helge Overland + */ +public final class DateUtils { + + static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; + + private DateUtils() { + // no instances + } + + /** + * Formats a Date to the format YYYY-MM-DD. + * + * @param date the Date to parse. + * @return A formatted date string. Null if argument is null. + */ + public static String getMediumDateString(Date date) { + final SimpleDateFormat format = new SimpleDateFormat(); + + format.applyPattern(DEFAULT_DATE_FORMAT); + + return date == null ? null : format.format(date); + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/support/ExpressionUtils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/support/ExpressionUtils.java new file mode 100644 index 0000000000..3f0413e470 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/support/ExpressionUtils.java @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2016, University of Oslo + * * All rights reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * * list of conditions and the following disclaimer. + * * + * * Redistributions in binary form must reproduce the above copyright notice, + * * this list of conditions and the following disclaimer in the documentation + * * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * * be used to endorse or promote products derived from this software without + * * specific prior written permission. + * * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package org.hisp.dhis.android.core.utils.support; + +import android.util.Log; + +import org.apache.commons.jexl2.Expression; +import org.apache.commons.jexl2.JexlContext; +import org.apache.commons.jexl2.JexlEngine; +import org.apache.commons.jexl2.JexlException; +import org.apache.commons.jexl2.MapContext; +import org.apache.commons.lang3.StringUtils; +import org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +/** + * @author Lars Helge Overland + */ +public final class ExpressionUtils { + private static final String CLASS_TAG = ExpressionUtils.class.getSimpleName(); + private static final JexlEngine JEXL = new JexlEngine(); + private static final JexlEngine JEXL_STRICT = new JexlEngine(); + + private static final Map EL_SQL_MAP = new HashMap<>(); + private static final String IGNORED_KEYWORDS_REGEX = + "(^|[^:])(SUM|sum|AVERAGE|average|COUNT|count|STDDEV|stddev|VARIANCE|variance|MIN|min|MAX|max|NONE|none)"; + + private static final Pattern NUMERIC_PATTERN = Pattern.compile("^(-?0|-?[1-9]\\d*)(\\.\\d+)?$"); + + private ExpressionUtils() { + // no instances + } + + static { + Map functions = new HashMap<>(); + functions.put(ExpressionFunctions.NAMESPACE, ExpressionFunctions.class); + + JEXL.setFunctions(functions); + JEXL.setCache(512); + JEXL.setSilent(false); + JEXL.setLenient(true); // Lenient + + JEXL_STRICT.setFunctions(functions); + JEXL_STRICT.setCache(512); + JEXL_STRICT.setSilent(false); + JEXL_STRICT.setStrict(true); // Strict + + EL_SQL_MAP.put("&&", "and"); + EL_SQL_MAP.put("\\|\\|", "or"); + EL_SQL_MAP.put("==", "="); + + //TODO Add support for textual operators like eq, ne and lt + } + + /** + * Evaluates the given expression. The given variables will be substituted + * in the expression. + * + * @param expression the expression. + * @param vars the variables, can be null. + * @return the result of the evaluation. + */ + private static Object evaluate(String expression, Map vars) { + try { + return evaluate(expression, vars, false); + } catch (Exception e) { + Log.e(CLASS_TAG, e.toString()); + return null; + } + } + + /** + * @param expression the expression. + * @param vars the variables, can be null. + * @param strict indicates whether to use strict or lenient engine mode. + * @return the result of the evaluation. + */ + private static Object evaluate(String expression, Map vars, boolean strict) { + String formattedExpression = expression.replaceAll(IGNORED_KEYWORDS_REGEX, StringUtils.EMPTY); + + JexlEngine engine = strict ? JEXL_STRICT : JEXL; + + Expression exp = engine.createExpression(formattedExpression); + + JexlContext context = vars == null ? new MapContext() : new MapContext(vars); + + return exp.evaluate(context); + } + + /** + * Evaluates the given expression. The given variables will be substituted + * in the expression. Converts the result of the evaluation to a Double. + * Throws an IllegalStateException if the result could not be converted to + * a Double + * + * @param expression the expression. + * @param vars the variables, can be null. + * @return the result of the evaluation. + */ + public static Double evaluateToDouble(String expression, Map vars) { + Object result = evaluate(expression, vars); + + if (result == null) { + throw new IllegalStateException("Result must be not null"); + } + + if (!isNumeric(String.valueOf(result))) { + throw new IllegalStateException("Result must be numeric: " + result + ", " + result.getClass()); + } + + return Double.valueOf(String.valueOf(result)); + } + + /** + * Evaluates the given expression to true or false. The given variables will + * be substituted in the expression. + * + * @param expression the expression. + * @param vars the variables, can be null. + * @return true or false. + */ + public static boolean isTrue(String expression, Map vars) { + Object result = evaluate(expression, vars); + + return result instanceof Boolean && (Boolean) result; + } + + /** + * Indicates whether the given expression is valid and evaluates to true or + * false. + * + * @param expression the expression. + * @param vars the variables, can be null. + * @return true or false. + */ + public static boolean isBoolean(String expression, Map vars) { + try { + Object result = evaluate(expression, vars); + + return result instanceof Boolean; + } catch (JexlException ex) { + return false; + } + } + + public static boolean isBoolean(String value) { + return value != null && ("true".equals(value) || "false".equals(value)); + } + + /** + * Indicates whether the given expression is valid, i.e. can be successfully + * evaluated. + * + * @param expression the expression. + * @param vars the variables, can be null. + * @return true or false. + */ + public static boolean isValid(String expression, Map vars) { + try { + Object result = evaluate(expression, vars, true); + + return result != null; + } catch (JexlException ex) { + //TODO Masking bug in Jexl, fix + return ex.getMessage().contains("divide error"); + } + } + + /** + * Indicates whether the given value is numeric. + * + * @param value the value. + * @return true or false. + */ + public static boolean isNumeric(String value) { + return NUMERIC_PATTERN.matcher(value).matches(); + } + + /** + * Converts the given expression into a valid SQL clause. + * + * @param expression the expression. + * @return an SQL clause. + */ + public static String asSql(String expression) { + if (expression == null) { + return null; + } + + String result = ""; + for (Map.Entry entry : EL_SQL_MAP.entrySet()) { + result = expression.replaceAll(entry.getKey(), entry.getValue()); + } + + return result; + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/support/MathUtils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/support/MathUtils.java new file mode 100644 index 0000000000..b0f071310c --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/support/MathUtils.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2016, University of Oslo + * * All rights reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * * list of conditions and the following disclaimer. + * * + * * Redistributions in binary form must reproduce the above copyright notice, + * * this list of conditions and the following disclaimer in the documentation + * * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * * be used to endorse or promote products derived from this software without + * * specific prior written permission. + * * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package org.hisp.dhis.android.core.utils.support; + +import java.util.regex.Pattern; + +/** + * @author Lars Helge Overland + */ +public final class MathUtils { + + private static final String NUMERIC_REGEXP = "^(-?0|-?[1-9]\\d*)(\\.\\d+)?(E(-)?\\d+)?$"; + private static final Pattern NUMERIC_PATTERN = Pattern.compile(NUMERIC_REGEXP); + + private MathUtils() { + // no instances + } + + /** + * Returns a number rounded off to the given number of decimals. + * + * @param value the value to round off. + * @param decimals the number of decimals. + * @return a number rounded off to the given number of decimals. + */ + static double getRounded(double value, int decimals) { + final double factor = Math.pow(10, decimals); + + return Math.round(value * factor) / factor; + } + + /** + * Returns a rounded off number. + *
    + *
  • If value is exclusively between 1 and -1 it will have 2 decimals.
  • + *
  • If value if greater or equal to 1 the value will have 1 decimal.
  • + *
+ * + * @param value the value to round off. + * @return a rounded off number. + */ + public static double getRounded(double value) { + if (value < 1d && value > -1d) { + return getRounded(value, 2); + } else { + return getRounded(value, 1); + } + } + + /** + * Returns true if the provided string argument is to be considered numeric. + * + * @param value the value. + * @return true if the provided string argument is to be considered numeric. + */ + public static boolean isNumeric(String value) { + return value != null && isDouble(value) && NUMERIC_PATTERN.matcher(value).matches(); + } + + private static boolean isDouble(String value) { + try { + Double.valueOf(value); + return true; + } catch (NumberFormatException e) { + return false; + } + } + +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/support/StringUtils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/support/StringUtils.java new file mode 100644 index 0000000000..88a7cd9446 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/support/StringUtils.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.utils.support; + +public final class StringUtils { + + private StringUtils() { + // no instances + } + + public static boolean isEmpty(CharSequence charSequence) { + return charSequence == null || charSequence.length() == 0; + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/support/TextUtils.java b/core/src/main/java/org/hisp/dhis/android/core/utils/support/TextUtils.java new file mode 100644 index 0000000000..dcd26793f9 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/support/TextUtils.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016, University of Oslo + * * All rights reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * * list of conditions and the following disclaimer. + * * + * * Redistributions in binary form must reproduce the above copyright notice, + * * this list of conditions and the following disclaimer in the documentation + * * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * * be used to endorse or promote products derived from this software without + * * specific prior written permission. + * * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package org.hisp.dhis.android.core.utils.support; + +import java.util.regex.Matcher; + +/** + * @author Lars Helge Overland + */ +public final class TextUtils { + + private TextUtils() { + // no instances + } + + /** + * Null-safe method for writing the items of a string array out as a string + * separated by the given char separator. + * + * @param array the array. + * @param separator the separator of the array items. + * @return a string. + */ + public static String toString(String[] array, String separator) { + StringBuilder builder = new StringBuilder(); + + if (array != null && array.length > 0) { + for (String string : array) { + builder.append(string).append(separator); + } + + builder.deleteCharAt(builder.length() - 1); + } + + return builder.toString(); + } + + /** + * Returns the string representation of the object, or null if the object is + * null. + * + * @param object the object. + * @return the string representation. + */ + public static String toString(Object object) { + return object == null ? null : object.toString(); + } + + /** + * Invokes append tail on matcher with the given string buffer, and returns + * the string buffer as a string. + * + * @param matcher the matcher. + * @param sb the string buffer. + * @return a string. + */ + public static String appendTail(Matcher matcher, StringBuffer sb) { + matcher.appendTail(sb); + return sb.toString(); + } + + /** + * Returns a quoted string (uses doubles quotes), or keep it unchanged if the string is numeric. + * + * @param value the input string. + * @return the quoted string. + */ + public static String quote(String value) { + return MathUtils.isNumeric(value) ? value : "\"" + value.replace("\"", "\\\"") + "\""; + } + + /** + * Takes a double and returns a string without the decimal part if it's all zeros. + * + * @param value the input numeric value. + * @return a string. + */ + public static String fromDouble(Double value) { + if (value != null && !Double.isNaN(value)) { + Double rounded = MathUtils.getRounded(value, 2); + return String.valueOf(rounded).replaceAll("\\.0+$", ""); + } + + return ""; + } +} diff --git a/core/src/main/java/org/hisp/dhis/android/core/utils/support/math/ExpressionFunctions.java b/core/src/main/java/org/hisp/dhis/android/core/utils/support/math/ExpressionFunctions.java new file mode 100644 index 0000000000..dc1b378292 --- /dev/null +++ b/core/src/main/java/org/hisp/dhis/android/core/utils/support/math/ExpressionFunctions.java @@ -0,0 +1,410 @@ +/* + * Copyright (c) 2016, University of Oslo + * * All rights reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * * list of conditions and the following disclaimer. + * * + * * Redistributions in binary form must reproduce the above copyright notice, + * * this list of conditions and the following disclaimer in the documentation + * * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * * be used to endorse or promote products derived from this software without + * * specific prior written permission. + * * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +package org.hisp.dhis.android.core.utils.support.math; + +import org.hisp.dhis.android.core.utils.support.ExpressionUtils; +import org.joda.time.DateTime; +import org.joda.time.Months; +import org.joda.time.Years; + +import java.text.ParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.hisp.dhis.android.core.utils.support.DateUtils.getMediumDateString; +import static org.hisp.dhis.android.core.utils.support.StringUtils.isEmpty; + +/** + * This class has been copied/pasted from Android Tracker Capture SDK. Non-compatible methods have been commented out. + */ +/* + * Defines a set of functions that can be used in expressions in + * {@link org.hisp.dhis.android.sdk.persistence.models.ProgramRule}s + * and {@link org.hisp.dhis.android.sdk.persistence.models.ProgramIndicator}s + * Please note that {@link VariableService#initialize(Enrollment, Event)} needs to be called before + * the functions in this class are called. + */ + +@SuppressWarnings("PMD.GodClass") +public final class ExpressionFunctions { + public static final String NAMESPACE = "d2"; + + private ExpressionFunctions() { + // no instances + } + + /** + * Function which will return zero if the argument is a negative number. + * + * @param value the value, must be a number. + * @return a Double. + */ + public static Double zing(Number value) { + if (value == null) { + return null; + } + + return Math.max(0d, value.doubleValue()); + } + + /** + * Function which will return one if the argument is zero or a positive + * number, and zero if not. + * + * @param value the value, must be a number. + * @return a Double. + */ + public static Double oizp(Number value) { + if (value == null) { + return null; + } + + return value.doubleValue() >= 0d ? 1d : 0d; + } + + /** + * Function which will return the count of zero or positive values among the + * given argument values. + * + * @param values the arguments. + * @return an Integer. + */ + public static Integer zpvc(Number... values) { + if (values == null || values.length == 0) { + throw new IllegalArgumentException("Argument is null or empty"); + } + + int count = 0; + + for (Number value : values) { + if (value != null && value.doubleValue() >= 0d) { + count++; + } + } + + return count; + } + + /** + * Functions which will return the true value if the condition is true, false + * value if not. + * + * @param condititon the condition. + * @param trueValue the true value. + * @param falseValue the false value. + * @return an Object. + */ + public static Object condition(String condititon, Object trueValue, Object falseValue) { + return ExpressionUtils.isTrue(condititon, null) ? trueValue : falseValue; + } + + /** + * Function which will return the number of days between the two given dates. + * + * @param start the start date. + * @param end the end date. + * @return number of days between dates. + */ + public static Integer daysBetween(String start, String end) throws ParseException { + if(isEmpty(start) || isEmpty(end)) { + return 0; + } + DateTime startDate = new DateTime(start); + DateTime endDate = new DateTime(end); + return (int) (endDate.getMillis() - startDate.getMillis()) / 86400000; + } + + public static Integer weeksBetween(String start, String end) throws ParseException { + if(isEmpty(start) || isEmpty(end)) { + return 0; + } + DateTime startDate = new DateTime(start); + DateTime endDate = new DateTime(end); + return (int) (endDate.getMillis() - startDate.getMillis()) / (86400000 * 7); + } + + public static Integer monthsBetween(String start, String end) throws ParseException { + if(isEmpty(start) || isEmpty(end)) { + return 0; + } + DateTime startDate = new DateTime(start); + DateTime endDate = new DateTime(end); + return Months.monthsBetween(startDate.withDayOfMonth(1), endDate.withDayOfMonth(1)).getMonths(); + } + + public static Integer yearsBetween(String start, String end) { + if(isEmpty(start) || isEmpty(end)) { + return 0; + } + DateTime startDate = new DateTime(start); + DateTime endDate = new DateTime(end); + return Years.yearsBetween(startDate.withDayOfMonth(1).withMonthOfYear(1), endDate.withDayOfMonth(1) + .withMonthOfYear(1)).getYears(); + } + + public static Integer floor(Number value) { + if (value == null) { + throw new IllegalArgumentException(); + } + return (int) Math.floor(value.doubleValue()); + } + + public static Integer modulus(Number dividend, Number divisor) { + if (dividend == null || divisor == null) { + throw new IllegalArgumentException(); + } + return dividend.intValue() % divisor.intValue(); + } + + public static String concatenate(Object... values) { + String returnString = ""; + for(Object value : values) { + returnString = returnString.concat(String.valueOf(value)); + } + return returnString; + } + + public static String addDays(String date, Number daysToAdd) { + if (date == null || daysToAdd == null) { + throw new IllegalArgumentException(); + } + DateTime dateTime = new DateTime(date); + DateTime newDateTime = dateTime.plusDays(daysToAdd.intValue()); + return getMediumDateString(newDateTime.toDate()); + } + + /* + public static Integer count(String variableName) { + ProgramRuleVariable programRuleVariable = VariableService.getInstance().getProgramRuleVariableMap() + .get(variableName); + Integer count = 0; + if(programRuleVariable != null) { + if(programRuleVariable.isHasValue()) { + if(programRuleVariable.getAllValues() != null) { + count = programRuleVariable.getAllValues().size(); + } else { + //If there is a value found for the variable, the count is 1 even if there is no list of + //alternate values + //This happens for variables of "DATAELEMENT_CURRENT_STAGE" and "TEI_ATTRIBUTE" + count = 1; + } + } + } + return count; + } + + public static Integer countIfZeroPos(String variableName) { + ProgramRuleVariable programRuleVariable = VariableService.getInstance().getProgramRuleVariableMap() + .get(variableName); + + Integer count = 0; + + if(programRuleVariable != null) { + if( programRuleVariable.isHasValue() ) { + if(programRuleVariable.getAllValues() != null && programRuleVariable.getAllValues().size() > 0) { + for(int i = 0; i < programRuleVariable.getAllValues().size(); i++) { + Double value = getVariableValue(programRuleVariable, programRuleVariable.getAllValues().get(i)); + if(value != null && value >= 0.0) { + count++; + } + } + } else { + //The variable has a value, but no list of alternates. + //This means we only compare the elements real value + Double value = getVariableValue(programRuleVariable, programRuleVariable.getVariableValue()); + if(value != null && value >= 0.0) { + count = 1; + } + } + } + } + + return count; + } + + public static Integer countIfValue(String variableName, String textToCompare) { + ProgramRuleVariable programRuleVariable = VariableService.getInstance().getProgramRuleVariableMap() + .get(variableName); + + Integer count = 0; + if(programRuleVariable != null) { + + if( programRuleVariable.isHasValue() ) { + if( programRuleVariable.getAllValues() != null ) { + for(int i = 0; i < programRuleVariable.getAllValues().size(); i++) { + if(textToCompare.equals(programRuleVariable.getAllValues().get(i))) { + count++; + } + } + } else { + //The variable has a value, but no list of alternates. + //This means we compare the standard variablevalue + if(textToCompare.equals(programRuleVariable.getVariableValue())) { + count = 1; + } + } + } + } + + return count; + } + */ + + public static Double ceil(double value) { + return Math.ceil(value); + } + + public static Long round(double value) { + return Math.round(value); + } + + /* + public static Boolean hasValue(String variableName) { + ProgramRuleVariable programRuleVariable = VariableService.getInstance().getProgramRuleVariableMap() + .get(variableName); + boolean valueFound = false; + if(programRuleVariable != null) { + if(programRuleVariable.isHasValue()){ + valueFound = true; + } + } + return valueFound; + } + + public static String lastEventDate(String variableName) { + ProgramRuleVariable programRuleVariable = VariableService.getInstance().getProgramRuleVariableMap() + .get(variableName); + String valueFound = ""; + if(programRuleVariable != null) { + if(programRuleVariable.getVariableEventDate() != null) { + valueFound = programRuleVariable.getVariableEventDate(); + } + } + return valueFound; + } + */ + + public static Boolean validatePattern(String inputToValidate, String patternString) { + Pattern pattern = Pattern.compile(patternString); + Matcher matcher = pattern.matcher(inputToValidate); + return matcher.matches(); + } + + public static Boolean validatePattern(long inputToValidate, String patternString) { + String inputString = Long.toString(inputToValidate); + return validatePattern(inputString, patternString); + } + + /** + * Return a substring from the beginning of a string up to a given length. + * + * @param inputString input value. + * @param length of the substring. + * @return the left substring. + */ + public static String left(String inputString, int length) { + if (inputString == null) { + return ""; + } + int safeLength = Math.min(Math.max(0, length), inputString.length()); + return inputString.substring(0, safeLength); + } + + /** + * Return a substring of the end of a string up to a given length. + * + * @param inputString input value. + * @param length of the substring. + * @return the right substring. + */ + public static String right(String inputString, int length) { + if (inputString == null) { + return ""; + } + int safeLength = Math.min(Math.max(0, length), inputString.length()); + return inputString.substring(inputString.length() - safeLength); + } + + /** + * Return the length of a given string. + * + * @param inputString input value. + * @return the length of the string + */ + public static Integer length(String inputString) { + return inputString == null ? 0 : inputString.length(); + } + + /** + * Split a string given a separator and get the nth item. + * + * @param inputString input value. + * @param splitString separator value. + * @param fieldIndex item index to get from the split. + * @return the field after split. + */ + public static String split(String inputString, String splitString, int fieldIndex) { + if (inputString == null || splitString == null) { + return ""; + } + String[] fields = inputString.split(Pattern.quote(splitString)); + return fieldIndex >= 0 && fieldIndex < fields.length ? fields[fieldIndex] : ""; + } + + /** + * Return a substring from a start index up to an end index (not included). + * + * @param inputString input value. + * @param startIndex start index. + * @param endIndex end index (not included) + * @return the substring. + */ + public static String substring(String inputString, int startIndex, int endIndex) { + if (inputString == null) { + return ""; + } + int safeStartIndex = Math.min(Math.max(0, startIndex), inputString.length()); + int safeEndIndex = Math.min(Math.max(0, endIndex), inputString.length()); + return inputString.substring(safeStartIndex, safeEndIndex); + } + + /* + private static Double getVariableValue(ProgramRuleVariable programRuleVariable, String evaluated) { + if (evaluated == null) + return null; + try { + String value = VariableService.processSingleValue(evaluated, programRuleVariable.getVariableType()); + return Double.parseDouble(value); + } catch (NumberFormatException ex) { + return null; + } + } + */ +} diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java index 8df314a78a..58c03ba054 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/server/Dhis2MockServer.java @@ -81,6 +81,11 @@ public void enqueueMockResponse(String fileName) throws IOException { server.enqueue(response); } + public void enqueueLoginResponses() throws IOException { + enqueueMockResponse("login.json"); + enqueueMockResponse("system_info.json"); + } + public void enqueueMetadataResponses() throws IOException { enqueueMetadataResponsesWithUserAndOrgUnits( "user.json", @@ -100,14 +105,12 @@ private void enqueueMetadataResponsesWithUserAndOrgUnits(String userPath, String enqueueMockResponse(userPath); enqueueMockResponse("categories.json"); enqueueMockResponse("category_combos.json"); - enqueueMockResponse("programs_with_access.json"); enqueueMockResponse("programs.json"); enqueueMockResponse("program_stages.json"); enqueueMockResponse("tracked_entities.json"); enqueueMockResponse("relationship_types.json"); enqueueMockResponse("option_sets.json"); enqueueMockResponse(orgUnitPath); - enqueueMockResponse("data_sets_with_access.json"); enqueueMockResponse("data_sets.json"); enqueueMockResponse("data_elements.json"); enqueueMockResponse("indicators.json"); diff --git a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/utils/FillPropertiesTestUtils.java b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/utils/FillPropertiesTestUtils.java index 5c775446d6..b757292589 100644 --- a/core/src/sharedTest/java/org/hisp/dhis/android/core/data/utils/FillPropertiesTestUtils.java +++ b/core/src/sharedTest/java/org/hisp/dhis/android/core/data/utils/FillPropertiesTestUtils.java @@ -73,7 +73,7 @@ public class FillPropertiesTestUtils { public static final boolean DELETED = false; - private static Date parseDate(String dateStr) { + public static Date parseDate(String dateStr) { try { return BaseIdentifiableObject.DATE_FORMAT.parse(dateStr); } catch (ParseException e) { diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java index b0d486c9bb..2dca3b1e2c 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/MetadataCallShould.java @@ -33,11 +33,9 @@ import org.hisp.dhis.android.core.category.CategoryCombo; import org.hisp.dhis.android.core.dataelement.DataElement; import org.hisp.dhis.android.core.dataset.DataSetParentCall; -import org.hisp.dhis.android.core.option.OptionSet; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.organisationunit.OrganisationUnitCall; import org.hisp.dhis.android.core.program.Program; -import org.hisp.dhis.android.core.program.ProgramParentCall; import org.hisp.dhis.android.core.settings.SystemSetting; import org.hisp.dhis.android.core.systeminfo.SystemInfo; import org.hisp.dhis.android.core.user.User; @@ -100,10 +98,7 @@ public class MetadataCallShould extends BaseCallShould { private Payload organisationUnitPayload; @Mock - private Payload programWithAccessPayload; - - @Mock - private Payload optionSetPayload; + private Payload programPayload; @Mock private Payload dataElementPayload; @@ -114,15 +109,6 @@ public class MetadataCallShould extends BaseCallShould { @Mock private CategoryCombo categoryCombo; - @Mock - private DataAccess dataAccess; - - @Mock - private Access access; - - @Mock - private Program programWithAccess; - @Mock private Call> systemInfoEndpointCall; @@ -139,10 +125,7 @@ public class MetadataCallShould extends BaseCallShould { private Call>> categoryComboEndpointCall; @Mock - private Call>> programAccessEndpointCall; - - @Mock - private Call programParentCall; + private Call>> programParentCall; @Mock private Call dataSetParentCall; @@ -159,9 +142,6 @@ public class MetadataCallShould extends BaseCallShould { @Mock private SimpleCallFactory userCallFactory; - @Mock - private SimpleCallFactory> programAccessCallFactory; - @Mock private SimpleCallFactory> categoryCallFactory; @@ -169,7 +149,7 @@ public class MetadataCallShould extends BaseCallShould { private SimpleCallFactory> categoryComboCallFactory; @Mock - private ProgramParentCall.Factory programParentCallFactory; + private SimpleCallFactory> programParentCallFactory; @Mock private OrganisationUnitCall.Factory organisationUnitCallFactory; @@ -192,12 +172,8 @@ public void setUp() throws Exception { when(organisationUnit.path()).thenReturn("path/to/org/unit"); when(user.userCredentials()).thenReturn(userCredentials); when(user.organisationUnits()).thenReturn(Collections.singletonList(organisationUnit)); - when(dataAccess.read()).thenReturn(true); - when(access.data()).thenReturn(dataAccess); - when(programWithAccess.access()).thenReturn(access); // Payloads - when(programWithAccessPayload.items()).thenReturn(Collections.singletonList(programWithAccess)); when(categoryPayload.items()).thenReturn(Collections.singletonList(category)); when(categoryComboPayload.items()).thenReturn(Collections.singletonList(categoryCombo)); when(organisationUnitPayload.items()).thenReturn(Collections.singletonList(organisationUnit)); @@ -207,9 +183,7 @@ public void setUp() throws Exception { when(systemInfoCallFactory.create(databaseAdapter, retrofit)).thenReturn(systemInfoEndpointCall); when(systemSettingCallFactory.create(any(GenericCallData.class))).thenReturn(systemSettingEndpointCall); when(userCallFactory.create(any(GenericCallData.class))).thenReturn(userCall); - when(programAccessCallFactory.create(any(GenericCallData.class))).thenReturn(programAccessEndpointCall); - when(programParentCallFactory.create(any(GenericCallData.class), anySetOf(String.class))) - .thenReturn(programParentCall); + when(programParentCallFactory.create(any(GenericCallData.class))).thenReturn(programParentCall); when(categoryCallFactory.create(any(GenericCallData.class))).thenReturn(categoryEndpointCall); when(categoryComboCallFactory.create(any(GenericCallData.class))).thenReturn(categoryComboEndpointCall); when(organisationUnitCallFactory.create(any(GenericCallData.class), same(user), anySetOf(String.class))) @@ -223,8 +197,7 @@ public void setUp() throws Exception { when(userCall.call()).thenReturn(Response.success(user)); when(categoryEndpointCall.call()).thenReturn(Response.success(categoryPayload)); when(categoryComboEndpointCall.call()).thenReturn(Response.success(categoryComboPayload)); - when(programParentCall.call()).thenReturn(Response.success(optionSetPayload)); - when(programAccessEndpointCall.call()).thenReturn(Response.success(programWithAccessPayload)); + when(programParentCall.call()).thenReturn(Response.success(programPayload)); when(organisationUnitEndpointCall.call()).thenReturn(Response.success(organisationUnitPayload)); when(dataSetParentCall.call()).thenReturn(Response.success(dataElementPayload)); @@ -237,7 +210,6 @@ public void setUp() throws Exception { userCallFactory, categoryCallFactory, categoryComboCallFactory, - programAccessCallFactory, programParentCallFactory, organisationUnitCallFactory, dataSetParentCallFactory); @@ -300,12 +272,6 @@ public void fail_when_category_combo_call_fail() throws Exception { @Test @SuppressWarnings("unchecked") - public void fail_when_program_access_call_fail() throws Exception { - when(programAccessEndpointCall.call()).thenReturn(errorResponse); - verifyFail(metadataCall.call()); - } - - @Test public void fail_when_program_call_fail() throws Exception { when(programParentCall.call()).thenReturn(errorResponse); verifyFail(metadataCall.call()); diff --git a/core/src/test/java/org/hisp/dhis/android/core/common/SQLStatementBuilderShould.java b/core/src/test/java/org/hisp/dhis/android/core/common/SQLStatementBuilderShould.java index 2b47a2f695..f133e2f6eb 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/common/SQLStatementBuilderShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/common/SQLStatementBuilderShould.java @@ -27,6 +27,11 @@ */ package org.hisp.dhis.android.core.common; +import org.hisp.dhis.android.core.dataset.DataSetModel; +import org.hisp.dhis.android.core.dataset.DataSetOrganisationUnitLinkModel; +import org.hisp.dhis.android.core.legendset.LegendModel; +import org.hisp.dhis.android.core.legendset.LegendSetModel; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,32 +52,32 @@ public void setUp() throws IOException { "Test_Column_Name1", "Test_Column_Name2" }; - this.builder = new SQLStatementBuilder("Test_Table", columns, columns, columns, columns); + this.builder = new SQLStatementBuilder("Test_Table", columns, columns); } @Test - public void generate_insert_statement() throws Exception { + public void generate_insert_statement() { assertThat(builder.insert()).isEqualTo( "INSERT INTO Test_Table (Test_Column_Name1, Test_Column_Name2) VALUES (?, ?);" ); } @Test - public void generate_update_statement() throws Exception { + public void generate_update_statement() { assertThat(builder.update()).isEqualTo( "UPDATE Test_Table SET Test_Column_Name1=?, Test_Column_Name2=? WHERE uid=?;" ); } @Test - public void generate_delete_statement() throws Exception { + public void generate_delete_statement() { assertThat(builder.deleteById()).isEqualTo( "DELETE FROM Test_Table WHERE uid=?;" ); } @Test - public void generate_create_model_table_statement() throws Exception { + public void generate_create_model_table_statement() { String statement = SQLStatementBuilder.createModelTable("Test_Table", "Test_Column_Name TEXT"); @@ -82,7 +87,7 @@ public void generate_create_model_table_statement() throws Exception { } @Test - public void generate_create_identifiable_table_statement() throws Exception { + public void generate_create_identifiable_table_statement() { String statement = SQLStatementBuilder.createIdentifiableModelTable("Test_Table", "Test_Column_Name TEXT"); @@ -98,7 +103,7 @@ public void generate_create_identifiable_table_statement() throws Exception { } @Test - public void generate_create_nameable_table_statement() throws Exception { + public void generate_create_nameable_table_statement() { String statement = SQLStatementBuilder.createNameableModelTable("Test_Table", "Test_Column_Name TEXT"); @@ -118,23 +123,81 @@ public void generate_create_nameable_table_statement() throws Exception { } @Test - public void generate_delete_where_statement() throws Exception { - assertThat(builder.deleteWhere()).isEqualTo( - "DELETE FROM Test_Table WHERE Test_Column_Name1=? AND Test_Column_Name2=?;" + public void generate_create_organisation_unit_table_statement() { + String createOrganisationUnitTable = + SQLStatementBuilder.createNameableModelTable(OrganisationUnitModel.TABLE, + OrganisationUnitModel.Columns.PATH + " TEXT," + + OrganisationUnitModel.Columns.OPENING_DATE + " TEXT," + + OrganisationUnitModel.Columns.CLOSED_DATE + " TEXT," + + OrganisationUnitModel.Columns.LEVEL + " INTEGER," + + OrganisationUnitModel.Columns.PARENT + " TEXT," + + OrganisationUnitModel.Columns.DISPLAY_NAME_PATH + " TEXT" + ); + + assertThat(createOrganisationUnitTable).isEqualTo("CREATE TABLE OrganisationUnit (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, shortName TEXT, displayShortName TEXT, description TEXT, displayDescription TEXT, path TEXT,openingDate TEXT,closedDate TEXT,level INTEGER,parent TEXT,displayNamePath TEXT);"); + } + + @Test + public void generate_create_data_set_organisation_unit_table_statement() { + String createDataSetOrganisationUnitLinkTable = + SQLStatementBuilder.createModelTable(DataSetOrganisationUnitLinkModel.TABLE, + DataSetOrganisationUnitLinkModel.Columns.DATA_SET + " TEXT NOT NULL," + + DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + " TEXT NOT NULL," + + " FOREIGN KEY (" + DataSetOrganisationUnitLinkModel.Columns.DATA_SET + ") " + + " REFERENCES " + DataSetModel.TABLE + " (" + DataSetModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " FOREIGN KEY (" + DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ") " + + " REFERENCES " + OrganisationUnitModel.TABLE + " (" + + OrganisationUnitModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED," + + " UNIQUE (" + DataSetOrganisationUnitLinkModel.Columns.DATA_SET + ", " + + DataSetOrganisationUnitLinkModel.Columns.ORGANISATION_UNIT + ")" + ); + + assertThat(createDataSetOrganisationUnitLinkTable).isEqualTo("CREATE TABLE DataSetOrganisationUnitLink (_id INTEGER PRIMARY KEY AUTOINCREMENT, dataSet TEXT NOT NULL,organisationUnit TEXT NOT NULL, FOREIGN KEY (dataSet) REFERENCES DataSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, FOREIGN KEY (organisationUnit) REFERENCES OrganisationUnit (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, UNIQUE (dataSet, organisationUnit));"); + } + + @Test + public void generate_create_legend_table_statement() { + String createLegendTable = + SQLStatementBuilder.createIdentifiableModelTable(LegendModel.TABLE, + LegendModel.Columns.START_VALUE + " REAL," + + LegendModel.Columns.END_VALUE + " REAL," + + LegendModel.Columns.COLOR + " TEXT," + + LegendModel.Columns.LEGEND_SET + " TEXT," + + " FOREIGN KEY ( " + LegendModel.Columns.LEGEND_SET + ")" + + " REFERENCES " + LegendSetModel.TABLE + " (" + LegendSetModel.Columns.UID + ")" + + " ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED" + ); + + assertThat(createLegendTable).isEqualTo("CREATE TABLE Legend (_id INTEGER PRIMARY KEY AUTOINCREMENT, uid TEXT NOT NULL UNIQUE, code TEXT, name TEXT, displayName TEXT, created TEXT, lastUpdated TEXT, startValue REAL,endValue REAL,color TEXT,legendSet TEXT, FOREIGN KEY ( legendSet) REFERENCES LegendSet (uid) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED);"); + } + + @Test + public void generate_select_where_statement() { + assertThat(builder.selectWhere("WH_CLAUSE")).isEqualTo( + "SELECT * FROM Test_Table WHERE WH_CLAUSE;" + ); + } + + @Test + public void generate_select_where_with_limit_statement() { + assertThat(builder.selectWhereWithLimit("WH_CLAUSE", 3)).isEqualTo( + "SELECT * FROM Test_Table WHERE WH_CLAUSE LIMIT 3;" ); } @Test - public void generate_select_where_statement() throws Exception { - assertThat(builder.selectWhere()).isEqualTo( - "SELECT * FROM Test_Table WHERE Test_Column_Name1=? AND Test_Column_Name2=?" + public void generate_count_where_statement() { + assertThat(builder.countWhere("WH_CLAUSE")).isEqualTo( + "SELECT COUNT(*) FROM Test_Table WHERE WH_CLAUSE;" ); } @Test - public void generate_select_by_uid_statement() throws Exception { + public void generate_select_by_uid_statement() { assertThat(builder.selectByUid()).isEqualTo( - "SELECT * FROM Test_Table WHERE uid=?" + "SELECT * FROM Test_Table WHERE uid=?;" ); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterConverterShould.java b/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterConverterShould.java index 2b3ee15a53..c4fdcce9f0 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterConverterShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterConverterShould.java @@ -78,7 +78,7 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters() TestService service = retrofit.create(TestService.class); service.test( InFilter.create(Field.create("id"), values), - GtFilter.create(Field.create("lastUpdated"), "updatedDate") + SingleValueFilter.gt(Field.create("lastUpdated"), "updatedDate") ).execute(); RecordedRequest request = server.takeRequest(); @@ -105,7 +105,7 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters_an TestService service = retrofit.create(TestService.class); service.test( InFilter.create(Field.create("id"), values), - GtFilter.create(Field.create("lastUpdated"), "updatedDate") + SingleValueFilter.gt(Field.create("lastUpdated"), "updatedDate") ).execute(); RecordedRequest request = server.takeRequest(); @@ -137,7 +137,7 @@ public void returns_correct_path_when_create_a_retrofit_request_using_filters_an Field.create("name"), Field.create("displayName") ).build(), InFilter.create(Field.create("id"), values), - GtFilter.create(Field.create("lastUpdated"), "updatedDate") + SingleValueFilter.gt(Field.create("lastUpdated"), "updatedDate") ).execute(); RecordedRequest request = server.takeRequest(); @@ -165,7 +165,7 @@ public void returns_correct_path_when_create_a_retrofit_request_ignoring_null_fi TestService service = retrofit.create(TestService.class); service.test( InFilter.create(Field.create("id"), values), - GtFilter.create(Field.create("lastUpdated"), null) + SingleValueFilter.gt(Field.create("lastUpdated"), null) ).execute(); RecordedRequest request = server.takeRequest(); @@ -192,7 +192,7 @@ public void returns_correct_path_when_create_a_retrofit_request_ignoring_empty_s TestService service = retrofit.create(TestService.class); service.test( InFilter.create(Field.create("id"), values), - GtFilter.create(Field.create("lastUpdated"), "") + SingleValueFilter.gt(Field.create("lastUpdated"), "") ).execute(); RecordedRequest request = server.takeRequest(); @@ -217,7 +217,7 @@ public void returns_correct_path_when_create_a_retrofit_request_with_in_filter_a TestService service = retrofit.create(TestService.class); service.test( InFilter.create(Field.create("id"), values), - GtFilter.create(Field.create("lastUpdated"), "") + SingleValueFilter.gt(Field.create("lastUpdated"), "") ).execute(); RecordedRequest request = server.takeRequest(); diff --git a/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterShould.java b/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterShould.java index 21a1949041..786fdc5b0b 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/data/api/FilterShould.java @@ -41,7 +41,7 @@ public class FilterShould { @Test public void return_null_filter_when_creates_with_null_params() { - Filter filter = GtFilter.create(null, null); + Filter filter = SingleValueFilter.gt(null, null); assertThat(filter).isNull(); } @@ -56,7 +56,7 @@ public void return_correct_values_when_create_field_filter() { @Test public void have_the_equals_method_conform_to_contract() { - EqualsVerifier.forClass(GtFilter.create(Field.create(""), "a").getClass()) + EqualsVerifier.forClass(SingleValueFilter.gt(Field.create(""), "a").getClass()) .suppress(Warning.NULL_FIELDS) .verify(); } diff --git a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java index 0d3cfe031e..12682b05f0 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/OrganisationUnitCallUnitShould.java @@ -189,7 +189,7 @@ public void setUp() throws IOException { organisationUnits = Collections.singletonList(organisationUnit); when(user.organisationUnits()).thenReturn(organisationUnits); - when(organisationUnitService.getOrganisationUnits( + when(organisationUnitService.getOrganisationUnitWithDescendants( uidCaptor.capture(), fieldsCaptor.capture(), filterCaptor.capture(), descendantsCaptor.capture(), pagingCaptor.capture() )).thenReturn(retrofitCall); diff --git a/core/src/test/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitHandlerShould.java new file mode 100644 index 0000000000..2bc21b9257 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/organisationunit/SearchOrganisationUnitHandlerShould.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.organisationunit; + +import org.assertj.core.util.Lists; +import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.hisp.dhis.android.core.user.UserOrganisationUnitLinkModel; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(JUnit4.class) +public class SearchOrganisationUnitHandlerShould { + + @Mock + private IdentifiableObjectStore organisationUnitStore; + + @Mock + private ObjectWithoutUidStore userOrganisationUnitLinkStore; + + @Mock + private OrganisationUnit organisationUnit; + + private String userUid = "userUid"; + private String organisationUnitUid = "orgUnitUid"; + + private GenericHandler handler; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(organisationUnit.uid()).thenReturn(organisationUnitUid); + + handler = new SearchOrganisationUnitHandler(organisationUnitStore, userOrganisationUnitLinkStore, userUid); + } + + @Test + public void persist_organisation_unit_user_link() { + UserOrganisationUnitLinkModel linkModel = UserOrganisationUnitLinkModel + .builder() + .organisationUnit(organisationUnitUid) + .user(userUid).root(false) + .organisationUnitScope(OrganisationUnitModel.Scope.SCOPE_TEI_SEARCH.toString()) + .build(); + + handler.handleMany(Lists.newArrayList(organisationUnit), new OrganisationUnitModelBuilder()); + verify(userOrganisationUnitLinkStore).updateOrInsertWhere(linkModel); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramEndpointCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramEndpointCallShould.java index 72cece5219..6893ff7cb0 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramEndpointCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramEndpointCallShould.java @@ -28,13 +28,11 @@ package org.hisp.dhis.android.core.program; import org.hisp.dhis.android.core.calls.Call; -import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseCallShould; import org.hisp.dhis.android.core.common.CallException; -import org.hisp.dhis.android.core.common.DataAccess; +import org.hisp.dhis.android.core.common.EmptyQuery; import org.hisp.dhis.android.core.common.GenericHandler; import org.hisp.dhis.android.core.common.Payload; -import org.hisp.dhis.android.core.common.UidsQuery; import org.hisp.dhis.android.core.data.api.Fields; import org.hisp.dhis.android.core.data.api.Filter; import org.hisp.dhis.android.core.resource.ResourceModel; @@ -53,9 +51,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Set; import retrofit2.Response; @@ -63,6 +59,7 @@ import static org.assertj.core.api.Java6Assertions.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.same; import static org.mockito.Mockito.inOrder; @@ -83,12 +80,6 @@ public class ProgramEndpointCallShould extends BaseCallShould { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private retrofit2.Call> programCall; - @Mock - private DataAccess dataAccess; - - @Mock - private Access access; - @Mock private Program program; @@ -99,7 +90,7 @@ public class ProgramEndpointCallShould extends BaseCallShould { private ArgumentCaptor> lastUpdatedFilter; @Captor - private ArgumentCaptor> idInFilter; + private ArgumentCaptor accessDataReadFilter; @Mock private Payload payload; @@ -114,24 +105,15 @@ public class ProgramEndpointCallShould extends BaseCallShould { public void setUp() throws Exception { super.setUp(); - Set uids = new HashSet<>(); - uids.add("test_program_uid"); - uids.add("test_program1_uid"); - - UidsQuery uidsQuery = UidsQuery.create(uids, 64); - - programEndpointCall = new ProgramEndpointCall(genericCallData, programService, programHandler, uidsQuery); + programEndpointCall = new ProgramEndpointCall(genericCallData, programService, programHandler, + EmptyQuery.create()); when(program.uid()).thenReturn("test_program_uid"); - when(program.access()).thenReturn(access); - when(access.data()).thenReturn(dataAccess); - when(dataAccess.read()).thenReturn(true); - when(dataAccess.write()).thenReturn(true); programList = Collections.singletonList(program); when(payload.items()).thenReturn(programList); - when(programService.getPrograms(any(Fields.class), any(Filter.class), any(Filter.class), anyBoolean()) + when(programService.getPrograms(any(Fields.class), any(Filter.class), anyString(), anyBoolean()) ).thenReturn(programCall); } @@ -146,7 +128,7 @@ public void return_correct_fields_when_invoke_server() throws Exception { when(programCall.execute()).thenReturn(Response.success(payload)); when(programService.getPrograms( - fieldsCaptor.capture(), lastUpdatedFilter.capture(), idInFilter.capture(), anyBoolean()) + fieldsCaptor.capture(), lastUpdatedFilter.capture(), accessDataReadFilter.capture(), anyBoolean()) ).thenReturn(programCall); diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java index 61971fad1f..984e22a254 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramHandlerShould.java @@ -61,7 +61,7 @@ public class ProgramHandlerShould { private ProgramRuleVariableHandler programRuleVariableHandler; @Mock - private ProgramIndicatorHandler programIndicatorHandler; + private GenericHandler programIndicatorHandler; @Mock private ProgramRuleHandler programRuleHandler; @@ -70,6 +70,9 @@ public class ProgramHandlerShould { private GenericHandler programTrackedEntityAttributeHandler; + @Mock + private GenericHandler programSectionHandler; + @Mock private GenericHandler styleHandler; @@ -103,6 +106,9 @@ public class ProgramHandlerShould { @Mock private List programRuleVariables; + @Mock + private List programSections; + // object to test private ProgramHandler programHandler; @@ -112,7 +118,7 @@ public void setUp() throws Exception { programHandler = new ProgramHandler( programStore, programRuleVariableHandler, programIndicatorHandler, programRuleHandler, - programTrackedEntityAttributeHandler, styleHandler); + programTrackedEntityAttributeHandler, programSectionHandler, styleHandler); when(program.uid()).thenReturn("test_program_uid"); when(program.code()).thenReturn("test_program_code"); @@ -148,6 +154,7 @@ public void setUp() throws Exception { when(program.programIndicators()).thenReturn(programIndicators); when(program.programRules()).thenReturn(programRules); when(program.programRuleVariables()).thenReturn(programRuleVariables); + when(program.programSections()).thenReturn(programSections); when(program.access()).thenReturn(access); when(access.data()).thenReturn(dataAccess); when(dataAccess.read()).thenReturn(true); @@ -164,7 +171,8 @@ public void call_program_tracked_entity_attributes_handler() throws Exception { @Test public void call_program_indicator_handler() throws Exception { programHandler.handle(program, new ProgramModelBuilder()); - verify(programIndicatorHandler).handleProgramIndicator(null, programIndicators); + verify(programIndicatorHandler).handleMany(anyListOf(ProgramIndicator.class), + any(ProgramIndicatorModelBuilder.class)); } @Test @@ -184,4 +192,11 @@ public void call_style_handler() throws Exception { programHandler.handle(program, new ProgramModelBuilder()); verify(styleHandler).handle(same(program.style()), any(ObjectStyleModelBuilder.class)); } + + @Test + public void call_program_section_handler() throws Exception { + programHandler.handle(program, new ProgramModelBuilder()); + verify(programSectionHandler).handleMany(anyListOf(ProgramSection.class), + any(ProgramSectionModelBuilder.class)); + } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandlerShould.java index faea9ef50f..670a73ee0a 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramIndicatorHandlerShould.java @@ -28,6 +28,8 @@ package org.hisp.dhis.android.core.program; import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; import org.hisp.dhis.android.core.legendset.LegendSet; import org.hisp.dhis.android.core.legendset.LegendSetModel; @@ -41,12 +43,9 @@ import org.mockito.MockitoAnnotations; import java.util.ArrayList; -import java.util.Date; import java.util.List; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; @@ -57,7 +56,7 @@ @RunWith(JUnit4.class) public class ProgramIndicatorHandlerShould { @Mock - private ProgramIndicatorStore programIndicatorStore; + private IdentifiableObjectStore programIndicatorStore; @Mock private ProgramStageSectionProgramIndicatorLinkStore programStageSectionProgramIndicatorLinkStore; @@ -75,7 +74,9 @@ public class ProgramIndicatorHandlerShould { private LegendSet legendSet; @Mock - private Program program; + private ObjectWithUid program; + + private ProgramIndicatorModelBuilder programIndicatorModelBuilder; // object to test private ProgramIndicatorHandler programIndicatorHandler; @@ -97,6 +98,8 @@ public void setUp() throws Exception { programIndicators = new ArrayList<>(); programIndicators.add(programIndicator); + programIndicatorModelBuilder = new ProgramIndicatorModelBuilder(); + legendSets = new ArrayList<>(); legendSets.add(legendSet); @@ -108,18 +111,14 @@ public void setUp() throws Exception { @Test public void do_nothing_when_passing_null_argument() throws Exception { - programIndicatorHandler.handleProgramIndicator(null, null); + programIndicatorHandler.handle(null, null); // verify that program indicator store is never called verify(programIndicatorStore, never()).delete(anyString()); - verify(programIndicatorStore, never()).update(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), - anyBoolean(), anyString(), anyString(), anyString(), anyInt(), anyString(), anyString()); + verify(programIndicatorStore, never()).update(any(ProgramIndicatorModel.class)); - verify(programIndicatorStore, never()).insert(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), - anyBoolean(), anyString(), anyString(), anyString(), anyInt(), anyString()); + verify(programIndicatorStore, never()).insert(any(ProgramIndicatorModel.class)); // verify that link store is never called verify(programStageSectionProgramIndicatorLinkStore, never()).update( @@ -134,20 +133,11 @@ public void do_nothing_when_passing_null_argument() throws Exception { public void delete_shouldDeleteProgramIndicator() throws Exception { when(programIndicator.deleted()).thenReturn(Boolean.TRUE); - programIndicatorHandler.handleProgramIndicator(null, programIndicators); + programIndicatorHandler.handleMany(programIndicators, programIndicatorModelBuilder); // verify that delete is called once verify(programIndicatorStore, times(1)).delete(programIndicator.uid()); - // verify that update and insert is never called - verify(programIndicatorStore, never()).update(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), - anyBoolean(), anyString(), anyString(), anyString(), anyInt(), anyString(), anyString()); - - verify(programIndicatorStore, never()).insert(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), anyString(), anyString(), - anyBoolean(), anyString(), anyString(), anyString(), anyInt(), anyString()); - // verify that link store is never called because it is self-maintained through sqLite verify(programStageSectionProgramIndicatorLinkStore, never()).update( anyString(), anyString(), anyString(), anyString() @@ -158,25 +148,10 @@ public void delete_shouldDeleteProgramIndicator() throws Exception { @Test public void update_shouldUpdateProgramIndicatorWithoutProgramStageSection() throws Exception { - when(programIndicatorStore.update( - anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString())).thenReturn(1); - - programIndicatorHandler.handleProgramIndicator(null, programIndicators); + programIndicatorHandler.handleMany(programIndicators, programIndicatorModelBuilder); // verify that update is called once - verify(programIndicatorStore, times(1)).update(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString()); - - // verify that insert and delete is never called - verify(programIndicatorStore, never()).insert(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString()); + verify(programIndicatorStore, times(1)).updateOrInsert(any(ProgramIndicatorModel.class)); verify(programIndicatorStore, never()).delete(anyString()); @@ -191,29 +166,11 @@ public void update_shouldUpdateProgramIndicatorWithoutProgramStageSection() thro @Test public void update_shouldUpdateProgramIndicatorWithProgramStageSection() throws Exception { - when(programIndicatorStore.update( - anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString())).thenReturn(1); - - when(programStageSectionProgramIndicatorLinkStore.update( - anyString(), anyString(), anyString(), anyString()) - ).thenReturn(1); - - programIndicatorHandler.handleProgramIndicator("test_program_stage_section", programIndicators); + programIndicatorHandler.handleManyWithProgramStageSection(programIndicators, programIndicatorModelBuilder, + "test_program_stage_section"); // verify that update is called once - verify(programIndicatorStore, times(1)).update(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString()); - - // verify that insert and delete is never called - verify(programIndicatorStore, never()).insert(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString()); + verify(programIndicatorStore, times(1)).updateOrInsert(any(ProgramIndicatorModel.class)); verify(programIndicatorStore, never()).delete(anyString()); @@ -221,107 +178,11 @@ public void update_shouldUpdateProgramIndicatorWithProgramStageSection() throws verify(programStageSectionProgramIndicatorLinkStore, times(1)).update( anyString(), anyString(), anyString(), anyString() ); - - verify(programStageSectionProgramIndicatorLinkStore, never()).insert(anyString(), anyString()); - } - - @Test - public void insert_shouldInsertProgramIndicatorWithoutProgramStageSection() throws Exception { - when(programIndicatorStore.update( - anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString())).thenReturn(0); - - programIndicatorHandler.handleProgramIndicator(null, programIndicators); - - // verify that insert is called once - verify(programIndicatorStore, times(1)).insert(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString()); - - // verify that update is called since we update before we insert - verify(programIndicatorStore, times(1)).update(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString()); - - // verify that delete is never called - verify(programIndicatorStore, never()).delete(anyString()); - - // verify that link store is never called - verify(programStageSectionProgramIndicatorLinkStore, never()).update( - anyString(), anyString(), anyString(), anyString() - ); - - verify(programStageSectionProgramIndicatorLinkStore, never()).insert(anyString(), anyString()); - - } - - - @Test - public void insert_shouldInsertProgramIndicatorWithProgramStageSection() throws Exception { - when(programIndicatorStore.update( - anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString())).thenReturn(0); - - when(programStageSectionProgramIndicatorLinkStore.update( - anyString(), anyString(), anyString(), anyString()) - ).thenReturn(0); - - programIndicatorHandler.handleProgramIndicator("test_program_stage_section_uid", programIndicators); - - // verify that insert is called once - verify(programIndicatorStore, times(1)).insert(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString()); - - // verify that update is called since we update before we insert - verify(programIndicatorStore, times(1)).update(anyString(), anyString(), anyString(), anyString(), - any(Date.class), any(Date.class), anyString(), anyString(), - anyString(), anyString(), anyBoolean(), anyString(), anyString(), - anyString(), anyInt(), anyString(), anyString()); - - // verify that delete is never called - verify(programIndicatorStore, never()).delete(anyString()); - - // verify that link store's insert method is called once - verify(programStageSectionProgramIndicatorLinkStore, times(1)).insert(anyString(), anyString()); - - // verify that link store's update method is called once since we try to update before we insert - verify(programStageSectionProgramIndicatorLinkStore, times(1)).update( - anyString(), anyString(), anyString(), anyString() - ); - - } - - @Test - public void call_program_indicator_legend_set_link_store() throws Exception { - programIndicatorHandler.handleProgramIndicator(null, programIndicators); - verify(programIndicatorLegendSetLinkStore).updateOrInsertWhere(any(ProgramIndicatorLegendSetLinkModel.class)); - } - - @Test - public void not_call_program_indicator_legend_set_link_store_if_program_stage_section_not_null() throws - Exception { - programIndicatorHandler.handleProgramIndicator("program_stage_section_uid", programIndicators); - verify(programIndicatorLegendSetLinkStore, never()) - .updateOrInsertWhere(any(ProgramIndicatorLegendSetLinkModel.class)); } @Test public void call_program_indicator_legend_set_handler() throws Exception { - programIndicatorHandler.handleProgramIndicator(null, programIndicators); + programIndicatorHandler.handleMany(programIndicators, programIndicatorModelBuilder); verify(legendSetHandler).handleMany(eq(legendSets), any(LegendSetModelBuilder.class)); } - - @Test - public void not_call_program_indicator_legend_set_handler() throws Exception { - programIndicatorHandler.handleProgramIndicator("program_stage_section_uid", programIndicators); - verify(legendSetHandler, never()).handleMany(eq(legendSets), any(LegendSetModelBuilder.class)); - } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramIndicatorModelBuilderShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramIndicatorModelBuilderShould.java new file mode 100644 index 0000000000..6090f0fe41 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramIndicatorModelBuilderShould.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.ModelBuilder; +import org.hisp.dhis.android.core.common.NameableModelBuilderAbstractShould; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.legendset.LegendSet; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.IOException; +import java.util.ArrayList; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DESCRIPTION; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_DESCRIPTION; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_SHORT_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.SHORT_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.UID; + +@RunWith(JUnit4.class) +public class ProgramIndicatorModelBuilderShould extends NameableModelBuilderAbstractShould { + + private static final Boolean DISPLAY_IN_FORM = true; + private static final String EXPRESSION = "test_expression"; + private static final String DIMENSION_ITEM = "test_dimension_item"; + private static final String FILTER = "test_filter"; + private static final Integer DECIMALS = 3; + private static final String PROGRAM = "program_uid"; + + @Override + @Before + public void setUp() throws IOException { + super.setUp(); + } + + @Override + protected ProgramIndicator buildPojo() { + return ProgramIndicator.create( + UID, + CODE, + NAME, + DISPLAY_NAME, + CREATED, + LAST_UPDATED, + SHORT_NAME, + DISPLAY_SHORT_NAME, + DESCRIPTION, + DISPLAY_DESCRIPTION, + DISPLAY_IN_FORM, + EXPRESSION, + DIMENSION_ITEM, + FILTER, + DECIMALS, + DELETED, + ObjectWithUid.create(PROGRAM), + new ArrayList()); + } + + @Override + protected ModelBuilder modelBuilder() { + return new ProgramIndicatorModelBuilder(); + } + + @Test + public void copy_pojo_program_indicator_properties() { + assertThat(model.displayInForm()).isEqualTo(pojo.displayInForm()); + assertThat(model.expression()).isEqualTo(pojo.expression()); + assertThat(model.dimensionItem()).isEqualTo(pojo.dimensionItem()); + assertThat(model.filter()).isEqualTo(pojo.filter()); + assertThat(model.decimals()).isEqualTo(pojo.decimals()); + assertThat(model.program()).isEqualTo(pojo.program().uid()); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramParentCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramParentCallShould.java index 573f700875..9e0d53179e 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramParentCallShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramParentCallShould.java @@ -27,11 +27,8 @@ */ package org.hisp.dhis.android.core.program; -import org.assertj.core.util.Sets; import org.hisp.dhis.android.core.calls.Call; -import org.hisp.dhis.android.core.common.Access; import org.hisp.dhis.android.core.common.BaseCallShould; -import org.hisp.dhis.android.core.common.DataAccess; import org.hisp.dhis.android.core.common.ObjectWithUid; import org.hisp.dhis.android.core.common.Payload; import org.hisp.dhis.android.core.common.SimpleCallFactory; @@ -82,12 +79,6 @@ public class ProgramParentCallShould extends BaseCallShould { @Mock private OptionSet optionSet; - @Mock - private DataAccess dataAccess; - - @Mock - private Access access; - @Mock private Program programWithAccess; @@ -116,7 +107,7 @@ public class ProgramParentCallShould extends BaseCallShould { private Call>> optionSetCall; @Mock - private UidsCallFactory programCallFactory; + private SimpleCallFactory> programCallFactory; @Mock private UidsCallFactory programStageCallFactory; @@ -143,11 +134,7 @@ public void setUp() throws Exception { ResponseBody.create(MediaType.parse("application/json"), "{}")); // Payload data - when(dataAccess.read()).thenReturn(true); - when(access.data()).thenReturn(dataAccess); - when(programWithAccess.access()).thenReturn(access); when(program.trackedEntityType()).thenReturn(trackedEntityType); - when(program.access()).thenReturn(access); when(program.programStages()).thenReturn(Collections.singletonList(programStageWithUid)); when(programStageWithUid.uid()).thenReturn("program_stage_uid"); when(trackedEntityType.uid()).thenReturn("test_tracked_entity_uid"); @@ -158,7 +145,7 @@ public void setUp() throws Exception { when(optionSetPayload.items()).thenReturn(Collections.singletonList(optionSet)); // Call factories - when(programCallFactory.create(same(genericCallData), any(Set.class))) + when(programCallFactory.create(same(genericCallData))) .thenReturn(programEndpointCall); when(programStageCallFactory.create(same(genericCallData), any(Set.class))) .thenReturn(programStageEndpointCall); @@ -176,8 +163,6 @@ public void setUp() throws Exception { when(optionSetCall.call()).thenReturn(Response.success(optionSetPayload)); when(programStageEndpointCall.call()).thenReturn(Response.success(programStagePayload)); - Set uids = Sets.newLinkedHashSet("programUid"); - // Metadata call programParentCall = new ProgramParentCall( genericCallData, @@ -185,8 +170,7 @@ public void setUp() throws Exception { programStageCallFactory, trackedEntityCallFactory, relationshiptTypeCallFactory, - optionSetCallFactory, - uids); + optionSetCallFactory); } @After @@ -202,11 +186,11 @@ public void succeed_when_endpoint_calls_succeed() throws Exception { @Test @SuppressWarnings("unchecked") - public void return_last_response_items() throws Exception { + public void return_programs() throws Exception { Response response = programParentCall.call(); Payload payload = (Payload) response.body(); assertTrue(!payload.items().isEmpty()); - assertThat(payload.items().get(0)).isEqualTo(optionSet); + assertThat(payload.items().get(0)).isEqualTo(program); } @Test diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelBuilderShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelBuilderShould.java new file mode 100644 index 0000000000..acb9695080 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionAttributeLinkModelBuilderShould.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.io.IOException; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(JUnit4.class) +public class ProgramSectionAttributeLinkModelBuilderShould { + + @Mock + private ProgramSection programSection; + + @Mock + private ObjectWithUid attribute; + + private ProgramSectionAttributeLinkModel model; + + @Before + @SuppressWarnings("unchecked") + public void setUp() throws IOException { + MockitoAnnotations.initMocks(this); + + when(programSection.uid()).thenReturn("program_section_uid"); + when(attribute.uid()).thenReturn("attribute_uid"); + + model = buildModel(); + } + + private ProgramSectionAttributeLinkModel buildModel() { + return new ProgramSectionAttributeLinkModelBuilder(programSection).buildModel(attribute); + } + + @Test + public void copy_link_properties() { + assertThat(model.programSection()).isEqualTo(programSection.uid()); + assertThat(model.attribute()).isEqualTo(attribute.uid()); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionHandlerShould.java new file mode 100644 index 0000000000..be41a4820a --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionHandlerShould.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.GenericHandler; +import org.hisp.dhis.android.core.common.IdentifiableHandlerImpl; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ObjectStyle; +import org.hisp.dhis.android.core.common.ObjectStyleModel; +import org.hisp.dhis.android.core.common.ObjectStyleModelBuilder; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.hisp.dhis.android.core.common.ObjectWithoutUidStore; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.same; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(JUnit4.class) +public class ProgramSectionHandlerShould { + + @Mock + private IdentifiableObjectStore programSectionStore; + + @Mock + private ObjectWithoutUidStore programSectionAttributeLinkStore; + + @Mock + private GenericHandler styleHandler; + + @Mock + private ProgramSection programSection; + + // object to test + private ProgramSectionHandler programSectionHandler; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + programSectionHandler = new ProgramSectionHandler(programSectionStore, programSectionAttributeLinkStore, + styleHandler); + + List attributes = new ArrayList<>(); + attributes.add(ObjectWithUid.create("attribute_uid")); + when(programSection.attributes()).thenReturn(attributes); + } + + @Test + public void call_style_handler() throws Exception { + programSectionHandler.handle(programSection, new ProgramSectionModelBuilder()); + verify(styleHandler).handle(same(programSection.style()), any(ObjectStyleModelBuilder.class)); + } + + @Test + public void save_program_section_attribute_links() throws Exception { + programSectionHandler.handle(programSection, new ProgramSectionModelBuilder()); + verify(programSectionAttributeLinkStore).updateOrInsertWhere(any(ProgramSectionAttributeLinkModel.class)); + } + + @Test + public void extend_identifiable_handler_impl() { + IdentifiableHandlerImpl genericHandler = new ProgramSectionHandler( + null,null, null); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionModelBuilderShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionModelBuilderShould.java new file mode 100644 index 0000000000..8d978fb9df --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionModelBuilderShould.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.IdentifiableModelBuilderAbstractShould; +import org.hisp.dhis.android.core.common.ModelBuilder; +import org.hisp.dhis.android.core.common.ObjectStyle; +import org.hisp.dhis.android.core.common.ObjectWithUid; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.IOException; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CODE; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.COLOR; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.CREATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DELETED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DESCRIPTION; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.DISPLAY_NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.ICON; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.LAST_UPDATED; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.NAME; +import static org.hisp.dhis.android.core.data.utils.FillPropertiesTestUtils.UID; + +@RunWith(JUnit4.class) +public class ProgramSectionModelBuilderShould extends + IdentifiableModelBuilderAbstractShould { + + @Override + @Before + public void setUp() throws IOException { + super.setUp(); + } + + @Override + protected ProgramSection buildPojo() { + return ProgramSection.create( + UID, + CODE, + NAME, + DISPLAY_NAME, + CREATED, + LAST_UPDATED, + DESCRIPTION, + ObjectWithUid.create("program_uid"), + null, + 2, + ObjectStyle.create(COLOR, ICON), + "form_name", + DELETED); + } + + @Override + protected ModelBuilder modelBuilder() { + return new ProgramSectionModelBuilder(); + } + + @Test + public void copy_pojo_program_section_properties() { + assertThat(model.description()).isEqualTo(pojo.description()); + assertThat(model.program()).isEqualTo(pojo.program().uid()); + assertThat(model.sortOrder()).isEqualTo(pojo.sortOrder()); + assertThat(model.formName()).isEqualTo(pojo.formName()); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionShould.java new file mode 100644 index 0000000000..b650a99f24 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramSectionShould.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.program; + +import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.BaseObjectShould; +import org.hisp.dhis.android.core.common.ObjectShould; +import org.hisp.dhis.android.core.common.ObjectStyle; +import org.junit.Test; + +import java.io.IOException; +import java.text.ParseException; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +public class ProgramSectionShould extends BaseObjectShould implements ObjectShould { + + public ProgramSectionShould() { + super("program/program_section.json"); + } + + @Override + @Test + public void map_from_json_string() throws IOException, ParseException { + ProgramSection programSection = objectMapper.readValue(jsonStream, ProgramSection.class); + + assertThat(programSection.uid()).isEqualTo("Nc8OxbNuVH3"); + assertThat(programSection.code()).isEqualTo("Code"); + assertThat(programSection.lastUpdated()).isEqualTo( + BaseIdentifiableObject.parseDate("2018-05-15T08:14:06.767")); + assertThat(programSection.created()).isEqualTo( + BaseIdentifiableObject.DATE_FORMAT.parse("2018-05-15T08:14:06.767")); + assertThat(programSection.name()).isEqualTo("My Program Section"); + assertThat(programSection.displayName()).isEqualTo("My Program Section"); + + assertThat(programSection.description()).isEqualTo("Description"); + assertThat(programSection.programUid()).isEqualTo("IpHINAT79UW"); + assertThat(programSection.attributes().get(0).uid()).isEqualTo("zDhUuAYrxNC"); + assertThat(programSection.sortOrder()).isEqualTo(1); + assertThat(programSection.formName()).isEqualTo("formName"); + assertThat(programSection.style()).isEqualTo(ObjectStyle.create("#fff", "my-icon")); + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramShould.java index 245f2db2e9..caab043bfa 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramShould.java @@ -32,6 +32,8 @@ import org.hisp.dhis.android.core.Inject; import org.hisp.dhis.android.core.common.BaseIdentifiableObject; +import org.hisp.dhis.android.core.common.BaseObjectShould; +import org.hisp.dhis.android.core.common.ObjectShould; import org.junit.Test; import java.io.IOException; @@ -39,232 +41,17 @@ import static org.assertj.core.api.Java6Assertions.assertThat; -public class ProgramShould { +public class ProgramShould extends BaseObjectShould implements ObjectShould { + + public ProgramShould() { + super("program/program.json"); + } + + @Override @Test public void map_from_json_string() throws IOException, ParseException { ObjectMapper objectMapper = Inject.objectMapper(); - Program program = objectMapper.readValue("{\n" + - "\n" + - " \"lastUpdated\": \"2015-10-15T11:32:27.242\",\n" + - " \"id\": \"WSGAb5XwJ3Y\",\n" + - " \"created\": \"2014-06-06T20:44:21.375\",\n" + - " \"name\": \"WHO RMNCH Tracker\",\n" + - " \"shortName\": \"WHO RMNCH Tracker\",\n" + - " \"publicAccess\": \"rw------\",\n" + - " \"ignoreOverdueEvents\": false,\n" + - " \"skipOffline\": false,\n" + - " \"dataEntryMethod\": false,\n" + - " \"captureCoordinates\": false,\n" + - " \"enrollmentDateLabel\": \"Date of first visit\",\n" + - " \"onlyEnrollOnce\": false,\n" + - " \"version\": 11,\n" + - " \"selectIncidentDatesInFuture\": true,\n" + - " \"incidentDateLabel\": \"Date of incident\",\n" + - " \"selectEnrollmentDatesInFuture\": false,\n" + - " \"registration\": true,\n" + - " \"useFirstStageDuringRegistration\": false,\n" + - " \"displayName\": \"WHO RMNCH Tracker\",\n" + - " \"completeEventsExpiryDays\": 0,\n" + - " \"displayShortName\": \"WHO RMNCH Tracker\",\n" + - " \"externalAccess\": false,\n" + - " \"withoutRegistration\": false,\n" + - " \"displayFrontPageList\": false,\n" + - " \"programType\": \"WITH_REGISTRATION\",\n" + - " \"relationshipFromA\": true,\n" + - " \"relationshipText\": \"Add child\",\n" + - " \"displayIncidentDate\": false,\n" + - " \"expiryDays\": 0,\n" + - " \"minAttributesRequiredToSearch\": 3,\n" + - " \"maxTeiCountToReturn\": 2,\n" + - " \"categoryCombo\": {\n" + - " \"id\": \"p0KPaWEg3cf\"\n" + - " },\n" + - " \"trackedEntityType\": {\n" + - " \"id\": \"nEenWmSyUEp\"\n" + - " },\n" + - " \"relatedProgram\": {\n" + - " \"id\": \"IpHINAT79UW\"\n" + - " },\n" + - " \"relationshipType\": {\n" + - " \"id\": \"V2kkHafqs8G\"\n" + - " },\n" + - " \"user\": {\n" + - " \"id\": \"xE7jOejl9FI\"\n" + - " },\n" + - " \"programIndicators\": [ ],\n" + - " \"translations\": [ ],\n" + - " \"userGroupAccesses\": [ ],\n" + - " \"attributeValues\": [ ],\n" + - " \"validationCriterias\": [ ],\n" + - " \"userRoles\": [\n" + - " {\n" + - " \"id\": \"Ufph3mGRmMo\"\n" + - " },\n" + - " {\n" + - " \"id\": \"LGWLyWNro4x\"\n" + - " }\n" + - " ],\n" + - " \"programRuleVariables\": [\n" + - " {\n" + - " \"id\": \"varonrw1032\"\n" + - " },\n" + - " {\n" + - " \"id\": \"idLCptBEOF9\"\n" + - " },\n" + - " {\n" + - " \"id\": \"iGBDXK1Gbcb\"\n" + - " },\n" + - " {\n" + - " \"id\": \"varonrw1026\"\n" + - " },\n" + - " {\n" + - " \"id\": \"pJ79JBmuFT4\"\n" + - " },\n" + - " {\n" + - " \"id\": \"YnREl4QOKFB\"\n" + - " },\n" + - " {\n" + - " \"id\": \"varonrw1030\"\n" + - " },\n" + - " {\n" + - " \"id\": \"yrhN4QM8gqg\"\n" + - " },\n" + - " {\n" + - " \"id\": \"WS8wNA4Jvev\"\n" + - " },\n" + - " {\n" + - " \"id\": \"varonrw1027\"\n" + - " },\n" + - " {\n" + - " \"id\": \"OnXTZg6lPA6\"\n" + - " },\n" + - " {\n" + - " \"id\": \"Jx93QwiIP1B\"\n" + - " },\n" + - " {\n" + - " \"id\": \"varonrw1029\"\n" + - " },\n" + - " {\n" + - " \"id\": \"AU9n351Zwno\"\n" + - " },\n" + - " {\n" + - " \"id\": \"k8QP8SWkQtA\"\n" + - " },\n" + - " {\n" + - " \"id\": \"VY8KZyr8d2d\"\n" + - " },\n" + - " {\n" + - " \"id\": \"varonrw1028\"\n" + - " },\n" + - " {\n" + - " \"id\": \"varonrw1033\"\n" + - " },\n" + - " {\n" + - " \"id\": \"varonrw1031\"\n" + - " },\n" + - " {\n" + - " \"id\": \"WuSvlMvjeu9\"\n" + - " },\n" + - " {\n" + - " \"id\": \"d1XWbV9mlle\"\n" + - " },\n" + - " {\n" + - " \"id\": \"XJ3gR8WFYP1\"\n" + - " }\n" + - " ],\n" + - " \"programTrackedEntityAttributes\": [\n" + - " {\n" + - " \"id\": \"YGMlKXYa5xF\"\n" + - " },\n" + - " {\n" + - " \"id\": \"WZWEBrkJSAm\"\n" + - " },\n" + - " {\n" + - " \"id\": \"v4GVdtLY8KV\"\n" + - " },\n" + - " {\n" + - " \"id\": \"pasqxL7MU6h\"\n" + - " },\n" + - " {\n" + - " \"id\": \"B5ggND5eXU5\"\n" + - " },\n" + - " {\n" + - " \"id\": \"pCliTGHh5WS\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ypiK0ehyoCv\"\n" + - " },\n" + - " {\n" + - " \"id\": \"Z5eRPdPIL49\"\n" + - " },\n" + - " {\n" + - " \"id\": \"dHThsTGLdC3\"\n" + - " },\n" + - " {\n" + - " \"id\": \"eNdG4pvswEX\"\n" + - " }\n" + - " ],\n" + - " \"notificationTemplates\": [ ],\n" + - " \"programStages\": [\n" + - " {\n" + - " \"id\": \"WZbXY0S00lP\"\n" + - " },\n" + - " {\n" + - " \"id\": \"PUZaKR0Jh2k\"\n" + - " },\n" + - " {\n" + - " \"id\": \"edqlbukwRfQ\"\n" + - " },\n" + - " {\n" + - " \"id\": \"PFDfvmGpsR3\"\n" + - " },\n" + - " {\n" + - " \"id\": \"bbKtnxRZKEP\"\n" + - " }\n" + - " ],\n" + - " \"programRules\": [\n" + - " {\n" + - " \"id\": \"tO1D62oB0tq\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ruleonr1065\"\n" + - " },\n" + - " {\n" + - " \"id\": \"jZ6TKNCRhdt\"\n" + - " },\n" + - " {\n" + - " \"id\": \"HTKIQDVMu0K\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ruleonr1066\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ruleonr1055\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ruleonr1061\"\n" + - " },\n" + - " {\n" + - " \"id\": \"RtCIjfyRB9L\"\n" + - " },\n" + - " {\n" + - " \"id\": \"hpO8g3CRAeC\"\n" + - " },\n" + - " {\n" + - " \"id\": \"IdrDtQmRGrv\"\n" + - " },\n" + - " {\n" + - " \"id\": \"NkpU28ZlfVh\"\n" + - " },\n" + - " {\n" + - " \"id\": \"GTtHkDt4doY\"\n" + - " },\n" + - " {\n" + - " \"id\": \"ruleonr1062\"\n" + - " }\n" + - " ]\n" + - "\n" + - "}", Program.class); + Program program = objectMapper.readValue(jsonStream, Program.class); assertThat(program.lastUpdated()).isEqualTo( BaseIdentifiableObject.DATE_FORMAT.parse("2015-10-15T11:32:27.242")); @@ -303,56 +90,16 @@ public void map_from_json_string() throws IOException, ParseException { assertThat(program.programStages().get(0).uid()).isEqualTo("WZbXY0S00lP"); assertThat(program.programStages().get(1).uid()).isEqualTo("PUZaKR0Jh2k"); - assertThat(program.programStages().get(2).uid()).isEqualTo("edqlbukwRfQ"); - assertThat(program.programStages().get(3).uid()).isEqualTo("PFDfvmGpsR3"); - assertThat(program.programStages().get(4).uid()).isEqualTo("bbKtnxRZKEP"); assertThat(program.programRules().get(0).uid()).isEqualTo("tO1D62oB0tq"); assertThat(program.programRules().get(1).uid()).isEqualTo("ruleonr1065"); - assertThat(program.programRules().get(2).uid()).isEqualTo("jZ6TKNCRhdt"); - assertThat(program.programRules().get(3).uid()).isEqualTo("HTKIQDVMu0K"); - assertThat(program.programRules().get(4).uid()).isEqualTo("ruleonr1066"); - assertThat(program.programRules().get(5).uid()).isEqualTo("ruleonr1055"); - assertThat(program.programRules().get(6).uid()).isEqualTo("ruleonr1061"); - assertThat(program.programRules().get(7).uid()).isEqualTo("RtCIjfyRB9L"); - assertThat(program.programRules().get(8).uid()).isEqualTo("hpO8g3CRAeC"); - assertThat(program.programRules().get(9).uid()).isEqualTo("IdrDtQmRGrv"); - assertThat(program.programRules().get(10).uid()).isEqualTo("NkpU28ZlfVh"); - assertThat(program.programRules().get(11).uid()).isEqualTo("GTtHkDt4doY"); - assertThat(program.programRules().get(12).uid()).isEqualTo("ruleonr1062"); assertThat(program.programRuleVariables().get(0).uid()).isEqualTo("varonrw1032"); assertThat(program.programRuleVariables().get(1).uid()).isEqualTo("idLCptBEOF9"); - assertThat(program.programRuleVariables().get(2).uid()).isEqualTo("iGBDXK1Gbcb"); - assertThat(program.programRuleVariables().get(3).uid()).isEqualTo("varonrw1026"); - assertThat(program.programRuleVariables().get(4).uid()).isEqualTo("pJ79JBmuFT4"); - assertThat(program.programRuleVariables().get(5).uid()).isEqualTo("YnREl4QOKFB"); - assertThat(program.programRuleVariables().get(6).uid()).isEqualTo("varonrw1030"); - assertThat(program.programRuleVariables().get(7).uid()).isEqualTo("yrhN4QM8gqg"); - assertThat(program.programRuleVariables().get(8).uid()).isEqualTo("WS8wNA4Jvev"); - assertThat(program.programRuleVariables().get(9).uid()).isEqualTo("varonrw1027"); - assertThat(program.programRuleVariables().get(10).uid()).isEqualTo("OnXTZg6lPA6"); - assertThat(program.programRuleVariables().get(11).uid()).isEqualTo("Jx93QwiIP1B"); - assertThat(program.programRuleVariables().get(12).uid()).isEqualTo("varonrw1029"); - assertThat(program.programRuleVariables().get(13).uid()).isEqualTo("AU9n351Zwno"); - assertThat(program.programRuleVariables().get(14).uid()).isEqualTo("k8QP8SWkQtA"); - assertThat(program.programRuleVariables().get(15).uid()).isEqualTo("VY8KZyr8d2d"); - assertThat(program.programRuleVariables().get(16).uid()).isEqualTo("varonrw1028"); - assertThat(program.programRuleVariables().get(17).uid()).isEqualTo("varonrw1033"); - assertThat(program.programRuleVariables().get(18).uid()).isEqualTo("varonrw1031"); - assertThat(program.programRuleVariables().get(19).uid()).isEqualTo("WuSvlMvjeu9"); - assertThat(program.programRuleVariables().get(20).uid()).isEqualTo("d1XWbV9mlle"); - assertThat(program.programRuleVariables().get(21).uid()).isEqualTo("XJ3gR8WFYP1"); assertThat(program.programTrackedEntityAttributes().get(0).uid()).isEqualTo("YGMlKXYa5xF"); assertThat(program.programTrackedEntityAttributes().get(1).uid()).isEqualTo("WZWEBrkJSAm"); - assertThat(program.programTrackedEntityAttributes().get(2).uid()).isEqualTo("v4GVdtLY8KV"); - assertThat(program.programTrackedEntityAttributes().get(3).uid()).isEqualTo("pasqxL7MU6h"); - assertThat(program.programTrackedEntityAttributes().get(4).uid()).isEqualTo("B5ggND5eXU5"); - assertThat(program.programTrackedEntityAttributes().get(5).uid()).isEqualTo("pCliTGHh5WS"); - assertThat(program.programTrackedEntityAttributes().get(6).uid()).isEqualTo("ypiK0ehyoCv"); - assertThat(program.programTrackedEntityAttributes().get(7).uid()).isEqualTo("Z5eRPdPIL49"); - assertThat(program.programTrackedEntityAttributes().get(8).uid()).isEqualTo("dHThsTGLdC3"); - assertThat(program.programTrackedEntityAttributes().get(9).uid()).isEqualTo("eNdG4pvswEX"); + + assertThat(program.programSections().get(0).uid()).isEqualTo("FdpWnXhl7c1"); } -} +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandlerShould.java b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandlerShould.java index 13c47d55a9..1d2914e074 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandlerShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/program/ProgramStageSectionHandlerShould.java @@ -114,8 +114,8 @@ public void invoke_delete_when_handle_program_stage_section_set_as_deleted() thr anyString(), anyString() ); - verify(programIndicatorHandler, times(1)).handleProgramIndicator( - anyString(), anyListOf(ProgramIndicator.class) + verify(programIndicatorHandler, times(1)).handleManyWithProgramStageSection( + anyListOf(ProgramIndicator.class), any(ProgramIndicatorModelBuilder.class), anyString() ); } @@ -152,8 +152,8 @@ public void invoke_only_update_when_handle_program_stage_section_inserted() thro anyString(), anyString() ); - verify(programIndicatorHandler, times(1)).handleProgramIndicator( - anyString(), anyListOf(ProgramIndicator.class) + verify(programIndicatorHandler, times(1)).handleManyWithProgramStageSection( + anyListOf(ProgramIndicator.class), any(ProgramIndicatorModelBuilder.class), anyString() ); } @@ -190,8 +190,8 @@ public void invoke_update_and_insert_when_handle_program_stage_section_not_inser anyString(), anyString() ); - verify(programIndicatorHandler, times(1)).handleProgramIndicator( - anyString(), anyListOf(ProgramIndicator.class) + verify(programIndicatorHandler, times(1)).handleManyWithProgramStageSection( + anyListOf(ProgramIndicator.class), any(ProgramIndicatorModelBuilder.class), anyString() ); } @@ -216,8 +216,8 @@ public void do_nothing_when_passing_null_program_stage_uid() throws Exception { anyString(), anyString() ); - verify(programIndicatorHandler, never()).handleProgramIndicator( - anyString(), anyListOf(ProgramIndicator.class) + verify(programIndicatorHandler, never()).handleManyWithProgramStageSection( + anyListOf(ProgramIndicator.class), any(ProgramIndicatorModelBuilder.class), anyString() ); } @@ -242,8 +242,8 @@ public void do_nothing_when_passing_null_program_stage_section() throws Exceptio anyString(), anyString() ); - verify(programIndicatorHandler, never()).handleProgramIndicator( - anyString(), anyListOf(ProgramIndicator.class) + verify(programIndicatorHandler, never()).handleManyWithProgramStageSection( + anyListOf(ProgramIndicator.class), any(ProgramIndicatorModelBuilder.class), anyString() ); } @@ -267,8 +267,8 @@ public void do_nothing_when_passing_null_arguments() throws Exception { anyString(), anyString() ); - verify(programIndicatorHandler, never()).handleProgramIndicator( - anyString(), anyListOf(ProgramIndicator.class) + verify(programIndicatorHandler, never()).handleManyWithProgramStageSection( + anyListOf(ProgramIndicator.class), any(ProgramIndicatorModelBuilder.class), anyString() ); } } diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceEndPointCallShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceEndPointCallShould.java deleted file mode 100644 index cbb5844b6b..0000000000 --- a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceEndPointCallShould.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.hisp.dhis.android.core.trackedentity; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.hisp.dhis.android.core.data.api.FieldsConverterFactory; -import org.hisp.dhis.android.core.data.api.FilterConverterFactory; -import org.hisp.dhis.android.core.data.database.DatabaseAdapter; -import org.hisp.dhis.android.core.data.file.ResourcesFileReader; -import org.hisp.dhis.android.core.data.server.Dhis2MockServer; -import org.hisp.dhis.android.core.resource.ResourceHandler; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import java.io.IOException; -import java.util.Date; - -import retrofit2.Retrofit; -import retrofit2.converter.jackson.JacksonConverterFactory; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNull.notNullValue; - -public class TrackedEntityInstanceEndPointCallShould { - @Mock - private TrackedEntityInstanceService trackedEntityInstanceService; - - @Mock - private DatabaseAdapter databaseAdapter; - - @Mock - private ResourceHandler resourceHandler; - - @Mock - private TrackedEntityInstanceHandler trackedEntityInstanceHandler; - - @Mock - private Date serverDate; - - Dhis2MockServer dhis2MockServer; - Retrofit retrofit; - - @Before - @SuppressWarnings("unchecked") - public void setUp() throws IOException { - dhis2MockServer = new Dhis2MockServer(new ResourcesFileReader()); - - retrofit = new Retrofit.Builder() - .baseUrl(dhis2MockServer.getBaseEndpoint()) - .addConverterFactory(JacksonConverterFactory.create(new ObjectMapper())) - .addConverterFactory(FilterConverterFactory.create()) - .addConverterFactory(FieldsConverterFactory.create()) - .build(); - - MockitoAnnotations.initMocks(this); - } - - @Test(expected = IllegalArgumentException.class) - public void throw_illegal_argument_exception_if_uid_is_null() { - givenATrackedEntityInstanceEndPointCall(null); - } - - @Test - public void create_call_if_uid_is_not_null() { - TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = - givenATrackedEntityInstanceEndPointCall("PgmUFEQYZdt"); - assertThat(trackedEntityInstanceEndPointCall, is(notNullValue())); - } - - private TrackedEntityInstanceEndPointCall givenATrackedEntityInstanceEndPointCall( - String trackedEntityInstanceUid) { - TrackedEntityInstanceEndPointCall trackedEntityInstanceEndPointCall = - new TrackedEntityInstanceEndPointCall( - databaseAdapter, - trackedEntityInstanceService, trackedEntityInstanceHandler, - trackedEntityInstanceUid); - - return trackedEntityInstanceEndPointCall; - } -} diff --git a/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelperShould.java b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelperShould.java new file mode 100644 index 0000000000..ee05113455 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/trackedentity/TrackedEntityInstanceUidHelperShould.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.trackedentity; + +import org.assertj.core.util.Lists; +import org.assertj.core.util.Sets; +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.enrollment.Enrollment; +import org.hisp.dhis.android.core.event.Event; +import org.hisp.dhis.android.core.organisationunit.OrganisationUnitModel; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.ArrayList; +import java.util.Set; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class TrackedEntityInstanceUidHelperShould { + + @Mock + private IdentifiableObjectStore organisationUnitStore; + + @Mock + private TrackedEntityInstance tei1; + + @Mock + private TrackedEntityInstance tei2; + + @Mock + private Enrollment enrollment; + + @Mock + private Event event; + + private TrackedEntityInstanceUidHelper uidHelper; + + @Before + @SuppressWarnings("unchecked") + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + when(organisationUnitStore.selectUids()).thenReturn(Sets.newLinkedHashSet("ou1", "ou2")); + uidHelper = new TrackedEntityInstanceUidHelperImpl(organisationUnitStore); + } + + @Test + public void call_organisation_unit_select_uids() { + uidHelper.getMissingOrganisationUnitUids(new ArrayList()); + verify(organisationUnitStore).selectUids(); + } + + @Test + public void return_tei_org_unit_if_not_in_store() { + when(tei1.organisationUnit()).thenReturn("ou3"); + Set missingUids = uidHelper.getMissingOrganisationUnitUids(Lists.newArrayList(tei1)); + assertThat(missingUids.size()).isEqualTo(1); + assertThat(missingUids.iterator().next()).isEqualTo("ou3"); + } + + @Test + public void not_return_tei_org_unit_if_in_store() { + when(tei1.organisationUnit()).thenReturn("ou2"); + Set missingUids = uidHelper.getMissingOrganisationUnitUids(Lists.newArrayList(tei1)); + assertThat(missingUids.size()).isEqualTo(0); + } + + @Test + public void return_2_tei_org_unit_if_not_in_store() { + when(tei1.organisationUnit()).thenReturn("ou3"); + when(tei2.organisationUnit()).thenReturn("ou4"); + Set missingUids = uidHelper.getMissingOrganisationUnitUids(Lists.newArrayList(tei1, tei2)); + assertThat(missingUids.size()).isEqualTo(2); + assertThat(missingUids.contains("ou3")).isEqualTo(true); + assertThat(missingUids.contains("ou4")).isEqualTo(true); + } + + @Test + public void return_enrollment_org_unit_if_not_in_store() { + addToEnrollment("ou3"); + Set missingUids = uidHelper.getMissingOrganisationUnitUids(Lists.newArrayList(tei1)); + assertThat(missingUids.size()).isEqualTo(1); + assertThat(missingUids.iterator().next()).isEqualTo("ou3"); + } + + @Test + public void not_return_enrollment_org_unit_if_in_store() { + addToEnrollment("ou2"); + Set missingUids = uidHelper.getMissingOrganisationUnitUids(Lists.newArrayList(tei1)); + assertThat(missingUids.size()).isEqualTo(0); + } + + @Test + public void return_event_org_unit_if_not_in_store() { + addToEvent("ou3"); + Set missingUids = uidHelper.getMissingOrganisationUnitUids(Lists.newArrayList(tei1)); + assertThat(missingUids.size()).isEqualTo(1); + assertThat(missingUids.iterator().next()).isEqualTo("ou3"); + } + + @Test + public void not_return_event_org_unit_if_in_store() { + addToEvent("ou2"); + Set missingUids = uidHelper.getMissingOrganisationUnitUids(Lists.newArrayList(tei1)); + assertThat(missingUids.size()).isEqualTo(0); + } + + private void addToEnrollment(String organisationUnitId) { + when(enrollment.organisationUnit()).thenReturn(organisationUnitId); + when(tei1.enrollments()).thenReturn(Lists.newArrayList(enrollment)); + } + + private void addToEvent(String organisationUnitId) { + when(event.organisationUnit()).thenReturn(organisationUnitId); + when(enrollment.events()).thenReturn(Lists.newArrayList(event)); + when(tei1.enrollments()).thenReturn(Lists.newArrayList(enrollment)); + } +} diff --git a/core/src/test/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngineShould.java b/core/src/test/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngineShould.java new file mode 100644 index 0000000000..0afec828f3 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/utils/services/ProgramIndicatorEngineShould.java @@ -0,0 +1,361 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.utils.services; + +import org.hisp.dhis.android.core.common.IdentifiableObjectStore; +import org.hisp.dhis.android.core.common.ValueType; +import org.hisp.dhis.android.core.constant.ConstantModel; +import org.hisp.dhis.android.core.dataelement.DataElementModel; +import org.hisp.dhis.android.core.enrollment.EnrollmentModel; +import org.hisp.dhis.android.core.enrollment.EnrollmentStore; +import org.hisp.dhis.android.core.event.EventModel; +import org.hisp.dhis.android.core.event.EventStore; +import org.hisp.dhis.android.core.program.ProgramIndicatorModel; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValueStore; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValue; +import org.hisp.dhis.android.core.trackedentity.TrackedEntityDataValueStore; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ProgramIndicatorEngineShould { + + private String enrollmentUid = "enrollment-uid"; + private String eventUid1 = "qCUMGmMZAhz"; + private String eventUid2 = "QApcv9Je3bp"; + private String programIndicatorUid = "program-indicator-uid"; + private String trackedEntityInstanceUid = "tei-uid"; + + @Mock + private EventModel event1; + + @Mock + private EventModel event2; + + @Mock + private EnrollmentModel enrollmentModel; + + @Mock + private ProgramIndicatorModel programIndicator; + + @Mock + private TrackedEntityDataValue value1; + + @Mock + private TrackedEntityDataValue value2; + + @Mock + private TrackedEntityDataValue value3; + + @Mock + private TrackedEntityDataValue value4; + + @Mock + private TrackedEntityAttributeValue attributeValue; + + @Mock + private DataElementModel dataElementModel; + + private String dataElementUid1 = "HhyfnvrrKpN"; + private String dataElementUid2 = "nM4RZkpgMcP"; + private String dataElementUid3 = "vJeQc8NlWu6"; + private String dataElementUid4 = "jnyUQYDwj7K"; + + private String attributeUid = "UQ0qSNHEpLt"; + + private String programStageUid1 = "un3rUMhluNu"; + private String programStageUid2 = "hr7jRePpYMD"; + + @Mock + private ConstantModel constantModel; + + private String constantUid1 = "gzlRs2HEGAf"; + + @Mock + private IdentifiableObjectStore programIndicatorStore; + @Mock + private TrackedEntityDataValueStore trackedEntityDataValueStore; + @Mock + private EnrollmentStore enrollmentStore; + @Mock + private EventStore eventStore; + @Mock + private IdentifiableObjectStore dataElementStore; + @Mock + private IdentifiableObjectStore constantStore; + @Mock + private TrackedEntityAttributeValueStore trackedEntityAttributeValueStore; + + // Object to test + private ProgramIndicatorEngine programIndicatorEngine; + + @Before + public void setUp() throws Exception { + + programIndicatorEngine = new ProgramIndicatorEngine(programIndicatorStore, trackedEntityDataValueStore, + enrollmentStore, eventStore, dataElementStore, constantStore, trackedEntityAttributeValueStore); + + when(value1.dataElement()).thenReturn(dataElementUid1); + when(value2.dataElement()).thenReturn(dataElementUid2); + when(value3.dataElement()).thenReturn(dataElementUid3); + when(value4.dataElement()).thenReturn(dataElementUid4); + when(attributeValue.trackedEntityAttribute()).thenReturn(attributeUid); + + when(trackedEntityDataValueStore.queryTrackedEntityDataValues(eventUid1)) + .thenReturn(Arrays.asList(value1, value2, value3)); + when(trackedEntityDataValueStore.queryTrackedEntityDataValues(eventUid2)) + .thenReturn(Collections.singletonList(value4)); + + when(event1.uid()).thenReturn(eventUid1); + when(event1.programStage()).thenReturn(programStageUid1); + when(eventStore.queryByUid(eventUid1)).thenReturn(event1); + when(eventStore.queryByEnrollmentAndProgramStage(enrollmentUid, programStageUid1)).thenReturn(event1); + + when(event2.uid()).thenReturn(eventUid2); + when(event2.programStage()).thenReturn(programStageUid2); + when(eventStore.queryByUid(eventUid2)).thenReturn(event2); + when(eventStore.queryByEnrollmentAndProgramStage(enrollmentUid, programStageUid2)).thenReturn(event2); + + when(enrollmentModel.uid()).thenReturn(enrollmentUid); + when(enrollmentModel.trackedEntityInstance()).thenReturn(trackedEntityInstanceUid); + when(enrollmentStore.queryByUid(enrollmentUid)).thenReturn(enrollmentModel); + + when(programIndicatorStore.selectByUid(programIndicatorUid, ProgramIndicatorModel.factory)).thenReturn + (programIndicator); + + when(dataElementModel.valueType()).thenReturn(ValueType.NUMBER); + when(dataElementStore.selectByUid(dataElementUid1, DataElementModel.factory)).thenReturn(dataElementModel); + when(dataElementStore.selectByUid(dataElementUid2, DataElementModel.factory)).thenReturn(dataElementModel); + when(dataElementStore.selectByUid(dataElementUid3, DataElementModel.factory)).thenReturn(dataElementModel); + when(dataElementStore.selectByUid(dataElementUid4, DataElementModel.factory)).thenReturn(dataElementModel); + + when(trackedEntityAttributeValueStore.queryByTrackedEntityInstance(trackedEntityInstanceUid)) + .thenReturn(Collections.singletonList(attributeValue)); + + when(constantModel.uid()).thenReturn(constantUid1); + when(constantStore.selectByUid(constantUid1, ConstantModel.factory)).thenReturn(constantModel); + } + + @Test + public void parse_one_dataelement() throws Exception { + when(programIndicator.expression()).thenReturn(de(programStageUid1, dataElementUid1)); + + when(value1.value()).thenReturn("3.5"); + + String result = programIndicatorEngine.parseIndicatorExpression(null, eventUid1, programIndicatorUid); + + assertThat(result).isEqualTo("3.5"); + } + + @Test + public void parse_operation_two_dataelements() throws Exception { + when(programIndicator.expression()).thenReturn( + de(programStageUid1, dataElementUid1) + " + " + de(programStageUid1, dataElementUid2)); + + when(value1.value()).thenReturn("3.5"); + when(value2.value()).thenReturn("2"); + + String result = programIndicatorEngine.parseIndicatorExpression(null, eventUid1, programIndicatorUid); + + assertThat(result).isEqualTo("3.5 + 2.0"); + } + + @Test + public void parse_operation_with_parenthesis() throws Exception { + when(programIndicator.expression()).thenReturn( + "(" + de(programStageUid1, dataElementUid1) + " + " + de(programStageUid1, dataElementUid2) + + ") / " + de(programStageUid1, dataElementUid3)); + + when(value1.value()).thenReturn("2.5"); + when(value2.value()).thenReturn("2"); + when(value3.value()).thenReturn("1.5"); + + String result = programIndicatorEngine.parseIndicatorExpression(null, eventUid1, programIndicatorUid); + + assertThat(result).isEqualTo("(2.5 + 2.0) / 1.5"); + } + + @Test + public void parse_dataelement_and_constant() throws Exception { + when(programIndicator.expression()).thenReturn( + de(programStageUid1, dataElementUid1) + " + " + cons(constantUid1)); + + when(value1.value()).thenReturn("3.5"); + when(constantModel.value()).thenReturn("2"); + + String result = programIndicatorEngine.parseIndicatorExpression(null, eventUid1, programIndicatorUid); + + assertThat(result).isEqualTo("3.5 + 2"); + } + + @Test + public void parse_enrollment_date_variable() throws Exception { + when(programIndicator.expression()).thenReturn(var("enrollment_date")); + + Date enrollmentDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2018-05-05T00:00:00.000"); + when(enrollmentModel.dateOfEnrollment()).thenReturn(enrollmentDate); + + String result = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, null, programIndicatorUid); + + assertThat(result).isEqualTo("\"2018-05-05\""); + } + + @Test + public void parse_incident_date_variable() throws Exception { + when(programIndicator.expression()).thenReturn(var("incident_date")); + + Date incidentDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2018-05-05T00:00:00.000"); + when(enrollmentModel.dateOfIncident()).thenReturn(incidentDate); + + String result = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, null, programIndicatorUid); + + assertThat(result).isEqualTo("\"2018-05-05\""); + } + + @Test + public void parse_event_date_variable() throws Exception { + when(programIndicator.expression()).thenReturn(var("event_date")); + + Date eventDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2018-05-05T00:00:00.000"); + when(event1.eventDate()).thenReturn(eventDate); + + String result = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, eventUid1, programIndicatorUid); + + assertThat(result).isEqualTo("\"2018-05-05\""); + } + + @Test + public void parse_value_count_variable() throws Exception { + when(programIndicator.expression()).thenReturn( + "(" + de(programStageUid1, dataElementUid1) + " + " + de(programStageUid1, dataElementUid2) + + ") / " + var("value_count")); + + when(value1.value()).thenReturn("3.5"); + when(value2.value()).thenReturn("2"); + + String result = programIndicatorEngine.parseIndicatorExpression(null, eventUid1, programIndicatorUid); + + assertThat(result).isEqualTo("(3.5 + 2.0) / 2"); + } + + @Test + public void parse_tracked_entity_attribute() { + when(programIndicator.expression()).thenReturn(att(attributeUid)); + + when(attributeValue.value()).thenReturn("1989"); + + String result = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, null, programIndicatorUid); + + assertThat(result).isEqualTo("1989"); + } + + @Test + public void do_not_parse_d2_functions() { + when(programIndicator.expression()).thenReturn("d2:floor(" + de(programStageUid1, dataElementUid1) + ")"); + + when(value1.value()).thenReturn("3.5"); + + String result = programIndicatorEngine.parseIndicatorExpression(null, eventUid1, programIndicatorUid); + + assertThat(result).isEqualTo("d2:floor(3.5)"); + } + + @Test + public void parse_values_from_different_program_stage_instances() { + when(programIndicator.expression()).thenReturn( + de(programStageUid1, dataElementUid1) + " + " + de(programStageUid2, dataElementUid4)); + + when(value1.value()).thenReturn("3.5"); + when(value4.value()).thenReturn("2"); + + String resultWithoutEvent = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, null, + programIndicatorUid); + String resultWithEvent1 = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, eventUid1, + programIndicatorUid); + String resultWithEvent2 = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, eventUid2, + programIndicatorUid); + + assertThat(resultWithoutEvent).isEqualTo("3.5 + 2.0"); + assertThat(resultWithEvent1).isEqualTo("3.5 + 2.0"); + assertThat(resultWithEvent2).isEqualTo("3.5 + 2.0"); + } + + @Test + public void ignore_values_from_non_existing_events() { + when(programIndicator.expression()).thenReturn( + de(programStageUid1, dataElementUid1) + " + " + de(programStageUid2, dataElementUid4)); + + when(value1.value()).thenReturn("3.5"); + + // Event2 does not exist + when(eventStore.queryByUid(eventUid2)).thenReturn(null); + when(eventStore.queryByEnrollmentAndProgramStage(enrollmentUid, programStageUid2)).thenReturn(null); + + String resultWithoutEvent = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, null, + programIndicatorUid); + String resultWithEvent1 = programIndicatorEngine.parseIndicatorExpression(enrollmentUid, eventUid1, + programIndicatorUid); + + assertThat(resultWithoutEvent).isEqualTo("3.5 + 0"); + assertThat(resultWithEvent1).isEqualTo("3.5 + 0"); + } + + + // ------------------------------------------------------------------------- + // Supportive methods + // ------------------------------------------------------------------------- + + private String de(String programStageUid, String dataElementUid) { + return "#{" + programStageUid + "." + dataElementUid + "}"; + } + + private String cons(String constantUid) { + return "C{" + constantUid + "}"; + } + + private String var(String variable) { + return "V{" + variable + "}"; + } + + private String att(String attributeUid) { + return "A{" + attributeUid + "}"; + } +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/utils/support/ExpressionUtilsShould.java b/core/src/test/java/org/hisp/dhis/android/core/utils/support/ExpressionUtilsShould.java new file mode 100644 index 0000000000..5dd5f4e659 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/utils/support/ExpressionUtilsShould.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017, University of Oslo + * + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.hisp.dhis.android.core.utils.support; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import nl.jqno.equalsverifier.internal.lib.bytebuddy.implementation.bytecode.constant.DoubleConstant; + +import static org.assertj.core.api.Java6Assertions.assertThat; + +@RunWith(MockitoJUnitRunner.class) +public class ExpressionUtilsShould { + + @Test + public void evaluate_one_value() throws Exception { + assertThat(evaluateToDouble("2.3")).isEqualTo(2.3); + } + + @Test + public void evaluate_base_mathematical_operations() throws Exception { + assertThat(evaluateToDouble("2.3 + 4")).isEqualTo(6.3); + assertThat(evaluateToDouble("4.3 - 2")).isEqualTo(2.3); + assertThat(evaluateToDouble("4.3 * 2")).isEqualTo(8.6); + assertThat(evaluateToDouble("7.5 / 2")).isEqualTo(3.75); + } + + @Test + public void evaluate_operations_with_parenthesis() throws Exception { + assertThat(evaluateToDouble("(2.3 + 4) * 2")).isEqualTo(12.6); + assertThat(evaluateToDouble("6 / (2 - 0.5)")).isEqualTo(4.0); + } + + + private Double evaluateToDouble(String expression) { + return ExpressionUtils.evaluateToDouble(expression, null); + } + +} \ No newline at end of file diff --git a/core/src/test/java/org/hisp/dhis/android/core/utils/support/math/ExpressionFunctionsTest.java b/core/src/test/java/org/hisp/dhis/android/core/utils/support/math/ExpressionFunctionsTest.java new file mode 100644 index 0000000000..23e79e4070 --- /dev/null +++ b/core/src/test/java/org/hisp/dhis/android/core/utils/support/math/ExpressionFunctionsTest.java @@ -0,0 +1,628 @@ +package org.hisp.dhis.android.core.utils.support.math; + +import org.junit.Test; + +import java.text.ParseException; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.addDays; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.ceil; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.concatenate; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.condition; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.daysBetween; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.floor; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.left; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.length; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.modulus; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.monthsBetween; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.oizp; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.right; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.round; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.split; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.substring; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.validatePattern; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.weeksBetween; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.yearsBetween; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.zing; +import static org.hisp.dhis.android.core.utils.support.math.ExpressionFunctions.zpvc; +import static org.junit.Assert.assertThat; + +public class ExpressionFunctionsTest { + private static Object trueValue = new Object(); + private static Object falseValue = new Object(); + + @Test + public void zingShouldReturnNullForNullInput() { + assertThat(zing(null), is(equalTo(null))); + } + + @Test + public void zingShouldReturnSameValueForNonNegativeInput() { + assertThat(zing(0), is(equalTo(0.0))); + assertThat(zing(1), is(equalTo(1.0))); + assertThat(zing(5), is(equalTo(5.0))); + assertThat(zing(0.1), is(equalTo(0.1))); + assertThat(zing(1.1), is(equalTo(1.1))); + } + + @Test + public void zingShouldReturnZeroForNegativeInput() { + assertThat(zing(-1), is(equalTo(0.0))); + assertThat(zing(-10), is(equalTo(0.0))); + assertThat(zing(-1.1), is(equalTo(0.0))); + } + + @Test + public void oizpShouldReturnNullForNullInput() { + assertThat(oizp(null), is(equalTo(null))); + } + + @Test + public void oizpShouldReturnOneForNonNegativeInputs() { + assertThat(oizp(0), is(equalTo(1.0))); + assertThat(oizp(1), is(equalTo(1.0))); + assertThat(oizp(10), is(equalTo(1.0))); + } + + @Test + public void oizpShouldReturnZeroForNegativeInputs() { + assertThat(oizp(-1), is(equalTo(0.0))); + assertThat(oizp(-10), is(equalTo(0.0))); + } + + @Test(expected = IllegalArgumentException.class) + public void zpvcShouldReturnThrowIllegalArgumentExceptionForNullInput() { + zpvc(); + } + + @Test + public void zpvcShouldReturnCountOfNonNegativeValuesInArguments() { + assertThat(zpvc(null, 0, 1, -1, 2, -2, 3), is(equalTo(4))); + } + + @Test + public void conditionShouldReturnFalseForUntrueConditions() { + assertThat(condition("", trueValue, falseValue), is(equalTo(falseValue))); + assertThat(condition("false", trueValue, falseValue), is(equalTo(falseValue))); + assertThat(condition("0 == 1", trueValue, falseValue), is(equalTo(falseValue))); + assertThat(condition("2*3 != 12/2", trueValue, falseValue), is(equalTo(falseValue))); + assertThat(condition("0 > 1", trueValue, falseValue), is(equalTo(falseValue))); + assertThat(condition("!true", trueValue, falseValue), is(equalTo(falseValue))); + } + + @Test + public void conditionShouldReturnTrueForTrueConditions() { + assertThat(condition("true", trueValue, falseValue), is(equalTo(trueValue))); + assertThat(condition("1 == 1", trueValue, falseValue), is(equalTo(trueValue))); + assertThat(condition("2*3 == 12/2", trueValue, falseValue), is(equalTo(trueValue))); + assertThat(condition("10 > 1", trueValue, falseValue), is(equalTo(trueValue))); + assertThat(condition("!false", trueValue, falseValue), is(equalTo(trueValue))); + } + + @Test + public void daysBetweenShouldReturnZeroIfSomeDateIsNotPresent() throws ParseException { + assertThat(daysBetween(null, null), is(equalTo(0))); + assertThat(daysBetween(null, ""), is(equalTo(0))); + assertThat(daysBetween("", null), is(equalTo(0))); + assertThat(daysBetween("", ""), is(equalTo(0))); + } + + @Test(expected = IllegalArgumentException.class) + public void daysBetweenShouldRaiseIllegalArgumentExceptionIfFirstDateIsInvalid() + throws ParseException { + daysBetween("bad date", "2010-01-01"); + } + + @Test(expected = IllegalArgumentException.class) + public void daysBetweenShouldRaiseIllegalArgumentExceptionIfSecondDateIsInvalid() + throws ParseException { + daysBetween("2010-01-01", "bad date"); + } + + @Test(expected = IllegalArgumentException.class) + public void daysBetweenShouldRaiseIllegalArgumentExceptionIfFirstAndSecondDateIsInvalid() + throws ParseException { + daysBetween("bad date", "bad date"); + } + + @Test + public void daysBetweenShouldReturnDifferenceOfDaysOfTwoDates() throws ParseException { + assertThat(daysBetween("2010-10-15", "2010-10-20"), is(equalTo(5))); + assertThat(daysBetween("2010-09-30", "2010-10-15"), is(equalTo(15))); + assertThat(daysBetween("2010-12-31", "2011-01-01"), is(equalTo(1))); + + assertThat(daysBetween("2010-10-20", "2010-10-15"), is(equalTo(-5))); + assertThat(daysBetween("2010-10-15", "2010-09-30"), is(equalTo(-15))); + assertThat(daysBetween("2011-01-01", "2010-12-31"), is(equalTo(-1))); + } + + @Test + public void weeksBetweenShouldReturnZeroIfSomeDateIsNotPresent() throws ParseException { + assertThat(weeksBetween(null, null), is(equalTo(0))); + assertThat(weeksBetween(null, ""), is(equalTo(0))); + assertThat(weeksBetween("", null), is(equalTo(0))); + assertThat(weeksBetween("", ""), is(equalTo(0))); + } + + @Test(expected = IllegalArgumentException.class) + public void weeksBetweenShouldRaiseIllegalArgumentExceptionIfFirstDateIsInvalid() + throws ParseException { + weeksBetween("bad date", "2010-01-01"); + } + + @Test(expected = IllegalArgumentException.class) + public void weeksBetweenShouldRaiseIllegalArgumentExceptionIfSecondDateIsInvalid() + throws ParseException { + weeksBetween("2010-01-01", "bad date"); + } + + @Test + public void weeksBetweenShouldReturnDifferenceOfWeeksOfTwoDates() throws ParseException { + assertThat(weeksBetween("2010-10-15", "2010-10-22"), is(equalTo(1))); + assertThat(weeksBetween("2010-09-30", "2010-10-15"), is(equalTo(2))); + assertThat(weeksBetween("2010-12-31", "2011-01-01"), is(equalTo(0))); + + assertThat(weeksBetween("2010-10-22", "2010-10-15"), is(equalTo(-1))); + assertThat(weeksBetween("2010-10-15", "2010-09-30"), is(equalTo(-2))); + assertThat(weeksBetween("2011-01-01", "2010-12-31"), is(equalTo(0))); + } + + @Test + public void monthsBetweenShouldReturnZeroIfSomeDateIsNotPresent() throws ParseException { + assertThat(monthsBetween(null, null), is(equalTo(0))); + assertThat(monthsBetween(null, ""), is(equalTo(0))); + assertThat(monthsBetween("", null), is(equalTo(0))); + assertThat(monthsBetween("", ""), is(equalTo(0))); + } + + @Test(expected = IllegalArgumentException.class) + public void monthsBetweenShouldRaiseIllegalArgumentExceptionIfFirstDateIsInvalid() + throws ParseException { + monthsBetween("bad date", "2010-01-01"); + } + + @Test(expected = IllegalArgumentException.class) + public void monthsBetweenShouldRaiseIllegalArgumentExceptionIfSecondDateIsInvalid() + throws ParseException { + monthsBetween("2010-01-01", "bad date"); + } + + @Test + public void monthsBetweenShouldReturnDifferenceOfMonthsOfTwoDates() throws ParseException { + assertThat(monthsBetween("2010-10-15", "2010-10-22"), is(equalTo(0))); + assertThat(monthsBetween("2010-09-30", "2010-10-31"), is(equalTo(1))); + assertThat(monthsBetween("2013-01-31", "2013-02-01"), is(equalTo(1))); + assertThat(monthsBetween("2016-01-01", "2016-07-31"), is(equalTo(6))); + assertThat(monthsBetween("2015-01-01", "2016-06-30"), is(equalTo(17))); + + assertThat(monthsBetween("2010-10-22", "2010-10-15"), is(equalTo(0))); + assertThat(monthsBetween("2010-10-31", "2010-09-30"), is(equalTo(-1))); + assertThat(monthsBetween("2013-02-01", "2013-01-31"), is(equalTo(-1))); + assertThat(monthsBetween("2016-07-31", "2016-01-01"), is(equalTo(-6))); + assertThat(monthsBetween("2016-06-30", "2015-01-01"), is(equalTo(-17))); + } + + @Test + public void yearsBetweenShouldReturnZeroIfSomeDateIsNotPresent() throws ParseException { + assertThat(yearsBetween(null, null), is(equalTo(0))); + assertThat(yearsBetween(null, ""), is(equalTo(0))); + assertThat(yearsBetween("", null), is(equalTo(0))); + assertThat(yearsBetween("", ""), is(equalTo(0))); + } + + @Test(expected = IllegalArgumentException.class) + public void yearsBetweenShouldRaiseIllegalArgumentExceptionIfFirstDateIsInvalid() + throws ParseException { + yearsBetween("bad date", "2010-01-01"); + } + + @Test(expected = IllegalArgumentException.class) + public void yearsBetweenShouldRaiseIllegalArgumentExceptionIfSecondDateIsInvalid() + throws ParseException { + yearsBetween("2010-01-01", "bad date"); + } + + @Test + public void yearsBetweenShouldReturnDifferenceOfYearsOfTwoDates() throws ParseException { + assertThat(yearsBetween("2010-10-15", "2010-10-22"), is(equalTo(0))); + assertThat(yearsBetween("2010-09-30", "2011-10-31"), is(equalTo(1))); + assertThat(yearsBetween("2010-01-01", "2016-06-30"), is(equalTo(6))); + assertThat(yearsBetween("2015-01-01", "2016-06-30"), is(equalTo(1))); + + assertThat(yearsBetween("2010-10-22", "2010-10-22"), is(equalTo(0))); + assertThat(yearsBetween("2011-10-31", "2010-09-30"), is(equalTo(-1))); + assertThat(yearsBetween("2016-06-30", "2010-01-01"), is(equalTo(-6))); + assertThat(yearsBetween("2016-06-30", "2015-01-01"), is(equalTo(-1))); + } + + @Test(expected = IllegalArgumentException.class) + public void floorShouldRaiseIllegalArgumentExceptionForNullInput() { + floor(null); + } + + @Test + public void floorShouldReturnArgumentRoundedDownToNearestWholeNumber() { + assertThat(floor(0), is(equalTo(0))); + assertThat(floor(0.8), is(equalTo(0))); + assertThat(floor(1.0), is(equalTo(1))); + assertThat(floor(-9.3), is(equalTo(-10))); + assertThat(floor(5.9), is(equalTo(5))); + assertThat(floor(5), is(equalTo(5))); + assertThat(floor(-5), is(equalTo(-5))); + } + + @Test(expected = IllegalArgumentException.class) + public void modulusShouldRaiseIllegalArgumentExceptionForNullInput() { + modulus(null, null); + } + + @Test(expected = ArithmeticException.class) + public void modulusWithZeroDivisorShouldRaiseArithmeticException() { + modulus(2, 0); + } + + @Test + public void modulusShouldReturnTheRemainderAfterDivisionOfInputs() { + assertThat(modulus(0, 2), is(equalTo(0))); + assertThat(modulus(11, 3), is(equalTo(2))); + assertThat(modulus(-11, 3), is(equalTo(-2))); + assertThat(modulus(11.5, 3.2), is(equalTo(2))); + assertThat(modulus(-11.5, 3.2), is(equalTo(-2))); + } + + @Test + public void concatenateShouldReturnConcatenatedStrings() { + assertThat(concatenate(), is(equalTo(""))); + assertThat(concatenate("hello"), is(equalTo("hello"))); + assertThat(concatenate("hello", " ", "there", "!"), is(equalTo("hello there!"))); + } + + @Test(expected = IllegalArgumentException.class) + public void addDaysShouldRaiseIllegalArgumentExceptionForEmptyDate() { + addDays("", 1); + } + + @Test(expected = IllegalArgumentException.class) + public void addDaysShouldRaiseIllegalArgumentExceptionForNullDaysDifference() { + addDays("2010-10-10", null); + } + + @Test + public void addDaysShouldReturnNewDateWithDaysAdded() { + assertThat(addDays("2010-10-10", 1), is(equalTo("2010-10-11"))); + assertThat(addDays("2010-10-31", 1), is(equalTo("2010-11-01"))); + assertThat(addDays("2010-12-01", 31), is(equalTo("2011-01-01"))); + } + + /* + private class Variable { + String variableValue; + Boolean hasValue; + List allValues; + String eventDate; + ValueType variableType = INTEGER; + + public Variable hasNoValue() { + this.hasValue = false; + return this; + } + + public Variable withValue(String variableValue) { + this.variableValue = variableValue; + return this; + } + + public Variable withValues(List allValues) { + this.allValues = allValues; + return this; + } + + public Variable withEventDate(String eventDate) { + this.eventDate = eventDate; + return this; + } + + public Variable withVariableType(ValueType variableType) { + this.variableType = variableType; + return this; + } + + public ProgramRuleVariable build() { + Boolean finalHasValue = + hasValue != null ? hasValue : variableValue != "null" && variableValue != ""; + ProgramRuleVariable programRuleVariable = new ProgramRuleVariable(); + programRuleVariable.setVariableType(variableType); + programRuleVariable.setVariableValue(variableValue); + programRuleVariable.setHasValue(finalHasValue); + programRuleVariable.setAllValues(allValues); + programRuleVariable.setVariableEventDate(eventDate); + return programRuleVariable; + } + } + + private class ProgramRuleVariableMapSetter { + private Map programRuleVariableMap = new HashMap<>(); + + public ProgramRuleVariableMapSetter addVariable(String variableName, + ProgramRuleVariable programRuleVariable) { + programRuleVariableMap.put(variableName, programRuleVariable); + return this; + } + + public void set() { + VariableService.getInstance().setProgramRuleVariableMap(programRuleVariableMap); + } + } + + @Test + public void countShouldReturnZeroForNonExistingVariable() { + new ProgramRuleVariableMapSetter().set(); + assertThat(count("nonexisting"), is(equalTo(0))); + } + + @Test + public void countShouldReturnZeroForProgramRuleVariableWithoutValues() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", + new Variable().withValue("1.0").hasNoValue().withValues( + Arrays.asList("1.0", "2.0")).build()) + .set(); + assertThat(count("myvar"), is(equalTo(0))); + } + + @Test + public void countShouldReturnSizeOfValuesForProgramRuleVariableWithValues() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", + new Variable().withValue("1.0").withValues( + Arrays.asList("1.0", "2.0")).build()) + .set(); + assertThat(count("myvar"), is(equalTo(2))); + } + + @Test + public void countShouldReturnOneForProgramRuleVariableWithUndefinedValues() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", new Variable().withValue("1.0").build()) + .set(); + assertThat(count("myvar"), is(equalTo(1))); + } + + @Test + public void countIfZeroPosShouldReturnZeroForNonExistingVariable() { + new ProgramRuleVariableMapSetter().set(); + assertThat(countIfZeroPos("nonexisting"), is(equalTo(0))); + } + + @Test + public void countIfZeroPosShouldReturnZeroForProgramRuleVariableWithoutValue() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", + new Variable().withValue("1.0").hasNoValue().withValues( + Arrays.asList("1.0", "2.0")).build()) + .set(); + assertThat(countIfZeroPos("myvar"), is(equalTo(0))); + } + + @Test + public void + countIfZeroPosShouldReturnSizeOfZeroOrPositiveValuesForProgramRuleVariableWithValues() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", + new Variable().withValue("1.0").withValues( + Arrays.asList("1.0", null, "2.0", "-3.0")).build()) + .set(); + assertThat(countIfZeroPos("myvar"), is(equalTo(2))); + } + + @Test + public void + countIfZeroPosShouldReturnZeroForProgramRuleVariableWithUndefinedValuesAndValueNotSet() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", new Variable().build()) + .set(); + assertThat(countIfZeroPos("myvar"), is(equalTo(0))); + } + + @Test + public void + countIfZeroPosShouldReturnOneForProgramRuleVariableWithValuesButNotDefinedAndValueSet() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", new Variable().withValue("1.0").build()) + .set(); + assertThat(countIfZeroPos("myvar"), is(equalTo(1))); + } + + @Test + public void countIfValueShouldReturnZeroForNonExistingVariable() { + new ProgramRuleVariableMapSetter().set(); + assertThat(countIfValue("nonexisting","textToCompare"), is(equalTo(0))); + } + + @Test + public void countIfValueShouldReturnCountOfMatchingValuesForProgramRuleVariableWithValues() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", + new Variable().withValue("1.0").withValues( + Arrays.asList("1.0", null, "2.0", "1.0")).build()) + .set(); + assertThat(countIfValue("myvar","1.0"), is(equalTo(2))); + } + + @Test + public void countIfValueShouldReturnOneForProgramRuleVariableWithUnsetValues() { + new ProgramRuleVariableMapSetter() + .addVariable("myvar", new Variable().withValue("1.0").build()) + .set(); + assertThat(countIfValue("myvar","1.0"), is(equalTo(1))); + } + */ + + @Test + public void ceilShouldReturnSmallestGreaterOrEqualThanAGivenNumber() { + assertThat(ceil(0), is(equalTo(0.0))); + assertThat(ceil(0.8), is(equalTo(1.0))); + assertThat(ceil(1.0), is(equalTo(1.0))); + assertThat(ceil(-9.3), is(equalTo(-9.0))); + } + + @Test + public void roundShouldReturnTheNearestIntegerOfAGivenNumber() { + assertThat(round(0), is(equalTo(0L))); + assertThat(round(0.8), is(equalTo(1L))); + assertThat(round(0.4999), is(equalTo(0L))); + assertThat(round(0.5001), is(equalTo(1L))); + assertThat(round(-9.3), is(equalTo(-9L))); + assertThat(round(-9.8), is(equalTo(-10L))); + } + + /* + @Test + public void hasValueShouldReturnFalseForNonExistingVariable() { + new ProgramRuleVariableMapSetter().set(); + assertThat(hasValue("nonexisting"), is(equalTo(false))); + } + + @Test + public void hasValueShouldReturnFalseForExistingVariableWithoutValue() { + new ProgramRuleVariableMapSetter() + .addVariable("some-var", new Variable().hasNoValue().build()) + .set(); + assertThat(hasValue("some-var"), is(equalTo(false))); + } + + @Test + public void hasValueShouldReturnTrueForExistingVariableWithValue() { + new ProgramRuleVariableMapSetter() + .addVariable("some-var", new Variable().withValue("1.0").build()) + .set(); + assertThat(hasValue("some-var"), is(equalTo(true))); + } + + @Test + public void lastEventDateShouldReturnEmptydStringForNonExistingVariable() { + new ProgramRuleVariableMapSetter().set(); + assertThat(lastEventDate("nonexisting"), is(equalTo(""))); + } + + @Test + public void lastEventDateShouldReturnEmptyStringForExistingVariableWithoutEventDate() { + new ProgramRuleVariableMapSetter() + .addVariable("some-var", new Variable().build()) + .set(); + assertThat(lastEventDate("some-var"), is(equalTo(""))); + } + + @Test + public void lastEventDateShouldReturnDateForExistingVariableWithEventDate() { + new ProgramRuleVariableMapSetter() + .addVariable("some-var", new Variable().withEventDate("2010-10-20").build()) + .set(); + assertThat(lastEventDate("some-var"), is(equalTo("2010-10-20"))); + } + */ + + @Test + public void validatePatternShouldReturnFalseForNonMatchingPairs() { + assertThat(validatePattern("abc123", "xyz"), is(equalTo(false))); + assertThat(validatePattern("abc123", "^bc"), is(equalTo(false))); + assertThat(validatePattern("abc123", "abc12345"), is(equalTo(false))); + assertThat(validatePattern("1999/99/9", "\\[9]{4}/\\d{2}/\\d"), is(equalTo(false))); + assertThat(validatePattern("9999/99/", "[0-9]{4}/[0-9]{2}/[0-9]"), is(equalTo(false))); + } + + @Test + public void validatePatternShouldReturnTrueForFullMatchingPairs() { + assertThat(validatePattern("abc123", "abc123"), is(equalTo(true))); + assertThat(validatePattern("abc123", "abc"), is(equalTo(false))); + assertThat(validatePattern("abc123", "123"), is(equalTo(false))); + assertThat(validatePattern(123, "12"), is(equalTo(false))); + assertThat(validatePattern(123, "123"), is(equalTo(true))); + assertThat(validatePattern("27123456789", "27\\d{2}\\d{3}\\d{4}"), is(equalTo(true))); + assertThat(validatePattern("9999/99/9", "\\d{4}/\\d{2}/\\d"), is(equalTo(true))); + assertThat(validatePattern("9999/99/9", "[0-9]{4}/[0-9]{2}/[0-9]"), is(equalTo(true))); + } + + @Test + public void validatePatternShouldWorkBeyondMaxIntValue() { + assertThat(validatePattern(27123456789L, "27\\d{9}"), is(equalTo(true))); + } + + @Test + public void leftShouldReturnEmptyStringForNullInput() { + assertThat(left(null, 0), is(equalTo(""))); + assertThat(left(null, 10), is(equalTo(""))); + assertThat(left(null, -10), is(equalTo(""))); + } + + @Test + public void leftShouldReturnSubstringOfInputStringFromTheBeginning() { + assertThat(left("abcdef", 0), is(equalTo(""))); + assertThat(left("abcdef", -5), is(equalTo(""))); + assertThat(left("abcdef", 2), is(equalTo("ab"))); + assertThat(left("abcdef", 30), is(equalTo("abcdef"))); + } + + @Test + public void rightShouldReturnEmptyStringForNullInput() { + assertThat(right(null, 0), is(equalTo(""))); + assertThat(right(null, 10), is(equalTo(""))); + assertThat(right(null, -10), is(equalTo(""))); + } + + @Test + public void rightShouldReturnSubstringOfInputStringFromTheEnd() { + assertThat(right("abcdef", 0), is(equalTo(""))); + assertThat(right("abcdef", -5), is(equalTo(""))); + assertThat(right("abcdef", 2), is(equalTo("ef"))); + assertThat(right("abcdef", 30), is(equalTo("abcdef"))); + } + + @Test + public void lengthShouldReturnZeroForNullString() { + assertThat(length(null), is(equalTo(0))); + } + + @Test + public void lengthShouldReturnLengthOfInputString() { + assertThat(length(""), is(equalTo(0))); + assertThat(length("abc"), is(equalTo(3))); + assertThat(length("abcdef"), is(equalTo(6))); + } + + @Test + public void splitShouldReturnEmptyStringForNullInputs() { + assertThat(split(null, null, 0), is(equalTo(""))); + assertThat(split("", null, 0), is(equalTo(""))); + assertThat(split(null, "", 0), is(equalTo(""))); + } + + @Test + public void splitShouldReturnTheNthFieldOfTheSplitedInputString() { + assertThat(split("a,b,c", ",", 0), is(equalTo("a"))); + assertThat(split("a,b,c", ",", 2), is(equalTo("c"))); + assertThat(split("a,;b,;c", ",;", 1), is(equalTo("b"))); + } + + @Test + public void splitShouldReturnEmptyStringIfFieldIndexIsOutOfBounds() { + assertThat(split("a,b,c", ",", 10), is(equalTo(""))); + assertThat(split("a,b,c", ",", -1), is(equalTo(""))); + } + + @Test + public void substringShouldReturnEmptyStringForNullInput() { + assertThat(substring(null, 0, 0), is(equalTo(""))); + assertThat(substring(null, 0, 10), is(equalTo(""))); + } + + @Test + public void substringShouldReturnSubstringFromStartIndexToEndIndexOfInputString() { + assertThat(substring("abcdef", 0, 0), is(equalTo(""))); + assertThat(substring("abcdef", 0, 1), is(equalTo("a"))); + assertThat(substring("abcdef", -10, 1), is(equalTo("a"))); + assertThat(substring("abcdef", 2, 4), is(equalTo("cd"))); + assertThat(substring("abcdef", 2, 10), is(equalTo("cdef"))); + } +} diff --git a/core/src/test/resources/data_sets_with_access.json b/core/src/test/resources/data_sets_with_access.json deleted file mode 100644 index d1b9248c2a..0000000000 --- a/core/src/test/resources/data_sets_with_access.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "dataSets": [ - { - "id": "lyLU2wR22tC", - "access": { - "read": true, - "update": true, - "externalize": false, - "delete": true, - "write": true, - "manage": true, - "data": { - "read": true, - "write": true - } - } - } - ] -} \ No newline at end of file diff --git a/core/src/test/resources/program/program.json b/core/src/test/resources/program/program.json new file mode 100644 index 0000000000..6eea2d83ca --- /dev/null +++ b/core/src/test/resources/program/program.json @@ -0,0 +1,99 @@ +{ + "lastUpdated": "2015-10-15T11:32:27.242", + "id": "WSGAb5XwJ3Y", + "created": "2014-06-06T20:44:21.375", + "name": "WHO RMNCH Tracker", + "shortName": "WHO RMNCH Tracker", + "publicAccess": "rw------", + "ignoreOverdueEvents": false, + "skipOffline": false, + "dataEntryMethod": false, + "captureCoordinates": false, + "enrollmentDateLabel": "Date of first visit", + "onlyEnrollOnce": false, + "version": 11, + "selectIncidentDatesInFuture": true, + "incidentDateLabel": "Date of incident", + "selectEnrollmentDatesInFuture": false, + "registration": true, + "useFirstStageDuringRegistration": false, + "displayName": "WHO RMNCH Tracker", + "completeEventsExpiryDays": 0, + "displayShortName": "WHO RMNCH Tracker", + "externalAccess": false, + "withoutRegistration": false, + "displayFrontPageList": false, + "programType": "WITH_REGISTRATION", + "relationshipFromA": true, + "relationshipText": "Add child", + "displayIncidentDate": false, + "expiryDays": 0, + "minAttributesRequiredToSearch": 3, + "maxTeiCountToReturn": 2, + "categoryCombo": { + "id": "p0KPaWEg3cf" + }, + "trackedEntityType": { + "id": "nEenWmSyUEp" + }, + "relatedProgram": { + "id": "IpHINAT79UW" + }, + "relationshipType": { + "id": "V2kkHafqs8G" + }, + "user": { + "id": "xE7jOejl9FI" + }, + "programIndicators": [], + "translations": [], + "userGroupAccesses": [], + "attributeValues": [], + "validationCriterias": [], + "userRoles": [ + { + "id": "Ufph3mGRmMo" + }, + { + "id": "LGWLyWNro4x" + } + ], + "programRuleVariables": [ + { + "id": "varonrw1032" + }, + { + "id": "idLCptBEOF9" + } + ], + "programTrackedEntityAttributes": [ + { + "id": "YGMlKXYa5xF" + }, + { + "id": "WZWEBrkJSAm" + } + ], + "notificationTemplates": [], + "programStages": [ + { + "id": "WZbXY0S00lP" + }, + { + "id": "PUZaKR0Jh2k" + } + ], + "programRules": [ + { + "id": "tO1D62oB0tq" + }, + { + "id": "ruleonr1065" + } + ], + "programSections": [ + { + "id": "FdpWnXhl7c1" + } + ] +} \ No newline at end of file diff --git a/core/src/test/resources/program/program_section.json b/core/src/test/resources/program/program_section.json new file mode 100644 index 0000000000..25d3615ec6 --- /dev/null +++ b/core/src/test/resources/program/program_section.json @@ -0,0 +1,46 @@ +{ + "code": "Code", + "lastUpdated": "2018-05-15T08:14:06.767", + "id": "Nc8OxbNuVH3", + "created": "2018-05-15T08:14:06.767", + "name": "My Program Section", + "displayName": "My Program Section", + "description": "Description", + "externalAccess": false, + "formName": "formName", + "sortOrder": 1, + "favorite": false, + "access": { + "read": true, + "update": true, + "externalize": false, + "delete": true, + "write": true, + "manage": true + }, + "program": { + "id": "IpHINAT79UW" + }, + "lastUpdatedBy": { + "id": "xE7jOejl9FI" + }, + "style": { + "color": "#fff", + "icon": "my-icon" + }, + "favorites": [ + ], + "programTrackedEntityAttribute": [ + { + "id": "zDhUuAYrxNC" + } + ], + "translations": [ + ], + "userGroupAccesses": [ + ], + "attributeValues": [ + ], + "userAccesses": [ + ] +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c77756b5fd..02891e52b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,8 +12,8 @@ org.gradle.jvmargs=-Xmx1536m # Properties which are consumed by plugins/gradle-mvn-push.gradle plugin. # They are used for publishing artifact to snapshot repository. -VERSION_NAME=0.7.5.1-SNAPSHOT -VERSION_CODE=751 +VERSION_NAME=0.9-SNAPSHOT +VERSION_CODE=90 GROUP=org.hisp.dhis