Search in sources :

Example 1 with DataSet

use of org.hisp.dhis.api.mobile.model.DataSet in project dhis2-core by dhis2.

the class FacilityReportingServiceImpl method getDataSetForLocale.

@Override
public DataSet getDataSetForLocale(int dataSetId, Locale locale) {
    org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet(dataSetId);
    if (dataSet == null) {
        return null;
    }
    DataSet ds = new DataSet();
    ds.setId(dataSet.getId());
    String name = StringUtils.defaultIfEmpty(dataSet.getName(), dataSet.getShortName());
    ds.setName(name);
    ds.setVersion(1);
    Integer version = dataSet.getVersion();
    if (version != null) {
        ds.setVersion(version);
    }
    ds.setPeriodType(dataSet.getPeriodType().getName());
    List<Section> sectionList = new ArrayList<>();
    ds.setSections(sectionList);
    Set<org.hisp.dhis.dataset.Section> sections = dataSet.getSections();
    if (sections == null || sections.size() == 0) {
        List<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
        // Fake section to store data elements
        Section section = new Section();
        section.setId(0);
        section.setName("");
        section.setDataElements(getDataElements(locale, dataElements));
        sectionList.add(section);
    } else {
        for (org.hisp.dhis.dataset.Section sec : sections) {
            Section section = new Section();
            section.setId(sec.getId());
            section.setName(sec.getName());
            List<org.hisp.dhis.dataelement.DataElement> des = new ArrayList<>(sec.getDataElements());
            // Remove grey fields in order to not display them on mobile
            List<DataElement> dataElementList = getDataElements(locale, des);
            List<DataElement> dataElementListFinal = new ArrayList<>(dataElementList);
            int tempI = 0;
            for (int i = 0; i < dataElementList.size(); i++) {
                List<Model> categoryOptionCombos = dataElementList.get(i).getCategoryOptionCombos().getModels();
                List<Model> newCategoryOptionCombos = new ArrayList<>();
                for (int j = 0; j < categoryOptionCombos.size(); j++) {
                    if (!isGreyField(sec, dataElementList.get(i).getId(), categoryOptionCombos.get(j).getId())) {
                        newCategoryOptionCombos.add(categoryOptionCombos.get(j));
                    }
                }
                if (newCategoryOptionCombos.isEmpty()) {
                    dataElementListFinal.remove(i - tempI);
                    tempI++;
                } else {
                    dataElementListFinal.get(i - tempI).getCategoryOptionCombos().setModels(newCategoryOptionCombos);
                }
            }
            section.setDataElements(dataElementListFinal);
            sectionList.add(section);
        }
    }
    return ds;
}
Also used : DataSet(org.hisp.dhis.api.mobile.model.DataSet) ArrayList(java.util.ArrayList) Section(org.hisp.dhis.api.mobile.model.Section) DataElement(org.hisp.dhis.api.mobile.model.DataElement) Model(org.hisp.dhis.api.mobile.model.Model)

Example 2 with DataSet

use of org.hisp.dhis.api.mobile.model.DataSet in project dhis2-core by dhis2.

the class FacilityReportingServiceImpl method getMobileDataSetsForUnit.

// -------------------------------------------------------------------------
// Service methods
// -------------------------------------------------------------------------
@Override
public List<DataSet> getMobileDataSetsForUnit(OrganisationUnit unit, String localeString) {
    List<DataSet> datasets = new ArrayList<>();
    Locale locale = LocaleUtil.getLocale(localeString);
    if (DEBUG)
        log.debug("Getting data sets for unit " + unit.getName());
    for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile(unit)) {
        PeriodType periodType = dataSet.getPeriodType();
        if (periodType instanceof DailyPeriodType || periodType instanceof WeeklyPeriodType || periodType instanceof MonthlyPeriodType || periodType instanceof YearlyPeriodType || periodType instanceof QuarterlyPeriodType) {
            if (DEBUG)
                log.debug("Found data set " + dataSet.getName());
            datasets.add(getDataSetForLocale(dataSet.getId(), locale));
        } else {
            log.warn("Dataset '" + dataSet.getName() + "' set to be reported from mobile, but not of a supported period type: " + periodType.getName());
        }
    }
    return datasets;
}
Also used : Locale(java.util.Locale) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) DailyPeriodType(org.hisp.dhis.period.DailyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.api.mobile.model.DataSet) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) ArrayList(java.util.ArrayList) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType)

