From 2059c639c37cc91b43b4ea769eb5d37f718ce6e6 Mon Sep 17 00:00:00 2001 From: idelcano Date: Wed, 28 Mar 2018 21:42:30 +0200 Subject: [PATCH 1/6] fix starter required question count --- .../org/eyeseetea/malariacare/data/database/model/Survey.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Survey.java b/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Survey.java index 68420aecce..77e6de7eb6 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Survey.java +++ b/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Survey.java @@ -962,6 +962,10 @@ public SurveyAnsweredRatio reloadSurveyAnsweredRatio() { Program program = Program.getFirstProgram(); Tab tab = program.getTabs().get(0); + if(tab.isMultiQuestionTab()){ + //First parent is calculated when tab is multiquestiontab + numRequired=0; + } Question rootQuestion = Question.findRootQuestion(tab); Question localQuestion = rootQuestion; while (localQuestion.getSibling() != null) { From 9cb412a7fcfa2bc87368296d6531aa9895b71b66 Mon Sep 17 00:00:00 2001 From: idelcano Date: Wed, 28 Mar 2018 21:43:41 +0200 Subject: [PATCH 2/6] fix udate survey, execute updatesurvey status one time --- .../malariacare/domain/usecase/CompletionSurveyUseCase.java | 1 + .../malariacare/strategies/DashboardActivityStrategy.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/myanmar/java/org/eyeseetea/malariacare/domain/usecase/CompletionSurveyUseCase.java b/app/src/myanmar/java/org/eyeseetea/malariacare/domain/usecase/CompletionSurveyUseCase.java index 1069d74921..c2da7d493e 100644 --- a/app/src/myanmar/java/org/eyeseetea/malariacare/domain/usecase/CompletionSurveyUseCase.java +++ b/app/src/myanmar/java/org/eyeseetea/malariacare/domain/usecase/CompletionSurveyUseCase.java @@ -67,6 +67,7 @@ private void updateRDTStockQuestion(Survey survey) { propagateQuestion.insertValue(rdtStockValue.getValue(), Session.getMalariaSurvey()).save(); } + Session.getStockSurvey().complete(); } } diff --git a/app/src/myanmar/java/org/eyeseetea/malariacare/strategies/DashboardActivityStrategy.java b/app/src/myanmar/java/org/eyeseetea/malariacare/strategies/DashboardActivityStrategy.java index 2a071cfc32..834ee1d6ee 100644 --- a/app/src/myanmar/java/org/eyeseetea/malariacare/strategies/DashboardActivityStrategy.java +++ b/app/src/myanmar/java/org/eyeseetea/malariacare/strategies/DashboardActivityStrategy.java @@ -84,14 +84,14 @@ public void newSurvey(Activity activity) { @Override public void sendSurvey() { - Session.getMalariaSurvey().updateSurveyStatus(); Survey stockSurvey = Session.getStockSurvey(); if (stockSurvey != null) { - Session.getStockSurvey().complete(); Date eventDate = new Date(); saveEventDate(Session.getMalariaSurvey(), eventDate); saveEventDate(Session.getStockSurvey(), eventDate); new CompletionSurveyUseCase().execute(Session.getMalariaSurvey().getId_survey()); + }else{ + Session.getMalariaSurvey().updateSurveyStatus(); } } From 3f3f6024ec3b0d6292f4d8bbcef92392a27f3709 Mon Sep 17 00:00:00 2001 From: idelcano Date: Thu, 29 Mar 2018 19:39:34 +0200 Subject: [PATCH 3/6] Added negativeQuestionUID in strings --- app/src/myanmar/res/values/donottranslate.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/myanmar/res/values/donottranslate.xml b/app/src/myanmar/res/values/donottranslate.xml index 2b248914cd..f8b02fe821 100644 --- a/app/src/myanmar/res/values/donottranslate.xml +++ b/app/src/myanmar/res/values/donottranslate.xml @@ -43,6 +43,7 @@ yPACdIBZEeZ FGG1GvvS8Xg lhJLBNebHcz + NoDataElementNegative NoDataElementOrgUnit Dropdown parent my From 14c005c4e51588e472f45af1f3c05db72d88f564 Mon Sep 17 00:00:00 2001 From: idelcano Date: Thu, 29 Mar 2018 19:41:16 +0200 Subject: [PATCH 4/6] Remove stock values when the survey ends with negative or invalid rdt --- .../layout/adapters/survey/DynamicTabAdapter.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/org/eyeseetea/malariacare/layout/adapters/survey/DynamicTabAdapter.java b/app/src/main/java/org/eyeseetea/malariacare/layout/adapters/survey/DynamicTabAdapter.java index 8580deb994..e3b15d139b 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/layout/adapters/survey/DynamicTabAdapter.java +++ b/app/src/main/java/org/eyeseetea/malariacare/layout/adapters/survey/DynamicTabAdapter.java @@ -475,6 +475,7 @@ public View getView(int position, View convertView, ViewGroup parent) { doseByQuestion = treatment.getDoseByQuestion(); } else { screenQuestions = treatment.getNoTreatmentQuestions(); + navigationController.setTotalPages(7); } } else if (Tab.isMultiQuestionTab(tabType)) { @@ -1002,6 +1003,15 @@ public void run() { Question question = navigationController.getCurrentQuestion(); Value value = question.getValueBySession(); if (isDone(value)) { + if (question!=null && (question.isNegative() || question.isRDT())){ + Treatment.cleanNotTreatmentQuestion(); + Session.getMalariaSurvey().deleteStockValues(); + for(Value stockValue:Session.getStockSurvey().getValuesFromDB()){ + if(stockValue.getQuestion()!=null && !stockValue.getQuestion().isRDT()){ + stockValue.delete(); + } + } + } navigationController.isMovingToForward = false; if (!wasPatientTested() || !BuildConfig.reviewScreen) { surveyShowDone(); From 6bec7ec17e01c25e1426c336be1a5f75a22eaec8 Mon Sep 17 00:00:00 2001 From: idelcano Date: Thu, 29 Mar 2018 19:43:34 +0200 Subject: [PATCH 5/6] Added isNegative check --- .../malariacare/data/database/model/Question.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Question.java b/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Question.java index ab5328e840..17316c7d45 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Question.java +++ b/app/src/main/java/org/eyeseetea/malariacare/data/database/model/Question.java @@ -1580,6 +1580,10 @@ public boolean isInvalidCounter() { return uid_question.equals(getContext().getString(R.string.confirmInvalidQuestionUID)); } + public boolean isNegative() { + return uid_question.equals(getContext().getString(R.string.negativeQuestionUID)); + } + public boolean isACT6() { return uid_question.equals(getContext().getString(R.string.act6QuestionUID)); } @@ -1825,6 +1829,10 @@ public String toString() { '}'; } + public static List getQuestionsWithoutHeader(){ + return new Select().from(Question.class).where(Question_Table.id_header_fk.isNull()).queryList(); + } + public List getPropagationQuestions() { if (propagationQuestion != null) { return propagationQuestion; From 76ce3d4e7138ebffc7ed79eca6d1ce7681b9ccf6 Mon Sep 17 00:00:00 2001 From: idelcano Date: Thu, 29 Mar 2018 19:44:38 +0200 Subject: [PATCH 6/6] remove treatment values when treatment not found or not exist --- .../malariacare/domain/entity/Treatment.java | 61 +++++++++++++------ 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/eyeseetea/malariacare/domain/entity/Treatment.java b/app/src/main/java/org/eyeseetea/malariacare/domain/entity/Treatment.java index 85b78a3b9e..aa605f3a0b 100644 --- a/app/src/main/java/org/eyeseetea/malariacare/domain/entity/Treatment.java +++ b/app/src/main/java/org/eyeseetea/malariacare/domain/entity/Treatment.java @@ -166,14 +166,18 @@ public boolean hasTreatment() { if (mTreatment != null) { putACTDefaultYes(); mQuestions = getQuestionsForTreatment(mTreatment); - saveTreatmentInTreatmentQuestion(mTreatment); + String diagnosisMessage = Utils.getInternationalizedString( + String.valueOf(mTreatment.getDiagnosis())); + String defaultDiagnosisMessage = Translation.getLocalizedString(mTreatment.getDiagnosis(), + Translation.DEFAULT_LANGUAGE); + saveTreatmentInTreatmentQuestion(diagnosisMessage, defaultDiagnosisMessage); } return mTreatment != null; } - private void putACTDefaultYes() { + private static void putACTDefaultYes() { Question actHiddenQuestion = Question.findByUID( - getContext().getString(R.string.dynamicTreatmentHideQuestionUID)); + PreferencesState.getInstance().getContext().getString(R.string.dynamicTreatmentHideQuestionUID)); List values = Session.getMalariaSurvey().getValuesFromDB(); Value actValue = null; for (Value value : values) { @@ -183,11 +187,11 @@ private void putACTDefaultYes() { } if (actValue == null) { actValue = new Value( - Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code)), + Option.findByCode(PreferencesState.getInstance().getContext().getString(R.string.dynamic_treatment_yes_code)), actHiddenQuestion, Session.getMalariaSurvey()); } else { actValue.setOption( - Option.findByCode(getContext().getString(R.string.dynamic_treatment_yes_code))); + Option.findByCode(PreferencesState.getInstance().getContext().getString(R.string.dynamic_treatment_yes_code))); } actValue.save(); } @@ -394,22 +398,17 @@ private String getCqTitleDose(float dose) { getContext().getResources().getString(R.string.drugs_referral_Cq_review_title)); } - private void saveTreatmentInTreatmentQuestion( - org.eyeseetea.malariacare.data.database.model.Treatment treatment) { - Question treatmentQuestionSend = Question.findByUID( - getContext().getResources().getString(R.string.dynamicTreatmentQuestionUID)); - Question treatmentQuestionShow = Question.findByUID( - getContext().getResources().getString(R.string.treatmentDiagnosisVisibleQuestion)); + private static void saveTreatmentInTreatmentQuestion(String diangosisMessage, String defaultDiagnosisMessage) { + Question treatmentQuestionSend = Question.findByUID(PreferencesState.getInstance().getContext() + .getResources().getString(R.string.dynamicTreatmentQuestionUID)); + Question treatmentQuestionShow = Question.findByUID(PreferencesState.getInstance().getContext() + .getResources().getString(R.string.treatmentDiagnosisVisibleQuestion)); Survey malariaSurvey = Session.getMalariaSurvey(); List values = malariaSurvey.getValues();//this values should be get from memory because the // treatment options are in memory boolean questionInSurvey = false; boolean questionShowInSurvey = false; - String diagnosisMessage = Utils.getInternationalizedString( - String.valueOf(treatment.getDiagnosis())); - String defaultDiagnosisMessage = Translation.getLocalizedString(treatment.getDiagnosis(), - Translation.DEFAULT_LANGUAGE); for (Value value : values) { if (value.getQuestion() == null) { continue; @@ -420,13 +419,13 @@ private void saveTreatmentInTreatmentQuestion( value.save(); } if (value.getQuestion().equals(treatmentQuestionShow)) { - value.setValue(diagnosisMessage); + value.setValue(diangosisMessage); questionShowInSurvey = true; value.save(); } } if (!questionShowInSurvey) { - Value value = new Value(diagnosisMessage, treatmentQuestionShow, + Value value = new Value(diangosisMessage, treatmentQuestionShow, malariaSurvey); value.insert(); } @@ -453,8 +452,34 @@ public List getNoTreatmentQuestions() { getContext().getResources().getResourceName(R.string.error_no_treatment)); treatmentQuestion.setCompulsory(Question.QUESTION_NOT_COMPULSORY); treatmentQuestion.setHeader(Header.DYNAMIC_TREATMENT_HEADER_ID); + treatmentQuestion.setTotalQuestions(7); questions.add(treatmentQuestion); - + cleanNotTreatmentFound(); return questions; } + public void cleanNotTreatmentFound(){ + putACTDefaultYes(); + + String diagnosisMessage = Utils.getInternationalizedString( + String.valueOf(getContext().getResources().getResourceName(R.string.error_no_treatment))); + String defaultDiagnosisMessage = Utils.getInternationalizedString( + String.valueOf(getContext().getResources().getResourceName(R.string.error_no_treatment))); + saveTreatmentInTreatmentQuestion(diagnosisMessage, defaultDiagnosisMessage); + } + public static void cleanNotTreatmentQuestion(){ + putACTDefaultYes(); + saveTreatmentInTreatmentQuestion("", ""); + String actHiddenQuestion = + PreferencesState.getInstance().getContext().getString(R.string.dynamicTreatmentHideQuestionUID); + String referallHiddenQuestion = + PreferencesState.getInstance().getContext().getString(R.string.referralQuestionUID); + + List values = Session.getMalariaSurvey().getValuesFromDB(); + for (Value value : values) { + if (value.getQuestion().getUid().equals(actHiddenQuestion) + || value.getQuestion().getUid().equals(referallHiddenQuestion)) { + value.delete(); + } + } + } }