← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6116: (patient) Remove saveDateValue action in case-entry module.

 

------------------------------------------------------------
revno: 6116
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-02-27 09:09:02 +0700
message:
  (patient) Remove saveDateValue action in case-entry module.
removed:
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveDateValueAction.java
modified:
  dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.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/struts.xml
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.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-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-03-01 07:44:57 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2012-02-27 02:09:02 +0000
@@ -808,7 +808,7 @@
         // Inline Javascript to add to HTML before outputting
         // ---------------------------------------------------------------------
 
-        final String jsCodeForDate = " name=\"entryfield\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', provided:'$PROVIDED'}\" onchange=\"saveDate( $DATAELEMENTID )\" style=\" text-align:center;\" ";
+        final String jsCodeForDate = " name=\"entryfield\" $DISABLED data=\"{compulsory:$COMPULSORY, deName:'$DATAELEMENTNAME', provided:'$PROVIDED'}\" onchange=\"saveVal( $DATAELEMENTID )\" style=\" text-align:center;\" ";
 
         // ---------------------------------------------------------------------
         // Metadata code to add to HTML before outputting

=== removed file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveDateValueAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveDateValueAction.java	2012-02-11 13:58:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveDateValueAction.java	1970-01-01 00:00:00 +0000
@@ -1,191 +0,0 @@
-/*
- * Copyright (c) 2004-2009, 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.caseentry;
-
-import java.util.Date;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.caseentry.state.SelectedStateManager;
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.patientdatavalue.PatientDataValue;
-import org.hisp.dhis.patientdatavalue.PatientDataValueService;
-import org.hisp.dhis.program.ProgramStageInstance;
-import org.hisp.dhis.program.ProgramStageInstanceService;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Abyot Asalefew Gizaw
- * @version $Id$
- */
-public class SaveDateValueAction
-    implements Action
-{
-    private static final Log LOG = LogFactory.getLog( SaveDateValueAction.class );
-
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    private ProgramStageInstanceService programStageInstanceService;
-
-    public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
-    {
-        this.programStageInstanceService = programStageInstanceService;
-    }
-
-    private DataElementService dataElementService;
-
-    public void setDataElementService( DataElementService dataElementService )
-    {
-        this.dataElementService = dataElementService;
-    }
-
-    private PatientDataValueService patientDataValueService;
-
-    public void setPatientDataValueService( PatientDataValueService patientDataValueService )
-    {
-        this.patientDataValueService = patientDataValueService;
-    }
-
-    private SelectedStateManager selectedStateManager;
-
-    public void setSelectedStateManager( SelectedStateManager selectedStateManager )
-    {
-        this.selectedStateManager = selectedStateManager;
-    }
-
-    // -------------------------------------------------------------------------
-    // Input/Output
-    // -------------------------------------------------------------------------
-
-    private boolean providedByAnotherFacility;
-
-    public void setProvidedByAnotherFacility( boolean providedByAnotherFacility )
-    {
-        this.providedByAnotherFacility = providedByAnotherFacility;
-    }
-
-    private String value;
-
-    public void setValue( String value )
-    {
-        this.value = value;
-    }
-
-    private int dataElementId;
-
-    public void setDataElementId( int dataElementId )
-    {
-        this.dataElementId = dataElementId;
-    }
-
-    public int getDataElementId()
-    {
-        return dataElementId;
-    }
-
-    private int statusCode;
-
-    public int getStatusCode()
-    {
-        return statusCode;
-    }
-
-    public void setStatusCode( int statusCode )
-    {
-        this.statusCode = statusCode;
-    }
-
-    private String message;
-
-    public String getMessage()
-    {
-        return message;
-    }
-
-    // -------------------------------------------------------------------------
-    // Implementation Action
-    // -------------------------------------------------------------------------
-
-    public String execute()
-        throws Exception
-    {
-        // ---------------------------------------------------------------------
-        // Get program-stage-instance
-        // ---------------------------------------------------------------------
-
-        OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
-
-        ProgramStageInstance programStageInstance = selectedStateManager.getSelectedProgramStageInstance();
-
-        DataElement dataElement = dataElementService.getDataElement( dataElementId );
-
-        PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance,
-            dataElement, organisationUnit );
-
-        if ( value != null && value.trim().length() == 0 )
-        {
-            value = null;
-        }
-
-        // ---------------------------------------------------------------------
-        // Save value
-        // ---------------------------------------------------------------------
-
-        if ( programStageInstance.getExecutionDate() == null )
-        {
-            programStageInstance.setExecutionDate( new Date() );
-            programStageInstanceService.updateProgramStageInstance( programStageInstance );
-        }
-
-        if ( patientDataValue == null && value != null )
-        {
-            LOG.debug( "Adding PatientDataValue, value added" );
-
-            patientDataValue = new PatientDataValue( programStageInstance, dataElement, organisationUnit,
-                new Date(), value, providedByAnotherFacility );
-
-            patientDataValueService.savePatientDataValue( patientDataValue );
-        }
-        else
-        {
-            LOG.debug( "Updating PatientDataValue, value added/changed" );
-
-            patientDataValue.setValue( value );
-            patientDataValue.setProvidedByAnotherFacility( providedByAnotherFacility );
-            patientDataValue.setTimestamp( new Date() );
-
-            patientDataValueService.updatePatientDataValue( patientDataValue );
-        }
-
-        return SUCCESS;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.java	2012-02-11 13:58:02 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/SaveValueAction.java	2012-02-27 02:09:02 +0000
@@ -76,7 +76,7 @@
     {
         this.patientDataValueService = patientDataValueService;
     }
-    
+
     private SelectedStateManager selectedStateManager;
 
     public void setSelectedStateManager( SelectedStateManager selectedStateManager )
@@ -140,35 +140,36 @@
     public String execute()
         throws Exception
     {
-        // ---------------------------------------------------------------------
-        // Get program-stage-instance
-        // ---------------------------------------------------------------------
-
         OrganisationUnit organisationUnit = selectedStateManager.getSelectedOrganisationUnit();
 
         ProgramStageInstance programStageInstance = selectedStateManager.getSelectedProgramStageInstance();
 
-        // ---------------------------------------------------------------------
-        // Save value
-        // ---------------------------------------------------------------------
-
         DataElement dataElement = dataElementService.getDataElement( dataElementId );
 
         PatientDataValue patientDataValue = patientDataValueService.getPatientDataValue( programStageInstance,
             dataElement, organisationUnit );
-        
+
+        if ( value != null && value.trim().length() == 0 )
+        {
+            value = null;
+        }
+
+        // ---------------------------------------------------------------------
+        // Save value
+        // ---------------------------------------------------------------------
+
         if ( programStageInstance.getExecutionDate() == null )
         {
             programStageInstance.setExecutionDate( new Date() );
             programStageInstanceService.updateProgramStageInstance( programStageInstance );
         }
 
-        if ( patientDataValue == null )
+        if ( patientDataValue == null  && value != null )
         {
             LOG.debug( "Adding PatientDataValue, value added" );
 
-            patientDataValue = new PatientDataValue( programStageInstance, dataElement, organisationUnit,
-                new Date(), value, providedByAnotherFacility );
+            patientDataValue = new PatientDataValue( programStageInstance, dataElement, organisationUnit, new Date(),
+                value, providedByAnotherFacility );
 
             patientDataValueService.savePatientDataValue( patientDataValue );
         }

=== 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-25 12:24:41 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/META-INF/dhis/beans.xml	2012-02-27 02:09:02 +0000
@@ -81,18 +81,6 @@
 			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
 	</bean>
 
-	<bean id="org.hisp.dhis.caseentry.action.caseentry.SaveDateValueAction"
-		class="org.hisp.dhis.caseentry.action.caseentry.SaveDateValueAction"
-		scope="prototype">
-		<property name="programStageInstanceService"
-			ref="org.hisp.dhis.program.ProgramStageInstanceService" />
-		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
-		<property name="patientDataValueService"
-			ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
-		<property name="selectedStateManager"
-			ref="org.hisp.dhis.caseentry.state.SelectedStateManager" />
-	</bean>
-
 	<bean
 		id="org.hisp.dhis.caseentry.action.caseentry.SaveProvidingFacilityAction"
 		class="org.hisp.dhis.caseentry.action.caseentry.SaveProvidingFacilityAction"

=== 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-23 08:38:50 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/resources/struts.xml	2012-02-27 02:09:02 +0000
@@ -109,13 +109,7 @@
 			<param name="onExceptionReturn">plainTextError</param>
 		</action>
 
-		<!-- save data-value -->
-
-		<action name="saveDateValue"
-			class="org.hisp.dhis.caseentry.action.caseentry.SaveDateValueAction">
-			<result name="success" type="velocity-xml">status.vm</result>
-			<param name="onExceptionReturn">plainTextError</param>
-		</action>
+		<!-- save providing-facility -->
 
 		<action name="saveProvidingFacility"
 			class="org.hisp.dhis.caseentry.action.caseentry.SaveProvidingFacilityAction">

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-02-17 16:17:14 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/dataEntryForm.vm	2012-02-27 02:09:02 +0000
@@ -98,7 +98,7 @@
 							<option value="false" #if( $patientDataValue.value == "false" ) selected="selected" #end>$i18n.getString( "no" )</option>
 						</select> 
 					#elseif( $programStageDataElement.dataElement.type == "date" )
-						<input type="text" data="{compulsory: $programStageDataElement.compulsory }" #if($programStageInstance.completed) disabled="disabled" #end id="$id" name="entryfield" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveDate( $programStageDataElement.dataElement.id )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
+						<input type="text" data="{compulsory: $programStageDataElement.compulsory }" #if($programStageInstance.completed) disabled="disabled" #end id="$id" name="entryfield" value="$!encoder.htmlEncode( $patientDataValue.value )" onchange="saveVal( $programStageDataElement.dataElement.id )" onkeypress="return keyPress(event, this)" tabindex="$tabIndex" >
 						#if(!$programStageInstance.completed)
 							<script type="text/javascript">
 								datePicker($programStageDataElement.programStage.id + '-' + $programStageDataElement.dataElement.id + '-val', false);

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-02-23 09:58:41 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2012-02-27 02:09:02 +0000
@@ -217,22 +217,6 @@
     valueSaver.save();
 }
 
-function saveDate( dataElementId )
-{	
-	var programStageId = byId('programStageId').value;
-	var fieldId = programStageId + '-' + dataElementId + '-val';
-	var field = jQuery( "#" + fieldId ); 
-	var data = field.metadata({
-        type:'attr',
-        name:'data'
-    });
-	
-    var providedByAnotherFacility = document.getElementById( programStageId + '_' + dataElementId + '_facility' ).checked;
-	
-    var dateSaver = new DateSaver( dataElementId, field.val(), providedByAnotherFacility, '#ccffcc' );
-    dateSaver.save();
-}
-
 function saveOpt( dataElementId )
 {
 	var programStageId = byId('programStageId').value;
@@ -460,98 +444,6 @@
     }
 }
 
