use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DataValueDimensionTest method testGetDimensions.
@Test
public void testGetDimensions() {
List<DataElementCategoryOption> categoryOptions = new ArrayList<>();
categoryOptions.add(male);
categoryOptions.add(under15);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
DataValue dataValue = dataValueService.getDataValue(dataElementA, periodA, sourceA, categoryOptionCombo);
assertNotNull(dataValue);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class DataValueDimensionTest method testGetByCategoryOptionCombos.
@Test
public void testGetByCategoryOptionCombos() {
List<DataElementCategoryOption> categoryOptions = new ArrayList<>();
categoryOptions.add(male);
categoryOptions.add(under15);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
assertNotNull(categoryOptionCombo);
assertEquals(genderAndAgeGroup, categoryOptionCombo.getCategoryCombo());
assertTrue(CollectionUtils.isEqualCollection(categoryOptions, categoryOptionCombo.getCategoryOptions()));
categoryOptions.clear();
categoryOptions.add(female);
categoryOptions.add(over15);
categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
assertNotNull(categoryOptionCombo);
assertEquals(genderAndAgeGroup, categoryOptionCombo.getCategoryCombo());
assertTrue(CollectionUtils.isEqualCollection(categoryOptions, categoryOptionCombo.getCategoryOptions()));
categoryOptions.clear();
categoryOptions.add(male);
categoryOptions.add(female);
categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptions);
assertNull(categoryOptionCombo);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo 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');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
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);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B');
sourceC = createOrganisationUnit('C', sourceB);
sourceD = createOrganisationUnit('D', sourceB);
sourceE = createOrganisationUnit('E', sourceD);
sourceF = createOrganisationUnit('F', sourceD);
sourceG = createOrganisationUnit('G');
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
organisationUnitService.addOrganisationUnit(sourceC);
organisationUnitService.addOrganisationUnit(sourceD);
organisationUnitService.addOrganisationUnit(sourceE);
organisationUnitService.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceG);
periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetMonthly.addDataSetElement(dataElementA);
dataSetMonthly.addDataSetElement(dataElementB);
dataSetMonthly.addDataSetElement(dataElementC);
dataSetMonthly.addDataSetElement(dataElementD);
dataSetMonthly.addDataSetElement(dataElementX);
dataSetMonthly.addOrganisationUnit(sourceA);
dataSetMonthly.addOrganisationUnit(sourceB);
dataSetMonthly.addOrganisationUnit(sourceC);
dataSetMonthly.addOrganisationUnit(sourceD);
dataSetMonthly.addOrganisationUnit(sourceE);
dataSetMonthly.addOrganisationUnit(sourceG);
dataSetService.addDataSet(dataSetMonthly);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
altCategoryOption = new DataElementCategoryOption("AltCategoryOption");
categoryService.addDataElementCategoryOption(altCategoryOption);
altDataElementCategory = createDataElementCategory('A', altCategoryOption);
categoryService.addDataElementCategory(altDataElementCategory);
altDataElementCategoryCombo = createCategoryCombo('Y', altDataElementCategory);
categoryService.addDataElementCategoryCombo(altDataElementCategoryCombo);
altCombo = createCategoryOptionCombo('Z', altDataElementCategoryCombo, altCategoryOption);
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
optionCombos.add(altCombo);
categoryService.addDataElementCategoryOptionCombo(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("1234", "descriptionC");
expressionD = new Expression(SYMBOL_DAYS, "descriptionD");
expressionService.addExpression(expressionA);
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionC);
expressionService.addExpression(expressionD);
Set<OrganisationUnit> units = newHashSet(sourceA, sourceB, sourceG);
CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, units, units);
setDependency(predictorService, "currentUserService", mockCurrentUserService, CurrentUserService.class);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class ExpressionStoreTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
DataElement dataElementA = createDataElement('A');
DataElement dataElementB = createDataElement('B');
DataElement dataElementC = createDataElement('C');
DataElement dataElementD = createDataElement('D');
dataElementIdA = dataElementService.addDataElement(dataElementA);
dataElementIdB = dataElementService.addDataElement(dataElementB);
dataElementIdC = dataElementService.addDataElement(dataElementC);
dataElementIdD = dataElementService.addDataElement(dataElementD);
DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryComboByName(DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
DataElementCategoryOptionCombo categoryOptionCombo = categoryCombo.getOptionCombos().iterator().next();
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
expressionA = "[" + dataElementIdA + "] + [" + dataElementIdB + "]";
expressionB = "[" + dataElementIdC + "] - [" + dataElementIdD + "]";
descriptionA = "Expression A";
descriptionB = "Expression B";
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
}
use of org.hisp.dhis.dataelement.DataElementCategoryOptionCombo in project dhis2-core by dhis2.
the class InputUtils method getAttributeOptionCombo.
/**
* Validates and retrieves the attribute option combo. 409 conflict as
* status code along with a textual message will be set on the response in
* case of invalid input.
*
* @param categoryCombo the category combo.
* @param opts list of category option uid.
* @param attributeOptionCombo the explicit attribute option combo
* identifier.
* @return the attribute option combo identified from the given input, or
* null if the input was invalid.
*/
public DataElementCategoryOptionCombo getAttributeOptionCombo(DataElementCategoryCombo categoryCombo, Set<String> opts, String attributeOptionCombo, IdScheme idScheme) {
if (categoryCombo == null) {
throw new IllegalQueryException("Illegal category combo");
}
// ---------------------------------------------------------------------
// Attribute category options validation
// ---------------------------------------------------------------------
DataElementCategoryOptionCombo attrOptCombo = null;
if (opts != null) {
Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
for (String uid : opts) {
DataElementCategoryOption categoryOption = idObjectManager.getObject(DataElementCategoryOption.class, idScheme, uid);
if (categoryOption == null) {
throw new IllegalQueryException("Illegal category option identifier: " + uid);
}
categoryOptions.add(categoryOption);
}
attrOptCombo = categoryService.getDataElementCategoryOptionCombo(categoryCombo, categoryOptions);
if (attrOptCombo == null) {
throw new IllegalQueryException("Attribute option combo does not exist for given category combo and category options");
}
} else if (attributeOptionCombo != null) {
attrOptCombo = categoryService.getDataElementCategoryOptionCombo(attributeOptionCombo);
}
if (attrOptCombo == null) {
attrOptCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
if (attrOptCombo == null) {
throw new IllegalQueryException("Default attribute option combo does not exist");
}
return attrOptCombo;
}
Aggregations