use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testHandleGridForDataValueSet.
@Test
void testHandleGridForDataValueSet() {
IndicatorType itA = new IndicatorType();
CategoryOptionCombo ocA = createCategoryOptionCombo('A');
ocA.setUid("ceabcdefghA");
DataElement dxA = createDataElement('A');
dxA.setUid("deabcdefghA");
dxA.setValueType(ValueType.INTEGER);
DataElement dxB = createDataElement('B');
dxB.setUid("deabcdefghB");
dxB.setValueType(ValueType.NUMBER);
Indicator dxC = createIndicator('C', itA);
dxC.setUid("deabcdefghC");
dxC.setDecimals(0);
dxC.setAggregateExportAttributeOptionCombo("ceabcdefghA");
Indicator dxD = createIndicator('D', itA);
dxD.setUid("deabcdefghD");
dxD.setDecimals(2);
dxD.setAggregateExportCategoryOptionCombo("ceabcdefghB");
DataElementOperand dxE = new DataElementOperand(dxA, ocA);
DataElementOperand dxF = new DataElementOperand(dxB, ocA);
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(dxA, dxB, dxC, dxD, dxE, dxF))).build();
Grid grid = new ListGrid();
grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, false, false));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA", "ouA", "peA", 1d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB", "ouA", "peA", 2d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghC", "ouA", "peA", 3d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghD", "ouA", "peA", 4d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA.ceabcdefghA", "ouA", "peA", 5d));
grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB.ceabcdefghA", "ouA", "peA", 6d));
assertEquals(4, grid.getWidth());
assertEquals(6, grid.getHeight());
AnalyticsUtils.handleGridForDataValueSet(params, grid);
assertEquals(6, grid.getWidth());
assertEquals(6, grid.getHeight());
assertEquals("deabcdefghA", grid.getRow(0).get(0));
assertNull(grid.getRow(0).get(3));
assertNull(grid.getRow(0).get(4));
assertEquals(1, grid.getRow(0).get(5));
assertEquals("deabcdefghB", grid.getRow(1).get(0));
assertNull(grid.getRow(1).get(3));
assertNull(grid.getRow(1).get(4));
assertEquals((Double) grid.getRow(1).get(5), 0.01, 2d);
assertEquals("deabcdefghC", grid.getRow(2).get(0));
assertNull(grid.getRow(2).get(3));
assertEquals("ceabcdefghA", grid.getRow(2).get(4));
assertEquals(3, grid.getRow(2).get(5));
assertEquals("deabcdefghD", grid.getRow(3).get(0));
assertEquals("ceabcdefghB", grid.getRow(3).get(3));
assertNull(grid.getRow(3).get(4));
assertEquals((Double) grid.getRow(3).get(5), 0.01, 4d);
assertEquals("deabcdefghA", grid.getRow(4).get(0));
assertEquals("ceabcdefghA", grid.getRow(4).get(3));
assertNull(grid.getRow(4).get(4));
assertEquals(5, grid.getRow(4).get(5));
assertEquals("deabcdefghB", grid.getRow(5).get(0));
assertEquals("ceabcdefghA", grid.getRow(5).get(3));
assertNull(grid.getRow(5).get(4));
assertEquals((Double) grid.getRow(5).get(5), 0.01, 6d);
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetCocNameMap.
@Test
void testGetCocNameMap() {
CategoryCombo ccA = createCategoryCombo('A', new Category[0]);
CategoryCombo ccB = createCategoryCombo('B', new Category[0]);
CategoryOptionCombo cocA = createCategoryOptionCombo('A');
CategoryOptionCombo cocB = createCategoryOptionCombo('B');
ccA.getOptionCombos().add(cocA);
ccB.getOptionCombos().add(cocB);
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
deA.setCategoryCombo(ccA);
deB.setCategoryCombo(ccB);
DimensionalObject dx = new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB));
DataQueryParams params = DataQueryParams.newBuilder().addDimension(dx).withDisplayProperty(DisplayProperty.NAME).build();
Map<String, String> map = AnalyticsUtils.getCocNameMap(params);
assertEquals(map.get(cocA.getUid()), cocA.getName());
assertEquals(map.get(cocB.getUid()), cocB.getName());
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class CategoryOptionGroupResolverTest method setUp.
@BeforeEach
public void setUp() {
uid1 = CodeGenerator.generateUid();
uid2 = CodeGenerator.generateUid();
uid3 = CodeGenerator.generateUid();
CategoryOptionGroup categoryOptionGroup = createCategoryOptionGroup('A');
coc1 = createCategoryOptionCombo('X');
coc2 = createCategoryOptionCombo('Y');
coc3 = createCategoryOptionCombo('Z');
resolver = new CategoryOptionGroupResolver(expressionService, categoryOptionGroupStore, categoryOptionComboStore);
when(categoryOptionGroupStore.getByUid(anyString())).thenReturn(categoryOptionGroup);
List<CategoryOptionCombo> cocList = new ArrayList<>();
cocList.add(coc1);
cocList.add(coc2);
cocList.add(coc3);
when(categoryOptionComboStore.getCategoryOptionCombosByGroupUid(anyString(), anyString())).thenReturn(cocList);
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PredictorStoreTest 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');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementX);
CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
defaultCombo = categoryOptionCombo;
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
expressionA = new Expression("expressionA", "descriptionA");
expressionB = new Expression("expressionB", "descriptionB");
expressionC = new Expression("expressionC", "descriptionC");
expressionD = new Expression("expressionD", "descriptionD");
periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class AttributeOptionComboDateCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
CategoryOptionCombo attributeOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
Date executionDate = null;
if (event.getEventDate() != null) {
executionDate = DateUtils.parseDate(event.getEventDate());
}
Date dueDate = new Date();
if (event.getDueDate() != null) {
dueDate = DateUtils.parseDate(event.getDueDate());
}
Date eventDate = executionDate != null ? executionDate : dueDate;
if (eventDate == null) {
return error("Event date can not be empty", event.getEvent());
}
Program program = ctx.getProgramsMap().get(event.getProgram());
for (CategoryOption categoryOption : attributeOptionCombo.getCategoryOptions()) {
if (categoryOption.getStartDate() != null && eventDate.compareTo(categoryOption.getStartDate()) < 0) {
return error("Event date " + getMediumDateString(eventDate) + " is before start date " + getMediumDateString(categoryOption.getStartDate()) + " for attributeOption '" + categoryOption.getName() + "'", event.getEvent());
}
if (categoryOption.getEndDate() != null && eventDate.compareTo(categoryOption.getAdjustedEndDate(program)) > 0) {
return error("Event date " + getMediumDateString(eventDate) + " is after end date " + getMediumDateString(categoryOption.getAdjustedEndDate(program)) + " for attributeOption '" + categoryOption.getName() + "' in program '" + program.getName() + "'", event.getEvent());
}
}
return success();
}
Aggregations