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;
}
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;
}
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;
}
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;
}
}
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;
}
Aggregations