use of org.hisp.dhis.common.BaseDimensionalItemObject 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.common.BaseDimensionalItemObject in project dhis2-core by dhis2.
the class EnrollmentAnalyticsManagerTest method verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTypeValue.
@Test
void verifyGetColumnOfTypeCoordinateAndWithProgramStagesAndParamsWithReferenceTypeValue() {
// Given
DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
QueryItem item = new QueryItem(dio);
item.setValueType(ValueType.COORDINATE);
item.setProgramStage(programStageWithRepeatableParams);
item.setProgram(programB);
RepeatableStageParams repeatableStageParams = new RepeatableStageParams();
repeatableStageParams.setStartIndex(0);
repeatableStageParams.setCount(100);
repeatableStageParams.setStartDate(DateUtils.parseDate("2022-01-01"));
repeatableStageParams.setEndDate(DateUtils.parseDate("2022-01-31"));
item.setRepeatableStageParams(repeatableStageParams);
// When
String columnSql = subject.getColumn(item);
// Then
assertThat(columnSql, is("(select json_agg(t1) from (select \"" + dataElementA.getUid() + "\", incidentdate, duedate, executiondate from analytics_event_" + programB.getUid() + " where analytics_event_" + programB.getUid() + ".pi = ax.pi and \"" + dataElementA.getUid() + "\" is not null and ps = '" + programStageWithRepeatableParams.getUid() + "' and executiondate >= '2022-01-01' and executiondate <= '2022-01-31' order by executiondate desc LIMIT 100 ) as t1)"));
}
use of org.hisp.dhis.common.BaseDimensionalItemObject in project dhis2-core by dhis2.
the class EnrollmentAnalyticsManagerTest method verifyGetCoordinateColumnWithNoProgram.
@Test
void verifyGetCoordinateColumnWithNoProgram() {
// Given
DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
QueryItem item = new QueryItem(dio);
item.setValueType(ValueType.COORDINATE);
item.setProgramStage(programStage);
// When
String columnSql = subject.getCoordinateColumn(item);
// Then
assertThat(columnSql, is(EMPTY));
}
use of org.hisp.dhis.common.BaseDimensionalItemObject in project dhis2-core by dhis2.
the class EventAnalyticsTest method createRequestParams.
protected EventQueryParams createRequestParams(ProgramStage withProgramStage, ValueType withQueryItemValueType) {
EventQueryParams.Builder params = new EventQueryParams.Builder(_createRequestParams());
DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
params.withProgram(programA);
if (withProgramStage != null) {
params.withProgramStage(programStage);
}
if (withQueryItemValueType != null) {
QueryItem queryItem = new QueryItem(dio);
if (withProgramStage != null) {
queryItem.setProgramStage(programStage);
}
queryItem.setProgram(programA);
queryItem.setValueType(withQueryItemValueType);
params.addItem(queryItem);
}
return params.build();
}
use of org.hisp.dhis.common.BaseDimensionalItemObject in project dhis2-core by dhis2.
the class AbstractJdbcEventAnalyticsManagerTest method verifyGetSelectSqlWithNonTextDataElement.
@Test
void verifyGetSelectSqlWithNonTextDataElement() {
DimensionalItemObject dio = new BaseDimensionalItemObject(dataElementA.getUid());
QueryItem item = new QueryItem(dio);
item.setValueType(ValueType.NUMBER);
String column = subject.getSelectSql(new QueryFilter(), item, from, to);
assertThat(column, is("ax.\"" + dataElementA.getUid() + "\""));
}
Aggregations