Search in sources :

Example 6 with DataElementCategoryCombo

use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.

the class CategoryOptionComboNameResourceTable method getPopulateTempTableContent.

@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<Object[]> batchArgs = new ArrayList<>();
    for (DataElementCategoryCombo combo : objects) {
        if (!combo.isValid()) {
            log.warn("Ignoring category combo, not valid: " + combo);
            continue;
        }
        for (DataElementCategoryOptionCombo coc : combo.getOptionCombos()) {
            List<Object> values = new ArrayList<>();
            values.add(coc.getId());
            values.add(coc.getName());
            values.add(coc.isIgnoreApproval() ? APPROVAL_LEVEL_HIGHEST : null);
            values.add(coc.getLatestStartDate());
            values.add(coc.getEarliestEndDate());
            batchArgs.add(values.toArray());
        }
    }
    return Optional.of(batchArgs);
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 7 with DataElementCategoryCombo

use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.

the class AbstractWebApiTest method createTestObject.

@SuppressWarnings("unchecked")
protected T createTestObject(Class<?> clazz, char uniqueName, Object... params) {
    if (DataElementGroup.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroup(uniqueName);
    } else if (DataElementCategoryCombo.class.isAssignableFrom(clazz)) {
        return (T) createCategoryCombo(uniqueName, Arrays.copyOf(params, params.length, DataElementCategory[].class));
    } else if (DataElementCategoryOption.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOption(uniqueName);
    } else if (DataElement.class.isAssignableFrom(clazz)) {
        return (T) createDataElement(uniqueName);
    } else if (DataElementCategory.class.isAssignableFrom(clazz)) {
        return (T) createDataElementCategory(uniqueName, Arrays.copyOf(params, params.length, DataElementCategoryOption[].class));
    } else if (Program.class.isAssignableFrom(clazz)) {
        OrganisationUnit organisationUnitA = createOrganisationUnit(uniqueName);
        manager.save(organisationUnitA);
        return (T) createProgram(uniqueName, new HashSet<>(), organisationUnitA);
    } else if (DataElementOperand.class.isAssignableFrom(clazz)) {
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        DataElementCategoryOptionCombo coc = createCategoryOptionCombo(cc, co);
        manager.save(coc);
        return (T) new DataElementOperand(deA, coc);
    } else if (DataElementGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createDataElementGroupSet(uniqueName);
    } else if (DataElementCategoryOptionCombo.class.isAssignableFrom(clazz)) {
        DataElementCategoryCombo cc = createCategoryCombo(uniqueName);
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(cc);
        manager.save(co);
        return (T) createCategoryOptionCombo(cc, co);
    } else if (CategoryOptionGroup.class.isAssignableFrom(clazz)) {
        DataElementCategoryOption co = createCategoryOption(uniqueName);
        manager.save(co);
        return (T) createCategoryOptionGroup(uniqueName, co);
    } else if (CategoryOptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createCategoryOptionGroupSet(uniqueName);
    } else if (EventChart.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventChart ecA = new EventChart("evc" + uniqueName);
        ecA.setProgram(prA);
        ecA.setType(ChartType.COLUMN);
        return (T) ecA;
    } else if (EventReport.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        EventReport erA = new EventReport("er" + uniqueName);
        erA.setProgram(prA);
        return (T) erA;
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        Program prA = createProgram(uniqueName);
        manager.save(prA);
        DataElement deA = createDataElement(uniqueName);
        manager.save(deA);
        return (T) new ProgramDataElementDimensionItem(prA, deA);
    } else if (ProgramIndicator.class.isAssignableFrom(clazz)) {
        Program program = (Program) createTestObject(Program.class, uniqueName);
        manager.save(program);
        Constant constantA = createConstant(uniqueName, 7.0);
        manager.save(constantA);
        String expressionA = "( " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "} - " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "} )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
        return (T) createProgramIndicator(uniqueName, program, expressionA, null);
    } else if (Indicator.class.isAssignableFrom(clazz)) {
        IndicatorType indicatorType = createIndicatorType(uniqueName);
        manager.save(indicatorType);
        return (T) createIndicator(uniqueName, indicatorType);
    } else if (IndicatorGroup.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroup(uniqueName);
    } else if (IndicatorGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorGroupSet(uniqueName);
    } else if (IndicatorType.class.isAssignableFrom(clazz)) {
        return (T) createIndicatorType(uniqueName);
    } else if (Legend.class.isAssignableFrom(clazz)) {
        return (T) createLegend(uniqueName, 0d, 10d);
    } else if (LegendSet.class.isAssignableFrom(clazz)) {
        return (T) createLegendSet(uniqueName);
    } else if (OrganisationUnit.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnit(uniqueName);
    } else if (OrganisationUnitGroup.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroup(uniqueName);
    } else if (OrganisationUnitGroupSet.class.isAssignableFrom(clazz)) {
        return (T) createOrganisationUnitGroupSet(uniqueName);
    } else if (OrganisationUnitLevel.class.isAssignableFrom(clazz)) {
        return (T) new OrganisationUnitLevel(uniqueName, "OrgLevel" + uniqueName);
    } else if (Color.class.isAssignableFrom(clazz)) {
        Color color = new Color("#ff3200");
        color.setName("Color" + uniqueName);
        return (T) color;
    } else if (ColorSet.class.isAssignableFrom(clazz)) {
        ColorSet colorSet = new ColorSet();
        colorSet.setName("ColorSet" + uniqueName);
        return (T) colorSet;
    } else if (org.hisp.dhis.mapping.Map.class.isAssignableFrom(clazz)) {
        org.hisp.dhis.mapping.Map map = new org.hisp.dhis.mapping.Map();
        map.setName("Map" + uniqueName);
        map.setDisplayName("DisplayName" + uniqueName);
        map.setLatitude(952175.62553525);
        map.setLongitude(-1378543.6774686);
        return (T) map;
    } else if (ExternalMapLayer.class.isAssignableFrom(clazz)) {
        ExternalMapLayer externalMapLayer = new ExternalMapLayer("ExternalMapLayer" + uniqueName);
        externalMapLayer.setMapService(MapService.WMS);
        externalMapLayer.setUrl("testUrl");
        externalMapLayer.setImageFormat(ImageFormat.JPG);
        externalMapLayer.setMapLayerPosition(MapLayerPosition.BASEMAP);
        return (T) externalMapLayer;
    } else if (OptionGroup.class.isAssignableFrom(clazz)) {
        OptionGroup optionGroup = new OptionGroup("OptionGroup" + uniqueName);
        optionGroup.setShortName("Group" + uniqueName);
        return (T) optionGroup;
    } else if (OptionGroupSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionGroupSet("OptionGroupSet" + uniqueName);
    } else if (Option.class.isAssignableFrom(clazz)) {
        return (T) new Option("Option" + uniqueName, "code" + uniqueName);
    } else if (OptionSet.class.isAssignableFrom(clazz)) {
        return (T) new OptionSet("OptionSet" + uniqueName, ValueType.TEXT);
    } else if (ProgramTrackedEntityAttributeGroup.class.isAssignableFrom(clazz)) {
        ProgramTrackedEntityAttributeGroup group = createProgramTrackedEntityAttributeGroup(uniqueName);
        ProgramTrackedEntityAttribute attr = createProgramTrackedEntityAttribute(uniqueName);
        group.addAttribute(attr);
        return (T) group;
    } else if (ProgramTrackedEntityAttribute.class.isAssignableFrom(clazz)) {
        return (T) createProgramTrackedEntityAttribute(uniqueName);
    } else if (ProgramDataElementDimensionItem.class.isAssignableFrom(clazz)) {
        return (T) createProgramDataElement(uniqueName);
    }
    return null;
}
Also used : ColorSet(org.hisp.dhis.color.ColorSet) OptionGroupSet(org.hisp.dhis.option.OptionGroupSet) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) ExternalMapLayer(org.hisp.dhis.mapping.ExternalMapLayer) Legend(org.hisp.dhis.legend.Legend) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Constant(org.hisp.dhis.constant.Constant) EventReport(org.hisp.dhis.eventreport.EventReport) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) IndicatorType(org.hisp.dhis.indicator.IndicatorType) OptionGroup(org.hisp.dhis.option.OptionGroup) CategoryOptionGroup(org.hisp.dhis.dataelement.CategoryOptionGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Program(org.hisp.dhis.program.Program) Color(org.hisp.dhis.color.Color) EventChart(org.hisp.dhis.eventchart.EventChart) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.option.Option) ProgramTrackedEntityAttributeGroup(org.hisp.dhis.program.ProgramTrackedEntityAttributeGroup) OptionSet(org.hisp.dhis.option.OptionSet) Map(java.util.Map) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Example 8 with DataElementCategoryCombo