Example 3 with DataSet

use of org.hisp.dhis.api.mobile.model.DataSet 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)

Example 4 with DataSet

use of org.hisp.dhis.api.mobile.model.DataSet in project dhis2-core by dhis2.

the class FacilityReportingServiceImpl method getUpdatedDataSet.

@Override
public DataSetList getUpdatedDataSet(DataSetList dataSetList, OrganisationUnit unit, String locale) {
    if (DEBUG)
        log.debug("Checking updated datasets for org unit " + unit.getName());
    DataSetList updatedDataSetList = new DataSetList();
    List<DataSet> dataSets = this.getMobileDataSetsForUnit(unit, locale);
    List<DataSet> currentDataSets = dataSetList.getCurrentDataSets();
    // check added dataset
    for (DataSet dataSet : dataSets) {
        if (!currentDataSets.contains(dataSet)) {
            if (updatedDataSetList.getAddedDataSets() == null)
                updatedDataSetList.setAddedDataSets(new ArrayList<>());
            updatedDataSetList.getAddedDataSets().add(dataSet);
            currentDataSets.add(dataSet);
        }
    }
    // check deleted dataset
    for (DataSet dataSet : currentDataSets) {
        if (!dataSets.contains(dataSet)) {
            if (updatedDataSetList.getDeletedDataSets() == null)
                updatedDataSetList.setDeletedDataSets(new ArrayList<>());
            updatedDataSetList.getDeletedDataSets().add(new DataSet(dataSet));
        }
    }
    if (updatedDataSetList.getDeletedDataSets() != null) {
        for (DataSet dataSet : updatedDataSetList.getDeletedDataSets()) {
            currentDataSets.remove(dataSet);
        }
    }
    // check modified dataset
    Collections.sort(dataSets);
    Collections.sort(currentDataSets);
    for (int i = 0; i < dataSets.size(); i++) {
        if (dataSets.get(i).getVersion() != currentDataSets.get(i).getVersion()) {
            if (updatedDataSetList.getModifiedDataSets() == null)
                updatedDataSetList.setModifiedDataSets(new ArrayList<>());
            updatedDataSetList.getModifiedDataSets().add(dataSets.get(i));
        }
    }
    if (DEBUG)
        log.debug("Returning updated datasets for org unit " + unit.getName());
    return updatedDataSetList;
}
Also used : DataSet(org.hisp.dhis.api.mobile.model.DataSet) ArrayList(java.util.ArrayList) DataSetList(org.hisp.dhis.api.mobile.model.DataSetList)

Example 5 with DataSet

use of org.hisp.dhis.api.mobile.model.DataSet in project dhis2-core by dhis2.

the class FacilityReportingServiceImpl method getDataSetsForLocale.

@Override
public DataSetList getDataSetsForLocale(OrganisationUnit unit, String locale) {
    DataSetList dataSetList = new DataSetList();
    List<DataSet> dataSets = getMobileDataSetsForUnit(unit, locale);
    dataSetList.setModifiedDataSets(dataSets);
    return dataSetList;
}
Also used : DataSet(org.hisp.dhis.api.mobile.model.DataSet) DataSetList(org.hisp.dhis.api.mobile.model.DataSetList)

Aggregations

DataSet (org.hisp.dhis.api.mobile.model.DataSet)5 ArrayList (java.util.ArrayList)3 DataElement (org.hisp.dhis.api.mobile.model.DataElement)2 DataSetList (org.hisp.dhis.api.mobile.model.DataSetList)2 Locale (java.util.Locale)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 Model (org.hisp.dhis.api.mobile.model.Model)1 Section (org.hisp.dhis.api.mobile.model.Section)1 DataExportParams (org.hisp.dhis.datavalue.DataExportParams)1 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)1 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)1 Period (org.hisp.dhis.period.Period)1 PeriodType (org.hisp.dhis.period.PeriodType)1 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)1 WeeklyPeriodType (org.hisp.dhis.period.WeeklyPeriodType)1 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)1