Skip to content

Integrating new dhis sdk

idelcano edited this page Nov 25, 2016 · 10 revisions

Environment

To work in the integration of the new SDK is necessary move your branch to:

malariapp: feature-new_sdk sdk: 2.25-EyeSeeTea_temp_changes

SDK important changes.

The sdk use dagger2.

The sdk use JXjava.

The sdk wiki code not work at this momment, example of login and organisationUnits pull by code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    D2.init(this);
    Configuration configuration = new Configuration("SERVER");
    ConfigurationPreferencesImpl pref= new ConfigurationPreferencesImpl(this);
    pref.save(configuration);
    D2.configuration();
    D2.configure(configuration);
    new TestAsync().execute();
    context=this;
}

class TestAsync extends AsyncTask<Void, Integer, String>
{
    protected void onPreExecute (){
    }

    protected String doInBackground(Void...arg0) {
            Observable<UserAccount> observable = D2.me().signIn("USER", "PASSWORD");
            observable.subscribe(new Action1<UserAccount>() {
                @Override
                public void call(UserAccount userAccount) {
                    Log.d("TAG", "userAccount+" + userAccount.toString());
                    userAccount.getOrganisationUnits();
                    Log.d("TAG", "programs+" + userAccount.getPrograms().toString());
                    Log.d("TAG", "orgunits" + userAccount.getOrganisationUnits().toString());
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    // do something
                    Log.d("TAG", "Error");
                    Log.d("TAG", throwable.toString());
                    throwable.printStackTrace();
                }
            });
        Set<ProgramType> programType = null;
        List<Program> pr= (List<Program>) D2.me().programs().pull(SyncStrategy.DEFAULT, ProgramFields.ALL,programType);
        Log.d("TAG",
                D2.programs().toString());
        Log.d("TAG", D2.me().organisationUnits().toString());

        return "You are at PostExecute";
    }

    protected void onPostExecute(String result) {
        Intent intent2 = new Intent(context, LoginActivity.class);
        startActivity(intent2);
    }
}

The sdk is now more abstract and modular.

The db models are sepparated than the sdk models.

The sdk new modules are these:

core

core-android -> contains the dbflow models, and android core

core-rules

models -> contains the sdk models

ui

ui-bindings -> contains the final android ui components

We need import core-rules and ui-bindings(and ui-binbdings imports ui and core-android, core-android imports core, and core-rules imports models).

Config gradle and sdk.

Clone git dhis sdk repository on workspace root folder(../malariapp).

git clone https://github.com/dhis2/dhis2-android-sdk.git

Move the branch to development

Remove DBflow folders and SDk from malariapp


In malariapp/build.gradle:

Add this line to include dbflow librarie

	maven {url "https://jitpack.io"} 

bellow this line:

    maven { url "https://raw.github.com/Raizlabs/maven-releases/master/releases"}

Add the sdk config extesions inside of ext:

configuration = [
        package          : "org.hisp.dhis.android.skeleton",
        buildToolsVersion: "23.0.2",
        minSdkVersion    : 15,
        compileSdkVersion: 23,
        targetSdkVersion : 23,
        versionCode      : 21,
        versionName      : "0.5.0.2"
]
libraries = [
        // dhis libs
        dhisCommonsVersion : "1.1",

        // android libs
        supportVersion          : "23.4.0",
        rxAndroidVersion        : "1.1.0",
        dbFlowVersion           : "3.0.1",
        progressBarVersion      : "1.2.0",
        smoothProgressBarVersion: "1.1.0",
        crashlyticsVersion      : "2.5.5",
        stethoVersion           : "1.3.1",
        multidex                : "1.0.1",

        // java libs
        timberVersion           : "4.1.0",
        okhttpVersion           : "3.2.0",
        retrofitVersion         : "2.0.0",
        jacksonVersion          : "2.7.4",
        jodaTimeVersion         : "2.9.2",
        jexlVersion             : "2.1.1",
        commonsLang3Version     : "3.3.2",
        commonsMath3Version     : "3.6",
        dagger                  : "2.2",

        // testing libs
        jUnitVersion            : "4.12",
        mockitoVersion          : "1.10.19",
        powerMockVersion        : "1.6.3",
]

