Search in sources :

Example 1 with MinMaxDataElement

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 2 with MinMaxDataElement

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 3 with MinMaxDataElement

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();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ValueType(org.hisp.dhis.common.ValueType) Date(java.util.Date) DateTime(org.joda.time.DateTime) MinMaxDataElementBatchHandler(org.hisp.dhis.jdbc.batchhandler.MinMaxDataElementBatchHandler) DataElement(org.hisp.dhis.dataelement.DataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 4 with MinMaxDataElement

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());
    }
}
Also used : MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement)

Example 5 with MinMaxDataElement

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);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MinMaxDataElement(org.hisp.dhis.minmax.MinMaxDataElement) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MinMaxDataElement (org.hisp.dhis.minmax.MinMaxDataElement)10 DataElement (org.hisp.dhis.dataelement.DataElement)3 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 Period (org.hisp.dhis.period.Period)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 UnivariateFunction (org.apache.commons.math3.analysis.UnivariateFunction)1 SplineInterpolator (org.apache.commons.math3.analysis.interpolation.SplineInterpolator)1 UnivariateInterpolator (org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator)1 MathRuntimeException (org.apache.commons.math3.exception.MathRuntimeException)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 ValueType (org.hisp.dhis.common.ValueType)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 DeflatedDataValue (org.hisp.dhis.datavalue.DeflatedDataValue)1 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 MinMaxDataElementBatchHandler (org.hisp.dhis.jdbc.batchhandler.MinMaxDataElementBatchHandler)1