Search in sources :

Example 1 with DataSetCompletenessResult

use of org.hisp.dhis.completeness.DataSetCompletenessResult in project dhis2-core by dhis2.

the class AbstractDataSetCompletenessService method getDataSetCompleteness.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private DataSetCompletenessResult getDataSetCompleteness(Period period, Collection<Integer> periodsBetweenDates, OrganisationUnit unit, Collection<Integer> relevantSources, DataSet dataSet) {
    final DataSetCompletenessResult result = new DataSetCompletenessResult();
    result.setName(unit.getName());
    result.setSources(getSources(dataSet, relevantSources, period));
    if (result.getSources() > 0) {
        result.setRegistrations(getRegistrations(dataSet, relevantSources, periodsBetweenDates));
        result.setRegistrationsOnTime(getRegistrationsOnTime(dataSet, relevantSources, periodsBetweenDates));
        result.setDataSetId(dataSet.getId());
        result.setPeriodId(period.getId());
        result.setPeriodName(period.getName());
        result.setOrganisationUnitId(unit.getId());
    }
    return result;
}
Also used : DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult)

Example 2 with DataSetCompletenessResult

use of org.hisp.dhis.completeness.DataSetCompletenessResult in project dhis2-core by dhis2.

the class AbstractDataSetCompletenessService method getDataSetCompleteness.