And set the buildToolsVersion supportVersion compileSdkVersion and targetSdkVersion with the sdk versions.


Replace the settings.gradle content with:

include ':app', ':core', ':core-android', ':core-rules', ':models', ':ui', ':ui-bindings', ':utils'

project(':core').projectDir = new File(settingsDir, '../dhis2-android-sdk/core')

project(':core-android').projectDir = new File(settingsDir, '../dhis2-android-sdk/core-android')

project(':core-rules').projectDir = new File(settingsDir, '../dhis2-android-sdk/core-rules')

project(':models').projectDir = new File(settingsDir, '../dhis2-android-sdk/models')

project(':ui').projectDir = new File(settingsDir, '../dhis2-android-sdk/ui')

project(':ui-bindings').projectDir = new File(settingsDir, '../dhis2-android-sdk/ui-bindings')

project(':utils').projectDir = new File(settingsDir, '../dhis2-android-sdk/utils')


malariapp/app/build.gradle remove:

compile project(':sdk:app')

apt project(':DBFlowORM:DBFlow-Compiler')

compile project(':DBFlowORM:DBFlow-Core')

compile project(':DBFlowORM:DBFlow')

and add:

compile project(":core-rules")

compile project(":ui-bindings")

We need add:

// Dagger dependencies
provided "com.google.dagger:dagger-compiler:${rootProject.ext.libraries.dagger}"
apt "com.google.dagger:dagger-compiler:${rootProject.ext.libraries.dagger}"
compile "com.google.dagger:dagger:${rootProject.ext.libraries.dagger}"

To use dagger like in the sdk. It's necesary by the userComponent().


ToDo

  • Fix queries

  • Use one dbflow instance to work with sdk database and our database.

  • Create and pull some entities.

  • Create missing queries: getMinimizedEvents getEventsFromDate getEventsBetweenDate getOrganisationUnitLevels().

  • Fix activities.

  • Its needed pull all the necessary from the server.

  • Its needed convert from DB to sdk model to our DB.

  • Its needed change the push methods to use the new push.

  • Its needed change the convertToSdkVisitor in some steps.


Database.

The sdk is using the last dbflow version(3.0.1).

New sdk scheme

List of entities:

UserFlow UserAccountFlow UnitToDataSetRelationShipFlow TrackedEntityInstanceFlow TrackedEntityFlow TrackedEntityDataValueFlow TrackedEntityAttributeValueFlow TrackedEntityAttributeFlow StateFlow RelationshipTypeFlow RelationshipFlow ProgramTrackedEntityAttributeFlow ProgramStageSectionFlow ProgramStageFlow ProgramStageDataElementFlow ProgramRuleVariableFlow ProgramRuleFlow ProgramRuleActionFlow ProgramIndicatorToProgramStageSectionRelationFlow ProgramIndicatorFlow ProgramFlow OrganisationUnitToProgramRelationFlow OrganisationUnitFlow OptionSetFlow OptionFlow ModelLinkFlow InterpretationFlow InterpretationElementFlow InterpretationCommentFlow ImportSummaryFlow ImportCountFlow FailedItemFlow EventFlow EnrollmentFlow DataSetFlow DataElementFlow DashboardFlow DashboardItemFlow DashboardElementFlow DashboardContentFlow ConstantFlow ConflictFlow CategoryOptionFlow CategoryOptionComboFlow CategoryFlow CategoryComboFlow

Sql query:

