=== removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/FormAction.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/FormAction.java 2011-05-07 23:05:00 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/FormAction.java 1970-01-01 00:00:00 +0000 @@ -1,499 +0,0 @@ -package org.hisp.dhis.de.action; - -/* - * Copyright (c) 2004-2010, 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.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategory; -import org.hisp.dhis.dataelement.DataElementCategoryCombo; -import org.hisp.dhis.dataelement.DataElementCategoryOption; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.dataelement.comparator.DataElementSortOrderComparator; -import org.hisp.dhis.dataentryform.DataEntryForm; -import org.hisp.dhis.dataentryform.DataEntryFormService; -import org.hisp.dhis.datalock.DataSetLock; -import org.hisp.dhis.datalock.DataSetLockService; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.de.comments.StandardCommentsManager; -import org.hisp.dhis.de.state.SelectedStateManager; -import org.hisp.dhis.i18n.I18n; -import org.hisp.dhis.minmax.MinMaxDataElement; -import org.hisp.dhis.minmax.MinMaxDataElementService; -import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.period.Period; - -import com.opensymphony.xwork2.Action; - -/** - * @author Abyot Asalefew - * @version $Id$ - */ -public class FormAction - implements Action -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataElementService dataElementService; - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private StandardCommentsManager standardCommentsManager; - - public void setStandardCommentsManager( StandardCommentsManager standardCommentsManager ) - { - this.standardCommentsManager = standardCommentsManager; - } - - private MinMaxDataElementService minMaxDataElementService; - - public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService ) - { - this.minMaxDataElementService = minMaxDataElementService; - } - - private SelectedStateManager selectedStateManager; - - public void setSelectedStateManager( SelectedStateManager selectedStateManager ) - { - this.selectedStateManager = selectedStateManager; - } - - private DataEntryFormService dataEntryFormService; - - public void setDataEntryFormService( DataEntryFormService dataEntryFormService ) - { - this.dataEntryFormService = dataEntryFormService; - } - - private DataElementCategoryService categoryService; - - public void setCategoryService( DataElementCategoryService categoryService ) - { - this.categoryService = categoryService; - } - - private I18n i18n; - - public void setI18n( I18n i18n ) - { - this.i18n = i18n; - } - - private DataSetLockService dataSetLockService; - - public void setDataSetLockService( DataSetLockService dataSetLockService ) - { - this.dataSetLockService = dataSetLockService; - } - - // ------------------------------------------------------------------------- - // Comparator - // ------------------------------------------------------------------------- - - private Comparator dataElementComparator; - - public void setDataElementComparator( Comparator dataElementComparator ) - { - this.dataElementComparator = dataElementComparator; - } - - // ------------------------------------------------------------------------- - // DisplayPropertyHandler - // ------------------------------------------------------------------------- - - private DisplayPropertyHandler displayPropertyHandler; - - public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler ) - { - this.displayPropertyHandler = displayPropertyHandler; - } - - // ------------------------------------------------------------------------- - // Output - // ------------------------------------------------------------------------- - - private Map> orderedDataElements = new HashMap>(); - - public Map> getOrderedDataElements() - { - return orderedDataElements; - } - - private Map dataValueMap; - - public Map getDataValueMap() - { - return dataValueMap; - } - - private List standardComments; - - public List getStandardComments() - { - return standardComments; - } - - private Map dataElementValueTypeMap; - - public Map getDataElementValueTypeMap() - { - return dataElementValueTypeMap; - } - - private Map minMaxMap; - - public Map getMinMaxMap() - { - return minMaxMap; - } - - private Integer integer = 0; - - public Integer getInteger() - { - return integer; - } - - private Map>> orderedOptionsMap = new HashMap>>(); - - public Map>> getOrderedOptionsMap() - { - return orderedOptionsMap; - } - - private Map> orderedCategories = new HashMap>(); - - public Map> getOrderedCategories() - { - return orderedCategories; - } - - private Map numberOfTotalColumns = new HashMap(); - - public Map getNumberOfTotalColumns() - { - return numberOfTotalColumns; - } - - private Map>> catColRepeat = new HashMap>>(); - - public Map>> getCatColRepeat() - { - return catColRepeat; - } - - private Map> orderdCategoryOptionCombos = new HashMap>(); - - public Map> getOrderdCategoryOptionCombos() - { - return orderdCategoryOptionCombos; - } - - private Collection allOptionCombos = new ArrayList(); - - public Collection getAllOptionCombos() - { - return allOptionCombos; - } - - private List orderedCategoryCombos = new ArrayList(); - - public List getOrderedCategoryCombos() - { - return orderedCategoryCombos; - } - - private Boolean cdeFormExists; - - public Boolean getCdeFormExists() - { - return cdeFormExists; - } - - private DataEntryForm dataEntryForm; - - public DataEntryForm getDataEntryForm() - { - return this.dataEntryForm; - } - - private String customDataEntryFormCode; - - public String getCustomDataEntryFormCode() - { - return this.customDataEntryFormCode; - } - - // ------------------------------------------------------------------------- - // Input/output - // ------------------------------------------------------------------------- - - private Integer selectedDataSetId; - - public void setSelectedDataSetId( Integer selectedDataSetId ) - { - this.selectedDataSetId = selectedDataSetId; - } - - public Integer getSelectedDataSetId() - { - return selectedDataSetId; - } - - private Integer selectedPeriodIndex; - - public void setSelectedPeriodIndex( Integer selectedPeriodIndex ) - { - this.selectedPeriodIndex = selectedPeriodIndex; - } - - public Integer getSelectedPeriodIndex() - { - return selectedPeriodIndex; - } - - private String disabled = " "; - - private String displayMode; - - public String getDisplayMode() - { - return displayMode; - } - - public void setDisplayMode( String displayMode ) - { - this.displayMode = displayMode; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit(); - - DataSet dataSet = selectedStateManager.getSelectedDataSet(); - - Period period = selectedStateManager.getSelectedPeriod(); - - DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( dataSet, period ); - - if ( dataSetLock != null && dataSetLock.getSources().contains( organisationUnit ) ) - { - disabled = "disabled"; - } - - List dataElements = new ArrayList( dataSet.getDataElements() ); - - if ( dataElements.isEmpty() ) - { - return SUCCESS; - } - - Collections.sort( dataElements, dataElementComparator ); - - orderedDataElements = dataElementService.getGroupedDataElementsByCategoryCombo( dataElements ); - - orderedCategoryCombos = dataElementService.getDataElementCategoryCombos( dataElements ); - - for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos ) - { - Collection optionCombos = categoryService.sortOptionCombos( categoryCombo ); - - allOptionCombos.addAll( optionCombos ); - - orderdCategoryOptionCombos.put( categoryCombo.getId(), optionCombos ); - - // ----------------------------------------------------------------- - // Perform ordering of categories and their options so that they - // could be displayed as in the paper form. Note that the total - // number of entry cells to be generated are the multiple of options - // from each category. - // ----------------------------------------------------------------- - - numberOfTotalColumns.put( categoryCombo.getId(), optionCombos.size() ); - - orderedCategories.put( categoryCombo.getId(), categoryCombo.getCategories() ); - - Map> optionsMap = new HashMap>(); - - for ( DataElementCategory dec : categoryCombo.getCategories() ) - { - optionsMap.put( dec.getId(), dec.getCategoryOptions() ); - } - - orderedOptionsMap.put( categoryCombo.getId(), optionsMap ); - - // ----------------------------------------------------------------- - // Calculating the number of times each category should be repeated - // ----------------------------------------------------------------- - - Map catRepeat = new HashMap(); - - Map> colRepeat = new HashMap>(); - - int catColSpan = optionCombos.size(); - - for ( DataElementCategory cat : categoryCombo.getCategories() ) - { - int categoryOptionSize = cat.getCategoryOptions().size(); - - if ( catColSpan > 0 && categoryOptionSize > 0 ) - { - catColSpan = catColSpan / categoryOptionSize; - int total = optionCombos.size() / ( catColSpan * categoryOptionSize ); - Collection cols = new ArrayList( total ); - - for ( int i = 0; i < total; i++ ) - { - cols.add( i ); - } - - /* - * TODO Cols are made to be a collection simply to - * facilitate a for loop in the velocity template - there - * should be a better way of "for" doing a loop. - */ - - colRepeat.put( cat.getId(), cols ); - - catRepeat.put( cat.getId(), catColSpan ); - } - } - - catColRepeat.put( categoryCombo.getId(), colRepeat ); - } - - // --------------------------------------------------------------------- - // Get the min/max values - // --------------------------------------------------------------------- - - Collection minMaxDataElements = minMaxDataElementService.getMinMaxDataElements( - organisationUnit, dataElements ); - - minMaxMap = new HashMap( minMaxDataElements.size() ); - - for ( MinMaxDataElement minMaxDataElement : minMaxDataElements ) - { - minMaxMap.put( minMaxDataElement.getDataElement().getId() + ":" - + minMaxDataElement.getOptionCombo().getId(), minMaxDataElement ); - } - - // --------------------------------------------------------------------- - // Get the DataValues and create a map - // --------------------------------------------------------------------- - - Collection dataValues = dataValueService.getDataValues( organisationUnit, period, dataElements, - allOptionCombos ); - - dataValueMap = new HashMap( dataValues.size() ); - - for ( DataValue dataValue : dataValues ) - { - Integer deId = dataValue.getDataElement().getId(); - Integer ocId = dataValue.getOptionCombo().getId(); - - dataValueMap.put( deId.toString() + ':' + ocId.toString(), dataValue ); - } - - // --------------------------------------------------------------------- - // Make the standard comments available - // --------------------------------------------------------------------- - - standardComments = standardCommentsManager.getStandardComments(); - - // --------------------------------------------------------------------- - // Make the DataElement types available - // --------------------------------------------------------------------- - - dataElementValueTypeMap = new HashMap(); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_DATE, i18n.getString( "date" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_BOOL, i18n.getString( "yes_no" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_INT, i18n.getString( "number" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_STRING, i18n.getString( "text" ) ); - - // --------------------------------------------------------------------- - // Get the custom data entry form (if any) - // --------------------------------------------------------------------- - - dataEntryForm = dataSet.getDataEntryForm(); - - cdeFormExists = (dataEntryForm != null); - - if ( cdeFormExists ) - { - customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry( - dataEntryForm.getHtmlCode(), dataValues, minMaxMap, disabled, i18n, dataSet ); - } - - // --------------------------------------------------------------------- - // Working on the display of dataelements - // --------------------------------------------------------------------- - - List des = new ArrayList(); - - for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos ) - { - des = (List) orderedDataElements.get( categoryCombo ); - - displayPropertyHandler.handle( des ); - Collections.sort( des, new DataElementSortOrderComparator() ); - - orderedDataElements.put( categoryCombo, des ); - } - - return SUCCESS; - } -} === removed file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SectionFormAction.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SectionFormAction.java 2011-05-07 13:38:00 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SectionFormAction.java 1970-01-01 00:00:00 +0000 @@ -1,451 +0,0 @@ -package org.hisp.dhis.de.action; - -/* - * Copyright (c) 2004-2010, 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.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategory; -import org.hisp.dhis.dataelement.DataElementCategoryCombo; -import org.hisp.dhis.dataelement.DataElementCategoryOption; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementOperand; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.dataset.Section; -import org.hisp.dhis.dataset.comparator.SectionOrderComparator; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; -import org.hisp.dhis.de.comments.StandardCommentsManager; -import org.hisp.dhis.de.state.SelectedStateManager; -import org.hisp.dhis.i18n.I18n; -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 com.opensymphony.xwork2.Action; - -/** - * @author Tri - * @version $Id: FormAction.java 4089 2007-11-24 13:30:44Z larshelg $ - */ -public class SectionFormAction - implements Action -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataValueService dataValueService; - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - - private StandardCommentsManager standardCommentsManager; - - public void setStandardCommentsManager( StandardCommentsManager standardCommentsManager ) - { - this.standardCommentsManager = standardCommentsManager; - } - - private MinMaxDataElementService minMaxDataElementService; - - public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService ) - { - this.minMaxDataElementService = minMaxDataElementService; - } - - private SelectedStateManager selectedStateManager; - - public void setSelectedStateManager( SelectedStateManager selectedStateManager ) - { - this.selectedStateManager = selectedStateManager; - } - - private DataElementCategoryService categoryService; - - public void setCategoryService( DataElementCategoryService categoryService ) - { - this.categoryService = categoryService; - } - - private I18n i18n; - - public void setI18n( I18n i18n ) - { - this.i18n = i18n; - } - - // ------------------------------------------------------------------------- - // Input/output - // ------------------------------------------------------------------------- - - private List
sections; - - public List
getSections() - { - return sections; - } - - private Map dataValueMap; - - public Map getDataValueMap() - { - return dataValueMap; - } - - private List standardComments; - - public List getStandardComments() - { - return standardComments; - } - - private Map dataElementValueTypeMap; - - public Map getDataElementValueTypeMap() - { - return dataElementValueTypeMap; - } - - private Map minMaxMap; - - public Map getMinMaxMap() - { - return minMaxMap; - } - - private Integer integer = 0; - - public Integer getInteger() - { - return integer; - } - - private Integer selectedDataSetId; - - public void setSelectedDataSetId( Integer selectedDataSetId ) - { - this.selectedDataSetId = selectedDataSetId; - } - - public Integer getSelectedDataSetId() - { - return selectedDataSetId; - } - - private Integer selectedPeriodIndex; - - public void setSelectedPeriodIndex( Integer selectedPeriodIndex ) - { - this.selectedPeriodIndex = selectedPeriodIndex; - } - - public Integer getSelectedPeriodIndex() - { - return selectedPeriodIndex; - } - - private Map>> orderedOptionsMap = new HashMap>>(); - - public Map>> getOrderedOptionsMap() - { - return orderedOptionsMap; - } - - private Map> orderedCategories = new HashMap>(); - - public Map> getOrderedCategories() - { - return orderedCategories; - } - - private Map numberOfTotalColumns = new HashMap(); - - public Map getNumberOfTotalColumns() - { - return numberOfTotalColumns; - } - - private Map>> catColRepeat = new HashMap>>(); - - public Map>> getCatColRepeat() - { - return catColRepeat; - } - - private Map> orderdCategoryOptionCombos = new HashMap>(); - - public Map> getOrderdCategoryOptionCombos() - { - return orderdCategoryOptionCombos; - } - - private List allOptionCombos = new ArrayList(); - - public List getAllOptionCombos() - { - return allOptionCombos; - } - - private List orderedCategoryCombos = new ArrayList(); - - public List getOrderedCategoryCombos() - { - return orderedCategoryCombos; - } - - private Map sectionIsMultiDimensional = new HashMap(); - - public Map getSectionIsMultiDimensional() - { - return sectionIsMultiDimensional; - } - - private Map sectionCombos = new HashMap(); - - public Map getSectionCombos() - { - return sectionCombos; - } - - private Map greyedFields = new HashMap(); - - public Map getGreyedFields() - { - return greyedFields; - } - - private String displayMode; - - public String getDisplayMode() - { - return displayMode; - } - - public void setDisplayMode( String displayMode ) - { - this.displayMode = displayMode; - } - - private Integer defaultOptionComboId; - - public Integer getDefaultOptionComboId() - { - return defaultOptionComboId; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - public String execute() - throws Exception - { - OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit(); - - DataSet dataSet = selectedStateManager.getSelectedDataSet(); - - Period period = selectedStateManager.getSelectedPeriod(); - - Collection dataElements = new ArrayList(); - - dataElements = dataSet.getDataElements(); - - if ( dataElements.size() == 0 ) - { - return SUCCESS; - } - - // --------------------------------------------------------------------- - // Get the min/max values - // --------------------------------------------------------------------- - - Collection minMaxDataElements = minMaxDataElementService.getMinMaxDataElements( - organisationUnit, dataElements ); - - minMaxMap = new HashMap( minMaxDataElements.size() ); - - for ( MinMaxDataElement minMaxDataElement : minMaxDataElements ) - { - minMaxMap.put( minMaxDataElement.getDataElement().getId() + ":" - + minMaxDataElement.getOptionCombo().getId(), minMaxDataElement ); - } - - // --------------------------------------------------------------------- - // Order the Sections - // --------------------------------------------------------------------- - - sections = new ArrayList
( dataSet.getSections() ); - - Collections.sort( sections, new SectionOrderComparator() ); - - // --------------------------------------------------------------------- - // Get the category combos for the sections - // --------------------------------------------------------------------- - - for ( Section section : sections ) - { - DataElementCategoryCombo sectionCategoryCombo = section.getCategoryCombo(); - - if ( sectionCategoryCombo != null ) - { - orderedCategoryCombos.add( sectionCategoryCombo ); - - sectionCombos.put( section.getId(), sectionCategoryCombo.getId() ); - } - - if ( section.hasMultiDimensionalDataElement() ) - { - sectionIsMultiDimensional.put( section.getId(), true ); - } - - for ( DataElementOperand operand : section.getGreyedFields() ) - { - greyedFields.put( operand.getDataElement().getId() + ":" + operand.getCategoryOptionCombo().getId(), - true ); - } - } - - defaultOptionComboId = categoryService.getDefaultDataElementCategoryOptionCombo().getId(); - - for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos ) - { - List optionCombos = categoryService.sortOptionCombos( categoryCombo ); - - allOptionCombos.addAll( optionCombos ); - - orderdCategoryOptionCombos.put( categoryCombo.getId(), optionCombos ); - - // ----------------------------------------------------------------- - // Perform ordering of categories and their options so that they - // could be displayed as in the paper form. Note that the total - // number of entry cells to be generated are the multiple of options - // from each category. - // ----------------------------------------------------------------- - - numberOfTotalColumns.put( categoryCombo.getId(), optionCombos.size() ); - - orderedCategories.put( categoryCombo.getId(), categoryCombo.getCategories() ); - - Map> optionsMap = new HashMap>(); - - for ( DataElementCategory dec : categoryCombo.getCategories() ) - { - optionsMap.put( dec.getId(), dec.getCategoryOptions() ); - } - - orderedOptionsMap.put( categoryCombo.getId(), optionsMap ); - - // ----------------------------------------------------------------- - // Calculating the number of times each category should be repeated - // ----------------------------------------------------------------- - - Map catRepeat = new HashMap(); - - Map> colRepeat = new HashMap>(); - - int catColSpan = optionCombos.size(); - - for ( DataElementCategory cat : categoryCombo.getCategories() ) - { - int categoryOptionSize = cat.getCategoryOptions().size(); - - if ( catColSpan > 0 && categoryOptionSize > 0 ) - { - catColSpan = catColSpan / categoryOptionSize; - int total = optionCombos.size() / ( catColSpan * categoryOptionSize ); - Collection cols = new ArrayList( total ); - - for ( int i = 0; i < total; i++ ) - { - cols.add( i ); - } - - /* - * TODO Cols are made to be a collection simply to - * facilitate a for loop in the velocity template - there - * should be a better way of "for" doing a loop. - */ - - colRepeat.put( cat.getId(), cols ); - - catRepeat.put( cat.getId(), catColSpan ); - } - } - - catColRepeat.put( categoryCombo.getId(), colRepeat ); - } - - // --------------------------------------------------------------------- - // Get the DataValues and create a map - // --------------------------------------------------------------------- - - Collection dataValues = dataValueService.getDataValues( organisationUnit, period, dataElements, - allOptionCombos ); - - dataValueMap = new HashMap( dataValues.size() ); - - for ( DataValue dataValue : dataValues ) - { - Integer deId = dataValue.getDataElement().getId(); - Integer ocId = dataValue.getOptionCombo().getId(); - - dataValueMap.put( deId.toString() + ':' + ocId.toString(), dataValue ); - } - - // --------------------------------------------------------------------- - // Make the standard comments available - // --------------------------------------------------------------------- - - standardComments = standardCommentsManager.getStandardComments(); - - // --------------------------------------------------------------------- - // Make the DataElement types available - // --------------------------------------------------------------------- - - dataElementValueTypeMap = new HashMap(); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_BOOL, i18n.getString( "yes_no" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_INT, i18n.getString( "int" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_NUMBER, i18n.getString( "number" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_POSITIVE_NUMBER, i18n.getString( "positiveNumber" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_NEGATIVE_NUMBER, i18n.getString( "negativeNumber" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_STRING, i18n.getString( "text" ) ); - dataElementValueTypeMap.put( DataElement.VALUE_TYPE_DATE, i18n.getString( "date" ) ); - - return SUCCESS; - } -} === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java 2011-05-05 21:15:45 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java 2011-05-31 07:54:15 +0000 @@ -27,16 +27,43 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategory; +import org.hisp.dhis.dataelement.DataElementCategoryCombo; +import org.hisp.dhis.dataelement.DataElementCategoryOption; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.DataElementCategoryService; +import org.hisp.dhis.dataelement.DataElementOperand; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.dataelement.comparator.DataElementSortOrderComparator; +import org.hisp.dhis.dataentryform.DataEntryForm; +import org.hisp.dhis.dataentryform.DataEntryFormService; import org.hisp.dhis.datalock.DataSetLock; import org.hisp.dhis.datalock.DataSetLockService; import org.hisp.dhis.dataset.CompleteDataSetRegistration; import org.hisp.dhis.dataset.CompleteDataSetRegistrationService; import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.Section; +import org.hisp.dhis.dataset.comparator.SectionOrderComparator; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.de.comments.StandardCommentsManager; import org.hisp.dhis.de.state.SelectedStateManager; +import org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.minmax.MinMaxDataElement; +import org.hisp.dhis.minmax.MinMaxDataElementService; +import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; @@ -51,10 +78,26 @@ { private static final Log log = LogFactory.getLog( SelectAction.class ); + private static final String SECTION_FORM = "sectionform"; + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- + private DataEntryFormService dataEntryFormService; + + public void setDataEntryFormService( DataEntryFormService dataEntryFormService ) + { + this.dataEntryFormService = dataEntryFormService; + } + + private DataElementService dataElementService; + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + private DataSetLockService dataSetLockService; public void setDataSetLockService( DataSetLockService dataSetLockService ) @@ -76,6 +119,93 @@ this.registrationService = registrationService; } + private DataValueService dataValueService; + + public void setDataValueService( DataValueService dataValueService ) + { + this.dataValueService = dataValueService; + } + + private StandardCommentsManager standardCommentsManager; + + public void setStandardCommentsManager( StandardCommentsManager standardCommentsManager ) + { + this.standardCommentsManager = standardCommentsManager; + } + + private MinMaxDataElementService minMaxDataElementService; + + public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService ) + { + this.minMaxDataElementService = minMaxDataElementService; + } + + private DataElementCategoryService categoryService; + + public void setCategoryService( DataElementCategoryService categoryService ) + { + this.categoryService = categoryService; + } + + private I18n i18n; + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + // ------------------------------------------------------------------------- + // Comparator + // ------------------------------------------------------------------------- + + private Comparator dataElementComparator; + + public void setDataElementComparator( Comparator dataElementComparator ) + { + this.dataElementComparator = dataElementComparator; + } + + // ------------------------------------------------------------------------- + // DisplayPropertyHandler + // ------------------------------------------------------------------------- + + private DisplayPropertyHandler displayPropertyHandler; + + public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler ) + { + this.displayPropertyHandler = displayPropertyHandler; + } + + private Map> orderedDataElements = new HashMap>(); + + public Map> getOrderedDataElements() + { + return orderedDataElements; + } + + private Boolean cdeFormExists; + + public Boolean getCdeFormExists() + { + return cdeFormExists; + } + + private String disabled = " "; + + private DataEntryForm dataEntryForm; + + public DataEntryForm getDataEntryForm() + { + return this.dataEntryForm; + } + + private String customDataEntryFormCode; + + public String getCustomDataEntryFormCode() + { + return this.customDataEntryFormCode; + } + // ------------------------------------------------------------------------- // Input // ------------------------------------------------------------------------- @@ -87,13 +217,6 @@ this.displayMode = displayMode; } - private Integer selectedPeriodIndex; - - public void setSelectedPeriodIndex( Integer selectedPeriodIndex ) - { - this.selectedPeriodIndex = selectedPeriodIndex; - } - // ------------------------------------------------------------------------- // Output // ------------------------------------------------------------------------- @@ -133,6 +256,149 @@ return registrationDate; } + private List
sections; + + public List
getSections() + { + return sections; + } + + private Map dataValueMap; + + public Map getDataValueMap() + { + return dataValueMap; + } + + private List standardComments; + + public List getStandardComments() + { + return standardComments; + } + + private Map dataElementValueTypeMap; + + public Map getDataElementValueTypeMap() + { + return dataElementValueTypeMap; + } + + private Map minMaxMap; + + public Map getMinMaxMap() + { + return minMaxMap; + } + + private Integer integer = 0; + + public Integer getInteger() + { + return integer; + } + + private Integer selectedDataSetId; + + public void setSelectedDataSetId( Integer selectedDataSetId ) + { + this.selectedDataSetId = selectedDataSetId; + } + + public Integer getSelectedDataSetId() + { + return selectedDataSetId; + } + + private Integer selectedPeriodIndex; + + public void setSelectedPeriodIndex( Integer selectedPeriodIndex ) + { + this.selectedPeriodIndex = selectedPeriodIndex; + } + + public Integer getSelectedPeriodIndex() + { + return selectedPeriodIndex; + } + + private Map>> orderedOptionsMap = new HashMap>>(); + + public Map>> getOrderedOptionsMap() + { + return orderedOptionsMap; + } + + private Map> orderedCategories = new HashMap>(); + + public Map> getOrderedCategories() + { + return orderedCategories; + } + + private Map numberOfTotalColumns = new HashMap(); + + public Map getNumberOfTotalColumns() + { + return numberOfTotalColumns; + } + + private Map>> catColRepeat = new HashMap>>(); + + public Map>> getCatColRepeat() + { + return catColRepeat; + } + + private Map> orderdCategoryOptionCombos = new HashMap>(); + + public Map> getOrderdCategoryOptionCombos() + { + return orderdCategoryOptionCombos; + } + + private List allOptionCombos = new ArrayList(); + + public List getAllOptionCombos() + { + return allOptionCombos; + } + + private List orderedCategoryCombos = new ArrayList(); + + public List getOrderedCategoryCombos() + { + return orderedCategoryCombos; + } + + private Map sectionIsMultiDimensional = new HashMap(); + + public Map getSectionIsMultiDimensional() + { + return sectionIsMultiDimensional; + } + + private Map sectionCombos = new HashMap(); + + public Map getSectionCombos() + { + return sectionCombos; + } + + private Map greyedFields = new HashMap(); + + public Map getGreyedFields() + { + return greyedFields; + } + + private Integer defaultOptionComboId; + + public Integer getDefaultOptionComboId() + { + return defaultOptionComboId; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- @@ -141,9 +407,9 @@ throws Exception { organisationUnit = selectedStateManager.getSelectedOrganisationUnit(); - + DataSet selectedDataSet = selectedStateManager.getSelectedDataSet(); - + // --------------------------------------------------------------------- // Validate selected period // --------------------------------------------------------------------- @@ -156,14 +422,14 @@ if ( selectedPeriodIndex != null && selectedPeriodIndex >= 0 ) { selectedStateManager.setSelectedPeriodIndex( selectedPeriodIndex ); - + period = selectedStateManager.getSelectedPeriod(); } else { selectedStateManager.clearSelectedPeriod(); - return SUCCESS; + return INPUT; } // --------------------------------------------------------------------- @@ -179,18 +445,19 @@ if ( dataSetLock != null && dataSetLock.getSources().contains( organisationUnit ) ) { locked = true; - + log.info( "Dataset '" + selectedDataSet.getName() + "' is locked " ); } } - + // --------------------------------------------------------------------- // Get data set completeness info // --------------------------------------------------------------------- if ( selectedDataSet != null && period != null && organisationUnit != null ) { - registration = registrationService.getCompleteDataSetRegistration( selectedDataSet, period, organisationUnit ); + registration = registrationService.getCompleteDataSetRegistration( selectedDataSet, period, + organisationUnit ); registrationDate = registration != null ? registration.getDate() : new Date(); } @@ -203,14 +470,244 @@ { displayMode = selectedStateManager.getSelectedDisplayMode(); } - + if ( !selectedStateManager.displayModeIsValid( displayMode ) ) { displayMode = selectedStateManager.getDisplayMode(); } - + selectedStateManager.setSelectedDisplayMode( displayMode ); + + // --------------------------------------------------------------------- + // Get entry form + // --------------------------------------------------------------------- + + List dataElements = new ArrayList( selectedDataSet.getDataElements() ); + + if ( dataElements.isEmpty() ) + { + return INPUT; + } + Collections.sort( dataElements, dataElementComparator ); + + // --------------------------------------------------------------------- + // Get the min/max values + // --------------------------------------------------------------------- + + Collection minMaxDataElements = minMaxDataElementService.getMinMaxDataElements( + organisationUnit, dataElements ); + + minMaxMap = new HashMap( minMaxDataElements.size() ); + + for ( MinMaxDataElement minMaxDataElement : minMaxDataElements ) + { + minMaxMap.put( minMaxDataElement.getDataElement().getId() + ":" + + minMaxDataElement.getOptionCombo().getId(), minMaxDataElement ); + } + + // --------------------------------------------------------------------- + // Get the min/max values + // --------------------------------------------------------------------- + + orderedDataElements = dataElementService.getGroupedDataElementsByCategoryCombo( dataElements ); + + orderedCategoryCombos = dataElementService.getDataElementCategoryCombos( dataElements ); + + for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos ) + { + Collection optionCombos = categoryService.sortOptionCombos( categoryCombo ); + + allOptionCombos.addAll( optionCombos ); + + orderdCategoryOptionCombos.put( categoryCombo.getId(), optionCombos ); + + // ----------------------------------------------------------------- + // Perform ordering of categories and their options so that they + // could be displayed as in the paper form. Note that the total + // number of entry cells to be generated are the multiple of options + // from each category. + // ----------------------------------------------------------------- + + numberOfTotalColumns.put( categoryCombo.getId(), optionCombos.size() ); + + orderedCategories.put( categoryCombo.getId(), categoryCombo.getCategories() ); + + Map> optionsMap = new HashMap>(); + + for ( DataElementCategory dec : categoryCombo.getCategories() ) + { + optionsMap.put( dec.getId(), dec.getCategoryOptions() ); + } + + orderedOptionsMap.put( categoryCombo.getId(), optionsMap ); + + // ----------------------------------------------------------------- + // Calculating the number of times each category should be repeated + // ----------------------------------------------------------------- + + Map catRepeat = new HashMap(); + + Map> colRepeat = new HashMap>(); + + int catColSpan = optionCombos.size(); + + for ( DataElementCategory cat : categoryCombo.getCategories() ) + { + int categoryOptionSize = cat.getCategoryOptions().size(); + + if ( catColSpan > 0 && categoryOptionSize > 0 ) + { + catColSpan = catColSpan / categoryOptionSize; + int total = optionCombos.size() / (catColSpan * categoryOptionSize); + Collection cols = new ArrayList( total ); + + for ( int i = 0; i < total; i++ ) + { + cols.add( i ); + } + + colRepeat.put( cat.getId(), cols ); + + catRepeat.put( cat.getId(), catColSpan ); + } + } + + catColRepeat.put( categoryCombo.getId(), colRepeat ); + } + + // --------------------------------------------------------------------- + // Get the DataValues and create a map + // --------------------------------------------------------------------- + + Collection dataValues = dataValueService.getDataValues( organisationUnit, period, dataElements, + allOptionCombos ); + + dataValueMap = new HashMap( dataValues.size() ); + + for ( DataValue dataValue : dataValues ) + { + Integer deId = dataValue.getDataElement().getId(); + Integer ocId = dataValue.getOptionCombo().getId(); + + dataValueMap.put( deId.toString() + ':' + ocId.toString(), dataValue ); + } + + // --------------------------------------------------------------------- + // Make the standard comments available + // --------------------------------------------------------------------- + + standardComments = standardCommentsManager.getStandardComments(); + + // --------------------------------------------------------------------- + // Make the DataElement types available + // --------------------------------------------------------------------- + + dataElementValueTypeMap = new HashMap(); + dataElementValueTypeMap.put( DataElement.VALUE_TYPE_DATE, i18n.getString( "date" ) ); + dataElementValueTypeMap.put( DataElement.VALUE_TYPE_BOOL, i18n.getString( "yes_no" ) ); + dataElementValueTypeMap.put( DataElement.VALUE_TYPE_INT, i18n.getString( "number" ) ); + dataElementValueTypeMap.put( DataElement.VALUE_TYPE_STRING, i18n.getString( "text" ) ); + + // --------------------------------------------------------------------- + // Get data entry form + // --------------------------------------------------------------------- + + if( displayMode.equals( SECTION_FORM ) ) + { + getSectionForm( dataElements, selectedDataSet ); + } + else + { + getOtherDataEntryForm( dataElements, selectedDataSet, dataValues ); + } + return displayMode; } + + // ------------------------------------------------------------------------- + // Supportive methods + // ------------------------------------------------------------------------- + + private void getSectionForm( Collection dataElements, DataSet dataSet ) + { + // --------------------------------------------------------------------- + // Order the Sections + // --------------------------------------------------------------------- + + sections = new ArrayList
( dataSet.getSections() ); + + Collections.sort( sections, new SectionOrderComparator() ); + + // --------------------------------------------------------------------- + // Get the category combos for the sections + // --------------------------------------------------------------------- + + for ( Section section : sections ) + { + DataElementCategoryCombo sectionCategoryCombo = section.getCategoryCombo(); + + if ( sectionCategoryCombo != null ) + { + orderedCategoryCombos.add( sectionCategoryCombo ); + + sectionCombos.put( section.getId(), sectionCategoryCombo.getId() ); + } + + if ( section.hasMultiDimensionalDataElement() ) + { + sectionIsMultiDimensional.put( section.getId(), true ); + } + + for ( DataElementOperand operand : section.getGreyedFields() ) + { + greyedFields.put( operand.getDataElement().getId() + ":" + operand.getCategoryOptionCombo().getId(), + true ); + } + } + + defaultOptionComboId = categoryService.getDefaultDataElementCategoryOptionCombo().getId(); + + } + + private void getOtherDataEntryForm( List dataElements, DataSet dataSet, + Collection dataValues ) + { + DataSetLock dataSetLock = dataSetLockService.getDataSetLockByDataSetAndPeriod( dataSet, period ); + + if ( dataSetLock != null && dataSetLock.getSources().contains( organisationUnit ) ) + { + disabled = "disabled"; + } + + // --------------------------------------------------------------------- + // Get the custom data entry form (if any) + // --------------------------------------------------------------------- + + dataEntryForm = dataSet.getDataEntryForm(); + + cdeFormExists = (dataEntryForm != null); + + if ( cdeFormExists ) + { + customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry( dataEntryForm.getHtmlCode(), + dataValues, minMaxMap, disabled, i18n, dataSet ); + } + + // --------------------------------------------------------------------- + // Working on the display of dataelements + // --------------------------------------------------------------------- + + List des = new ArrayList(); + + for ( DataElementCategoryCombo categoryCombo : orderedCategoryCombos ) + { + des = (List) orderedDataElements.get( categoryCombo ); + + displayPropertyHandler.handle( des ); + Collections.sort( des, new DataElementSortOrderComparator() ); + + orderedDataElements.put( categoryCombo, des ); + } + } } === 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 2011-05-10 08:58:10 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2011-05-31 07:54:15 +0000 @@ -49,30 +49,17 @@ - - - - - - - - - + + + + + - - - - - - - - - === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2011-05-08 19:22:16 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/struts.xml 2011-05-31 07:54:15 +0000 @@ -40,22 +40,10 @@ - customform - sectionform - defaultform - /dhis-web-dataentry/responseVoid.vm - - - - /dhis-web-dataentry/customForm.vm - - - - /dhis-web-dataentry/sectionForm.vm - - - - /dhis-web-dataentry/defaultForm.vm + /dhis-web-dataentry/customForm.vm + /dhis-web-dataentry/sectionForm.vm + /dhis-web-dataentry/defaultForm.vm + /dhis-web-dataentry/responseVoid.vm