Search in sources :

Example 51 with CategoryOption

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

the class PredictorServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
    organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
    dataElementA = createDataElement('A');
    dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    DataElement dataElementD = createDataElement('D');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementX);
    dataElements = new HashSet<>();
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    dataElements.add(dataElementC);
    dataElements.add(dataElementD);
    periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
    CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    defaultCombo = categoryService.getDefaultCategoryOptionCombo();
    altCategoryOption = new CategoryOption("AltCategoryOption");
    categoryService.addCategoryOption(altCategoryOption);
    altCategory = createCategory('A', altCategoryOption);
    categoryService.addCategory(altCategory);
    altCategoryCombo = createCategoryCombo('Y', altCategory);
    categoryService.addCategoryCombo(altCategoryCombo);
    altCombo = createCategoryOptionCombo(altCategoryCombo, altCategoryOption);
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    optionCombos.add(altCombo);
    categoryService.addCategoryOptionCombo(altCombo);
    expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
    expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
    expressionC = new Expression("135.79", "descriptionC");
    expressionD = new Expression("34.98", "descriptionD");
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Expression(org.hisp.dhis.expression.Expression) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 52 with CategoryOption

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

the class DefaultCsvImportService method categoryOptionsFromCsv.

private List<CategoryOption> categoryOptionsFromCsv(CsvReader reader) throws IOException {
    List<CategoryOption> list = new ArrayList<>();
    while (reader.readRecord()) {
        String[] values = reader.getValues();
        if (values != null && values.length > 0) {
            CategoryOption object = new CategoryOption();
            setIdentifiableObject(object, values);
            object.setShortName(getSafe(values, 3, object.getName(), 50));
            list.add(object);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) CategoryOption(org.hisp.dhis.category.CategoryOption)

Example 53 with CategoryOption

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

the class AttributeOptionComboLoader method getAttributeOptionCombo.

private CategoryOptionCombo getAttributeOptionCombo(IdScheme idScheme, String categoryComboId, Set<CategoryOption> categoryOptions) {
    final String key = "categorycomboid";
    final String categoryComboKey = resolveId(idScheme, key, categoryComboId);
    final String optionsId = categoryOptions.stream().map(co -> Long.toString(co.getId())).map(s -> "'" + s + "'").collect(Collectors.joining(","));
    StringSubstitutor sub = new StringSubstitutor(ImmutableMap.<String, String>builder().put("resolvedScheme", Objects.requireNonNull(categoryComboKey)).put("option_ids", optionsId).build());
    // TODO use cache
    List<CategoryOptionCombo> categoryOptionCombos = jdbcTemplate.query(sub.replace(SQL_GET_CATEGORYOPTIONCOMBO_BY_CATEGORYIDS), (rs, i) -> bind("categoryoptioncomboid", rs));
    if (categoryOptionCombos.size() == 1) {
        return categoryOptionCombos.get(0);
    } else {
        // TODO throw an error??
        return null;
    }
}
Also used : Arrays(java.util.Arrays) CategoryOption(org.hisp.dhis.category.CategoryOption) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) StringSubstitutor(org.apache.commons.text.StringSubstitutor) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) HashSet(java.util.HashSet) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) IdentifiableProperty(org.hisp.dhis.common.IdentifiableProperty) Qualifier(org.springframework.beans.factory.annotation.Qualifier) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectUtils(org.springframework.util.ObjectUtils) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) Sharing(org.hisp.dhis.user.sharing.Sharing) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) JacksonObjectMapperConfig(org.hisp.dhis.commons.jackson.config.JacksonObjectMapperConfig) Component(org.springframework.stereotype.Component) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) CategoryCombo(org.hisp.dhis.category.CategoryCombo) IdScheme(org.hisp.dhis.common.IdScheme) TextUtils(org.hisp.dhis.commons.util.TextUtils) StringSubstitutor(org.apache.commons.text.StringSubstitutor) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 54 with CategoryOption

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

the class DefaultDataSetMetadataExportService method getDataSetMetadata.