BEGIN TRANSACTION; CREATE TABLE android_metadata (locale TEXT); CREATE TABLE `UserFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT); CREATE TABLE `UserAccountFlow`(`id` INTEGER,`uId` TEXT,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`action` null,`firstName` TEXT,`surname` TEXT,`gender` TEXT,`birthday` TEXT,`introduction` TEXT,`education` TEXT,`employer` TEXT,`interests` TEXT,`jobTitle` TEXT,`languages` TEXT,`email` TEXT,`phoneNumber` TEXT, PRIMARY KEY(`id`)); CREATE TABLE `UnitToDataSetRelationShipFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`organisationUnit` TEXT,`dataSet` TEXT, UNIQUE(`organisationUnit`,`dataSet`) ON CONFLICT FAIL, FOREIGN KEY(`organisationUnit`) REFERENCES `OrganisationUnitFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`dataSet`) REFERENCES `DataSetFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `TrackedEntityInstanceFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`trackedEntityInstanceUid` TEXT,`trackedEntity` TEXT,`orgUnit` TEXT,`created` TEXT,`lastUpdated` TEXT); CREATE TABLE `TrackedEntityFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT); CREATE TABLE `TrackedEntityDataValueFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`event` TEXT,`dataElement` TEXT,`storedBy` TEXT,`value` TEXT, UNIQUE(`event`,`dataElement`) ON CONFLICT FAIL, FOREIGN KEY(`event`) REFERENCES `EventFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `TrackedEntityAttributeValueFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`trackedEntityAttributeUId` TEXT,`trackedEntityInstance` TEXT,`value` TEXT, UNIQUE(`trackedEntityInstance`) ON CONFLICT FAIL, FOREIGN KEY(`trackedEntityInstance`) REFERENCES `TrackedEntityInstanceFlow`(`trackedEntityInstanceUid`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `TrackedEntityAttributeFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`optionSet` TEXT,`isUnique` INTEGER,`programScope` INTEGER,`orgunitScope` INTEGER,`displayInListNoProgram` INTEGER,`displayOnVisitSchedule` INTEGER,`externalAccess` INTEGER,`valueType` null,`confidential` INTEGER,`inherit` INTEGER,`sortOrderVisitSchedule` INTEGER,`dimension` TEXT,`sortOrderInListNoProgram` INTEGER, FOREIGN KEY(`optionSet`) REFERENCES `OptionSetFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `StateFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`itemId` INTEGER,`itemType` TEXT,`action` null, UNIQUE(`itemId`,`itemType`) ON CONFLICT REPLACE); CREATE TABLE `RelationshipTypeFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`aIsToB` TEXT,`bIsToA` TEXT); CREATE TABLE `RelationshipFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`relationship` TEXT UNIQUE ON CONFLICT FAIL,`trackedEntityInstanceA` TEXT,`trackedEntityInstanceB` TEXT,`displayName` TEXT, UNIQUE(`relationship`,`trackedEntityInstanceA`,`trackedEntityInstanceB`) ON CONFLICT FAIL, FOREIGN KEY(`trackedEntityInstanceA`) REFERENCES `TrackedEntityInstanceFlow`(`trackedEntityInstanceUid`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`trackedEntityInstanceB`) REFERENCES `TrackedEntityInstanceFlow`(`trackedEntityInstanceUid`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ProgramTrackedEntityAttributeFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`trackedEntityAttribute` TEXT,`program` TEXT,`sortOrder` INTEGER,`allowFutureDate` INTEGER,`displayInList` INTEGER,`mandatory` INTEGER, FOREIGN KEY(`trackedEntityAttribute`) REFERENCES `TrackedEntityAttributeFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`program`) REFERENCES `ProgramFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ProgramStageSectionFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`sortOrder` INTEGER,`externalAccess` INTEGER,`programStage` TEXT, FOREIGN KEY(`programStage`) REFERENCES `ProgramStageFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ProgramStageFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`program` TEXT,`dataEntryType` TEXT,`blockEntryForm` INTEGER,`reportDateDescription` TEXT,`executionDateLabel` TEXT,`displayGenerateEventBox` INTEGER,`description` TEXT,`externalAccess` INTEGER,`openAfterEnrollment` INTEGER,`captureCoordinates` INTEGER,`defaultTemplateMessage` TEXT,`remindCompleted` INTEGER,`validCompleteOnly` INTEGER,`sortOrder` INTEGER,`generatedByEnrollmentDate` INTEGER,`preGenerateUID` INTEGER,`autoGenerateEvent` INTEGER,`allowGenerateNextVisit` INTEGER,`repeatable` INTEGER,`minDaysFromStart` INTEGER, FOREIGN KEY(`program`) REFERENCES `ProgramFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ProgramStageDataElementFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`programStage` TEXT,`programStageSection` TEXT,`dataElement` TEXT,`allowFutureDate` INTEGER,`sortOrder` INTEGER,`displayInReports` INTEGER,`allowProvidedElsewhere` INTEGER,`compulsory` INTEGER, FOREIGN KEY(`programStage`) REFERENCES `ProgramStageFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`programStageSection`) REFERENCES `ProgramStageSectionFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`dataElement`) REFERENCES `DataElementFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ProgramRuleVariableFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`sourceType` null,`program` TEXT,`programStage` TEXT,`dataElement` TEXT,`trackedEntityAttribute` TEXT, FOREIGN KEY(`program`) REFERENCES `ProgramFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`programStage`) REFERENCES `ProgramStageFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`dataElement`) REFERENCES `DataElementFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`trackedEntityAttribute`) REFERENCES `TrackedEntityAttributeFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `ProgramRuleFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`programStage` TEXT,`program` TEXT,`condition` TEXT,`description` TEXT,`priority` INTEGER,`externalAction` INTEGER, FOREIGN KEY(`programStage`) REFERENCES `ProgramStageFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`program`) REFERENCES `ProgramFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `ProgramRuleActionFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`programRuleActionType` null,`programRule` TEXT,`programStage` TEXT,`programStageSection` TEXT,`programIndicator` TEXT,`trackedEntityAttribute` TEXT,`dataElement` TEXT,`content` TEXT,`location` TEXT,`data` TEXT, FOREIGN KEY(`programRule`) REFERENCES `ProgramRuleFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`programStage`) REFERENCES `ProgramStageFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`programStageSection`) REFERENCES `ProgramStageSectionFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`programIndicator`) REFERENCES `ProgramIndicatorFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`trackedEntityAttribute`) REFERENCES `TrackedEntityAttributeFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION, FOREIGN KEY(`dataElement`) REFERENCES `DataElementFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `ProgramIndicatorToProgramStageSectionRelationFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`programIndicator` TEXT,`programStageSection` TEXT, FOREIGN KEY(`programIndicator`) REFERENCES `ProgramIndicatorFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`programStageSection`) REFERENCES `ProgramStageSectionFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ProgramIndicatorFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`program` TEXT,`programstage` TEXT,`programstagesection` TEXT,`code` TEXT,`expression` TEXT,`displayDescription` TEXT,`rootDate` TEXT,`externalAccess` INTEGER,`valueType` null,`displayShortName` TEXT, FOREIGN KEY(`program`) REFERENCES `ProgramFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`programstage`) REFERENCES `ProgramStageFlow`(`uId`) ON UPDATE NO ACTION ON DELETE SET NULL, FOREIGN KEY(`programstagesection`) REFERENCES `ProgramStageSectionFlow`(`uId`) ON UPDATE NO ACTION ON DELETE SET NULL); CREATE TABLE `ProgramFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`trackedEntity` TEXT,`programType` null,`version` INTEGER,`enrollmentDateLabel` TEXT,`description` TEXT,`onlyEnrollOnce` INTEGER,`externalAccess` INTEGER,`displayIncidentDate` INTEGER,`incidentDateLabel` TEXT,`registration` INTEGER,`selectEnrollmentDatesInFuture` INTEGER,`dataEntryMethod` INTEGER,`singleEvent` INTEGER,`ignoreOverdueEvents` INTEGER,`relationshipFromA` INTEGER,`selectIncidentDatesInFuture` INTEGER,`isAssignedToUser` INTEGER, FOREIGN KEY(`trackedEntity`) REFERENCES `TrackedEntityFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `OrganisationUnitToProgramRelationFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`organisationUnit` TEXT,`program` TEXT, UNIQUE(`organisationUnit`,`program`) ON CONFLICT REPLACE, FOREIGN KEY(`organisationUnit`) REFERENCES `OrganisationUnitFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`program`) REFERENCES `ProgramFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `OrganisationUnitFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`level` INTEGER,`parent` TEXT,`isAssignedToUser` INTEGER, FOREIGN KEY(`parent`) REFERENCES `OrganisationUnitFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `OptionSetFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`version` INTEGER); CREATE TABLE `OptionFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`sortOrder` INTEGER,`optionSet` TEXT,`code` TEXT, FOREIGN KEY(`optionSet`) REFERENCES `OptionSetFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ModelLinkFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`modelKeyOne` TEXT,`modelKeyTwo` TEXT,`linkMimeType` TEXT); CREATE TABLE `InterpretationFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`text` TEXT,`type` TEXT,`action` null NOT NULL,`user` TEXT, FOREIGN KEY(`user`) REFERENCES `UserFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `InterpretationElementFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`type` TEXT NOT NULL,`interpretation` TEXT, FOREIGN KEY(`interpretation`) REFERENCES `InterpretationFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `InterpretationCommentFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`text` TEXT,`user` TEXT,`interpretation` TEXT, FOREIGN KEY(`user`) REFERENCES `UserFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`interpretation`) REFERENCES `InterpretationFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `ImportSummaryFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`status` null,`description` TEXT,`importCount` INTEGER,`reference` TEXT,`href` TEXT, FOREIGN KEY(`importCount`) REFERENCES `ImportCountFlow`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `ImportCountFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`imported` INTEGER,`updated` INTEGER,`ignored` INTEGER,`deleted` INTEGER); CREATE TABLE `FailedItemFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`importSummary` INTEGER,`itemId` INTEGER UNIQUE ON CONFLICT FAIL,`itemType` null UNIQUE ON CONFLICT FAIL,`httpStatusCode` INTEGER,`errorMessage` TEXT, FOREIGN KEY(`importSummary`) REFERENCES `ImportSummaryFlow`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `EventFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`status` null,`latitude` REAL,`longitude` REAL,`program` TEXT,`programStage` TEXT,`orgUnit` TEXT,`eventDate` TEXT,`dueDate` TEXT); CREATE TABLE `EnrollmentFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`enrollmentUid` TEXT UNIQUE ON CONFLICT FAIL,`orgUnit` TEXT,`tei` TEXT,`program` TEXT,`dateOfEnrollment` TEXT,`dateOfIncident` TEXT,`followup` INTEGER,`status` TEXT,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT, FOREIGN KEY(`tei`) REFERENCES `TrackedEntityInstanceFlow`(`trackedEntityInstanceUid`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `DataSetFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`version` INTEGER,`expiryDays` INTEGER,`allowFuturePeriods` INTEGER,`periodType` TEXT,`categoryComboKey` TEXT, FOREIGN KEY(`categoryComboKey`) REFERENCES `CategoryComboFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `DataElementFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`valueType` null,`zeroIsSignificant` INTEGER,`aggregationOperator` TEXT,`formName` TEXT,`numberType` TEXT,`domainType` TEXT,`dimension` TEXT,`displayFormName` TEXT,`optionset` TEXT, FOREIGN KEY(`optionset`) REFERENCES `OptionSetFlow`(`uId`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `DashboardItemFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`type` TEXT,`shape` TEXT,`dashboard` TEXT, FOREIGN KEY(`dashboard`) REFERENCES `DashboardFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `DashboardFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT); CREATE TABLE `DashboardElementFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`dashboardItem` TEXT, FOREIGN KEY(`dashboardItem`) REFERENCES `DashboardItemFlow`(`uId`) ON UPDATE NO ACTION ON DELETE CASCADE); CREATE TABLE `DashboardContentFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`type` TEXT NOT NULL); CREATE TABLE `ConstantFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`value` REAL); CREATE TABLE `ConflictFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`importSummary` INTEGER,`object` TEXT,`value` TEXT, FOREIGN KEY(`importSummary`) REFERENCES `ImportSummaryFlow`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE TABLE `CategoryOptionFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT); CREATE TABLE `CategoryOptionComboFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT); CREATE TABLE `CategoryFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`dataDimension` TEXT,`dataDimensionType` TEXT,`dimension` TEXT); CREATE TABLE `CategoryComboFlow`(`id` INTEGER PRIMARY KEY AUTOINCREMENT,`uId` TEXT UNIQUE ON CONFLICT REPLACE,`name` TEXT,`displayName` TEXT,`created` TEXT,`lastUpdated` TEXT,`access` TEXT,`dimensionType` TEXT,`skipTotal` INTEGER); COMMIT;

  • Its need fix queries

