use of org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended in project pictureapp by EyeSeeTea.
the class ConvertToSDKVisitor method buildAndSaveDataValue.
/**
* Adds value in Datavalue
*
* @param UID is the dataElement uid
* @param value is the value
*/
private void buildAndSaveDataValue(String UID, String value, EventExtended event) {
DataValueExtended dataValue = new DataValueExtended();
dataValue.setDataElement(UID);
dataValue.setEvent(event.getEvent());
dataValue.setProvidedElsewhere(false);
if (Session.getUser() != null) {
dataValue.setStoredBy(Session.getUser().getName());
}
dataValue.setValue(value);
dataValue.save();
}
use of org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended in project pictureapp by EyeSeeTea.
the class DataConverterStrategy method convertPatientSexPregnancyDataValue.
private void convertPatientSexPregnancyDataValue(ConvertFromSDKVisitor converter, EventExtended event) throws QuestionNotFoundException {
if (event.getProgramUId().equals(mContext.getString(R.string.stockProgramUID))) {
return;
}
Question sexPregnancyQuestion = Question.findByUID(SEX_PREGNANCY_QUESTION_UID);
if (sexPregnancyQuestion == null) {
Log.d(TAG, event.getUid() + "With invalid sexPregnancy question");
return;
}
List<DataValueExtended> dataValues = DataValueExtended.getExtendedList(SdkQueries.getDataValues(event.getUid()));
DataValueExtended sexDataValue = getDataValue(dataValues, SEX_QUESTION_UID);
DataValueExtended pregnancyDataValue = getDataValue(dataValues, PREGNANT_QUESTION_UID);
if (sexDataValue == null || pregnancyDataValue == null) {
Log.d(TAG, event.getUid() + "With invalid sexPregnancy question");
return;
}
DataValueExtended OrgUnitDataValue = new DataValueExtended();
OrgUnitDataValue.setEvent(event.getEvent());
OrgUnitDataValue.setDataElement(sexPregnancyQuestion.getUid());
if (sexDataValue.getValue().equals("F")) {
if (pregnancyDataValue.getValue().equals("true")) {
OrgUnitDataValue.setValue(SEX_PREGNANCY_PREGNANT_VALUE);
} else {
OrgUnitDataValue.setValue(SEX_PREGNANCY_FEMALE_VALUE);
}
} else {
OrgUnitDataValue.setValue(SEX_PREGNANCY_MALE_VALUE);
}
OrgUnitDataValue.accept(converter);
}
use of org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended in project pictureapp by EyeSeeTea.
the class DataConverterStrategy method convertOrgUnitDataValue.
private void convertOrgUnitDataValue(ConvertFromSDKVisitor converter, EventExtended event) throws QuestionNotFoundException {
if (event.getProgramUId().equals(mContext.getString(R.string.stockProgramUID))) {
return;
}
Question orgUnitQuestion = Question.findByUID(ORG_UNIT_QUESTION_UID);
if (orgUnitQuestion == null) {
throw new QuestionNotFoundException(String.format("Question with uid %s not found", ORG_UNIT_QUESTION_UID));
}
DataValueExtended OrgUnitDataValue = new DataValueExtended();
OrgUnitDataValue.setEvent(event.getEvent());
OrgUnitDataValue.setDataElement(orgUnitQuestion.getUid());
OrgUnitDataValue.setValue(event.getOrganisationUnitId());
OrgUnitDataValue.accept(converter);
}
use of org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended in project pictureapp by EyeSeeTea.
the class DataConverter method convert.
public void convert(IPullController.Callback callback, ConvertFromSDKVisitor converter) {
String orgUnitName = PreferencesState.getInstance().getOrgUnit();
List<OrgUnit> orgUnits = converter.getOrgUnits();
for (OrgUnit orgUnit : orgUnits) {
//Only events for the right ORGUNIT are loaded
if (!orgUnitName.isEmpty() && orgUnit.getName() != null && !orgUnit.getName().equals(orgUnitName)) {
continue;
}
List<Program> programs = Program.getAllPrograms();
for (Program program : programs) {
List<EventExtended> events = EventExtended.getExtendedList(SdkQueries.getEvents(orgUnit.getUid(), program.getUid()));
callback.onStep(BUILDING_SURVEYS);
for (EventExtended event : events) {
event.accept(converter);
}
callback.onStep(BUILDING_VALUES);
for (EventExtended event : events) {
List<DataValueExtended> dataValues = DataValueExtended.getExtendedList(SdkQueries.getDataValues(event.getUid()));
for (DataValueExtended dataValueExtended : dataValues) {
dataValueExtended.accept(converter);
}
try {
dataConverterStrategy.convert(converter, event);
} catch (QuestionNotFoundException e) {
callback.onError(e);
}
}
}
}
saveConvertedSurveys(callback, converter);
}
Aggregations