Search in sources :

Example 1 with DataSetValueList

use of org.hisp.dhis.api.mobile.model.DataSetValueList 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;
}
Also used : DataSet(org.hisp.dhis.api.mobile.model.DataSet) DataValue(org.hisp.dhis.api.mobile.model.DataValue) DataSetValue(org.hisp.dhis.api.mobile.model.DataSetValue) Period(org.hisp.dhis.period.Period) DataElement(org.hisp.dhis.api.mobile.model.DataElement) DataExportParams(org.hisp.dhis.datavalue.DataExportParams) DataSetValueList(org.hisp.dhis.api.mobile.model.DataSetValueList)

Aggregations

DataElement (org.hisp.dhis.api.mobile.model.DataElement)1 DataSet (org.hisp.dhis.api.mobile.model.DataSet)1 DataSetValue (org.hisp.dhis.api.mobile.model.DataSetValue)1 DataSetValueList (org.hisp.dhis.api.mobile.model.DataSetValueList)1 DataValue (org.hisp.dhis.api.mobile.model.DataValue)1 DataExportParams (org.hisp.dhis.datavalue.DataExportParams)1 Period (org.hisp.dhis.period.Period)1