Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature fix not treatment workflown when go back from alternative treatment #2002

Open
wants to merge 7 commits into
base: v1.0_mm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -1825,6 +1829,10 @@ public String toString() {
'}';
}

public static List<Question> getQuestionsWithoutHeader(){
return new Select().from(Question.class).where(Question_Table.id_header_fk.isNull()).queryList();
}

public List<Question> getPropagationQuestions() {
if (propagationQuestion != null) {
return propagationQuestion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value> values = Session.getMalariaSurvey().getValuesFromDB();
Value actValue = null;
for (Value value : values) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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<Value> 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;
Expand All @@ -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();
}
Expand All @@ -453,8 +452,34 @@ public List<Question> 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<Value> values = Session.getMalariaSurvey().getValuesFromDB();
for (Value value : values) {
if (value.getQuestion().getUid().equals(actHiddenQuestion)
|| value.getQuestion().getUid().equals(referallHiddenQuestion)) {
value.delete();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void updateRDTStockQuestion(Survey survey) {
propagateQuestion.insertValue(rdtStockValue.getValue(),
Session.getMalariaSurvey()).save();
}
Session.getStockSurvey().complete();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/myanmar/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="dynamicTreatmentQuestionUID" translatable="false">yPACdIBZEeZ</string>
<string name="stockRDTQuestionUID" translatable="false">FGG1GvvS8Xg</string>
<string name="confirmInvalidQuestionUID" translatable="false">lhJLBNebHcz</string>
<string name="negativeQuestionUID" translatable="false">NoDataElementNegative</string>
<string name="residenceVillageUID" translatable="false">NoDataElementOrgUnit</string>
<string name="patientResidenceVillageOtherCode" translatable="false">Dropdown parent</string>
<string name="myanmar_locale" translatable="false">my</string>
Expand Down