@Override
@Transactional
public List<DataSetCompletenessResult> getDataSetCompleteness(int periodId, Collection<Integer> organisationUnitIds, int dataSetId, Set<Integer> groupIds) {
    final DataSet dataSet = dataSetService.getDataSet(dataSetId);
    final Period period = periodService.getPeriod(periodId);
    final List<Integer> periodsBetweenDates = getIdentifiers(periodService.getPeriodsBetweenDates(dataSet.getPeriodType(), period.getStartDate(), period.getEndDate()));
    final Map<Integer, OrganisationUnit> orgUnits = Maps.uniqueIndex(organisationUnitService.getOrganisationUnits(organisationUnitIds), OrganisationUnit::getId);
    final Set<OrganisationUnitGroup> groups = groupIds != null ? Sets.newHashSet(idObjectManager.getObjects(OrganisationUnitGroup.class, groupIds)) : null;
    final List<DataSetCompletenessResult> results = new ArrayList<>();
    for (final Integer unitId : organisationUnitIds) {
        final OrganisationUnit unit = orgUnits.get(unitId);
        final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(unit.getId());
        final Set<Integer> relevantSources = getRelevantSources(dataSet, children, groups);
        final DataSetCompletenessResult result = getDataSetCompleteness(period, periodsBetweenDates, unit, relevantSources, dataSet);
        if (result.getSources() > 0) {
            results.add(result);
        }
    }
    return results;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DataSetCompletenessResult

use of org.hisp.dhis.completeness.DataSetCompletenessResult in project dhis2-core by dhis2.

the class GetDataCompletenessAction method getGrid.

private Grid getGrid(List<DataSetCompletenessResult> mainResults, List<DataSetCompletenessResult> footerResults, OrganisationUnit unit, DataSet dataSet, Period period) {
    String title = (unit != null ? unit.getName() : EMPTY) + (dataSet != null ? TITLE_SEP + dataSet.getName() : EMPTY) + (period != null ? TITLE_SEP + format.formatPeriod(period) : EMPTY);
    Grid grid = new ListGrid().setTitle(title);
    grid.addHeader(new GridHeader(i18n.getString("name"), false, true));
    grid.addHeader(new GridHeader(i18n.getString("actual_reports"), false, false));
    grid.addHeader(new GridHeader(i18n.getString("expected_reports"), false, false));
    grid.addHeader(new GridHeader(i18n.getString("percent"), false, false));
    grid.addHeader(new GridHeader(i18n.getString("reports_on_time"), false, false));
    grid.addHeader(new GridHeader(i18n.getString("percent_on_time"), false, false));
    for (DataSetCompletenessResult result : mainResults) {
        addRow(grid, result);
    }
    if (grid.getWidth() >= 4) {
        grid.sortGrid(4, 1);
    }
    for (DataSetCompletenessResult result : footerResults) {
        addRow(grid, result);
    }
    return grid;
}
Also used : DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ListGrid(org.hisp.dhis.system.grid.ListGrid) GridHeader(org.hisp.dhis.common.GridHeader)

Example 4 with DataSetCompletenessResult

use of org.hisp.dhis.completeness.DataSetCompletenessResult in project dhis2-core by dhis2.

the class GetDataCompletenessAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    Grid _grid = (Grid) SessionUtils.getSessionVar(KEY_DATA_COMPLETENESS);
    if (_grid != null && type != null && !type.equals(DEFAULT_TYPE)) {
        grid = _grid;
        return type;
    } else {
        OrganisationUnit selectedUnit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
        if (periodId == null || selectedUnit == null || criteria == null) {
            return INPUT;
        } else {
            Period period = periodService.reloadPeriod(PeriodType.getPeriodFromIsoString(periodId));
            Integer _periodId = period.getId();
            DataSet dataSet = null;
            List<DataSetCompletenessResult> mainResults = new ArrayList<>();
            List<DataSetCompletenessResult> footerResults = new ArrayList<>();
            DataSetCompletenessService completenessService = serviceProvider.provide(criteria);
            if (// One ds for one ou
            dataSetId != null && dataSetId != 0) {
                mainResults = new ArrayList<>(completenessService.getDataSetCompleteness(_periodId, getIdentifiers(selectedUnit.getChildren()), dataSetId, groupId));
                footerResults = new ArrayList<>(completenessService.getDataSetCompleteness(_periodId, Arrays.asList(selectedUnit.getId()), dataSetId, groupId));
                dataSet = dataSetService.getDataSet(dataSetId);
            } else // All ds for children of one ou               
            {
                mainResults = new ArrayList<>(completenessService.getDataSetCompleteness(_periodId, selectedUnit.getId(), groupId));
            }
            grid = getGrid(mainResults, footerResults, selectedUnit, dataSet, period);
            SessionUtils.setSessionVar(KEY_DATA_COMPLETENESS, grid);
        }
        return type != null ? type : DEFAULT_TYPE;
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataSetCompletenessService(org.hisp.dhis.completeness.DataSetCompletenessService)

Example 5 with DataSetCompletenessResult

use of org.hisp.dhis.completeness.DataSetCompletenessResult in project dhis2-core by dhis2.

the class AbstractDataSetCompletenessService method getDataSetCompleteness.

// -------------------------------------------------------------------------
// DataSetCompleteness
// -------------------------------------------------------------------------
@Override
@Transactional
public List<DataSetCompletenessResult> getDataSetCompleteness(int periodId, int organisationUnitId, Set<Integer> groupIds) {
    final Period period = periodService.getPeriod(periodId);
    final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(organisationUnitId);
    final List<DataSet> dataSets = dataSetService.getAllDataSets();
    final Set<OrganisationUnitGroup> groups = groupIds != null ? Sets.newHashSet(idObjectManager.getObjects(OrganisationUnitGroup.class, groupIds)) : null;
    final List<DataSetCompletenessResult> results = new ArrayList<>();
    for (final DataSet dataSet : dataSets) {
        final List<Integer> periodsBetweenDates = getIdentifiers(periodService.getPeriodsBetweenDates(dataSet.getPeriodType(), period.getStartDate(), period.getEndDate()));
        final Set<Integer> relevantSources = getRelevantSources(dataSet, children, groups);
        final DataSetCompletenessResult result = new DataSetCompletenessResult();
        result.setSources(getSources(dataSet, relevantSources, period));
        if (result.getSources() > 0) {
            result.setName(dataSet.getName());
            result.setRegistrations(getRegistrations(dataSet, relevantSources, periodsBetweenDates));
            result.setRegistrationsOnTime(getRegistrationsOnTime(dataSet, relevantSources, periodsBetweenDates));
            result.setDataSetId(dataSet.getId());
            result.setPeriodId(periodId);
            result.setOrganisationUnitId(organisationUnitId);
            results.add(result);
        }
    }
    return results;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DataSetCompletenessResult(org.hisp.dhis.completeness.DataSetCompletenessResult) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DataSetCompletenessResult (org.hisp.dhis.completeness.DataSetCompletenessResult)5 ArrayList (java.util.ArrayList)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Period (org.hisp.dhis.period.Period)3 Grid (org.hisp.dhis.common.Grid)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 ListGrid (org.hisp.dhis.system.grid.ListGrid)2 Transactional (org.springframework.transaction.annotation.Transactional)2 GridHeader (org.hisp.dhis.common.GridHeader)1 DataSetCompletenessService (org.hisp.dhis.completeness.DataSetCompletenessService)1