=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java 2013-12-19 23:00:15 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java 2013-12-21 17:59:39 +0000 @@ -206,6 +206,21 @@ Collection getDataValues( OrganisationUnit source, Period period, Collection dataElements ); /** + * Returns all DataValues for a given Source, Period, collection of + * DataElements and DataElementCategoryOptionCombo. + * + * @param source the Source of the DataValues. + * @param period the Period of the DataValues. + * @param dataElements the DataElements of the DataValues. + * @param attributeOptionCombo the DataElementCategoryCombo. + * @return a collection of all DataValues which match the given Source, + * Period, and any of the DataElements, or an empty collection if no + * values match. + */ + Collection getDataValues( OrganisationUnit source, Period period, + Collection dataElements, DataElementCategoryOptionCombo attributeOptionCombo ); + + /** * Returns all DataValues for a given DataElement, Period, and collection of * Sources. * === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java 2013-12-19 18:12:57 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java 2013-12-21 17:59:39 +0000 @@ -170,6 +170,21 @@ * values match. */ Collection getDataValues( OrganisationUnit source, Period period, Collection dataElements ); + + /** + * Returns all DataValues for a given Source, Period, collection of + * DataElements and DataElementCategoryOptionCombo. + * + * @param source the Source of the DataValues. + * @param period the Period of the DataValues. + * @param dataElements the DataElements of the DataValues. + * @param attributeOptionCombo the DataElementCategoryCombo. + * @return a collection of all DataValues which match the given Source, + * Period, and any of the DataElements, or an empty collection if no + * values match. + */ + Collection getDataValues( OrganisationUnit source, Period period, + Collection dataElements, DataElementCategoryOptionCombo attributeOptionCombo ); /** * Returns all DataValues for a given Source, Period, collection of === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2013-12-19 23:00:15 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java 2013-12-21 17:59:39 +0000 @@ -170,6 +170,12 @@ return dataValueStore.getDataValues( source, period, dataElements ); } + public Collection getDataValues( OrganisationUnit source, Period period, + Collection dataElements, DataElementCategoryOptionCombo attributeOptionCombo ) + { + return dataValueStore.getDataValues( source, period, dataElements, attributeOptionCombo ); + } + public Collection getDataValues( OrganisationUnit source, Period period, Collection dataElements, Collection optionCombos ) { === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java 2013-12-19 18:12:57 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueStore.java 2013-12-21 17:59:39 +0000 @@ -273,6 +273,28 @@ } @SuppressWarnings( "unchecked" ) + public Collection getDataValues( OrganisationUnit source, Period period, + Collection dataElements, DataElementCategoryOptionCombo attributeOptionCombo ) + { + Period storedPeriod = periodStore.reloadPeriod( period ); + + if ( storedPeriod == null || dataElements == null || dataElements.isEmpty() ) + { + return Collections.emptySet(); + } + + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( DataValue.class ); + criteria.add( Restrictions.eq( "source", source ) ); + criteria.add( Restrictions.eq( "period", storedPeriod ) ); + criteria.add( Restrictions.in( "dataElement", dataElements ) ); + criteria.add( Restrictions.eq( "attributeOptionCombo", attributeOptionCombo ) ); + + return criteria.list(); + } + + @SuppressWarnings( "unchecked" ) public Collection getDataValues( OrganisationUnit source, Period period, Collection dataElements, Collection categoryOptionCombos ) { === modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java 2013-12-21 17:07:21 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetDataValuesForDataSetAction.java 2013-12-21 17:59:39 +0000 @@ -32,6 +32,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +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.dataset.CompleteDataSetRegistration; import org.hisp.dhis.dataset.CompleteDataSetRegistrationService; import org.hisp.dhis.dataset.DataSet; @@ -48,6 +52,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.HashSet; import java.util.Set; /** @@ -96,6 +101,13 @@ { this.organisationUnitService = organisationUnitService; } + + private DataElementCategoryService categoryService; + + public void setCategoryService( DataElementCategoryService categoryService ) + { + this.categoryService = categoryService; + } // ------------------------------------------------------------------------- // Input @@ -133,6 +145,20 @@ { return multiOrganisationUnit; } + + private String cc; + + public void setCc( String cc ) + { + this.cc = cc; + } + + private Set cp; + + public void setCp( Set cp ) + { + this.cp = cp; + } // ------------------------------------------------------------------------- // Output @@ -186,6 +212,10 @@ public String execute() { + // --------------------------------------------------------------------- + // Validation + // --------------------------------------------------------------------- + DataSet dataSet = dataSetService.getDataSet( dataSetId ); Period period = PeriodType.getPeriodFromIsoString( periodId ); @@ -195,9 +225,41 @@ if ( organisationUnit == null || period == null || dataSet == null ) { log.warn( "Illegal input, org unit: " + organisationUnit + ", period: " + period + ", data set: " + dataSet ); + return SUCCESS; } Set children = organisationUnit.getChildren(); + + // --------------------------------------------------------------------- + // Attributes + // --------------------------------------------------------------------- + + DataElementCategoryOptionCombo attributeOptionCombo = null; + + if ( cc != null && cp != null ) + { + DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( cc ); + + Set categoryOptions = new HashSet(); + + for ( String id : cp ) + { + categoryOptions.add( categoryService.getDataElementCategoryOption( id ) ); + } + + attributeOptionCombo = categoryService.getDataElementCategoryOptionCombo( categoryCombo, categoryOptions ); + + if ( attributeOptionCombo == null ) + { + log.warn( "Illegal input, attribute option combo does not exist" ); + return SUCCESS; + } + } + + if ( attributeOptionCombo == null ) + { + attributeOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo(); + } // --------------------------------------------------------------------- // Data values & Min-max data elements @@ -207,7 +269,7 @@ if ( !multiOrganisationUnit ) { - dataValues.addAll( dataValueService.getDataValues( organisationUnit, period, dataSet.getDataElements() ) ); + dataValues.addAll( dataValueService.getDataValues( organisationUnit, period, dataSet.getDataElements(), attributeOptionCombo ) ); } else { @@ -215,7 +277,7 @@ { if ( ou.getDataSets().contains( dataSet ) ) { - dataValues.addAll( dataValueService.getDataValues( ou, period, dataSet.getDataElements() ) ); + dataValues.addAll( dataValueService.getDataValues( ou, period, dataSet.getDataElements(), attributeOptionCombo ) ); minMaxDataElements.addAll( minMaxDataElementService.getMinMaxDataElements( ou, dataSet .getDataElements() ) ); } === 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-20 22:02:12 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml 2013-12-21 17:59:39 +0000 @@ -36,6 +36,7 @@ +