use of org.hisp.dhis.api.mobile.model.DataSetValue in project dhis2-core by dhis2.
the class FacilityReportingServiceImpl method getDataSetValues.
@Override
public DataSetValueList getDataSetValues(OrganisationUnit unit, DataSetList dataSetList) throws NotAllowedException {
DataSetValueList dataSetValueList = new DataSetValueList();
List<DataSet> dataSets = dataSetList.getCurrentDataSets();
for (DataSet dataSet : dataSets) {
log.info("Getting DataSetValue for: " + dataSet.getName());
org.hisp.dhis.dataset.DataSet apiDataSet = dataSetService.getDataSet(dataSet.getId());
Vector<String> periods = PeriodUtil.generatePeriods(dataSet.getPeriodType());
if (periods != null) {
for (int i = 0; i < periods.size(); i++) {
Period period = getPeriod(periods.elementAt(i), apiDataSet.getPeriodType());
if (period != null) {
Set<org.hisp.dhis.dataelement.DataElement> dataElements = apiDataSet.getDataElements();
Collection<org.hisp.dhis.datavalue.DataValue> dataValues = dataValueService.getDataValues(new DataExportParams().setDataElements(dataElements).setPeriods(Sets.newHashSet(period)).setOrganisationUnits(Sets.newHashSet(unit)));
if (dataValues != null && !dataValues.isEmpty()) {
DataSetValue dataSetValue = new DataSetValue();
dataSetValue.setId(dataSet.getId());
dataSetValue.setName(dataSet.getName());
dataSetValue.setPeriodName(periods.elementAt(i));
dataSetValue.setCompleted(true);
for (org.hisp.dhis.datavalue.DataValue dataValue : dataValues) {
DataValue dv = new DataValue();
dv.setCategoryOptComboID(dataValue.getCategoryOptionCombo().getId());
dv.setClientVersion(dataSet.getClientVersion());
dv.setId(dataValue.getDataElement().getId());
dv.setValue(dataValue.getValue());
dataSetValue.getDataValues().add(dv);
}
dataSetValueList.getDataSetValues().add(dataSetValue);
}
}
}
}
}
log.info("Retrieved Data value set: " + unit.getName() + ", " + dataSetList.getName());
return dataSetValueList;
}
Aggregations