use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.

the class FormUtils method getCategoryCombo.

private static CategoryCombo getCategoryCombo(DataSet dataset, Set<OrganisationUnit> userOrganisationUnits) {
    if (dataset.hasCategoryCombo()) {
        DataElementCategoryCombo categoryCombo = dataset.getCategoryCombo();
        CategoryCombo catCombo = new CategoryCombo();
        catCombo.setId(categoryCombo.getUid());
        List<DataElementCategory> cats = categoryCombo.getCategories();
        if (cats != null && cats.size() > 0) {
            for (DataElementCategory cat : cats) {
                if (cat.getAccess() != null && !cat.getAccess().isRead()) {
                    continue;
                }
                Category c = new Category();
                c.setId(cat.getUid());
                c.setLabel(cat.getName());
                List<DataElementCategoryOption> options = cat.getCategoryOptions();
                if (options != null && options.size() > 0) {
                    for (DataElementCategoryOption option : options) {
                        if (option.getAccess() != null && !option.getAccess().isRead()) {
                            continue;
                        }
                        Option o = new Option();
                        o.setId(option.getUid());
                        o.setLabel(option.getDisplayName());
                        o.setStartDate(option.getStartDate());
                        o.setEndDate(option.getEndDate());
                        Set<OrganisationUnit> catOptionOUs = option.getOrganisationUnits();
                        if (userOrganisationUnits == null || userOrganisationUnits.isEmpty() || catOptionOUs == null || catOptionOUs.isEmpty()) {
                            c.getOptions().add(o);
                        } else if (userOrganisationUnits != null && catOptionOUs != null && !Collections.disjoint(userOrganisationUnits, catOptionOUs)) {
                            HashSet<OrganisationUnit> organisationUnits = new HashSet<>();
                            catOptionOUs.stream().filter(ou -> userOrganisationUnits.contains(ou)).forEach(ou -> {
                                organisationUnits.add(ou);
                                organisationUnits.addAll(getChildren(ou, new HashSet<>()));
                            });
                            o.setOrganisationUnits(organisationUnits);
                            c.getOptions().add(o);
                        }
                    }
                }
                catCombo.getCategories().add(c);
            }
        }
        return catCombo;
    }
    return null;
}
Also used : SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) Category(org.hisp.dhis.webapi.webdomain.form.Category) ValueType(org.hisp.dhis.common.ValueType) DataSet(org.hisp.dhis.dataset.DataSet) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) HashMap(java.util.HashMap) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) HashSet(java.util.HashSet) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) Map(java.util.Map) Field(org.hisp.dhis.webapi.webdomain.form.Field) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) Option(org.hisp.dhis.webapi.webdomain.form.Option) Collection(java.util.Collection) Set(java.util.Set) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) NameableObjectUtils(org.hisp.dhis.common.NameableObjectUtils) ProgramStage(org.hisp.dhis.program.ProgramStage) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Section(org.hisp.dhis.dataset.Section) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) DataValue(org.hisp.dhis.datavalue.DataValue) Group(org.hisp.dhis.webapi.webdomain.form.Group) Form(org.hisp.dhis.webapi.webdomain.form.Form) Collections(java.util.Collections) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Category(org.hisp.dhis.webapi.webdomain.form.Category) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) CategoryCombo(org.hisp.dhis.webapi.webdomain.form.CategoryCombo) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) Option(org.hisp.dhis.webapi.webdomain.form.Option) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) HashSet(java.util.HashSet)