// TODO add lock exceptions
// TODO add validation caching (ETag and If-None-Match).
@Override
public ObjectNode getDataSetMetadata() {
    User user = currentUserService.getCurrentUser();
    List<DataSet> dataSets = idObjectManager.getDataWriteAll(DataSet.class);
    Set<DataElement> dataElements = flatMapToSet(dataSets, DataSet::getDataElements);
    Set<Indicator> indicators = flatMapToSet(dataSets, DataSet::getIndicators);
    Set<CategoryCombo> dataElementCategoryCombos = flatMapToSet(dataElements, DataElement::getCategoryCombos);
    Set<CategoryCombo> dataSetCategoryCombos = mapToSet(dataSets, DataSet::getCategoryCombo);
    Set<Category> dataElementCategories = flatMapToSet(dataElementCategoryCombos, CategoryCombo::getCategories);
    Set<Category> dataSetCategories = flatMapToSet(dataSetCategoryCombos, CategoryCombo::getCategories);
    Set<CategoryOption> categoryOptions = getCategoryOptions(dataElementCategories, dataSetCategories, user);
    expressionService.substituteIndicatorExpressions(indicators);
    ObjectNode rootNode = fieldFilterService.createObjectNode();
    rootNode.putArray(DataSetSchemaDescriptor.PLURAL).addAll(asObjectNodes(dataSets, FIELDS_DATA_SETS, DataSet.class));
    rootNode.putArray(DataElementSchemaDescriptor.PLURAL).addAll(asObjectNodes(dataElements, FIELDS_DATA_ELEMENTS, DataElement.class));
    rootNode.putArray(IndicatorSchemaDescriptor.PLURAL).addAll(asObjectNodes(indicators, FIELDS_INDICATORS, Indicator.class));
    rootNode.putArray(CategoryComboSchemaDescriptor.PLURAL).addAll(asObjectNodes(dataElementCategoryCombos, FIELDS_DATAELEMENT_CAT_COMBOS, CategoryCombo.class)).addAll(asObjectNodes(dataSetCategoryCombos, FIELDS_DATA_SET_CAT_COMBOS, CategoryCombo.class));
    rootNode.putArray(CategorySchemaDescriptor.PLURAL).addAll(asObjectNodes(dataElementCategories, FIELDS_CATEGORIES, Category.class)).addAll(asObjectNodes(dataSetCategories, FIELDS_CATEGORIES, Category.class));
    rootNode.putArray(CategoryOptionSchemaDescriptor.PLURAL).addAll(asObjectNodes(categoryOptions, FIELDS_CATEGORIES, CategoryOption.class));
    return rootNode;
}
Also used : User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DataSet(org.hisp.dhis.dataset.DataSet) Indicator(org.hisp.dhis.indicator.Indicator) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption)

Example 55 with CategoryOption

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

the class AdxDataServiceIntegrationTest method setUpTest.

