use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class EventQueryPlannerTest method setUpTest.
@Override
public void setUpTest() {
prA = createProgram('A');
prA.setUid("programuida");
idObjectManager.save(prA);
deA = createDataElement('A', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
deB = createDataElement('B', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
deC = createDataElement('C', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
deD = createDataElement('D', ValueType.INTEGER, AggregationType.AVERAGE_SUM_ORG_UNIT, DataElementDomain.TRACKER);
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
idObjectManager.save(deD);
pdeA = new ProgramDataElementDimensionItem(prA, deA);
pdeB = new ProgramDataElementDimensionItem(prA, deB);
pdeC = new ProgramDataElementDimensionItem(prA, deC);
pdeD = new ProgramDataElementDimensionItem(prA, deD);
atA = createTrackedEntityAttribute('A');
atB = createTrackedEntityAttribute('B');
idObjectManager.save(atA);
idObjectManager.save(atB);
patA = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
patB = new ProgramTrackedEntityAttributeDimensionItem(prA, atB);
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
ouC = createOrganisationUnit('C', ouA);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
organisationUnitService.addOrganisationUnit(ouC);
lsA = createLegendSet('A');
idObjectManager.save(lsA);
osA = new OptionSet("OptionSetA", ValueType.TEXT);
idObjectManager.save(osA);
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class DimensionalObjectUtilsTest method testGetUidMapIsSchemeCodeCompositeObject.
@Test
public void testGetUidMapIsSchemeCodeCompositeObject() {
Program prA = new Program();
prA.setUid("P123456789A");
prA.setCode("PCodeA");
DataElement deA = new DataElement("NameA");
DataElement deB = new DataElement("NameB");
deA.setUid("D123456789A");
deB.setUid("D123456789B");
deA.setCode("DCodeA");
deB.setCode("DCodeB");
ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
List<ProgramDataElementDimensionItem> elements = Lists.newArrayList(pdeA, pdeB);
Map<String, String> map = DimensionalObjectUtils.getDimensionItemIdSchemeMap(elements, IdScheme.CODE);
assertEquals(2, map.size());
assertEquals("PCodeA.DCodeA", map.get("P123456789A.D123456789A"));
assertEquals("PCodeA.DCodeB", map.get("P123456789A.D123456789B"));
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class AnalyticsUtilsTest method testGetByDataDimensionType.
@Test
public void testGetByDataDimensionType() {
Program prA = createProgram('A');
DataElement deA = createDataElement('A', new DataElementCategoryCombo());
DataElement deB = createDataElement('B', new DataElementCategoryCombo());
ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
ProgramIndicator piA = createProgramIndicator('A', prA, null, null);
List<DimensionalItemObject> list = Lists.newArrayList(deA, deB, pdeA, pdeB, piA);
assertEquals(Lists.newArrayList(deA, deB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.DATA_ELEMENT, list));
assertEquals(Lists.newArrayList(pdeA, pdeB), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_DATA_ELEMENT, list));
assertEquals(Lists.newArrayList(piA), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_INDICATOR, list));
assertEquals(Lists.newArrayList(), AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.PROGRAM_ATTRIBUTE, list));
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class DefaultQueryPlanner method validate.
// -------------------------------------------------------------------------
// DefaultQueryPlanner implementation
// -------------------------------------------------------------------------
@Override
public void validate(DataQueryParams params) throws IllegalQueryException {
String violation = null;
if (params == null) {
throw new IllegalQueryException("Params cannot be null");
}
final List<DimensionalItemObject> dataElements = Lists.newArrayList(params.getDataElements());
params.getProgramDataElements().stream().forEach(pde -> dataElements.add(((ProgramDataElementDimensionItem) pde).getDataElement()));
final List<DataElement> nonAggDataElements = FilterUtils.inverseFilter(asTypedList(dataElements), AggregatableDataElementFilter.INSTANCE);
if (params.getDimensions().isEmpty()) {
violation = "At least one dimension must be specified";
}
if (!params.getDimensionsAsFilters().isEmpty()) {
violation = "Dimensions cannot be specified as dimension and filter simultaneously: " + params.getDimensionsAsFilters();
}
if (!params.hasPeriods() && !params.isSkipPartitioning() && !params.hasStartEndDate()) {
violation = "At least one period must be specified as dimension or filter";
}
if (params.hasPeriods() && params.hasStartEndDate()) {
violation = "Periods and start and end dates cannot be specified simultaneously";
}
if (!params.getFilterIndicators().isEmpty() && params.getFilterOptions(DATA_X_DIM_ID).size() > 1) {
violation = "Only a single indicator can be specified as filter";
}
if (!params.getFilterReportingRates().isEmpty() && params.getFilterOptions(DATA_X_DIM_ID).size() > 1) {
violation = "Only a single reporting rate can be specified as filter";
}
if (params.getFilters().contains(new BaseDimensionalObject(CATEGORYOPTIONCOMBO_DIM_ID))) {
violation = "Category option combos cannot be specified as filter";
}
if (!params.getDuplicateDimensions().isEmpty()) {
violation = "Dimensions cannot be specified more than once: " + params.getDuplicateDimensions();
}
if (!params.getAllReportingRates().isEmpty() && !params.containsOnlyDimensionsAndFilters(COMPLETENESS_DIMENSION_TYPES)) {
violation = "Reporting rates can only be specified together with dimensions of type: " + COMPLETENESS_DIMENSION_TYPES;
}
if (params.hasDimensionOrFilter(CATEGORYOPTIONCOMBO_DIM_ID) && params.getAllDataElements().isEmpty()) {
violation = "Assigned categories cannot be specified when data elements are not specified";
}
if (params.hasDimensionOrFilter(CATEGORYOPTIONCOMBO_DIM_ID) && (params.getAllDataElements().size() != params.getAllDataDimensionItems().size())) {
violation = "Assigned categories can only be specified together with data elements, not indicators or reporting rates";
}
if (!nonAggDataElements.isEmpty()) {
violation = "Data elements must be of a value and aggregation type that allow aggregation: " + getUids(nonAggDataElements);
}
if (params.isOutputFormat(OutputFormat.DATA_VALUE_SET)) {
if (!params.hasDimension(DATA_X_DIM_ID)) {
violation = "A data dimension 'dx' must be specified when output format is DATA_VALUE_SET";
}
if (!params.hasDimension(PERIOD_DIM_ID)) {
violation = "A period dimension 'pe' must be specified when output format is DATA_VALUE_SET";
}
if (!params.hasDimension(ORGUNIT_DIM_ID)) {
violation = "An organisation unit dimension 'ou' must be specified when output format is DATA_VALUE_SET";
}
}
if (violation != null) {
log.warn(String.format("Analytics validation failed: %s", violation));
throw new IllegalQueryException(violation);
}
}
use of org.hisp.dhis.program.ProgramDataElementDimensionItem in project dhis2-core by dhis2.
the class EventQueryParams method fromDataQueryParams.
public static EventQueryParams fromDataQueryParams(DataQueryParams dataQueryParams) {
EventQueryParams params = new EventQueryParams();
dataQueryParams.copyTo(params);
EventQueryParams.Builder builder = new EventQueryParams.Builder(params);
for (DimensionalItemObject object : dataQueryParams.getProgramDataElements()) {
ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
DataElement dataElement = element.getDataElement();
QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
item.setProgram(element.getProgram());
builder.addItem(item);
}
for (DimensionalItemObject object : dataQueryParams.getProgramAttributes()) {
ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
TrackedEntityAttribute attribute = element.getAttribute();
QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
item.setProgram(element.getProgram());
builder.addItem(item);
}
for (DimensionalItemObject object : dataQueryParams.getFilterProgramDataElements()) {
ProgramDataElementDimensionItem element = (ProgramDataElementDimensionItem) object;
DataElement dataElement = element.getDataElement();
QueryItem item = new QueryItem(dataElement, (dataElement.getLegendSets().isEmpty() ? null : dataElement.getLegendSets().get(0)), dataElement.getValueType(), dataElement.getAggregationType(), dataElement.getOptionSet());
item.setProgram(element.getProgram());
builder.addItemFilter(item);
}
for (DimensionalItemObject object : dataQueryParams.getFilterProgramAttributes()) {
ProgramTrackedEntityAttributeDimensionItem element = (ProgramTrackedEntityAttributeDimensionItem) object;
TrackedEntityAttribute attribute = element.getAttribute();
QueryItem item = new QueryItem(attribute, (attribute.getLegendSets().isEmpty() ? null : attribute.getLegendSets().get(0)), attribute.getValueType(), attribute.getAggregationType(), attribute.getOptionSet());
builder.addItemFilter(item);
}
for (DimensionalItemObject object : dataQueryParams.getProgramIndicators()) {
ProgramIndicator programIndicator = (ProgramIndicator) object;
builder.addItemProgramIndicator(programIndicator);
}
return builder.withAggregateData(true).removeDimension(DATA_X_DIM_ID).build();
}
Aggregations