The com.raizlabs.android.dbflow.sql.language.ColumnAlias not exist and is used in so many queries.

And its needed modify all the sdk imports and models in our queries.


  • its need use one dbflow instance to work with sdk database and our database:

The FlowManager is initialized in:

core-android/src/main/java/org/hisp/dhis/client/sdk/android/api/persistence/PersistenceModuleImpl

Look how create two modules with one dbflow here:

https://github.com/Raizlabs/DBFlow/issues/266

https://github.com/Raizlabs/DBFlow/blob/master/usage2/MultipleModules.md


Difference between dbflow models and sdk models:

The dhis models are in:

org.hisp.dhis.client.sdk.models.*

and the database POJOS are in :

org.hisp.dhis.client.sdk.android.api.persistence.*

Example: Event controllers

SDK Event

DB models

The sdk-dbflow(in core-android) uses XXXFlow.class models and the sdk uses XXX.class, the application entities are abstracted from the db POJOS, the sdk uses XXXStoreImpl to transform it, for example event to stored eventflow.

To create new sdk model we need create the follow structure:

XXXApiClientImpl contains the server querys

XXXApiClientRetrofit(Interfaz)

XXXInteractor(interfaz)

XXXInteractorImpl contains the observable calls

XXXStoreImpl contains the dbflow queries and the dbflow mapper.


  • Create and pull the follow entities:

