Search in sources :

Example 6 with EventExtended

use of org.eyeseetea.malariacare.data.sync.importer.models.EventExtended in project pictureapp by EyeSeeTea.

the class ConvertToSDKVisitor method buildEvent.

/**
     * Builds an event from a survey
     */
private EventExtended buildEvent(Survey survey) throws Exception {
    EventExtended event = new EventExtended();
    event.getEvent().setAttributeCategoryOptions(getCategoryOptionUIDByCurrentUser());
    event.setProgramId(survey.getProgram().getUid());
    event.setOrganisationUnitId(survey.getOrgUnit().getUid());
    event.setStatus(EventExtended.STATUS_COMPLETED);
    event.setOrganisationUnitId(getSafeOrgUnitUID(survey));
    event.setProgramId(survey.getProgram().getUid());
    event.setProgramStageId(survey.getProgram().getStageUid());
    event = updateEventLocation(survey, event);
    event = updateEventDates(survey, event);
    Log.d(TAG, "Saving event " + event.toString());
    event.save();
    return event;
}
Also used : EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)

Example 7 with EventExtended

use of org.eyeseetea.malariacare.data.sync.importer.models.EventExtended in project pictureapp by EyeSeeTea.

the class SurveyChecker method getEvents.

public static List<EventExtended> getEvents(JsonNode jsonNode) {
    TypeReference<List<Event>> typeRef = new TypeReference<List<Event>>() {
    };
    List<Event> events;
    try {
        if (jsonNode.has("events")) {
            ObjectMapper objectMapper = new ObjectMapper().registerModule(new JodaModule());
            events = objectMapper.readValue(jsonNode.get("events").traverse(), typeRef);
        } else {
            events = new ArrayList<>();
        }
    } catch (IOException e) {
        events = new ArrayList<>();
        e.printStackTrace();
    }
    List<EventExtended> eventExtendedList = new ArrayList<>();
    for (Event event : events) {
        EventFlow eventFlow = EventFlow.MAPPER.mapToDatabaseEntity(event);
        EventExtended eventExtended = new EventExtended(eventFlow);
        if (event.getDataValues() != null && event.getDataValues().size() > 0) {
            List<TrackedEntityDataValueFlow> trackedEntityDataValueFlows = TrackedEntityDataValueFlow.MAPPER.mapToDatabaseEntities(event.getDataValues());
            eventExtended.setDataValuesInMemory(trackedEntityDataValueFlows);
        }
        eventExtendedList.add(eventExtended);
    }
    return eventExtendedList;
}
Also used : EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) EventFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) TrackedEntityDataValueFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.TrackedEntityDataValueFlow) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Event(org.hisp.dhis.client.sdk.models.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

EventExtended (org.eyeseetea.malariacare.data.sync.importer.models.EventExtended)7 OrgUnit (org.eyeseetea.malariacare.data.database.model.OrgUnit)2 Program (org.eyeseetea.malariacare.data.database.model.Program)2 Survey (org.eyeseetea.malariacare.data.database.model.Survey)2 ImportSummaryErrorException (org.eyeseetea.malariacare.domain.exception.ImportSummaryErrorException)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Value (org.eyeseetea.malariacare.data.database.model.Value)1 DataValueExtended (org.eyeseetea.malariacare.data.sync.importer.models.DataValueExtended)1 QuestionNotFoundException (org.eyeseetea.malariacare.domain.exception.QuestionNotFoundException)1 EventFlow (org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow)1 TrackedEntityDataValueFlow (org.hisp.dhis.client.sdk.android.api.persistence.flow.TrackedEntityDataValueFlow)1 Conflict (org.hisp.dhis.client.sdk.models.common.importsummary.Conflict)1 ImportSummary (org.hisp.dhis.client.sdk.models.common.importsummary.ImportSummary)1 Event (org.hisp.dhis.client.sdk.models.event.Event)1