-function DateSaver( dataElementId_, value_, providedByAnotherFacility_, resultColor_ )
-{
-    var SUCCESS = '#ccffcc';
-    var ERROR = '#ffcc00';
-	
-    var dataElementId = dataElementId_;
-    var value = value_;
-    var providedByAnotherFacility = providedByAnotherFacility_;
-    var resultColor = resultColor_;
-
-    this.save = function()
-    {
-		var params = 'dataElementId=' + dataElementId;
-		params +=  '&value=' + value;
-		params +=  '&providedByAnotherFacility=' + providedByAnotherFacility;
-		
-		$.ajax({
-			   type: "POST",
-			   url: "saveDateValue.action",
-			   data: params,
-			   dataType: "xml",
-			   success: function(result){
-					handleResponse (result);
-			   },
-			   error: function(request,status,errorThrown) {
-					handleHttpError (request);
-			   }
-			});
-    };
-
-    function handleResponse( rootElement )
-    {
-        var codeElement = rootElement.getElementsByTagName( 'code' )[0];
-        var code = parseInt( codeElement.firstChild.nodeValue );
-        if ( code == 0 )
-        {
-            markValue( resultColor );
-        }
-        else if(code == 1)
-        {
-            if(value != "")
-            {
-                var dataelementList = rootElement.getElementsByTagName( 'validation' );
-                var message = '';
-
-                for ( var i = 0; i < dataelementList.length; i++ )
-                {
-                    message += "\n - " + dataelementList[i].firstChild.nodeValue;
-                }
-
-                markValue( ERROR );
-                window.alert( i18n_violate_validation + message);
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-        }
-		else if(code == 2)
-        {
-			markValue( ERROR );
-            window.alert( i18n_invalid_date + ":\n" + rootElement.getElementsByTagName( 'message' )[0].firstChild.nodeValue );
-		}
-        else
-        {
-            if(value != "")
-            {
-                markValue( ERROR );
-                window.alert( i18n_invalid_date );
-            }
-            else
-            {
-                markValue( resultColor );
-            }
-        }
-    }
-
-    function handleHttpError( errorCode )
-    {
-        markValue( ERROR );
-        window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
-    }
-
-    function markValue( color )
-    {
-		var programStageId = byId('programStageId').value;
-        var element = byId(  programStageId + "-" + dataElementId + '-val' );
-        
-        element.style.backgroundColor = color;
-    }
-}
-
 function FacilitySaver( dataElementId_, providedByAnotherFacility_, resultColor_ )
 {
     var SUCCESS = 'success';
@@ -579,7 +471,7 @@
 			});
     };
 
-    function handleResponseCheckBox( rootElement )
+    function handleResponse( rootElement )
     {
         var codeElement = rootElement.getElementsByTagName( 'code' )[0];
         var code = parseInt( codeElement.firstChild.nodeValue );
@@ -594,7 +486,7 @@
         }
     }
 
-    function handleHttpErrorCheckBox( errorCode )
+    function handleHttpError( errorCode )
     {
         markValue( ERROR );
         window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );