dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16222
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6117: (patient) Allow to select data-values in the aggregate result to add/update/delete into database.
------------------------------------------------------------
revno: 6117
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-02-27 12:35:23 +0700
message:
(patient) Allow to select data-values in the aggregate result to add/update/delete into database.
added:
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.java
modified:
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties
dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm
dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js
--
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-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java 2012-02-23 08:38:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/CaseAggregationResultAction.java 2012-02-27 05:35:23 +0000
@@ -36,7 +36,6 @@
import java.util.Map;
import java.util.Set;
-import org.apache.struts.taglib.html.FormTag;
import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
import org.hisp.dhis.caseaggregation.CaseAggregationConditionService;
import org.hisp.dhis.caseentry.state.PeriodGenericManager;
@@ -53,13 +52,18 @@
import org.hisp.dhis.oust.manager.SelectionTreeManager;
import org.hisp.dhis.period.CalendarPeriodType;
import org.hisp.dhis.period.Period;
-import org.hisp.dhis.user.CurrentUserService;
import com.opensymphony.xwork2.Action;
public class CaseAggregationResultAction
implements Action
{
+ private String ADD_STATUS = "add";
+
+ private String UPDATE_STATUS = "update";
+
+ private String DELETE_STATUS = "delete";
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -92,13 +96,6 @@
this.dataValueService = dataValueService;
}
- private CurrentUserService currentUserService;
-
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
-
private PeriodGenericManager periodGenericManager;
public void setPeriodGenericManager( PeriodGenericManager periodGenericManager )
@@ -180,8 +177,6 @@
public String execute()
throws Exception
{
- String storedBy = currentUserService.getCurrentUsername() + "_CAE";
-
// ---------------------------------------------------------------------
// Get selected orgunits
// ---------------------------------------------------------------------
@@ -265,21 +260,17 @@
{
if ( dataValue == null )
{
- dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, storedBy,
+ dataValue = new DataValue( dElement, period, orgUnit, "" + resultValue, "",
new Date(), null, optionCombo );
- dataValueService.addDataValue( dataValue );
- mapStatusValues.put( keyStatus, i18n.getString( "added" ) );
+ mapStatusValues.put( keyStatus, i18n.getString( ADD_STATUS ) );
}
else
{
dataValue.setValue( "" + resultValue );
dataValue.setTimestamp( new Date() );
- dataValue.setStoredBy( storedBy );
-
- dataValueService.updateDataValue( dataValue );
-
- mapStatusValues.put( keyStatus, i18n.getString( "updated" ) );
+
+ mapStatusValues.put( keyStatus, i18n.getString( UPDATE_STATUS ) );
}
mapCaseAggCondition.put( dataValue, condition );
@@ -287,14 +278,7 @@
}
else if ( dataValue != null )
{
- String value = dataValue.getValue();
-
- dataValueService.deleteDataValue( dataValue );
-
- dataValue = new DataValue( dElement, period, orgUnit, value, storedBy, new Date(),
- null, optionCombo );
-
- mapStatusValues.put( keyStatus, i18n.getString( "deleted" ) );
+ mapStatusValues.put( keyStatus, i18n.getString( DELETE_STATUS ) );
}
if ( dataValue != null )
=== added file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseaggregation/SaveAggregateDataValueAction.java 2012-02-27 05:35:23 +0000
@@ -0,0 +1,195 @@
+/*
+ * Copyright (c) 2004-2012, 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.
+ */
+
+package org.hisp.dhis.caseentry.action.caseaggregation;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+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.datavalue.DataValue;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.user.CurrentUserService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $SaveAggregateDataValueAction.java Feb 27, 2012 10:04:36 AM$
+ */
+public class SaveAggregateDataValueAction
+ implements Action
+{
+ private String SEPERATE_SIGN = "_";
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ private DataElementCategoryService categoryService;
+
+ public void setCategoryService( DataElementCategoryService categoryService )
+ {
+ this.categoryService = categoryService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ private DataValueService dataValueService;
+
+ public void setDataValueService( DataValueService dataValueService )
+ {
+ this.dataValueService = dataValueService;
+ }
+
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private Set<String> aggregateValues = new HashSet<String>();
+
+ public void setAggregateValues( Set<String> aggregateValues )
+ {
+ this.aggregateValues = aggregateValues;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action Implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ throws Exception
+ {
+ String storedBy = currentUserService.getCurrentUsername() + "_CAE";
+
+ for ( String aggregateValue : aggregateValues )
+ {
+ // -----------------------------------------------------------------
+ // Get params
+ // -----------------------------------------------------------------
+ String[] info = aggregateValue.split( SEPERATE_SIGN );
+
+ int dataElementId = Integer.parseInt( info[0] );
+ int optionComboId = Integer.parseInt( info[1] );
+
+ String periodTypeName = info[2];
+ String startDate = info[3];
+
+ int orgunitId = Integer.parseInt( info[4] );
+
+ String resultValue = info[5];
+
+ // -----------------------------------------------------------------
+ // Create objects
+ // -----------------------------------------------------------------
+
+ DataElement dataElement = dataElementService.getDataElement( dataElementId );
+ DataElementCategoryOptionCombo optionCombo = categoryService
+ .getDataElementCategoryOptionCombo( optionComboId );
+
+ PeriodType periodType = periodService.getPeriodTypeByName( periodTypeName );
+ Period period = periodType.createPeriod( format.parseDate( startDate ) );
+
+ OrganisationUnit orgunit = organisationUnitService.getOrganisationUnit( orgunitId );
+
+ DataValue dataValue = dataValueService.getDataValue( orgunit, dataElement, period, optionCombo );
+
+ // -----------------------------------------------------------------
+ // Save/Update/Delete data-values
+ // -----------------------------------------------------------------
+
+ if ( resultValue != "0.0" )
+ {
+ if ( dataValue == null )
+ {
+ dataValue = new DataValue( dataElement, period, orgunit, "" + resultValue, "", new Date(), null,
+ optionCombo );
+
+ dataValueService.addDataValue( dataValue );
+ }
+ else
+ {
+ dataValue.setValue( resultValue );
+ dataValue.setTimestamp( new Date() );
+ dataValue.setStoredBy( storedBy );
+
+ dataValueService.updateDataValue( dataValue );
+ }
+ }
+ else if ( dataValue != null )
+ {
+ dataValueService.deleteDataValue( dataValue );
+ }
+ }
+
+ return SUCCESS;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2012-02-27 02:09:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml 2012-02-27 05:35:23 +0000
@@ -299,9 +299,24 @@
<property name="aggregationConditionService"
ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionService" />
<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
+ <property name="periodGenericManager"
+ ref="org.hisp.dhis.caseentry.state.PeriodGenericManager" />
+ </bean>
+
+ <bean
+ id="org.hisp.dhis.caseentry.action.caseaggregation.SaveAggregateDataValueAction"
+ class="org.hisp.dhis.caseentry.action.caseaggregation.SaveAggregateDataValueAction"
+ scope="prototype">
+ <property name="organisationUnitService"
+ ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+ <property name="categoryService"
+ ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+ <property name="periodService"
+ ref="org.hisp.dhis.period.PeriodService" />
+ <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
- <property name="periodGenericManager"
- ref="org.hisp.dhis.caseentry.state.PeriodGenericManager" />
+
</bean>
<bean
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2012-02-23 08:38:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/org/hisp/dhis/caseentry/i18n_module.properties 2012-02-27 05:35:23 +0000
@@ -252,4 +252,7 @@
see_history_plan=See history / plan
name_based_data_entry=Name-based data entry
multiple_name_based_data_entry=Multiple name-based data entry
-ga_facilityby=Organisation Unit By
\ No newline at end of file
+ga_facilityby=Organisation Unit By
+saved = Saved
+save_selected_values = Save selected values
+save_all_values = Save all values
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2012-02-27 02:09:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml 2012-02-27 05:35:23 +0000
@@ -281,6 +281,12 @@
<param name="menu">/dhis-web-caseentry/caseAggregationMenu.vm</param>
<param name="javascripts">javascript/caseagg.js</param>
</action>
+
+ <action name="saveAggregateDataValue"
+ class="org.hisp.dhis.caseentry.action.caseaggregation.SaveAggregateDataValueAction">
+ <result name="success" type="velocity-json">
+ /dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
+ </action>
<action name="caseAggregationResultDetails"
class="org.hisp.dhis.caseentry.action.caseaggregation.CaseAggregationResultDetailsAction">
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm 2012-02-23 08:38:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/caseAggregationResult.vm 2012-02-27 05:35:23 +0000
@@ -1,9 +1,10 @@
<h4> $i18n.getString( "case_aggregation_result" )</h4>
<div>
- <input type="button" value="$i18n.getString( "back" )" onclick="backBtnOnClick();" style="width:10em">
+ <input type="button" value="$i18n.getString( 'back' )" onclick="backBtnOnClick();" style="width:10em">
+ <input type='button' value="$i18n.getString( 'save_selected_values' )" onclick='saveAggregateDataValues( false )' >
+ <input type='button' value="$i18n.getString( 'save_all_values' )" onclick='saveAggregateDataValues( true )' >
</div>
-
<p></p>
#set( $index = 0 )
@@ -31,17 +32,26 @@
#set($no = 1)
<tr>
<th>#</th>
+ <th><input type='checkbox' onchange="toogleAllCheckBoxes( '$periodDiv', this.checked );"></th>
<th>$i18n.getString('name')</th>
<th>$i18n.getString('value')</th>
<th>$i18n.getString('status')</th>
+ <th>$i18n.getString('operator')</th>
</tr>
#foreach( $dataValue in $dataValues)
#set( $statusKey = $key + '-' + $dataValue.dataElement.id )
- <tr #alternate( $mark ) style="cursor: pointer" title="$i18n.getString('show_details')" onclick="viewResultDetails($orgunit.id,$period.id,$mapCaseAggCondition.get($dataValue).id)">
+ <tr #alternate( $mark )>
<td>$no</td>
+ <td>
+ #set( $item=$dataValue.dataElement.id + '_' + $dataValue.optionCombo.id + '_' + $period.periodType.name + '_' + $format.formatDate($period.startDate) + '_' + $orgunit.id + '_' + $dataValue.value )
+ <input type='checkbox' name='aggregateValues' value='$item'>
+ </td>
<td>$dataValue.dataElement.name</td>
<td>$dataValue.value</td>
<td>$!mapStatusValues.get( $statusKey )</td>
+ <td>
+ <a href="javascript:viewResultDetails($orgunit.id,$period.id,$mapCaseAggCondition.get($dataValue).id)" title="$i18n.getString( 'show_details' )"><img src="../images/information.png" alt="$i18n.getString( 'show_details' )"></a>
+ </td>
</tr>
#set( $mark = !$mark )
#set ($no = $no + 1)
@@ -58,4 +68,6 @@
<script>
var i18n_aggregate_details = '$encoder.jsEscape( $i18n.getString( "aggregate_details" ) , "'")';
+ var i18n_save_success = '$encoder.jsEscape( $i18n.getString( "save_success" ) , "'")';
+ var i18n_saved = '$encoder.jsEscape( $i18n.getString( "saved" ) , "'")';
</script>
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js 2012-02-23 08:38:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/caseagg.js 2012-02-27 05:35:23 +0000
@@ -148,3 +148,50 @@
{
$( "#" + id + "-div" ).slideToggle( "fast" );
}
+
+function saveAggregateDataValues( isSaveAll )
+{
+ lockScreen();
+
+ var params = ""
+ if( isSaveAll )
+ {
+ jQuery("input[name=aggregateValues]").each(function( ){
+ params += "aggregateValues=" + $(this).val() + "&";
+ });
+ }
+ else
+ {
+ jQuery("input[name=aggregateValues]:checked").each(function( ){
+ params += "aggregateValues=" + $(this).val() + "&";
+ });
+ }
+
+ $.ajax({
+ type: "POST",
+ url: "saveAggregateDataValue.action",
+ data: params,
+ dataType: "json",
+ success: function(json){
+ if( isSaveAll )
+ {
+ jQuery("input[name=aggregateValues]").each(function( ){
+ $(this).replaceWith('<span>' + i18n_saved + '<span>' );
+ });
+ }
+ else
+ {
+ jQuery("input[name=aggregateValues]:checked").each(function( ){
+ $(this).replaceWith('<span>' + i18n_saved + '<span>' );
+ });
+ }
+ unLockScreen();
+ showSuccessMessage( i18n_save_success );
+ }
+ });
+}
+
+function toogleAllCheckBoxes( tableDiv, checked )
+{
+ jQuery("#" + tableDiv + " input[name=aggregateValues]").attr( 'checked', checked );
+}
\ No newline at end of file