Search in sources :

Example 76 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testCreateDataSetWithSectionsAndGreyedFields.

@Test
void testCreateDataSetWithSectionsAndGreyedFields() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    List<DataSet> dataSets = manager.getAll(DataSet.class);
    List<Section> sections = manager.getAll(Section.class);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    List<User> users = manager.getAll(User.class);
    List<DataElementOperand> dataElementOperands = manager.getAll(DataElementOperand.class);
    List<TrackedEntityType> trackedEntityTypes = manager.getAll(TrackedEntityType.class);
    List<OrganisationUnitLevel> organisationUnitLevels = manager.getAll(OrganisationUnitLevel.class);
    assertFalse(organisationUnits.isEmpty());
    assertEquals(1, organisationUnitLevels.size());
    assertEquals(1, trackedEntityTypes.size());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, dataSets.size());
    assertEquals(2, sections.size());
    assertEquals(1, dataElementOperands.size());
    DataSet dataSet = dataSets.get(0);
    assertEquals(2, dataSet.getSections().size());
    Section section1 = sections.get(0);
    Section section2 = sections.get(1);
    assertEquals(1, section1.getDataElements().size());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section1.getDataSet());
    assertNotNull(section2.getDataSet());
    Section section = manager.get(Section.class, "C50M0WxaI7y");
    assertNotNull(section.getDataSet());
    assertEquals(1, section.getCategoryCombos().size());
    assertEquals(1, section.getGreyedFields().size());
    CategoryCombo categoryCombo = manager.get(CategoryCombo.class, "faV8QvLgIwB");
    assertNotNull(categoryCombo);
    Category category = manager.get(Category.class, "XJGLlMAMCcn");
    assertNotNull(category);
    CategoryOption categoryOption1 = manager.get(CategoryOption.class, "JYiFOMKa25J");
    CategoryOption categoryOption2 = manager.get(CategoryOption.class, "tdaMRD34m8o");
    assertNotNull(categoryOption1);
    assertNotNull(categoryOption2);
}
Also used : User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) DataSet(org.hisp.dhis.dataset.DataSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) Section(org.hisp.dhis.dataset.Section) ClassPathResource(org.springframework.core.io.ClassPathResource) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 77 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class SectionUtilsTest method testDataSetSection.

