use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class ConvertFromSDKVisitor method visit.
@Override
public void visit(DataValueExtended sdkDataValueExtended) {
Survey survey = (Survey) appMapObjects.get(sdkDataValueExtended.getEvent());
String questionUID = sdkDataValueExtended.getDataElement();
//Data value is a value from compositeScore -> ignore
if (appMapObjects.get(questionUID) instanceof CompositeScore) {
return;
}
//Phone metadata -> ignore
if (PreferencesState.getInstance().getContext().getString(R.string.control_data_element_phone_metadata).equals(questionUID)) {
return;
}
//Datavalue is a value from a question
Question question = Question.findByUID(questionUID);
if (question == null) {
Log.e(TAG, "Question not found with dataelement uid " + questionUID);
}
Value value = new Value();
value.setQuestion(question);
value.setSurvey(survey);
Option option = sdkDataValueExtended.findOptionByQuestion(question);
value.setOption(option);
//No option -> text question (straight value)
if (option == null) {
value.setValue(sdkDataValueExtended.getValue());
} else {
//Option -> extract value from code
value.setValue(sdkDataValueExtended.getDataValue().getValue());
}
values.add(value);
}
use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class ConvertFromSDKVisitor method visit.
/**
* Turns an event into a sent survey
*/
@Override
public void visit(EventExtended sdkEventExtended) {
OrgUnit orgUnit = (OrgUnit) appMapObjects.get(sdkEventExtended.getOrganisationUnitId());
Program program = Program.getProgram(sdkEventExtended.getProgramUId());
Survey survey = new Survey();
//Any survey that comes from the pull has been sent
survey.setStatus(Constants.SURVEY_SENT);
//Set dates
survey.setCreationDate(sdkEventExtended.getCreationDate());
survey.setCompletionDate(sdkEventExtended.getEventDate());
survey.setEventDate(sdkEventExtended.getEventDate());
survey.setScheduledDate(sdkEventExtended.getScheduledDate());
//Set fks
survey.setOrgUnit(orgUnit);
survey.setProgram(program);
survey.setEventUid(sdkEventExtended.getUid());
mConvertFromSDKVisitorStrategy.visit(sdkEventExtended, survey);
surveys.add(survey);
//Annotate object in map
appMapObjects.put(sdkEventExtended.getUid(), survey);
}
use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class SurveyFragment method areActiveSurveysInQuarantine.
private boolean areActiveSurveysInQuarantine() {
Survey survey = Session.getMalariaSurvey();
if (survey != null && survey.isQuarantine()) {
return true;
}
survey = Session.getStockSurvey();
if (survey != null && survey.isQuarantine()) {
return true;
}
return false;
}
use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class ConvertToSDKVisitor method setSurveysAsQuarantine.
public void setSurveysAsQuarantine() {
for (Survey survey : surveys) {
Log.d(TAG, "Set Survey status as QUARANTINE" + survey.getId_survey());
Log.d(TAG, "Set Survey status as QUARANTINE" + survey.toString());
survey.setStatus(Constants.SURVEY_QUARANTINE);
survey.save();
}
}
use of org.eyeseetea.malariacare.data.database.model.Survey in project pictureapp by EyeSeeTea.
the class Treatment method saveTreatmentInTreatmentQuestion.
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));
Survey malariaSurvey = Session.getMalariaSurvey();
List<Value> values = //this values should be get from memory because the
malariaSurvey.getValues();
// 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;
}
if (value.getQuestion().equals(treatmentQuestionSend)) {
value.setValue(defaultDiagnosisMessage);
questionInSurvey = true;
value.save();
}
if (value.getQuestion().equals(treatmentQuestionShow)) {
value.setValue(diagnosisMessage);
questionShowInSurvey = true;
value.save();
}
}
if (!questionShowInSurvey) {
Value value = new Value(diagnosisMessage, treatmentQuestionShow, malariaSurvey);
value.insert();
}
if (!questionInSurvey) {
Value value = new Value(defaultDiagnosisMessage, treatmentQuestionSend, malariaSurvey);
value.insert();
}
}
Aggregations