use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class DataQueryServiceTest method setUpTest.
@Override
public void setUpTest() {
super.userService = internalUserService;
prA = createProgram('A');
programService.addProgram(prA);
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
deD = createDataElement('D');
DataElement deE = createDataElement('E');
DataElement deF = createDataElement('F');
deE.setDomainType(DataElementDomain.TRACKER);
deF.setDomainType(DataElementDomain.TRACKER);
dataElementService.addDataElement(deA);
dataElementService.addDataElement(deB);
dataElementService.addDataElement(deC);
dataElementService.addDataElement(deD);
dataElementService.addDataElement(deE);
dataElementService.addDataElement(deF);
pdA = new ProgramDataElementDimensionItem(prA, deE);
pdB = new ProgramDataElementDimensionItem(prA, deF);
cocA = categoryService.getDefaultCategoryOptionCombo();
DataSet dsA = createDataSet('A', monthly);
DataSet dsB = createDataSet('B', monthly);
dataSetService.addDataSet(dsA);
dataSetService.addDataSet(dsB);
rrA = new ReportingRate(dsA, ReportingRateMetric.REPORTING_RATE);
rrB = new ReportingRate(dsB, ReportingRateMetric.REPORTING_RATE);
rrC = new ReportingRate(dsB, ReportingRateMetric.ACTUAL_REPORTS);
itA = createIndicatorType('A');
idObjectManager.save(itA);
inA = createIndicator('A', itA);
inB = createIndicator('B', itA);
idObjectManager.save(inA);
idObjectManager.save(inB);
inGroupA = createIndicatorGroup('A');
inGroupA.getMembers().add(inA);
inGroupA.getMembers().add(inB);
idObjectManager.save(inGroupA);
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');
ouC = createOrganisationUnit('C');
ouD = createOrganisationUnit('D');
ouE = createOrganisationUnit('E');
ouB.updateParent(ouA);
ouC.updateParent(ouA);
ouD.updateParent(ouB);
ouE.updateParent(ouB);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
organisationUnitService.addOrganisationUnit(ouC);
organisationUnitService.addOrganisationUnit(ouD);
organisationUnitService.addOrganisationUnit(ouE);
ouGroupSetA = createOrganisationUnitGroupSet('A');
organisationUnitGroupService.addOrganisationUnitGroupSet(ouGroupSetA);
ouGroupA = createOrganisationUnitGroup('A');
ouGroupA.setPublicAccess(AccessStringHelper.FULL);
ouGroupB = createOrganisationUnitGroup('B');
ouGroupB.setPublicAccess(AccessStringHelper.FULL);
ouGroupC = createOrganisationUnitGroup('C');
ouGroupC.setPublicAccess(AccessStringHelper.FULL);
ouGroupA.addOrganisationUnit(ouA);
ouGroupA.addOrganisationUnit(ouB);
ouGroupA.addOrganisationUnit(ouC);
organisationUnitGroupService.addOrganisationUnitGroup(ouGroupA);
organisationUnitGroupService.addOrganisationUnitGroup(ouGroupB);
organisationUnitGroupService.addOrganisationUnitGroup(ouGroupC);
ouGroupSetA.addOrganisationUnitGroup(ouGroupA);
ouGroupSetA.addOrganisationUnitGroup(ouGroupB);
ouGroupSetA.addOrganisationUnitGroup(ouGroupC);
organisationUnitGroupService.updateOrganisationUnitGroupSet(ouGroupSetA);
deGroupSetA = createDataElementGroupSet('A');
dataElementService.addDataElementGroupSet(deGroupSetA);
deGroupA = createDataElementGroup('A');
deGroupB = createDataElementGroup('B');
deGroupC = createDataElementGroup('C');
deGroupA.getGroupSets().add(deGroupSetA);
deGroupB.getGroupSets().add(deGroupSetA);
deGroupC.getGroupSets().add(deGroupSetA);
deGroupA.getGroupSets().add(deGroupSetA);
deGroupA.addDataElement(deA);
deGroupA.addDataElement(deB);
deGroupA.addDataElement(deC);
dataElementService.addDataElementGroup(deGroupA);
dataElementService.addDataElementGroup(deGroupB);
dataElementService.addDataElementGroup(deGroupC);
deGroupSetA.addDataElementGroup(deGroupA);
deGroupSetA.addDataElementGroup(deGroupB);
deGroupSetA.addDataElementGroup(deGroupC);
dataElementService.updateDataElementGroupSet(deGroupSetA);
// ---------------------------------------------------------------------
// Inject user
// ---------------------------------------------------------------------
UserAuthorityGroup role = createUserAuthorityGroup('A', "ALL");
userService.addUserAuthorityGroup(role);
User user = createUser('A');
user.addOrganisationUnit(ouA);
user.getUserAuthorityGroups().add(role);
saveAndInjectUserSecurityContext(user);
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class DataDimensionExtractor method getBaseDimensionalItemObject.
private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
BaseDimensionalItemObject dimensionalItemObject = null;
switch(id.getDimensionItemType()) {
case DATA_ELEMENT:
DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
if (dataElement != null) {
dimensionalItemObject = cloneIfNeeded(dataElement, id);
}
break;
case INDICATOR:
final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
if (indicator != null) {
dimensionalItemObject = cloneIfNeeded(indicator, id);
}
break;
case DATA_ELEMENT_OPERAND:
dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
}
break;
case REPORTING_RATE:
final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
if (dataSet != null) {
dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
}
break;
case PROGRAM_DATA_ELEMENT:
Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
if (program != null && dataElement != null) {
dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
}
break;
case PROGRAM_ATTRIBUTE:
program = (Program) atomicObjects.getValue(Program.class, id.getId0());
final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
if (program != null && attribute != null) {
dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
}
break;
case PROGRAM_INDICATOR:
final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
if (programIndicator != null) {
dimensionalItemObject = cloneIfNeeded(programIndicator, id);
}
break;
default:
log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
break;
}
return dimensionalItemObject;
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class DefaultDimensionService method getDataDimensionalItemObject.
@Override
public DimensionalItemObject getDataDimensionalItemObject(IdScheme idScheme, String dimensionItem) {
if (DimensionalObjectUtils.isCompositeDimensionalObject(dimensionItem)) {
String id0 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 0);
String id1 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 1);
String id2 = splitSafe(dimensionItem, COMPOSITE_DIM_OBJECT_ESCAPED_SEP, 2);
DataElementOperand operand;
ReportingRate reportingRate;
ProgramDataElementDimensionItem programDataElement;
ProgramTrackedEntityAttributeDimensionItem programAttribute;
if ((operand = getDataElementOperand(idScheme, id0, id1, id2)) != null) {
return operand;
} else if ((reportingRate = dataDimensionExtractor.getReportingRate(idScheme, id0, id1)) != null) {
return reportingRate;
} else if ((programDataElement = dataDimensionExtractor.getProgramDataElementDimensionItem(idScheme, id0, id1)) != null) {
return programDataElement;
} else if ((programAttribute = dataDimensionExtractor.getProgramAttributeDimensionItem(idScheme, id0, id1)) != null) {
return programAttribute;
}
} else if (!idScheme.is(IdentifiableProperty.UID) || CodeGenerator.isValidUid(dimensionItem)) {
DimensionalItemObject itemObject = idObjectManager.get(DataDimensionItem.DATA_DIMENSION_CLASSES, idScheme, dimensionItem);
if (itemObject != null) {
return itemObject;
}
}
return null;
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem 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();
}
use of org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem in project dhis2-core by dhis2.
the class DimensionServiceTest method testGetDimensionalItemObject.
@Test
void testGetDimensionalItemObject() {
String idA = deA.getUid();
String idB = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + deA.getUid();
String idC = prA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + atA.getUid();
String idD = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + ReportingRateMetric.REPORTING_RATE.name();
String idE = dsA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_METRIC";
String idF = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
String idG = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
String idH = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + "UNKNOWN_SYMBOL";
String idI = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
String idJ = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD;
String idK = deA.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + SYMBOL_WILDCARD + COMPOSITE_DIM_OBJECT_PLAIN_SEP + cocA.getUid();
ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
ProgramTrackedEntityAttributeDimensionItem ptaA = new ProgramTrackedEntityAttributeDimensionItem(prA, atA);
ReportingRate rrA = new ReportingRate(dsA, ReportingRateMetric.REPORTING_RATE);
DataElementOperand deoA = new DataElementOperand(deA, cocA);
DataElementOperand deoB = new DataElementOperand(deA, null);
DataElementOperand deoC = new DataElementOperand(deA, cocA, cocA);
DataElementOperand deoD = new DataElementOperand(deA, cocA, null);
DataElementOperand deoE = new DataElementOperand(deA, null, cocA);
assertNotNull(dimensionService.getDataDimensionalItemObject(idA));
assertEquals(deA, dimensionService.getDataDimensionalItemObject(idA));
assertNotNull(dimensionService.getDataDimensionalItemObject(idB));
assertEquals(pdeA, dimensionService.getDataDimensionalItemObject(idB));
assertNotNull(dimensionService.getDataDimensionalItemObject(idC));
assertEquals(ptaA, dimensionService.getDataDimensionalItemObject(idC));
assertNotNull(dimensionService.getDataDimensionalItemObject(idD));
assertEquals(rrA, dimensionService.getDataDimensionalItemObject(idD));
assertNull(dimensionService.getDataDimensionalItemObject(idE));
assertNotNull(dimensionService.getDataDimensionalItemObject(idF));
assertEquals(deoA, dimensionService.getDataDimensionalItemObject(idF));
assertNotNull(dimensionService.getDataDimensionalItemObject(idG));
assertEquals(deoB, dimensionService.getDataDimensionalItemObject(idG));
assertNull(dimensionService.getDataDimensionalItemObject(idH));
assertNotNull(dimensionService.getDataDimensionalItemObject(idI));
assertEquals(deoC, dimensionService.getDataDimensionalItemObject(idI));
assertNotNull(dimensionService.getDataDimensionalItemObject(idJ));
assertEquals(deoD, dimensionService.getDataDimensionalItemObject(idJ));
assertNotNull(dimensionService.getDataDimensionalItemObject(idK));
assertEquals(deoE, dimensionService.getDataDimensionalItemObject(idK));
}
Aggregations