use of org.hisp.dhis.minmax.MinMaxDataElement 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.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class SaveMinMaxLimitsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
minLimit = minLimit != null ? minLimit : 0;
maxLimit = maxLimit != null ? maxLimit : 0;
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) {
minMaxDataElement = new MinMaxDataElement(organisationUnit, dataElement, optionCombo, minLimit, maxLimit, false);
minMaxDataElementService.addMinMaxDataElement(minMaxDataElement);
} else {
minMaxDataElement.setMin(minLimit);
minMaxDataElement.setMax(maxLimit);
minMaxDataElement.setGenerated(false);
minMaxDataElementService.updateMinMaxDataElement(minMaxDataElement);
}
return SUCCESS;
}
use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class MinMaxOutlierAnalysisService method generateMinMaxValues.
@Override
public void generateMinMaxValues(Collection<OrganisationUnit> parents, Collection<DataElement> dataElements, Double stdDevFactor) {
log.info("Starting min-max value generation, no of data elements: " + dataElements.size() + ", no of org units: " + parents.size());
//Set<Integer> orgUnitIds = new HashSet<>( IdentifiableObjectUtils.getIdentifiers( organisationUnits ) );
Date from = new DateTime(1, 1, 1, 1, 1).toDate();
minMaxDataElementService.removeMinMaxDataElements(dataElements, parents);
log.debug("Deleted existing min-max values");
BatchHandler<MinMaxDataElement> batchHandler = batchHandlerFactory.createBatchHandler(MinMaxDataElementBatchHandler.class).init();
for (DataElement dataElement : dataElements) {
ValueType valueType = dataElement.getValueType();
if (valueType.isNumeric()) {
Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryOptionCombos();
for (DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos) {
Map<Integer, Double> standardDeviations = dataAnalysisStore.getStandardDeviation(dataElement, categoryOptionCombo, parents, from);
Map<Integer, Double> averages = dataAnalysisStore.getAverage(dataElement, categoryOptionCombo, parents, from);
for (Integer unit : averages.keySet()) {
Double stdDev = standardDeviations.get(unit);
Double avg = averages.get(unit);
if (stdDev != null && avg != null) {
int min = (int) MathUtils.getLowBound(stdDev, stdDevFactor, avg);
int max = (int) MathUtils.getHighBound(stdDev, stdDevFactor, avg);
if (ValueType.INTEGER_POSITIVE == valueType || ValueType.INTEGER_ZERO_OR_POSITIVE == valueType) {
// Cannot be < 0
min = Math.max(0, min);
}
if (ValueType.INTEGER_NEGATIVE == valueType) {
// Cannot be > 0
max = Math.min(0, max);
}
OrganisationUnit source = new OrganisationUnit();
source.setId(unit);
batchHandler.addObject(new MinMaxDataElement(source, dataElement, categoryOptionCombo, min, max, true));
}
}
}
}
}
log.info("Min-max value generation done");
batchHandler.flush();
}
use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class DefaultHistoryRetriever method addMinMaxLimits.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void addMinMaxLimits(OrganisationUnit organisationUnit, DataElement dataElement, DataElementCategoryOptionCombo optionCombo, DataElementHistory history) {
MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement(organisationUnit, dataElement, optionCombo);
if (minMaxDataElement != null) {
history.setMaxLimit(minMaxDataElement.getMax());
history.setMinLimit(minMaxDataElement.getMin());
}
}
use of org.hisp.dhis.minmax.MinMaxDataElement in project dhis2-core by dhis2.
the class MinMaxDataElementController method deleteObject.
//--------------------------------------------------------------------------
// DELETE
//--------------------------------------------------------------------------
@RequestMapping(method = RequestMethod.DELETE, consumes = "application/json")
@PreAuthorize("hasRole('ALL') or hasRole('F_MINMAX_DATAELEMENT_DELETE')")
public void deleteObject(HttpServletRequest request, HttpServletResponse response) throws Exception {
MinMaxDataElement minMax = renderService.fromJson(request.getInputStream(), MinMaxDataElement.class);
validate(minMax);
minMax = getReferences(minMax);
MinMaxDataElement persisted = minMaxService.getMinMaxDataElement(minMax.getSource(), minMax.getDataElement(), minMax.getOptionCombo());
if (Objects.isNull(persisted)) {
throw new WebMessageException(WebMessageUtils.notFound("Can not find MinMaxDataElement."));
}
minMaxService.deleteMinMaxDataElement(persisted);
webMessageService.send(WebMessageUtils.ok("MinMaxDataElement deleted."), response, request);
}
Aggregations