From cc837780f3ae36de5afd1a2ffd59b86f65242035 Mon Sep 17 00:00:00 2001 From: Ivan Arrizabalaga Date: Tue, 12 Jan 2016 17:38:54 +0100 Subject: [PATCH 01/81] Moves latests malariapp database model into pictureapp --- app/src/main/assets/Answers.csv | 14 +- app/src/main/assets/Questions.csv | 14 +- app/src/main/assets/TabGroups.csv | 1 + app/src/main/assets/Tabs.csv | 2 +- .../eyeseetea/malariacare/BaseActivity.java | 7 +- .../malariacare/CreateSurveyActivity.java | 66 +- .../malariacare/EyeSeeTeaApplication.java | 21 + .../eyeseetea/malariacare/SurveyActivity.java | 8 +- .../malariacare/database/model/Answer.java | 63 +- .../database/model/CompositeScore.java | 165 +++-- .../malariacare/database/model/Header.java | 81 ++- .../malariacare/database/model/Match.java | 126 ++++ .../malariacare/database/model/Option.java | 100 +-- .../malariacare/database/model/OrgUnit.java | 122 +++- .../database/model/OrgUnitLevel.java | 108 +++ .../malariacare/database/model/Program.java | 49 +- .../malariacare/database/model/Question.java | 624 +++++++++++++----- .../database/model/QuestionOption.java | 174 +++++ .../database/model/QuestionRelation.java | 134 ++-- .../malariacare/database/model/Score.java | 97 +-- .../malariacare/database/model/Survey.java | 574 ++++++++++++---- .../malariacare/database/model/Tab.java | 139 ++-- .../malariacare/database/model/TabGroup.java | 171 +++++ .../malariacare/database/model/User.java | 60 +- .../malariacare/database/model/Value.java | 141 ++-- .../database/utils/PopulateDB.java | 71 +- .../database/utils/ReadWriteDB.java | 2 +- .../adapters/survey/AutoTabAdapter.java | 113 ++-- .../survey/CompositeScoreAdapter.java | 2 +- .../survey/CustomAdherenceAdapter.java | 41 +- .../adapters/survey/CustomIQTABAdapter.java | 26 +- .../survey/CustomReportingAdapter.java | 10 +- .../adapters/survey/DynamicTabAdapter.java | 2 +- .../layout/score/ScoreRegister.java | 25 +- .../malariacare/layout/utils/LayoutUtils.java | 215 ------ .../malariacare/network/PushClient.java | 12 +- .../malariacare/services/SurveyService.java | 4 +- .../malariacare/utils/Constants.java | 42 +- 38 files changed, 2422 insertions(+), 1204 deletions(-) create mode 100644 app/src/main/assets/TabGroups.csv create mode 100644 app/src/main/java/org/eyeseetea/malariacare/database/model/Match.java create mode 100644 app/src/main/java/org/eyeseetea/malariacare/database/model/OrgUnitLevel.java create mode 100644 app/src/main/java/org/eyeseetea/malariacare/database/model/QuestionOption.java create mode 100644 app/src/main/java/org/eyeseetea/malariacare/database/model/TabGroup.java diff --git a/app/src/main/assets/Answers.csv b/app/src/main/assets/Answers.csv index 5ca9c10042..ea7b889833 100644 --- a/app/src/main/assets/Answers.csv +++ b/app/src/main/assets/Answers.csv @@ -1,7 +1,7 @@ -1;'RDT';14 -2;'Sex';10 -3;'Age';6 -4;'Specie';14 -5;'Treatment';11 -6;'Risk Group';11 -7;'Phone';13 +1;'RDT' +2;'Sex' +3;'Age' +4;'Specie' +5;'Treatment' +6;'Risk Group' +7;'Phone' diff --git a/app/src/main/assets/Questions.csv b/app/src/main/assets/Questions.csv index a7b2506dfb..42d3659deb 100644 --- a/app/src/main/assets/Questions.csv +++ b/app/src/main/assets/Questions.csv @@ -1,7 +1,7 @@ -1;'RDT';'What is your patient\'s RDT result?';;'តើលទ្ធផលតេស្តឈាមរបស់អ្នកជំងឺដោយប្រើ ឧបករណ៍ RDT បង្ហាញថាជាអ្វី?';'OEdLEjF6Z8p';1;0;0;1;1;1 -2;'Sex';'Male or Female?';;'ប្រុស ឬ ស្រី?';'uuudizosfpU';2;0;0;1;2;1 -3;'Age';'How old is your patient (years)?';;'តើអ្នកជំងឺរបស់អ្នកមានអាយុប៉ុន្មាន​(ឆ្នាំ)?';'JMM92njKuSc';3;0;0;1;3;1 -4;'Specie';'What type of malaria does your patient have?';;'តើអ្នកជំងឺរបស់អ្នកមានមេរោគគ្រុនចាញ់ប្រភេទអ្វី?';'X6RFHreAu0L';4;0;0;1;4;1 -5;'Treatment';'What type of treatment did you provide?';;'តើការព្យាបាលបែបណាដែលអ្នកផ្តល់ជូនអ្នកជំងឺ?';'fNpYtVaL7OV';5;0;0;1;5;1 -6;'Risk Group';'Where did your patient get malaria?';;'តើអ្នកជំងឺឆ្លងជំងឺគ្រុនចាញ់ពីកន្លែងណា?';'IR2vkwx9D8H';6;0;0;1;6;1 -7;'Phone';'Please enter your patient’s phone number.';;'សូមវាយបញ្ចូលលេខទូរស័ព្ទអ្នកជំងឺ';'rDubghVv1L8';7;0;0;1;7;1 +1;'RDT';'What is your patient\'s RDT result?';;'តើលទ្ធផលតេស្តឈាមរបស់អ្នកជំងឺដោយប្រើ ឧបករណ៍ RDT បង្ហាញថាជាអ្វី?';'OEdLEjF6Z8p';1;0;0;1;1;1;14 +2;'Sex';'Male or Female?';;'ប្រុស ឬ ស្រី?';'uuudizosfpU';2;0;0;1;2;1;10 +3;'Age';'How old is your patient (years)?';;'តើអ្នកជំងឺរបស់អ្នកមានអាយុប៉ុន្មាន​(ឆ្នាំ)?';'JMM92njKuSc';3;0;0;1;3;1;6 +4;'Specie';'What type of malaria does your patient have?';;'តើអ្នកជំងឺរបស់អ្នកមានមេរោគគ្រុនចាញ់ប្រភេទអ្វី?';'X6RFHreAu0L';4;0;0;1;4;1;14 +5;'Treatment';'What type of treatment did you provide?';;'តើការព្យាបាលបែបណាដែលអ្នកផ្តល់ជូនអ្នកជំងឺ?';'fNpYtVaL7OV';5;0;0;1;5;1;11 +6;'Risk Group';'Where did your patient get malaria?';;'តើអ្នកជំងឺឆ្លងជំងឺគ្រុនចាញ់ពីកន្លែងណា?';'IR2vkwx9D8H';6;0;0;1;6;1;11 +7;'Phone';'Please enter your patient’s phone number.';;'សូមវាយបញ្ចូលលេខទូរស័ព្ទអ្នកជំងឺ';'rDubghVv1L8';7;0;0;1;7;1;13 diff --git a/app/src/main/assets/TabGroups.csv b/app/src/main/assets/TabGroups.csv new file mode 100644 index 0000000000..712708328b --- /dev/null +++ b/app/src/main/assets/TabGroups.csv @@ -0,0 +1 @@ +1;'Health System QIS TabGroup';1 diff --git a/app/src/main/assets/Tabs.csv b/app/src/main/assets/Tabs.csv index a2505bc0a4..938fdc56e0 100644 --- a/app/src/main/assets/Tabs.csv +++ b/app/src/main/assets/Tabs.csv @@ -1 +1 @@ -1;'Health System QIS';1;1;8 +1;'Health System QIS';1;1;9 diff --git a/app/src/main/java/org/eyeseetea/malariacare/BaseActivity.java b/app/src/main/java/org/eyeseetea/malariacare/BaseActivity.java index 91652da882..130f14f599 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/BaseActivity.java +++ b/app/src/main/java/org/eyeseetea/malariacare/BaseActivity.java @@ -47,6 +47,7 @@ import org.eyeseetea.malariacare.database.model.Program; import org.eyeseetea.malariacare.database.model.Program$Table; import org.eyeseetea.malariacare.database.model.Survey; +import org.eyeseetea.malariacare.database.model.TabGroup; import org.eyeseetea.malariacare.database.utils.LocationMemory; import org.eyeseetea.malariacare.database.utils.PreferencesState; import org.eyeseetea.malariacare.database.utils.Session; @@ -188,10 +189,10 @@ public void onClick(DialogInterface arg0, int arg1) { } public void newSurvey(View v){ - //Get Programs from database - List firstProgram = new Select().from(Program.class).where(Condition.column(Program$Table.ID_PROGRAM).eq(1)).queryList(); + + TabGroup tabGroup = new Select().from(TabGroup.class).querySingle(); // Put new survey in session - Survey survey = new Survey(null, firstProgram.get(0), Session.getUser()); + Survey survey = new Survey(null, tabGroup, Session.getUser()); survey.save(); Session.setSurvey(survey); diff --git a/app/src/main/java/org/eyeseetea/malariacare/CreateSurveyActivity.java b/app/src/main/java/org/eyeseetea/malariacare/CreateSurveyActivity.java index c848c80adb..4d0eb4898a 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/CreateSurveyActivity.java +++ b/app/src/main/java/org/eyeseetea/malariacare/CreateSurveyActivity.java @@ -40,6 +40,7 @@ import java.util.List; +//TODO This whole file should be removed from pictureapp public class CreateSurveyActivity extends BaseActivity { // UI references. @@ -85,43 +86,46 @@ public boolean checkEverythingFilled() { } public boolean checkSurveyDoesntExist() { - // Read Selected Items - OrgUnit orgUnit = (OrgUnit) orgUnitView.getSelectedItem(); - Program program = (Program) programView.getSelectedItem(); - - List existing = Survey.getUnsentSurveys(orgUnit, program); - return (existing == null || existing.size() == 0); + return true; + //FIXME Commented since pictureapp does not create surveys from this activity +// // Read Selected Items +// OrgUnit orgUnit = (OrgUnit) orgUnitView.getSelectedItem(); +// Program program = (Program) programView.getSelectedItem(); +// +// List existing = Survey.getUnsentSurveys(orgUnit, program); +// return (existing == null || existing.size() == 0); } /** * Called when the user clicks the Send button */ public void createSurvey(View view) { - Log.i(".CreateSurveyActivity", "Saving survey and saving in session"); - - // Read Selected Items - OrgUnit orgUnit = (OrgUnit) orgUnitView.getSelectedItem(); - Program program = (Program) programView.getSelectedItem(); - - if (!checkEverythingFilled()) { - new AlertDialog.Builder(this) - .setTitle(getApplicationContext().getString(R.string.dialog_title_missing_selection)) - .setMessage(getApplicationContext().getString(R.string.dialog_content_missing_selection)) - .setPositiveButton(android.R.string.ok, null).create().show(); - } else if (!checkSurveyDoesntExist()) { - new AlertDialog.Builder(this) - .setTitle(getApplicationContext().getString(R.string.dialog_title_existing_survey)) - .setMessage(getApplicationContext().getString(R.string.dialog_content_existing_survey)) - .setPositiveButton(android.R.string.ok, null).create().show(); - } else { - // Put new survey in session - Survey survey = new Survey(orgUnit, program, Session.getUser()); - survey.save(); - Session.setSurvey(survey); - - //Call Survey Activity - finishAndGo(SurveyActivity.class); - } + //FIXME Commented since pictureapp does not create surveys from this activity +// Log.i(".CreateSurveyActivity", "Saving survey and saving in session"); +// +// // Read Selected Items +// OrgUnit orgUnit = (OrgUnit) orgUnitView.getSelectedItem(); +// Program program = (Program) programView.getSelectedItem(); +// +// if (!checkEverythingFilled()) { +// new AlertDialog.Builder(this) +// .setTitle(getApplicationContext().getString(R.string.dialog_title_missing_selection)) +// .setMessage(getApplicationContext().getString(R.string.dialog_content_missing_selection)) +// .setPositiveButton(android.R.string.ok, null).create().show(); +// } else if (!checkSurveyDoesntExist()) { +// new AlertDialog.Builder(this) +// .setTitle(getApplicationContext().getString(R.string.dialog_title_existing_survey)) +// .setMessage(getApplicationContext().getString(R.string.dialog_content_existing_survey)) +// .setPositiveButton(android.R.string.ok, null).create().show(); +// } else { +// // Put new survey in session +// Survey survey = new Survey(orgUnit, program, Session.getUser()); +// survey.save(); +// Session.setSurvey(survey); +// +// //Call Survey Activity +// finishAndGo(SurveyActivity.class); +// } } diff --git a/app/src/main/java/org/eyeseetea/malariacare/EyeSeeTeaApplication.java b/app/src/main/java/org/eyeseetea/malariacare/EyeSeeTeaApplication.java index dbb5f992e3..d6e5924411 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/EyeSeeTeaApplication.java +++ b/app/src/main/java/org/eyeseetea/malariacare/EyeSeeTeaApplication.java @@ -26,11 +26,21 @@ import com.crashlytics.android.Crashlytics; import com.raizlabs.android.dbflow.config.FlowManager; +import com.raizlabs.android.dbflow.sql.index.Index; +import org.eyeseetea.malariacare.database.model.Match; +import org.eyeseetea.malariacare.database.model.Match$Table; +import org.eyeseetea.malariacare.database.model.QuestionOption; +import org.eyeseetea.malariacare.database.model.QuestionOption$Table; +import org.eyeseetea.malariacare.database.model.QuestionRelation; +import org.eyeseetea.malariacare.database.model.QuestionRelation$Table; +import org.eyeseetea.malariacare.database.model.Value; +import org.eyeseetea.malariacare.database.model.Value$Table; import org.eyeseetea.malariacare.database.utils.LocationMemory; import org.eyeseetea.malariacare.database.utils.PreferencesState; import org.eyeseetea.malariacare.database.utils.Session; import org.eyeseetea.malariacare.phonemetadata.PhoneMetaData; +import org.eyeseetea.malariacare.utils.Constants; import io.fabric.sdk.android.Fabric; @@ -51,8 +61,19 @@ public void onCreate() { Session.setPhoneMetaData(phoneMetaData); FlowManager.init(this); + createDBIndexes(); } + private void createDBIndexes(){ + new Index(Constants.QUESTION_OPTION_IDX).on(QuestionOption.class, QuestionOption$Table.ID_QUESTION).enable(); + new Index(Constants.QUESTION_RELATION_IDX).on(QuestionRelation.class, QuestionRelation$Table.OPERATION).enable(); + //XXX This should be reviewed + new Index(Constants.QUESTION_RELATION_IDX).on(QuestionRelation.class, QuestionRelation$Table.ID_QUESTION).enable(); + new Index(Constants.MATCH_IDX).on(Match.class, Match$Table.ID_QUESTION_RELATION).enable(); + new Index(Constants.VALUE_IDX).on(Value.class, Value$Table.ID_SURVEY).enable(); + } + + PhoneMetaData getPhoneMetadata(){ PhoneMetaData phoneMetaData=new PhoneMetaData(); TelephonyManager phoneManagerMetaData=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); diff --git a/app/src/main/java/org/eyeseetea/malariacare/SurveyActivity.java b/app/src/main/java/org/eyeseetea/malariacare/SurveyActivity.java index 6ac76ac532..d625c52ee1 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/SurveyActivity.java +++ b/app/src/main/java/org/eyeseetea/malariacare/SurveyActivity.java @@ -24,7 +24,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; -import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.content.LocalBroadcastManager; @@ -32,12 +31,10 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.View; -import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; -import android.widget.Spinner; import org.eyeseetea.malariacare.database.model.CompositeScore; import org.eyeseetea.malariacare.database.model.Option; @@ -47,7 +44,6 @@ import org.eyeseetea.malariacare.database.model.Tab; import org.eyeseetea.malariacare.database.utils.PreferencesState; import org.eyeseetea.malariacare.database.utils.Session; -import org.eyeseetea.malariacare.layout.adapters.general.TabArrayAdapter; import org.eyeseetea.malariacare.layout.adapters.survey.AutoTabAdapter; import org.eyeseetea.malariacare.layout.adapters.survey.CompositeScoreAdapter; import org.eyeseetea.malariacare.layout.adapters.survey.CustomAdherenceAdapter; @@ -58,8 +54,6 @@ import org.eyeseetea.malariacare.layout.utils.LayoutUtils; import org.eyeseetea.malariacare.services.SurveyService; import org.eyeseetea.malariacare.utils.Constants; -import org.eyeseetea.malariacare.utils.Utils; -import org.eyeseetea.malariacare.views.TextCard; import java.util.ArrayList; import java.util.HashMap; @@ -233,7 +227,7 @@ protected void onPostExecute(View viewContent) { content.removeAllViews(); content.addView(viewContent); ITabAdapter tabAdapter = tabAdaptersCache.findAdapter(tab); - if ( tab.getType() == Constants.TAB_AUTOMATIC_SCORED || + if ( tab.getType() == Constants.TAB_AUTOMATIC || tab.getType() == Constants.TAB_ADHERENCE || tab.getType() == Constants.TAB_IQATAB || tab.getType() == Constants.TAB_SCORE_SUMMARY) { diff --git a/app/src/main/java/org/eyeseetea/malariacare/database/model/Answer.java b/app/src/main/java/org/eyeseetea/malariacare/database/model/Answer.java index 6dfc1ad990..be5c16dce8 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/database/model/Answer.java +++ b/app/src/main/java/org/eyeseetea/malariacare/database/model/Answer.java @@ -1,26 +1,25 @@ /* * Copyright (c) 2015. * - * This file is part of QIS Survelliance App. + * This file is part of QA App. * - * QIS Survelliance App is free software: you can redistribute it and/or modify + * Facility QA Tool App is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * QIS Survelliance App is distributed in the hope that it will be useful, + * Facility QA Tool App is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with QIS Survelliance App. If not, see . + * along with Foobar. If not, see . */ package org.eyeseetea.malariacare.database.model; import com.raizlabs.android.dbflow.annotation.Column; -import com.raizlabs.android.dbflow.annotation.OneToMany; import com.raizlabs.android.dbflow.annotation.PrimaryKey; import com.raizlabs.android.dbflow.annotation.Table; import com.raizlabs.android.dbflow.sql.builder.Condition; @@ -34,26 +33,32 @@ @Table(databaseName = AppDatabase.NAME) public class Answer extends BaseModel { + /** + * Default mock answer.output value + */ + public static final Integer DEFAULT_ANSWER_OUTPUT = -1; + @Column @PrimaryKey(autoincrement = true) long id_answer; - @Column String name; - @Column - Integer output; - + /** + * List of options that belongs to this answer type + */ List