dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26981
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13369: Data entry, retrieving data with attribute option combo
------------------------------------------------------------
revno: 13369
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-12-21 18:59:39 +0100
message:
Data entry, retrieving data with attribute option combo
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueStore.java
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/hibernate/HibernateDataValueStore.java
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/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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<DataValue> getDataValues( OrganisationUnit source, Period period, Collection<DataElement> 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<DataValue> getDataValues( OrganisationUnit source, Period period,
+ Collection<DataElement> 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<DataValue> getDataValues( OrganisationUnit source, Period period, Collection<DataElement> 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<DataValue> getDataValues( OrganisationUnit source, Period period,
+ Collection<DataElement> 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<DataValue> getDataValues( OrganisationUnit source, Period period,
+ Collection<DataElement> dataElements, DataElementCategoryOptionCombo attributeOptionCombo )
+ {
+ return dataValueStore.getDataValues( source, period, dataElements, attributeOptionCombo );
+ }
+
public Collection<DataValue> getDataValues( OrganisationUnit source, Period period, Collection<DataElement> dataElements,
Collection<DataElementCategoryOptionCombo> 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<DataValue> getDataValues( OrganisationUnit source, Period period,
+ Collection<DataElement> 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<DataValue> getDataValues( OrganisationUnit source, Period period, Collection<DataElement> dataElements,
Collection<DataElementCategoryOptionCombo> 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<String> cp;
+
+ public void setCp( Set<String> 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<OrganisationUnit> children = organisationUnit.getChildren();
+
+ // ---------------------------------------------------------------------
+ // Attributes
+ // ---------------------------------------------------------------------
+
+ DataElementCategoryOptionCombo attributeOptionCombo = null;
+
+ if ( cc != null && cp != null )
+ {
+ DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryCombo( cc );
+
+ Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
+
+ 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 @@
<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
<property name="registrationService" ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService" />
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
</bean>
<bean id="org.hisp.dhis.de.action.LoadFormAction" class="org.hisp.dhis.de.action.LoadFormAction" scope="prototype">