Example 9 with DataElementCategoryCombo

use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.

the class GetDataElementsAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    if (id != null && id != ALL) {
        DataElementGroup dataElementGroup = dataElementService.getDataElementGroup(id);
        if (dataElementGroup != null) {
            dataElements = new ArrayList<>(dataElementGroup.getMembers());
        }
    } else if (categoryComboId != null && categoryComboId != ALL) {
        DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo(categoryComboId);
        if (categoryCombo != null) {
            dataElements = new ArrayList<>(dataElementService.getDataElementByCategoryCombo(categoryCombo));
        }
    } else if (dataSetId != null) {
        DataSet dataset = dataSetService.getDataSet(dataSetId);
        if (dataset != null) {
            dataElements = new ArrayList<>(dataset.getDataElements());
        }
    } else if (periodTypeName != null) {
        PeriodType periodType = periodService.getPeriodTypeByName(periodTypeName);
        if (periodType != null) {
            dataElements = new ArrayList<>(dataElementService.getDataElementsByPeriodType(periodType));
        }
    } else if (domain != null) {
        if (domain.equals(DataElementDomain.AGGREGATE.getValue())) {
            dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.AGGREGATE));
        } else {
            dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.TRACKER));
        }
    } else {
        dataElements = new ArrayList<>(dataElementService.getAllDataElements());
        ContextUtils.clearIfNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), dataElements);
    }
    if (key != null) {
        dataElements = IdentifiableObjectUtils.filterNameByKey(dataElements, key, true);
    }
    if (dataElements == null) {
        dataElements = new ArrayList<>();
    }
    Collections.sort(dataElements);
    if (aggregate) {
        FilterUtils.filter(dataElements, new AggregatableDataElementFilter());
    }
    if (usePaging) {
        this.paging = createPaging(dataElements.size());
        dataElements = dataElements.subList(paging.getStartPos(), paging.getEndPos());
    }
    return SUCCESS;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) AggregatableDataElementFilter(org.hisp.dhis.system.filter.AggregatableDataElementFilter)

