=== added directory 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory' === added file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DataElementHistory.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DataElementHistory.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DataElementHistory.java 2013-12-21 19:02:27 +0000 @@ -0,0 +1,176 @@ +package org.hisp.dhis.dataelementhistory; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.organisationunit.OrganisationUnit; + +/** + * @author Torgeir Lorange Ostby + * @version $Id: DataElementHistory.java 4438 2008-01-26 16:35:24Z abyot $ + */ +public class DataElementHistory +{ + private DataElement dataElement; + + private DataElementCategoryOptionCombo optionCombo; + + private OrganisationUnit organisationUnit; + + private Integer minLimit; + + private Integer maxLimit; + + private int historyLength; + + /** + * Max value used to draw the history graph + */ + private double maxHistoryValue; + + /** + * The lowest entered value + */ + private double minValue; + + /** + * The highest entered value + */ + private double maxValue = Double.NEGATIVE_INFINITY; + + private List historyPoints = new ArrayList(); + + // ------------------------------------------------------------------------- + // Getters and setters + // ------------------------------------------------------------------------- + + public Integer getMaxLimit() + { + return maxLimit; + } + + public void setMaxLimit( Integer maxLimit ) + { + this.maxLimit = maxLimit; + } + + public OrganisationUnit getOrganisationUnit() + { + return organisationUnit; + } + + public void setOrganisationUnit( OrganisationUnit organisationUnit ) + { + this.organisationUnit = organisationUnit; + } + + public Integer getMinLimit() + { + return minLimit; + } + + public void setMinLimit( Integer minLimit ) + { + this.minLimit = minLimit; + } + + public DataElement getDataElement() + { + return dataElement; + } + + public void setDataElement( DataElement dataElement ) + { + this.dataElement = dataElement; + } + + public DataElementCategoryOptionCombo getOptionCombo() + { + return optionCombo; + } + + public void setOptionCombo( DataElementCategoryOptionCombo optionCombo ) + { + this.optionCombo = optionCombo; + } + + public int getHistoryLength() + { + return historyLength; + } + + public void setHistoryLength( int historyLength ) + { + this.historyLength = historyLength; + } + + public List getHistoryPoints() + { + return historyPoints; + } + + public void setHistoryPoints( List historyPoints ) + { + this.historyPoints = historyPoints; + } + + public double getMaxValue() + { + return maxValue; + } + + public void setMaxValue( double maxValue ) + { + this.maxValue = maxValue; + } + + public double getMinValue() + { + return minValue; + } + + public void setMinValue( double minValue ) + { + this.minValue = minValue; + } + + public double getMaxHistoryValue() + { + return maxHistoryValue; + } + + public void setMaxHistoryValue( double maxHistoryValue ) + { + this.maxHistoryValue = maxHistoryValue; + } +} === added file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DataElementHistoryPoint.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DataElementHistoryPoint.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DataElementHistoryPoint.java 2013-12-21 19:02:27 +0000 @@ -0,0 +1,78 @@ +package org.hisp.dhis.dataelementhistory; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.period.Period; + +/** + * @author Torgeir Lorange Ostby + * @version $Id: DataElementHistoryPoint.java 2869 2007-02-20 14:26:09Z andegje $ + */ +public class DataElementHistoryPoint +{ + private Period period; + + private Double value; + + private double average; + + // ------------------------------------------------------------------------- + // Getters and setters + // ------------------------------------------------------------------------- + + public double getAverage() + { + return average; + } + + public void setAverage( double average ) + { + this.average = average; + } + + public Period getPeriod() + { + return period; + } + + public void setPeriod( Period period ) + { + this.period = period; + } + + public Double getValue() + { + return value; + } + + public void setValue( Double value ) + { + this.value = value; + } +} === added file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DefaultHistoryRetriever.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DefaultHistoryRetriever.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/DefaultHistoryRetriever.java 2013-12-21 19:02:27 +0000 @@ -0,0 +1,253 @@ +package org.hisp.dhis.dataelementhistory; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.List; + +import org.apache.commons.math.util.MathUtils; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.minmax.MinMaxDataElement; +import org.hisp.dhis.minmax.MinMaxDataElementService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; +import org.hisp.dhis.period.PeriodService; + +/** + * @author Torgeir Lorange Ostby + */ +public class DefaultHistoryRetriever + implements HistoryRetriever +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private MinMaxDataElementService minMaxDataElementService; + + public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService ) + { + this.minMaxDataElementService = minMaxDataElementService; + } + + private DataValueService dataValueService; + + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + private PeriodService periodService; + + public void setPeriodService( PeriodService periodService ) + { + this.periodService = periodService; + } + + // ------------------------------------------------------------------------- + // HistoryRetriever implementation + // ------------------------------------------------------------------------- + + public DataElementHistory getHistory( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, + OrganisationUnit organisationUnit, Period lastPeriod, int historyLength ) + { + if ( !dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) ) + { + return null; // TODO + } + + // --------------------------------------------------------------------- + // Initialise history + // --------------------------------------------------------------------- + + DataElementHistory history = new DataElementHistory(); + history.setDataElement( dataElement ); + history.setOptionCombo( optionCombo ); + history.setOrganisationUnit( organisationUnit ); + history.setHistoryLength( historyLength ); + addMinMaxLimits( organisationUnit, dataElement, optionCombo, history ); + + // --------------------------------------------------------------------- + // Create history points + // --------------------------------------------------------------------- + + List periods = periodService.getPeriods( lastPeriod, historyLength ); + + double max = 1; + double average = 0; + double total = 0; + int count = 0; + + if ( history.getMaxLimit() != null ) + { + max = Math.max( max, history.getMaxLimit() ); + } + + for ( Period period : periods ) + { + DataElementHistoryPoint historyPoint = new DataElementHistoryPoint(); + historyPoint.setPeriod( period ); + + Double value = getValue( dataElement, optionCombo, organisationUnit, period ); + + if ( value != null ) + { + historyPoint.setValue( value ); + } + + if ( historyPoint.getValue() != null ) + { + max = Math.max( max, historyPoint.getValue() ); + total += historyPoint.getValue(); + average = total / ++count; + average = MathUtils.round( average, 1 ); + } + + historyPoint.setAverage( average ); + + history.getHistoryPoints().add( historyPoint ); + } + + history.setMaxHistoryValue( max ); + + double maxValue = getMaxValue( history ); + + if ( maxValue != Double.NEGATIVE_INFINITY ) + { + history.setMaxValue( maxValue ); + + double minValue = getMinValue( history ); + history.setMinValue( minValue ); + } + + return history; + } + + // ------------------------------------------------------------------------- + // 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() ); + } + } + + /** + * Finds the lowest value entered in the periode given by + * history.historyLenght. + * + * @param history DataElementHistory + * @return the lowest Double value entred. If no values are entred, + * Double.MAX_VALUE is returned + */ + private Double getMinValue( DataElementHistory history ) + { + double value = Double.MAX_VALUE; + List historyPoints = history.getHistoryPoints(); + + for ( DataElementHistoryPoint DEPoint : historyPoints ) + { + if ( DEPoint.getValue() != null ) + { + if ( DEPoint.getValue() < value ) + { + value = DEPoint.getValue(); + } + } + } + + return value; + } + + /** + * Finds the highest value entered in the periode given by + * history.historyLenght. + * + * @param history DataElementHistory + * @return the highest entred value. If no value is entred + * Double.NEGATIVE_INFINITY is returned + */ + private Double getMaxValue( DataElementHistory history ) + { + double value = Double.NEGATIVE_INFINITY; + List historyPoints = history.getHistoryPoints(); + + for ( DataElementHistoryPoint DEPoint : historyPoints ) + { + if ( DEPoint.getValue() != null ) + { + if ( DEPoint.getValue() > value ) + { + value = DEPoint.getValue(); + } + } + } + + return value; + } + + private Double getValue( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, + OrganisationUnit organisationUnit, Period period ) + { + DataValue dataValue = dataValueService.getDataValue( dataElement, period, organisationUnit, optionCombo ); + + if ( dataValue != null ) + { + if ( dataValue.getValue() != null ) + { + return parseValue( dataValue.getValue() ); + + } + } + + return null; + } + + private Double parseValue( String value ) + { + try + { + return Double.parseDouble( value ); + } + catch ( NumberFormatException e ) + { + throw new RuntimeException( "Failed to parse double: " + value, e ); + } + } +} === added file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/HistoryRetriever.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/HistoryRetriever.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dataelementhistory/HistoryRetriever.java 2013-12-21 19:02:27 +0000 @@ -0,0 +1,47 @@ +package org.hisp.dhis.dataelementhistory; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.period.Period; + +/** + * @author Torgeir Lorange Ostby + * @version $Id: HistoryRetriever.java 4438 2008-01-26 16:35:24Z abyot $ + */ +public interface HistoryRetriever +{ + String ID = HistoryRetriever.class.getName(); + + DataElementHistory getHistory( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, + OrganisationUnit organisationUnit, Period lastPeriod, int historyLength ); + +} === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2013-12-13 11:08:00 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2013-12-21 19:02:27 +0000 @@ -161,6 +161,14 @@ + + + + + + + + org.hisp.dhis dhis-service-core - - + org.hisp.dhis dhis-service-reporting === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java 2013-12-19 18:12:57 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java 2013-12-21 19:02:27 +0000 @@ -28,17 +28,19 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.opensymphony.xwork2.Action; +import java.util.Collection; +import java.util.List; + import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataelementhistory.DataElementHistory; +import org.hisp.dhis.dataelementhistory.HistoryRetriever; import org.hisp.dhis.datavalue.DataValue; import org.hisp.dhis.datavalue.DataValueAudit; import org.hisp.dhis.datavalue.DataValueAuditService; import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.de.history.DataElementHistory; -import org.hisp.dhis.de.history.HistoryRetriever; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.period.Period; @@ -46,8 +48,7 @@ import org.hisp.dhis.user.UserCredentials; import org.hisp.dhis.user.UserService; -import java.util.Collection; -import java.util.List; +import com.opensymphony.xwork2.Action; /** * @author Torgeir Lorange Ostby === removed directory 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history' === removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DataElementHistory.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DataElementHistory.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DataElementHistory.java 1970-01-01 00:00:00 +0000 @@ -1,176 +0,0 @@ -package org.hisp.dhis.de.history; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.ArrayList; -import java.util.List; - -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.organisationunit.OrganisationUnit; - -/** - * @author Torgeir Lorange Ostby - * @version $Id: DataElementHistory.java 4438 2008-01-26 16:35:24Z abyot $ - */ -public class DataElementHistory -{ - private DataElement dataElement; - - private DataElementCategoryOptionCombo optionCombo; - - private OrganisationUnit organisationUnit; - - private Integer minLimit; - - private Integer maxLimit; - - private int historyLength; - - /** - * Max value used to draw the history graph - */ - private double maxHistoryValue; - - /** - * The lowest entered value - */ - private double minValue; - - /** - * The highest entered value - */ - private double maxValue = Double.NEGATIVE_INFINITY; - - private List historyPoints = new ArrayList(); - - // ------------------------------------------------------------------------- - // Getters and setters - // ------------------------------------------------------------------------- - - public Integer getMaxLimit() - { - return maxLimit; - } - - public void setMaxLimit( Integer maxLimit ) - { - this.maxLimit = maxLimit; - } - - public OrganisationUnit getOrganisationUnit() - { - return organisationUnit; - } - - public void setOrganisationUnit( OrganisationUnit organisationUnit ) - { - this.organisationUnit = organisationUnit; - } - - public Integer getMinLimit() - { - return minLimit; - } - - public void setMinLimit( Integer minLimit ) - { - this.minLimit = minLimit; - } - - public DataElement getDataElement() - { - return dataElement; - } - - public void setDataElement( DataElement dataElement ) - { - this.dataElement = dataElement; - } - - public DataElementCategoryOptionCombo getOptionCombo() - { - return optionCombo; - } - - public void setOptionCombo( DataElementCategoryOptionCombo optionCombo ) - { - this.optionCombo = optionCombo; - } - - public int getHistoryLength() - { - return historyLength; - } - - public void setHistoryLength( int historyLength ) - { - this.historyLength = historyLength; - } - - public List getHistoryPoints() - { - return historyPoints; - } - - public void setHistoryPoints( List historyPoints ) - { - this.historyPoints = historyPoints; - } - - public double getMaxValue() - { - return maxValue; - } - - public void setMaxValue( double maxValue ) - { - this.maxValue = maxValue; - } - - public double getMinValue() - { - return minValue; - } - - public void setMinValue( double minValue ) - { - this.minValue = minValue; - } - - public double getMaxHistoryValue() - { - return maxHistoryValue; - } - - public void setMaxHistoryValue( double maxHistoryValue ) - { - this.maxHistoryValue = maxHistoryValue; - } -} === removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DataElementHistoryPoint.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DataElementHistoryPoint.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DataElementHistoryPoint.java 1970-01-01 00:00:00 +0000 @@ -1,78 +0,0 @@ -package org.hisp.dhis.de.history; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.hisp.dhis.period.Period; - -/** - * @author Torgeir Lorange Ostby - * @version $Id: DataElementHistoryPoint.java 2869 2007-02-20 14:26:09Z andegje $ - */ -public class DataElementHistoryPoint -{ - private Period period; - - private Double value; - - private double average; - - // ------------------------------------------------------------------------- - // Getters and setters - // ------------------------------------------------------------------------- - - public double getAverage() - { - return average; - } - - public void setAverage( double average ) - { - this.average = average; - } - - public Period getPeriod() - { - return period; - } - - public void setPeriod( Period period ) - { - this.period = period; - } - - public Double getValue() - { - return value; - } - - public void setValue( Double value ) - { - this.value = value; - } -} === removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DefaultHistoryRetriever.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DefaultHistoryRetriever.java 2013-12-19 18:12:57 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/DefaultHistoryRetriever.java 1970-01-01 00:00:00 +0000 @@ -1,255 +0,0 @@ -package org.hisp.dhis.de.history; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.List; - -import org.apache.commons.math.util.MathUtils; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.minmax.MinMaxDataElement; -import org.hisp.dhis.minmax.MinMaxDataElementService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.Period; -import org.hisp.dhis.period.PeriodService; - -/** - * @author Torgeir Lorange Ostby - * @version $Id: DefaultHistoryRetriever.java 5131 2008-05-11 21:06:23Z larshelg - * $ - */ -public class DefaultHistoryRetriever - implements HistoryRetriever -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private MinMaxDataElementService minMaxDataElementService; - - public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService ) - { - this.minMaxDataElementService = minMaxDataElementService; - } - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private PeriodService periodService; - - public void setPeriodService( PeriodService periodService ) - { - this.periodService = periodService; - } - - // ------------------------------------------------------------------------- - // HistoryRetriever implementation - // ------------------------------------------------------------------------- - - public DataElementHistory getHistory( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, - OrganisationUnit organisationUnit, Period lastPeriod, int historyLength ) - { - if ( !dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) ) - { - return null; // TODO - } - - // --------------------------------------------------------------------- - // Initialise history - // --------------------------------------------------------------------- - - DataElementHistory history = new DataElementHistory(); - history.setDataElement( dataElement ); - history.setOptionCombo( optionCombo ); - history.setOrganisationUnit( organisationUnit ); - history.setHistoryLength( historyLength ); - addMinMaxLimits( organisationUnit, dataElement, optionCombo, history ); - - // --------------------------------------------------------------------- - // Create history points - // --------------------------------------------------------------------- - - List periods = periodService.getPeriods( lastPeriod, historyLength ); - - double max = 1; - double average = 0; - double total = 0; - int count = 0; - - if ( history.getMaxLimit() != null ) - { - max = Math.max( max, history.getMaxLimit() ); - } - - for ( Period period : periods ) - { - DataElementHistoryPoint historyPoint = new DataElementHistoryPoint(); - historyPoint.setPeriod( period ); - - Double value = getValue( dataElement, optionCombo, organisationUnit, period ); - - if ( value != null ) - { - historyPoint.setValue( value ); - } - - if ( historyPoint.getValue() != null ) - { - max = Math.max( max, historyPoint.getValue() ); - total += historyPoint.getValue(); - average = total / ++count; - average = MathUtils.round( average, 1 ); - } - - historyPoint.setAverage( average ); - - history.getHistoryPoints().add( historyPoint ); - } - - history.setMaxHistoryValue( max ); - - double maxValue = getMaxValue( history ); - - if ( maxValue != Double.NEGATIVE_INFINITY ) - { - history.setMaxValue( maxValue ); - - double minValue = getMinValue( history ); - history.setMinValue( minValue ); - } - - return history; - } - - // ------------------------------------------------------------------------- - // 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() ); - } - } - - /** - * Finds the lowest value entered in the periode given by - * history.historyLenght. - * - * @param history DataElementHistory - * @return the lowest Double value entred. If no values are entred, - * Double.MAX_VALUE is returned - */ - private Double getMinValue( DataElementHistory history ) - { - double value = Double.MAX_VALUE; - List historyPoints = history.getHistoryPoints(); - - for ( DataElementHistoryPoint DEPoint : historyPoints ) - { - if ( DEPoint.getValue() != null ) - { - if ( DEPoint.getValue() < value ) - { - value = DEPoint.getValue(); - } - } - } - - return value; - } - - /** - * Finds the highest value entered in the periode given by - * history.historyLenght. - * - * @param history DataElementHistory - * @return the highest entred value. If no value is entred - * Double.NEGATIVE_INFINITY is returned - */ - private Double getMaxValue( DataElementHistory history ) - { - double value = Double.NEGATIVE_INFINITY; - List historyPoints = history.getHistoryPoints(); - - for ( DataElementHistoryPoint DEPoint : historyPoints ) - { - if ( DEPoint.getValue() != null ) - { - if ( DEPoint.getValue() > value ) - { - value = DEPoint.getValue(); - } - } - } - - return value; - } - - private Double getValue( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, - OrganisationUnit organisationUnit, Period period ) - { - DataValue dataValue = dataValueService.getDataValue( dataElement, period, organisationUnit, optionCombo ); - - if ( dataValue != null ) - { - if ( dataValue.getValue() != null ) - { - return parseValue( dataValue.getValue() ); - - } - } - - return null; - } - - private Double parseValue( String value ) - { - try - { - return Double.parseDouble( value ); - } - catch ( NumberFormatException e ) - { - throw new RuntimeException( "Failed to parse double: " + value, e ); - } - } -} === removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/HistoryRetriever.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/HistoryRetriever.java 2013-08-23 16:05:01 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/history/HistoryRetriever.java 1970-01-01 00:00:00 +0000 @@ -1,47 +0,0 @@ -package org.hisp.dhis.de.history; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.Period; - -/** - * @author Torgeir Lorange Ostby - * @version $Id: HistoryRetriever.java 4438 2008-01-26 16:35:24Z abyot $ - */ -public interface HistoryRetriever -{ - String ID = HistoryRetriever.class.getName(); - - DataElementHistory getHistory( DataElement dataElement, DataElementCategoryOptionCombo optionCombo, - OrganisationUnit organisationUnit, Period lastPeriod, int historyLength ); - -} === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2013-12-21 17:59:39 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2013-12-21 19:02:27 +0000 @@ -2,12 +2,6 @@ - - - - - - @@ -63,7 +57,7 @@ - + === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-12-21 18:46:53 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2013-12-21 19:02:27 +0000 @@ -70,8 +70,6 @@ // "organisationUnits" object inherited from ouwt.js -// TODO remove all usage of name="entryfield" etc and migrate to class="entryfield" etc - var COLOR_GREEN = '#b9ffb9'; var COLOR_YELLOW = '#fffe8c'; var COLOR_RED = '#ff8a8a';