Search in sources :

Example 61 with CategoryOption

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

the class AttributeOptionComboLoaderTest method verifyGetAttributeOptionCombo.

@Test
void verifyGetAttributeOptionCombo() {
    // prepare data
    CategoryCombo cc = createCategoryCombo('B');
    CategoryOption categoryOption = createCategoryOption('A');
    categoryOption.setId(100L);
    when(jdbcTemplate.queryForObject(eq("select categoryoptionid, uid, code, name, startdate, enddate, sharing from dataelementcategoryoption where uid = 'abcdef'"), any(RowMapper.class))).thenReturn(categoryOption);
    when(jdbcTemplate.query(anyString(), any(RowMapper.class))).thenReturn(singletonList(createCategoryOptionCombo(cc, categoryOption)));
    // method under test
    CategoryOptionCombo categoryOptionCombo = subject.getAttributeOptionCombo(cc, "abcdef", "", IdScheme.UID);
    // assertions
    assertThat(categoryOptionCombo, is(notNullValue()));
    verify(jdbcTemplate).query(sqlCaptor.capture(), any(RowMapper.class));
    final String sql = sqlCaptor.getValue();
    assertThat(sql, is(replace(SQL_GET_CATEGORYOPTIONCOMBO_BY_CATEGORYIDS, "resolvedScheme", "uid = '" + cc.getUid() + "'", "option_ids", "'100'")));
}
Also used : DhisConvenienceTest.createCategoryCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryCombo) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) DhisConvenienceTest.createCategoryOption(org.hisp.dhis.DhisConvenienceTest.createCategoryOption) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DhisConvenienceTest.createCategoryOptionCombo(org.hisp.dhis.DhisConvenienceTest.createCategoryOptionCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.junit.jupiter.api.Test)

Example 62 with CategoryOption

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

the class AttributeOptionComboDateCheckTest method createCategoryOptionCombo.

private CategoryOptionCombo createCategoryOptionCombo(String date, boolean startDate) {
    CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
    Set<CategoryOption> catOptions = new HashSet<>();
    CategoryOption categoryOptionA = new CategoryOption();
    categoryOptionA.setName("test");
    if (startDate) {
        categoryOptionA.setStartDate(DateUtils.parseDate(date));
    } else {
        categoryOptionA.setEndDate(DateUtils.parseDate(date));
    }
    catOptions.add(categoryOptionA);
    categoryOptionCombo.setCategoryOptions(catOptions);
    return categoryOptionCombo;
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Example 63 with CategoryOption

use of org.hisp.dhis.category.CategoryOption 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 64 with CategoryOption

use of org.hisp.dhis.category.CategoryOption 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 65 with CategoryOption

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

the class DefaultFieldFilterServiceTest method baseIdentifiableName.

@Test
void baseIdentifiableName() {
    final OrganisationUnit ou1 = new OrganisationUnit();
    ou1.setUid("abc1");
    ou1.setName("OU 1");
    final OrganisationUnit ou2 = new OrganisationUnit();
    ou2.setUid("abc2");
    ou2.setName("OU 2");
    final CategoryOption option = new CategoryOption();
    option.setUid("def1");
    option.getOrganisationUnits().add(ou1);
    option.getOrganisationUnits().add(ou2);
    final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(option), Arrays.asList("id", "organisationUnits~pluck(name)[id,name]"));
    final ComplexNode node = service.toComplexNode(params);
    Assertions.assertEquals("categoryOption", node.getName());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "id") instanceof SimpleNode);
    Assertions.assertEquals("def1", ((SimpleNode) getNamedNode(node.getUnorderedChildren(), "id")).getValue());
    Assertions.assertTrue(getNamedNode(node.getUnorderedChildren(), "organisationUnits") instanceof CollectionNode);
    final CollectionNode collectionNode = (CollectionNode) getNamedNode(node.getUnorderedChildren(), "organisationUnits");
    Assertions.assertEquals(2, collectionNode.getUnorderedChildren().size());
    final List<String> ouIds = new ArrayList<>();
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(0) instanceof SimpleNode);
    SimpleNode simpleNode = (SimpleNode) collectionNode.getUnorderedChildren().get(0);
    Assertions.assertEquals("name", simpleNode.getName());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    Assertions.assertTrue(collectionNode.getUnorderedChildren().get(1) instanceof SimpleNode);
    simpleNode = (SimpleNode) collectionNode.getUnorderedChildren().get(1);
    Assertions.assertEquals("name", simpleNode.getName());
    ouIds.add(String.valueOf(simpleNode.getValue()));
    assertThat(ouIds, Matchers.containsInAnyOrder("OU 1", "OU 2"));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ComplexNode(org.hisp.dhis.node.types.ComplexNode) ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode) Test(org.junit.jupiter.api.Test)

Aggregations

CategoryOption (org.hisp.dhis.category.CategoryOption)87 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)47 CategoryCombo (org.hisp.dhis.category.CategoryCombo)38 Category (org.hisp.dhis.category.Category)34 Test (org.junit.jupiter.api.Test)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)26 Program (org.hisp.dhis.program.Program)19 ArrayList (java.util.ArrayList)18 Event (org.hisp.dhis.tracker.domain.Event)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 DataElement (org.hisp.dhis.dataelement.DataElement)13 Collections (java.util.Collections)12 DataSet (org.hisp.dhis.dataset.DataSet)12 CodeGenerator (org.hisp.dhis.common.CodeGenerator)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)11 CategoryService (org.hisp.dhis.category.CategoryService)10 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10