@Test
void testDataSetSection() {
    CategoryOption categoryOptionA = new CategoryOption("OptionA");
    CategoryOption categoryOptionB = new CategoryOption("OptionB");
    CategoryOption categoryOptionC = new CategoryOption("OptionC");
    CategoryOption categoryOptionD = new CategoryOption("OptionD");
    CategoryOption categoryOptionE = new CategoryOption("OptionE");
    CategoryOption categoryOptionF = new CategoryOption("OptionF");
    CategoryOption categoryOptionG = new CategoryOption("OptionG");
    categoryService.addCategoryOption(categoryOptionA);
    categoryService.addCategoryOption(categoryOptionB);
    categoryService.addCategoryOption(categoryOptionC);
    categoryService.addCategoryOption(categoryOptionD);
    categoryService.addCategoryOption(categoryOptionE);
    categoryService.addCategoryOption(categoryOptionF);
    categoryService.addCategoryOption(categoryOptionG);
    Category categoryA = createCategory('A', categoryOptionA, categoryOptionB);
    Category categoryB = createCategory('B', categoryOptionC, categoryOptionD);
    Category categoryC = createCategory('C', categoryOptionE, categoryOptionF);
    categoryService.addCategory(categoryA);
    categoryService.addCategory(categoryB);
    categoryService.addCategory(categoryC);
    List<Category> categoriesAB = new ArrayList<>();
    List<Category> categoriesABC = new ArrayList<>();
    categoriesAB.add(categoryA);
    categoriesAB.add(categoryB);
    categoriesABC.add(categoryA);
    categoriesABC.add(categoryB);
    categoriesABC.add(categoryC);
    CategoryCombo categoryComboAB = new CategoryCombo("CategoryComboA", DataDimensionType.DISAGGREGATION, categoriesAB);
    CategoryCombo categoryComboABC = new CategoryCombo("CategoryComboB", DataDimensionType.DISAGGREGATION, categoriesABC);
    long catAB = categoryService.addCategoryCombo(categoryComboAB);
    long catABC = categoryService.addCategoryCombo(categoryComboABC);
    long catDefault = categoryService.getDefaultCategoryCombo().getId();
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C', categoryComboAB);
    DataElement dataElementD = createDataElement('D', categoryComboAB);
    DataElement dataElementE = createDataElement('E');
    DataElement dataElementF = createDataElement('F', categoryComboABC);
    DataElement dataElementG = createDataElement('G', categoryComboABC);
    DataElement dataElementH = createDataElement('H', categoryComboAB);
    DataElement dataElementI = createDataElement('I', categoryComboABC);
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementE);
    dataElementService.addDataElement(dataElementF);
    dataElementService.addDataElement(dataElementG);
    dataElementService.addDataElement(dataElementH);
    dataElementService.addDataElement(dataElementI);
    PeriodType periodType = new MonthlyPeriodType();
    DataSet dataSetA = createDataSet('A', periodType);
    dataSetA.addDataSetElement(dataElementA);
    dataSetA.addDataSetElement(dataElementB);
    dataSetA.addDataSetElement(dataElementC);
    dataSetA.addDataSetElement(dataElementD);
    dataSetA.addDataSetElement(dataElementE);
    dataSetA.addDataSetElement(dataElementF);
    dataSetA.addDataSetElement(dataElementG);
    dataSetA.addDataSetElement(dataElementH);
    dataSetA.addDataSetElement(dataElementI);
    Section section = new Section();
    List<DataElement> dataElements = new ArrayList<>();
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    dataElements.add(dataElementC);
    dataElements.add(dataElementD);
    dataElements.add(dataElementE);
    dataElements.add(dataElementF);
    dataElements.add(dataElementG);
    dataElements.add(dataElementH);
    dataElements.add(dataElementI);
    section.setDataElements(dataElements);
    dataSetA.getSections().add(section);
    long idA = dataSetService.addDataSet(dataSetA);
    DataSet ds = dataSetService.getDataSet(idA);
    assertEquals(idA, ds.getId());
    assertEquals(9, ds.getDataSetElements().size());
    assertEquals(1, ds.getSections().size());
    Section sec = ds.getSections().iterator().next();
    assertEquals(9, sec.getDataElements().size());
    Map<String, Collection<DataElement>> orderedDataElements = sectionUtils.getOrderedDataElementsMap(sec);
    List<String> keys = new ArrayList<>(orderedDataElements.keySet());
    assertEquals(6, orderedDataElements.keySet().size());
    String key1 = sec.getId() + "-" + catDefault + "-" + "0";
    String key2 = sec.getId() + "-" + catAB + "-" + "1";
    String key3 = sec.getId() + "-" + catDefault + "-" + "2";
    String key4 = sec.getId() + "-" + catABC + "-" + "3";
    String key5 = sec.getId() + "-" + catAB + "-" + "4";
    String key6 = sec.getId() + "-" + catABC + "-" + "5";
    assertEquals(key1, keys.get(0));
    assertEquals(key2, keys.get(1));
    assertEquals(key3, keys.get(2));
    assertEquals(key4, keys.get(3));
    assertEquals(key5, keys.get(4));
    assertEquals(key6, keys.get(5));
    assertEquals(2, orderedDataElements.get(key1).size());
    assertEquals(2, orderedDataElements.get(key2).size());
    assertEquals(1, orderedDataElements.get(key3).size());
    assertEquals(2, orderedDataElements.get(key4).size());
    assertEquals(1, orderedDataElements.get(key5).size());
    assertEquals(1, orderedDataElements.get(key6).size());
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) Category(org.hisp.dhis.category.Category) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) Section(org.hisp.dhis.dataset.Section) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryOption(org.hisp.dhis.category.CategoryOption) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 78 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class AnalyticsDataSetReportStore method getAggregatedSubTotals.

@Override
public Map<String, Object> getAggregatedSubTotals(DataSet dataSet, List<Period> periods, OrganisationUnit unit, Set<String> filters) {
    Map<String, Object> dataMap = new HashMap<>();
    for (Section section : dataSet.getSections()) {
        List<DataElement> dataElements = new ArrayList<>(section.getDataElements());
        Set<Category> categories = new HashSet<>();
        for (CategoryCombo categoryCombo : section.getCategoryCombos()) {
            categories.addAll(categoryCombo.getCategories());
        }
        FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
        if (dataElements.isEmpty() || categories == null || categories.isEmpty()) {
            continue;
        }
        for (Category category : categories) {
            if (category.isDefault()) {
                // No need for sub-total for default
                continue;
            }
            if (!category.isDataDimension()) {
                log.warn("Could not get sub-total for category: " + category.getUid() + " for data set report: " + dataSet + ", not a data dimension");
                continue;
            }
            DataQueryParams.Builder params = DataQueryParams.newBuilder().withDataElements(dataElements).withPeriods(periods).withOrganisationUnit(unit).withCategory(category);
            if (filters != null) {
                params.addFilters(dataQueryService.getDimensionalObjects(filters, null, null, null, false, IdScheme.UID));
            }
            Map<String, Object> map = analyticsService.getAggregatedDataValueMapping(params.build());
            for (Entry<String, Object> entry : map.entrySet()) {
                String[] split = entry.getKey().split(SEPARATOR);
                addToMap(dataMap, split[0] + SEPARATOR + split[3], entry.getValue());
            }
        }
    }
    return dataMap;
}
Also used : Category(org.hisp.dhis.category.Category) Section(org.hisp.dhis.dataset.Section) DataElement(org.hisp.dhis.dataelement.DataElement) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo)

