use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class GetMetaDataAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
User user = currentUserService.getCurrentUser();
Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(DataElementCategoryCombo.class), identifiableObjectManager.getLastUpdated(DataElementCategory.class), identifiableObjectManager.getLastUpdated(DataElementCategoryOption.class)));
String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
return SUCCESS;
}
if (user != null && user.getOrganisationUnits().isEmpty()) {
emptyOrganisationUnits = true;
return SUCCESS;
}
significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
dataElements = dataElementService.getDataElementsWithDataSets();
for (DataElement dataElement : dataElements) {
if (dataElement != null && dataElement.getOptionSet() != null) {
dataElementsWithOptionSet.add(dataElement);
}
}
indicators = indicatorService.getIndicatorsWithDataSets();
expressionService.substituteExpressions(indicators, null);
dataSets = dataSetService.getCurrentUserDataSets();
Set<DataElementCategoryCombo> categoryComboSet = new HashSet<>();
Set<DataElementCategory> categorySet = new HashSet<>();
for (DataSet dataSet : dataSets) {
if (dataSet.getCategoryCombo() != null) {
categoryComboSet.add(dataSet.getCategoryCombo());
}
}
for (DataElementCategoryCombo categoryCombo : categoryComboSet) {
if (categoryCombo.getCategories() != null) {
categorySet.addAll(categoryCombo.getCategories());
}
}
categoryCombos = new ArrayList<>(categoryComboSet);
categories = new ArrayList<>(categorySet);
for (DataElementCategory category : categories) {
List<DataElementCategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataElementCategoryOptions(category));
Collections.sort(categoryOptions);
categoryOptionMap.put(category.getUid(), categoryOptions);
}
Collections.sort(dataSets);
Collections.sort(categoryCombos);
Collections.sort(categories);
defaultCategoryCombo = categoryService.getDefaultDataElementCategoryCombo();
return SUCCESS;
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class RemoveMinMaxLimitsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
DataElement dataElement = dataElementService.getDataElement(dataElementId);
DataElementCategoryOptionCombo optionCombo = categoryService.getDataElementCategoryOptionCombo(categoryOptionComboId);
MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement(organisationUnit, dataElement, optionCombo);
if (minMaxDataElement != null) {
minMaxDataElementService.deleteMinMaxDataElement(minMaxDataElement);
}
return SUCCESS;
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class AnalyticsUtils method getDimensionMetadataItemMap.
/**
* Returns a mapping between identifiers and meta data items for the given query.
*
* @param params the data query parameters.
* @return a mapping between identifiers and meta data items.
*/
public static Map<String, MetadataItem> getDimensionMetadataItemMap(DataQueryParams params) {
List<DimensionalObject> dimensions = params.getDimensionsAndFilters();
Map<String, MetadataItem> map = new HashMap<>();
Calendar calendar = PeriodType.getCalendar();
for (DimensionalObject dimension : dimensions) {
for (DimensionalItemObject item : dimension.getItems()) {
if (DimensionType.PERIOD == dimension.getDimensionType() && !calendar.isIso8601()) {
Period period = (Period) item;
DateTimeUnit dateTimeUnit = calendar.fromIso(period.getStartDate());
map.put(period.getPeriodType().getIsoDate(dateTimeUnit), new MetadataItem(period.getDisplayName()));
} else {
String legendSet = item.hasLegendSet() ? item.getLegendSet().getUid() : null;
map.put(item.getDimensionItem(), new MetadataItem(item.getDisplayProperty(params.getDisplayProperty()), legendSet));
}
if (DimensionType.ORGANISATION_UNIT == dimension.getDimensionType() && params.isHierarchyMeta()) {
OrganisationUnit unit = (OrganisationUnit) item;
for (OrganisationUnit ancestor : unit.getAncestors()) {
map.put(ancestor.getUid(), new MetadataItem(ancestor.getDisplayProperty(params.getDisplayProperty())));
}
}
if (DimensionItemType.DATA_ELEMENT == item.getDimensionItemType()) {
DataElement dataElement = (DataElement) item;
for (DataElementCategoryOptionCombo coc : dataElement.getCategoryOptionCombos()) {
map.put(coc.getUid(), new MetadataItem(coc.getDisplayProperty(params.getDisplayProperty())));
}
}
}
map.put(dimension.getDimension(), new MetadataItem(dimension.getDisplayProperty(params.getDisplayProperty())));
}
return map;
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class ResourceTableServiceTest method setUpTest.
@Override
public void setUpTest() {
PeriodType pt = new MonthlyPeriodType();
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
idObjectManager.save(deA);
idObjectManager.save(deB);
DataElementGroup degA = createDataElementGroup('A');
DataElementGroup degB = createDataElementGroup('B');
degA.addDataElement(deA);
degB.addDataElement(deB);
idObjectManager.save(degA);
idObjectManager.save(degB);
DataElementGroupSet degsA = createDataElementGroupSet('A');
degsA.addDataElementGroup(degA);
degsA.addDataElementGroup(degB);
idObjectManager.save(degsA);
OrganisationUnit ouA = createOrganisationUnit('A');
OrganisationUnit ouB = createOrganisationUnit('B');
OrganisationUnit ouC = createOrganisationUnit('C');
ouB.setParent(ouA);
ouC.setParent(ouA);
ouA.getChildren().add(ouB);
ouA.getChildren().add(ouC);
idObjectManager.save(ouA);
idObjectManager.save(ouB);
idObjectManager.save(ouC);
DataSet dsA = createDataSet('A', pt);
DataSet dsB = createDataSet('B', pt);
dsA.addDataSetElement(deA);
dsB.addDataSetElement(deA);
dsA.addOrganisationUnit(ouA);
dsB.addOrganisationUnit(ouA);
dataSetService.addDataSet(dsA);
dataSetService.addDataSet(dsB);
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class DefaultPredictorService method predict.
// -------------------------------------------------------------------------
// Predictor run
// -------------------------------------------------------------------------
@Override
public int predict(Predictor predictor, Date startDate, Date endDate) {
log.info("Predicting for " + predictor.getName() + " from " + startDate.toString() + " to " + endDate.toString());
Expression generator = predictor.getGenerator();
Expression skipTest = predictor.getSampleSkipTest();
DataElement outputDataElement = predictor.getOutput();
Set<String> aggregates = expressionService.getAggregatesInExpression(generator.getExpression());
Map<String, Double> constantMap = constantService.getConstantMap();
List<Period> outputPeriods = getPeriodsBetweenDates(predictor.getPeriodType(), startDate, endDate);
ListMap<Period, Period> samplePeriodsMap = getSamplePeriodsMap(outputPeriods, predictor);
Set<Period> allSamplePeriods = samplePeriodsMap.uniqueValues();
Set<DataElementOperand> dataElementOperands = getDataElementOperands(aggregates, skipTest);
User currentUser = currentUserService.getCurrentUser();
DataElementCategoryOptionCombo outputOptionCombo = predictor.getOutputCombo() == null ? categoryService.getDefaultDataElementCategoryOptionCombo() : predictor.getOutputCombo();
List<OrganisationUnit> orgUnits = organisationUnitService.getOrganisationUnitsAtOrgUnitLevels(predictor.getOrganisationUnitLevels(), currentUser.getOrganisationUnits());
int predictionCount = 0;
for (OrganisationUnit orgUnit : orgUnits) {
MapMapMap<Period, String, DimensionalItemObject, Double> dataMap = dataElementOperands.isEmpty() ? null : dataValueService.getDataElementOperandValues(dataElementOperands, allSamplePeriods, orgUnit);
applySkipTest(dataMap, skipTest, constantMap);
for (Period period : outputPeriods) {
ListMapMap<String, String, Double> aggregateSampleMap = getAggregateSamples(dataMap, aggregates, samplePeriodsMap.get(period), constantMap);
for (String aoc : aggregateSampleMap.keySet()) {
ListMap<String, Double> aggregateValueMap = aggregateSampleMap.get(aoc);
Double value = expressionService.getExpressionValue(generator, new HashMap<>(), constantMap, null, period.getDaysInPeriod(), aggregateValueMap);
if (value != null && !value.isNaN() && !value.isInfinite()) {
writeDataValue(outputDataElement, period, orgUnit, outputOptionCombo, categoryService.getDataElementCategoryOptionCombo(aoc), value.toString(), currentUser.getUsername());
predictionCount++;
}
}
}
}
log.info("Generated " + predictionCount + " predictions for " + predictor.getName() + " from " + startDate.toString() + " to " + endDate.toString());
return predictionCount;
}
Aggregations