app/src/main/java/org/hisp/dhis/android/app/views/dashboard/navigation/event/TeiProgramStagePresenterImpl.java
/**
     * Returns a list of ReportEntities that corresponds to Event's in that program stage.
     *
     * @param programStage
     * @param events
     * @return
     */
Returns a list of ReportEntities that corresponds to Event's in that program stage.
@param programStage
@param events
@return
Returns a list of ReportEntities that corresponds to Event ' s in that program stage . @param programStage @param events @return
private List<ReportEntity> eventsToReportEntityList(ProgramStage programStage, List<Event> events) {
        List<ReportEntity> reportEntities = new ArrayList<>();
        if (events == null || events.isEmpty()) { 
            return reportEntities;
        }
        Collections.sort(events, Event.DESCENDING_EVENT_DATE_COMPARATOR); 
        for (Event event : events) {
            if (programStage.uid().equals(event.programStage())) { 
                ReportEntity.Status syncStatus;
                State state = event.state();
                switch (state) {
                    case SYNCED: {
                        syncStatus = ReportEntity.Status.SENT;
                        break;
                    }
                    case TO_POST: {
                        syncStatus = ReportEntity.Status.TO_POST;
                        break;
                    }
                    case TO_UPDATE: {
                        syncStatus = ReportEntity.Status.TO_UPDATE;
                        break;
                    }
                    case ERROR: {
                        syncStatus = ReportEntity.Status.ERROR;
                        break;
                    }
                    case TO_DELETE: {
                        continue; 
                    }
                    default: {
                        throw new IllegalArgumentException(
                                "Unsupported event state: " + state);
                    }
                }
                EventStatus eventStatus = event.status();
                Date dateToShow;
                switch (eventStatus) {
                    case ACTIVE:
                        dateToShow = event.eventDate();
                        break;
                    case COMPLETED:
                        dateToShow = event.eventDate();
                        break;
                    case SCHEDULE:
                        dateToShow = event.dueDate();
                        break;
                    case SKIPPED:
                        dateToShow = event.eventDate();
                        break;
                    default:
                        throw new IllegalArgumentException("Unknown event status");
                }
                Map<String, String> dataElementToValueMap = new HashMap<>();
                SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT, LocaleUtils.getLocale());
                OrganisationUnit organisationUnit = organisationUnitInteractor.store().queryByUid(event.organisationUnit());
                String organisationUnitName;
                if(organisationUnit != null) {
                    organisationUnitName = organisationUnit.displayName();
                } else {
                    organisationUnitName = "";
                }
                dataElementToValueMap.put(ReportEntityFilter.DATE_KEY, sdf.format(dateToShow));
                dataElementToValueMap.put(ReportEntityFilter.STATUS_KEY, event.status().toString());
                dataElementToValueMap.put(ReportEntityChildViewHolder.SUB_LABEL, organisationUnitName);
                dataElementToValueMap.put(ReportEntityChildViewHolder.TEXT_LABEL, sdf.format(dateToShow));
                reportEntities.add(new ReportEntity(event.uid(), syncStatus, dataElementToValueMap));
            }
        }
        return reportEntities;
    }
private List < ReportEntity > eventsToReportEntityList ( ProgramStage programStage , List < Event > events ) { List < ReportEntity > reportEntities = new ArrayList < > ( ) ; if ( events == null || events . isEmpty ( ) ) { return reportEntities ; } Collections . sort ( events , Event . DESCENDING_EVENT_DATE_COMPARATOR ) ; for ( Event event : events ) { if ( programStage . uid ( ) . equals ( event . programStage ( ) ) ) { ReportEntity . Status syncStatus ; State state = event . state ( ) ; switch ( state ) { case SYNCED : { syncStatus = ReportEntity . Status . SENT ; break ; } case TO_POST : { syncStatus = ReportEntity . Status . TO_POST ; break ; } case TO_UPDATE : { syncStatus = ReportEntity . Status . TO_UPDATE ; break ; } case ERROR : { syncStatus = ReportEntity . Status . ERROR ; break ; } case TO_DELETE : { continue ; } default : { throw new IllegalArgumentException ( "Unsupported event state: " + state ) ; } } EventStatus eventStatus = event . status ( ) ; Date dateToShow ; switch ( eventStatus ) { case ACTIVE : dateToShow = event . eventDate ( ) ; break ; case COMPLETED : dateToShow = event . eventDate ( ) ; break ; case SCHEDULE : dateToShow = event . dueDate ( ) ; break ; case SKIPPED : dateToShow = event . eventDate ( ) ; break ; default : throw new IllegalArgumentException ( "Unknown event status" ) ; } Map < String , String > dataElementToValueMap = new HashMap < > ( ) ; SimpleDateFormat sdf = new SimpleDateFormat ( DATE_FORMAT , LocaleUtils . getLocale ( ) ) ; OrganisationUnit organisationUnit = organisationUnitInteractor . store ( ) . queryByUid ( event . organisationUnit ( ) ) ; String organisationUnitName ; if ( organisationUnit != null ) { organisationUnitName = organisationUnit . displayName ( ) ; } else { organisationUnitName = "" ; } dataElementToValueMap . put ( ReportEntityFilter . DATE_KEY , sdf . format ( dateToShow ) ) ; dataElementToValueMap . put ( ReportEntityFilter . STATUS_KEY , event . status ( ) . toString ( ) ) ; dataElementToValueMap . put ( ReportEntityChildViewHolder . SUB_LABEL , organisationUnitName ) ; dataElementToValueMap . put ( ReportEntityChildViewHolder . TEXT_LABEL , sdf . format ( dateToShow ) ) ; reportEntities . add ( new ReportEntity ( event . uid ( ) , syncStatus , dataElementToValueMap ) ) ; } } return reportEntities ; }
Returns a list of ReportEntities that corresponds to Event's in that program stage.
Returns a list of ReportEntities that corresponds to Event ' s in that program stage .
// preventing additional work // sort events by eventDate // retrieve state map for given events // it is done synchronously //TODO: use the new sdk when out, get states from the sdk : //Map<Long, State> stateMap = eventInteractor.map(events).toBlocking().first(); //if event in prog stage: // syncStatus of event // get state of event // If event is to delete, skip this event.