Example 10 with DataElementCategoryCombo

use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.

the class DefaultCsvImportService method dataElementsFromCsv.

private List<DataElement> dataElementsFromCsv(CsvReader reader) throws IOException {
    DataElementCategoryCombo categoryCombo = categoryService.getDefaultDataElementCategoryCombo();
    List<DataElement> list = new ArrayList<>();
    while (reader.readRecord()) {
        String[] values = reader.getValues();
        if (values != null && values.length > 0) {
            DataElement object = new DataElement();
            setIdentifiableObject(object, values);
            object.setShortName(getSafe(values, 3, object.getName(), 50));
            object.setDescription(getSafe(values, 4, null, null));
            object.setFormName(getSafe(values, 5, null, 230));
            String domainType = getSafe(values, 6, DataElementDomain.AGGREGATE.getValue(), 16);
            object.setDomainType(DataElementDomain.fromValue(domainType));
            object.setValueType(ValueType.valueOf(getSafe(values, 7, ValueType.INTEGER.toString(), 50)));
            object.setAggregationType(AggregationType.valueOf(getSafe(values, 8, AggregationType.SUM.toString(), 50)));
            String categoryComboUid = getSafe(values, 9, null, 11);
            object.setUrl(getSafe(values, 10, null, 255));
            object.setZeroIsSignificant(Boolean.valueOf(getSafe(values, 11, "false", null)));
            String optionSetUid = getSafe(values, 12, null, 11);
            String commentOptionSetUid = getSafe(values, 13, null, 11);
            object.setAutoFields();
            DataElementCategoryCombo cc = new DataElementCategoryCombo();
            cc.setUid(categoryComboUid);
            cc.setAutoFields();
            if (categoryComboUid == null) {
                cc.setUid(categoryCombo.getUid());
            }
            object.setDataElementCategoryCombo(cc);
            if (optionSetUid != null) {
                OptionSet optionSet = new OptionSet();
                optionSet.setUid(optionSetUid);
                optionSet.setAutoFields();
                object.setOptionSet(optionSet);
            }
            if (commentOptionSetUid != null) {
                OptionSet optionSet = new OptionSet();
                optionSet.setUid(commentOptionSetUid);
                optionSet.setAutoFields();
                object.setCommentOptionSet(optionSet);
            }
            list.add(object);
        }
    }
    return list;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) ArrayList(java.util.ArrayList) OptionSet(org.hisp.dhis.option.OptionSet)

Aggregations

DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)32 DataElement (org.hisp.dhis.dataelement.DataElement)14 DataSet (org.hisp.dhis.dataset.DataSet)12 ArrayList (java.util.ArrayList)11 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)10 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)8 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)8 Section (org.hisp.dhis.dataset.Section)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)5 List (java.util.List)4 Map (java.util.Map)4 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 SectionOrderComparator (org.hisp.dhis.dataset.comparator.SectionOrderComparator)3 OptionSet (org.hisp.dhis.option.OptionSet)3 Period (org.hisp.dhis.period.Period)3 Program (org.hisp.dhis.program.Program)3