Attribute

DataelementAttributeValue

OptionAttributeValue

OrganisationUnitAttribute

OrganisationUnitDataSet

OrganisationUnitGroup

OrganisationUnitLevel

ProgramAttributeValue

DataValue is now called TrackedEntityDataValue

Note: The sdk is using a new table called ModelLinkFlow to create relations between entities.


  • Create missing queries: getMinimizedEvents getEventsFromDate getEventsBetweenDate getOrganisationUnitLevels()

Create Events queries in: To create queries in EventApiClientImpl/EventApiClient(Interface) Tp create or modify pull in EventControllerImpl.

Fix activities:


  • EyeSeeTeaApplication -> EventCaptureApp in EventCapture App The sdk needs a Inject class that need be initialise here with Inject.init method, and it needs dagger.

We need build a DraggerAppComponent from the dagger library for that. (It should compile with the project not have compilation errors).


LoginActivity should extends from DefaultLoginActivity.

The sdk uses a LoginPresenter that calls validateCredentials, that calls onSuccess(). We can overwrite the method navigateToHome or OnSuccess.


  • ProgressActivity -> Progressactivity not exists in the sdk or in EventCapture App

The EventCapture App use showProgressBar() method. This fragment use a SwipeRefreshLayout to show the progress wheel.

Note: The dhis2Api class is only used by the sdk with the method "getDashboards", for example the events queries are in the events package(EventControllerImpl to call requests to the server and XXXStoreImpl to use local db).