Example 79 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class OperandTest method testEquals.

@Test
void testEquals() {
    DataElement dataElementA = new DataElement("DataElement A");
    DataElement dataElementB = new DataElement("DataElement B");
    CategoryCombo categoryComboA = new CategoryCombo("CategoryCombo A", DISAGGREGATION);
    CategoryCombo categoryComboB = new CategoryCombo("CategoryCombo B", DISAGGREGATION);
    CategoryCombo defaultCatCombo = new CategoryCombo(DEFAULT_CATEGORY_COMBO_NAME, DISAGGREGATION);
    CategoryOptionCombo categoryOptionComboA = new CategoryOptionCombo();
    categoryOptionComboA.setCategoryCombo(categoryComboA);
    CategoryOptionCombo categoryOptionComboB = new CategoryOptionCombo();
    categoryOptionComboB.setCategoryCombo(categoryComboB);
    CategoryOptionCombo defaultCatOptionCombo = new CategoryOptionCombo();
    defaultCatOptionCombo.setCategoryCombo(defaultCatCombo);
    DataElementOperand dataElementOperandA = new DataElementOperand(dataElementA, categoryOptionComboA);
    DataElementOperand dataElementOperandB = new DataElementOperand(dataElementB, categoryOptionComboB);
    DataElementOperand dataElementOperandC = new DataElementOperand(dataElementA, categoryOptionComboA);
    DataElementOperand dataElementOperandD = new DataElementOperand(dataElementB, categoryOptionComboB);
    DataElementOperand dataElementOperandE = new DataElementOperand(dataElementA, categoryOptionComboA, categoryOptionComboA);
    DataElementOperand dataElementOperandF = new DataElementOperand(dataElementA, categoryOptionComboB, categoryOptionComboB);
    DataElementOperand dataElementOperandG = new DataElementOperand(dataElementA, categoryOptionComboA, categoryOptionComboA);
    DataElementOperand dataElementOperandH = new DataElementOperand(dataElementA, categoryOptionComboB, categoryOptionComboB);
    DataElementOperand dataElementOperandI = new DataElementOperand(dataElementA);
    DataElementOperand dataElementOperandJ = new DataElementOperand(dataElementA, defaultCatOptionCombo);
    assertEquals(dataElementOperandA, dataElementOperandC);
    assertEquals(dataElementOperandB, dataElementOperandD);
    assertEquals(dataElementOperandE, dataElementOperandG);
    assertEquals(dataElementOperandF, dataElementOperandH);
    assertNotEquals(dataElementOperandA, dataElementOperandB);
    assertNotEquals(dataElementOperandC, dataElementOperandD);
    assertNotEquals(dataElementOperandE, dataElementOperandF);
    assertNotEquals(dataElementOperandG, dataElementOperandH);
    assertNotEquals(dataElementOperandI, dataElementOperandJ);
    assertNotEquals(dataElementOperandA, dataElementOperandE);
    assertNotEquals(dataElementOperandA, dataElementOperandI);
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Example 80 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class AnalyticsServiceMetadataTest method metadataContainsRelativePeriodItem.

@SuppressWarnings("unchecked")
@Test
void metadataContainsRelativePeriodItem() {
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 4, 1, 0, 0).toDate()));
    BaseDimensionalObject periodDimension = new BaseDimensionalObject("pe", DimensionType.PERIOD, periods);
    DimensionItemKeywords dimensionalKeywords = new DimensionItemKeywords();
    dimensionalKeywords.addKeyword(THIS_QUARTER.name(), "This quarter");
    periodDimension.setDimensionalKeywords(dimensionalKeywords);
    DataQueryParams params = DataQueryParams.newBuilder().withDimensions(Lists.newArrayList(periodDimension, new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', new CategoryCombo()))))).withSkipData(true).build();
    initMock(params);
    Grid grid = target.getAggregatedDataValueGrid(params);
    Map<String, Object> items = (Map<String, Object>) grid.getMetaData().get("items");
    assertTrue(items.containsKey(THIS_QUARTER.name()));
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionItemKeywords(org.hisp.dhis.common.DimensionItemKeywords) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DateTime(org.joda.time.DateTime) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseNameableObject(org.hisp.dhis.common.BaseNameableObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

CategoryCombo (org.hisp.dhis.category.CategoryCombo)114 Test (org.junit.jupiter.api.Test)66 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)53 CategoryOption (org.hisp.dhis.category.CategoryOption)47 Category (org.hisp.dhis.category.Category)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)36 Program (org.hisp.dhis.program.Program)31 Event (org.hisp.dhis.tracker.domain.Event)27 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)23 BeforeEach (org.junit.jupiter.api.BeforeEach)23 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 Collectors (java.util.stream.Collectors)21 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 Collections (java.util.Collections)20 CategoryService (org.hisp.dhis.category.CategoryService)20 CodeGenerator (org.hisp.dhis.common.CodeGenerator)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)20 Sets (com.google.common.collect.Sets)19