use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class CategoryOptionResolver method resolve.
@Override
public String resolve(String expression) {
Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
for (DimensionalItemId id : dimItemIds) {
if (id.getItem() != null && id.getId1() != null && id.getId1().startsWith(CATEGORY_OPTION_PREFIX)) {
CategoryOption co = categoryOptionStore.getByUid(id.getId1().replace(CATEGORY_OPTION_PREFIX, EMPTY_STRING));
if (co != null) {
List<String> resolved = co.getCategoryOptionCombos().stream().map(coc -> id.getItem().replace(id.getId1(), coc.getUid())).collect(Collectors.toList());
expression = expression.replace(id.getItem(), LEFT_BRACKET + Joiner.on("+").join(resolved) + RIGHT_BRACKET);
}
}
}
return expression;
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class ExpressionService2Test method setUp.
@BeforeEach
public void setUp() {
target = new DefaultExpressionService(hibernateGenericStore, constantService, dimensionService, idObjectManager, statementBuilder, i18nManager, cacheProvider);
categoryOptionA = new CategoryOption("Under 5");
categoryOptionB = new CategoryOption("Over 5");
categoryOptionC = new CategoryOption("Male");
categoryOptionD = new CategoryOption("Female");
categoryA = new Category("Age", DataDimensionType.DISAGGREGATION);
categoryB = new Category("Gender", DataDimensionType.DISAGGREGATION);
categoryA.getCategoryOptions().add(categoryOptionA);
categoryA.getCategoryOptions().add(categoryOptionB);
categoryB.getCategoryOptions().add(categoryOptionC);
categoryB.getCategoryOptions().add(categoryOptionD);
categoryCombo = new CategoryCombo("Age and gender", DataDimensionType.DISAGGREGATION);
categoryCombo.getCategories().add(categoryA);
categoryCombo.getCategories().add(categoryB);
categoryCombo.generateOptionCombos();
List<CategoryOptionCombo> optionCombos = Lists.newArrayList(categoryCombo.getOptionCombos());
cocA = optionCombos.get(0);
cocA.setUid(CodeGenerator.generateUid());
cocB = optionCombos.get(1);
cocB.setUid(CodeGenerator.generateUid());
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
deD = createDataElement('D');
deE = createDataElement('E', categoryCombo);
coc = rnd.nextObject(CategoryOptionCombo.class);
coc.setName(DEFAULT_CATEGORY_COMBO_NAME);
optionCombos.add(coc);
opA = new DataElementOperand(deA, coc);
opB = new DataElementOperand(deB, coc);
opC = new DataElementOperand(deC, coc);
opD = new DataElementOperand(deD, coc);
opE = new DataElementOperand(deB, cocA);
opF = new DataElementOperand(deA, cocA, cocB);
period = createPeriod(getDate(2000, 1, 1), getDate(2000, 1, 31));
pteaA = rnd.nextObject(ProgramTrackedEntityAttributeDimensionItem.class);
pdeA = rnd.nextObject(ProgramDataElementDimensionItem.class);
piA = rnd.nextObject(ProgramIndicator.class);
unitA = createOrganisationUnit('A');
unitB = createOrganisationUnit('B');
unitC = createOrganisationUnit('C');
constantA = rnd.nextObject(Constant.class);
constantA.setName("ConstantA");
constantA.setValue(2.0);
constantB = rnd.nextObject(Constant.class);
constantB.setName("ConstantB");
constantB.setValue(5.0);
groupA = createOrganisationUnitGroup('A');
groupA.addOrganisationUnit(unitA);
groupA.addOrganisationUnit(unitB);
groupA.addOrganisationUnit(unitC);
groupB = createOrganisationUnitGroup('B');
groupB.addOrganisationUnit(unitB);
DataSet dataSetA = createDataSet('A');
dataSetA.setUid("a23dataSetA");
dataSetA.addOrganisationUnit(unitA);
reportingRate = new ReportingRate(dataSetA);
expressionA = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
expressionB = "#{" + deC.getUid() + SEPARATOR + coc.getUid() + "}-#{" + deD.getUid() + SEPARATOR + coc.getUid() + "}";
expressionC = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+#{" + deE.getUid() + "}-10";
expressionD = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}+" + SYMBOL_DAYS;
expressionE = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*C{" + constantA.getUid() + "}";
expressionF = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}";
expressionG = expressionF + "+#{" + deB.getUid() + "}-#{" + deC.getUid() + "}";
expressionH = "#{" + deA.getUid() + SEPARATOR + coc.getUid() + "}*OUG{" + groupA.getUid() + "}";
expressionI = "#{" + opA.getDimensionItem() + "}*" + "#{" + deB.getDimensionItem() + "}+" + "C{" + constantA.getUid() + "}+5-" + "D{" + pdeA.getDimensionItem() + "}+" + "A{" + pteaA.getDimensionItem() + "}-10+" + "I{" + piA.getDimensionItem() + "}";
expressionJ = "#{" + opA.getDimensionItem() + "}+#{" + opB.getDimensionItem() + "}";
expressionK = "1.5*avg(" + expressionJ + ")";
expressionL = expressionA + "+avg(" + expressionJ + ")+1.5*stddev(" + expressionJ + ")+" + expressionB;
expressionM = "#{" + deA.getUid() + SEPARATOR + SYMBOL_WILDCARD + "}-#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
expressionN = "#{" + deA.getUid() + SEPARATOR + cocA.getUid() + SEPARATOR + cocB.getUid() + "}-#{" + deB.getUid() + SEPARATOR + cocA.getUid() + "}";
expressionO = "#{" + opA.getDimensionItem() + "}+sum(#{" + opB.getDimensionItem() + "})";
expressionP = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}";
expressionR = "#{" + deB.getUid() + SEPARATOR + coc.getUid() + "}" + " + R{" + reportingRate.getUid() + ".REPORTING_RATE}";
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DataApprovalStoreUserTest method testGetDataApprovalStatuses.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testGetDataApprovalStatuses() {
CategoryOption catOptionA = new CategoryOption("CategoryOptionA");
catOptionA.addOrganisationUnit(orgUnitB);
categoryService.addCategoryOption(catOptionA);
org.hisp.dhis.category.Category catA = createCategory('A', catOptionA);
categoryService.addCategory(catA);
CategoryCombo catComboA = createCategoryCombo('A', catA);
categoryService.addCategoryCombo(catComboA);
CategoryOptionCombo catOptionComboA = createCategoryOptionCombo(catComboA, catOptionA);
categoryService.addCategoryOptionCombo(catOptionComboA);
List<DataApprovalStatus> statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitA), orgUnitA.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
assertEquals(1, statuses.size());
DataApprovalStatus status = statuses.get(0);
assertEquals(DataApprovalState.UNAPPROVED_WAITING, status.getState());
assertEquals(orgUnitA.getUid(), status.getOrganisationUnitUid());
assertEquals(orgUnitA.getName(), status.getOrganisationUnitName());
assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitB), orgUnitB.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
assertEquals(1, statuses.size());
status = statuses.get(0);
assertEquals(DataApprovalState.UNAPPROVED_WAITING, status.getState());
assertEquals(orgUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(orgUnitB.getName(), status.getOrganisationUnitName());
assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitC), orgUnitC.getHierarchyLevel(), catComboA, null, dataApprovalLevelService.getUserDataApprovalLevelsOrLowestLevel(mockCurrentUserService.getCurrentUser(), workflowA), dataApprovalLevelService.getDataApprovalLevelMap());
assertEquals(1, statuses.size());
status = statuses.get(0);
assertEquals(DataApprovalState.UNAPPROVED_READY, status.getState());
assertEquals(orgUnitC.getUid(), status.getOrganisationUnitUid());
assertEquals(orgUnitC.getName(), status.getOrganisationUnitName());
assertEquals(catOptionComboA.getUid(), status.getAttributeOptionComboUid());
statuses = dataApprovalStore.getDataApprovalStatuses(workflowA, periodA, Lists.newArrayList(orgUnitD), orgUnitD.getHierarchyLevel(), catComboA, null, null, null);
assertEquals(0, statuses.size());
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultAnalyticalObjectImportHandler method handleCategoryDimensions.
private void handleCategoryDimensions(Session session, Schema schema, BaseAnalyticalObject analyticalObject, ObjectBundle bundle) {
if (!schema.havePersistedProperty("categoryDimensions"))
return;
for (CategoryDimension categoryDimension : analyticalObject.getCategoryDimensions()) {
if (categoryDimension == null) {
continue;
}
categoryDimension.setDimension(bundle.getPreheat().get(bundle.getPreheatIdentifier(), categoryDimension.getDimension()));
List<CategoryOption> categoryOptions = new ArrayList<>(categoryDimension.getItems());
categoryDimension.getItems().clear();
categoryOptions.forEach(co -> {
CategoryOption categoryOption = bundle.getPreheat().get(bundle.getPreheatIdentifier(), co);
if (categoryOption != null)
categoryDimension.getItems().add(categoryOption);
});
preheatService.connectReferences(categoryDimension, bundle.getPreheat(), bundle.getPreheatIdentifier());
session.save(categoryDimension);
}
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class CategoryOptionResolverTest method setUp.
@BeforeEach
public void setUp() {
uid1 = CodeGenerator.generateUid();
uid2 = CodeGenerator.generateUid();
uid3 = CodeGenerator.generateUid();
CategoryOption categoryOption = createCategoryOption('A');
coc1 = createCategoryOptionCombo('X');
categoryOption.addCategoryOptionCombo(coc1);
coc2 = createCategoryOptionCombo('Y');
categoryOption.addCategoryOptionCombo(coc2);
coc3 = createCategoryOptionCombo('Z');
categoryOption.addCategoryOptionCombo(coc3);
resolver = new CategoryOptionResolver(expressionService, categoryOptionStore);
when(categoryOptionStore.getByUid(anyString())).thenReturn(categoryOption);
}
Aggregations