Pull:


  • Its need pull all the necessary from the server.

The EventCapture App is downloading only:

"OrganisationUnitFlow" "ModelLinkFlow" "ProgramFlow" "ProgramStageFlow" "ProgramStageSectionFlow" "ProgramStageDataElementFlow" "DataElementFlow" "OptionFlow" "OptionSetFlow"


  • Its need include all the missing Pojos and download:

Attribute not exists

Dataelement is pulled as DataelementFlow

DataElementAttributeValue not exists

DataValue is not pulled and is TrackedEntityDataValue

Event is not pulled and is EventFlow

Option is pulled as OptionFlow

OptionAttributeValue not exists

OptionSet is pulled as OptionSetFlow

OrganisationUnit is pulled as OrganisationUnitFlow

OrganisationUnitAttributeValue not exists

OrganisationUnitDataSet not exists

OrganisationUnitGroup not exists

OrganisationUnitLevel not exists

OrganisationUnitProgamRelationship

Program is pulled as ProgramFlow

ProgramAttributeValue not exists

ProgramStage is pulled as ProgramStageFlow

ProgramStageDataElement is pulled as ProgramStageDataElementFlow

ProgramStageSection is pulled as ProgramStageSectionFlow

UserAccount is pulled as UserAccountFlow

We need copy the SyncWrapper class from Eventcapture App.

This class is used to pull the programs and the organisationunits. Special attention to the methods syncMetaData() and syncData()


  • Its need convert from DB to sdk model to our DB.

Push:

  • Its need change the convertToSdkVisitor in some steps.

For example: The events not have LocalEventId, and not have setFromServer, the date format is datatime.

To create a event we need take a look at:

createEvent in SelectorPresenterImpl in the eventcapture App.

  • Its need change the push methods to use the new push.

We can look a example of the event push in syncData() called by sync() in the eventCapture