Search in sources :

Example 1 with Section

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

Aggregations

ArrayList (java.util.ArrayList)1 DataElement (org.hisp.dhis.api.mobile.model.DataElement)1 DataSet (org.hisp.dhis.api.mobile.model.DataSet)1 Model (org.hisp.dhis.api.mobile.model.Model)1 Section (org.hisp.dhis.api.mobile.model.Section)1