@Override
public void setUpTest() {
    // UserService
    userService = _userService;
    // Category Option
    coUnder5 = new CategoryOption("Under 5");
    coOver5 = new CategoryOption("Over 5");
    coF = new CategoryOption("Female");
    coM = new CategoryOption("Male");
    coPepfar = new CategoryOption("PEPFAR mechanism");
    coMcDonalds = new CategoryOption("McDonalds mechanism");
    coUnder5.setCode("under5");
    coOver5.setCode("over5");
    coF.setCode("F");
    coM.setCode("M");
    coPepfar.setCode("PEPFAR");
    coMcDonalds.setCode("McDonalds");
    coUnder5.setUid("under555555");
    coOver5.setUid("over5555555");
    coF.setUid("FFFFFFFFFFF");
    coM.setUid("MMMMMMMMMMM");
    coPepfar.setUid("PEPFARRRRRR");
    coMcDonalds.setUid("McDonaldsss");
    idObjectManager.save(coUnder5);
    idObjectManager.save(coOver5);
    idObjectManager.save(coF);
    idObjectManager.save(coM);
    idObjectManager.save(coPepfar);
    idObjectManager.save(coMcDonalds);
    // Category
    cAge = createCategory('A', coUnder5, coOver5);
    cSex = createCategory('B', coF, coM);
    cMechanism = createCategory('C', coPepfar, coMcDonalds);
    cAge.setName("Age_category");
    cSex.setName("Sex_category");
    cMechanism.setName("Mechanism_category");
    cAge.setCode("age");
    cSex.setCode("sex");
    cMechanism.setCode("mechanism");
    cAge.setUid("ageeeeeeeee");
    cSex.setUid("sexxxxxxxxx");
    cMechanism.setUid("mechanismmm");
    idObjectManager.save(cAge);
    idObjectManager.save(cSex);
    idObjectManager.save(cMechanism);
    // Category Combo
    ccAgeAndSex = createCategoryCombo('A', cAge, cSex);
    ccMechanism = createCategoryCombo('B', cMechanism);
    ccAgeAndSex.setName("Age and Sex Category Combo");
    ccMechanism.setName("Mechanism Category Combo");
    idObjectManager.save(ccAgeAndSex);
    idObjectManager.save(ccMechanism);
    cAge.setCategoryCombos(Lists.newArrayList(ccAgeAndSex));
    cSex.setCategoryCombos(Lists.newArrayList(ccAgeAndSex));
    cMechanism.setCategoryCombos(Lists.newArrayList(ccMechanism));
    idObjectManager.update(cAge);
    idObjectManager.update(cSex);
    idObjectManager.update(cMechanism);
    // Category Option Combo
    cocFUnder5 = createCategoryOptionCombo(ccAgeAndSex, coF, coUnder5);
    cocMUnder5 = createCategoryOptionCombo(ccAgeAndSex, coM, coUnder5);
    cocFOver5 = createCategoryOptionCombo(ccAgeAndSex, coF, coOver5);
    cocMOver5 = createCategoryOptionCombo(ccAgeAndSex, coM, coOver5);
    cocPepfar = createCategoryOptionCombo(ccMechanism, coPepfar);
    cocMcDonalds = createCategoryOptionCombo(ccMechanism, coMcDonalds);
    cocFUnder5.setName("Female Under 5");
    cocMUnder5.setName("Male Under 5");
    cocFOver5.setName("Female Over 5");
    cocMOver5.setName("Male Over 5");
    cocPepfar.setName("PEPFAR CategoryOptionCombo");
    cocMcDonalds.setName("McDonalds CategoryOptionCombo");
    cocFUnder5.setCode("F_Under5");
    cocMUnder5.setCode("M_Under5");
    cocFOver5.setCode("F_Over5");
    cocMOver5.setCode("M_Over5");
    cocPepfar.setCode("coc_PEPFAR");
    cocMcDonalds.setCode("coc_McDonalds");
    cocFUnder5.setUid("FUnder55555");
    cocMUnder5.setUid("MUnder55555");
    cocFOver5.setUid("FOver555555");
    cocMOver5.setUid("MOver555555");
    cocPepfar.setUid("cocPEPFARRR");
    cocMcDonalds.setUid("cocMcDonald");
    idObjectManager.save(cocFUnder5);
    idObjectManager.save(cocMUnder5);
    idObjectManager.save(cocFOver5);
    idObjectManager.save(cocMOver5);
    idObjectManager.save(cocPepfar);
    idObjectManager.save(cocMcDonalds);
    ccAgeAndSex.getOptionCombos().add(cocFUnder5);
    ccAgeAndSex.getOptionCombos().add(cocMUnder5);
    ccAgeAndSex.getOptionCombos().add(cocFOver5);
    ccAgeAndSex.getOptionCombos().add(cocMOver5);
    ccMechanism.getOptionCombos().add(cocPepfar);
    ccMechanism.getOptionCombos().add(cocMcDonalds);
    idObjectManager.update(ccAgeAndSex);
    idObjectManager.update(ccMechanism);
    cocDefault = categoryService.getDefaultCategoryOptionCombo();
    // Data Element
    deA = createDataElement('A');
    deB = createDataElement('B');
    deA.setName("Malaria numeric");
    deB.setName("Malaria text");
    deA.setCode("Mal_num");
    deB.setCode("Mal_text");
    deA.setUid("MalNummmmmm");
    deB.setUid("MalTexttttt");
    deA.setCategoryCombo(ccAgeAndSex);
    deB.setValueType(ValueType.TEXT);
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    // Period
    pe202001 = PeriodType.getPeriodFromIsoString("202001");
    pe202002 = PeriodType.getPeriodFromIsoString("202002");
    pe2021Q1 = PeriodType.getPeriodFromIsoString("2021Q1");
    periodService.addPeriod(pe202001);
    periodService.addPeriod(pe202002);
    periodService.addPeriod(pe2021Q1);
    // Data Set
    dsA = createDataSet('A', PeriodType.getPeriodTypeByName("Monthly"));
    dsB = createDataSet('B', PeriodType.getPeriodTypeByName("Quarterly"));
    dsA.setName("Malaria DS");
    dsB.setName("Malaria Mechanism DS");
    dsA.setCode("MalariaDS");
    dsB.setCode("MalariaMechanismDS");
    dsA.setUid("MalariaDSSS");
    dsB.setUid("MalariaMech");
    dsA.addDataSetElement(deA);
    dsA.addDataSetElement(deB);
    dsB.addDataSetElement(deA);
    dsB.addDataSetElement(deB);
    dsB.setCategoryCombo(ccMechanism);
    idObjectManager.save(dsA);
    idObjectManager.save(dsB);
    // Organisation Unit
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B', ouA);
    ouA.setName("Provincial Hospital");
    ouB.setName("District Hospital");
    ouA.setCode("123");
    ouB.setCode("456");
    ouA.setUid("P1233333333");
    ouB.setUid("D4566666666");
    idObjectManager.save(ouA);
    idObjectManager.save(ouB);
    // Organisation Unit Group
    ougA = createOrganisationUnitGroup('A');
    ougA.addOrganisationUnit(ouA);
    ougA.addOrganisationUnit(ouB);
    organisationUnitGroupService.addOrganisationUnitGroup(ougA);
    // User & Current User Service
    user = createAndInjectAdminUser();
    user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    userService.addUser(user);
    CurrentUserService currentUserService = new MockCurrentUserService(user);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService, organisationUnitService);
}
Also used : MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CategoryOption(org.hisp.dhis.category.CategoryOption) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget)

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