Search in sources :

Example 1 with DataValueExtended

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();
}
Also used : DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Example 2 with DataValueExtended

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);
}
Also used : Question(org.eyeseetea.malariacare.data.database.model.Question) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Example 3 with DataValueExtended

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);
}
Also used : QuestionNotFoundException(org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException) Question(org.eyeseetea.malariacare.data.database.model.Question) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Example 4 with DataValueExtended

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);
}
Also used : OrgUnit(org.eyeseetea.malariacare.data.database.model.OrgUnit) Program(org.eyeseetea.malariacare.data.database.model.Program) EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) QuestionNotFoundException(org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException) DataValueExtended(org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)

Aggregations

DataValueExtended (org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)4 Question (org.eyeseetea.malariacare.data.database.model.Question)2 QuestionNotFoundException (org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException)2 OrgUnit (org.eyeseetea.malariacare.data.database.model.OrgUnit)1 Program (org.eyeseetea.malariacare.data.database.model.Program)1 EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)1