Skip to content

Commit

Permalink
Merge pull request #715 from EyeSeeTea/code-v1.0
Browse files Browse the repository at this point in the history
Code v1.0
  • Loading branch information
ifoche committed Jan 24, 2016
2 parents d8d54b0 + 7b6b72f commit f27bdb8
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 102 deletions.
34 changes: 17 additions & 17 deletions app/src/edsGhana/assets/Questions.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eyeseetea.malariacare.fragments.DashboardSentFragment;
import org.eyeseetea.malariacare.fragments.DashboardUnsentFragment;
import org.eyeseetea.malariacare.services.SurveyService;
import org.eyeseetea.malariacare.utils.Constants;

import java.io.IOException;
import java.util.List;
Expand All @@ -57,6 +58,9 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_dashboard);

// Set the value that will hide questions
Constants.HIDE_VALUE = getString(R.string.no);

try {
initDataIfRequired();
loadSessionIfRequired();
Expand Down
73 changes: 7 additions & 66 deletions app/src/main/java/org/eyeseetea/malariacare/SurveyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eyeseetea.malariacare.database.model.Question;
import org.eyeseetea.malariacare.database.model.Survey;
import org.eyeseetea.malariacare.database.model.Tab;
import org.eyeseetea.malariacare.database.model.Value;
import org.eyeseetea.malariacare.database.utils.Session;
import org.eyeseetea.malariacare.layout.adapters.general.TabArrayAdapter;
import org.eyeseetea.malariacare.layout.adapters.survey.AutoTabAdapter;
Expand Down Expand Up @@ -253,16 +254,8 @@ protected void onPreExecute() {

@Override
protected View doInBackground(Void... params) {

Log.d(TAG, "doInBackground("+Thread.currentThread().getId()+")..");
View view=null;
if (tab.isGeneralScore()) {
showGeneralScores();
} else {
view=prepareTab(tab);
}
Log.d(TAG, "doInBackground(" + Thread.currentThread().getId() + ")..DONE");
return view;
return prepareTab(tab);
}

@Override
Expand Down Expand Up @@ -320,64 +313,17 @@ private View prepareTab(Tab selectedTab) {
LayoutInflater inflater = LayoutInflater.from(this);

if(selectedTab.isCompositeScore()){
//Initialize scores x question not loaded yet
List<Tab> notLoadedTabs=tabAdaptersCache.getNotLoadedTabs();
ScoreRegister.initScoresForQuestions(Question.listAllByTabs(notLoadedTabs), Session.getSurvey());
//Register scores for composites
List<CompositeScore> compositeScoreList=CompositeScore.listByTabGroup(Session.getSurvey().getTabGroup());
ScoreRegister.registerCompositeScores(compositeScoreList);

ScoreRegister.initScoresForQuestions(Question.listAllByTabs(tabsList), Session.getSurvey());
}
ITabAdapter tabAdapter=tabAdaptersCache.findAdapter(selectedTab);

return inflater.inflate(tabAdapter.getLayout(), content, false);
}

/**
* Shows the special 'Score' tab
*/
private void showGeneralScores() {
LayoutInflater inflater = LayoutInflater.from(this);

content.removeAllViews();
View view = inflater.inflate(R.layout.scoretab, content, false);
content.addView(view);

List<ITabAdapter> adaptersList = tabAdaptersCache.list();
Float avgClinical = 0F;
Float avgRdt = 0F;
Float avgOverall = 0F;
for(ITabAdapter adapter:adaptersList){
updateViewInGeneralScores(adapter);
avgClinical += valueForClinical(adapter);
avgRdt += valueForRdt(adapter);
avgOverall += valueForOverall(adapter);
}

avgClinical = avgClinical/3;
avgRdt = avgRdt/3;
avgOverall = (avgOverall+avgClinical+avgRdt)/5;

updateAvgInGeneralScores(R.id.clinicalAvg, avgClinical);
updateAvgInGeneralScores(R.id.rdtAvg, avgRdt);
updateAvgInGeneralScores(R.id.totalScore, avgOverall);
}

private void updateViewInGeneralScores(ITabAdapter adapter){

if(isNotAutoTabAdapterOrNull(adapter)){
return;
}

Float score=adapter.getScore();
if(score==null){
return;
}
Tab tab=((AutoTabAdapter)adapter).getTab();
int viewId=IDS_SCORES_IN_GENERAL_TAB[tab.getOrder_pos()];
if(viewId!=0) {
CustomTextView customTextView =((CustomTextView) this.findViewById(viewId));
customTextView.setText(Utils.round(score));
LayoutUtils.trafficLight(customTextView, score, null);
}
}

private Float valueForClinical(ITabAdapter adapter){
return valueForAvg(adapter,ORDER_TABS_AVG_CLINICAL);
}
Expand Down Expand Up @@ -428,11 +374,6 @@ private boolean isNotAutoTabAdapterOrNull(ITabAdapter adapter){
return adapter==null || !(adapter instanceof AutoTabAdapter);
}

private void updateAvgInGeneralScores(int viewId, Float score){
((CustomTextView) this.findViewById(viewId)).setText(Utils.round(score));
LayoutUtils.trafficLight(this.findViewById(viewId), score, null);
}

/**
* Stops progress view and shows real form
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ public boolean isHiddenBySurvey(Survey survey){
if (parent!= null && parent.getValueBySurvey(survey)==null && !parent.belongsToCustomTab()) {
return true;
}
//There is a parent question and it is answered but answered with the value that hides the child question and it is not a phantom question
if (parent!= null && parent.getValueBySurvey(survey).getValue()==Constants.HIDE_VALUE && !parent.belongsToCustomTab()) {
return true;
}

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ public static List<Tab> getTabsBySession(){
.orderBy(Tab$Table.ORDER_POS).queryList();
}

/**
* Checks if this tab is a general score tab.
* @return
*/
public boolean isGeneralScore(){
return getType() == Constants.TAB_SCORE_SUMMARY && !isCompositeScore();
}

/**
* Checks if this tab is the composite score tab
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,12 @@ public View getView(int position, View convertView, ViewGroup parent) {

//Put current value in the component
setValues(viewHolder, question);
//Disables component if survey has already been sent
AutoTabLayoutUtils.updateReadOnly(viewHolder.component, getReadOnly());
//Disables component if survey has already been sent (except match spinner that are always disabled)
if(question.getAnswer().getOutput()==Constants.DROPDOWN_LIST_DISABLED){
AutoTabLayoutUtils.updateReadOnly(viewHolder.component, true);
}else{
AutoTabLayoutUtils.updateReadOnly(viewHolder.component, getReadOnly());
}
} else {
rowView = getInflater().inflate(R.layout.headers, parent, false);
viewHolder.statement = (CustomTextView) rowView.findViewById(R.id.headerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ public List<Float> calculateNumDenTotal(List<Float> numDenTotal){

}

public void clearRecords(){
numDenRecord.clear();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eyeseetea.malariacare.database.model.Question;
import org.eyeseetea.malariacare.database.model.Survey;
import org.eyeseetea.malariacare.database.model.Tab;
import org.eyeseetea.malariacare.database.model.Value;
import org.eyeseetea.malariacare.database.utils.Session;

import java.util.ArrayList;
Expand Down Expand Up @@ -81,13 +82,7 @@ public static void deleteRecord(Question question){
private static List<Float> getRecursiveScore(CompositeScore cScore, List<Float> result) {

if (!cScore.hasChildren()) {

//FIXME this try catch just covers a error in data compositeScore: '4.2'
try{
return compositeScoreMap.get(cScore).calculateNumDenTotal(result);
}catch(Exception ex){
return Arrays.asList(new Float(0f),new Float(0f));
}
return compositeScoreMap.get(cScore).calculateNumDenTotal(result);
}else {
for (CompositeScore cScoreChildren : cScore.getCompositeScoreChildren())
result = getRecursiveScore(cScoreChildren, result);
Expand All @@ -100,7 +95,7 @@ public static List<Float> getNumDenum(Question question) {
}

public static Float getCompositeScore(CompositeScore cScore) {

List<Float>result = compositeScoreMap.get(cScore).calculateNumDenTotal(new ArrayList<>(Arrays.asList(0F, 0F)));

result = getRecursiveScore(cScore, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private JSONArray prepareCompositeScores(JSONArray values) throws Exception{
ScoreRegister.registerCompositeScores(compositeScoreList);

//Initialize scores x question
ScoreRegister.initScoresForQuestions(Question.listByTabGroup(survey.getTabGroup()),survey);
ScoreRegister.initScoresForQuestions(Question.listByTabGroup(survey.getTabGroup()), survey);

//1 CompositeScore -> 1 dataValue
for(CompositeScore compositeScore:compositeScoreList){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ public class Constants {

public static final String CHECKBOX_YES_OPTION="Yes";

public static String HIDE_VALUE;

}

0 comments on commit f27bdb8

Please sign in to comment.